From 8a3eaf9b18a77c6aa41ef752b1f4fe3a876f89a0 Mon Sep 17 00:00:00 2001 From: jjceresa <32781294+jjceresa@users.noreply.github.com> Date: Sat, 2 May 2020 14:31:34 +0200 Subject: [PATCH] Make fluidsynth call ipatch_close() (#644) --- src/sfloader/fluid_instpatch.c | 5 +++++ src/sfloader/fluid_instpatch.h | 1 + src/synth/fluid_synth.c | 18 ++++++++++++++++-- src/utils/fluid_sys.h | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/sfloader/fluid_instpatch.c b/src/sfloader/fluid_instpatch.c index 77eef056..88c66e72 100644 --- a/src/sfloader/fluid_instpatch.c +++ b/src/sfloader/fluid_instpatch.c @@ -49,6 +49,11 @@ void fluid_instpatch_init(void) ipatch_init(); } +void fluid_instpatch_deinit(void) +{ + ipatch_close(); +} + static int delete_fluid_instpatch(fluid_instpatch_font_t *pfont); static const char *fluid_instpatch_sfont_get_name(fluid_sfont_t *sfont); diff --git a/src/sfloader/fluid_instpatch.h b/src/sfloader/fluid_instpatch.h index 1ef5f294..89071865 100644 --- a/src/sfloader/fluid_instpatch.h +++ b/src/sfloader/fluid_instpatch.h @@ -6,6 +6,7 @@ #include "fluid_settings.h" void fluid_instpatch_init(void); +void fluid_instpatch_deinit(void); fluid_sfloader_t *new_fluid_instpatch_loader(fluid_settings_t *settings); #endif // _FLUID_INSTPATCH_H diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 7541e77d..97a871b2 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -463,8 +463,10 @@ fluid_synth_init(void) fluid_mod_set_dest(&custom_balance_mod, GEN_CUSTOM_BALANCE); /* Destination: stereo balance */ /* Amount: 96 dB of attenuation (on the opposite channel) */ fluid_mod_set_amount(&custom_balance_mod, FLUID_PEAK_ATTENUATION); /* Amount: 960 */ - -#ifdef LIBINSTPATCH_SUPPORT + + /* libinstpatch <= 1.1.4 only supports calling init() once */ +#if defined(LIBINSTPATCH_SUPPORT) && \ + FLUID_VERSION_CHECK(IPATCH_VERSION_MAJOR,IPATCH_VERSION_MINOR,IPATCH_VERSION_PATCH) <= FLUID_VERSION_CHECK(1,1,4) /* defer libinstpatch init to fluid_instpatch.c to avoid #include "libinstpatch.h" */ fluid_instpatch_init(); #endif @@ -626,6 +628,12 @@ new_fluid_synth(fluid_settings_t *settings) FLUID_MEMSET(synth, 0, sizeof(fluid_synth_t)); +#if defined(LIBINSTPATCH_SUPPORT) && \ + FLUID_VERSION_CHECK(IPATCH_VERSION_MAJOR,IPATCH_VERSION_MINOR,IPATCH_VERSION_PATCH) > FLUID_VERSION_CHECK(1,1,4) + /* defer libinstpatch init to fluid_instpatch.c to avoid #include "libinstpatch.h" */ + fluid_instpatch_init(); +#endif + fluid_rec_mutex_init(synth->mutex); fluid_settings_getint(settings, "synth.threadsafe-api", &synth->use_mutex); synth->public_api_count = 0; @@ -1116,6 +1124,12 @@ delete_fluid_synth(fluid_synth_t *synth) fluid_rec_mutex_destroy(synth->mutex); FLUID_FREE(synth); + +#if defined(LIBINSTPATCH_SUPPORT) && \ + FLUID_VERSION_CHECK(IPATCH_VERSION_MAJOR,IPATCH_VERSION_MINOR,IPATCH_VERSION_PATCH) > FLUID_VERSION_CHECK(1,1,4) + /* defer libinstpatch deinit to fluid_instpatch.c to avoid #include "libinstpatch.h" */ + fluid_instpatch_deinit(); +#endif } /** diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 032b905d..c1644035 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -170,6 +170,8 @@ typedef gintptr intptr_t; #define FLUID_INLINE inline +#define FLUID_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) + /* Integer<->pointer conversion */ #define FLUID_POINTER_TO_UINT(x) ((unsigned int)(uintptr_t)(x)) #define FLUID_UINT_TO_POINTER(x) ((void *)(uintptr_t)(x))