Skip to content

Commit df2cdf6

Browse files
committed
Merge branch 'master' into monitor-cpu-load
2 parents 098cabc + aee8aba commit df2cdf6

1 file changed

Lines changed: 80 additions & 28 deletions

File tree

src/effects.c

Lines changed: 80 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ enum PluginHints {
263263
HINT_HAS_STATE = 1 << 4,
264264
HINT_STATE_UNSAFE = 1 << 5, // state restore needs mutex protection
265265
HINT_IS_LIVE = 1 << 6, // needs to be always running, cannot have processing disabled
266+
HINT_NO_PRE_RUN = 1 << 7, // do not keep plugin active for pre-run
266267
};
267268

268269
enum TransportSyncMode {
@@ -460,7 +461,8 @@ typedef struct EFFECT_T {
460461
jack_ringbuffer_t *events_out_buffer;
461462
char *events_in_buffer_helper;
462463

463-
bool activated;
464+
bool jack_activated;
465+
bool lv2_activated;
464466

465467
bool monitor_cpu;
466468
bool monitor_cpu_reset;
@@ -525,6 +527,7 @@ typedef struct LILV_NODES_T {
525527
LilvNode *mod_default_custom;
526528
LilvNode *mod_maximum;
527529
LilvNode *mod_minimum;
530+
LilvNode *noPreRun;
528531
LilvNode *options_interface;
529532
LilvNode *output;
530533
LilvNode *patch_readable;
@@ -1159,11 +1162,13 @@ static int BufferSize(jack_nframes_t nframes, void* data)
11591162
options[4].type = 0;
11601163
options[4].value = NULL;
11611164

1162-
lilv_instance_deactivate(effect->lilv_instance);
1165+
if (effect->lv2_activated)
1166+
lilv_instance_deactivate(effect->lilv_instance);
11631167

11641168
effect->options_interface->set(effect->lilv_instance->lv2_handle, options);
11651169

1166-
lilv_instance_activate(effect->lilv_instance);
1170+
if (effect->lv2_activated)
1171+
lilv_instance_activate(effect->lilv_instance);
11671172
}
11681173
}
11691174
#ifdef HAVE_HYLIA
@@ -4788,6 +4793,7 @@ int effects_init(void* client)
47884793
#endif
47894794
g_lilv_nodes.mod_maximum = lilv_new_uri(g_lv2_data, LILV_NS_MOD "maximum");
47904795
g_lilv_nodes.mod_minimum = lilv_new_uri(g_lv2_data, LILV_NS_MOD "minimum");
4796+
g_lilv_nodes.noPreRun = lilv_new_uri(g_lv2_data, "http://www.darkglass.com/lv2/ns#noPreRun");
47914797
g_lilv_nodes.options_interface = lilv_new_uri(g_lv2_data, LV2_OPTIONS__interface);
47924798
g_lilv_nodes.output = lilv_new_uri(g_lv2_data, LILV_URI_OUTPUT_PORT);
47934799
g_lilv_nodes.patch_writable = lilv_new_uri(g_lv2_data, LV2_PATCH__writable);
@@ -5138,6 +5144,7 @@ int effects_finish(int close_client)
51385144
lilv_node_free(g_lilv_nodes.mod_default_custom);
51395145
lilv_node_free(g_lilv_nodes.mod_maximum);
51405146
lilv_node_free(g_lilv_nodes.mod_minimum);
5147+
lilv_node_free(g_lilv_nodes.noPreRun);
51415148
lilv_node_free(g_lilv_nodes.output);
51425149
lilv_node_free(g_lilv_nodes.patch_readable);
51435150
lilv_node_free(g_lilv_nodes.patch_writable);
@@ -5232,7 +5239,8 @@ int effects_add(const char *uri, int instance, int activate)
52325239
/* Init the struct */
52335240
mod_memset(effect, 0, sizeof(effect_t));
52345241
effect->instance = instance;
5235-
effect->activated = activate;
5242+
effect->jack_activated = activate;
5243+
effect->lv2_activated = true;
52365244

52375245
/* Init the pointers */
52385246
plugin_uri = NULL;
@@ -5324,6 +5332,9 @@ int effects_add(const char *uri, int instance, int activate)
53245332
if (lilv_plugin_has_feature(effect->lilv_plugin, g_lilv_nodes.is_live))
53255333
effect->hints |= HINT_IS_LIVE;
53265334

5335+
if (lilv_plugin_has_feature(effect->lilv_plugin, g_lilv_nodes.noPreRun))
5336+
effect->hints |= HINT_NO_PRE_RUN;
5337+
53275338
/* Query plugin extensions/interfaces */
53285339
if (lilv_plugin_has_extension_data(effect->lilv_plugin, g_lilv_nodes.worker_interface))
53295340
{
@@ -6540,7 +6551,9 @@ static void effects_remove_inner_loop(int effect_id)
65406551

65416552
if (effect->lilv_instance)
65426553
{
6543-
lilv_instance_deactivate(effect->lilv_instance);
6554+
if (effect->lv2_activated)
6555+
lilv_instance_deactivate(effect->lilv_instance);
6556+
65446557
lilv_instance_free(effect->lilv_instance);
65456558
}
65466559

@@ -6732,7 +6745,7 @@ int effects_remove_multi(int num_effects, int *effects)
67326745
if (effect->jack_client == NULL)
67336746
continue;
67346747

6735-
if (effect->activated)
6748+
if (effect->jack_activated)
67366749
{
67376750
if (zix_thread_create(&threads[num_threads], sizeof(void*), effects_deactivate_thread, effect) == 0)
67386751
++num_threads;
@@ -6794,9 +6807,15 @@ int effects_activate(int effect_id, int value)
67946807

67956808
if (value)
67966809
{
6797-
if (! effect->activated)
6810+
if (! effect->lv2_activated)
67986811
{
6799-
effect->activated = true;
6812+
effect->lv2_activated = true;
6813+
lilv_instance_activate(effect->lilv_instance);
6814+
}
6815+
6816+
if (! effect->jack_activated)
6817+
{
6818+
effect->jack_activated = true;
68006819

68016820
if (jack_activate(effect->jack_client) != 0)
68026821
{
@@ -6807,16 +6826,22 @@ int effects_activate(int effect_id, int value)
68076826
}
68086827
else
68096828
{
6810-
if (effect->activated)
6829+
if (effect->jack_activated)
68116830
{
6812-
effect->activated = false;
6831+
effect->jack_activated = false;
68136832

68146833
if (jack_deactivate(effect->jack_client) != 0)
68156834
{
68166835
fprintf(stderr, "can't deactivate jack_client\n");
68176836
return ERR_JACK_CLIENT_DEACTIVATION;
68186837
}
68196838
}
6839+
6840+
if (effect->lv2_activated && ((effect->hints & HINT_NO_PRE_RUN) != 0))
6841+
{
6842+
effect->lv2_activated = false;
6843+
lilv_instance_deactivate(effect->lilv_instance);
6844+
}
68206845
}
68216846

68226847
return SUCCESS;
@@ -6826,7 +6851,13 @@ static void* effects_activate_thread(void* arg)
68266851
{
68276852
effect_t *effect = arg;
68286853

6829-
effect->activated = true;
6854+
if (! effect->lv2_activated)
6855+
{
6856+
effect->lv2_activated = true;
6857+
lilv_instance_activate(effect->lilv_instance);
6858+
}
6859+
6860+
effect->jack_activated = true;
68306861

68316862
if (jack_activate(effect->jack_client) != 0)
68326863
fprintf(stderr, "can't activate jack_client\n");
@@ -6841,7 +6872,13 @@ static void* effects_deactivate_thread(void* arg)
68416872
if (jack_deactivate(effect->jack_client) != 0)
68426873
fprintf(stderr, "can't deactivate jack_client\n");
68436874

6844-
effect->activated = false;
6875+
if (effect->lv2_activated && ((effect->hints & HINT_NO_PRE_RUN) != 0))
6876+
{
6877+
effect->lv2_activated = false;
6878+
lilv_instance_deactivate(effect->lilv_instance);
6879+
}
6880+
6881+
effect->jack_activated = false;
68456882

68466883
return NULL;
68476884
}
@@ -6874,7 +6911,7 @@ int effects_activate_multi(int value, int num_effects, int *effects)
68746911

68756912
if (value)
68766913
{
6877-
if (! effect->activated)
6914+
if (! effect->jack_activated)
68786915
{
68796916
if (zix_thread_create(&threads[num_threads], sizeof(void*), effects_activate_thread, effect) == 0)
68806917
++num_threads;
@@ -6884,7 +6921,7 @@ int effects_activate_multi(int value, int num_effects, int *effects)
68846921
}
68856922
else
68866923
{
6887-
if (effect->activated)
6924+
if (effect->jack_activated)
68886925
{
68896926
if (zix_thread_create(&threads[num_threads], sizeof(void*), effects_deactivate_thread, effect) == 0)
68906927
++num_threads;
@@ -7177,7 +7214,7 @@ int effects_flush_parameters_multi(int reset, int param_count, const flushed_par
71777214
{
71787215
effect = &(g_effects[effect_id]);
71797216

7180-
if (! effect->activated)
7217+
if (! effect->lv2_activated)
71817218
{
71827219
fprintf(stderr, "multi-param-flush attempted on non-activated plugin #%d\n", effect->instance);
71837220
continue;
@@ -7264,13 +7301,6 @@ int effects_pre_run(int effect_id, int reset, int param_count, const flushed_par
72647301
return ERR_INSTANCE_NON_EXISTS;
72657302

72667303
effect_t *effect = &(g_effects[effect_id]);
7267-
7268-
if (effect->activated && ((effect->hints & HINT_IS_LIVE) != 0 || g_processing_enabled))
7269-
{
7270-
fprintf(stderr, "pre-run attempted on activated plugin #%d\n", effect_id);
7271-
return ERR_INVALID_OPERATION;
7272-
}
7273-
72747304
port_t *port;
72757305

72767306
for (int i = 0; i < param_count; i++)
@@ -7291,6 +7321,20 @@ int effects_pre_run(int effect_id, int reset, int param_count, const flushed_par
72917321
port->prev_value = *(port->buffer) = reset;
72927322
}
72937323

7324+
if ((effect->hints & HINT_NO_PRE_RUN) != 0)
7325+
return SUCCESS;
7326+
7327+
if (effect->jack_activated && ((effect->hints & HINT_IS_LIVE) != 0 || g_processing_enabled))
7328+
{
7329+
fprintf(stderr, "pre-run attempted on jack-activated instance #%d\n", effect_id);
7330+
return ERR_INVALID_OPERATION;
7331+
}
7332+
if (! effect->lv2_activated)
7333+
{
7334+
fprintf(stderr, "pre-run attempted on non lv2-activated instance #%d\n", effect_id);
7335+
return ERR_INVALID_OPERATION;
7336+
}
7337+
72947338
PreRunPlugin(effect);
72957339

72967340
return SUCCESS;
@@ -7314,12 +7358,6 @@ int effects_pre_run_multi(int reset, int param_count, const flushed_param_t *par
73147358
{
73157359
effect = &(g_effects[effect_id]);
73167360

7317-
if (effect->activated && ((effect->hints & HINT_IS_LIVE) != 0 || g_processing_enabled))
7318-
{
7319-
fprintf(stderr, "multi-pre-run attempted on activated plugin #%d\n", effect->instance);
7320-
continue;
7321-
}
7322-
73237361
for (int j = 0; j < param_count; j++)
73247362
{
73257363
port = FindEffectInputPortBySymbol(effect, params[j].symbol);
@@ -7338,6 +7376,20 @@ int effects_pre_run_multi(int reset, int param_count, const flushed_param_t *par
73387376
}
73397377
}
73407378

7379+
if (effect->jack_activated && ((effect->hints & HINT_IS_LIVE) != 0 || g_processing_enabled))
7380+
{
7381+
fprintf(stderr, "multi-pre-run attempted on jack-activated instance #%d\n", effect->instance);
7382+
continue;
7383+
}
7384+
if (! effect->lv2_activated)
7385+
{
7386+
fprintf(stderr, "multi-pre-run attempted on non lv2-activated instance #%d\n", effect->instance);
7387+
continue;
7388+
}
7389+
7390+
if ((effect->hints & HINT_NO_PRE_RUN) != 0)
7391+
continue;
7392+
73417393
PreRunPlugin(effect);
73427394
}
73437395
}

0 commit comments

Comments
 (0)