diff --git a/fluidsynth/ChangeLog b/fluidsynth/ChangeLog index 7449d55c..7d524223 100644 --- a/fluidsynth/ChangeLog +++ b/fluidsynth/ChangeLog @@ -1,3 +1,24 @@ +2009-04-26 Josh Green + * configure.ac: Added glib 2.10 as a dependency, added notes in output + for LASH, LADCCA and READLINE that they are GPL. + * src/fluid_io.c: Moved code to fluid_sys.c and removed. + * src/config_win32.h: Added "typedef int socklen_t" definition. + * src/fluid_defsfont.h: Removed glib ripped code. + * src/fluid_oss.c: Fixed warnings where return value of write() was + being ignored. + * src/fluid_sys.c: Re-organized, implemented portable fluid_curtime() and + fluid_utime() using glib functions and removed old platform specific + code, implemented fluid_thread functionality using glib and removed + old platform specific code, fluid_istream_readline(), fluid_istream_gets() + and fluid_ostream_printf() should now work on WIN32 also, added code + for WIN32 for TCP sockets (not yet tested). + * src/fluid_sys.h: Added fluid_gerror_message() macro to extract message + safely from GError structures, replaced fluid_mutex macros with + portable implementations using glib, removed new_fluid_client_socket() + and delete_fluid_client_socket() which were never implemented or used. + * src/fluidsynth.c: Added call to g_thread_init(). + * src/fluidsynth_priv.h: Integer types now use glib integer types. + 2009-04-11 Josh Green * FluidSynth release 1.0.9 "A Sound Future" * configure.ac: Bumped version, no library interfaces added, removed or changed. diff --git a/fluidsynth/configure.ac b/fluidsynth/configure.ac index cde2090f..7b363936 100644 --- a/fluidsynth/configure.ac +++ b/fluidsynth/configure.ac @@ -7,8 +7,8 @@ AC_INIT(src/fluidsynth.c) dnl *** NOTE *** Don't forget to update library version below also FLUIDSYNTH_VERSION_MAJOR=1 -FLUIDSYNTH_VERSION_MINOR=0 -FLUIDSYNTH_VERSION_MICRO=9 +FLUIDSYNTH_VERSION_MINOR=1 +FLUIDSYNTH_VERSION_MICRO=0 FLUIDSYNTH_VERSION=$FLUIDSYNTH_VERSION_MAJOR.$FLUIDSYNTH_VERSION_MINOR.$FLUIDSYNTH_VERSION_MICRO AC_SUBST(FLUIDSYNTH_VERSION_MAJOR) @@ -145,6 +145,11 @@ else AC_DEFINE(DEBUG, 0, [Define to activate debugging message]) fi +dnl Assert that glib and gthread are available +PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.10 gthread-2.0 >= 2.10) +AC_SUBST(GLIB_CFLAGS) +AC_SUBST(GLIB_LIBS) + dnl dnl Check support for all the drivers @@ -466,13 +471,13 @@ else fi if test "${LASH_FOUND}" = "yes"; then - echo "LASH support: yes" + echo "LASH support: yes (NOTE: GPL library)" else echo "LASH support: no" fi if test "${LADCCA_FOUND}" = "yes"; then - echo "LADCCA support: yes" + echo "LADCCA support: yes (NOTE: GPL library)" else echo "LADCCA support: no" fi @@ -490,7 +495,7 @@ dnl echo "Sound file: no" dnl fi if test "$WITH_READLINE" = "1"; then - echo "Readline: yes" + echo "Readline: yes (NOTE: GPL library)" else echo "Readline: no" fi diff --git a/fluidsynth/fluidsynth.anjuta b/fluidsynth/fluidsynth.anjuta index 8b9268a4..8af7c743 100644 --- a/fluidsynth/fluidsynth.anjuta +++ b/fluidsynth/fluidsynth.anjuta @@ -10,13 +10,6 @@ attribute="Supported-Project-Types" value="automake"/> - - - @@ -27,13 +20,6 @@ attribute="Supported-Build-Types" value="make"/> - - - diff --git a/fluidsynth/src/Makefile.am b/fluidsynth/src/Makefile.am index 156a4946..20dc0175 100644 --- a/fluidsynth/src/Makefile.am +++ b/fluidsynth/src/Makefile.am @@ -86,8 +86,6 @@ libfluidsynth_la_SOURCES = \ fluid_gen.h \ fluid_hash.c \ fluid_hash.h \ - fluid_io.c \ - fluid_io.h \ fluid_ladspa.c \ fluid_ladspa.h \ fluid_lash.h \ @@ -126,11 +124,12 @@ libfluidsynth_la_SOURCES = \ INCLUDES = -I$(top_srcdir)/include $(LASH_CFLAGS) $(LADCCA_CFLAGS) \ $(READLINE_CFLAGS) $(JACK_CFLAGS) $(ALSA_CFLAGS) $(PULSE_CFLAGS) \ - $(PORTAUDIO_CFLAGS) $(DART_CFLAGS) + $(PORTAUDIO_CFLAGS) $(DART_CFLAGS) $(GLIB_CFLAGS) libfluidsynth_la_LIBADD = $(LIBFLUID_LIBS) $(LASH_LIBS) $(LADCCA_LIBS) \ $(READLINE_LIBS) $(COREAUDIO_LIBS) $(COREMIDI_LIBS) $(JACK_LIBS) \ - $(ALSA_LIBS) $(PULSE_LIBS) $(PORTAUDIO_LIBS) $(DART_LIBS) + $(ALSA_LIBS) $(PULSE_LIBS) $(PORTAUDIO_LIBS) $(DART_LIBS) \ + $(GLIB_LIBS) libfluidsynth_la_LDFLAGS = \ -version-info @LT_VERSION_INFO@ \ diff --git a/fluidsynth/src/config.h.in b/fluidsynth/src/config.h.in index af7b85b3..9b21060b 100644 --- a/fluidsynth/src/config.h.in +++ b/fluidsynth/src/config.h.in @@ -1,5 +1,8 @@ /* src/config.h.in. Generated from configure.ac by autoheader. */ +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + /* Define to enable ALSA driver */ #undef ALSA_SUPPORT @@ -187,9 +190,17 @@ /* Define to use the readline library for line editing */ #undef WITH_READLINE -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -#undef WORDS_BIGENDIAN +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ diff --git a/fluidsynth/src/config_win32.h b/fluidsynth/src/config_win32.h index 3da7bfc0..9744bef4 100644 --- a/fluidsynth/src/config_win32.h +++ b/fluidsynth/src/config_win32.h @@ -38,3 +38,5 @@ #ifndef inline #define inline __inline #endif + +typedef int socklen_t; diff --git a/fluidsynth/src/fluid_cmd.c b/fluidsynth/src/fluid_cmd.c index 086a225f..08e77def 100644 --- a/fluidsynth/src/fluid_cmd.c +++ b/fluidsynth/src/fluid_cmd.c @@ -22,10 +22,8 @@ #include "fluid_cmd.h" #include "fluid_synth.h" #include "fluid_settings.h" -#include "fluid_io.h" #include "fluid_hash.h" #include "fluid_sys.h" -#include "fluid_io.h" #include "fluid_midi_router.h" #include "fluid_sfont.h" diff --git a/fluidsynth/src/fluid_cmd.h b/fluidsynth/src/fluid_cmd.h index 9c05589e..48a015b8 100644 --- a/fluidsynth/src/fluid_cmd.h +++ b/fluidsynth/src/fluid_cmd.h @@ -22,7 +22,6 @@ #define _FLUID_CMD_H #include "fluidsynth_priv.h" -#include "fluid_io.h" void fluid_shell_settings(fluid_settings_t* settings); diff --git a/fluidsynth/src/fluid_defsfont.h b/fluidsynth/src/fluid_defsfont.h index 1fe463f2..70e0ce25 100644 --- a/fluidsynth/src/fluid_defsfont.h +++ b/fluidsynth/src/fluid_defsfont.h @@ -325,88 +325,7 @@ SFData *sfload_file (const char * fname); * Boston, MA 02111-1307, USA. */ - -/* Provide definitions for some commonly used macros. - * Some of them are only provided if they haven't already - * been defined. It is assumed that if they are already - * defined then the current definition is correct. - */ -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -#define GPOINTER_TO_INT(p) ((int) (p)) -#define GINT_TO_POINTER(i) ((void *) (i)) - -char* g_strdup (const char *str); - - - - - -/* Provide simple macro statement wrappers (adapted from Perl): - * G_STMT_START { statements; } G_STMT_END; - * can be used as a single statement, as in - * if (x) G_STMT_START { ... } G_STMT_END; else ... - * - * For gcc we will wrap the statements within `({' and `})' braces. - * For SunOS they will be wrapped within `if (1)' and `else (void) 0', - * and otherwise within `do' and `while (0)'. - */ -#if !(defined (G_STMT_START) && defined (G_STMT_END)) -# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) -# define G_STMT_START (void)( -# define G_STMT_END ) -# else -# if (defined (sun) || defined (__sun__)) -# define G_STMT_START if (1) -# define G_STMT_END else (void)0 -# else -# define G_STMT_START do -# define G_STMT_END while (0) -# endif -# endif -#endif - - -/* Basic bit swapping functions - */ -#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((unsigned short) ( \ - (((unsigned short) (val) & (unsigned short) 0x00ffU) << 8) | \ - (((unsigned short) (val) & (unsigned short) 0xff00U) >> 8))) -#define GUINT32_SWAP_LE_BE_CONSTANT(val) ((unsigned int) ( \ - (((unsigned int) (val) & (unsigned int) 0x000000ffU) << 24) | \ - (((unsigned int) (val) & (unsigned int) 0x0000ff00U) << 8) | \ - (((unsigned int) (val) & (unsigned int) 0x00ff0000U) >> 8) | \ - (((unsigned int) (val) & (unsigned int) 0xff000000U) >> 24))) - -#define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) -#define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val)) - -#define GINT16_TO_LE(val) ((signed short) (val)) -#define GUINT16_TO_LE(val) ((unsigned short) (val)) -#define GINT16_TO_BE(val) ((signed short) GUINT16_SWAP_LE_BE (val)) -#define GUINT16_TO_BE(val) (GUINT16_SWAP_LE_BE (val)) -#define GINT32_TO_LE(val) ((signed int) (val)) -#define GUINT32_TO_LE(val) ((unsigned int) (val)) -#define GINT32_TO_BE(val) ((signed int) GUINT32_SWAP_LE_BE (val)) -#define GUINT32_TO_BE(val) (GUINT32_SWAP_LE_BE (val)) - -/* The G*_TO_?E() macros are defined in glibconfig.h. - * The transformation is symmetric, so the FROM just maps to the TO. - */ -#define GINT16_FROM_LE(val) (GINT16_TO_LE (val)) -#define GUINT16_FROM_LE(val) (GUINT16_TO_LE (val)) -#define GINT16_FROM_BE(val) (GINT16_TO_BE (val)) -#define GUINT16_FROM_BE(val) (GUINT16_TO_BE (val)) -#define GINT32_FROM_LE(val) (GINT32_TO_LE (val)) -#define GUINT32_FROM_LE(val) (GUINT32_TO_LE (val)) -#define GINT32_FROM_BE(val) (GINT32_TO_BE (val)) -#define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val)) +#include /*-----------------------------------util.h----------------------------*/ diff --git a/fluidsynth/src/fluid_io.c b/fluidsynth/src/fluid_io.c deleted file mode 100644 index 1c46d9d3..00000000 --- a/fluidsynth/src/fluid_io.c +++ /dev/null @@ -1,121 +0,0 @@ -/* FluidSynth - A Software Synthesizer - * - * Copyright (C) 2003 Peter Hanappe and others. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307, USA - */ - - -#include "fluidsynth_priv.h" -#include "fluid_io.h" - -#if WITH_READLINE -#include -#include -#endif - -int fluid_istream_gets(fluid_istream_t in, char* buf, int len); - -fluid_istream_t fluid_get_stdin() -{ -#ifdef MACOS9 - return 0; /* to be tested - Antoine 8/3/3 */ -#else - return STDIN_FILENO; -#endif -} - -fluid_ostream_t fluid_get_stdout() -{ -#ifdef MACOS9 - return 1; /* to be tested - Antoine 8/3/3 */ -#else - return STDOUT_FILENO; -#endif -} - -int fluid_istream_readline(fluid_istream_t in, char* prompt, char* buf, int len) -{ -#if WITH_READLINE - if (in == fluid_get_stdin()) { - char* line; - - line = readline(prompt); - if (line == NULL) { - return -1; - } - - snprintf(buf, len, "%s", line); - buf[len - 1] = 0; - - free(line); - return 1; - } else { - return fluid_istream_gets(in, buf, len); - } -#else - return fluid_istream_gets(in, buf, len); -#endif -} - -/* FIXME */ -int fluid_istream_gets(fluid_istream_t in, char* buf, int len) -{ - char c; - int n; - - buf[len - 1] = 0; - - while (--len > 0) { - n = read(in, &c, 1); - if (n == 0) { - *buf++ = 0; - return 0; - } - if (n < 0) { - return n; - } - if ((c == '\n') || (c == '\r')) { - *buf++ = 0; - return 1; - } - *buf++ = c; - } - - return -1; -} - - -int fluid_ostream_printf(fluid_ostream_t out, char* format, ...) -{ - char buf[4096]; - va_list args; - int len; - - va_start(args, format); - len = vsnprintf(buf, 4095, format, args); - va_end(args); - - if (len <= 0) { - printf("fluid_ostream_printf: buffer overflow"); - return -1; - } - - buf[4095] = 0; - -/* return write(out, buf, len); */ - return write(out, buf, strlen(buf)); -} diff --git a/fluidsynth/src/fluid_io.h b/fluidsynth/src/fluid_io.h deleted file mode 100644 index 95e1aaff..00000000 --- a/fluidsynth/src/fluid_io.h +++ /dev/null @@ -1,42 +0,0 @@ -/* FluidSynth - A Software Synthesizer - * - * Copyright (C) 2003 Peter Hanappe and others. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307, USA - */ - - -#ifndef _FLUID_IO_H -#define _FLUID_IO_H - - -/** Read a line from the input stream. - - \returns 0 if end-of-stream, -1 if error, non zero otherwise -*/ -int fluid_istream_readline(fluid_istream_t in, char* prompt, char* buf, int len); - - -/** Read a line from the input stream. - - \returns The number of bytes written. If an error occured, -1 is - returned. -*/ -int fluid_ostream_printf(fluid_ostream_t out, char* format, ...); - - - -#endif /* _FLUID_IO_H */ diff --git a/fluidsynth/src/fluid_ladspa.c b/fluidsynth/src/fluid_ladspa.c index 57efa9be..4b88a50a 100644 --- a/fluidsynth/src/fluid_ladspa.c +++ b/fluidsynth/src/fluid_ladspa.c @@ -34,7 +34,6 @@ #include "fluid_ladspa.h" #include "fluid_synth.h" -#include "fluid_io.h" /* Logging to stdout. */ //#define L(x) x;printf("\n"); diff --git a/fluidsynth/src/fluid_midi_router.c b/fluidsynth/src/fluid_midi_router.c index f907f7f7..56f7fec9 100644 --- a/fluidsynth/src/fluid_midi_router.c +++ b/fluidsynth/src/fluid_midi_router.c @@ -24,7 +24,6 @@ #include "fluid_midi_router.h" #include "fluid_midi.h" #include "fluid_synth.h" -#include "fluid_io.h" /** * Create a new midi router. diff --git a/fluidsynth/src/fluid_oss.c b/fluidsynth/src/fluid_oss.c index ea75dc0d..3ba3f23b 100644 --- a/fluidsynth/src/fluid_oss.c +++ b/fluidsynth/src/fluid_oss.c @@ -593,7 +593,13 @@ fluid_oss_audio_run(void* d) while (dev->cont) { dev->read (synth, len, buffer, 0, 2, buffer, 1, 2); - write (dev->dspfd, buffer, dev->buffer_byte_size); + + if (write (dev->dspfd, buffer, dev->buffer_byte_size) < 0) + { + FLUID_LOG(FLUID_ERR, "Error writing to OSS sound device: %s", + g_strerror (errno)); + break; + } } FLUID_LOG(FLUID_DBG, "Audio thread finished"); @@ -629,7 +635,12 @@ fluid_oss_audio_run2(void* d) fluid_synth_dither_s16 (&dither_index, buffer_size, left, right, buffer, 0, 2, buffer, 1, 2); - write (dev->dspfd, buffer, dev->buffer_byte_size); + if (write (dev->dspfd, buffer, dev->buffer_byte_size) < 0) + { + FLUID_LOG(FLUID_ERR, "Error writing to OSS sound device: %s", + g_strerror (errno)); + break; + } } FLUID_LOG(FLUID_DBG, "Audio thread finished"); diff --git a/fluidsynth/src/fluid_sys.c b/fluidsynth/src/fluid_sys.c index 6caa6817..bf73606f 100644 --- a/fluidsynth/src/fluid_sys.c +++ b/fluidsynth/src/fluid_sys.c @@ -18,9 +18,28 @@ * 02111-1307, USA */ - #include "fluid_sys.h" + +#if WITH_READLINE +#include +#include +#endif + + +struct _fluid_server_socket_t +{ + fluid_socket_t socket; + fluid_thread_t *thread; + int cont; + fluid_server_func_t func; + void *data; +}; + + +static int fluid_istream_gets(fluid_istream_t in, char* buf, int len); + + static char fluid_errbuf[512]; /* buffer for error message */ static fluid_log_function_t fluid_log_function[LAST_LOG_LEVEL]; @@ -33,7 +52,6 @@ static char* fluid_libname = "fluidsynth"; void fluid_sys_config() { fluid_log_config(); - fluid_time_config(); } @@ -310,6 +328,34 @@ fluid_is_soundfont(char* filename) return strncmp(id, "RIFF", 4) == 0; } +/** + * Get time in milliseconds to be used in relative timing operations. + * @return Unix time in milliseconds. + */ +unsigned int fluid_curtime(void) +{ + GTimeVal timeval; + + g_get_current_time (&timeval); + + return (timeval.tv_sec * 1000.0 + timeval.tv_usec / 1000.0); +} + +/** + * Get time in microseconds to be used in relative timing operations. + * @return Unix time in microseconds. + */ +double +fluid_utime (void) +{ + GTimeVal timeval; + + g_get_current_time (&timeval); + + return (timeval.tv_sec * 1000000.0 + timeval.tv_usec); +} + + #if defined(WIN32) /*=============================================================*/ @@ -437,205 +483,6 @@ fluid_timer_join(fluid_timer_t* timer) } -/*************************************************************** - * - * Time - */ - -double rdtsc(void); -double fluid_estimate_cpu_frequency(void); - -static double fluid_cpu_frequency = -1.0; - -void fluid_time_config(void) -{ - if (fluid_cpu_frequency < 0.0) { - fluid_cpu_frequency = fluid_estimate_cpu_frequency() / 1000000.0; - } -} - -double fluid_utime(void) -{ - return (rdtsc() / fluid_cpu_frequency); -} - -double rdtsc(void) -{ - LARGE_INTEGER t; - QueryPerformanceCounter(&t); - return (double) t.QuadPart; -} - -double fluid_estimate_cpu_frequency(void) -{ -#if 0 - LONGLONG start, stop, ticks; - unsigned int before, after, delta; - double freq; - - start = rdtsc(); - stop = start; - before = fluid_curtime(); - after = before; - - while (1) { - if (after - before > 1000) { - break; - } - after = fluid_curtime(); - stop = rdtsc(); - } - - delta = after - before; - ticks = stop - start; - - freq = 1000 * ticks / delta; - - return freq; - -#else - unsigned int before, after; - LARGE_INTEGER start, stop; - - before = fluid_curtime(); - QueryPerformanceCounter(&start); - - Sleep(1000); - - after = fluid_curtime(); - QueryPerformanceCounter(&stop); - - return (double) 1000 * (stop.QuadPart - start.QuadPart) / (after - before); -#endif -} - - - -#elif defined(MACOS9) -/*=============================================================*/ -/* */ -/* MacOS 9 */ -/* */ -/*=============================================================*/ - - -/*************************************************************** - * - * Timer - */ - -struct _fluid_timer_t -{ - TMTask myTmTask; - long msec; - unsigned int start; - unsigned int count; - int isInstalled; - fluid_timer_callback_t callback; - void* data; - int auto_destroy; -}; - -static TimerUPP myTimerUPP; - -void -_timerCallback(fluid_timer_t *timer) -{ - int cont; - cont = (*timer->callback)(timer->data, fluid_curtime() - timer->start); - if (cont) { - PrimeTime((QElemPtr)timer, timer->msec); - } else { - timer->isInstalled = 0; - } - timer->count++; -} - -fluid_timer_t* -new_fluid_timer(int msec, fluid_timer_callback_t callback, void* data, - int new_thread, int auto_destroy) -{ - fluid_timer_t* timer = FLUID_NEW(fluid_timer_t); - if (timer == NULL) { - FLUID_LOG(FLUID_ERR, "Out of memory"); - return NULL; - } - - if (!myTimerUPP) - myTimerUPP = NewTimerProc(_timerCallback); - - /* setup tmtask */ - timer->myTmTask.tmAddr = myTimerUPP; - timer->myTmTask.qLink = NULL; - timer->myTmTask.qType = 0; - timer->myTmTask.tmCount = 0L; - timer->myTmTask.tmWakeUp = 0L; - timer->myTmTask.tmReserved = 0L; - - timer->callback = callback; - - timer->msec = msec; - timer->data = data; - timer->start = fluid_curtime(); - timer->isInstalled = 1; - timer->count = 0; - timer->auto_destroy = auto_destroy; - - InsXTime((QElemPtr)timer); - PrimeTime((QElemPtr)timer, msec); - - return timer; -} - -int -delete_fluid_timer(fluid_timer_t* timer) -{ - if (timer->isInstalled) { - RmvTime((QElemPtr)timer); - } - FLUID_FREE(timer); - return FLUID_OK; -} - -int -fluid_timer_join(fluid_timer_t* timer) -{ - if (timer->isInstalled) { - int count = timer->count; - /* wait until count has incremented */ - while (count == timer->count) {} - } - return FLUID_OK; -} - -/*************************************************************** - * - * Time - */ -#define kTwoPower32 (4294967296.0) /* 2^32 */ - -void fluid_time_config(void) -{ -} - -unsigned int fluid_curtime() -{ - /* could be optimized by not going though a double */ - UnsignedWide uS; - double mSf; - unsigned int ms; - - Microseconds(&uS); - - mSf = ((((double) uS.hi) * kTwoPower32) + uS.lo)/1000.0f; - - ms = mSf; - - return (ms); -} - - - #elif defined(__OS2__) /*=============================================================*/ /* */ @@ -759,63 +606,6 @@ fluid_timer_join(fluid_timer_t* timer) return (wait_result == 0)? FLUID_OK : FLUID_FAILED; } - -/*************************************************************** - * - * Time - */ - -double rdtsc(void); -double fluid_estimate_cpu_frequency(void); - -static double fluid_cpu_frequency = -1.0; - -void fluid_time_config(void) -{ - if (fluid_cpu_frequency < 0.0) { - fluid_cpu_frequency = fluid_estimate_cpu_frequency() / 1000000.0; - } -} - -unsigned int fluid_curtime(void) -{ - ULONG ulMS; - DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, &ulMS, sizeof( ULONG )); - return ulMS; -} - -double fluid_utime(void) -{ - return (rdtsc() / fluid_cpu_frequency); -} - -#define Q2ULL( q ) (*(unsigned long long *)&q) - -double rdtsc(void) -{ - QWORD t; - DosTmrQueryTime(&t); - return (double)Q2ULL(t); -} - -double fluid_estimate_cpu_frequency(void) -{ - unsigned int before, after; - QWORD start, stop; - - before = fluid_curtime(); - DosTmrQueryTime(&start); - - DosSleep(1000); - - after = fluid_curtime(); - DosTmrQueryTime(&stop); - - return (double) 1000 * (Q2ULL(stop) - Q2ULL(start)) / (after - before); -} - - - #else /*=============================================================*/ @@ -961,81 +751,6 @@ fluid_timer_join(fluid_timer_t* timer) } -/*************************************************************** - * - * Time - */ - -static double fluid_cpu_frequency = -1.0; - -double rdtsc(void); -double fluid_estimate_cpu_frequency(void); - -void fluid_time_config(void) -{ - if (fluid_cpu_frequency < 0.0) { - fluid_cpu_frequency = fluid_estimate_cpu_frequency() / 1000000.0; - if (fluid_cpu_frequency == 0.0) fluid_cpu_frequency = 1.0; - } -} - -unsigned int fluid_curtime() -{ - struct timeval now; - gettimeofday(&now, NULL); - return now.tv_sec * 1000 + now.tv_usec / 1000; -} - -double fluid_utime(void) -{ - return (rdtsc() / fluid_cpu_frequency); -} - -#if !defined(__i386__) - -double rdtsc(void) -{ - return 0.0; -} - -double fluid_estimate_cpu_frequency(void) -{ - return 1.0; -} - -#else - -double rdtsc(void) -{ - unsigned int a, b; - - __asm__ ("rdtsc" : "=a" (a), "=d" (b)); - return (double)b * (double)0x10000 * (double)0x10000 + a; -} - -double fluid_estimate_cpu_frequency(void) -{ - double start, stop; - unsigned int a0, b0, a1, b1; - unsigned int before, after; - - before = fluid_curtime(); - __asm__ ("rdtsc" : "=a" (a0), "=d" (b0)); - - sleep(1); - - after = fluid_curtime(); - __asm__ ("rdtsc" : "=a" (a1), "=d" (b1)); - - - start = (double)b0 * (double)0x10000 * (double)0x10000 + a0; - stop = (double)b1 * (double)0x10000 * (double)0x10000 + a1; - - return 1000 * (stop - start) / (after - before); -} -#endif - - #ifdef FPE_CHECK /*************************************************************** @@ -1165,61 +880,22 @@ void fluid_profiling_print(void) * */ -#if defined(MACOS9) -/* Not implemented */ -fluid_thread_t* new_fluid_thread(fluid_thread_func_t func, void* data, int detach) { return NULL; } -int delete_fluid_thread(fluid_thread_t* thread) { return 0; } -int fluid_thread_join(fluid_thread_t* thread) { return 0; } -#elif defined(WIN32) - -struct _fluid_thread_t { - HANDLE thread; - DWORD thread_id; - fluid_thread_func_t func; - void* data; - int detached; -}; - -static DWORD WINAPI fluid_thread_start(LPVOID data) +fluid_thread_t * +new_fluid_thread (fluid_thread_func_t func, void *data, int detach) { - fluid_thread_t* thread = (fluid_thread_t*) data; + GThread *thread; + GError *err = NULL; - thread->func(thread->data); + g_return_val_if_fail (func != NULL, NULL); - if (thread->detached) { - FLUID_FREE(thread); - } + thread = g_thread_create ((GThreadFunc)func, data, detach == FALSE, &err); - return 0; -} - - -fluid_thread_t* new_fluid_thread(fluid_thread_func_t func, void* data, int detach) -{ - fluid_thread_t* thread; - - if (func == NULL) { - FLUID_LOG(FLUID_ERR, "Invalid thread function"); - return NULL; - } - - thread = FLUID_NEW(fluid_thread_t); - if (thread == NULL) { - FLUID_LOG(FLUID_ERR, "Out of memory"); - return NULL; - } - - thread->data = data; - thread->func = func; - thread->detached = detach; - - thread->thread = CreateThread(NULL, 0, fluid_thread_start, (LPVOID) thread, - 0, &thread->thread_id); - if (thread->thread == NULL) { - FLUID_LOG(FLUID_ERR, "Couldn't create the thread"); - FLUID_FREE(thread); - return NULL; + if (!thread) + { + FLUID_LOG(FLUID_ERR, "Failed to create the thread: %s", + fluid_gerror_message (err)); + g_clear_error (&err); } return thread; @@ -1227,270 +903,203 @@ fluid_thread_t* new_fluid_thread(fluid_thread_func_t func, void* data, int detac int delete_fluid_thread(fluid_thread_t* thread) { - FLUID_FREE(thread); - return FLUID_OK; -} - - -int fluid_thread_join(fluid_thread_t* thread) -{ - DWORD wait_result; - if (thread->thread == 0) { - return FLUID_OK; - } - wait_result = WaitForSingleObject(thread->thread, INFINITE); - return (wait_result == WAIT_OBJECT_0)? FLUID_OK : FLUID_FAILED; -} - -#elif defined(__OS2__) - -struct _fluid_thread_t { - int thread_id; - fluid_thread_func_t func; - void* data; - int detached; -}; - -static void fluid_thread_start(void *data) -{ - fluid_thread_t* thread = (fluid_thread_t*) data; - - thread->func(thread->data); - - if (thread->detached) { - FLUID_FREE(thread); - } - - return 0; -} - - -fluid_thread_t* new_fluid_thread(fluid_thread_func_t func, void* data, int detach) -{ - fluid_thread_t* thread; - - if (func == NULL) { - FLUID_LOG(FLUID_ERR, "Invalid thread function"); - return NULL; - } - - thread = FLUID_NEW(fluid_thread_t); - if (thread == NULL) { - FLUID_LOG(FLUID_ERR, "Out of memory"); - return NULL; - } - - thread->data = data; - thread->func = func; - thread->detached = detach; - - thread->thread_id = _beginthread(fluid_thread_start, NULL, 256 * 1024, (void *) thread); - if (thread->thread_id == -1) { - FLUID_LOG(FLUID_ERR, "Couldn't create the thread"); - FLUID_FREE(thread); - return NULL; - } - - return thread; -} - -int delete_fluid_thread(fluid_thread_t* thread) -{ - FLUID_FREE(thread); - return FLUID_OK; -} - - -int fluid_thread_join(fluid_thread_t* thread) -{ - ULONG wait_result; - if (thread->thread_id == -1) { - return FLUID_OK; - } - wait_result = DosWaitThread(&thread->thread_id, DCWW_WAIT); - return (wait_result == 0)? FLUID_OK : FLUID_FAILED; -} - -#else - - -struct _fluid_thread_t { - pthread_t pthread; - fluid_thread_func_t func; - void* data; - int detached; -}; - -static void* fluid_thread_start(void *data) -{ - fluid_thread_t* thread = (fluid_thread_t*) data; - - thread->func(thread->data); - - if (thread->detached) { - FLUID_FREE(thread); - } - - return NULL; -} - -fluid_thread_t* new_fluid_thread(fluid_thread_func_t func, void* data, int detach) -{ - fluid_thread_t* thread; - pthread_attr_t attr; - - if (func == NULL) { - FLUID_LOG(FLUID_ERR, "Invalid thread function"); - return NULL; - } - - thread = FLUID_NEW(fluid_thread_t); - if (thread == NULL) { - FLUID_LOG(FLUID_ERR, "Out of memory"); - return NULL; - } - - thread->data = data; - thread->func = func; - thread->detached = detach; - - pthread_attr_init(&attr); - - if (detach) { - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - } - - if (pthread_create(&thread->pthread, &attr, fluid_thread_start, thread)) { - FLUID_LOG(FLUID_ERR, "Failed to create the thread"); - FLUID_FREE(thread); - return NULL; - } - - return thread; -} - -int delete_fluid_thread(fluid_thread_t* thread) -{ - FLUID_FREE(thread); return FLUID_OK; } int fluid_thread_join(fluid_thread_t* thread) { - int err = 0; + g_thread_join (thread); - if (thread->pthread != 0) { - err = pthread_join(thread->pthread, NULL); - } - return (err == 0)? FLUID_OK : FLUID_FAILED; + return FLUID_OK; } -#endif - - /*************************************************************** * - * Sockets + * Sockets and I/O * */ - -#if defined(MACINTOSH) -/* Not implemented */ - - -#elif defined(WIN32) - -#if 0 -typedef unsigned int socklen_t; - -#define fluid_socket_read(_S,_B,_L) recv(_S,_B,_L,0) -#define fluid_socket_write(_S,_B,_L) send(_S,_B,_L,0) - -void fluid_socket_close(fluid_socket_t sock) +fluid_istream_t +fluid_get_stdin (void) { - int r; - char buf[1024]; - if (sock != INVALID_SOCKET) { - shutdown(sock, 0x02); - while (1) { - r = recv(sock, buf, 1024, 0); - if ((r == 0) || (r == SOCKET_ERROR)) { - break; - } - } - closesocket(sock); - } + return STDIN_FILENO; } + +fluid_ostream_t +fluid_get_stdout (void) +{ + return STDOUT_FILENO; +} + +/** + * Read a line from an input stream. + * @return 0 if end-of-stream, -1 if error, non zero otherwise + */ +int +fluid_istream_readline(fluid_istream_t in, char* prompt, char* buf, int len) +{ +#if WITH_READLINE + if (in == fluid_get_stdin ()) + { + char *line; + + line = readline (prompt); + + if (line == NULL) + return -1; + + snprintf(buf, len, "%s", line); + buf[len - 1] = 0; + + free(line); + return 1; + } + else + return fluid_istream_gets(in, buf, len); +#else + return fluid_istream_gets(in, buf, len); +#endif +} + +/** + * Reads a line from an input stream (socket). + * @param in The input socket + * @param buf Buffer to store data to + * @param len Maximum length to store to buf + * @return 1 if a line was read, 0 on end of stream, -1 on error + */ +static int +fluid_istream_gets (fluid_istream_t in, char* buf, int len) +{ + char c; + int n; + + buf[len - 1] = 0; + + while (--len > 0) + { +#ifndef WIN32 + n = read(in, &c, 1); + if (n == -1) return -1; +#else + n = recv (in, &c, 1, 0); + if (n == SOCKET_ERROR) return -1; #endif + if (n == 0) + { + *buf++ = 0; + return 0; + } + if ((c == '\n') || (c == '\r')) + { + *buf++ = 0; + return 1; + } + + *buf++ = c; + } + + return -1; +} + +/** + * Send a printf style string with arguments to an output stream (socket). + * @param out Output stream + * @param format printf style format string + * @param ... Arguments for the printf format string + * @return Number of bytes written or -1 on error + */ +int +fluid_ostream_printf (fluid_ostream_t out, char* format, ...) +{ + char buf[4096]; + va_list args; + int len; + + va_start (args, format); + len = vsnprintf (buf, 4095, format, args); + va_end (args); + + if (len <= 0) + { + printf("fluid_ostream_printf: buffer overflow"); + return -1; + } + + buf[4095] = 0; + +#ifndef WIN32 + return write (out, buf, strlen (buf)); #else -#define fluid_socket_read(_S,_B,_L) read(_S,_B,_L) -#define fluid_socket_write(_S,_B,_L) write(_S,_B,_L) + { + int retval; + + retval = send (out, buf, strlen (buf), 0); + + return retval != SOCKET_ERROR ? retval : -1; + } +#endif +} + +fluid_istream_t fluid_socket_get_istream (fluid_socket_t sock) +{ + return sock; +} + +fluid_ostream_t fluid_socket_get_ostream (fluid_socket_t sock) +{ + return sock; +} + +int fluid_server_socket_join(fluid_server_socket_t *server_socket) +{ + return fluid_thread_join (server_socket->thread); +} + + +#ifndef WIN32 // Not win32? + #define SOCKET_ERROR -1 void fluid_socket_close(fluid_socket_t sock) { - if (sock != INVALID_SOCKET) { - close(sock); - } + if (sock != INVALID_SOCKET) + close (sock); } -#endif - -#if !defined(MACINTOSH) && !defined(WIN32) - - -fluid_istream_t fluid_socket_get_istream(fluid_socket_t sock) +static void +fluid_server_socket_run (void *data) { - return sock; -} - -fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock) -{ - return sock; -} - - - -struct _fluid_server_socket_t { - fluid_socket_t socket; - fluid_thread_t* thread; - int cont; - fluid_server_func_t func; - void* data; -}; - - -static void fluid_server_socket_run(void* data) -{ - fluid_server_socket_t* server_socket = (fluid_server_socket_t*) data; + fluid_server_socket_t *server_socket = (fluid_server_socket_t *)data; fluid_socket_t client_socket; struct sockaddr_in addr; - socklen_t addrlen = sizeof(addr); + socklen_t addrlen = sizeof (addr); + int retval; - FLUID_LOG(FLUID_DBG, "Server listening for connections"); + FLUID_LOG (FLUID_DBG, "Server listening for connections"); - while (server_socket->cont) { + while (server_socket->cont) + { + client_socket = accept (server_socket->socket, (struct sockaddr *)&addr, &addrlen); - client_socket = accept(server_socket->socket, (struct sockaddr*) &addr, &addrlen); + FLUID_LOG (FLUID_DBG, "New client connection"); - FLUID_LOG(FLUID_DBG, "New client connection"); - - if (client_socket == INVALID_SOCKET) { - if (server_socket->cont) { + if (client_socket == INVALID_SOCKET) + { + if (server_socket->cont) FLUID_LOG(FLUID_ERR, "Failed to accept connection"); - } + server_socket->cont = 0; return; } else { - int r; - r = (*server_socket->func)(server_socket->data, client_socket, inet_ntoa(addr.sin_addr)); - if (r != 0) { + retval = server_socket->func (server_socket->data, client_socket, + inet_ntoa (addr.sin_addr)); // FIXME - inet_ntoa is not thread safe + + if (retval != 0) fluid_socket_close(client_socket); - } } } @@ -1504,10 +1113,7 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void* data) struct sockaddr_in addr; fluid_socket_t sock; - if (func == NULL) { - FLUID_LOG(FLUID_ERR, "Invalid callback function"); - return NULL; - } + g_return_val_if_fail (func != NULL, NULL); sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { @@ -1567,9 +1173,170 @@ int delete_fluid_server_socket(fluid_server_socket_t* server_socket) return FLUID_OK; } -int fluid_server_socket_join(fluid_server_socket_t* server_socket) + +#else // Win32 is "special" + + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include +#include + +void fluid_socket_close (fluid_socket_t sock) { - return fluid_thread_join(server_socket->thread); + if (sock != INVALID_SOCKET) + closesocket (sock); +} + +static void fluid_server_socket_run (void *data) +{ + fluid_server_socket_t *server_socket = (fluid_server_socket_t *)data; + fluid_socket_t client_socket; + struct sockaddr_in addr; + socklen_t addrlen = sizeof (addr); + int r; + + FLUID_LOG(FLUID_DBG, "Server listening for connections"); + + while (server_socket->cont) + { + client_socket = accept (server_socket->socket, &addr, &addrlen); + + FLUID_LOG (FLUID_DBG, "New client connection"); + + if (client_socket == INVALID_SOCKET) + { + if (server_socket->cont) + FLUID_LOG (FLUID_ERR, "Failed to accept connection: %ld", WSAGetLastError ()); + + server_socket->cont = 0; + return; + } + else + { + r = server_socket->func (server_socket->data, client_socket, + inet_ntoa (addr.sin_addr)); // FIXME - inet_ntoa is not thread safe + if (r != 0) + fluid_socket_close (client_socket); + } + } + + FLUID_LOG (FLUID_DBG, "Server closing"); +} + +fluid_server_socket_t* +new_fluid_server_socket(int port, fluid_server_func_t func, void* data) +{ + fluid_server_socket_t* server_socket; + struct sockaddr_in addr; + fluid_socket_t sock; + WSADATA wsaData; + struct addrinfo *result = NULL, *ptr = NULL, hints; + int retval; + + g_return_val_if_fail (func != NULL, NULL); + + // Win32 requires initialization of winsock + retval = WSAStartup (MAKEWORD (2,2), &wsaData); + + if (retval != 0) + { + FLUID_LOG(FLUID_ERR, "Server socket creation error: WSAStartup failed: %d", retval); + return NULL; + } + + ZeroMemory (&hints, sizeof (hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_PASSIVE; + + // Resolve the local address and port to be used by the server + retval = getaddrinfo (NULL, port, &hints, &result); // ++ alloc 'result' + + if (retval != 0) + { + FLUID_LOG(FLUID_ERR, "Server socket creation error: getaddrinfo failed: %d", retval); + WSACleanup (); + return NULL; + } + + sock = socket (result->ai_family, result->ai_socktype, result->ai_protocol); + + if (sock == INVALID_SOCKET) + { + FLUID_LOG (FLUID_ERR, "Failed to create server socket: %ld", WSAGetLastError ()); + freeaddrinfo (result); // -- free result + WSACleanup (); + return NULL; + } + + retval = bind (sock, result->ai_addr, (int)result->ai_addrlen); + + if (retval == SOCKET_ERROR) + { + FLUID_LOG (FLUID_ERR, "Failed to bind server socket: %ld", WSAGetLastError ()); + freeaddrinfo (result); // -- free result + fluid_socket_close (sock); + WSACleanup (); + return NULL; + } + + freeaddrinfo (result); // -- free result + + if (listen (sock, SOMAXCONN) == SOCKET_ERROR) + { + FLUID_LOG (FLUID_ERR, "Failed to listen on server socket: %ld", WSAGetLastError ()); + fluid_socket_close (sock); + WSACleanup (); + return NULL; + } + + server_socket = FLUID_NEW (fluid_server_socket_t); + + if (server_socket == NULL) + { + FLUID_LOG (FLUID_ERR, "Out of memory"); + fluid_socket_close (sock); + WSACleanup (); + return NULL; + } + + server_socket->socket = sock; + server_socket->func = func; + server_socket->data = data; + server_socket->cont = 1; + + server_socket->thread = new_fluid_thread (fluid_server_socket_run, server_socket, FALSE); + + if (server_socket->thread == NULL) + { + FLUID_FREE (server_socket); + fluid_socket_close (sock); + WSACleanup (); + return NULL; + } + + return server_socket; +} + +int delete_fluid_server_socket(fluid_server_socket_t *server_socket) +{ + server_socket->cont = 0; + + if (server_socket->socket != INVALID_SOCKET) + fluid_socket_close (server_socket->socket); + + if (server_socket->thread) + delete_fluid_thread (server_socket->thread); + + FLUID_FREE (server_socket); + + WSACleanup (); // Should be called the same number of times as WSAStartup + + return FLUID_OK; } #endif diff --git a/fluidsynth/src/fluid_sys.h b/fluidsynth/src/fluid_sys.h index 24497051..c0eafb62 100644 --- a/fluidsynth/src/fluid_sys.h +++ b/fluidsynth/src/fluid_sys.h @@ -36,9 +36,19 @@ #ifndef _FLUID_SYS_H #define _FLUID_SYS_H +#include #include "fluidsynth_priv.h" +/** + * Macro used for safely accessing a message from a GError and using a default + * message if it is NULL. + * @param err Pointer to a GError to access the message field of. + * @return Message string + */ +#define fluid_gerror_message(err) ((err) ? err->message : "No error details") + + void fluid_sys_config(void); void fluid_log_config(void); void fluid_time_config(void); @@ -72,40 +82,15 @@ int fluid_debug(int level, char * fmt, ...); #endif -/** fluid_curtime() returns the current time in milliseconds. This time - should only be used in relative time measurements. */ - -/** fluid_utime() returns the time in micro seconds. this time should - only be used to measure duration (relative times). */ - -#if defined(WIN32) -#define fluid_curtime() GetTickCount() - -double fluid_utime(void); - -#elif defined(MACOS9) -#include -#include - -unsigned int fluid_curtime(); -#define fluid_utime() 0.0 - -#elif defined(__OS2__) +#if defined(__OS2__) #define INCL_DOS #include typedef int socklen_t; - -unsigned int fluid_curtime(void); -double fluid_utime(void); - -#else - -unsigned int fluid_curtime(void); -double fluid_utime(void); - #endif +unsigned int fluid_curtime(void); +double fluid_utime(void); /** @@ -120,7 +105,7 @@ typedef int (*fluid_timer_callback_t)(void* data, unsigned int msec); typedef struct _fluid_timer_t fluid_timer_t; fluid_timer_t* new_fluid_timer(int msec, fluid_timer_callback_t callback, - void* data, int new_thread, int auto_destroy); + void* data, int new_thread, int auto_destroy); int delete_fluid_timer(fluid_timer_t* timer); int fluid_timer_join(fluid_timer_t* timer); @@ -132,34 +117,11 @@ int fluid_timer_stop(fluid_timer_t* timer); */ -#if defined(MACOS9) -typedef int fluid_mutex_t; -#define fluid_mutex_init(_m) { (_m) = 0; } -#define fluid_mutex_destroy(_m) -#define fluid_mutex_lock(_m) -#define fluid_mutex_unlock(_m) - -#elif defined(WIN32) -typedef HANDLE fluid_mutex_t; -#define fluid_mutex_init(_m) { (_m) = CreateMutex(NULL, 0, NULL); } -#define fluid_mutex_destroy(_m) if (_m) { CloseHandle(_m); } -#define fluid_mutex_lock(_m) WaitForSingleObject(_m, INFINITE) -#define fluid_mutex_unlock(_m) ReleaseMutex(_m) - -#elif defined(__OS2__) -typedef HMTX fluid_mutex_t; -#define fluid_mutex_init(_m) { (_m) = 0; DosCreateMutexSem( NULL, &(_m), 0, FALSE ); } -#define fluid_mutex_destroy(_m) if (_m) { DosCloseMutexSem(_m); } -#define fluid_mutex_lock(_m) DosRequestMutexSem(_m, -1L) -#define fluid_mutex_unlock(_m) DosReleaseMutexSem(_m) - -#else -typedef pthread_mutex_t fluid_mutex_t; -#define fluid_mutex_init(_m) pthread_mutex_init(&(_m), NULL) -#define fluid_mutex_destroy(_m) pthread_mutex_destroy(&(_m)) -#define fluid_mutex_lock(_m) pthread_mutex_lock(&(_m)) -#define fluid_mutex_unlock(_m) pthread_mutex_unlock(&(_m)) -#endif +typedef GStaticMutex fluid_mutex_t; +#define fluid_mutex_init(_m) g_static_mutex_init(&(_m)) +#define fluid_mutex_destroy(_m) g_static_mutex_free(&(_m)) +#define fluid_mutex_lock(_m) g_static_mutex_lock(&(_m)) +#define fluid_mutex_unlock(_m) g_static_mutex_unlock(&(_m)) /** @@ -167,7 +129,7 @@ typedef pthread_mutex_t fluid_mutex_t; */ -typedef struct _fluid_thread_t fluid_thread_t; +typedef GThread fluid_thread_t; typedef void (*fluid_thread_func_t)(void* data); /** When detached, 'join' does not work and the thread destroys itself @@ -176,32 +138,24 @@ fluid_thread_t* new_fluid_thread(fluid_thread_func_t func, void* data, int detac int delete_fluid_thread(fluid_thread_t* thread); int fluid_thread_join(fluid_thread_t* thread); - /** - Sockets + Sockets and I/O */ +fluid_istream_t fluid_get_stdin (void); +fluid_ostream_t fluid_get_stdout (void); +int fluid_istream_readline(fluid_istream_t in, char* prompt, char* buf, int len); +int fluid_ostream_printf (fluid_ostream_t out, char* format, ...); /** 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. */ typedef int (*fluid_server_func_t)(void* data, fluid_socket_t client_socket, char* addr); - fluid_server_socket_t* new_fluid_server_socket(int port, fluid_server_func_t func, void* data); int delete_fluid_server_socket(fluid_server_socket_t* sock); int fluid_server_socket_join(fluid_server_socket_t* sock); - - -/** Create a new client socket. */ -fluid_socket_t new_fluid_client_socket(char* host, int port); - -/** Delete the client socket. This function should only be called on - sockets create with 'new_fluid_client_socket'. */ -void delete_fluid_client_socket(fluid_socket_t sock); - - void fluid_socket_close(fluid_socket_t sock); fluid_istream_t fluid_socket_get_istream(fluid_socket_t sock); fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock); diff --git a/fluidsynth/src/fluidsynth.c b/fluidsynth/src/fluidsynth.c index ad0d06bb..e9ada1c5 100644 --- a/fluidsynth/src/fluidsynth.c +++ b/fluidsynth/src/fluidsynth.c @@ -447,6 +447,8 @@ int main(int argc, char** argv) exit (0); } + g_thread_init (NULL); + #ifdef WIN32 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); #endif diff --git a/fluidsynth/src/fluidsynth_priv.h b/fluidsynth/src/fluidsynth_priv.h index 41b6c8da..9f30559d 100644 --- a/fluidsynth/src/fluidsynth_priv.h +++ b/fluidsynth/src/fluidsynth_priv.h @@ -22,6 +22,8 @@ #ifndef _FLUIDSYNTH_PRIV_H #define _FLUIDSYNTH_PRIV_H +#include + #if HAVE_CONFIG_H #include "config.h" #endif @@ -168,57 +170,14 @@ typedef int fluid_socket_t; /** Integer types */ - -#if defined(MINGW32) - -/* Windows using MinGW32 */ -typedef int8_t sint8; -typedef uint8_t uint8; -typedef int16_t sint16; -typedef uint16_t uint16; -typedef int32_t sint32; -typedef uint32_t uint32; -typedef int64_t sint64; -typedef uint64_t uint64; - -#elif defined(_WIN32) - -/* Windows */ -typedef signed __int8 sint8; -typedef unsigned __int8 uint8; -typedef signed __int16 sint16; -typedef unsigned __int16 uint16; -typedef signed __int32 sint32; -typedef unsigned __int32 uint32; -typedef signed __int64 sint64; -typedef unsigned __int64 uint64; - -#elif defined(MACOS9) - -/* Macintosh */ -typedef signed char sint8; -typedef unsigned char uint8; -typedef signed short sint16; -typedef unsigned short uint16; -typedef signed int sint32; -typedef unsigned int uint32; -/* FIXME: needs to be verified */ -typedef long long sint64; -typedef unsigned long long uint64; - -#else - -/* Linux & Darwin */ -typedef int8_t sint8; -typedef u_int8_t uint8; -typedef int16_t sint16; -typedef u_int16_t uint16; -typedef int32_t sint32; -typedef u_int32_t uint32; -typedef int64_t sint64; -typedef u_int64_t uint64; - -#endif +typedef gint8 sint8; +typedef guint8 uint8; +typedef gint16 sint16; +typedef guint16 uint16; +typedef gint32 sint32; +typedef guint32 uint32; +typedef gint64 sint64; +typedef guint64 uint64; /***************************************************************