Skip to content

Commit

Permalink
Implement params_flush command
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Dec 31, 2024
1 parent 9dc9eb9 commit 32b09e0
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +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...>
* flush several param values at once and trigger reset if available
e.g.: params_flush 0 2 "gain" 0.0 "distortion" 0.5

patch_set <instance_number> <property_uri> <value>
* set the value of a control port
e.g.: patch_set 0 "gain" 2.5
Expand Down
45 changes: 45 additions & 0 deletions src/effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -6358,6 +6358,51 @@ 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)
{
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;
}

for (int i = 0; i < param_count; i++)
{
port = FindEffectInputPortBySymbol(effect, params[i].symbol);
if (port)
{
value = params[i].value;

if (value < port->min_value)
value = port->max_value;
else if (value > port->max_value)
value = port->max_value;

port->prev_value = *port->buffer = params[i].value;

#ifdef WITH_EXTERNAL_UI_SUPPORT
port->hints |= HINT_SHOULD_UPDATE;
#endif
}
}

// 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;
}

return SUCCESS;
}

static inline
bool lv2_atom_forge_property_set(LV2_Atom_Forge *forge, LV2_URID urid, const char *value, LV2_URID type)
{
Expand Down
6 changes: 6 additions & 0 deletions src/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ typedef struct {
float value;
} scalepoint_t;

typedef struct {
const char *symbol;
float value;
} flushed_param_t;


/*
************************************************************************************************************************
Expand Down Expand Up @@ -146,6 +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_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
36 changes: 36 additions & 0 deletions src/mod-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,41 @@ static void effects_monitor_param_cb(proto_t *proto)
protocol_response_int(resp, proto);
}

static void effects_flush_params_cb(proto_t *proto)
{
int resp;
int param_count = atoi(proto->list[2]);
flushed_param_t *params;

if (param_count == 0)
{
protocol_response_int(ERR_ASSIGNMENT_INVALID_OP, proto);
return;
}

params = malloc(sizeof(flushed_param_t) * param_count);

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]);
}
}
else
{
protocol_response_int(ERR_MEMORY_ALLOCATION, proto);
return;
}

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

free(params);

protocol_response_int(resp, proto);
}

static void effects_set_property_cb(proto_t *proto)
{
int resp;
Expand Down Expand Up @@ -715,6 +750,7 @@ static int mod_host_init(jack_client_t* client, int socket_port, int feedback_po
protocol_add_command(EFFECT_PARAM_SET, effects_set_param_cb);
protocol_add_command(EFFECT_PARAM_GET, effects_get_param_cb);
protocol_add_command(EFFECT_PARAM_MON, effects_monitor_param_cb);
protocol_add_command(EFFECT_PARAMS_FLUSH, effects_flush_params_cb);
protocol_add_command(EFFECT_PATCH_GET, effects_get_property_cb);
protocol_add_command(EFFECT_PATCH_SET, effects_set_property_cb);
protocol_add_command(EFFECT_LICENSEE, effects_licensee_cb);
Expand Down
1 change: 1 addition & 0 deletions src/mod-host.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +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_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 32b09e0

Please sign in to comment.