mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-04-22 07:30:50 +00:00
Merge pull request #506 from FluidSynth/cleanup21
Minor cleanup for 2.1
This commit is contained in:
commit
9f15fef192
11 changed files with 34 additions and 140 deletions
|
@ -1133,7 +1133,7 @@ new_fluid_preset_zone(char *name)
|
|||
/* Flag all generators as unused (default, they will be set when they are found
|
||||
* in the sound font).
|
||||
* This also sets the generator values to default, but that is of no concern here.*/
|
||||
fluid_gen_set_default_values(&zone->gen[0]);
|
||||
fluid_gen_init(&zone->gen[0], NULL);
|
||||
zone->mod = NULL; /* list of modulators */
|
||||
return zone;
|
||||
}
|
||||
|
@ -1843,7 +1843,7 @@ new_fluid_inst_zone(char *name)
|
|||
zone->range.ignore = FALSE;
|
||||
/* Flag the generators as unused.
|
||||
* This also sets the generator values to default, but they will be overwritten anyway, if used.*/
|
||||
fluid_gen_set_default_values(&zone->gen[0]);
|
||||
fluid_gen_init(&zone->gen[0], NULL);
|
||||
zone->mod = NULL; /* list of modulators */
|
||||
return zone;
|
||||
}
|
||||
|
|
|
@ -128,7 +128,6 @@ fluid_channel_init_ctrl(fluid_channel_t *chan, int is_all_ctrl_off)
|
|||
for(i = 0; i < GEN_LAST; i++)
|
||||
{
|
||||
chan->gen[i] = 0.0f;
|
||||
chan->gen_abs[i] = 0;
|
||||
}
|
||||
|
||||
if(is_all_ctrl_off)
|
||||
|
|
|
@ -129,18 +129,6 @@ struct _fluid_channel_t
|
|||
* applied to future notes. They are copied to a voice's generators
|
||||
* in fluid_voice_init(), which calls fluid_gen_init(). */
|
||||
fluid_real_t gen[GEN_LAST];
|
||||
|
||||
/* By default, the NRPN values are relative to the values of the
|
||||
* generators set in the SoundFont. For example, if the NRPN
|
||||
* specifies an attack of 100 msec then 100 msec will be added to the
|
||||
* combined attack time of the sound font and the modulators.
|
||||
*
|
||||
* However, it is useful to be able to specify the generator value
|
||||
* absolutely, completely ignoring the generators of the SoundFont
|
||||
* and the values of modulators. The gen_abs field, is a boolean
|
||||
* flag indicating whether the NRPN value is absolute or not.
|
||||
*/
|
||||
char gen_abs[GEN_LAST];
|
||||
};
|
||||
|
||||
fluid_channel_t *new_fluid_channel(fluid_synth_t *synth, int num);
|
||||
|
@ -200,9 +188,8 @@ void fluid_channel_get_sfont_bank_prog(fluid_channel_t *chan, int *sfont,
|
|||
#define fluid_channel_legato(_c) ((_c)->cc[LEGATO_SWITCH] >= 64)
|
||||
#define fluid_channel_sustained(_c) ((_c)->cc[SUSTAIN_SWITCH] >= 64)
|
||||
#define fluid_channel_sostenuto(_c) ((_c)->cc[SOSTENUTO_SWITCH] >= 64)
|
||||
#define fluid_channel_set_gen(_c, _n, _v, _a) { (_c)->gen[_n] = _v; (_c)->gen_abs[_n] = _a; }
|
||||
#define fluid_channel_set_gen(_c, _n, _v) { (_c)->gen[_n] = _v; }
|
||||
#define fluid_channel_get_gen(_c, _n) ((_c)->gen[_n])
|
||||
#define fluid_channel_get_gen_abs(_c, _n) ((_c)->gen_abs[_n])
|
||||
#define fluid_channel_get_min_note_length_ticks(chan) \
|
||||
((chan)->synth->min_note_length_ticks)
|
||||
|
||||
|
|
|
@ -92,14 +92,12 @@ static const fluid_gen_info_t fluid_gen_info[] =
|
|||
{ GEN_CUSTOM_FILTERQ, 1, 1, 0.0f, 960.0f, 0.0f }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set an array of generators to their default values.
|
||||
* @param gen Array of generators (should be #GEN_LAST in size).
|
||||
* @return Always returns #FLUID_OK
|
||||
/* fluid_gen_init
|
||||
*
|
||||
* Set an array of generators to their initial value
|
||||
*/
|
||||
int
|
||||
fluid_gen_set_default_values(fluid_gen_t *gen)
|
||||
void
|
||||
fluid_gen_init(fluid_gen_t *gen, fluid_channel_t *channel)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -107,39 +105,9 @@ fluid_gen_set_default_values(fluid_gen_t *gen)
|
|||
{
|
||||
gen[i].flags = GEN_UNUSED;
|
||||
gen[i].mod = 0.0;
|
||||
gen[i].nrpn = 0.0;
|
||||
gen[i].nrpn = (channel == NULL) ? 0.0 : fluid_channel_get_gen(channel, i);
|
||||
gen[i].val = fluid_gen_info[i].def;
|
||||
}
|
||||
|
||||
return FLUID_OK;
|
||||
}
|
||||
|
||||
|
||||
/* fluid_gen_init
|
||||
*
|
||||
* Set an array of generators to their initial value
|
||||
*/
|
||||
int
|
||||
fluid_gen_init(fluid_gen_t *gen, fluid_channel_t *channel)
|
||||
{
|
||||
int i;
|
||||
|
||||
fluid_gen_set_default_values(gen);
|
||||
|
||||
for(i = 0; i < GEN_LAST; i++)
|
||||
{
|
||||
gen[i].nrpn = fluid_channel_get_gen(channel, i);
|
||||
|
||||
/* This is an extension to the SoundFont standard. More
|
||||
* documentation is available at the fluid_synth_set_gen2()
|
||||
* function. */
|
||||
if(fluid_channel_get_gen_abs(channel, i))
|
||||
{
|
||||
gen[i].flags = GEN_ABS_NRPN;
|
||||
}
|
||||
}
|
||||
|
||||
return FLUID_OK;
|
||||
}
|
||||
|
||||
fluid_real_t fluid_gen_scale(int gen, float value)
|
||||
|
|
|
@ -31,7 +31,7 @@ typedef struct _fluid_gen_info_t
|
|||
char nrpn_scale; /* The scale to convert from NRPN (cfr. fluid_gen_map_nrpn()) */
|
||||
float min; /* The minimum value */
|
||||
float max; /* The maximum value */
|
||||
float def; /* The default value (cfr. fluid_gen_set_default_values()) */
|
||||
float def; /* The default value (cfr. fluid_gen_init()) */
|
||||
} fluid_gen_info_t;
|
||||
|
||||
/*
|
||||
|
@ -52,7 +52,6 @@ enum fluid_gen_flags
|
|||
{
|
||||
GEN_UNUSED, /**< Generator value is not set */
|
||||
GEN_SET, /**< Generator value is set */
|
||||
GEN_ABS_NRPN /**< Generator is an absolute value */
|
||||
};
|
||||
|
||||
#define fluid_gen_set_mod(_gen, _val) { (_gen)->mod = (double) (_val); }
|
||||
|
@ -60,8 +59,7 @@ enum fluid_gen_flags
|
|||
|
||||
fluid_real_t fluid_gen_scale(int gen, float value);
|
||||
fluid_real_t fluid_gen_scale_nrpn(int gen, int nrpn);
|
||||
int fluid_gen_init(fluid_gen_t *gen, fluid_channel_t *channel);
|
||||
int fluid_gen_set_default_values(fluid_gen_t *gen);
|
||||
void fluid_gen_init(fluid_gen_t *gen, fluid_channel_t *channel);
|
||||
|
||||
|
||||
#endif /* _FLUID_GEN_H */
|
||||
|
|
|
@ -109,7 +109,7 @@ static void fluid_synth_update_voice_tuning_LOCAL(fluid_synth_t *synth,
|
|||
static int fluid_synth_set_tuning_LOCAL(fluid_synth_t *synth, int chan,
|
||||
fluid_tuning_t *tuning, int apply);
|
||||
static void fluid_synth_set_gen_LOCAL(fluid_synth_t *synth, int chan,
|
||||
int param, float value, int absolute);
|
||||
int param, float value);
|
||||
static void fluid_synth_stop_LOCAL(fluid_synth_t *synth, unsigned int id);
|
||||
|
||||
|
||||
|
@ -1107,12 +1107,10 @@ delete_fluid_synth(fluid_synth_t *synth)
|
|||
* @deprecated This function is not thread-safe and does not work with multiple synths.
|
||||
* It has been deprecated. It may return "" in a future release and will eventually be removed.
|
||||
*/
|
||||
/* FIXME - The error messages are not thread-safe, yet. They are still stored
|
||||
* in a global message buffer (see fluid_sys.c). */
|
||||
const char *
|
||||
fluid_synth_error(fluid_synth_t *synth)
|
||||
{
|
||||
return fluid_error();
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1696,7 +1694,7 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
|
|||
if(nrpn_select < GEN_LAST)
|
||||
{
|
||||
float val = fluid_gen_scale_nrpn(nrpn_select, data);
|
||||
fluid_synth_set_gen_LOCAL(synth, channum, nrpn_select, val, FALSE);
|
||||
fluid_synth_set_gen_LOCAL(synth, channum, nrpn_select, val);
|
||||
}
|
||||
|
||||
chan->nrpn_select = 0; /* Reset to 0 */
|
||||
|
@ -1714,12 +1712,12 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
|
|||
|
||||
case RPN_CHANNEL_FINE_TUNE: /* Fine tune is 14 bit over +/-1 semitone (+/- 100 cents, 8192 = center) */
|
||||
fluid_synth_set_gen_LOCAL(synth, channum, GEN_FINETUNE,
|
||||
(data - 8192) / 8192.0 * 100.0, FALSE);
|
||||
(data - 8192) / 8192.0 * 100.0);
|
||||
break;
|
||||
|
||||
case RPN_CHANNEL_COARSE_TUNE: /* Coarse tune is 7 bit and in semitones (64 is center) */
|
||||
fluid_synth_set_gen_LOCAL(synth, channum, GEN_COARSETUNE,
|
||||
value - 64, FALSE);
|
||||
value - 64);
|
||||
break;
|
||||
|
||||
case RPN_TUNING_PROGRAM_CHANGE:
|
||||
|
@ -6119,51 +6117,22 @@ fluid_synth_get_settings(fluid_synth_t *synth)
|
|||
*/
|
||||
int fluid_synth_set_gen(fluid_synth_t *synth, int chan, int param, float value)
|
||||
{
|
||||
return fluid_synth_set_gen2(synth, chan, param, value, FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a SoundFont generator (effect) value on a MIDI channel in real-time.
|
||||
* @param synth FluidSynth instance
|
||||
* @param chan MIDI channel number (0 to MIDI channel count - 1)
|
||||
* @param param SoundFont generator ID (#fluid_gen_type)
|
||||
* @param value Offset or absolute generator value to assign to the MIDI channel
|
||||
* @param absolute FALSE to assign a relative value, TRUE to assign an absolute value
|
||||
* @param normalized FALSE if value is specified in the native units of the generator,
|
||||
* TRUE to take the value as a 0.0-1.0 range and apply it to the valid
|
||||
* generator effect range (scaled and shifted as necessary).
|
||||
* @return #FLUID_OK on success, #FLUID_FAILED otherwise
|
||||
*
|
||||
* This function allows for setting all effect parameters in real time on a
|
||||
* MIDI channel. Setting absolute to non-zero will cause the value to override
|
||||
* any generator values set in the instruments played on the MIDI channel.
|
||||
* See SoundFont 2.01 spec, paragraph 8.1.3, page 48 for details on SoundFont
|
||||
* generator parameters and valid ranges.
|
||||
*/
|
||||
int
|
||||
fluid_synth_set_gen2(fluid_synth_t *synth, int chan, int param,
|
||||
float value, int absolute, int normalized)
|
||||
{
|
||||
float v;
|
||||
fluid_return_val_if_fail(param >= 0 && param < GEN_LAST, FLUID_FAILED);
|
||||
FLUID_API_ENTRY_CHAN(FLUID_FAILED);
|
||||
|
||||
v = normalized ? fluid_gen_scale(param, value) : value;
|
||||
|
||||
fluid_synth_set_gen_LOCAL(synth, chan, param, v, absolute);
|
||||
fluid_synth_set_gen_LOCAL(synth, chan, param, value);
|
||||
|
||||
FLUID_API_RETURN(FLUID_OK);
|
||||
}
|
||||
|
||||
/* Synthesis thread local set gen function */
|
||||
static void
|
||||
fluid_synth_set_gen_LOCAL(fluid_synth_t *synth, int chan, int param, float value,
|
||||
int absolute)
|
||||
fluid_synth_set_gen_LOCAL(fluid_synth_t *synth, int chan, int param, float value)
|
||||
{
|
||||
fluid_voice_t *voice;
|
||||
int i;
|
||||
|
||||
fluid_channel_set_gen(synth->channel[chan], param, value, absolute);
|
||||
fluid_channel_set_gen(synth->channel[chan], param, value);
|
||||
|
||||
for(i = 0; i < synth->polyphony; i++)
|
||||
{
|
||||
|
@ -6171,7 +6140,7 @@ fluid_synth_set_gen_LOCAL(fluid_synth_t *synth, int chan, int param, float value
|
|||
|
||||
if(fluid_voice_get_channel(voice) == chan)
|
||||
{
|
||||
fluid_voice_set_param(voice, param, value, absolute);
|
||||
fluid_voice_set_param(voice, param, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,9 +209,6 @@ void delete_fluid_sample_timer(fluid_synth_t *synth, fluid_sample_timer_t *timer
|
|||
|
||||
void fluid_synth_process_event_queue(fluid_synth_t *synth);
|
||||
|
||||
int fluid_synth_set_gen2(fluid_synth_t *synth, int chan,
|
||||
int param, float value,
|
||||
int absolute, int normalized);
|
||||
/*
|
||||
* misc
|
||||
*/
|
||||
|
|
|
@ -428,17 +428,7 @@ fluid_voice_gen_get(fluid_voice_t *voice, int gen)
|
|||
|
||||
fluid_real_t fluid_voice_gen_value(const fluid_voice_t *voice, int num)
|
||||
{
|
||||
/* This is an extension to the SoundFont standard. More
|
||||
* documentation is available at the fluid_synth_set_gen2()
|
||||
* function. */
|
||||
if(voice->gen[num].flags == GEN_ABS_NRPN)
|
||||
{
|
||||
return (fluid_real_t) voice->gen[num].nrpn;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (fluid_real_t)(voice->gen[num].val + voice->gen[num].mod + voice->gen[num].nrpn);
|
||||
}
|
||||
return (fluid_real_t)(voice->gen[num].val + voice->gen[num].mod + voice->gen[num].nrpn);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -605,7 +595,7 @@ fluid_voice_calculate_runtime_synthesis_parameters(fluid_voice_t *voice)
|
|||
* - Add the output value to the modulation value of the generator.
|
||||
*
|
||||
* Note: The generators have been initialized with
|
||||
* fluid_gen_set_default_values.
|
||||
* fluid_gen_init().
|
||||
*/
|
||||
|
||||
for(i = 0; i < voice->mod_count; i++)
|
||||
|
@ -1789,10 +1779,10 @@ fluid_voice_get_lower_boundary_for_attenuation(fluid_voice_t *voice)
|
|||
|
||||
|
||||
|
||||
int fluid_voice_set_param(fluid_voice_t *voice, int gen, fluid_real_t nrpn_value, int abs)
|
||||
int fluid_voice_set_param(fluid_voice_t *voice, int gen, fluid_real_t nrpn_value)
|
||||
{
|
||||
voice->gen[gen].nrpn = nrpn_value;
|
||||
voice->gen[gen].flags = (abs) ? GEN_ABS_NRPN : GEN_SET;
|
||||
voice->gen[gen].flags = GEN_SET;
|
||||
fluid_voice_update_param(voice, gen);
|
||||
return FLUID_OK;
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ int fluid_voice_modulate(fluid_voice_t *voice, int cc, int ctrl);
|
|||
int fluid_voice_modulate_all(fluid_voice_t *voice);
|
||||
|
||||
/** Set the NRPN value of a generator. */
|
||||
int fluid_voice_set_param(fluid_voice_t *voice, int gen, fluid_real_t value, int abs);
|
||||
int fluid_voice_set_param(fluid_voice_t *voice, int gen, fluid_real_t value);
|
||||
|
||||
|
||||
/** Set the gain. */
|
||||
|
|
|
@ -73,9 +73,6 @@ struct _fluid_server_socket_t
|
|||
|
||||
static int fluid_istream_gets(fluid_istream_t in, char *buf, int len);
|
||||
|
||||
|
||||
static char fluid_errbuf[512]; /* buffer for error message */
|
||||
|
||||
static fluid_log_function_t fluid_log_function[LAST_LOG_LEVEL] =
|
||||
{
|
||||
fluid_default_log_function,
|
||||
|
@ -169,20 +166,20 @@ fluid_default_log_function(int level, const char *message, void *data)
|
|||
int
|
||||
fluid_log(int level, const char *fmt, ...)
|
||||
{
|
||||
fluid_log_function_t fun = NULL;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
FLUID_VSNPRINTF(fluid_errbuf, sizeof(fluid_errbuf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
if((level >= 0) && (level < LAST_LOG_LEVEL))
|
||||
{
|
||||
fun = fluid_log_function[level];
|
||||
fluid_log_function_t fun = fluid_log_function[level];
|
||||
|
||||
if(fun != NULL)
|
||||
{
|
||||
(*fun)(level, fluid_errbuf, fluid_log_user_data[level]);
|
||||
char errbuf[1024];
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
FLUID_VSNPRINTF(errbuf, sizeof(errbuf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
(*fun)(level, errbuf, fluid_log_user_data[level]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,15 +262,6 @@ char *fluid_strtok(char **str, char *delim)
|
|||
return token;
|
||||
}
|
||||
|
||||
/*
|
||||
* fluid_error
|
||||
*/
|
||||
char *
|
||||
fluid_error()
|
||||
{
|
||||
return fluid_errbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend the execution of the current thread for the specified amount of time.
|
||||
* @param milliseconds to wait.
|
||||
|
|
|
@ -233,8 +233,6 @@ do { strncpy(_dst,_src,_n); \
|
|||
#define FLUID_LIKELY G_LIKELY
|
||||
#define FLUID_UNLIKELY G_UNLIKELY
|
||||
|
||||
char *fluid_error(void);
|
||||
|
||||
/* Misc */
|
||||
#if defined(__INTEL_COMPILER)
|
||||
#define FLUID_RESTRICT restrict
|
||||
|
|
Loading…
Reference in a new issue