From da1e23ca66e2dfd501ef04bd5c9e811df26f5bd9 Mon Sep 17 00:00:00 2001 From: loki666 Date: Fri, 27 Oct 2017 20:30:52 +0200 Subject: [PATCH 01/34] initial changes for android (remove glib dep) --- android/.gitignore | 2 + android/Android.mk | 9 + android/jni/Android.mk | 63 ++ android/jni/Application.mk | 5 + android/jni/config.h | 212 ++++ android/jni/include/fluidsynth/version.h | 47 + android/jni/src/bindings/fluid_cmd.c | 8 + src/utils/fluid_atomic.h | 69 ++ src/utils/fluid_sys.c | 1245 ++++++++-------------- src/utils/fluid_sys.h | 248 ++--- src/utils/fluidsynth_priv.h | 72 +- 11 files changed, 929 insertions(+), 1051 deletions(-) create mode 100644 android/.gitignore create mode 100644 android/Android.mk create mode 100644 android/jni/Android.mk create mode 100644 android/jni/Application.mk create mode 100644 android/jni/config.h create mode 100644 android/jni/include/fluidsynth/version.h create mode 100644 android/jni/src/bindings/fluid_cmd.c create mode 100644 src/utils/fluid_atomic.h diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 000000000..e0c35b993 --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,2 @@ +obj/ +libs/ diff --git a/android/Android.mk b/android/Android.mk new file mode 100644 index 000000000..3ed58799e --- /dev/null +++ b/android/Android.mk @@ -0,0 +1,9 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := fluidsynth_shared +LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libfluidsynth.so +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/jni/include +TARGET_PLATFORM = android-14 + +include $(PREBUILT_SHARED_LIBRARY) diff --git a/android/jni/Android.mk b/android/jni/Android.mk new file mode 100644 index 000000000..c57a99246 --- /dev/null +++ b/android/jni/Android.mk @@ -0,0 +1,63 @@ +LOCAL_PATH := $(call my-dir)/../.. +include $(CLEAR_VARS) + +LOCAL_MODULE := fluidsynth + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/android/jni \ + $(LOCAL_PATH)/android/jni/include \ + $(LOCAL_PATH)/include \ + $(LOCAL_PATH)/src/synth \ + $(LOCAL_PATH)/src/midi \ + $(LOCAL_PATH)/src/rvoice \ + $(LOCAL_PATH)/src/sfloader \ + $(LOCAL_PATH)/src/utils \ + $(LOCAL_PATH)/src/bindings \ + $(LOCAL_PATH)/src/drivers + +LOCAL_ARM_MODE := arm +LOCAL_CFLAGS += -DHAVE_CONFIG_H -Wall -Werror -std=gnu11 -Wno-unused-variable + +ifeq ($(TARGET_ARCH_ABI), armeabi-v7a) + LOCAL_CFLAGS += -DWITH_FLOAT +endif +ifeq ($(TARGET_ARCH_ABI), x86) + LOCAL_CFLAGS += -DWITH_FLOAT +endif + +LOCAL_SRC_FILES := \ + src/midi/fluid_midi.c \ + src/midi/fluid_midi_router.c \ + src/midi/fluid_seq.c \ + src/midi/fluid_seqbind.c \ + src/rvoice/fluid_adsr_env.c \ + src/rvoice/fluid_chorus.c \ + src/rvoice/fluid_iir_filter.c \ + src/rvoice/fluid_lfo.c \ + src/rvoice/fluid_rev.c \ + src/rvoice/fluid_rvoice.c \ + src/rvoice/fluid_rvoice_dsp.c \ + src/rvoice/fluid_rvoice_event.c \ + src/rvoice/fluid_rvoice_mixer.c \ + src/sfloader/fluid_defsfont.c \ + src/sfloader/fluid_ramsfont.c \ + src/synth/fluid_chan.c \ + src/synth/fluid_event.c \ + src/synth/fluid_gen.c \ + src/synth/fluid_mod.c \ + src/synth/fluid_synth.c \ + src/synth/fluid_tuning.c \ + src/synth/fluid_voice.c \ + src/utils/fluid_conv.c \ + src/utils/fluid_hash.c \ + src/utils/fluid_list.c \ + src/utils/fluid_ringbuffer.c \ + src/utils/fluid_settings.c \ + src/bindings/fluid_filerenderer.c \ + src/drivers/fluid_adriver.c \ + src/drivers/fluid_mdriver.c \ + src/utils/fluid_sys.c \ + android/jni/src/bindings/fluid_cmd.c + +include $(BUILD_SHARED_LIBRARY) + diff --git a/android/jni/Application.mk b/android/jni/Application.mk new file mode 100644 index 000000000..485a8ac52 --- /dev/null +++ b/android/jni/Application.mk @@ -0,0 +1,5 @@ +APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 +APP_MODULES := fluidsynth +APP_PLATFORM := android-14 +APP_OPTIM := release +NDK_TOOLCHAIN_VERSION := clang diff --git a/android/jni/config.h b/android/jni/config.h new file mode 100644 index 000000000..fe8883e88 --- /dev/null +++ b/android/jni/config.h @@ -0,0 +1,212 @@ +#ifndef CONFIG_H +#define CONFIG_H + +/* Define to enable ALSA driver */ +/* #undef ALSA_SUPPORT */ + +/* Define to activate sound output to files */ +/* #undef AUFILE_SUPPORT */ + +/* whether or not we are supporting CoreAudio */ +/* #undef COREAUDIO_SUPPORT */ + +/* whether or not we are supporting CoreMIDI */ +/* #undef COREMIDI_SUPPORT */ + +/* whether or not we are supporting DART */ +/* #undef DART_SUPPORT */ + +/* Define if building for Mac OS X Darwin */ +/* #undef DARWIN */ + +/* Define if D-Bus support is enabled */ +/* #undef DBUS_SUPPORT */ + +/* Define to enable FPE checks */ +/* #undef FPE_CHECK */ + +/* Define to 1 if you have the header file. */ +/*#undef HAVE_ARPA_INET_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* whether or not we are supporting ladcca */ +/* #undef HAVE_LADCCA */ + +/* whether or not we are supporting lash */ +/* #undef HAVE_LASH */ + +/* Define to 1 if you have the `dl' library (-ldl). */ +/* #undef HAVE_LIBDL */ + +/* Define to 1 if you have the `MidiShare' library (-lMidiShare). */ +/* #undef HAVE_LIBMIDISHARE */ + +/* Define to 1 if you have the `pthread' library (-lpthread). */ +#define HAVE_LIBPTHREAD TRUE + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_MACHINE_SOUNDCARD_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MATH_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_MIDISHARE_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_PTHREAD_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDARG_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_MMAN_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SOUNDCARD_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_WINDOWS_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_GETOPT_H 1 + +/* Define to enable JACK driver */ +/* #undef JACK_SUPPORT */ + +/* Include the LADSPA Fx unit */ +/* #undef LADSPA */ + +/* libsndfile has ogg vorbis support */ +/* #undef LIBSNDFILE_HASVORBIS */ + +/* Define to enable libsndfile support */ +/* #undef LIBSNDFILE_SUPPORT */ + +/* Define to enable MidiShare driver */ +/* #undef MIDISHARE_SUPPORT */ + +/* Define if using the MinGW32 environment */ +/* #undef MINGW32 */ + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +/* #undef NO_MINUS_C_MINUS_O */ + +/* Define to enable OSS driver */ +/* #undef OSS_SUPPORT */ + +/* Name of package */ +#define PACKAGE "fluidsynth" + +/* Define to the address where bug reports for this package should be sent. */ +/* #undef PACKAGE_BUGREPORT */ + +/* Define to the full name of this package. */ +/* #undef PACKAGE_NAME */ + +/* Define to the full name and version of this package. */ +/* #undef PACKAGE_STRING */ + +/* Define to the one symbol short name of this package. */ +/* #undef PACKAGE_TARNAME */ + +/* Define to the version of this package. */ +/* #undef PACKAGE_VERSION */ + +/* Define to enable PortAudio driver */ +/* #undef PORTAUDIO_SUPPORT */ + +/* Define to enable PulseAudio driver */ +/* #undef PULSE_SUPPORT */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to enable SIGFPE assertions */ +/* #undef TRAP_ON_FPE */ + +/* Version number of package */ +#define VERSION "1.1.8" + +/* Define to do all DSP in single floating point precision */ +/* #undef WITH_FLOAT */ + +/* Define to profile the DSP code */ +/* #undef WITH_PROFILING */ + +/* Define to use the readline library for line editing */ +/* #undef WITH_READLINE */ + +/* Define if the compiler supports VLA */ +#define SUPPORTS_VLA + +/* 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 to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +#endif /* CONFIG_H */ diff --git a/android/jni/include/fluidsynth/version.h b/android/jni/include/fluidsynth/version.h new file mode 100644 index 000000000..7031c1026 --- /dev/null +++ b/android/jni/include/fluidsynth/version.h @@ -0,0 +1,47 @@ +/* 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 + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA + */ + +#ifndef _FLUIDSYNTH_VERSION_H +#define _FLUIDSYNTH_VERSION_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file version.h + * @brief Library version functions and defines + */ + +#define FLUIDSYNTH_VERSION "1.1.8" /**< String constant of libfluidsynth version. */ +#define FLUIDSYNTH_VERSION_MAJOR 1 /**< libfluidsynth major version integer constant. */ +#define FLUIDSYNTH_VERSION_MINOR 1 /**< libfluidsynth minor version integer constant. */ +#define FLUIDSYNTH_VERSION_MICRO 8 /**< libfluidsynth micro version integer constant. */ + +FLUIDSYNTH_API void fluid_version(int *major, int *minor, int *micro); +FLUIDSYNTH_API char* fluid_version_str(void); + + +#ifdef __cplusplus +} +#endif + +#endif /* _FLUIDSYNTH_VERSION_H */ diff --git a/android/jni/src/bindings/fluid_cmd.c b/android/jni/src/bindings/fluid_cmd.c new file mode 100644 index 000000000..280ce98af --- /dev/null +++ b/android/jni/src/bindings/fluid_cmd.c @@ -0,0 +1,8 @@ +#include "fluid_synth.h" +#include "fluid_settings.h" + +void fluid_shell_settings(fluid_settings_t* settings) +{ + // NOOP +} + \ No newline at end of file diff --git a/src/utils/fluid_atomic.h b/src/utils/fluid_atomic.h new file mode 100644 index 000000000..c5bb397f0 --- /dev/null +++ b/src/utils/fluid_atomic.h @@ -0,0 +1,69 @@ + +#ifndef _FLUID_ATOMIC_H +#define _FLUID_ATOMIC_H + +#include + +#ifndef STATIC_ASSERT +#if __STDC_VERSION__ >= 201112L +#define STATIC_ASSERT _Static_assert +#else +#define STATIC_ASSERT(expr, msg) typedef char __static_assertion_ ## __COUNTER__[(expr) ? 1 : -1] +#endif +#endif //STATIC_ASSERT + +#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 + +#define fluid_atomic_int_add(atomic, val) __extension__ ({ \ + STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ + "Atomic must be the size of an int"); \ + __sync_fetch_and_add(&(atomic)->value, (val));}) + +#define fluid_atomic_int_get(atomic) __extension__ ({ \ + STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ + "Atomic must be the size of an int"); \ + __sync_synchronize(); \ + (atomic)->value;}) + +#define fluid_atomic_int_set(atomic, newval) __extension__ ({ \ + STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ + "Atomic must be the size of an int"); \ + (atomic)->value = (newval); \ + __sync_synchronize();}) + +#define fluid_atomic_int_inc(atomic) __extension__ ({ \ + STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ + "Atomic must be the size of an int"); \ + __sync_synchronize(); \ + __sync_fetch_and_add(&(atomic)->value, 1);}) + +#define fluid_atomic_int_compare_and_exchange(atomic, oldval, newval) __extension__ ({ \ + STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ + "Atomic must be the size of an int"); \ + __sync_bool_compare_and_swap(&(atomic)->value, (oldval), (newval));}) + +#define fluid_atomic_int_exchange_and_add(atomic, add) __extension__ ({ \ + STATIC_ASSERT(sizeof((atomic)->value) == sizeof(int), \ + "Atomic must be the size of an int"); \ + __sync_synchronize(); \ + __sync_fetch_and_add(&(atomic)->value, add);}) + +#define fluid_atomic_float_get(atomic) __extension__ ({ \ + STATIC_ASSERT(sizeof((atomic)->value) == sizeof(float), \ + "Atomic must be the size of a float"); \ + __sync_synchronize(); \ + (atomic)->value;}) + +#define fluid_atomic_float_set(atomic, val) __extension__ ({ \ + STATIC_ASSERT(sizeof((atomic)->value) == sizeof(float), \ + "Atomic must be the size of a float"); \ + (atomic)->value = (val); \ + __sync_synchronize();}) + +#else + +#error "GCC builtins missings for atomic operations" + +#endif + +#endif /* _FLUID_ATOMIC_H */ diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c index f308de2bf..223c388c3 100644 --- a/src/utils/fluid_sys.c +++ b/src/utils/fluid_sys.c @@ -3,36 +3,26 @@ * 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 Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of + * 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 - * Lesser General Public License for more details. + * Library General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA */ -#include "fluid_sys.h" - - -#if WITH_READLINE -#include -#include -#endif - -#ifdef DBUS_SUPPORT -#include "fluid_rtkit.h" +#ifdef _WIN32 +#include #endif -/* WIN32 HACK - Flag used to differentiate between a file descriptor and a socket. - * Should work, so long as no SOCKET or file descriptor ends up with this bit set. - JG */ -#define WIN32_SOCKET_FLAG 0x40000000 +#include "fluid_sys.h" /* SCHED_FIFO priority for high priority timer threads */ #define FLUID_SYS_TIMER_HIGH_PRIO_LEVEL 10 @@ -40,28 +30,19 @@ typedef struct { - fluid_thread_func_t func; - void *data; - int prio_level; + fluid_thread_func_t func; + void *data; + int prio_level; } fluid_thread_info_t; struct _fluid_timer_t { - long msec; - fluid_timer_callback_t callback; - void *data; - fluid_thread_t *thread; - int cont; - int auto_destroy; -}; - -struct _fluid_server_socket_t -{ - fluid_socket_t socket; - fluid_thread_t *thread; - int cont; - fluid_server_func_t func; - void *data; + long msec; + fluid_timer_callback_t callback; + void *data; + fluid_thread_t *thread; + int cont; + int auto_destroy; }; @@ -79,10 +60,35 @@ static const char fluid_libname[] = "fluidsynth"; void fluid_sys_config() { - fluid_log_config(); + fluid_log_config(); } +unsigned int fluid_debug_flags = 0; + +#if DEBUG +/* + * fluid_debug + */ +int fluid_debug(int level, char * fmt, ...) +{ + if (fluid_debug_flags & level) { + fluid_log_function_t fun; + va_list args; + + va_start (args, fmt); + vsnprintf(fluid_errbuf, sizeof (fluid_errbuf), fmt, args); + va_end (args); + + fun = fluid_log_function[FLUID_DBG]; + if (fun != NULL) { + (*fun)(level, fluid_errbuf, fluid_log_user_data[FLUID_DBG]); + } + } + return 0; +} +#endif + /** * Installs a new log function for a specified log level. * @param level Log level to install handler for. @@ -93,14 +99,14 @@ void fluid_sys_config() fluid_log_function_t fluid_set_log_function(int level, fluid_log_function_t fun, void* data) { - fluid_log_function_t old = NULL; - - if ((level >= 0) && (level < LAST_LOG_LEVEL)) { - old = fluid_log_function[level]; - fluid_log_function[level] = fun; - fluid_log_user_data[level] = data; - } - return old; + fluid_log_function_t old = NULL; + + if ((level >= 0) && (level < LAST_LOG_LEVEL)) { + old = fluid_log_function[level]; + fluid_log_function[level] = fun; + fluid_log_user_data[level] = data; + } + return old; } /** @@ -112,41 +118,41 @@ fluid_set_log_function(int level, fluid_log_function_t fun, void* data) void fluid_default_log_function(int level, char* message, void* data) { - FILE* out; + FILE* out; #if defined(WIN32) - out = stdout; + out = stdout; #else - out = stderr; + out = stderr; #endif - if (fluid_log_initialized == 0) { - fluid_log_config(); - } - - switch (level) { - case FLUID_PANIC: - FLUID_FPRINTF(out, "%s: panic: %s\n", fluid_libname, message); - break; - case FLUID_ERR: - FLUID_FPRINTF(out, "%s: error: %s\n", fluid_libname, message); - break; - case FLUID_WARN: - FLUID_FPRINTF(out, "%s: warning: %s\n", fluid_libname, message); - break; - case FLUID_INFO: - FLUID_FPRINTF(out, "%s: %s\n", fluid_libname, message); - break; - case FLUID_DBG: + if (fluid_log_initialized == 0) { + fluid_log_config(); + } + + switch (level) { + case FLUID_PANIC: + FLUID_FPRINTF(out, "%s: panic: %s\n", fluid_libname, message); + break; + case FLUID_ERR: + FLUID_FPRINTF(out, "%s: error: %s\n", fluid_libname, message); + break; + case FLUID_WARN: + FLUID_FPRINTF(out, "%s: warning: %s\n", fluid_libname, message); + break; + case FLUID_INFO: + FLUID_FPRINTF(out, "%s: %s\n", fluid_libname, message); + break; + case FLUID_DBG: #if DEBUG - FLUID_FPRINTF(out, "%s: debug: %s\n", fluid_libname, message); + FLUID_FPRINTF(out, "%s: debug: %s\n", fluid_libname, message); #endif - break; - default: - FLUID_FPRINTF(out, "%s: %s\n", fluid_libname, message); - break; - } - fflush(out); + break; + default: + FLUID_FPRINTF(out, "%s: %s\n", fluid_libname, message); + break; + } + fflush(out); } /* @@ -155,30 +161,30 @@ fluid_default_log_function(int level, char* message, void* data) void fluid_log_config(void) { - if (fluid_log_initialized == 0) { + if (fluid_log_initialized == 0) { - fluid_log_initialized = 1; + fluid_log_initialized = 1; - if (fluid_log_function[FLUID_PANIC] == NULL) { - fluid_set_log_function(FLUID_PANIC, fluid_default_log_function, NULL); - } + if (fluid_log_function[FLUID_PANIC] == NULL) { + fluid_set_log_function(FLUID_PANIC, fluid_default_log_function, NULL); + } - if (fluid_log_function[FLUID_ERR] == NULL) { - fluid_set_log_function(FLUID_ERR, fluid_default_log_function, NULL); - } + if (fluid_log_function[FLUID_ERR] == NULL) { + fluid_set_log_function(FLUID_ERR, fluid_default_log_function, NULL); + } - if (fluid_log_function[FLUID_WARN] == NULL) { - fluid_set_log_function(FLUID_WARN, fluid_default_log_function, NULL); - } + if (fluid_log_function[FLUID_WARN] == NULL) { + fluid_set_log_function(FLUID_WARN, fluid_default_log_function, NULL); + } - if (fluid_log_function[FLUID_INFO] == NULL) { - fluid_set_log_function(FLUID_INFO, fluid_default_log_function, NULL); - } + if (fluid_log_function[FLUID_INFO] == NULL) { + fluid_set_log_function(FLUID_INFO, fluid_default_log_function, NULL); + } - if (fluid_log_function[FLUID_DBG] == NULL) { - fluid_set_log_function(FLUID_DBG, fluid_default_log_function, NULL); + if (fluid_log_function[FLUID_DBG] == NULL) { + fluid_set_log_function(FLUID_DBG, fluid_default_log_function, NULL); + } } - } } /** @@ -191,20 +197,20 @@ fluid_log_config(void) int fluid_log(int level, const char* fmt, ...) { - fluid_log_function_t fun = NULL; + fluid_log_function_t fun = NULL; - va_list args; - va_start (args, fmt); - FLUID_VSNPRINTF (fluid_errbuf, sizeof (fluid_errbuf), fmt, args); - va_end (args); + va_list args; + va_start (args, fmt); + vsnprintf(fluid_errbuf, sizeof (fluid_errbuf), fmt, args); + va_end (args); - if ((level >= 0) && (level < LAST_LOG_LEVEL)) { - fun = fluid_log_function[level]; - if (fun != NULL) { - (*fun)(level, fluid_errbuf, fluid_log_user_data[level]); + if ((level >= 0) && (level < LAST_LOG_LEVEL)) { + fun = fluid_log_function[level]; + if (fun != NULL) { + (*fun)(level, fluid_errbuf, fluid_log_user_data[level]); + } } - } - return FLUID_FAILED; + return FLUID_FAILED; } /** @@ -222,59 +228,51 @@ fluid_log(int level, const char* fmt, ...) */ char *fluid_strtok (char **str, char *delim) { - char *s, *d, *token; - char c; - - if (str == NULL || delim == NULL || !*delim) - { - FLUID_LOG(FLUID_ERR, "Null pointer"); - return NULL; - } - - s = *str; - if (!s) return NULL; /* str points to a NULL pointer? (tokenize already ended) */ - - /* skip delimiter chars at beginning of token */ - do - { - c = *s; - if (!c) /* end of source string? */ - { - *str = NULL; - return NULL; - } + char *s, *d, *token; + char c; - for (d = delim; *d; d++) /* is source char a token char? */ - { - if (c == *d) /* token char match? */ - { - s++; /* advance to next source char */ - break; - } + if (str == NULL || delim == NULL || !*delim) { + FLUID_LOG(FLUID_ERR, "Null pointer"); + return NULL; } - } while (*d); /* while token char match */ - - token = s; /* start of token found */ - - /* search for next token char or end of source string */ - for (s = s+1; *s; s++) - { - c = *s; - for (d = delim; *d; d++) /* is source char a token char? */ - { - if (c == *d) /* token char match? */ - { - *s = '\0'; /* overwrite token char with zero byte to terminate token */ - *str = s+1; /* update str to point to beginning of next token */ - return token; - } + s = *str; + if (!s) return NULL; /* str points to a NULL pointer? (tokenize already ended) */ + + /* skip delimiter chars at beginning of token */ + do { + c = *s; + if (!c) { /* end of source string? */ + *str = NULL; + return NULL; + } + + for (d = delim; *d; d++) { /* is source char a token char? */ + if (c == *d) { /* token char match? */ + s++; /* advance to next source char */ + break; + } + } + } while (*d); /* while token char match */ + + token = s; /* start of token found */ + + /* search for next token char or end of source string */ + for (s = s+1; *s; s++) { + c = *s; + + for (d = delim; *d; d++) { /* is source char a token char? */ + if (c == *d) { /* token char match? */ + *s = '\0'; /* overwrite token char with zero byte to terminate token */ + *str = s+1; /* update str to point to beginning of next token */ + return token; + } + } } - } - /* we get here only if source string ended */ - *str = NULL; - return token; + /* we get here only if source string ended */ + *str = NULL; + return token; } /* @@ -283,7 +281,7 @@ char *fluid_strtok (char **str, char *delim) char* fluid_error() { - return fluid_errbuf; + return fluid_errbuf; } /** @@ -297,19 +295,19 @@ fluid_error() int fluid_is_midifile(const char *filename) { - FILE* fp = fopen(filename, "rb"); - char id[4]; + FILE* fp = fopen(filename, "rb"); + char id[4]; - if (fp == NULL) { - return 0; - } - if (fread((void*) id, 1, 4, fp) != 4) { + if (fp == NULL) { + return 0; + } + if (fread((void*) id, 1, 4, fp) != 4) { + fclose(fp); + return 0; + } fclose(fp); - return 0; - } - fclose(fp); - return strncmp(id, "MThd", 4) == 0; + return strncmp(id, "MThd", 4) == 0; } /** @@ -323,19 +321,19 @@ fluid_is_midifile(const char *filename) int fluid_is_soundfont(const char *filename) { - FILE* fp = fopen(filename, "rb"); - char id[4]; + FILE* fp = fopen(filename, "rb"); + char id[4]; - if (fp == NULL) { - return 0; - } - if (fread((void*) id, 1, 4, fp) != 4) { + if (fp == NULL) { + return 0; + } + if (fread((void*) id, 1, 4, fp) != 4) { + fclose(fp); + return 0; + } fclose(fp); - return 0; - } - fclose(fp); - return strncmp(id, "RIFF", 4) == 0; + return strncmp(id, "RIFF", 4) == 0; } /** @@ -344,17 +342,41 @@ fluid_is_soundfont(const char *filename) */ unsigned int fluid_curtime(void) { - static glong initial_seconds = 0; - GTimeVal timeval; + static long initial_seconds = 0; +#ifdef _WIN32 + UINT64 time; + FILETIME ft; + + if (initial_seconds == 0) { + GetSystemTimeAsFileTime(&ft); + time = ft.dwHighDateTime; + time <<= 32ULL; + time |= ft.dwLowDateTime; + time /= 10000000; // time is 100ns, convert to seconds + time -= 11644473600LL; // Seconds between Windows epoch (1601/01/01) and Unix + initial_seconds = time; + } + + GetSystemTimeAsFileTime(&ft); + time = ft.dwHighDateTime; + time <<= 32ULL; + time |= ft.dwLowDateTime; + time /= 10000; // time is 100ns, convert to ms + time -= 11644473600000LL; // Milliseconds between Windows epoch (1601/01/01) and Unix + + return time - initial_seconds * 1000; +#else + struct timespec timeval; - if (initial_seconds == 0) { - g_get_current_time (&timeval); - initial_seconds = timeval.tv_sec; - } + if (initial_seconds == 0) { + clock_gettime(CLOCK_REALTIME, &timeval); + initial_seconds = timeval.tv_sec; + } - g_get_current_time (&timeval); + clock_gettime(CLOCK_REALTIME, &timeval); - return (unsigned int)((timeval.tv_sec - initial_seconds) * 1000.0 + timeval.tv_usec / 1000.0); + return (unsigned int)((timeval.tv_sec - initial_seconds) * 1000.0 + timeval.tv_nsec / 1000000.0); +#endif } /** @@ -364,11 +386,25 @@ unsigned int fluid_curtime(void) double fluid_utime (void) { - GTimeVal timeval; +#ifdef _WIN32 + FILETIME ft; + UINT64 time; - g_get_current_time (&timeval); + GetSystemTimeAsFileTime(&ft); + time = ft.dwHighDateTime; + time <<= 32ULL; + time |= ft.dwLowDateTime; + time /= 10; // time is 100ns, convert to us + time -= 11644473600000000ULL; // Microseconds between Windows epoch (1601/01/01) and Unix + + return time / 1000000.0; +#else + struct timespec timeval; - return (timeval.tv_sec * 1000000.0 + timeval.tv_usec); + clock_gettime(CLOCK_REALTIME, &timeval); + + return (timeval.tv_sec * 1000000.0 + timeval.tv_nsec / 1000.0); +#endif } @@ -377,8 +413,8 @@ fluid_utime (void) void fluid_thread_self_set_prio (int prio_level) { - if (prio_level > 0) - SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_HIGHEST); + if (prio_level > 0) + SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_HIGHEST); } @@ -387,8 +423,8 @@ fluid_thread_self_set_prio (int prio_level) void fluid_thread_self_set_prio (int prio_level) { - if (prio_level > 0) - DosSetPriority (PRTYS_THREAD, PRTYC_REGULAR, PRTYD_MAXIMUM, 0); + if (prio_level > 0) + DosSetPriority (PRTYS_THREAD, PRTYC_REGULAR, PRTYD_MAXIMUM, 0); } #else /* POSIX stuff.. Nice POSIX.. Good POSIX. */ @@ -396,26 +432,25 @@ fluid_thread_self_set_prio (int prio_level) void fluid_thread_self_set_prio (int prio_level) { - struct sched_param priority; + struct sched_param priority; - if (prio_level > 0) - { + if (prio_level > 0) { - memset(&priority, 0, sizeof(priority)); - priority.sched_priority = prio_level; + memset(&priority, 0, sizeof(priority)); + priority.sched_priority = prio_level; - if (pthread_setschedparam (pthread_self (), SCHED_FIFO, &priority) == 0) { - return; - } + if (pthread_setschedparam (pthread_self (), SCHED_FIFO, &priority) == 0) { + return; + } #ifdef DBUS_SUPPORT -/* Try to gain high priority via rtkit */ - - if (fluid_rtkit_make_realtime(0, prio_level) == 0) { - return; - } + /* Try to gain high priority via rtkit */ + + if (fluid_rtkit_make_realtime(0, prio_level) == 0) { + return; + } #endif - FLUID_LOG(FLUID_WARN, "Failed to set thread to high priority"); - } + FLUID_LOG(FLUID_WARN, "Failed to set thread to high priority"); + } } #ifdef FPE_CHECK @@ -457,24 +492,23 @@ fluid_thread_self_set_prio (int prio_level) */ unsigned int fluid_check_fpe_i386(char* explanation) { - unsigned int s; + unsigned int s; - _FPU_GET_SW(s); - _FPU_CLR_SW(); + _FPU_GET_SW(s); + _FPU_CLR_SW(); - s &= _FPU_STATUS_IE | _FPU_STATUS_DE | _FPU_STATUS_ZE | _FPU_STATUS_OE | _FPU_STATUS_UE; + s &= _FPU_STATUS_IE | _FPU_STATUS_DE | _FPU_STATUS_ZE | _FPU_STATUS_OE | _FPU_STATUS_UE; - if (s) - { - FLUID_LOG(FLUID_WARN, "FPE exception (before or in %s): %s%s%s%s%s", explanation, - (s & _FPU_STATUS_IE) ? "Invalid operation " : "", - (s & _FPU_STATUS_DE) ? "Denormal number " : "", - (s & _FPU_STATUS_ZE) ? "Zero divide " : "", - (s & _FPU_STATUS_OE) ? "Overflow " : "", - (s & _FPU_STATUS_UE) ? "Underflow " : ""); - } + if (s) { + FLUID_LOG(FLUID_WARN, "FPE exception (before or in %s): %s%s%s%s%s", explanation, + (s & _FPU_STATUS_IE) ? "Invalid operation " : "", + (s & _FPU_STATUS_DE) ? "Denormal number " : "", + (s & _FPU_STATUS_ZE) ? "Zero divide " : "", + (s & _FPU_STATUS_OE) ? "Overflow " : "", + (s & _FPU_STATUS_UE) ? "Underflow " : ""); + } - return s; + return s; } /* Purpose: @@ -482,7 +516,7 @@ unsigned int fluid_check_fpe_i386(char* explanation) */ void fluid_clear_fpe_i386 (void) { - _FPU_CLR_SW(); + _FPU_CLR_SW(); } #endif // ifdef FPE_CHECK @@ -499,40 +533,39 @@ void fluid_clear_fpe_i386 (void) #if WITH_PROFILING -fluid_profile_data_t fluid_profile_data[] = -{ - { FLUID_PROF_WRITE, "fluid_synth_write_* ", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_ONE_BLOCK, "fluid_synth_one_block ", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_ONE_BLOCK_CLEAR, "fluid_synth_one_block:clear ", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_ONE_BLOCK_VOICE, "fluid_synth_one_block:one voice ", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_ONE_BLOCK_VOICES, "fluid_synth_one_block:all voices", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_ONE_BLOCK_REVERB, "fluid_synth_one_block:reverb ", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_ONE_BLOCK_CHORUS, "fluid_synth_one_block:chorus ", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_VOICE_NOTE, "fluid_voice:note ", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_VOICE_RELEASE, "fluid_voice:release ", 1e10, 0.0, 0.0, 0}, - { FLUID_PROF_LAST, "last", 1e100, 0.0, 0.0, 0} +fluid_profile_data_t fluid_profile_data[] = { + { FLUID_PROF_WRITE, "fluid_synth_write_* ", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_ONE_BLOCK, "fluid_synth_one_block ", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_ONE_BLOCK_CLEAR, "fluid_synth_one_block:clear ", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_ONE_BLOCK_VOICE, "fluid_synth_one_block:one voice ", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_ONE_BLOCK_VOICES, "fluid_synth_one_block:all voices", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_ONE_BLOCK_REVERB, "fluid_synth_one_block:reverb ", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_ONE_BLOCK_CHORUS, "fluid_synth_one_block:chorus ", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_VOICE_NOTE, "fluid_voice:note ", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_VOICE_RELEASE, "fluid_voice:release ", 1e10, 0.0, 0.0, 0}, + { FLUID_PROF_LAST, "last", 1e100, 0.0, 0.0, 0} }; void fluid_profiling_print(void) { - int i; + int i; - printf("fluid_profiling_print\n"); + printf("fluid_profiling_print\n"); - FLUID_LOG(FLUID_INFO, "Estimated times: min/avg/max (micro seconds)"); + FLUID_LOG(FLUID_INFO, "Estimated times: min/avg/max (micro seconds)"); - for (i = 0; i < FLUID_PROF_LAST; i++) { - if (fluid_profile_data[i].count > 0) { - FLUID_LOG(FLUID_INFO, "%s: %.3f/%.3f/%.3f", - fluid_profile_data[i].description, - fluid_profile_data[i].min, - fluid_profile_data[i].total / fluid_profile_data[i].count, - fluid_profile_data[i].max); - } else { - FLUID_LOG(FLUID_DBG, "%s: no profiling available", fluid_profile_data[i].description); + for (i = 0; i < FLUID_PROF_LAST; i++) { + if (fluid_profile_data[i].count > 0) { + FLUID_LOG(FLUID_INFO, "%s: %.3f/%.3f/%.3f", + fluid_profile_data[i].description, + fluid_profile_data[i].min, + fluid_profile_data[i].total / fluid_profile_data[i].count, + fluid_profile_data[i].max); + } else { + FLUID_LOG(FLUID_DBG, "%s: no profiling available", fluid_profile_data[i].description); + } } - } } @@ -553,23 +586,23 @@ void fluid_profiling_print(void) fluid_cond_t * new_fluid_cond (void) { - if (!g_thread_supported ()) g_thread_init (NULL); - return g_cond_new (); + if (!g_thread_supported ()) g_thread_init (NULL); + return g_cond_new (); } #endif -static gpointer -fluid_thread_high_prio (gpointer data) +static FLUID_THREAD_RETURN_TYPE +fluid_thread_high_prio (void *data) { - fluid_thread_info_t *info = data; + fluid_thread_info_t *info = data; - fluid_thread_self_set_prio (info->prio_level); + fluid_thread_self_set_prio (info->prio_level); - info->func (info->data); - FLUID_FREE (info); + info->func (info->data); + FLUID_FREE (info); - return NULL; + return FLUID_THREAD_RETURN_VALUE; } /** @@ -584,57 +617,47 @@ fluid_thread_high_prio (gpointer data) fluid_thread_t * new_fluid_thread (const char *name, fluid_thread_func_t func, void *data, int prio_level, int detach) { - GThread *thread; - fluid_thread_info_t *info; - GError *err = NULL; + fluid_thread_t *thread; + fluid_thread_info_t *info; - g_return_val_if_fail (func != NULL, NULL); + fluid_return_val_if_fail (func != NULL, NULL); -#if OLD_GLIB_THREAD_API - /* Make sure g_thread_init has been called. - * FIXME - Probably not a good idea in a shared library, - * but what can we do *and* remain backwards compatible? */ - if (!g_thread_supported ()) g_thread_init (NULL); -#endif + thread = FLUID_NEW(fluid_thread_t); + if (prio_level > 0) { + info = FLUID_NEW (fluid_thread_info_t); - if (prio_level > 0) - { - info = FLUID_NEW (fluid_thread_info_t); + if (!info) { + FLUID_LOG(FLUID_ERR, "Out of memory"); + return NULL; + } - if (!info) - { - FLUID_LOG(FLUID_ERR, "Out of memory"); - return NULL; + info->func = func; + info->data = data; + info->prio_level = prio_level; + data = info; + func = fluid_thread_high_prio; } - info->func = func; - info->data = data; - info->prio_level = prio_level; -#if NEW_GLIB_THREAD_API - thread = g_thread_try_new (name, fluid_thread_high_prio, info, &err); -#else - thread = g_thread_create (fluid_thread_high_prio, info, detach == FALSE, &err); -#endif - } -#if NEW_GLIB_THREAD_API - else thread = g_thread_try_new (name, (GThreadFunc)func, data, &err); +#if _WIN32 + *thread = CreateThread(NULL, 0, func, data, 0, NULL); #else - else thread = g_thread_create ((GThreadFunc)func, data, detach == FALSE, &err); + pthread_create(thread, NULL, func, data); #endif - if (!thread) - { - FLUID_LOG(FLUID_ERR, "Failed to create the thread: %s", - fluid_gerror_message (err)); - g_clear_error (&err); - return NULL; - } + if (!thread) { + FLUID_LOG(FLUID_ERR, "Failed to create the thread"); + return NULL; + } -#if NEW_GLIB_THREAD_API - if (detach) g_thread_unref (thread); // Release thread reference, if caller wants to detach + if (detach) { +#if _WIN32 + CloseHandle(*thread); +#else + pthread_detach(*thread); #endif + } - return thread; + return thread; } /** @@ -644,7 +667,7 @@ new_fluid_thread (const char *name, fluid_thread_func_t func, void *data, int pr void delete_fluid_thread(fluid_thread_t* thread) { - /* Threads free themselves when they quit, nothing to do */ + /* Threads free themselves when they quit, nothing to do */ } /** @@ -655,121 +678,116 @@ delete_fluid_thread(fluid_thread_t* thread) int fluid_thread_join(fluid_thread_t* thread) { - g_thread_join (thread); +#ifdef _WIN32 + WaitForSingleObject(*thread, INFINITE); + CloseHandle(*thread); +#else + pthread_join(*thread, NULL); +#endif - return FLUID_OK; + return FLUID_OK; } -fluid_thread_return_t +FLUID_THREAD_RETURN_TYPE fluid_timer_run (void *data) { - fluid_timer_t *timer; - int count = 0; - int cont; - long start; - long delay; + fluid_timer_t *timer; + int count = 0; + int cont; + long start; + long delay; - timer = (fluid_timer_t *)data; + timer = (fluid_timer_t *)data; - /* keep track of the start time for absolute positioning */ - start = fluid_curtime (); + /* keep track of the start time for absolute positioning */ + start = fluid_curtime (); - while (timer->cont) - { - cont = (*timer->callback)(timer->data, fluid_curtime() - start); + while (timer->cont) { + cont = (*timer->callback)(timer->data, fluid_curtime() - start); - count++; - if (!cont) break; + count++; + if (!cont) break; - /* to avoid incremental time errors, calculate the delay between - two callbacks bringing in the "absolute" time (count * - timer->msec) */ - delay = (count * timer->msec) - (fluid_curtime() - start); - if (delay > 0) g_usleep (delay * 1000); - } + /* to avoid incremental time errors, calculate the delay between + two callbacks bringing in the "absolute" time (count * + timer->msec) */ + delay = (count * timer->msec) - (fluid_curtime() - start); +#ifdef _WIN32 + if (delay > 0) Sleep (delay); +#else + if (delay > 0) usleep (delay * 1000); +#endif + } - FLUID_LOG (FLUID_DBG, "Timer thread finished"); + FLUID_LOG (FLUID_DBG, "Timer thread finished"); - if (timer->auto_destroy) - FLUID_FREE (timer); + if (timer->auto_destroy) + FLUID_FREE (timer); - return FLUID_THREAD_RETURN_VALUE; + return FLUID_THREAD_RETURN_VALUE; } fluid_timer_t* new_fluid_timer (int msec, fluid_timer_callback_t callback, void* data, int new_thread, int auto_destroy, int high_priority) { - fluid_timer_t *timer; - - timer = FLUID_NEW (fluid_timer_t); - - if (timer == NULL) - { - FLUID_LOG (FLUID_ERR, "Out of memory"); - return NULL; - } - - timer->msec = msec; - timer->callback = callback; - timer->data = data; - timer->cont = TRUE ; - timer->thread = NULL; - timer->auto_destroy = auto_destroy; - - if (new_thread) - { - timer->thread = new_fluid_thread ("timer", fluid_timer_run, timer, high_priority - ? FLUID_SYS_TIMER_HIGH_PRIO_LEVEL : 0, FALSE); - if (!timer->thread) - { - FLUID_FREE (timer); - return NULL; + fluid_timer_t *timer; + + timer = FLUID_NEW (fluid_timer_t); + + if (timer == NULL) { + FLUID_LOG (FLUID_ERR, "Out of memory"); + return NULL; } - } - else - { - fluid_timer_run (timer); /* Run directly, instead of as a separate thread */ - if(auto_destroy) - { - /* do NOT return freed memory */ - return NULL; - } - } - - return timer; + + timer->msec = msec; + timer->callback = callback; + timer->data = data; + timer->cont = TRUE ; + timer->thread = NULL; + timer->auto_destroy = auto_destroy; + + if (new_thread) { + timer->thread = new_fluid_thread ("timer", fluid_timer_run, timer, high_priority + ? FLUID_SYS_TIMER_HIGH_PRIO_LEVEL : 0, false); + if (!timer->thread) { + FLUID_FREE (timer); + return NULL; + } + } else fluid_timer_run (timer); /* Run directly, instead of as a separate thread */ + + return timer; } int delete_fluid_timer (fluid_timer_t *timer) { - int auto_destroy = timer->auto_destroy; + int auto_destroy = timer->auto_destroy; - timer->cont = 0; - fluid_timer_join (timer); + timer->cont = 0; + fluid_timer_join (timer); - /* Shouldn't access timer now if auto_destroy enabled, since it has been destroyed */ + /* Shouldn't access timer now if auto_destroy enabled, since it has been destroyed */ - if (!auto_destroy) FLUID_FREE (timer); + if (!auto_destroy) FLUID_FREE (timer); - return FLUID_OK; + return FLUID_OK; } int fluid_timer_join (fluid_timer_t *timer) { - int auto_destroy; + int auto_destroy; - if (timer->thread) - { - auto_destroy = timer->auto_destroy; - fluid_thread_join (timer->thread); + if (timer->thread) { + auto_destroy = timer->auto_destroy; + fluid_thread_join (timer->thread); - if (!auto_destroy) timer->thread = NULL; - } + if (!auto_destroy) timer->thread = NULL; + } - return FLUID_OK; + return FLUID_OK; } @@ -786,7 +804,7 @@ fluid_timer_join (fluid_timer_t *timer) fluid_istream_t fluid_get_stdin (void) { - return STDIN_FILENO; + return STDIN_FILENO; } /** @@ -796,7 +814,7 @@ fluid_get_stdin (void) fluid_ostream_t fluid_get_stdout (void) { - return STDOUT_FILENO; + return STDOUT_FILENO; } /** @@ -808,27 +826,25 @@ fluid_istream_readline (fluid_istream_t in, fluid_ostream_t out, char* prompt, char* buf, int len) { #if WITH_READLINE - if (in == fluid_get_stdin ()) - { - char *line; + if (in == fluid_get_stdin ()) { + char *line; - line = readline (prompt); + line = readline (prompt); - if (line == NULL) - return -1; + if (line == NULL) + return -1; - FLUID_SNPRINTF (buf, len, "%s", line); - buf[len - 1] = 0; + snprintf(buf, len, "%s", line); + buf[len - 1] = 0; - free(line); - return 1; - } - else + free(line); + return 1; + } else #endif - { - fluid_ostream_printf (out, "%s", prompt); - return fluid_istream_gets (in, buf, len); - } + { + fluid_ostream_printf (out, "%s", prompt); + return fluid_istream_gets (in, buf, len); + } } /** @@ -841,47 +857,30 @@ fluid_istream_readline (fluid_istream_t in, fluid_ostream_t out, char* prompt, static int fluid_istream_gets (fluid_istream_t in, char* buf, int len) { - char c; - int n; + char c; + int n; - buf[len - 1] = 0; + buf[len - 1] = 0; - while (--len > 0) - { -#ifndef WIN32 - n = read(in, &c, 1); - if (n == -1) return -1; -#else - /* Handle read differently depending on if its a socket or file descriptor */ - if (!(in & WIN32_SOCKET_FLAG)) - { - n = read(in, &c, 1); - if (n == -1) return -1; - } - else - { - n = recv(in & ~WIN32_SOCKET_FLAG, &c, 1, 0); - if (n == SOCKET_ERROR) return -1; - } -#endif + while (--len > 0) { + n = read(in, &c, 1); + if (n == -1) return -1; - if (n == 0) - { - *buf++ = 0; - return 0; - } + if (n == 0) { + *buf++ = 0; + return 0; + } - if (c == '\n') - { - *buf++ = 0; - return 1; - } + if (c == '\n') { + *buf++ = 0; + return 1; + } - /* Store all characters excluding CR */ - if (c != '\r') *buf++ = c; - } + /* Store all characters excluding CR */ + if (c != '\r') *buf++ = c; + } - return -1; + return -1; } /** @@ -894,406 +893,24 @@ fluid_istream_gets (fluid_istream_t in, char* buf, int len) int fluid_ostream_printf (fluid_ostream_t out, char* format, ...) { - char buf[4096]; - va_list args; - int len; - - va_start (args, format); - len = FLUID_VSNPRINTF (buf, 4095, format, args); - va_end (args); - - if (len == 0) - { - return 0; - } - - if (len < 0) - { - printf("fluid_ostream_printf: buffer overflow"); - return -1; - } - - buf[4095] = 0; - -#ifndef WIN32 - return write (out, buf, strlen (buf)); -#else - { - int retval; - - /* Handle write differently depending on if its a socket or file descriptor */ - if (!(out & WIN32_SOCKET_FLAG)) - return write(out, buf, strlen (buf)); - - /* Socket */ - retval = send (out & ~WIN32_SOCKET_FLAG, buf, strlen (buf), 0); - - return retval != SOCKET_ERROR ? retval : -1; - } -#endif -} - -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 - -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; -} - -void fluid_socket_close(fluid_socket_t sock) -{ - if (sock != INVALID_SOCKET) - close (sock); -} - -static fluid_thread_return_t -fluid_server_socket_run (void *data) -{ - fluid_server_socket_t *server_socket = (fluid_server_socket_t *)data; - fluid_socket_t client_socket; -#ifdef IPV6_SUPPORT - struct sockaddr_in6 addr; - char straddr[INET6_ADDRSTRLEN]; -#else - struct sockaddr_in addr; - char straddr[INET_ADDRSTRLEN]; -#endif - socklen_t addrlen = sizeof (addr); - int retval; - FLUID_MEMSET((char *)&addr, 0, sizeof(addr)); - - FLUID_LOG (FLUID_DBG, "Server listening for connections"); - - while (server_socket->cont) - { - client_socket = accept (server_socket->socket, (struct sockaddr *)&addr, &addrlen); + char buf[4096]; + va_list args; + int len; - FLUID_LOG (FLUID_DBG, "New client connection"); + va_start (args, format); + len = vsnprintf (buf, 4095, format, args); + va_end (args); - if (client_socket == INVALID_SOCKET) - { - if (server_socket->cont) - FLUID_LOG(FLUID_ERR, "Failed to accept connection"); - - server_socket->cont = 0; - return FLUID_THREAD_RETURN_VALUE; - } else { -#ifdef HAVE_INETNTOP -#ifdef IPV6_SUPPORT - inet_ntop(AF_INET6, &addr.sin6_addr, straddr, sizeof(straddr)); -#else - inet_ntop(AF_INET, &addr.sin_addr, straddr, sizeof(straddr)); -#endif -#endif -#ifdef HAVE_INETNTOP - retval = server_socket->func (server_socket->data, client_socket, - straddr); -#else - retval = server_socket->func (server_socket->data, client_socket, - inet_ntoa (addr.sin_addr)); -#endif - - if (retval != 0) - fluid_socket_close(client_socket); + if (len == 0) { + return 0; } - } - - FLUID_LOG(FLUID_DBG, "Server closing"); - - return FLUID_THREAD_RETURN_VALUE; -} - -fluid_server_socket_t* -new_fluid_server_socket(int port, fluid_server_func_t func, void* data) -{ - fluid_server_socket_t* server_socket; -#ifdef IPV6_SUPPORT - struct sockaddr_in6 addr; -#else - struct sockaddr_in addr; -#endif - fluid_socket_t sock; - - g_return_val_if_fail (func != NULL, NULL); -#ifdef IPV6_SUPPORT - sock = socket(AF_INET6, SOCK_STREAM, 0); - if (sock == INVALID_SOCKET) { - FLUID_LOG(FLUID_ERR, "Failed to create server socket"); - return NULL; - } - - FLUID_MEMSET((char *)&addr, 0, sizeof(struct sockaddr_in6)); - addr.sin6_family = AF_INET6; - addr.sin6_addr = in6addr_any; - addr.sin6_port = htons(port); -#else - - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock == INVALID_SOCKET) { - FLUID_LOG(FLUID_ERR, "Failed to create server socket"); - return NULL; - } - - FLUID_MEMSET((char *)&addr, 0, sizeof(struct sockaddr_in)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(INADDR_ANY); - addr.sin_port = htons(port); -#endif - if (bind(sock, (const struct sockaddr *) &addr, sizeof(addr)) == SOCKET_ERROR) { - FLUID_LOG(FLUID_ERR, "Failed to bind server socket"); - fluid_socket_close(sock); - return NULL; - } - - if (listen(sock, 10) == SOCKET_ERROR) { - FLUID_LOG(FLUID_ERR, "Failed listen on server socket"); - fluid_socket_close(sock); - 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); - return NULL; - } - - server_socket->socket = sock; - server_socket->func = func; - server_socket->data = data; - server_socket->cont = 1; - - server_socket->thread = new_fluid_thread("server", fluid_server_socket_run, server_socket, - 0, FALSE); - if (server_socket->thread == NULL) { - FLUID_FREE(server_socket); - fluid_socket_close(sock); - 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); - return FLUID_OK; -} - -#else // Win32 is "special" - - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -fluid_istream_t fluid_socket_get_istream (fluid_socket_t sock) -{ - return sock | WIN32_SOCKET_FLAG; -} - -fluid_ostream_t fluid_socket_get_ostream (fluid_socket_t sock) -{ - return sock | WIN32_SOCKET_FLAG; -} - -void fluid_socket_close (fluid_socket_t sock) -{ - if (sock != INVALID_SOCKET) - closesocket (sock); -} - -static fluid_thread_return_t fluid_server_socket_run (void *data) -{ - fluid_server_socket_t *server_socket = (fluid_server_socket_t *)data; - fluid_socket_t client_socket; -#ifdef IPV6_SUPPORT - struct sockaddr_in6 addr; - char straddr[INET6_ADDRSTRLEN]; -#else - struct sockaddr_in addr; -#ifdef HAVE_INETNTOP - char straddr[INET_ADDRSTRLEN]; -#endif -#endif - socklen_t addrlen = sizeof (addr); - int r; - FLUID_MEMSET((char *)&addr, 0, sizeof(addr)); - - FLUID_LOG(FLUID_DBG, "Server listening for connections"); - - while (server_socket->cont) - { - client_socket = accept (server_socket->socket, (struct sockaddr *)&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 FLUID_THREAD_RETURN_VALUE; - } - else - { -#ifdef HAVE_INETNTOP -#ifdef IPV6_SUPPORT - inet_ntop(AF_INET6, &addr.sin6_addr, straddr, sizeof(straddr)); -#else - inet_ntop(AF_INET, &addr.sin_addr, straddr, sizeof(straddr)); -#endif -#endif -#ifdef HAVE_INETNTOP - r = server_socket->func (server_socket->data, client_socket, - straddr); -#else - r = server_socket->func (server_socket->data, client_socket, - inet_ntoa (addr.sin_addr)); -#endif - if (r != 0) - fluid_socket_close (client_socket); + if (len < 0) { + printf("fluid_ostream_printf: buffer overflow"); + return -1; } - } - - FLUID_LOG (FLUID_DBG, "Server closing"); - - return FLUID_THREAD_RETURN_VALUE; -} - -fluid_server_socket_t* -new_fluid_server_socket(int port, fluid_server_func_t func, void* data) -{ - fluid_server_socket_t* server_socket; -#ifdef IPV6_SUPPORT - struct sockaddr_in6 addr; -#else - struct sockaddr_in addr; -#endif - - fluid_socket_t sock; - WSADATA wsaData; - 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; - } -#ifdef IPV6_SUPPORT - sock = socket (AF_INET6, SOCK_STREAM, 0); - if (sock == INVALID_SOCKET) - { - FLUID_LOG (FLUID_ERR, "Failed to create server socket: %ld", WSAGetLastError ()); - WSACleanup (); - return NULL; - } - addr.sin6_family = AF_INET6; - addr.sin6_port = htons (port); - addr.sin6_addr = in6addr_any; -#else - sock = socket (AF_INET, SOCK_STREAM, 0); + buf[4095] = 0; - if (sock == INVALID_SOCKET) - { - FLUID_LOG (FLUID_ERR, "Failed to create server socket: %ld", WSAGetLastError ()); - WSACleanup (); - return NULL; - } - - addr.sin_family = AF_INET; - addr.sin_port = htons (port); - addr.sin_addr.s_addr = htonl (INADDR_ANY); -#endif - retval = bind (sock, (struct sockaddr *)&addr, sizeof (addr)); - - if (retval == SOCKET_ERROR) - { - FLUID_LOG (FLUID_ERR, "Failed to bind server socket: %ld", WSAGetLastError ()); - fluid_socket_close (sock); - WSACleanup (); - return NULL; - } - - 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("server", fluid_server_socket_run, server_socket, - 0, 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 + return write (out, buf, strlen (buf)); +} \ No newline at end of file diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 6e58ae69f..342feafc3 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -36,7 +36,6 @@ #ifndef _FLUID_SYS_H #define _FLUID_SYS_H -#include #include "fluidsynth_priv.h" @@ -56,33 +55,24 @@ void fluid_time_config(void); /* Misc */ -#define fluid_return_val_if_fail g_return_val_if_fail -#define fluid_return_if_fail g_return_if_fail -#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_return_val_if_fail(expr, val) if (!(expr)) return (val) +#define fluid_return_if_fail(expr) if (!(expr)) return +#define FLUID_INLINE inline +#define FLUID_POINTER_TO_UINT(x) ((size_t)(x)) +#define FLUID_POINTER_TO_INT(x) ((intptr_t)(x)) +#define FLUID_INT_TO_POINTER(val) ((void*) (((char*) 0) + (val))) +#define FLUID_N_ELEMENTS(struct) (sizeof (struct) / sizeof (struct[0])) -#define FLUID_IS_BIG_ENDIAN (G_BYTE_ORDER == G_BIG_ENDIAN) +// TODO: Add proper big endianess check +#define FLUID_IS_BIG_ENDIAN false -#define FLUID_LE32TOH(x) GINT32_FROM_LE(x) -#define FLUID_LE16TOH(x) GINT16_FROM_LE(x) +#define FLUID_LE32TOH(x) le32toh(x) +#define FLUID_LE16TOH(x) le16toh(x) /* * Utility functions */ char *fluid_strtok (char **str, char *delim); - - -#if defined(__OS2__) -#define INCL_DOS -#include - -typedef int socklen_t; -#endif - unsigned int fluid_curtime(void); double fluid_utime(void); @@ -106,188 +96,86 @@ int delete_fluid_timer(fluid_timer_t* timer); int fluid_timer_join(fluid_timer_t* timer); int fluid_timer_stop(fluid_timer_t* timer); -// Macros to use for pre-processor if statements to test which Glib thread API we have (pre or post 2.32) -#define NEW_GLIB_THREAD_API (GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 32)) -#define OLD_GLIB_THREAD_API (GLIB_MAJOR_VERSION < 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32)) - /* Muteces */ -#if NEW_GLIB_THREAD_API - -/* glib 2.32 and newer */ +static FLUID_INLINE void +fluid_pthread_mutex_init(pthread_mutex_t *m, int kind) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, kind); + pthread_mutex_init(m, &attr); +} /* Regular mutex */ -typedef GMutex fluid_mutex_t; -#define FLUID_MUTEX_INIT { 0 } -#define fluid_mutex_init(_m) g_mutex_init (&(_m)) -#define fluid_mutex_destroy(_m) g_mutex_clear (&(_m)) -#define fluid_mutex_lock(_m) g_mutex_lock(&(_m)) -#define fluid_mutex_unlock(_m) g_mutex_unlock(&(_m)) +typedef pthread_mutex_t fluid_mutex_t; +#define FLUID_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER +#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)) /* Recursive lock capable mutex */ -typedef GRecMutex fluid_rec_mutex_t; -#define fluid_rec_mutex_init(_m) g_rec_mutex_init(&(_m)) -#define fluid_rec_mutex_destroy(_m) g_rec_mutex_clear(&(_m)) -#define fluid_rec_mutex_lock(_m) g_rec_mutex_lock(&(_m)) -#define fluid_rec_mutex_unlock(_m) g_rec_mutex_unlock(&(_m)) +typedef pthread_mutex_t fluid_rec_mutex_t; +#define fluid_rec_mutex_init(_m) fluid_pthread_mutex_init(&(_m), PTHREAD_MUTEX_RECURSIVE) +#define fluid_rec_mutex_destroy(_m) pthread_mutex_destroy(&(_m)) +#define fluid_rec_mutex_lock(_m) pthread_mutex_lock(&(_m)) +#define fluid_rec_mutex_unlock(_m) pthread_mutex_unlock(&(_m)) /* Dynamically allocated mutex suitable for fluid_cond_t use */ -typedef GMutex fluid_cond_mutex_t; -#define fluid_cond_mutex_lock(m) g_mutex_lock(m) -#define fluid_cond_mutex_unlock(m) g_mutex_unlock(m) +typedef pthread_mutex_t fluid_cond_mutex_t; +#define fluid_cond_mutex_init(m) pthread_mutex_init(m, NULL) +#define fluid_cond_mutex_destroy(m) pthread_mutex_destroy(m) +#define fluid_cond_mutex_lock(m) pthread_mutex_lock(m) +#define fluid_cond_mutex_unlock(m) pthread_mutex_unlock(m) static FLUID_INLINE fluid_cond_mutex_t * new_fluid_cond_mutex (void) { - GMutex *mutex; - mutex = g_new (GMutex, 1); - g_mutex_init (mutex); - return (mutex); + fluid_cond_mutex_t *mutex; + mutex = malloc(sizeof(fluid_cond_mutex_t)); + fluid_cond_mutex_init(mutex); + return mutex; } static FLUID_INLINE void delete_fluid_cond_mutex (fluid_cond_mutex_t *m) { - g_mutex_clear (m); - g_free (m); + fluid_cond_mutex_destroy(m); + free(m); } /* Thread condition signaling */ -typedef GCond fluid_cond_t; -#define fluid_cond_signal(cond) g_cond_signal(cond) -#define fluid_cond_broadcast(cond) g_cond_broadcast(cond) -#define fluid_cond_wait(cond, mutex) g_cond_wait(cond, mutex) +typedef pthread_cond_t fluid_cond_t; +#define fluid_cond_init(cond) pthread_cond_init(cond, NULL) +#define fluid_cond_destroy(cond) pthread_cond_destroy(cond) +#define fluid_cond_signal(cond) pthread_cond_signal(cond) +#define fluid_cond_broadcast(cond) pthread_cond_broadcast(cond) +#define fluid_cond_wait(cond, mutex) pthread_cond_wait(cond, mutex) static FLUID_INLINE fluid_cond_t * new_fluid_cond (void) { - GCond *cond; - cond = g_new (GCond, 1); - g_cond_init (cond); - return (cond); + fluid_cond_t *cond; + cond = malloc(sizeof(fluid_cond_t)); + fluid_cond_init(cond); + return cond; } static FLUID_INLINE void delete_fluid_cond (fluid_cond_t *cond) { - g_cond_clear (cond); - g_free (cond); + fluid_cond_destroy(cond); + free(cond); } /* Thread private data */ -typedef GPrivate fluid_private_t; -#define fluid_private_init(_priv) memset (&_priv, 0, sizeof (_priv)) +typedef pthread_key_t fluid_private_t; +#define fluid_private_init(_priv) pthread_key_create(&_priv, NULL) #define fluid_private_free(_priv) -#define fluid_private_get(_priv) g_private_get(&(_priv)) -#define fluid_private_set(_priv, _data) g_private_set(&(_priv), _data) - -#else - -/* glib prior to 2.32 */ - -/* Regular mutex */ -typedef GStaticMutex fluid_mutex_t; -#define FLUID_MUTEX_INIT G_STATIC_MUTEX_INIT -#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)) - -#define fluid_mutex_init(_m) do { \ - if (!g_thread_supported ()) g_thread_init (NULL); \ - g_static_mutex_init (&(_m)); \ -} while(0) - -/* Recursive lock capable mutex */ -typedef GStaticRecMutex fluid_rec_mutex_t; -#define fluid_rec_mutex_destroy(_m) g_static_rec_mutex_free(&(_m)) -#define fluid_rec_mutex_lock(_m) g_static_rec_mutex_lock(&(_m)) -#define fluid_rec_mutex_unlock(_m) g_static_rec_mutex_unlock(&(_m)) - -#define fluid_rec_mutex_init(_m) do { \ - if (!g_thread_supported ()) g_thread_init (NULL); \ - g_static_rec_mutex_init (&(_m)); \ -} while(0) - -/* Dynamically allocated mutex suitable for fluid_cond_t use */ -typedef GMutex fluid_cond_mutex_t; -#define delete_fluid_cond_mutex(m) g_mutex_free(m) -#define fluid_cond_mutex_lock(m) g_mutex_lock(m) -#define fluid_cond_mutex_unlock(m) g_mutex_unlock(m) - -static FLUID_INLINE fluid_cond_mutex_t * -new_fluid_cond_mutex (void) -{ - if (!g_thread_supported ()) g_thread_init (NULL); - return g_mutex_new (); -} - -/* Thread condition signaling */ -typedef GCond fluid_cond_t; -fluid_cond_t *new_fluid_cond (void); -#define delete_fluid_cond(cond) g_cond_free(cond) -#define fluid_cond_signal(cond) g_cond_signal(cond) -#define fluid_cond_broadcast(cond) g_cond_broadcast(cond) -#define fluid_cond_wait(cond, mutex) g_cond_wait(cond, mutex) - -/* Thread private data */ -typedef GStaticPrivate fluid_private_t; -#define fluid_private_get(_priv) g_static_private_get(&(_priv)) -#define fluid_private_set(_priv, _data) g_static_private_set(&(_priv), _data, NULL) -#define fluid_private_free(_priv) g_static_private_free(&(_priv)) - -#define fluid_private_init(_priv) do { \ - if (!g_thread_supported ()) g_thread_init (NULL); \ - g_static_private_init (&(_priv)); \ -} while(0) - -#endif - - -/* Atomic operations */ - -#define fluid_atomic_int_inc(_pi) g_atomic_int_inc(_pi) -#define fluid_atomic_int_get(_pi) g_atomic_int_get(_pi) -#define fluid_atomic_int_set(_pi, _val) g_atomic_int_set(_pi, _val) -#define fluid_atomic_int_dec_and_test(_pi) g_atomic_int_dec_and_test(_pi) -#define fluid_atomic_int_compare_and_exchange(_pi, _old, _new) \ - g_atomic_int_compare_and_exchange(_pi, _old, _new) - -#if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 30) -#define fluid_atomic_int_exchange_and_add(_pi, _add) \ - g_atomic_int_add(_pi, _add) -#define fluid_atomic_int_add(_pi, _add) \ - g_atomic_int_add(_pi, _add) -#else -#define fluid_atomic_int_exchange_and_add(_pi, _add) \ - g_atomic_int_exchange_and_add(_pi, _add) -#define fluid_atomic_int_add(_pi, _add) \ - g_atomic_int_exchange_and_add(_pi, _add) -#endif - -#define fluid_atomic_pointer_get(_pp) g_atomic_pointer_get(_pp) -#define fluid_atomic_pointer_set(_pp, val) g_atomic_pointer_set(_pp, val) -#define fluid_atomic_pointer_compare_and_exchange(_pp, _old, _new) \ - g_atomic_pointer_compare_and_exchange(_pp, _old, _new) - -static FLUID_INLINE void -fluid_atomic_float_set(volatile float *fptr, float val) -{ - sint32 ival; - memcpy (&ival, &val, 4); - fluid_atomic_int_set ((volatile int *)fptr, ival); -} - -static FLUID_INLINE float -fluid_atomic_float_get(volatile float *fptr) -{ - sint32 ival; - float fval; - ival = fluid_atomic_int_get ((volatile int *)fptr); - memcpy (&fval, &ival, 4); - return fval; -} - +#define fluid_private_get(_priv) pthread_getspecific((_priv)) +#define fluid_private_set(_priv, _data) pthread_setspecific((_priv), (_data)) /* Threads */ @@ -296,12 +184,12 @@ typedef void* fluid_thread_return_t; /* static return value for thread functions which requires a return value */ #define FLUID_THREAD_RETURN_VALUE (NULL) -typedef GThread fluid_thread_t; -typedef fluid_thread_return_t (*fluid_thread_func_t)(void* data); +typedef pthread_t fluid_thread_t; +typedef void *(*fluid_thread_func_t)(void* data); -#define FLUID_THREAD_ID_NULL NULL /* A NULL "ID" value */ -#define fluid_thread_id_t GThread * /* Data type for a thread ID */ -#define fluid_thread_get_id() g_thread_self() /* Get unique "ID" for current thread */ +#define FLUID_THREAD_ID_NULL NULL /* A NULL "ID" value */ +#define fluid_thread_id_t pthread_t /* Data type for a thread ID */ +#define fluid_thread_get_id() pthread_self() /* Get unique "ID" for current thread */ fluid_thread_t* new_fluid_thread(const char *name, fluid_thread_func_t func, void *data, int prio_level, int detach); @@ -309,6 +197,10 @@ void delete_fluid_thread(fluid_thread_t* thread); void fluid_thread_self_set_prio (int prio_level); int fluid_thread_join(fluid_thread_t* thread); +/* Atomic operations */ + +#include "fluid_atomic.h" + /* Sockets and I/O */ fluid_istream_t fluid_get_stdin (void); @@ -424,15 +316,7 @@ extern fluid_profile_data_t fluid_profile_data[]; fluid_check_fpe() checks for "unnormalized numbers" and other exceptions of the floating point processsor. */ -#ifdef FPE_CHECK -#define fluid_check_fpe(expl) fluid_check_fpe_i386(expl) -#define fluid_clear_fpe() fluid_clear_fpe_i386() -#else #define fluid_check_fpe(expl) #define fluid_clear_fpe() -#endif - -unsigned int fluid_check_fpe_i386(char * explanation_in_case_of_fpe); -void fluid_clear_fpe_i386(void); #endif /* _FLUID_SYS_H */ diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h index f2fc8ddac..15273f8f2 100644 --- a/src/utils/fluidsynth_priv.h +++ b/src/utils/fluidsynth_priv.h @@ -22,20 +22,10 @@ #ifndef _FLUIDSYNTH_PRIV_H #define _FLUIDSYNTH_PRIV_H -#include - #if HAVE_CONFIG_H #include "config.h" #endif -#if defined(__POWERPC__) && !(defined(__APPLE__) && defined(__MACH__)) -#include "config_maxmsp43.h" -#endif - -#if defined(WIN32) && !defined(MINGW32) -#include "config_win32.h" -#endif - #if HAVE_STRING_H #include #endif @@ -112,32 +102,6 @@ #include #endif -#if defined(WIN32) && HAVE_WINDOWS_H -#include -#include -#include -#endif - -/* MinGW32 special defines */ -#ifdef MINGW32 - -#include - -#define DSOUND_SUPPORT 1 -#define WINMIDI_SUPPORT 1 -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -#endif - -/* Darwin special defines (taken from config_macosx.h) */ -#ifdef DARWIN -#define MACINTOSH -#define __Types__ -#define WITHOUT_SERVER 1 -#endif - #include "fluidsynth.h" @@ -154,12 +118,8 @@ typedef double fluid_real_t; #endif -#if defined(WIN32) -typedef SOCKET fluid_socket_t; -#else typedef int fluid_socket_t; #define INVALID_SOCKET -1 -#endif #if defined(SUPPORTS_VLA) # define FLUID_DECLARE_VLA(_type, _name, _len) \ @@ -169,22 +129,25 @@ typedef int fluid_socket_t; _type* _name = g_newa(_type, (_len)) #endif +#define TRUE 1 +#define FALSE 0 -/** Integer types */ -//typedef gint8 sint8; -typedef guint8 uint8; -//typedef gint16 sint16; -typedef guint16 uint16; -typedef gint32 sint32; -typedef guint32 uint32; -//typedef gint64 sint64; -//typedef guint64 uint64; - -/** Atomic types */ -typedef int fluid_atomic_int_t; -typedef unsigned int fluid_atomic_uint_t; -typedef float fluid_atomic_float_t; +/** Integer types */ +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; + +/** Atomic types */ +typedef struct { + volatile int value; +} fluid_atomic_int_t; +typedef struct { + volatile unsigned value; +} fluid_atomic_uint_t; +typedef struct { + volatile float value; +} fluid_atomic_float_t; /*************************************************************** * @@ -309,5 +272,4 @@ char* fluid_error(void); /* Internationalization */ #define _(s) s - #endif /* _FLUIDSYNTH_PRIV_H */ From d2c9b8240fb79e29f96bdcbf52a4b14347bec968 Mon Sep 17 00:00:00 2001 From: loki666 Date: Fri, 27 Oct 2017 20:57:21 +0200 Subject: [PATCH 02/34] update fluid_sys.c --- src/utils/fluid_sys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c index 223c388c3..dd1ed11d0 100644 --- a/src/utils/fluid_sys.c +++ b/src/utils/fluid_sys.c @@ -592,7 +592,7 @@ new_fluid_cond (void) #endif -static FLUID_THREAD_RETURN_TYPE +static fluid_thread_return_t fluid_thread_high_prio (void *data) { fluid_thread_info_t *info = data; @@ -689,7 +689,7 @@ fluid_thread_join(fluid_thread_t* thread) } -FLUID_THREAD_RETURN_TYPE +fluid_thread_return_t fluid_timer_run (void *data) { fluid_timer_t *timer; From 0fdab269c1743fdddb6855b24a77f34bfd956e8a Mon Sep 17 00:00:00 2001 From: loki666 Date: Mon, 13 Nov 2017 14:08:17 +0100 Subject: [PATCH 03/34] fix indentation --- src/utils/fluid_sys.c | 265 +++++++++++++++++++----------------------- 1 file changed, 117 insertions(+), 148 deletions(-) diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c index c530e26dd..bb109a083 100644 --- a/src/utils/fluid_sys.c +++ b/src/utils/fluid_sys.c @@ -346,17 +346,17 @@ fluid_is_soundfont(const char *filename) */ unsigned int fluid_curtime(void) { - static long initial_seconds = 0; - struct timespec timeval; - - if (initial_seconds == 0) { - clock_gettime(CLOCK_REALTIME, &timeval); - initial_seconds = timeval.tv_sec; - } + static long initial_seconds = 0; + struct timespec timeval; + if (initial_seconds == 0) { clock_gettime(CLOCK_REALTIME, &timeval); + initial_seconds = timeval.tv_sec; + } + + clock_gettime(CLOCK_REALTIME, &timeval); - return (unsigned int)((timeval.tv_sec - initial_seconds) * 1000.0 + timeval.tv_nsec / 1000000.0); + return (unsigned int)((timeval.tv_sec - initial_seconds) * 1000.0 + timeval.tv_nsec / 1000000.0); } /** @@ -366,29 +366,29 @@ unsigned int fluid_curtime(void) double fluid_utime (void) { - struct timespec timeval; + struct timespec timeval; - clock_gettime(CLOCK_REALTIME, &timeval); + clock_gettime(CLOCK_REALTIME, &timeval); - return (timeval.tv_sec * 1000000.0 + timeval.tv_nsec / 1000.0); + return (timeval.tv_sec * 1000000.0 + timeval.tv_nsec / 1000.0); } void fluid_thread_self_set_prio (int prio_level) { - struct sched_param priority; + struct sched_param priority; - if (prio_level > 0) { + if (prio_level > 0) { - memset(&priority, 0, sizeof(priority)); - priority.sched_priority = prio_level; + memset(&priority, 0, sizeof(priority)); + priority.sched_priority = prio_level; - if (pthread_setschedparam (pthread_self (), SCHED_FIFO, &priority) == 0) { - return; - } - FLUID_LOG(FLUID_WARN, "Failed to set thread to high priority"); + if (pthread_setschedparam (pthread_self (), SCHED_FIFO, &priority) == 0) { + return; } + FLUID_LOG(FLUID_WARN, "Failed to set thread to high priority"); + } } /*************************************************************** @@ -415,23 +415,23 @@ fluid_profile_data_t fluid_profile_data[] = { void fluid_profiling_print(void) { - int i; + int i; - printf("fluid_profiling_print\n"); + printf("fluid_profiling_print\n"); - FLUID_LOG(FLUID_INFO, "Estimated times: min/avg/max (micro seconds)"); + FLUID_LOG(FLUID_INFO, "Estimated times: min/avg/max (micro seconds)"); - for (i = 0; i < FLUID_PROF_LAST; i++) { - if (fluid_profile_data[i].count > 0) { - FLUID_LOG(FLUID_INFO, "%s: %.3f/%.3f/%.3f", - fluid_profile_data[i].description, - fluid_profile_data[i].min, - fluid_profile_data[i].total / fluid_profile_data[i].count, - fluid_profile_data[i].max); - } else { - FLUID_LOG(FLUID_DBG, "%s: no profiling available", fluid_profile_data[i].description); - } + for (i = 0; i < FLUID_PROF_LAST; i++) { + if (fluid_profile_data[i].count > 0) { + FLUID_LOG(FLUID_INFO, "%s: %.3f/%.3f/%.3f", + fluid_profile_data[i].description, + fluid_profile_data[i].min, + fluid_profile_data[i].total / fluid_profile_data[i].count, + fluid_profile_data[i].max); + } else { + FLUID_LOG(FLUID_DBG, "%s: no profiling available", fluid_profile_data[i].description); } + } } @@ -445,30 +445,17 @@ void fluid_profiling_print(void) * */ -#if OLD_GLIB_THREAD_API - -/* Rather than inline this one, we just declare it as a function, to prevent - * GCC warning about inline failure. */ -fluid_cond_t * -new_fluid_cond (void) -{ - if (!g_thread_supported ()) g_thread_init (NULL); - return g_cond_new (); -} - -#endif - static fluid_thread_return_t fluid_thread_high_prio (void *data) { - fluid_thread_info_t *info = data; + fluid_thread_info_t *info = data; - fluid_thread_self_set_prio (info->prio_level); + fluid_thread_self_set_prio (info->prio_level); - info->func (info->data); - FLUID_FREE (info); + info->func (info->data); + FLUID_FREE (info); - return FLUID_THREAD_RETURN_VALUE; + return FLUID_THREAD_RETURN_VALUE; } /** @@ -483,39 +470,39 @@ fluid_thread_high_prio (void *data) fluid_thread_t * new_fluid_thread (const char *name, fluid_thread_func_t func, void *data, int prio_level, int detach) { - fluid_thread_t *thread; - fluid_thread_info_t *info; + fluid_thread_t *thread; + fluid_thread_info_t *info; - fluid_return_val_if_fail (func != NULL, NULL); + fluid_return_val_if_fail (func != NULL, NULL); - thread = FLUID_NEW(fluid_thread_t); - if (prio_level > 0) { - info = FLUID_NEW (fluid_thread_info_t); + thread = FLUID_NEW(fluid_thread_t); + if (prio_level > 0) { + info = FLUID_NEW (fluid_thread_info_t); - if (!info) { - FLUID_LOG(FLUID_ERR, "Out of memory"); - return NULL; - } - - info->func = func; - info->data = data; - info->prio_level = prio_level; - data = info; - func = fluid_thread_high_prio; + if (!info) { + FLUID_LOG(FLUID_ERR, "Out of memory"); + return NULL; } - pthread_create(thread, NULL, func, data); + info->func = func; + info->data = data; + info->prio_level = prio_level; + data = info; + func = fluid_thread_high_prio; + } - if (!thread) { - FLUID_LOG(FLUID_ERR, "Failed to create the thread"); - return NULL; - } + pthread_create(thread, NULL, func, data); - if (detach) { - pthread_detach(*thread); - } + if (!thread) { + FLUID_LOG(FLUID_ERR, "Failed to create the thread"); + return NULL; + } + + if (detach) { + pthread_detach(*thread); + } - return thread; + return thread; } /** @@ -536,9 +523,9 @@ delete_fluid_thread(fluid_thread_t* thread) int fluid_thread_join(fluid_thread_t* thread) { - pthread_join(*thread, NULL); + pthread_join(*thread, NULL); - return FLUID_OK; + return FLUID_OK; } @@ -564,8 +551,8 @@ fluid_timer_run (void *data) if (!cont) break; /* to avoid incremental time errors, calculate the delay between - two callbacks bringing in the "absolute" time (count * - timer->msec) */ + two callbacks bringing in the "absolute" time (count * + timer->msec) */ delay = (count * timer->msec) - (fluid_curtime() - start); if (delay > 0) usleep (delay * 1000); } @@ -582,32 +569,32 @@ fluid_timer_t* new_fluid_timer (int msec, fluid_timer_callback_t callback, void* data, int new_thread, int auto_destroy, int high_priority) { - fluid_timer_t *timer; + fluid_timer_t *timer; - timer = FLUID_NEW (fluid_timer_t); + timer = FLUID_NEW (fluid_timer_t); - if (timer == NULL) { - FLUID_LOG (FLUID_ERR, "Out of memory"); - return NULL; - } + if (timer == NULL) { + FLUID_LOG (FLUID_ERR, "Out of memory"); + return NULL; + } - timer->msec = msec; - timer->callback = callback; - timer->data = data; - timer->cont = TRUE ; - timer->thread = NULL; - timer->auto_destroy = auto_destroy; - - if (new_thread) { - timer->thread = new_fluid_thread ("timer", fluid_timer_run, timer, high_priority - ? FLUID_SYS_TIMER_HIGH_PRIO_LEVEL : 0, false); - if (!timer->thread) { - FLUID_FREE (timer); - return NULL; - } - } else fluid_timer_run (timer); /* Run directly, instead of as a separate thread */ + timer->msec = msec; + timer->callback = callback; + timer->data = data; + timer->cont = TRUE ; + timer->thread = NULL; + timer->auto_destroy = auto_destroy; + + if (new_thread) { + timer->thread = new_fluid_thread ("timer", fluid_timer_run, timer, high_priority + ? FLUID_SYS_TIMER_HIGH_PRIO_LEVEL : 0, false); + if (!timer->thread) { + FLUID_FREE (timer); + return NULL; + } + } else fluid_timer_run (timer); /* Run directly, instead of as a separate thread */ - return timer; + return timer; } void @@ -629,16 +616,16 @@ delete_fluid_timer (fluid_timer_t *timer) int fluid_timer_join (fluid_timer_t *timer) { - int auto_destroy; + int auto_destroy; - if (timer->thread) { - auto_destroy = timer->auto_destroy; - fluid_thread_join (timer->thread); + if (timer->thread) { + auto_destroy = timer->auto_destroy; + fluid_thread_join (timer->thread); - if (!auto_destroy) timer->thread = NULL; - } + if (!auto_destroy) timer->thread = NULL; + } - return FLUID_OK; + return FLUID_OK; } @@ -655,7 +642,7 @@ fluid_timer_join (fluid_timer_t *timer) fluid_istream_t fluid_get_stdin (void) { - return STDIN_FILENO; + return STDIN_FILENO; } /** @@ -665,7 +652,7 @@ fluid_get_stdin (void) fluid_ostream_t fluid_get_stdout (void) { - return STDOUT_FILENO; + return STDOUT_FILENO; } /** @@ -676,26 +663,8 @@ int fluid_istream_readline (fluid_istream_t in, fluid_ostream_t out, 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 -#endif - { - fluid_ostream_printf (out, "%s", prompt); - return fluid_istream_gets (in, buf, len); - } + fluid_ostream_printf (out, "%s", prompt); + return fluid_istream_gets (in, buf, len); } /** @@ -708,30 +677,30 @@ fluid_istream_readline (fluid_istream_t in, fluid_ostream_t out, char* prompt, static int fluid_istream_gets (fluid_istream_t in, char* buf, int len) { - char c; - int n; - - buf[len - 1] = 0; + char c; + int n; - while (--len > 0) { - n = read(in, &c, 1); - if (n == -1) return -1; + buf[len - 1] = 0; - if (n == 0) { - *buf++ = 0; - return 0; - } + while (--len > 0) { + n = read(in, &c, 1); + if (n == -1) return -1; - if (c == '\n') { - *buf++ = 0; - return 1; - } + if (n == 0) { + *buf++ = 0; + return 0; + } - /* Store all characters excluding CR */ - if (c != '\r') *buf++ = c; + if (c == '\n') { + *buf++ = 0; + return 1; } - return -1; + /* Store all characters excluding CR */ + if (c != '\r') *buf++ = c; + } + + return -1; } /** From 838a97984823da609e412da5fe1bbfc24e81f6c2 Mon Sep 17 00:00:00 2001 From: loki666 Date: Mon, 13 Nov 2017 14:15:59 +0100 Subject: [PATCH 04/34] fix new_fluid_timer --- src/utils/fluid_sys.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c index bb109a083..e881c9094 100644 --- a/src/utils/fluid_sys.c +++ b/src/utils/fluid_sys.c @@ -585,14 +585,25 @@ new_fluid_timer (int msec, fluid_timer_callback_t callback, void* data, timer->thread = NULL; timer->auto_destroy = auto_destroy; - if (new_thread) { + if (new_thread) + { timer->thread = new_fluid_thread ("timer", fluid_timer_run, timer, high_priority ? FLUID_SYS_TIMER_HIGH_PRIO_LEVEL : 0, false); - if (!timer->thread) { + if (!timer->thread) + { FLUID_FREE (timer); return NULL; } - } else fluid_timer_run (timer); /* Run directly, instead of as a separate thread */ + } + else + { + fluid_timer_run (timer); /* Run directly, instead of as a separate thread */ + if(auto_destroy) + { + /* do NOT return freed memory */ + return NULL; + } + } return timer; } From b03a403a68362d1440b32641bfe79dbe9d0ca383 Mon Sep 17 00:00:00 2001 From: loki666 Date: Fri, 15 Dec 2017 15:45:51 +0100 Subject: [PATCH 05/34] fix merge --- android/jni/config.h | 9 +++++++++ src/utils/fluid_sys.h | 13 +++++++++++++ src/utils/fluidsynth_priv.h | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/android/jni/config.h b/android/jni/config.h index fe8883e88..b161456e0 100644 --- a/android/jni/config.h +++ b/android/jni/config.h @@ -109,6 +109,15 @@ /* Define to 1 if you have the header file. */ #define HAVE_SYS_SOCKET_H 1 +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_SOUNDCARD_H */ diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index b0c27994a..84247d24a 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -219,6 +219,19 @@ 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, 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); +void delete_fluid_server_socket(fluid_server_socket_t* sock); +int fluid_server_socket_join(fluid_server_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); + + /* Profiling */ diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h index eee1f1f3c..2677ac5cc 100644 --- a/src/utils/fluidsynth_priv.h +++ b/src/utils/fluidsynth_priv.h @@ -265,8 +265,8 @@ do { strncpy(_dst,_src,_n); \ #define FLUID_ASSERT(a,b) #define FLUID_ASSERT_P(a,b) -#define FLUID_LIKELY G_LIKELY -#define FLUID_UNLIKELY G_UNLIKELY +#define FLUID_LIKELY(x) __builtin_expect(!!(x), 1) +#define FLUID_UNLIKELY(x) __builtin_expect(!!(x), 0) char* fluid_error(void); From 9bf7207e36a937f088737686dc677cae037c148e Mon Sep 17 00:00:00 2001 From: loki666 Date: Thu, 18 Jan 2018 15:28:29 +0100 Subject: [PATCH 06/34] switch to cmake --- android/.gitignore | 2 - android/Android.mk | 9 --- android/CMakeLists.txt | 64 +++++++++++++++++++ android/{jni => }/config.h | 0 .../{jni => }/include/fluidsynth/version.h | 0 android/jni/Android.mk | 63 ------------------ android/jni/Application.mk | 5 -- android/{jni => }/src/bindings/fluid_cmd.c | 0 android/{jni => }/src/drivers/fluid_adriver.c | 0 android/{jni => }/src/drivers/fluid_mdriver.c | 0 10 files changed, 64 insertions(+), 79 deletions(-) delete mode 100644 android/.gitignore delete mode 100644 android/Android.mk create mode 100644 android/CMakeLists.txt rename android/{jni => }/config.h (100%) rename android/{jni => }/include/fluidsynth/version.h (100%) delete mode 100644 android/jni/Android.mk delete mode 100644 android/jni/Application.mk rename android/{jni => }/src/bindings/fluid_cmd.c (100%) rename android/{jni => }/src/drivers/fluid_adriver.c (100%) rename android/{jni => }/src/drivers/fluid_mdriver.c (100%) diff --git a/android/.gitignore b/android/.gitignore deleted file mode 100644 index e0c35b993..000000000 --- a/android/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -obj/ -libs/ diff --git a/android/Android.mk b/android/Android.mk deleted file mode 100644 index 3ed58799e..000000000 --- a/android/Android.mk +++ /dev/null @@ -1,9 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_MODULE := fluidsynth_shared -LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libfluidsynth.so -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include $(LOCAL_PATH)/jni/include -TARGET_PLATFORM = android-14 - -include $(PREBUILT_SHARED_LIBRARY) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt new file mode 100644 index 000000000..18046eb17 --- /dev/null +++ b/android/CMakeLists.txt @@ -0,0 +1,64 @@ +cmake_minimum_required(VERSION 3.4.1) + +set(src_DIR ../src) + +set (fluidsynth_sources + ${src_DIR}/midi/fluid_midi.c + ${src_DIR}/midi/fluid_midi_router.c + ${src_DIR}/midi/fluid_seq.c + ${src_DIR}/midi/fluid_seqbind.c + ${src_DIR}/rvoice/fluid_adsr_env.c + ${src_DIR}/rvoice/fluid_chorus.c + ${src_DIR}/rvoice/fluid_iir_filter.c + ${src_DIR}/rvoice/fluid_lfo.c + ${src_DIR}/rvoice/fluid_rev.c + ${src_DIR}/rvoice/fluid_rvoice.c + ${src_DIR}/rvoice/fluid_rvoice_dsp.c + ${src_DIR}/rvoice/fluid_rvoice_event.c + ${src_DIR}/rvoice/fluid_rvoice_mixer.c + ${src_DIR}/sfloader/fluid_defsfont.c + ${src_DIR}/sfloader/fluid_ramsfont.c + ${src_DIR}/synth/fluid_chan.c + ${src_DIR}/synth/fluid_event.c + ${src_DIR}/synth/fluid_gen.c + ${src_DIR}/synth/fluid_mod.c + ${src_DIR}/synth/fluid_synth.c + ${src_DIR}/synth/fluid_tuning.c + ${src_DIR}/synth/fluid_voice.c + ${src_DIR}/utils/fluid_conv.c + ${src_DIR}/utils/fluid_hash.c + ${src_DIR}/utils/fluid_list.c + ${src_DIR}/utils/fluid_ringbuffer.c + ${src_DIR}/utils/fluid_settings.c + ${src_DIR}/bindings/fluid_filerenderer.c + ${src_DIR}/utils/fluid_sys.c + jni/src/bindings/fluid_cmd.c + jni/src/drivers/fluid_adriver.c + jni/src/drivers/fluid_mdriver.c + ) + +add_library(fluidsynth SHARED ${fluidsynth_sources}) + +# Specify directories which the compiler should look for headers +target_include_directories(fluidsynth PRIVATE + . include + ${src_DIR}/../include + ${src_DIR}/synth + ${src_DIR}/midi + ${src_DIR}/rvoice + ${src_DIR}/sfloader + ${src_DIR}/utils + ${src_DIR}/bindings + ${src_DIR}/drivers + ) + +target_include_directories(fluidsynth INTERFACE + . include + ${src_DIR}/../include + ) + +target_compile_options(fluidsynth PRIVATE -std=gnu11 + PRIVATE -Wall + PRIVATE -DHAVE_CONFIG_H + PRIVATE -Wno-unused-variable + PRIVATE "$<$:-Werror>") # Only include -Werror when building debug config \ No newline at end of file diff --git a/android/jni/config.h b/android/config.h similarity index 100% rename from android/jni/config.h rename to android/config.h diff --git a/android/jni/include/fluidsynth/version.h b/android/include/fluidsynth/version.h similarity index 100% rename from android/jni/include/fluidsynth/version.h rename to android/include/fluidsynth/version.h diff --git a/android/jni/Android.mk b/android/jni/Android.mk deleted file mode 100644 index 6d28e47af..000000000 --- a/android/jni/Android.mk +++ /dev/null @@ -1,63 +0,0 @@ -LOCAL_PATH := $(call my-dir)/../.. -include $(CLEAR_VARS) - -LOCAL_MODULE := fluidsynth - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/android/jni \ - $(LOCAL_PATH)/android/jni/include \ - $(LOCAL_PATH)/include \ - $(LOCAL_PATH)/src/synth \ - $(LOCAL_PATH)/src/midi \ - $(LOCAL_PATH)/src/rvoice \ - $(LOCAL_PATH)/src/sfloader \ - $(LOCAL_PATH)/src/utils \ - $(LOCAL_PATH)/src/bindings \ - $(LOCAL_PATH)/src/drivers - -LOCAL_ARM_MODE := arm -LOCAL_CFLAGS += -DHAVE_CONFIG_H -Wall -Werror -std=gnu11 -Wno-unused-variable - -ifeq ($(TARGET_ARCH_ABI), armeabi-v7a) - LOCAL_CFLAGS += -DWITH_FLOAT -endif -ifeq ($(TARGET_ARCH_ABI), x86) - LOCAL_CFLAGS += -DWITH_FLOAT -endif - -LOCAL_SRC_FILES := \ - src/midi/fluid_midi.c \ - src/midi/fluid_midi_router.c \ - src/midi/fluid_seq.c \ - src/midi/fluid_seqbind.c \ - src/rvoice/fluid_adsr_env.c \ - src/rvoice/fluid_chorus.c \ - src/rvoice/fluid_iir_filter.c \ - src/rvoice/fluid_lfo.c \ - src/rvoice/fluid_rev.c \ - src/rvoice/fluid_rvoice.c \ - src/rvoice/fluid_rvoice_dsp.c \ - src/rvoice/fluid_rvoice_event.c \ - src/rvoice/fluid_rvoice_mixer.c \ - src/sfloader/fluid_defsfont.c \ - src/sfloader/fluid_ramsfont.c \ - src/synth/fluid_chan.c \ - src/synth/fluid_event.c \ - src/synth/fluid_gen.c \ - src/synth/fluid_mod.c \ - src/synth/fluid_synth.c \ - src/synth/fluid_tuning.c \ - src/synth/fluid_voice.c \ - src/utils/fluid_conv.c \ - src/utils/fluid_hash.c \ - src/utils/fluid_list.c \ - src/utils/fluid_ringbuffer.c \ - src/utils/fluid_settings.c \ - src/bindings/fluid_filerenderer.c \ - src/utils/fluid_sys.c \ - android/jni/src/bindings/fluid_cmd.c \ - android/jni/src/drivers/fluid_adriver.c \ - android/jni/src/drivers/fluid_mdriver.c - -include $(BUILD_SHARED_LIBRARY) - diff --git a/android/jni/Application.mk b/android/jni/Application.mk deleted file mode 100644 index 485a8ac52..000000000 --- a/android/jni/Application.mk +++ /dev/null @@ -1,5 +0,0 @@ -APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 -APP_MODULES := fluidsynth -APP_PLATFORM := android-14 -APP_OPTIM := release -NDK_TOOLCHAIN_VERSION := clang diff --git a/android/jni/src/bindings/fluid_cmd.c b/android/src/bindings/fluid_cmd.c similarity index 100% rename from android/jni/src/bindings/fluid_cmd.c rename to android/src/bindings/fluid_cmd.c diff --git a/android/jni/src/drivers/fluid_adriver.c b/android/src/drivers/fluid_adriver.c similarity index 100% rename from android/jni/src/drivers/fluid_adriver.c rename to android/src/drivers/fluid_adriver.c diff --git a/android/jni/src/drivers/fluid_mdriver.c b/android/src/drivers/fluid_mdriver.c similarity index 100% rename from android/jni/src/drivers/fluid_mdriver.c rename to android/src/drivers/fluid_mdriver.c From 6df25fe08ea9a087bf5400dec47b7531c2f93ce1 Mon Sep 17 00:00:00 2001 From: loki666 Date: Thu, 18 Jan 2018 15:33:01 +0100 Subject: [PATCH 07/34] oops --- android/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 18046eb17..4cd0ce9f0 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -32,9 +32,9 @@ set (fluidsynth_sources ${src_DIR}/utils/fluid_settings.c ${src_DIR}/bindings/fluid_filerenderer.c ${src_DIR}/utils/fluid_sys.c - jni/src/bindings/fluid_cmd.c - jni/src/drivers/fluid_adriver.c - jni/src/drivers/fluid_mdriver.c + src/bindings/fluid_cmd.c + src/drivers/fluid_adriver.c + src/drivers/fluid_mdriver.c ) add_library(fluidsynth SHARED ${fluidsynth_sources}) From 2f80817514dd3232480b4605a624d4cab9a21c4e Mon Sep 17 00:00:00 2001 From: loki666 Date: Fri, 19 Jan 2018 11:17:40 +0100 Subject: [PATCH 08/34] use floats on 32bits arch --- android/CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 4cd0ce9f0..ba6a31602 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -39,6 +39,13 @@ set (fluidsynth_sources add_library(fluidsynth SHARED ${fluidsynth_sources}) +if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a") + target_compile_options(fluidsynth PRIVATE -DWITH_FLOAT) +endif() +if(CMAKE_ANDROID_ARCH_ABI STREQUAL "x86") + target_compile_options(fluidsynth PRIVATE -DWITH_FLOAT) +endif() + # Specify directories which the compiler should look for headers target_include_directories(fluidsynth PRIVATE . include From 1eb3433384af6a2eb780d1fc822b4133ed8b4cd6 Mon Sep 17 00:00:00 2001 From: loki666 Date: Fri, 19 Jan 2018 11:19:09 +0100 Subject: [PATCH 09/34] use ANDROID_ABI cmake variable --- android/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index ba6a31602..81c58bd53 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -39,10 +39,10 @@ set (fluidsynth_sources add_library(fluidsynth SHARED ${fluidsynth_sources}) -if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a") +if(ANDROID_ABI STREQUAL "armeabi-v7a") target_compile_options(fluidsynth PRIVATE -DWITH_FLOAT) endif() -if(CMAKE_ANDROID_ARCH_ABI STREQUAL "x86") +if(ANDROID_ABI STREQUAL "x86") target_compile_options(fluidsynth PRIVATE -DWITH_FLOAT) endif() From 58894b75c3700374e15c6a3a2f31602e96f939ee Mon Sep 17 00:00:00 2001 From: loki666 Date: Fri, 23 Feb 2018 11:36:26 +0100 Subject: [PATCH 10/34] build fluid_sfont.c --- android/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 81c58bd53..b025c653c 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -18,6 +18,7 @@ set (fluidsynth_sources ${src_DIR}/rvoice/fluid_rvoice_mixer.c ${src_DIR}/sfloader/fluid_defsfont.c ${src_DIR}/sfloader/fluid_ramsfont.c + ${src_DIR}/sfloader/fluid_sfont.c ${src_DIR}/synth/fluid_chan.c ${src_DIR}/synth/fluid_event.c ${src_DIR}/synth/fluid_gen.c @@ -68,4 +69,4 @@ target_compile_options(fluidsynth PRIVATE -std=gnu11 PRIVATE -Wall PRIVATE -DHAVE_CONFIG_H PRIVATE -Wno-unused-variable - PRIVATE "$<$:-Werror>") # Only include -Werror when building debug config \ No newline at end of file + PRIVATE "$<$:-Werror>") # Only include -Werror when building debug config From b1ab2b74a8af1dbff19235e02b53fc1cfc487198 Mon Sep 17 00:00:00 2001 From: loki666 Date: Wed, 7 Mar 2018 13:33:26 +0100 Subject: [PATCH 11/34] fix build --- android/CMakeLists.txt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index b025c653c..d28e442b7 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4.1) set(src_DIR ../src) -set (fluidsynth_sources +set(fluidsynth_sources ${src_DIR}/midi/fluid_midi.c ${src_DIR}/midi/fluid_midi_router.c ${src_DIR}/midi/fluid_seq.c @@ -18,7 +18,7 @@ set (fluidsynth_sources ${src_DIR}/rvoice/fluid_rvoice_mixer.c ${src_DIR}/sfloader/fluid_defsfont.c ${src_DIR}/sfloader/fluid_ramsfont.c - ${src_DIR}/sfloader/fluid_sfont.c + ${src_DIR}/sfloader/fluid_sfont.c ${src_DIR}/synth/fluid_chan.c ${src_DIR}/synth/fluid_event.c ${src_DIR}/synth/fluid_gen.c @@ -26,6 +26,7 @@ set (fluidsynth_sources ${src_DIR}/synth/fluid_synth.c ${src_DIR}/synth/fluid_tuning.c ${src_DIR}/synth/fluid_voice.c + ${src_DIR}/synth/fluid_synth_monopoly.c ${src_DIR}/utils/fluid_conv.c ${src_DIR}/utils/fluid_hash.c ${src_DIR}/utils/fluid_list.c @@ -36,7 +37,14 @@ set (fluidsynth_sources src/bindings/fluid_cmd.c src/drivers/fluid_adriver.c src/drivers/fluid_mdriver.c - ) +) + +set ( public_main_HEADER + ${CMAKE_BINARY_DIR}/include/fluidsynth.h +) + +configure_file ( ../include/fluidsynth.cmake + ${public_main_HEADER} ) add_library(fluidsynth SHARED ${fluidsynth_sources}) @@ -58,11 +66,13 @@ target_include_directories(fluidsynth PRIVATE ${src_DIR}/utils ${src_DIR}/bindings ${src_DIR}/drivers + ${CMAKE_BINARY_DIR}/include ) target_include_directories(fluidsynth INTERFACE . include ${src_DIR}/../include + ${CMAKE_BINARY_DIR}/include ) target_compile_options(fluidsynth PRIVATE -std=gnu11 From 1d304303a84bfe8d499cfec4cd8468e98e8b12e3 Mon Sep 17 00:00:00 2001 From: loki666 Date: Sun, 8 Apr 2018 20:40:02 +0200 Subject: [PATCH 12/34] add files to android CMakeLists.txt --- android/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index d28e442b7..2d5473b89 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -19,6 +19,8 @@ set(fluidsynth_sources ${src_DIR}/sfloader/fluid_defsfont.c ${src_DIR}/sfloader/fluid_ramsfont.c ${src_DIR}/sfloader/fluid_sfont.c + ${src_DIR}/sfloader/fluid_sffile.c + ${src_DIR}/sfloader/fluid_samplecache.c ${src_DIR}/synth/fluid_chan.c ${src_DIR}/synth/fluid_event.c ${src_DIR}/synth/fluid_gen.c From 0a066c1b4d2b82bca48467c62837a3bdfe39627f Mon Sep 17 00:00:00 2001 From: loki666 Date: Sun, 8 Apr 2018 20:54:12 +0200 Subject: [PATCH 13/34] fix fluid_sys.h --- src/utils/fluid_sys.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 3dfade815..e58afde91 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -39,17 +39,6 @@ #include "fluidsynth_priv.h" -#include - -/** - * 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); @@ -235,8 +224,8 @@ fluid_istream_t fluid_socket_get_istream(fluid_socket_t sock); fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock); /* File access */ -typedef GStatBuf fluid_stat_buf_t; -#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf)) +typedef struct stat fluid_stat_buf_t; +#define fluid_stat(_filename, _statbuf) stat((_filename), (_statbuf)) /* Profiling */ From 0f871e7037f32d4f2f465154bbdaecf1352a34fd Mon Sep 17 00:00:00 2001 From: loki666 Date: Fri, 20 Apr 2018 11:22:48 +0200 Subject: [PATCH 14/34] register audio settings --- android/src/drivers/fluid_adriver.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/android/src/drivers/fluid_adriver.c b/android/src/drivers/fluid_adriver.c index 5d3921c8e..0998da8fc 100644 --- a/android/src/drivers/fluid_adriver.c +++ b/android/src/drivers/fluid_adriver.c @@ -23,5 +23,16 @@ void fluid_audio_driver_settings(fluid_settings_t* settings) { - // NOOP + /* Register audio settings */ + fluid_settings_register_str(settings, "audio.sample-format", "16bits", 0); + fluid_settings_add_option(settings, "audio.sample-format", "16bits"); + fluid_settings_add_option(settings, "audio.sample-format", "float"); + + fluid_settings_register_int(settings, "audio.period-size", 64, 64, 8192, 0); + fluid_settings_register_int(settings, "audio.periods", 16, 2, 64, 0); + + fluid_settings_register_int (settings, "audio.realtime-prio", + FLUID_DEFAULT_AUDIO_RT_PRIO, 0, 99, 0); + + fluid_settings_register_str(settings, "audio.driver", "", 0); } \ No newline at end of file From d4b4dd0e3ee0ef68a2e00841cc30a0f352b65f0d Mon Sep 17 00:00:00 2001 From: loki666 Date: Fri, 25 May 2018 11:33:36 +0200 Subject: [PATCH 15/34] fix FLUID_ASSERT --- src/utils/fluidsynth_priv.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h index 29b191991..d8993e900 100644 --- a/src/utils/fluidsynth_priv.h +++ b/src/utils/fluidsynth_priv.h @@ -299,7 +299,8 @@ do { strncpy(_dst,_src,_n); \ #ifdef NDEBUG #define FLUID_ASSERT(a) #else -#define FLUID_ASSERT(a) g_assert(a) +#include +#define FLUID_ASSERT(a) assert(a) #endif #define FLUID_LIKELY(x) __builtin_expect(!!(x), 1) From e34125808865dd58fcf1d607c6d18ca707081ccb Mon Sep 17 00:00:00 2001 From: loki666 Date: Mon, 11 Jun 2018 13:52:52 +0200 Subject: [PATCH 16/34] android: move android/CMakeLists.txt in /CMakeLists.txt --- CMakeLists.txt | 89 ++++++++++++++++++++++++++++++++++++++++++ android/CMakeLists.txt | 84 --------------------------------------- 2 files changed, 89 insertions(+), 84 deletions(-) delete mode 100644 android/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index bdd0b47db..3395e2760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,93 @@ # CMake based build system. Pedro Lopez-Cabanillas +if ( ANDROID ) + +cmake_minimum_required(VERSION 3.4.1) + +set(fluidsynth_sources + src/midi/fluid_midi.c + src/midi/fluid_midi_router.c + src/midi/fluid_seq.c + src/midi/fluid_seqbind.c + src/rvoice/fluid_adsr_env.c + src/rvoice/fluid_chorus.c + src/rvoice/fluid_iir_filter.c + src/rvoice/fluid_lfo.c + src/rvoice/fluid_rev.c + src/rvoice/fluid_rvoice.c + src/rvoice/fluid_rvoice_dsp.c + src/rvoice/fluid_rvoice_event.c + src/rvoice/fluid_rvoice_mixer.c + src/sfloader/fluid_defsfont.c + src/sfloader/fluid_ramsfont.c + src/sfloader/fluid_sfont.c + src/sfloader/fluid_sffile.c + src/sfloader/fluid_samplecache.c + src/synth/fluid_chan.c + src/synth/fluid_event.c + src/synth/fluid_gen.c + src/synth/fluid_mod.c + src/synth/fluid_synth.c + src/synth/fluid_tuning.c + src/synth/fluid_voice.c + src/synth/fluid_synth_monopoly.c + src/utils/fluid_conv.c + src/utils/fluid_hash.c + src/utils/fluid_list.c + src/utils/fluid_ringbuffer.c + src/utils/fluid_settings.c + src/bindings/fluid_filerenderer.c + src/utils/fluid_sys.c + android/src/bindings/fluid_cmd.c + android/src/drivers/fluid_adriver.c + android/src/drivers/fluid_mdriver.c +) + +set ( public_main_HEADER + ${CMAKE_BINARY_DIR}/include/fluidsynth.h +) + +configure_file ( include/fluidsynth.cmake + ${public_main_HEADER} ) + +add_library(fluidsynth SHARED ${fluidsynth_sources}) + +if(ANDROID_ABI STREQUAL "armeabi-v7a") + target_compile_options(fluidsynth PRIVATE -DWITH_FLOAT) +endif() +if(ANDROID_ABI STREQUAL "x86") + target_compile_options(fluidsynth PRIVATE -DWITH_FLOAT) +endif() + +# Specify directories which the compiler should look for headers +target_include_directories(fluidsynth PRIVATE + android android/include + include + src/synth + src/midi + src/rvoice + src/sfloader + src/utils + src/bindings + src/drivers + ${CMAKE_BINARY_DIR}/include + ) + +target_include_directories(fluidsynth INTERFACE + android android/include + include + ${CMAKE_BINARY_DIR}/include + ) + +target_compile_options(fluidsynth PRIVATE -std=gnu11 + PRIVATE -Wall + PRIVATE -DHAVE_CONFIG_H + PRIVATE -Wno-unused-variable + PRIVATE "$<$:-Werror>") # Only include -Werror when building debug config + +else ( ANDROID ) + cmake_minimum_required ( VERSION 3.1.0 ) # because of CMAKE_C_STANDARD project ( FluidSynth C ) set ( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_admin ) @@ -635,3 +722,5 @@ set ( CPACK_PACKAGE_NAME ${PACKAGE} ) set ( CPACK_STRIP_FILES ON ) include ( CPack ) + +endif ( ANDROID ) \ No newline at end of file diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt deleted file mode 100644 index 2d5473b89..000000000 --- a/android/CMakeLists.txt +++ /dev/null @@ -1,84 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) - -set(src_DIR ../src) - -set(fluidsynth_sources - ${src_DIR}/midi/fluid_midi.c - ${src_DIR}/midi/fluid_midi_router.c - ${src_DIR}/midi/fluid_seq.c - ${src_DIR}/midi/fluid_seqbind.c - ${src_DIR}/rvoice/fluid_adsr_env.c - ${src_DIR}/rvoice/fluid_chorus.c - ${src_DIR}/rvoice/fluid_iir_filter.c - ${src_DIR}/rvoice/fluid_lfo.c - ${src_DIR}/rvoice/fluid_rev.c - ${src_DIR}/rvoice/fluid_rvoice.c - ${src_DIR}/rvoice/fluid_rvoice_dsp.c - ${src_DIR}/rvoice/fluid_rvoice_event.c - ${src_DIR}/rvoice/fluid_rvoice_mixer.c - ${src_DIR}/sfloader/fluid_defsfont.c - ${src_DIR}/sfloader/fluid_ramsfont.c - ${src_DIR}/sfloader/fluid_sfont.c - ${src_DIR}/sfloader/fluid_sffile.c - ${src_DIR}/sfloader/fluid_samplecache.c - ${src_DIR}/synth/fluid_chan.c - ${src_DIR}/synth/fluid_event.c - ${src_DIR}/synth/fluid_gen.c - ${src_DIR}/synth/fluid_mod.c - ${src_DIR}/synth/fluid_synth.c - ${src_DIR}/synth/fluid_tuning.c - ${src_DIR}/synth/fluid_voice.c - ${src_DIR}/synth/fluid_synth_monopoly.c - ${src_DIR}/utils/fluid_conv.c - ${src_DIR}/utils/fluid_hash.c - ${src_DIR}/utils/fluid_list.c - ${src_DIR}/utils/fluid_ringbuffer.c - ${src_DIR}/utils/fluid_settings.c - ${src_DIR}/bindings/fluid_filerenderer.c - ${src_DIR}/utils/fluid_sys.c - src/bindings/fluid_cmd.c - src/drivers/fluid_adriver.c - src/drivers/fluid_mdriver.c -) - -set ( public_main_HEADER - ${CMAKE_BINARY_DIR}/include/fluidsynth.h -) - -configure_file ( ../include/fluidsynth.cmake - ${public_main_HEADER} ) - -add_library(fluidsynth SHARED ${fluidsynth_sources}) - -if(ANDROID_ABI STREQUAL "armeabi-v7a") - target_compile_options(fluidsynth PRIVATE -DWITH_FLOAT) -endif() -if(ANDROID_ABI STREQUAL "x86") - target_compile_options(fluidsynth PRIVATE -DWITH_FLOAT) -endif() - -# Specify directories which the compiler should look for headers -target_include_directories(fluidsynth PRIVATE - . include - ${src_DIR}/../include - ${src_DIR}/synth - ${src_DIR}/midi - ${src_DIR}/rvoice - ${src_DIR}/sfloader - ${src_DIR}/utils - ${src_DIR}/bindings - ${src_DIR}/drivers - ${CMAKE_BINARY_DIR}/include - ) - -target_include_directories(fluidsynth INTERFACE - . include - ${src_DIR}/../include - ${CMAKE_BINARY_DIR}/include - ) - -target_compile_options(fluidsynth PRIVATE -std=gnu11 - PRIVATE -Wall - PRIVATE -DHAVE_CONFIG_H - PRIVATE -Wno-unused-variable - PRIVATE "$<$:-Werror>") # Only include -Werror when building debug config From 9812648905e045efc5b55880847cddfc1cb2e683 Mon Sep 17 00:00:00 2001 From: loki666 Date: Mon, 2 Jul 2018 16:31:18 +0200 Subject: [PATCH 17/34] remove ramsfont --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 517a16152..3dbcc3588 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,6 @@ set(fluidsynth_sources src/rvoice/fluid_rvoice_event.c src/rvoice/fluid_rvoice_mixer.c src/sfloader/fluid_defsfont.c - src/sfloader/fluid_ramsfont.c src/sfloader/fluid_sfont.c src/sfloader/fluid_sffile.c src/sfloader/fluid_samplecache.c From e49105686ce2c2b29296a5f91fc3b1f7752475c6 Mon Sep 17 00:00:00 2001 From: Philippe Simons Date: Wed, 14 Nov 2018 16:31:07 +0100 Subject: [PATCH 18/34] Update fluidsynth_priv.h --- src/utils/fluidsynth_priv.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h index cde1d67f8..c08a76606 100644 --- a/src/utils/fluidsynth_priv.h +++ b/src/utils/fluidsynth_priv.h @@ -115,8 +115,6 @@ #include #endif -<<<<<<< HEAD -======= #if defined(WIN32) && HAVE_WINDOWS_H #include #include /* Provides also socklen_t */ @@ -142,7 +140,6 @@ #endif ->>>>>>> 417dc59ffd45b31d57ca3cd376b1148b4c9c09d3 #include "fluidsynth.h" From 95df4b0e272dd8713c88a33c77d3b008e35f4791 Mon Sep 17 00:00:00 2001 From: Philippe Simons Date: Wed, 14 Nov 2018 16:38:32 +0100 Subject: [PATCH 19/34] Update CMakeLists.txt --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f10f0c3f..1d48e528b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ endif() target_include_directories(fluidsynth PRIVATE android android/include include + src src/synth src/midi src/rvoice @@ -789,4 +790,4 @@ set ( CPACK_STRIP_FILES ON ) include ( CPack ) -endif ( ANDROID ) \ No newline at end of file +endif ( ANDROID ) From 619bd9e168eb99f79b7155c078f16e21cc4336cb Mon Sep 17 00:00:00 2001 From: Philippe Simons Date: Thu, 15 Nov 2018 09:51:38 +0100 Subject: [PATCH 20/34] Update CMakeLists.txt --- CMakeLists.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d48e528b..3dc05e876 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ endif() target_include_directories(fluidsynth PRIVATE android android/include include - src + src src/synth src/midi src/rvoice @@ -90,6 +90,7 @@ target_include_directories(fluidsynth PRIVATE src/bindings src/drivers ${CMAKE_BINARY_DIR}/include + ${CMAKE_BINARY_DIR} ) target_include_directories(fluidsynth INTERFACE @@ -104,6 +105,18 @@ target_compile_options(fluidsynth PRIVATE -std=gnu11 PRIVATE -Wno-unused-variable PRIVATE "$<$:-Werror>") # Only include -Werror when building debug config +# ******* Auto Generated Lookup Tables ****** + +include(ExternalProject) +ExternalProject_Add(gentables + DOWNLOAD_COMMAND "" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/gentables + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/gentables + INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/src/gentables/make_tables${CMAKE_EXECUTABLE_SUFFIX} "${CMAKE_BINARY_DIR}/" + CMAKE_GENERATOR "Unix Makefiles" + ) +add_dependencies(fluidsynth gentables) + else ( ANDROID ) cmake_minimum_required ( VERSION 3.1.0 ) # because of CMAKE_C_STANDARD From 64cdbdfdec90974edd4bbd0697a7fa90ca47c15a Mon Sep 17 00:00:00 2001 From: Philippe Simons Date: Sun, 18 Nov 2018 18:07:59 +0100 Subject: [PATCH 21/34] use upstream fluid_adriver.c and fluid_mdriver.c --- CMakeLists.txt | 4 +-- android/include/fluidsynth/version.h | 2 +- android/src/drivers/fluid_adriver.c | 38 ---------------------------- android/src/drivers/fluid_mdriver.c | 27 -------------------- 4 files changed, 3 insertions(+), 68 deletions(-) delete mode 100644 android/src/drivers/fluid_adriver.c delete mode 100644 android/src/drivers/fluid_mdriver.c diff --git a/CMakeLists.txt b/CMakeLists.txt index fcec1486e..dbfc6b47e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,8 +57,8 @@ set(fluidsynth_sources src/bindings/fluid_filerenderer.c src/utils/fluid_sys.c android/src/bindings/fluid_cmd.c - android/src/drivers/fluid_adriver.c - android/src/drivers/fluid_mdriver.c + src/drivers/fluid_adriver.c + src/drivers/fluid_mdriver.c ) set ( public_main_HEADER diff --git a/android/include/fluidsynth/version.h b/android/include/fluidsynth/version.h index 06b91d7cc..77006533d 100644 --- a/android/include/fluidsynth/version.h +++ b/android/include/fluidsynth/version.h @@ -31,7 +31,7 @@ extern "C" { * @brief Library version functions and defines */ -#define FLUIDSYNTH_VERSION "1.1.9" /**< String constant of libfluidsynth version. */ +#define FLUIDSYNTH_VERSION "2.0.2" /**< String constant of libfluidsynth version. */ #define FLUIDSYNTH_VERSION_MAJOR 1 /**< libfluidsynth major version integer constant. */ #define FLUIDSYNTH_VERSION_MINOR 1 /**< libfluidsynth minor version integer constant. */ #define FLUIDSYNTH_VERSION_MICRO 9 /**< libfluidsynth micro version integer constant. */ diff --git a/android/src/drivers/fluid_adriver.c b/android/src/drivers/fluid_adriver.c deleted file mode 100644 index 0998da8fc..000000000 --- a/android/src/drivers/fluid_adriver.c +++ /dev/null @@ -1,38 +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 Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ - -#include "fluid_adriver.h" -#include "fluid_settings.h" - -void fluid_audio_driver_settings(fluid_settings_t* settings) -{ - /* Register audio settings */ - fluid_settings_register_str(settings, "audio.sample-format", "16bits", 0); - fluid_settings_add_option(settings, "audio.sample-format", "16bits"); - fluid_settings_add_option(settings, "audio.sample-format", "float"); - - fluid_settings_register_int(settings, "audio.period-size", 64, 64, 8192, 0); - fluid_settings_register_int(settings, "audio.periods", 16, 2, 64, 0); - - fluid_settings_register_int (settings, "audio.realtime-prio", - FLUID_DEFAULT_AUDIO_RT_PRIO, 0, 99, 0); - - fluid_settings_register_str(settings, "audio.driver", "", 0); -} \ No newline at end of file diff --git a/android/src/drivers/fluid_mdriver.c b/android/src/drivers/fluid_mdriver.c deleted file mode 100644 index e1602a8c3..000000000 --- a/android/src/drivers/fluid_mdriver.c +++ /dev/null @@ -1,27 +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 Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA - */ - -#include "fluid_mdriver.h" -#include "fluid_settings.h" - -void fluid_midi_driver_settings(fluid_settings_t* settings) -{ - // NOOP -} \ No newline at end of file From b2b19072ef7491409f4ded9120183db775e34354 Mon Sep 17 00:00:00 2001 From: loki666 Date: Tue, 26 Feb 2019 13:05:40 +0100 Subject: [PATCH 22/34] fix merge --- src/sfloader/fluid_sfont.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sfloader/fluid_sfont.c b/src/sfloader/fluid_sfont.c index d0ce264d0..e29d1ee0c 100644 --- a/src/sfloader/fluid_sfont.c +++ b/src/sfloader/fluid_sfont.c @@ -25,7 +25,8 @@ void *default_fopen(const char *path) { FILE* handle; - + + #ifndef ANDROID if(!fluid_file_test(path, G_FILE_TEST_EXISTS)) { FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Unable to load non-existent file. ('%s')", path); @@ -37,6 +38,7 @@ void *default_fopen(const char *path) FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Refusing to load non-regular file! ('%s')", path); return NULL; } +#endif if((handle = FLUID_FOPEN(path, "rb")) == NULL) { From e3740cc670fc0840af4825eddb2507625964139e Mon Sep 17 00:00:00 2001 From: loki666 Date: Tue, 26 Feb 2019 13:07:25 +0100 Subject: [PATCH 23/34] update version --- android/include/fluidsynth/version.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/include/fluidsynth/version.h b/android/include/fluidsynth/version.h index 77006533d..456cf8eaf 100644 --- a/android/include/fluidsynth/version.h +++ b/android/include/fluidsynth/version.h @@ -31,10 +31,10 @@ extern "C" { * @brief Library version functions and defines */ -#define FLUIDSYNTH_VERSION "2.0.2" /**< String constant of libfluidsynth version. */ -#define FLUIDSYNTH_VERSION_MAJOR 1 /**< libfluidsynth major version integer constant. */ -#define FLUIDSYNTH_VERSION_MINOR 1 /**< libfluidsynth minor version integer constant. */ -#define FLUIDSYNTH_VERSION_MICRO 9 /**< libfluidsynth micro version integer constant. */ +#define FLUIDSYNTH_VERSION "2.0.4" /**< String constant of libfluidsynth version. */ +#define FLUIDSYNTH_VERSION_MAJOR 2 /**< libfluidsynth major version integer constant. */ +#define FLUIDSYNTH_VERSION_MINOR 0 /**< libfluidsynth minor version integer constant. */ +#define FLUIDSYNTH_VERSION_MICRO 4 /**< libfluidsynth micro version integer constant. */ FLUIDSYNTH_API void fluid_version(int *major, int *minor, int *micro); FLUIDSYNTH_API char* fluid_version_str(void); From 8435cd46ec25fed56784e6823aa66dd49a0ff977 Mon Sep 17 00:00:00 2001 From: loki666 Date: Tue, 26 Feb 2019 13:20:39 +0100 Subject: [PATCH 24/34] fix gentables build --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75056af48..e728a9549 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,7 +112,7 @@ ExternalProject_Add(gentables DOWNLOAD_COMMAND "" SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/gentables BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/gentables - INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/src/gentables/make_tables${CMAKE_EXECUTABLE_SUFFIX} "${CMAKE_BINARY_DIR}/" + INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/src/gentables/make_tables.exe "${CMAKE_BINARY_DIR}/" CMAKE_GENERATOR "Unix Makefiles" ) add_dependencies(fluidsynth gentables) From 0bb67a652a106ffb52ae8d493c148d08076449f2 Mon Sep 17 00:00:00 2001 From: loki666 Date: Tue, 26 Feb 2019 13:22:55 +0100 Subject: [PATCH 25/34] fix merge --- src/utils/fluidsynth_priv.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h index 32f529f2d..6e544b276 100644 --- a/src/utils/fluidsynth_priv.h +++ b/src/utils/fluidsynth_priv.h @@ -31,6 +31,7 @@ #if HAVE_CONFIG_H #include "config.h" +#endif #if HAVE_STDLIB_H #include // malloc, free From 487875f2efdde88920f6e6439d425071774cae9a Mon Sep 17 00:00:00 2001 From: loki666 Date: Tue, 26 Feb 2019 13:24:19 +0100 Subject: [PATCH 26/34] fix merge --- src/midi/fluid_midi.c | 2 ++ src/sfloader/fluid_sffile.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/midi/fluid_midi.c b/src/midi/fluid_midi.c index 38c2bf6ef..385eacb6b 100644 --- a/src/midi/fluid_midi.c +++ b/src/midi/fluid_midi.c @@ -99,10 +99,12 @@ int fluid_is_midifile(const char *filename) do { + #ifndef ANDROID if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR)) { return retcode; } + #endif // file seems to exist and is a regular file or a symlink to such if((fp = FLUID_FOPEN(filename, "rb")) == NULL) diff --git a/src/sfloader/fluid_sffile.c b/src/sfloader/fluid_sffile.c index b5a641b63..8ae26a6f6 100644 --- a/src/sfloader/fluid_sffile.c +++ b/src/sfloader/fluid_sffile.c @@ -340,10 +340,12 @@ int fluid_is_soundfont(const char *filename) do { + #ifndef ANDROID if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR)) { return retcode; } + #endif // file seems to exist and is a regular file or a symlink to such if((fp = FLUID_FOPEN(filename, "rb")) == NULL) From 63cfb110a2bb80ad3532e3051c89d310bdc9fc79 Mon Sep 17 00:00:00 2001 From: loki666 Date: Tue, 26 Feb 2019 13:27:12 +0100 Subject: [PATCH 27/34] fix fluid_sys.h --- src/utils/fluid_sys.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index fe89ced32..fc45e839d 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -113,6 +113,10 @@ #if HAVE_STDINT_H #include +#if HAVE_PTHREAD_H +#include +#endif + #else /* Assume GLIB types */ From 96c388628acf5482b33e7719db79d43b26042d55 Mon Sep 17 00:00:00 2001 From: loki666 Date: Tue, 26 Feb 2019 13:28:35 +0100 Subject: [PATCH 28/34] fix fluid_sys.h --- src/utils/fluid_sys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index fc45e839d..700299cfe 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -161,7 +161,7 @@ typedef guint64 uint64_t; #define FLUID_INLINE inline -#define FLUID_POINTER_TO_UINT(x) ((uint) (unsigned long) (p)) +#define FLUID_POINTER_TO_UINT(p) ((uint) (unsigned long) (p)) #define FLUID_UINT_TO_POINTER(u) ((void*) (unsigned long) (u)) #define FLUID_POINTER_TO_INT(p) ((int) (long) (p)) #define FLUID_INT_TO_POINTER(i) ((void*) (long) (i)) From 00a2db311b92f4c17da54154a1fbeeb02f504b81 Mon Sep 17 00:00:00 2001 From: Roman Shterenzon Date: Wed, 25 Sep 2019 15:05:06 +0300 Subject: [PATCH 29/34] Fix build --- CMakeLists.txt | 2 +- src/utils/fluid_sys.h | 15 +-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e728a9549..684bca48d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ # CMake based build system. Pedro Lopez-Cabanillas if ( ANDROID ) - +enable_language(C) cmake_minimum_required(VERSION 3.4.1) set(fluidsynth_sources diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 700299cfe..737af0312 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -112,25 +112,12 @@ /** Integer types */ #if HAVE_STDINT_H #include +#endif #if HAVE_PTHREAD_H #include #endif -#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 */ From ee32185bf7b49902d18850f299b84095e9d2f262 Mon Sep 17 00:00:00 2001 From: Roman Shterenzon Date: Wed, 25 Sep 2019 22:12:06 +0300 Subject: [PATCH 30/34] C++ compilation fixes --- src/rvoice/fluid_adsr_env.h | 2 +- src/rvoice/fluid_rvoice_event.h | 2 +- src/utils/fluid_sys.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rvoice/fluid_adsr_env.h b/src/rvoice/fluid_adsr_env.h index 9ed652d0b..802cbfe2c 100644 --- a/src/rvoice/fluid_adsr_env.h +++ b/src/rvoice/fluid_adsr_env.h @@ -137,7 +137,7 @@ fluid_adsr_env_set_val(fluid_adsr_env_t *env, fluid_real_t val) static FLUID_INLINE fluid_adsr_env_section_t fluid_adsr_env_get_section(fluid_adsr_env_t *env) { - return env->section; + return (fluid_adsr_env_section_t)env->section; } static FLUID_INLINE void diff --git a/src/rvoice/fluid_rvoice_event.h b/src/rvoice/fluid_rvoice_event.h index d1fd8d62c..75953d17b 100644 --- a/src/rvoice/fluid_rvoice_event.h +++ b/src/rvoice/fluid_rvoice_event.h @@ -86,7 +86,7 @@ fluid_rvoice_eventhandler_get_finished_voice(fluid_rvoice_eventhandler_t *handle result = * (fluid_rvoice_t **) result; fluid_ringbuffer_next_outptr(handler->finished_voices); - return result; + return (fluid_rvoice_t *)result; } diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index b18aa8bbd..8066cb065 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -238,7 +238,7 @@ static FLUID_INLINE fluid_cond_mutex_t * new_fluid_cond_mutex(void) { fluid_cond_mutex_t *mutex; - mutex = malloc(sizeof(fluid_cond_mutex_t)); + mutex = (fluid_cond_mutex_t *)malloc(sizeof(fluid_cond_mutex_t)); fluid_cond_mutex_init(mutex); return mutex; } @@ -263,7 +263,7 @@ static FLUID_INLINE fluid_cond_t * new_fluid_cond(void) { fluid_cond_t *cond; - cond = malloc(sizeof(fluid_cond_t)); + cond = (fluid_cond_t *)malloc(sizeof(fluid_cond_t)); fluid_cond_init(cond); return cond; } From 26669aaae29f2bd5b0f45165b8a571eda156e9b9 Mon Sep 17 00:00:00 2001 From: Philippe Simons Date: Wed, 23 Oct 2019 12:49:10 +0200 Subject: [PATCH 31/34] Update fluid_sys.h --- src/utils/fluid_sys.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 8066cb065..e8d582f7a 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -148,10 +148,13 @@ #define FLUID_INLINE inline -#define FLUID_POINTER_TO_UINT(p) ((uint) (unsigned long) (p)) -#define FLUID_UINT_TO_POINTER(u) ((void*) (unsigned long) (u)) -#define FLUID_POINTER_TO_INT(p) ((int) (long) (p)) -#define FLUID_INT_TO_POINTER(i) ((void*) (long) (i)) + +/* Integer<->pointer conversion */ +#define FLUID_POINTER_TO_UINT(x) ((unsigned int)(uintptr_t)(x)) +#define FLUID_UINT_TO_POINTER(x) ((void *)(uintptr_t)(x)) +#define FLUID_POINTER_TO_INT(x) ((signed int)(intptr_t)(x)) +#define FLUID_INT_TO_POINTER(x) ((void *)(intptr_t)(x)) + #define FLUID_IS_BIG_ENDIAN false #define FLUID_LE32TOH(x) le32toh(x) From fde1c25c54e2bfcb398ec511a321f56acc095d4e Mon Sep 17 00:00:00 2001 From: loki666 Date: Thu, 9 Jan 2020 10:14:36 +0100 Subject: [PATCH 32/34] bump version strings to 2.1.0 --- android/include/fluidsynth/version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/include/fluidsynth/version.h b/android/include/fluidsynth/version.h index d3a5c9cc7..52a328372 100644 --- a/android/include/fluidsynth/version.h +++ b/android/include/fluidsynth/version.h @@ -31,10 +31,10 @@ extern "C" { * @brief Library version functions and defines */ -#define FLUIDSYNTH_VERSION "2.0.7" /**< String constant of libfluidsynth version. */ +#define FLUIDSYNTH_VERSION "2.1.0" /**< String constant of libfluidsynth version. */ #define FLUIDSYNTH_VERSION_MAJOR 2 /**< libfluidsynth major version integer constant. */ -#define FLUIDSYNTH_VERSION_MINOR 0 /**< libfluidsynth minor version integer constant. */ -#define FLUIDSYNTH_VERSION_MICRO 7 /**< libfluidsynth micro version integer constant. */ +#define FLUIDSYNTH_VERSION_MINOR 1 /**< libfluidsynth minor version integer constant. */ +#define FLUIDSYNTH_VERSION_MICRO 0 /**< libfluidsynth micro version integer constant. */ FLUIDSYNTH_API void fluid_version(int *major, int *minor, int *micro); FLUIDSYNTH_API char* fluid_version_str(void); From 679c63c9a5c7f988b9fdcb2ee2f7a57ae6062229 Mon Sep 17 00:00:00 2001 From: loki666 Date: Thu, 9 Jan 2020 10:48:26 +0100 Subject: [PATCH 33/34] fix for Android NDK --- CMakeLists.txt | 1 + android/config.h | 2 +- src/utils/fluid_sys.h | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77264360c..5fa7825ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,7 @@ target_compile_options(fluidsynth PRIVATE -std=gnu11 PRIVATE -Wall PRIVATE -DHAVE_CONFIG_H PRIVATE -Wno-unused-variable + PRIVATE -Wno-error=format PRIVATE "$<$:-Werror>") # Only include -Werror when building debug config # ******* Auto Generated Lookup Tables ****** diff --git a/android/config.h b/android/config.h index 93691a466..87f7a7911 100644 --- a/android/config.h +++ b/android/config.h @@ -194,7 +194,7 @@ /* #undef TRAP_ON_FPE */ /* Version number of package */ -#define VERSION "2.0.7" +#define VERSION "2.1.0" /* Define to do all DSP in single floating point precision */ /* #undef WITH_FLOAT */ diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 6e2c76029..b65583dbd 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -156,7 +156,7 @@ #define FLUID_INT_TO_POINTER(x) ((void *)(intptr_t)(x)) /* Endian detection */ -#define FLUID_IS_BIG_ENDIAN (G_BYTE_ORDER == G_BIG_ENDIAN) +#define FLUID_IS_BIG_ENDIAN false #define FLUID_LE32TOH(x) le32toh(x) #define FLUID_LE16TOH(x) le16toh(x) From cdeac3edc1b010309e282c4efd02fd8a60ec9cb4 Mon Sep 17 00:00:00 2001 From: Philippe Simons Date: Fri, 14 Feb 2020 09:32:18 +0100 Subject: [PATCH 34/34] add math floats functions defines --- android/config.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/android/config.h b/android/config.h index 87f7a7911..7a4417d4d 100644 --- a/android/config.h +++ b/android/config.h @@ -199,6 +199,13 @@ /* Define to do all DSP in single floating point precision */ /* #undef WITH_FLOAT */ +#define HAVE_SINF 1 +#define HAVE_COSF 1 +#define HAVE_FABSF 1 +#define HAVE_POWF 1 +#define HAVE_SQRTF 1 +#define HAVE_LOGF 1 + /* Define to profile the DSP code */ /* #undef WITH_PROFILING */