diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index a718e1ec..5aeec834 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -183,10 +183,8 @@ static const fluid_cmd_int_t fluid_commands[] = { "ladspa_link Connect an effect port to a host port or buffer"}, { "ladspa_node", "ladspa", fluid_handle_ladspa_node, "ladspa_node Create a LADSPA audio or control node"}, - { "ladspa_control", "ladspa", fluid_handle_ladspa_control, - "ladspa_control Set the value of a LADSPA control node"}, - { "ladspa_control_defaults", "ladspa", fluid_handle_ladspa_control_defaults, - "ladspa_control_defaults Assign all unconnected controls on all plugins their default value"}, + { "ladspa_set", "ladspa", fluid_handle_ladspa_set, + "ladspa_set Set the value of an effect control port"}, { "ladspa_check", "ladspa", fluid_handle_ladspa_check, "ladspa_check Check LADSPA configuration"}, { "ladspa_start", "ladspa", fluid_handle_ladspa_start, @@ -1973,25 +1971,6 @@ int fluid_handle_ladspa_reset(void* data, int ac, char **av, fluid_ostream_t out return FLUID_OK; } -int fluid_handle_ladspa_control_defaults(void* data, int ac, char **av, fluid_ostream_t out) -{ - FLUID_ENTRY_COMMAND(data); - fluid_ladspa_fx_t *fx = handler->synth->ladspa_fx; - - CHECK_LADSPA_ENABLED(fx, out); - CHECK_LADSPA_INACTIVE(fx, out); - - if (fluid_ladspa_control_defaults(fx) != FLUID_OK) - { - fluid_ostream_printf(out, "Error while setting default values for control ports\n"); - return FLUID_FAILED; - } - - fluid_ostream_printf(out, "Control port defaults set\n"); - - return FLUID_OK; -} - int fluid_handle_ladspa_check(void* data, int ac, char **av, fluid_ostream_t out) { FLUID_ENTRY_COMMAND(data); @@ -2011,30 +1990,38 @@ int fluid_handle_ladspa_check(void* data, int ac, char **av, fluid_ostream_t out return FLUID_OK; } -int fluid_handle_ladspa_control(void* data, int ac, char **av, fluid_ostream_t out) +int fluid_handle_ladspa_set(void *data, int ac, char **av, fluid_ostream_t out) { FLUID_ENTRY_COMMAND(data); + char *effect_name = NULL; + char *port_name = NULL; fluid_ladspa_fx_t *fx = handler->synth->ladspa_fx; CHECK_LADSPA_ENABLED(fx, out); if (ac != 2) { - fluid_ostream_printf(out, "ladspa_control needs two arguments: node name and value.\n"); + fluid_ostream_printf(out, "ladspa_set needs two arguments: port name and value.\n"); return FLUID_FAILED; }; - /* Redundant check, just here to give a more detailed error message */ - if (!fluid_ladspa_node_exists(fx, av[0])) + if (!fluid_ladspa_split(av[0], &effect_name, &port_name)) { - fluid_ostream_printf(out, "Node '%s' not found.\n", av[0]); + fluid_ostream_printf(out, "Effect port names need to be in the format :\n"); return FLUID_FAILED; } - if (fluid_ladspa_set_control_node(fx, av[0], atof(av[1])) != FLUID_OK) + /* Redundant check, just here to give a more detailed error message */ + if (!fluid_ladspa_port_exists(fx, effect_name, port_name)) { - fluid_ostream_printf(out, "Failed to set node '%s', maybe it's not a control node?\n", - av[0]); + fluid_ostream_printf(out, "Effect port '%s:%s' not found\n", effect_name, port_name); + return FLUID_FAILED; + } + + if (fluid_ladspa_set_control_port(fx, effect_name, port_name, atof(av[1])) != FLUID_OK) + { + fluid_ostream_printf(out, "Failed to set effect port '%s:%s', maybe it is " + "not a control node?\n", effect_name, port_name); return FLUID_FAILED; } diff --git a/src/bindings/fluid_cmd.h b/src/bindings/fluid_cmd.h index de7d8572..1bfff6e0 100644 --- a/src/bindings/fluid_cmd.h +++ b/src/bindings/fluid_cmd.h @@ -89,8 +89,7 @@ int fluid_handle_router_par2(void* data, int ac, char** av, fluid_ostream_t out) int fluid_handle_ladspa_effect(void *data, int ac, char **av, fluid_ostream_t out); int fluid_handle_ladspa_link(void *data, int ac, char **av, fluid_ostream_t out); int fluid_handle_ladspa_node(void *data, int ac, char **av, fluid_ostream_t out); -int fluid_handle_ladspa_control(void *data, int ac, char **av, fluid_ostream_t out); -int fluid_handle_ladspa_control_defaults(void *data, int ac, char **av, fluid_ostream_t out); +int fluid_handle_ladspa_set(void *data, int ac, char **av, fluid_ostream_t out); int fluid_handle_ladspa_check(void *data, int ac, char **av, fluid_ostream_t out); int fluid_handle_ladspa_start(void *data, int ac, char **av, fluid_ostream_t out); int fluid_handle_ladspa_stop(void *data, int ac, char **av, fluid_ostream_t out); diff --git a/src/bindings/fluid_ladspa.c b/src/bindings/fluid_ladspa.c index e445ecd9..2351b70f 100644 --- a/src/bindings/fluid_ladspa.c +++ b/src/bindings/fluid_ladspa.c @@ -691,22 +691,38 @@ int fluid_ladspa_add_control_node(fluid_ladspa_fx_t *fx, const char *name, fluid } /** - * Set the value of a user constrol node + * Set the value of an effect control port * * Nodes are searched by case-insensitive string comparison. * * @param fx LADSPA fx instance - * @param name node name string + * @param effect_name name of the effect + * @param port_name name of the port * @param val floating point value * @return FLUID_OK on success, FLUID_FAILED on error */ -int fluid_ladspa_set_control_node(fluid_ladspa_fx_t *fx, const char *name, fluid_real_t val) +int fluid_ladspa_set_control_port(fluid_ladspa_fx_t *fx, const char *effect_name, + const char *port_name, fluid_real_t val) { fluid_ladspa_node_t *node; + fluid_ladspa_plugin_t *plugin; + int port_idx; LADSPA_API_ENTER(fx); - node = get_node(fx, name); + plugin = get_plugin(fx, effect_name); + if (plugin == NULL) + { + LADSPA_API_RETURN(fx, FLUID_FAILED); + } + + port_idx = get_plugin_port_idx(plugin, port_name); + if (port_idx < 0) + { + LADSPA_API_RETURN(fx, FLUID_FAILED); + } + + node = plugin->port_nodes[port_idx]; if (node == NULL) { LADSPA_API_RETURN(fx, FLUID_FAILED); @@ -771,6 +787,12 @@ int fluid_ladspa_add_plugin(fluid_ladspa_fx_t *fx, const char *effect_name, fx->plugins[fx->num_plugins++] = plugin; + /* Create nodes for all plugin controls */ + if (connect_default_control_nodes(fx, plugin) != FLUID_OK) + { + LADSPA_API_RETURN(fx, FLUID_FAILED); + } + LADSPA_API_RETURN(fx, FLUID_OK); } @@ -857,35 +879,6 @@ int fluid_ladspa_connect(fluid_ladspa_fx_t *fx, const char *effect_name, LADSPA_API_RETURN(fx, FLUID_OK); } -/** - * Find all unconnected control ports on all configured plugins and fill any unconnected ports with - * their default value, if available. - * - * @param fx LADSPA fx instance - * @return FLUID_OK on success, otherwise FLUID_FAILED - */ -int fluid_ladspa_control_defaults(fluid_ladspa_fx_t *fx) -{ - int i; - - LADSPA_API_ENTER(fx); - - if (fluid_ladspa_is_active(fx)) - { - LADSPA_API_RETURN(fx, FLUID_FAILED); - } - - for (i = 0; i < fx->num_plugins; i++) - { - if (connect_default_control_nodes(fx, fx->plugins[i]) != FLUID_OK) - { - LADSPA_API_RETURN(fx, FLUID_FAILED); - } - } - - LADSPA_API_RETURN(fx, FLUID_OK); -} - /** * Do a sanity check for problems in the LADSPA setup * @@ -1542,17 +1535,19 @@ static int connect_default_control_nodes(fluid_ladspa_fx_t *fx, fluid_ladspa_plu if (set_default_port_value(plugin, i, fx->sample_rate, &value) == FLUID_OK) { - node = new_fluid_ladspa_node(fx, "", FLUID_LADSPA_NODE_CONTROL, NULL); - if (node == NULL) - { - return FLUID_FAILED; - } - node->plugin_buffer[0] = value; - - dir = LADSPA_IS_PORT_INPUT(port_flags) ? FLUID_LADSPA_INPUT : FLUID_LADSPA_OUTPUT; - - connect_node_to_port(node, dir, plugin, i); + value = 0.0f; } + + node = new_fluid_ladspa_node(fx, "", FLUID_LADSPA_NODE_CONTROL, NULL); + if (node == NULL) + { + return FLUID_FAILED; + } + node->plugin_buffer[0] = value; + + dir = LADSPA_IS_PORT_INPUT(port_flags) ? FLUID_LADSPA_INPUT : FLUID_LADSPA_OUTPUT; + + connect_node_to_port(node, dir, plugin, i); } return FLUID_OK; diff --git a/src/bindings/fluid_ladspa.h b/src/bindings/fluid_ladspa.h index d2e02ac3..dbbd863d 100644 --- a/src/bindings/fluid_ladspa.h +++ b/src/bindings/fluid_ladspa.h @@ -165,13 +165,13 @@ int fluid_ladspa_port_exists(fluid_ladspa_fx_t *fx, const char *plugin_name, con int fluid_ladspa_add_audio_node(fluid_ladspa_fx_t *fx, const char *name); int fluid_ladspa_add_control_node(fluid_ladspa_fx_t *fx, const char *name, fluid_real_t val); -int fluid_ladspa_set_control_node(fluid_ladspa_fx_t *fx, const char *name, fluid_real_t val); +int fluid_ladspa_set_control_port(fluid_ladspa_fx_t *fx, const char *effect_name, + const char *port_name, fluid_real_t val); int fluid_ladspa_node_exists(fluid_ladspa_fx_t *fx, const char *name); int fluid_ladspa_connect(fluid_ladspa_fx_t *fx, const char *effect_name, const char *port_name, const char *node_name); int fluid_ladspa_check(fluid_ladspa_fx_t *fx, char *err, int err_size); -int fluid_ladspa_control_defaults(fluid_ladspa_fx_t *fx); #endif /* LADSPA */ #endif /* _FLUID_LADSPA_H */