Skip to content

Commit bc9a83e

Browse files
committed
Allow custom reset value and 0 params in params_flush
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 32b09e0 commit bc9a83e

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +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...>
172+
params_flush <instance_number> <reset_value> <param_count> <params...>
173173
* flush several param values at once and trigger reset if available
174-
e.g.: params_flush 0 2 "gain" 0.0 "distortion" 0.5
174+
* reset value must be according to reset property spec
175+
e.g.: params_flush 0 1 2 "gain" 0.0 "distortion" 0.5
175176

176177
patch_set <instance_number> <property_uri> <value>
177178
* set the value of a control port

src/effects.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6358,20 +6358,18 @@ 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)
6361+
int effects_flush_parameters(int effect_id, int reset, int param_count, const flushed_param_t *params)
63626362
{
63636363
if (!InstanceExist(effect_id))
63646364
return ERR_INSTANCE_NON_EXISTS;
6365-
if (param_count == 0)
6366-
return ERR_ASSIGNMENT_INVALID_OP;
63676365

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

63726370
if (effect->reset_index >= 0)
63736371
{
6374-
*(effect->ports[effect->reset_index]->buffer) = 1.0f;
6372+
*(effect->ports[effect->reset_index]->buffer) = reset;
63756373
}
63766374

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

64036401
return SUCCESS;

src/effects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int effects_disconnect(const char *portA, const char *portB);
151151
int effects_disconnect_all(const char *port);
152152
int effects_set_parameter(int effect_id, const char *control_symbol, float value);
153153
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);
154+
int effects_flush_parameters(int effect_id, int reset, int param_count, const flushed_param_t *params);
155155
int effects_set_property(int effect_id, const char *uri, const char *value);
156156
int effects_get_property(int effect_id, const char *uri);
157157
int effects_monitor_parameter(int effect_id, const char *control_symbol, const char *op, float value);

src/mod-host.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,32 +250,31 @@ static void effects_monitor_param_cb(proto_t *proto)
250250
static void effects_flush_params_cb(proto_t *proto)
251251
{
252252
int resp;
253-
int param_count = atoi(proto->list[2]);
253+
int param_count = atoi(proto->list[3]);
254254
flushed_param_t *params;
255255

256-
if (param_count == 0)
256+
if (param_count != 0)
257257
{
258-
protocol_response_int(ERR_ASSIGNMENT_INVALID_OP, proto);
259-
return;
260-
}
258+
params = malloc(sizeof(flushed_param_t) * param_count);
261259

262-
params = malloc(sizeof(flushed_param_t) * param_count);
260+
if (params == NULL)
261+
{
262+
protocol_response_int(ERR_MEMORY_ALLOCATION, proto);
263+
return;
264+
}
263265

264-
if (params != NULL)
265-
{
266266
for (int i = 0; i < param_count; i++)
267267
{
268-
params[i].symbol = proto->list[3 + i * 2];
269-
params[i].value = atof(proto->list[4 + i * 2]);
268+
params[i].symbol = proto->list[4 + i * 2];
269+
params[i].value = atof(proto->list[5 + i * 2]);
270270
}
271271
}
272272
else
273273
{
274-
protocol_response_int(ERR_MEMORY_ALLOCATION, proto);
275-
return;
274+
params = NULL;
276275
}
277276

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

280279
free(params);
281280

src/mod-host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +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 ..."
68+
#define EFFECT_PARAMS_FLUSH "params_flush %i %i %i ..."
6969
#define EFFECT_PATCH_GET "patch_get %i %s"
7070
#define EFFECT_PATCH_SET "patch_set %i %s %s"
7171
#define EFFECT_LICENSEE "licensee %i"

0 commit comments

Comments
 (0)