From 5da9451321b143dffee102c91e51b6d3a73e7193 Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 21 Sep 2017 10:52:48 +0200 Subject: [PATCH] move struct _fluid_mod_t to private header --- include/fluidsynth/mod.h | 24 +++---------------- src/sfloader/fluid_defsfont.h | 1 + src/synth/fluid_mod.c | 45 ++++++++++++++++++++++++++++++++--- src/synth/fluid_mod.h | 31 +++++++++++++++++------- 4 files changed, 68 insertions(+), 33 deletions(-) diff --git a/include/fluidsynth/mod.h b/include/fluidsynth/mod.h index a50c5218..d68b85f1 100644 --- a/include/fluidsynth/mod.h +++ b/include/fluidsynth/mod.h @@ -32,27 +32,6 @@ extern "C" { #define FLUID_NUM_MOD 64 /**< Maximum number of modulators in a voice */ -/** - * Modulator structure. See SoundFont 2.04 PDF section 8.2. - * - * @deprecated To be removed from the public API. - */ -struct _fluid_mod_t -{ - unsigned char dest; /**< Destination generator to control */ - unsigned char src1; /**< Source controller 1 */ - unsigned char flags1; /**< Source controller 1 flags */ - unsigned char src2; /**< Source controller 2 */ - unsigned char flags2; /**< Source controller 2 flags */ - double amount; /**< Multiplier amount */ - /* The 'next' field allows to link modulators into a list. It is - * not used in fluid_voice.c, there each voice allocates memory for a - * fixed number of modulators. Since there may be a huge number of - * different zones, this is more efficient. - */ - fluid_mod_t * next; -}; - /** * Flags defining the polarity, mapping function and type of a modulator source. * Compare with SoundFont 2.04 PDF section 8.2. @@ -105,7 +84,10 @@ 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_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 void fluid_mod_clone(fluid_mod_t* mod, fluid_mod_t* src); #ifdef __cplusplus } diff --git a/src/sfloader/fluid_defsfont.h b/src/sfloader/fluid_defsfont.h index 245d3e7f..ee0d0b75 100644 --- a/src/sfloader/fluid_defsfont.h +++ b/src/sfloader/fluid_defsfont.h @@ -28,6 +28,7 @@ #include "fluidsynth.h" #include "fluidsynth_priv.h" #include "fluid_list.h" +#include "fluid_mod.h" diff --git a/src/synth/fluid_mod.c b/src/synth/fluid_mod.c index eb9116c6..087b94c7 100644 --- a/src/synth/fluid_mod.c +++ b/src/synth/fluid_mod.c @@ -22,8 +22,11 @@ #include "fluid_chan.h" #include "fluid_voice.h" -/* - * fluid_mod_clone +/** + * Clone the modulators destination, sources, flags and amount. + * @param mod the modulator to store the copy to + * @param src the source modulator to retrieve the information from + * @note The \c next member of \c mod will be left unchanged. */ void fluid_mod_clone(fluid_mod_t* mod, fluid_mod_t* src) @@ -418,7 +421,43 @@ fluid_mod_test_identity (fluid_mod_t *mod1, fluid_mod_t *mod2) && mod1->flags2 == mod2->flags2; } +/** + * Check if the modulator has the given source. + * + * @param cc Boolean value indicating if ctrl is a CC controller or not + * @param ctrl The source to check for (if \c cc == FALSE : a value of type #fluid_mod_src, else the value of the MIDI CC to check for) + * + * @return TRUE if the modulator has the given source, FALSE otherwise. + */ +int fluid_mod_has_source(fluid_mod_t * mod, int cc, int ctrl) +{ + return + ( + ( + ((mod->src1 == ctrl) && ((mod->flags1 & FLUID_MOD_CC) != 0) && (cc != 0)) + || ((mod->src1 == ctrl) && ((mod->flags1 & FLUID_MOD_CC) == 0) && (cc == 0)) + ) + || + ( + ((mod->src2 == ctrl) && ((mod->flags2 & FLUID_MOD_CC) != 0) && (cc != 0)) + || ((mod->src2 == ctrl) && ((mod->flags2 & FLUID_MOD_CC) == 0) && (cc == 0)) + ) + ); +} + +/** + * Check if the modulator has the given destination. + * @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) +{ + return mod->dest == gen; +} + + /* debug function: Prints the contents of a modulator */ +#ifdef DEBUG void fluid_dump_modulator(fluid_mod_t * mod){ int src1=mod->src1; int dest=mod->dest; @@ -467,5 +506,5 @@ void fluid_dump_modulator(fluid_mod_t * mod){ }; /* switch dest */ printf(", amount %f flags %i src2 %i flags2 %i\n",amount, flags1, src2, flags2); }; - +#endif diff --git a/src/synth/fluid_mod.h b/src/synth/fluid_mod.h index 72dcc516..d34576da 100644 --- a/src/synth/fluid_mod.h +++ b/src/synth/fluid_mod.h @@ -24,17 +24,30 @@ #include "fluidsynth_priv.h" #include "fluid_conv.h" -void fluid_mod_clone(fluid_mod_t* mod, fluid_mod_t* src); +/** + * Modulator structure. See SoundFont 2.04 PDF section 8.2. + */ +struct _fluid_mod_t +{ + unsigned char dest; /**< Destination generator to control */ + unsigned char src1; /**< Source controller 1 */ + unsigned char flags1; /**< Source controller 1 flags */ + unsigned char src2; /**< Source controller 2 */ + unsigned char flags2; /**< Source controller 2 flags */ + double amount; /**< Multiplier amount */ + /* The 'next' field allows to link modulators into a list. It is + * not used in fluid_voice.c, there each voice allocates memory for a + * fixed number of modulators. Since there may be a huge number of + * different zones, this is more efficient. + */ + fluid_mod_t * next; +}; + fluid_real_t fluid_mod_get_value(fluid_mod_t* mod, fluid_channel_t* chan, fluid_voice_t* voice); + +#ifdef DEBUG void fluid_dump_modulator(fluid_mod_t * mod); - -#define fluid_mod_has_source(mod,cc,ctrl) \ -( ((((mod)->src1 == ctrl) && (((mod)->flags1 & FLUID_MOD_CC) != 0) && (cc != 0)) \ - || ((((mod)->src1 == ctrl) && (((mod)->flags1 & FLUID_MOD_CC) == 0) && (cc == 0)))) \ -|| ((((mod)->src2 == ctrl) && (((mod)->flags2 & FLUID_MOD_CC) != 0) && (cc != 0)) \ - || ((((mod)->src2 == ctrl) && (((mod)->flags2 & FLUID_MOD_CC) == 0) && (cc == 0))))) - -#define fluid_mod_has_dest(mod,gen) ((mod)->dest == gen) +#endif #endif /* _FLUID_MOD_H */