Merge pull request #263 from FluidSynth/rm-def-mod

support removing default modulators
This commit is contained in:
Tom M 2017-11-10 16:41:56 +01:00 committed by GitHub
commit 987aa33486
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 20 deletions

View file

@ -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_dest(fluid_mod_t* mod, int dst);
FLUIDSYNTH_API void fluid_mod_set_amount(fluid_mod_t* mod, double amount); 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_source1(const fluid_mod_t* mod);
FLUIDSYNTH_API int fluid_mod_get_flags1(fluid_mod_t* mod); FLUIDSYNTH_API int fluid_mod_get_flags1(const fluid_mod_t* mod);
FLUIDSYNTH_API int fluid_mod_get_source2(fluid_mod_t* mod); FLUIDSYNTH_API int fluid_mod_get_source2(const fluid_mod_t* mod);
FLUIDSYNTH_API int fluid_mod_get_flags2(fluid_mod_t* mod); FLUIDSYNTH_API int fluid_mod_get_flags2(const fluid_mod_t* mod);
FLUIDSYNTH_API int fluid_mod_get_dest(fluid_mod_t* mod); FLUIDSYNTH_API int fluid_mod_get_dest(const fluid_mod_t* mod);
FLUIDSYNTH_API double fluid_mod_get_amount(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_test_identity(const fluid_mod_t * mod1, const 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_source(const 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_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 #ifdef __cplusplus
} }

View file

@ -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_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);
/* /*

View file

@ -29,7 +29,7 @@
* @note The \c next member of \c mod will be left unchanged. * @note The \c next member of \c mod will be left unchanged.
*/ */
void 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->dest = src->dest;
mod->src1 = src->src1; 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). * @return The primary source value (#fluid_mod_src or a MIDI CC controller value).
*/ */
int int
fluid_mod_get_source1(fluid_mod_t* mod) fluid_mod_get_source1(const fluid_mod_t* mod)
{ {
return mod->src1; return mod->src1;
} }
@ -108,7 +108,7 @@ fluid_mod_get_source1(fluid_mod_t* mod)
* @return The primary source flags (#fluid_mod_flags). * @return The primary source flags (#fluid_mod_flags).
*/ */
int int
fluid_mod_get_flags1(fluid_mod_t* mod) fluid_mod_get_flags1(const fluid_mod_t* mod)
{ {
return mod->flags1; 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). * @return The secondary source value (#fluid_mod_src or a MIDI CC controller value).
*/ */
int int
fluid_mod_get_source2(fluid_mod_t* mod) fluid_mod_get_source2(const fluid_mod_t* mod)
{ {
return mod->src2; return mod->src2;
} }
@ -130,7 +130,7 @@ fluid_mod_get_source2(fluid_mod_t* mod)
* @return The secondary source flags (#fluid_mod_flags). * @return The secondary source flags (#fluid_mod_flags).
*/ */
int int
fluid_mod_get_flags2(fluid_mod_t* mod) fluid_mod_get_flags2(const fluid_mod_t* mod)
{ {
return mod->flags2; return mod->flags2;
} }
@ -141,7 +141,7 @@ fluid_mod_get_flags2(fluid_mod_t* mod)
* @return Destination generator (#fluid_gen_type) * @return Destination generator (#fluid_gen_type)
*/ */
int int
fluid_mod_get_dest(fluid_mod_t* mod) fluid_mod_get_dest(const fluid_mod_t* mod)
{ {
return mod->dest; return mod->dest;
} }
@ -152,7 +152,7 @@ fluid_mod_get_dest(fluid_mod_t* mod)
* @return Scale amount * @return Scale amount
*/ */
double double
fluid_mod_get_amount(fluid_mod_t* mod) fluid_mod_get_amount(const fluid_mod_t* mod)
{ {
return (double) mod->amount; 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'. * SF2.01 section 9.5.1 page 69, 'bullet' 3 defines 'identical'.
*/ */
int 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 return mod1->dest == mod2->dest
&& mod1->src1 == mod2->src1 && 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. * @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 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 * @param gen The destination generator of type #fluid_gen_type to check for
* @return TRUE if the modulator has the given destination, FALSE otherwise. * @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; return mod->dest == gen;
} }

View file

@ -1145,6 +1145,46 @@ fluid_synth_add_default_mod(fluid_synth_t* synth, fluid_mod_t* mod, int mode)
FLUID_API_RETURN(FLUID_OK); 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. * Send a MIDI controller event on a MIDI channel.