From 179f87f952bfefd52d1bc49301f1ba8494a5c456 Mon Sep 17 00:00:00 2001 From: derselbst Date: Mon, 30 Oct 2017 15:19:46 +0100 Subject: [PATCH] add a function for removing default modulators --- include/fluidsynth/synth.h | 1 + src/synth/fluid_synth.c | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/fluidsynth/synth.h b/include/fluidsynth/synth.h index fa279ef3..715786ca 100644 --- a/include/fluidsynth/synth.h +++ b/include/fluidsynth/synth.h @@ -295,6 +295,7 @@ enum fluid_synth_add_mod { }; FLUIDSYNTH_API int fluid_synth_add_default_mod(fluid_synth_t* synth, fluid_mod_t* mod, int mode); +FLUIDSYNTH_API int fluid_synth_remove_default_mod(fluid_synth_t* synth, const fluid_mod_t* mod); /* diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index dfbc4732..0ce78ef5 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -1157,6 +1157,46 @@ fluid_synth_add_default_mod(fluid_synth_t* synth, fluid_mod_t* mod, int mode) FLUID_API_RETURN(FLUID_OK); } +/** + * Removes the specified modulator \c mod from the synth's default modulator list. + * fluid_mod_test_identity() will be used to test modulator matching. + * @param synth synth instance + * @param mod The modulator to remove + * @return FLUID_OK if a matching modulator was found and successfully removed, FLUID_FAILED otherwise + */ +int +fluid_synth_remove_default_mod(fluid_synth_t* synth, const fluid_mod_t* mod) +{ + fluid_mod_t* default_mod; + fluid_mod_t* last_mod; + + fluid_return_val_if_fail (synth != NULL, FLUID_FAILED); + fluid_return_val_if_fail (mod != NULL, FLUID_FAILED); + fluid_synth_api_enter(synth); + + last_mod = default_mod = synth->default_mod; + + while (default_mod != NULL) { + if (fluid_mod_test_identity(default_mod, mod)) + { + if(synth->default_mod == default_mod) + { + synth->default_mod = synth->default_mod->next; + } + else + { + last_mod->next = default_mod->next; + } + fluid_mod_delete(default_mod); + FLUID_API_RETURN(FLUID_OK); + } + last_mod = default_mod; + default_mod = default_mod->next; + } + + FLUID_API_RETURN(FLUID_FAILED); +} + /** * Send a MIDI controller event on a MIDI channel.