Skip to content

Commit

Permalink
Allow custom reset value and 0 params in params_flush
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Dec 31, 2024
1 parent 32b09e0 commit bc9a83e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ The commands supported by mod-host are:
* monitor a control port according to a condition
e.g: param_monitor 0 "gain" ">" 2.5

params_flush <instance_number> <param_count> <params...>
params_flush <instance_number> <reset_value> <param_count> <params...>
* flush several param values at once and trigger reset if available
e.g.: params_flush 0 2 "gain" 0.0 "distortion" 0.5
* reset value must be according to reset property spec
e.g.: params_flush 0 1 2 "gain" 0.0 "distortion" 0.5

patch_set <instance_number> <property_uri> <value>
* set the value of a control port
Expand Down
8 changes: 3 additions & 5 deletions src/effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -6358,20 +6358,18 @@ int effects_get_parameter(int effect_id, const char *control_symbol, float *valu
return ERR_INSTANCE_NON_EXISTS;
}

int effects_flush_parameters(int effect_id, int param_count, const flushed_param_t *params)
int effects_flush_parameters(int effect_id, int reset, int param_count, const flushed_param_t *params)
{
if (!InstanceExist(effect_id))
return ERR_INSTANCE_NON_EXISTS;
if (param_count == 0)
return ERR_ASSIGNMENT_INVALID_OP;

effect_t *effect = &(g_effects[effect_id]);
port_t *port;
float value;

if (effect->reset_index >= 0)
{
*(effect->ports[effect->reset_index]->buffer) = 1.0f;
*(effect->ports[effect->reset_index]->buffer) = reset;
}

for (int i = 0; i < param_count; i++)
Expand All @@ -6397,7 +6395,7 @@ int effects_flush_parameters(int effect_id, int param_count, const flushed_param
// reset a 2nd time in case plugin was processing while we changed parameters
if (effect->reset_index >= 0)
{
*(effect->ports[effect->reset_index]->buffer) = 1.0f;
*(effect->ports[effect->reset_index]->buffer) = reset;
}

return SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int effects_disconnect(const char *portA, const char *portB);
int effects_disconnect_all(const char *port);
int effects_set_parameter(int effect_id, const char *control_symbol, float value);
int effects_get_parameter(int effect_id, const char *control_symbol, float *value);
int effects_flush_parameters(int effect_id, int param_count, const flushed_param_t *params);
int effects_flush_parameters(int effect_id, int reset, int param_count, const flushed_param_t *params);
int effects_set_property(int effect_id, const char *uri, const char *value);
int effects_get_property(int effect_id, const char *uri);
int effects_monitor_parameter(int effect_id, const char *control_symbol, const char *op, float value);
Expand Down
25 changes: 12 additions & 13 deletions src/mod-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,32 +250,31 @@ static void effects_monitor_param_cb(proto_t *proto)
static void effects_flush_params_cb(proto_t *proto)
{
int resp;
int param_count = atoi(proto->list[2]);
int param_count = atoi(proto->list[3]);
flushed_param_t *params;

if (param_count == 0)
if (param_count != 0)
{
protocol_response_int(ERR_ASSIGNMENT_INVALID_OP, proto);
return;
}
params = malloc(sizeof(flushed_param_t) * param_count);

params = malloc(sizeof(flushed_param_t) * param_count);
if (params == NULL)
{
protocol_response_int(ERR_MEMORY_ALLOCATION, proto);
return;
}

if (params != NULL)
{
for (int i = 0; i < param_count; i++)
{
params[i].symbol = proto->list[3 + i * 2];
params[i].value = atof(proto->list[4 + i * 2]);
params[i].symbol = proto->list[4 + i * 2];
params[i].value = atof(proto->list[5 + i * 2]);
}
}
else
{
protocol_response_int(ERR_MEMORY_ALLOCATION, proto);
return;
params = NULL;
}

resp = effects_flush_parameters(atoi(proto->list[1]), param_count, params);
resp = effects_flush_parameters(atoi(proto->list[1]), atoi(proto->list[2]), param_count, params);

free(params);

Expand Down
2 changes: 1 addition & 1 deletion src/mod-host.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#define EFFECT_PARAM_SET "param_set %i %s %s"
#define EFFECT_PARAM_GET "param_get %i %s"
#define EFFECT_PARAM_MON "param_monitor %i %s %s %f"
#define EFFECT_PARAMS_FLUSH "params_flush %i %i ..."
#define EFFECT_PARAMS_FLUSH "params_flush %i %i %i ..."
#define EFFECT_PATCH_GET "patch_get %i %s"
#define EFFECT_PATCH_SET "patch_set %i %s %s"
#define EFFECT_LICENSEE "licensee %i"
Expand Down

0 comments on commit bc9a83e

Please sign in to comment.