diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index a45eba97..63bb2915 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -18,12 +18,10 @@ * 02110-1301, USA */ -#include "fluidsynth_priv.h" #include "fluid_cmd.h" #include "fluid_synth.h" #include "fluid_settings.h" #include "fluid_hash.h" -#include "fluid_sys.h" #include "fluid_midi_router.h" #include "fluid_sfont.h" #include "fluid_chan.h" diff --git a/src/bindings/fluid_cmd.h b/src/bindings/fluid_cmd.h index 7e81ab08..b3df00d2 100644 --- a/src/bindings/fluid_cmd.h +++ b/src/bindings/fluid_cmd.h @@ -21,7 +21,7 @@ #ifndef _FLUID_CMD_H #define _FLUID_CMD_H -#include "fluidsynth_priv.h" +#include "fluid_sys.h" void fluid_shell_settings(fluid_settings_t *settings); diff --git a/src/bindings/fluid_rtkit.c b/src/bindings/fluid_rtkit.c index 282a4014..55be6149 100644 --- a/src/bindings/fluid_rtkit.c +++ b/src/bindings/fluid_rtkit.c @@ -25,7 +25,7 @@ SOFTWARE. ***/ -#include "fluidsynth_priv.h" +#include "fluid_sys.h" #ifdef DBUS_SUPPORT diff --git a/src/drivers/fluid_adriver.c b/src/drivers/fluid_adriver.c index f1ab772a..4311c46f 100644 --- a/src/drivers/fluid_adriver.c +++ b/src/drivers/fluid_adriver.c @@ -19,6 +19,7 @@ */ #include "fluid_adriver.h" +#include "fluid_sys.h" #include "fluid_settings.h" /* diff --git a/src/drivers/fluid_adriver.h b/src/drivers/fluid_adriver.h index 1564168f..5cfc688b 100644 --- a/src/drivers/fluid_adriver.h +++ b/src/drivers/fluid_adriver.h @@ -21,7 +21,7 @@ #ifndef _FLUID_AUDRIVER_H #define _FLUID_AUDRIVER_H -#include "fluid_sys.h" +#include "fluidsynth_priv.h" /* * fluid_audio_driver_t diff --git a/src/drivers/fluid_coreaudio.c b/src/drivers/fluid_coreaudio.c index 56860701..baeada53 100644 --- a/src/drivers/fluid_coreaudio.c +++ b/src/drivers/fluid_coreaudio.c @@ -24,12 +24,16 @@ * */ -#include "fluid_synth.h" -#include "fluid_midi.h" #include "fluid_adriver.h" -#include "fluid_mdriver.h" #include "fluid_settings.h" +/* + * !!! Make sure that no include above includes !!! + * It #defines some macros that collide with enum definitions of OpenTransportProviders.h, which is included from OSServices.h, included from CoreServices.h + * + * https://trac.macports.org/ticket/36962 + */ + #if COREAUDIO_SUPPORT #include #include diff --git a/src/fluidsynth.c b/src/fluidsynth.c index 16eafb3c..7bd6cdf6 100644 --- a/src/fluidsynth.c +++ b/src/fluidsynth.c @@ -18,13 +18,7 @@ * 02110-1301, USA */ -#include "config.h" - -#include -#include -#include - -#include "fluidsynth_priv.h" +#include "fluid_sys.h" #if !defined(WIN32) && !defined(MACINTOSH) #define _GNU_SOURCE @@ -35,8 +29,6 @@ #define GETOPT_SUPPORT 1 #endif -#include "fluidsynth.h" - #include "fluid_lash.h" diff --git a/src/midi/fluid_midi.c b/src/midi/fluid_midi.c index fb71a822..38c2bf6e 100644 --- a/src/midi/fluid_midi.c +++ b/src/midi/fluid_midi.c @@ -34,6 +34,7 @@ static long fluid_getlength(unsigned char *s); * Note: This rewinds the file to the start before reading. * Returns NULL if there was an error reading or allocating memory. */ +typedef FILE *fluid_file; static char *fluid_file_read_full(fluid_file fp, size_t *length); static void fluid_midi_event_set_sysex_LOCAL(fluid_midi_event_t *evt, int type, void *data, int size, int dynamic); static void fluid_midi_event_get_sysex_LOCAL(fluid_midi_event_t *evt, void **data, int *size); diff --git a/src/rvoice/fluid_rvoice_dsp.c b/src/rvoice/fluid_rvoice_dsp.c index 25f4a4b8..aec79aab 100644 --- a/src/rvoice/fluid_rvoice_dsp.c +++ b/src/rvoice/fluid_rvoice_dsp.c @@ -18,10 +18,9 @@ * 02110-1301, USA */ -#include "fluidsynth_priv.h" +#include "fluid_sys.h" #include "fluid_phase.h" #include "fluid_rvoice.h" -#include "fluid_sys.h" #include "fluid_rvoice_dsp_tables.c" /* Purpose: diff --git a/src/rvoice/fluid_rvoice_mixer.c b/src/rvoice/fluid_rvoice_mixer.c index af0ef75d..85c3fb91 100644 --- a/src/rvoice/fluid_rvoice_mixer.c +++ b/src/rvoice/fluid_rvoice_mixer.c @@ -23,7 +23,6 @@ #include "fluid_sys.h" #include "fluid_rev.h" #include "fluid_chorus.h" -#include "fluidsynth_priv.h" #include "fluid_ladspa.h" #include "fluid_synth.h" diff --git a/src/sfloader/fluid_samplecache.c b/src/sfloader/fluid_samplecache.c index 036964f5..f464f178 100644 --- a/src/sfloader/fluid_samplecache.c +++ b/src/sfloader/fluid_samplecache.c @@ -29,7 +29,6 @@ #include "fluid_samplecache.h" #include "fluid_sys.h" -#include "fluidsynth.h" #include "fluid_list.h" diff --git a/src/synth/fluid_tuning.c b/src/synth/fluid_tuning.c index ee083116..0df248b7 100644 --- a/src/synth/fluid_tuning.c +++ b/src/synth/fluid_tuning.c @@ -20,7 +20,6 @@ #include "fluid_tuning.h" -#include "fluidsynth_priv.h" #include "fluid_sys.h" diff --git a/src/synth/fluid_voice.c b/src/synth/fluid_voice.c index 2bbe5de2..ab48b4e8 100644 --- a/src/synth/fluid_voice.c +++ b/src/synth/fluid_voice.c @@ -18,7 +18,7 @@ * 02110-1301, USA */ -#include "fluidsynth_priv.h" +#include "fluid_sys.h" #include "fluid_voice.h" #include "fluid_mod.h" #include "fluid_chan.h" diff --git a/src/synth/fluid_voice.h b/src/synth/fluid_voice.h index 6038a1a9..386f70e7 100644 --- a/src/synth/fluid_voice.h +++ b/src/synth/fluid_voice.h @@ -30,7 +30,6 @@ #include "fluid_lfo.h" #include "fluid_rvoice.h" #include "fluid_rvoice_event.h" -#include "fluid_sys.h" #define NO_CHANNEL 0xff diff --git a/src/utils/fluid_conv.c b/src/utils/fluid_conv.c index 483b371d..6e169b03 100644 --- a/src/utils/fluid_conv.c +++ b/src/utils/fluid_conv.c @@ -19,6 +19,7 @@ */ #include "fluid_conv.h" +#include "fluid_sys.h" #include "fluid_conv_tables.c" /* diff --git a/src/utils/fluid_hash.c b/src/utils/fluid_hash.c index 37b0a06a..946a873b 100644 --- a/src/utils/fluid_hash.c +++ b/src/utils/fluid_hash.c @@ -31,7 +31,7 @@ * MT safe */ -#include "fluidsynth_priv.h" +#include "fluid_sys.h" #include "fluid_hash.h" #include "fluid_list.h" diff --git a/src/utils/fluid_ringbuffer.c b/src/utils/fluid_ringbuffer.c index 71fd1e48..e6720011 100644 --- a/src/utils/fluid_ringbuffer.c +++ b/src/utils/fluid_ringbuffer.c @@ -24,7 +24,7 @@ */ #include "fluid_ringbuffer.h" -#include "fluidsynth_priv.h" +#include "fluid_sys.h" /** diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 10f7d12b..72ca197e 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -20,17 +20,20 @@ /** - - This header contains a bunch of (mostly) system and machine - dependent functions: - - - timers - - current time in milliseconds and microseconds - - debug logging - - profiling - - memory locking - - checking for floating point exceptions - + * @file fluid_sys.h + * + * This header contains a bunch of (mostly) system and machine + * dependent functions: + * + * - timers + * - current time in milliseconds and microseconds + * - debug logging + * - profiling + * - memory locking + * - checking for floating point exceptions + * + * fluidsynth's wrapper OSAL so to say; include it in .c files, be careful to include + * it in fluidsynth's private header files (see comment in fluid_coreaudio.c) */ #ifndef _FLUID_SYS_H @@ -38,6 +41,124 @@ #include "fluidsynth_priv.h" +#if defined(__POWERPC__) && !(defined(__APPLE__) && defined(__MACH__)) +#include "config_maxmsp43.h" +#endif + +#if HAVE_MATH_H +#include +#endif + +#if HAVE_ERRNO_H +#include +#endif + +#if HAVE_STDARG_H +#include +#endif + +#if HAVE_UNISTD_H +#include +#endif + +#if HAVE_FCNTL_H +#include +#endif + +#if HAVE_SYS_MMAN_H +#include +#endif + +#if HAVE_SYS_TYPES_H +#include +#endif + +#if HAVE_SYS_STAT_H +#include +#endif + +#if HAVE_SYS_TIME_H +#include +#endif + +#if HAVE_SYS_SOCKET_H +#include +#endif + +#if HAVE_NETINET_IN_H +#include +#endif + +#if HAVE_NETINET_TCP_H +#include +#endif + +#if HAVE_ARPA_INET_H +#include +#endif + +#if HAVE_LIMITS_H +#include +#endif + +#if HAVE_PTHREAD_H +#include +#endif + +#if HAVE_OPENMP +#include +#endif + +#if HAVE_IO_H +#include // _open(), _close(), read(), write() on windows +#endif + +#if HAVE_SIGNAL_H +#include +#endif + +/** Integer types */ +#if HAVE_STDINT_H +#include + +#else + +/* Assume GLIB types */ +typedef gint8 int8_t; +typedef guint8 uint8_t; +typedef gint16 int16_t; +typedef guint16 uint16_t; +typedef gint32 int32_t; +typedef guint32 uint32_t; +typedef gint64 int64_t; +typedef guint64 uint64_t; + +#endif + +#if defined(WIN32) && HAVE_WINDOWS_H +#include +#include /* Provides also socklen_t */ + +/* WIN32 special defines */ +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +#ifdef _MSC_VER +#pragma warning(disable : 4244) +#pragma warning(disable : 4101) +#pragma warning(disable : 4305) +#pragma warning(disable : 4996) +#endif + +#endif + +/* Darwin special defines (taken from config_macosx.h) */ +#ifdef DARWIN +# define MACINTOSH +# define __Types__ +#endif + #ifdef LADSPA #include #endif @@ -52,26 +173,12 @@ */ #define fluid_gerror_message(err) ((err) ? err->message : "No error details") -/* Misc */ -#if defined(__INTEL_COMPILER) -#define FLUID_RESTRICT restrict -#elif defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) -#define FLUID_RESTRICT __restrict__ -#elif defined(_MSC_VER) && _MSC_VER >= 1400 -#define FLUID_RESTRICT __restrict -#else -#warning "Dont know how this compiler handles restrict pointers, refuse to use them." -#define FLUID_RESTRICT -#endif #define FLUID_INLINE inline #define FLUID_POINTER_TO_UINT GPOINTER_TO_UINT #define FLUID_UINT_TO_POINTER GUINT_TO_POINTER #define FLUID_POINTER_TO_INT GPOINTER_TO_INT #define FLUID_INT_TO_POINTER GINT_TO_POINTER -#define FLUID_N_ELEMENTS(struct) (sizeof (struct) / sizeof (struct[0])) -#define FLUID_MEMBER_SIZE(struct, member) ( sizeof (((struct *)0)->member) ) - #define FLUID_IS_BIG_ENDIAN (G_BYTE_ORDER == G_BIG_ENDIAN) #define FLUID_LE32TOH(x) GINT32_FROM_LE(x) @@ -85,17 +192,6 @@ (uint32_t)(((uint32_t)(_d) << 24) | ((uint32_t)(_c) << 16) | ((uint32_t)(_b) << 8) | (uint32_t)(_a)) #endif - -#define fluid_return_if_fail(cond) \ -if(cond) \ - ; \ -else \ - return - -#define fluid_return_val_if_fail(cond, val) \ - fluid_return_if_fail(cond) (val) - - /* * Utility functions */ @@ -361,6 +457,12 @@ fluid_ostream_t fluid_get_stdout(void); int fluid_istream_readline(fluid_istream_t in, fluid_ostream_t out, char *prompt, char *buf, int len); int fluid_ostream_printf(fluid_ostream_t out, const char *format, ...); +#if defined(WIN32) +typedef SOCKET fluid_socket_t; +#else +typedef int fluid_socket_t; +#endif + /* The function should return 0 if no error occured, non-zero otherwise. If the function return non-zero, the socket will be closed by the server. */ diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h index 4df590e2..e299a5ff 100644 --- a/src/utils/fluidsynth_priv.h +++ b/src/utils/fluidsynth_priv.h @@ -18,6 +18,13 @@ * 02110-1301, USA */ +/** + * @file fluidsynth_priv.h + * + * lightweight part of fluid_sys.h, containing forward declarations of fluidsynth's private types and private macros + * + * include this one file in fluidsynth's private header files + */ #ifndef _FLUIDSYNTH_PRIV_H #define _FLUIDSYNTH_PRIV_H @@ -26,136 +33,18 @@ #include "config.h" -#if defined(__POWERPC__) && !(defined(__APPLE__) && defined(__MACH__)) -#include "config_maxmsp43.h" +#if HAVE_STDLIB_H +#include // malloc, free +#endif + +#if HAVE_STDIO_H +#include // printf #endif #if HAVE_STRING_H #include #endif -#if HAVE_STDLIB_H -#include -#endif - -#if HAVE_STDIO_H -#include -#endif - -#if HAVE_MATH_H -#include -#endif - -#if HAVE_ERRNO_H -#include -#endif - -#if HAVE_STDARG_H -#include -#endif - -#if HAVE_UNISTD_H -#include -#endif - -#if HAVE_FCNTL_H -#include -#endif - -#if HAVE_SYS_MMAN_H -#include -#endif - -#if HAVE_SYS_TYPES_H -#include -#endif - -#if HAVE_SYS_STAT_H -#include -#endif - -#if HAVE_SYS_TIME_H -#include -#endif - -#if HAVE_SYS_SOCKET_H -#include -#endif - -#if HAVE_NETINET_IN_H -#include -#endif - -#if HAVE_NETINET_TCP_H -#include -#endif - -#if HAVE_ARPA_INET_H -#include -#endif - -#if HAVE_LIMITS_H -#include -#endif - -#if HAVE_PTHREAD_H -#include -#endif - -#if HAVE_OPENMP -#include -#endif - -#if HAVE_IO_H -#include // _open(), _close(), read(), write() on windows -#endif - -#if HAVE_SIGNAL_H -#include -#endif - -/** Integer types */ -#if HAVE_STDINT_H -#include - -#else - -/* Assume GLIB types */ -typedef gint8 int8_t; -typedef guint8 uint8_t; -typedef gint16 int16_t; -typedef guint16 uint16_t; -typedef gint32 int32_t; -typedef guint32 uint32_t; -typedef gint64 int64_t; -typedef guint64 uint64_t; - -#endif - -#if defined(WIN32) && HAVE_WINDOWS_H -#include -#include /* Provides also socklen_t */ - -/* WIN32 special defines */ -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -#ifdef _MSC_VER -#pragma warning(disable : 4244) -#pragma warning(disable : 4101) -#pragma warning(disable : 4305) -#pragma warning(disable : 4996) -#endif - -#endif - -/* Darwin special defines (taken from config_macosx.h) */ -#ifdef DARWIN -# define MACINTOSH -# define __Types__ -#endif - #include "fluidsynth.h" @@ -171,13 +60,6 @@ typedef float fluid_real_t; typedef double fluid_real_t; #endif - -#if defined(WIN32) -typedef SOCKET fluid_socket_t; -#else -typedef int fluid_socket_t; -#endif - #if defined(SUPPORTS_VLA) # define FLUID_DECLARE_VLA(_type, _name, _len) \ _type _name[_len] @@ -243,7 +125,6 @@ typedef void (*fluid_rvoice_function_t)(void *obj, const fluid_rvoice_param_t pa * * SYSTEM INTERFACE */ -typedef FILE *fluid_file; #define FLUID_MALLOC(_n) malloc(_n) #define FLUID_REALLOC(_p,_n) realloc(_p,_n) @@ -354,4 +235,30 @@ do { strncpy(_dst,_src,_n); \ char *fluid_error(void); +/* Misc */ +#if defined(__INTEL_COMPILER) +#define FLUID_RESTRICT restrict +#elif defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) +#define FLUID_RESTRICT __restrict__ +#elif defined(_MSC_VER) && _MSC_VER >= 1400 +#define FLUID_RESTRICT __restrict +#else +#warning "Dont know how this compiler handles restrict pointers, refuse to use them." +#define FLUID_RESTRICT +#endif + +#define FLUID_N_ELEMENTS(struct) (sizeof (struct) / sizeof (struct[0])) +#define FLUID_MEMBER_SIZE(struct, member) ( sizeof (((struct *)0)->member) ) + + +#define fluid_return_if_fail(cond) \ +if(cond) \ + ; \ +else \ + return + +#define fluid_return_val_if_fail(cond, val) \ + fluid_return_if_fail(cond) (val) + + #endif /* _FLUIDSYNTH_PRIV_H */ diff --git a/test/test_preset_sample_loading.c b/test/test_preset_sample_loading.c index fcccc639..5f884cf1 100644 --- a/test/test_preset_sample_loading.c +++ b/test/test_preset_sample_loading.c @@ -2,7 +2,7 @@ #include "fluidsynth.h" #include "sfloader/fluid_sfont.h" #include "sfloader/fluid_defsfont.h" -#include "utils/fluidsynth_priv.h" +#include "utils/fluid_sys.h" #include "utils/fluid_list.h" // load our sf2 and sf3 test soundfonts, with and without dynamic sample loading diff --git a/test/test_sample_cache.c b/test/test_sample_cache.c index 16771649..a76d2508 100644 --- a/test/test_sample_cache.c +++ b/test/test_sample_cache.c @@ -1,7 +1,7 @@ #include "test.h" #include "fluidsynth.h" // use local fluidsynth header -#include "utils/fluidsynth_priv.h" +#include "utils/fluid_sys.h" // this test aims to make sure that sample data used by multiple synths is not freed diff --git a/test/test_sample_rate_change.c b/test/test_sample_rate_change.c index 48e66df8..d0a5d643 100644 --- a/test/test_sample_rate_change.c +++ b/test/test_sample_rate_change.c @@ -4,7 +4,7 @@ #include "synth/fluid_synth.h" #include "synth/fluid_voice.h" #include "rvoice/fluid_rvoice.h" -#include "utils/fluidsynth_priv.h" +#include "utils/fluid_sys.h" static void verify_sample_rate(fluid_synth_t *synth, int expected_srate) { diff --git a/test/test_sf3_sfont_loading.c b/test/test_sf3_sfont_loading.c index d454a1e4..ed6064e5 100644 --- a/test/test_sf3_sfont_loading.c +++ b/test/test_sf3_sfont_loading.c @@ -1,7 +1,7 @@ #include "test.h" #include "fluidsynth.h" #include "sfloader/fluid_sfont.h" -#include "utils/fluidsynth_priv.h" +#include "utils/fluid_sys.h" int main(void) diff --git a/test/test_sfont_loading.c b/test/test_sfont_loading.c index 9cac3d07..c8f4c043 100644 --- a/test/test_sfont_loading.c +++ b/test/test_sfont_loading.c @@ -2,7 +2,7 @@ #include "test.h" #include "fluidsynth.h" #include "sfloader/fluid_sfont.h" -#include "utils/fluidsynth_priv.h" +#include "utils/fluid_sys.h" // this tests the soundfont loading API of the synth. diff --git a/test/test_snprintf.c b/test/test_snprintf.c index d0fee749..35722e5a 100644 --- a/test/test_snprintf.c +++ b/test/test_snprintf.c @@ -1,6 +1,6 @@ #include "test.h" -#include "utils/fluidsynth_priv.h" +#include "utils/fluid_sys.h" // this test makes sure FLUID_SNPRINTF uses a proper C99 compliant implementation