split set mapping API. This leads to 3 API:

- fluid_synth_mixer_set_chan_to_out_mapping().
- fluid_synth_mixer_set_chan_to_fx_mapping().
- fluid_synth_mixer_set_fx_to_out_mapping().
This commit is contained in:
jjceresa 2020-09-16 02:59:56 +02:00
parent ce472b340c
commit b2cc3a6341
4 changed files with 120 additions and 149 deletions

View file

@ -392,11 +392,15 @@ FLUIDSYNTH_API int fluid_synth_get_breath_mode(fluid_synth_t *synth,
/* API: Mixer MIDI channels mapping */
FLUIDSYNTH_API int fluid_synth_mixer_get_channel_mapping(fluid_synth_t *synth,
int chan, int *out_from_chan, int *fx_from_chan);
FLUIDSYNTH_API int fluid_synth_mixer_get_fx_mapping(fluid_synth_t *synth, int fxunit_idx, int *out_idx);
FLUIDSYNTH_API int fluid_synth_mixer_set_mapping(fluid_synth_t *synth,
int chan_to_out, int out_from_chan,
int chan_to_fx, int fx_from_chan,
int chanfx_to_out, int out_from_fx);
FLUIDSYNTH_API int fluid_synth_mixer_get_fx_mapping(fluid_synth_t *synth,
int fxunit_idx, int *out_idx);
FLUIDSYNTH_API int fluid_synth_mixer_set_chan_to_out_mapping(fluid_synth_t *synth,
int chan, int out_idx);
FLUIDSYNTH_API int fluid_synth_mixer_set_chan_to_fx_mapping(fluid_synth_t *synth,
int chan, int fxunit_idx);
FLUIDSYNTH_API int fluid_synth_mixer_set_fx_to_out_mapping(fluid_synth_t *synth,
int fxunit_idx, int out_idx);
FLUIDSYNTH_API int fluid_synth_mixer_reset_mapping(fluid_synth_t *synth, int chan);
#ifdef __cplusplus

View file

@ -208,11 +208,11 @@ static const fluid_cmd_t fluid_commands[] =
},
{
"setchanmapfx", "mixer", fluid_handle_setchanmapfx,
"setchanmapfx chan0 out0 [chan1 out1..] Set MIDI channels mapping to fx unit"
"setchanmapfx chan0 fx0 [chan1 fx1..] Set MIDI channels mapping to fx unit"
},
{
"setchanfxmapout", "mixer", fluid_handle_setchanfxmapout,
"setchanfxmapout chan0 out0 [chan1 out1..] Set fx unit mapping to dry output"
"setfxmapout", "mixer", fluid_handle_setfxmapout,
"setfxmapout fx0 out0 [fx1 out1..] Set fx unit mapping to dry output"
},
/* reverb commands */
{
@ -3006,7 +3006,7 @@ int fluid_handle_legatomode(void *data, int ac, char **av,
@param nbr_arg_group_msg message when the number of argument by group is invalid.
@return 0 if arguments are valid, -1 otherwise.
*/
static int check_channels_group_arguments(int ac, char **av, int nbr_arg_group,
static int check_group_arguments(int ac, char **av, int nbr_arg_group,
fluid_ostream_t out,
char const *name_cde,
char const *nbr_arg_group_msg
@ -3023,7 +3023,7 @@ static int check_channels_group_arguments(int ac, char **av, int nbr_arg_group,
if(ac % nbr_arg_group)
{
/* each group entry needs nbr_arg_group parameters */
fluid_ostream_printf(out, "%s: channel %d, %s\n", name_cde,
fluid_ostream_printf(out, "%s: arg1 %d, %s\n", name_cde,
atoi(av[((ac / nbr_arg_group) * nbr_arg_group)]),
nbr_arg_group_msg);
return -1;
@ -3071,7 +3071,7 @@ int fluid_handle_setlegatomode(void *data, int ac, char **av,
int i, n ;
/* checks channels arguments by group of 2: chan1 val1 chan2 val1 .. ..*/
if(check_channels_group_arguments(ac, av, 2, out, name_cde, too_few_arg_chan_mode_msg) < 0)
if(check_group_arguments(ac, av, 2, out, name_cde, too_few_arg_chan_mode_msg) < 0)
{
return -1;
}
@ -3161,7 +3161,7 @@ int fluid_handle_setportamentomode(void *data, int ac, char **av,
int i, n ;
/* checks channels arguments by group of 2: chan1 val1 chan2 val1 .. .. */
if(check_channels_group_arguments(ac, av, 2, out, name_cde, too_few_arg_chan_mode_msg) < 0)
if(check_group_arguments(ac, av, 2, out, name_cde, too_few_arg_chan_mode_msg) < 0)
{
return -1;
}
@ -3307,7 +3307,7 @@ int fluid_handle_setbreathmode(void *data, int ac, char **av,
/* checks channels arguments by group of 4:
chan1 val1 val2 val3 chan2 val1 val2 val3 .... ....*/
if(check_channels_group_arguments(ac, av, 4, out, name_cde, too_few_arg_breath_msg) < 0)
if(check_group_arguments(ac, av, 4, out, name_cde, too_few_arg_breath_msg) < 0)
{
return -1;
}
@ -3583,7 +3583,7 @@ enum channel_mapping_type
{
MAP_CHAN_TO_OUT, /* mapping between MIDI channel and dry output index */
MAP_CHAN_TO_FX, /* mappping between MIDI channel and fx input index */
MAP_CHANFX_TO_OUT, /* mapping between FX output and dry output index */
MAP_FX_TO_OUT, /* mapping between fx unit output and dry output index */
NBR_MAPPING_TYPE
};
@ -3596,28 +3596,32 @@ enum channel_mapping_type
(MAP_CHAN_TO_FX) Any MIDI channel mapped to any fx unit input:
setchanmapfx chan0 fx0 [chan1 fx1 .. ..]
(MAP_CHANFX_TO_OUT) Any unit fx output mapped to any audio dry buffers:
setchanfxmapout chanfx0 out0 [chanfx1 out1 .. ..]
(MAP_FX_TO_OUT) Any unit fx output mapped to any audio dry buffers:
setfxmapout fx0 out0 [fx1 out1 .. ..]
*/
static int fluid_setchanmap(void *data, int ac, char **av,
static int fluid_handle_set_map(void *data, int ac, char **av,
fluid_ostream_t out, int map_type)
{
static const char *name_cde[NBR_MAPPING_TYPE] =
{"setchanmapout", "setchanmapfx", "setchanfxmapout"};
static const char *too_few_arg_chan_map_msg[NBR_MAPPING_TYPE] =
{"setchanmapout", "setchanmapfx", "setfxmapout"};
static const char *too_few_arg_map_msg[NBR_MAPPING_TYPE] =
{
"too few argument, chan out [chan out]...\n",
"too few argument, chan fx [chan fx]...\n",
"too few argument, chanfx out [chanfx out]...\n"
"too few argument, fx out [fx out]...\n"
};
static int (*map_func[NBR_MAPPING_TYPE]) (fluid_synth_t *, int, int);
FLUID_ENTRY_COMMAND(data);
fluid_synth_t *synth = handler->synth;
int i, n ;
/* checks channels arguments by group of 2: chan1 val1 chan2 val1 .. ..*/
if(check_channels_group_arguments(ac, av, 2, out, name_cde[map_type],
too_few_arg_chan_map_msg[map_type]) < 0)
map_func[MAP_CHAN_TO_OUT] = fluid_synth_mixer_set_chan_to_out_mapping;
map_func[MAP_CHAN_TO_FX] = fluid_synth_mixer_set_chan_to_fx_mapping;
map_func[MAP_FX_TO_OUT] = fluid_synth_mixer_set_fx_to_out_mapping;
/* checks arguments by group of 2: [arg1 arg2] [argr3 arg4] .. .. */
if(check_group_arguments(ac, av, 2, out, name_cde[map_type],
too_few_arg_map_msg[map_type]) < 0)
{
return -1;
}
@ -3626,27 +3630,15 @@ static int fluid_setchanmap(void *data, int ac, char **av,
for(i = 0; i < n; i++)
{
struct
{
int chan;
int val;
}chan_val[NBR_MAPPING_TYPE] ={-1,0,-1,0,-1,0}; /* set all chan parameter to -1*/
int chan, val, result;
chan_val[map_type].chan = chan = atoi(av[i * 2]);
chan_val[map_type].val = val = atoi(av[(i * 2) + 1]);
int arg1 = atoi(av[i * 2]);
int arg2 = atoi(av[(i * 2) + 1]);
/* set mapping */
result = fluid_synth_mixer_set_mapping(synth,
chan_val[MAP_CHAN_TO_OUT].chan,
chan_val[MAP_CHAN_TO_OUT].val,
chan_val[MAP_CHAN_TO_FX].chan,
chan_val[MAP_CHAN_TO_FX].val,
chan_val[MAP_CHANFX_TO_OUT].chan,
chan_val[MAP_CHANFX_TO_OUT].val);
int result = map_func[map_type](synth, arg1, arg2);
if(result == FLUID_FAILED)
{
fluid_ostream_printf(out, "%s: channel %3d, map to %3d, %s",
name_cde[map_type], chan, val, invalid_arg_msg);
fluid_ostream_printf(out, "%s: arg1 %3d, map to arg2 %3d, %s",
name_cde[map_type], arg1, arg2, invalid_arg_msg);
}
}
@ -3661,7 +3653,7 @@ static int fluid_setchanmap(void *data, int ac, char **av,
int fluid_handle_setchanmapout(void *data, int ac, char **av,
fluid_ostream_t out)
{
return fluid_setchanmap(data, ac, av, out, MAP_CHAN_TO_OUT);
return fluid_handle_set_map(data, ac, av, out, MAP_CHAN_TO_OUT);
}
/*-----------------------------------------------------------------------------
@ -3672,18 +3664,17 @@ int fluid_handle_setchanmapout(void *data, int ac, char **av,
int fluid_handle_setchanmapfx(void *data, int ac, char **av,
fluid_ostream_t out)
{
return fluid_setchanmap(data, ac, av, out, MAP_CHAN_TO_FX);
return fluid_handle_set_map(data, ac, av, out, MAP_CHAN_TO_FX);
}
/*-----------------------------------------------------------------------------
setchanfxmapout chanfx0 out0 [chanfx1 out1 .. ..]
setfxmapout fx0 out0 [fx1 out1 .. ..]
Set a mapping between fx unit (actually mapped to chanfx) and dry output index.
Set a mapping between fx unit and dry output index.
*/
int fluid_handle_setchanfxmapout(void *data, int ac, char **av,
fluid_ostream_t out)
int fluid_handle_setfxmapout(void *data, int ac, char **av, fluid_ostream_t out)
{
return fluid_setchanmap(data, ac, av, out, MAP_CHANFX_TO_OUT);
return fluid_handle_set_map(data, ac, av, out, MAP_FX_TO_OUT);
}
#ifdef LADSPA

View file

@ -108,7 +108,7 @@ int fluid_handle_fxmap(void *data, int ac, char **av,fluid_ostream_t out);
int fluid_handle_resetchanmap(void *data, int ac, char **av, fluid_ostream_t out);
int fluid_handle_setchanmapout(void *data, int ac, char **av, fluid_ostream_t out);
int fluid_handle_setchanmapfx(void *data, int ac, char **av, fluid_ostream_t out);
int fluid_handle_setchanfxmapout(void *data, int ac, char **av, fluid_ostream_t out);
int fluid_handle_setfxmapout(void *data, int ac, char **av, fluid_ostream_t out);
#ifdef LADSPA
int fluid_handle_ladspa_effect(void *data, int ac, char **av, fluid_ostream_t out);

View file

@ -7420,7 +7420,7 @@ int fluid_synth_get_basic_channel(fluid_synth_t *synth, int chan,
FLUID_API_RETURN(FLUID_OK);
}
/** API Mixer MIDI channel mapping ******************************************/
/** API Mixer MIDI channel mapping, fx unit mapping *************************/
/**
* Get mixer MIDI channel mapping to audio buffers.
@ -7429,7 +7429,7 @@ int fluid_synth_get_basic_channel(fluid_synth_t *synth, int chan,
* @param chan, MIDI channel to get mapping from.
* Must be in the range (0 to MIDI channel count - 1).
*
* @param out_from_chan, pointer on value to return dry output
* @param out_idx, pointer on value to return dry output
* index which is mapped to chan.(NULL to ignore the value).
*
* @param fx_from_chan, pointer on value to return fx unit index
@ -7439,20 +7439,20 @@ int fluid_synth_get_basic_channel(fluid_synth_t *synth, int chan,
*/
int
fluid_synth_mixer_get_channel_mapping(fluid_synth_t *synth, int chan,
int *out_from_chan, int *fx_from_chan)
int *out_idx, int *fxunit_idx)
{
FLUID_API_ENTRY_CHAN(FLUID_FAILED);
/* return audio output index mapped to chan if queried */
if(out_from_chan)
if(out_idx)
{
*out_from_chan = synth->channel[chan]->mapping_to_out;
*out_idx = synth->channel[chan]->mapping_to_out;
}
/* return fx unit input index mapped to chan if queried */
if(fx_from_chan)
if(fxunit_idx)
{
*fx_from_chan = synth->channel[chan]->mapping_to_fx;
*fxunit_idx = synth->channel[chan]->mapping_to_fx;
}
FLUID_API_RETURN(FLUID_OK);
@ -7488,115 +7488,91 @@ fluid_synth_mixer_get_fx_mapping(fluid_synth_t *synth, int fxunit_idx, int *out_
}
/**
* Set mixer MIDI channel mapping to audio buffers.
* These mapping allows:
* (1) Any MIDI channels mapped to any audio dry buffers.
* (2) Any MIDI channel mapped to any fx unit input .
* (3) Any unit fx output mapped to any audio dry buffers.
*
* The function allows the setting of mapping (1) or/and(2) or/and (3)
* simultaneously or not:
* 1)Mapping between MIDI channel chan_to_out and audio dry output at
* index out_from_chan. If chan_to_out is -1 this mapping is ignored,
* otherwise the mapping is done with the following special case:
* if out_from_chan is -1, this disable dry audio for this MIDI channel.
* This allows playing only fx (with dry muted temporarily).
* Set mixer MIDI channel mapping to audio buffers. This allows any
* MIDI channels mapped to any audio dry buffers output.
*
* @param synth FluidSynth instance.
* @param chan_to_out, MIDI channel to which out_from_chan must be mapped.
* Must be in the range (-1 to MIDI channel count-1).
* @param out_from_chan, audio output index to map to chan_to_out.
* @param chan, MIDI channel to which out_idx must be mapped.
* Must be in the range (0 to MIDI channel count-1).
* @param out_idx, audio output index to map to chan.
* Must be in the range (-1 to synth->audio_groups-1).
* If -1, this disable dry audio for this MIDI channel.
* This allows playing only fx (with dry muted temporarily).
*
* 2)Mapping between MIDI channel chan_to_fx and fx unit input at
* index fx_from_chan. If chan_to_fx is -1 this mapping is ignored,
* otherwise the mapping is done with the following special case:
* if fx_from_chan is -1, this disable fx audio for this MIDI channel.
* This allows playing only dry (with fx muted temporarily).
*
* @param chan_to_fx, MIDI channel to which fx_from_chan must be mapped.
* Must be in the range (-1 to MIDI channel count-1).
* @param fx_from_chan, fx unit input index to map to chan_to_fx.
* @return #FLUID_OK on success, #FLUID_FAILED otherwise
*/
int
fluid_synth_mixer_set_chan_to_out_mapping(fluid_synth_t *synth,
int chan, int out_idx)
{
FLUID_API_ENTRY_CHAN(FLUID_FAILED);
/* check out_idx */
if((out_idx < -1) || (out_idx >= synth->audio_groups))
{
FLUID_API_RETURN(FLUID_FAILED);
}
/* Mapping between MIDI channel chan and audio output at index out_idx */
synth->channel[chan]->mapping_to_out = out_idx;
FLUID_API_RETURN(FLUID_OK);
}
/**
* Set mixer MIDI channel mapping to fx unit. This allows
* any MIDI channels mapped to any fx unit input.
* @param synth FluidSynth instance.
* @param chan, MIDI channel to which fxunit_idx must be mapped.
* Must be in the range (0 to MIDI channel count-1).
* @param fxunit_idx, fx unit index to map to chan.
* Must be in the range (-1 to synth->effects_groups-1).
* If -1, this disable fx audio for this MIDI channel.
* This allows playing only dry (with fx muted temporarily).
*
* 3)Mapping between fx unit output (which is mapped to chanfx_to_out) and
* audio dry output at index index out_from_fx. If chanfx_to_out is -1,
* this mapping is ignored.
*
* @param chanfx_to_out, indicates the fx unit (which is actually mapped
* to chanfx_to_out) whose output must be mapped with out_from_fx.
* Must be in the range (-1 to MIDI channel count-1).
* @param out_from_fx, audio output index that must be mapped to fx unit output
* (which is actually mapped to chanfx_to_out).
* @return #FLUID_OK on success, #FLUID_FAILED otherwise
*/
int
fluid_synth_mixer_set_chan_to_fx_mapping(fluid_synth_t *synth,
int chan, int fxunit_idx)
{
FLUID_API_ENTRY_CHAN(FLUID_FAILED);
/* check fxunit_idx */
if((fxunit_idx < -1) || (fxunit_idx >= synth->effects_groups))
{
FLUID_API_RETURN(FLUID_FAILED);
}
/* Mapping between MIDI channel chan and audio output at index out_idx */
synth->channel[chan]->mapping_to_fx = fxunit_idx;
FLUID_API_RETURN(FLUID_OK);
}
/**
* Set mixer fx unit mapping to to audio buffers. This allows any
* This allows any fx unit output mapped to any dry audio buffers output.
* @param synth FluidSynth instance.
* @param fxunit_idx, fx unit index to which out_idx must be mapped.
* Must be in the range (0 to synth->effects_groups-1).
* @param out_idx, audio output index to map to chan.
* Must be in the range (0 to synth->audio_groups-1).
*
* @return #FLUID_OK on success, #FLUID_FAILED otherwise
*/
int
fluid_synth_mixer_set_mapping(fluid_synth_t *synth,
int chan_to_out, int out_from_chan,
int chan_to_fx, int fx_from_chan,
int chanfx_to_out, int out_from_fx)
fluid_synth_mixer_set_fx_to_out_mapping(fluid_synth_t *synth,
int fxunit_idx, int out_idx)
{
int result = FLUID_OK;
int result;
fluid_return_val_if_fail(synth != NULL, FLUID_FAILED);
fluid_synth_api_enter(synth);
/* Map chan_to_out and audio dry output if queried */
if(chan_to_out >= 0)
{
/* check chan_to_out and out_from_chan */
if((chan_to_out >= synth->midi_channels)
||(out_from_chan < -1)
||(out_from_chan >= synth->audio_groups))
{
FLUID_API_RETURN(FLUID_FAILED);
}
/* Mapping between MIDI channel chan_to_out and audio dry output
at index out_from_chan.
*/
synth->channel[chan_to_out]->mapping_to_out = out_from_chan;
}
/* Map chan_to_fx and fx input index if queried */
if(chan_to_fx >= 0)
{
/* check chan_to_fx and fx_from_chan */
if((chan_to_fx >= synth->midi_channels)
||(fx_from_chan < -1)
||(fx_from_chan >= synth->effects_groups))
{
FLUID_API_RETURN(FLUID_FAILED);
}
/* Mapping between MIDI channel chan_to_fx and fx input
at index fx_from_chan.
*/
synth->channel[chan_to_fx]->mapping_to_fx = fx_from_chan;
}
/* Map fx unit output and audio dry output if queried */
if(chanfx_to_out >= 0)
{
int fxunit_idx; /* fx input which is actually mapped to chanfx_to_out*/
/* check chanfx_to_out and out_from_fx */
if(chanfx_to_out >= synth->midi_channels)
{
FLUID_API_RETURN(FLUID_FAILED);
}
/* get fx unit actually mapped to chanfx_fx_to out */
fxunit_idx = synth->channel[chanfx_to_out]->mapping_to_fx;
/* Mapping between fx unit output and audio dry output
at index index out_from_fx.
*/
result = fluid_rvoice_mixer_set_fx_out_mapping(synth->eventhandler->mixer,
fxunit_idx, out_from_fx);
}
/* Map fx unit output and audio dry output */
result = fluid_rvoice_mixer_set_fx_out_mapping(synth->eventhandler->mixer,
fxunit_idx, out_idx);
FLUID_API_RETURN(result);
}