mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-01-31 13:40:35 +00:00
Make plugin label optional when creating effect
This commit is contained in:
parent
a4312c65ed
commit
ea9c868c86
2 changed files with 34 additions and 13 deletions
|
@ -2096,22 +2096,24 @@ int fluid_handle_ladspa_effect(void* data, int ac, char **av, fluid_ostream_t ou
|
|||
{
|
||||
FLUID_ENTRY_COMMAND(data);
|
||||
fluid_ladspa_fx_t *fx = handler->synth->ladspa_fx;
|
||||
char *lib_name = NULL;
|
||||
char *plugin_name = NULL;
|
||||
int mode;
|
||||
float gain;
|
||||
|
||||
CHECK_LADSPA_ENABLED(fx, out);
|
||||
CHECK_LADSPA_INACTIVE(fx, out);
|
||||
|
||||
if (ac < 2 || ac > 5)
|
||||
if (ac < 2 || ac > 4)
|
||||
{
|
||||
fluid_ostream_printf(out, "ladspa_effect: invalid number of arguments\n");
|
||||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
if ((ac > 3) && (FLUID_STRCMP(av[3], "mix") == 0))
|
||||
if ((ac > 2) && (FLUID_STRCMP(av[2], "mix") == 0))
|
||||
{
|
||||
mode = FLUID_LADSPA_MODE_ADD;
|
||||
gain = (ac > 4) ? atof(av[4]) : 1.0f;
|
||||
gain = (ac > 3) ? atof(av[3]) : 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2119,9 +2121,11 @@ int fluid_handle_ladspa_effect(void* data, int ac, char **av, fluid_ostream_t ou
|
|||
gain = 1.0f;
|
||||
}
|
||||
|
||||
if (fluid_ladspa_add_plugin(fx, av[0], av[1], av[2]) != FLUID_OK)
|
||||
fluid_ladspa_split(av[1], &lib_name, &plugin_name);
|
||||
|
||||
if (fluid_ladspa_add_plugin(fx, av[0], lib_name, plugin_name) != FLUID_OK)
|
||||
{
|
||||
fluid_ostream_printf(out, "Failed to add plugin\n");
|
||||
fluid_ostream_printf(out, "Failed to create effect\n");
|
||||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
|
|
|
@ -728,7 +728,7 @@ int fluid_ladspa_set_control_node(fluid_ladspa_fx_t *fx, const char *name, fluid
|
|||
* @param fx LADSPA effects instance
|
||||
* @param effect_name name of the effect (plugin instance)
|
||||
* @param lib_name filename of ladspa plugin library
|
||||
* @param plugin_name plugin name (the unique label of the plugin in the LADSPA library)
|
||||
* @param plugin_name optional, plugin name if there is more than one plugin in the library
|
||||
* @return FLUID_OK on success, otherwise FLUID_FAILED
|
||||
*/
|
||||
int fluid_ladspa_add_plugin(fluid_ladspa_fx_t *fx, const char *effect_name,
|
||||
|
@ -1040,6 +1040,8 @@ static int get_plugin_port_idx(const fluid_ladspa_plugin_t *plugin, const char *
|
|||
/**
|
||||
* Return a LADSPA descriptor structure for a plugin in a LADSPA library.
|
||||
*
|
||||
* If name is optional if the library contains only one plugin.
|
||||
*
|
||||
* @param lib pointer to fluid_ladspa_lib_t instance
|
||||
* @param name name (LADSPA Label) of the plugin
|
||||
* @return pointer to LADSPA_Descriptor, NULL on error or if not found
|
||||
|
@ -1047,32 +1049,47 @@ static int get_plugin_port_idx(const fluid_ladspa_plugin_t *plugin, const char *
|
|||
static const LADSPA_Descriptor *get_plugin_descriptor(const fluid_ladspa_lib_t *lib, const char *name)
|
||||
{
|
||||
const LADSPA_Descriptor *desc;
|
||||
const LADSPA_Descriptor *last_desc = NULL;
|
||||
int i = 0;
|
||||
|
||||
while (1)
|
||||
for (i = 0; /* endless */; i++)
|
||||
{
|
||||
desc = lib->descriptor(i++);
|
||||
desc = lib->descriptor(i);
|
||||
if (desc == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
if (FLUID_STRCMP(desc->Label, name) == 0)
|
||||
if (name != NULL && FLUID_STRCMP(desc->Label, name) == 0)
|
||||
{
|
||||
return desc;
|
||||
}
|
||||
|
||||
last_desc = desc;
|
||||
}
|
||||
|
||||
if (name == NULL)
|
||||
{
|
||||
if (i == 1)
|
||||
{
|
||||
return last_desc;
|
||||
}
|
||||
FLUID_LOG(FLUID_ERR, "Library contains more than one plugin, please specify "
|
||||
"the plugin label");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a new LADSPA plugin from a library and set up the associated
|
||||
* control structures needed by the LADSPA fx engine.
|
||||
*
|
||||
* If the library contains only one plugin, then the name is optional.
|
||||
*
|
||||
* Plugins are identified by their "Label" in the plugin descriptor structure.
|
||||
*
|
||||
* @param fx LADSPA fx instance
|
||||
* @param lib pointer to fluid_ladspa_lib_t
|
||||
* @param name string name of the plugin (the LADSPA Label)
|
||||
* @param name (optional) string name of the plugin (the LADSPA Label)
|
||||
* @return pointer to the new ladspa_plugin_t structure or NULL on error
|
||||
*/
|
||||
static fluid_ladspa_plugin_t *
|
||||
|
|
Loading…
Reference in a new issue