Skip to content

Commit 32b09e0

Browse files
committed
Implement params_flush command
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 9dc9eb9 commit 32b09e0

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ The commands supported by mod-host are:
169169
* monitor a control port according to a condition
170170
e.g: param_monitor 0 "gain" ">" 2.5
171171

172+
params_flush <instance_number> <param_count> <params...>
173+
* flush several param values at once and trigger reset if available
174+
e.g.: params_flush 0 2 "gain" 0.0 "distortion" 0.5
175+
172176
patch_set <instance_number> <property_uri> <value>
173177
* set the value of a control port
174178
e.g.: patch_set 0 "gain" 2.5

src/effects.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6358,6 +6358,51 @@ int effects_get_parameter(int effect_id, const char *control_symbol, float *valu
63586358
return ERR_INSTANCE_NON_EXISTS;
63596359
}
63606360

6361+
int effects_flush_parameters(int effect_id, int param_count, const flushed_param_t *params)
6362+
{
6363+
if (!InstanceExist(effect_id))
6364+
return ERR_INSTANCE_NON_EXISTS;
6365+
if (param_count == 0)
6366+
return ERR_ASSIGNMENT_INVALID_OP;
6367+
6368+
effect_t *effect = &(g_effects[effect_id]);
6369+
port_t *port;
6370+
float value;
6371+
6372+
if (effect->reset_index >= 0)
6373+
{
6374+
*(effect->ports[effect->reset_index]->buffer) = 1.0f;
6375+
}
6376+
6377+
for (int i = 0; i < param_count; i++)
6378+
{
6379+
port = FindEffectInputPortBySymbol(effect, params[i].symbol);
6380+
if (port)
6381+
{
6382+
value = params[i].value;
6383+
6384+
if (value < port->min_value)
6385+
value = port->max_value;
6386+
else if (value > port->max_value)
6387+
value = port->max_value;
6388+
6389+
port->prev_value = *port->buffer = params[i].value;
6390+
6391+
#ifdef WITH_EXTERNAL_UI_SUPPORT
6392+
port->hints |= HINT_SHOULD_UPDATE;
6393+
#endif
6394+
}
6395+
}
6396+
6397+
// reset a 2nd time in case plugin was processing while we changed parameters
6398+
if (effect->reset_index >= 0)
6399+
{
6400+
*(effect->ports[effect->reset_index]->buffer) = 1.0f;
6401+
}
6402+
6403+
return SUCCESS;
6404+
}
6405+
63616406
static inline
63626407
bool lv2_atom_forge_property_set(LV2_Atom_Forge *forge, LV2_URID urid, const char *value, LV2_URID type)
63636408
{

src/effects.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ typedef struct {
112112
float value;
113113
} scalepoint_t;
114114

115+
typedef struct {
116+
const char *symbol;
117+
float value;
118+
} flushed_param_t;
119+
115120

116121
/*
117122
************************************************************************************************************************
@@ -146,6 +151,7 @@ int effects_disconnect(const char *portA, const char *portB);
146151
int effects_disconnect_all(const char *port);
147152
int effects_set_parameter(int effect_id, const char *control_symbol, float value);
148153
int effects_get_parameter(int effect_id, const char *control_symbol, float *value);
154+
int effects_flush_parameters(int effect_id, int param_count, const flushed_param_t *params);
149155
int effects_set_property(int effect_id, const char *uri, const char *value);
150156
int effects_get_property(int effect_id, const char *uri);
151157
int effects_monitor_parameter(int effect_id, const char *control_symbol, const char *op, float value);

src/mod-host.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,41 @@ static void effects_monitor_param_cb(proto_t *proto)
247247
protocol_response_int(resp, proto);
248248
}
249249

250+
static void effects_flush_params_cb(proto_t *proto)
251+
{
252+
int resp;
253+
int param_count = atoi(proto->list[2]);
254+
flushed_param_t *params;
255+
256+
if (param_count == 0)
257+
{
258+
protocol_response_int(ERR_ASSIGNMENT_INVALID_OP, proto);
259+
return;
260+
}
261+
262+
params = malloc(sizeof(flushed_param_t) * param_count);
263+
264+
if (params != NULL)
265+
{
266+
for (int i = 0; i < param_count; i++)
267+
{
268+
params[i].symbol = proto->list[3 + i * 2];
269+
params[i].value = atof(proto->list[4 + i * 2]);
270+
}
271+
}
272+
else
273+
{
274+
protocol_response_int(ERR_MEMORY_ALLOCATION, proto);
275+
return;
276+
}
277+
278+
resp = effects_flush_parameters(atoi(proto->list[1]), param_count, params);
279+
280+
free(params);
281+
282+
protocol_response_int(resp, proto);
283+
}
284+
250285
static void effects_set_property_cb(proto_t *proto)
251286
{
252287
int resp;
@@ -715,6 +750,7 @@ static int mod_host_init(jack_client_t* client, int socket_port, int feedback_po
715750
protocol_add_command(EFFECT_PARAM_SET, effects_set_param_cb);
716751
protocol_add_command(EFFECT_PARAM_GET, effects_get_param_cb);
717752
protocol_add_command(EFFECT_PARAM_MON, effects_monitor_param_cb);
753+
protocol_add_command(EFFECT_PARAMS_FLUSH, effects_flush_params_cb);
718754
protocol_add_command(EFFECT_PATCH_GET, effects_get_property_cb);
719755
protocol_add_command(EFFECT_PATCH_SET, effects_set_property_cb);
720756
protocol_add_command(EFFECT_LICENSEE, effects_licensee_cb);

src/mod-host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#define EFFECT_PARAM_SET "param_set %i %s %s"
6666
#define EFFECT_PARAM_GET "param_get %i %s"
6767
#define EFFECT_PARAM_MON "param_monitor %i %s %s %f"
68+
#define EFFECT_PARAMS_FLUSH "params_flush %i %i ..."
6869
#define EFFECT_PATCH_GET "patch_get %i %s"
6970
#define EFFECT_PATCH_SET "patch_set %i %s %s"
7071
#define EFFECT_LICENSEE "licensee %i"

0 commit comments

Comments
 (0)