From 179f87f952bfefd52d1bc49301f1ba8494a5c456 Mon Sep 17 00:00:00 2001 From: derselbst Date: Mon, 30 Oct 2017 15:19:46 +0100 Subject: [PATCH 1/2] 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. From abab1f87e4e22ceb91e869b8bc5dfc14436f2a61 Mon Sep 17 00:00:00 2001 From: derselbst Date: Mon, 30 Oct 2017 15:21:38 +0100 Subject: [PATCH 2/2] make modulator API const correct --- include/fluidsynth/mod.h | 20 ++++++++++---------- src/synth/fluid_mod.c | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/fluidsynth/mod.h b/include/fluidsynth/mod.h index d68b85f1..857a622e 100644 --- a/include/fluidsynth/mod.h +++ b/include/fluidsynth/mod.h @@ -76,18 +76,18 @@ FLUIDSYNTH_API void fluid_mod_set_source2(fluid_mod_t* mod, int src, int flags); FLUIDSYNTH_API void fluid_mod_set_dest(fluid_mod_t* mod, int dst); FLUIDSYNTH_API void fluid_mod_set_amount(fluid_mod_t* mod, double amount); -FLUIDSYNTH_API int fluid_mod_get_source1(fluid_mod_t* mod); -FLUIDSYNTH_API int fluid_mod_get_flags1(fluid_mod_t* mod); -FLUIDSYNTH_API int fluid_mod_get_source2(fluid_mod_t* mod); -FLUIDSYNTH_API int fluid_mod_get_flags2(fluid_mod_t* mod); -FLUIDSYNTH_API int fluid_mod_get_dest(fluid_mod_t* mod); -FLUIDSYNTH_API double fluid_mod_get_amount(fluid_mod_t* mod); +FLUIDSYNTH_API int fluid_mod_get_source1(const fluid_mod_t* mod); +FLUIDSYNTH_API int fluid_mod_get_flags1(const fluid_mod_t* mod); +FLUIDSYNTH_API int fluid_mod_get_source2(const fluid_mod_t* mod); +FLUIDSYNTH_API int fluid_mod_get_flags2(const fluid_mod_t* mod); +FLUIDSYNTH_API int fluid_mod_get_dest(const fluid_mod_t* mod); +FLUIDSYNTH_API double fluid_mod_get_amount(const fluid_mod_t* mod); -FLUIDSYNTH_API int fluid_mod_test_identity(fluid_mod_t * mod1, fluid_mod_t * mod2); -FLUIDSYNTH_API int fluid_mod_has_source(fluid_mod_t * mod, int cc, int ctrl); -FLUIDSYNTH_API int fluid_mod_has_dest(fluid_mod_t * mod, int gen); +FLUIDSYNTH_API int fluid_mod_test_identity(const fluid_mod_t * mod1, const fluid_mod_t * mod2); +FLUIDSYNTH_API int fluid_mod_has_source(const fluid_mod_t * mod, int cc, int ctrl); +FLUIDSYNTH_API int fluid_mod_has_dest(const fluid_mod_t * mod, int gen); -FLUIDSYNTH_API void fluid_mod_clone(fluid_mod_t* mod, fluid_mod_t* src); +FLUIDSYNTH_API void fluid_mod_clone(fluid_mod_t* mod, const fluid_mod_t* src); #ifdef __cplusplus } diff --git a/src/synth/fluid_mod.c b/src/synth/fluid_mod.c index 087b94c7..1dd7ec63 100644 --- a/src/synth/fluid_mod.c +++ b/src/synth/fluid_mod.c @@ -29,7 +29,7 @@ * @note The \c next member of \c mod will be left unchanged. */ void -fluid_mod_clone(fluid_mod_t* mod, fluid_mod_t* src) +fluid_mod_clone(fluid_mod_t* mod, const fluid_mod_t* src) { mod->dest = src->dest; mod->src1 = src->src1; @@ -97,7 +97,7 @@ fluid_mod_set_amount(fluid_mod_t* mod, double amount) * @return The primary source value (#fluid_mod_src or a MIDI CC controller value). */ int -fluid_mod_get_source1(fluid_mod_t* mod) +fluid_mod_get_source1(const fluid_mod_t* mod) { return mod->src1; } @@ -108,7 +108,7 @@ fluid_mod_get_source1(fluid_mod_t* mod) * @return The primary source flags (#fluid_mod_flags). */ int -fluid_mod_get_flags1(fluid_mod_t* mod) +fluid_mod_get_flags1(const fluid_mod_t* mod) { return mod->flags1; } @@ -119,7 +119,7 @@ fluid_mod_get_flags1(fluid_mod_t* mod) * @return The secondary source value (#fluid_mod_src or a MIDI CC controller value). */ int -fluid_mod_get_source2(fluid_mod_t* mod) +fluid_mod_get_source2(const fluid_mod_t* mod) { return mod->src2; } @@ -130,7 +130,7 @@ fluid_mod_get_source2(fluid_mod_t* mod) * @return The secondary source flags (#fluid_mod_flags). */ int -fluid_mod_get_flags2(fluid_mod_t* mod) +fluid_mod_get_flags2(const fluid_mod_t* mod) { return mod->flags2; } @@ -141,7 +141,7 @@ fluid_mod_get_flags2(fluid_mod_t* mod) * @return Destination generator (#fluid_gen_type) */ int -fluid_mod_get_dest(fluid_mod_t* mod) +fluid_mod_get_dest(const fluid_mod_t* mod) { return mod->dest; } @@ -152,7 +152,7 @@ fluid_mod_get_dest(fluid_mod_t* mod) * @return Scale amount */ double -fluid_mod_get_amount(fluid_mod_t* mod) +fluid_mod_get_amount(const fluid_mod_t* mod) { return (double) mod->amount; } @@ -412,7 +412,7 @@ fluid_mod_delete (fluid_mod_t *mod) * SF2.01 section 9.5.1 page 69, 'bullet' 3 defines 'identical'. */ int -fluid_mod_test_identity (fluid_mod_t *mod1, fluid_mod_t *mod2) +fluid_mod_test_identity (const fluid_mod_t *mod1, const fluid_mod_t *mod2) { return mod1->dest == mod2->dest && mod1->src1 == mod2->src1 @@ -429,7 +429,7 @@ fluid_mod_test_identity (fluid_mod_t *mod1, fluid_mod_t *mod2) * * @return TRUE if the modulator has the given source, FALSE otherwise. */ -int fluid_mod_has_source(fluid_mod_t * mod, int cc, int ctrl) +int fluid_mod_has_source(const fluid_mod_t * mod, int cc, int ctrl) { return ( @@ -450,7 +450,7 @@ int fluid_mod_has_source(fluid_mod_t * mod, int cc, int ctrl) * @param gen The destination generator of type #fluid_gen_type to check for * @return TRUE if the modulator has the given destination, FALSE otherwise. */ -int fluid_mod_has_dest(fluid_mod_t * mod, int gen) +int fluid_mod_has_dest(const fluid_mod_t * mod, int gen) { return mod->dest == gen; }