@@ -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
268269enum TransportSyncMode {
@@ -459,7 +460,8 @@ typedef struct EFFECT_T {
459460 jack_ringbuffer_t * events_out_buffer ;
460461 char * events_in_buffer_helper ;
461462
462- bool activated ;
463+ bool jack_activated ;
464+ bool lv2_activated ;
463465
464466 // previous transport state
465467 bool transport_rolling ;
@@ -520,6 +522,7 @@ typedef struct LILV_NODES_T {
520522 LilvNode * mod_default_custom ;
521523 LilvNode * mod_maximum ;
522524 LilvNode * mod_minimum ;
525+ LilvNode * noPreRun ;
523526 LilvNode * options_interface ;
524527 LilvNode * output ;
525528 LilvNode * patch_readable ;
@@ -1147,11 +1150,13 @@ static int BufferSize(jack_nframes_t nframes, void* data)
11471150 options [4 ].type = 0 ;
11481151 options [4 ].value = NULL ;
11491152
1150- lilv_instance_deactivate (effect -> lilv_instance );
1153+ if (effect -> lv2_activated )
1154+ lilv_instance_deactivate (effect -> lilv_instance );
11511155
11521156 effect -> options_interface -> set (effect -> lilv_instance -> lv2_handle , options );
11531157
1154- lilv_instance_activate (effect -> lilv_instance );
1158+ if (effect -> lv2_activated )
1159+ lilv_instance_activate (effect -> lilv_instance );
11551160 }
11561161 }
11571162#ifdef HAVE_HYLIA
@@ -4718,6 +4723,7 @@ int effects_init(void* client)
47184723#endif
47194724 g_lilv_nodes .mod_maximum = lilv_new_uri (g_lv2_data , LILV_NS_MOD "maximum" );
47204725 g_lilv_nodes .mod_minimum = lilv_new_uri (g_lv2_data , LILV_NS_MOD "minimum" );
4726+ g_lilv_nodes .noPreRun = lilv_new_uri (g_lv2_data , "http://www.darkglass.com/lv2/ns#noPreRun" );
47214727 g_lilv_nodes .options_interface = lilv_new_uri (g_lv2_data , LV2_OPTIONS__interface );
47224728 g_lilv_nodes .output = lilv_new_uri (g_lv2_data , LILV_URI_OUTPUT_PORT );
47234729 g_lilv_nodes .patch_writable = lilv_new_uri (g_lv2_data , LV2_PATCH__writable );
@@ -5068,6 +5074,7 @@ int effects_finish(int close_client)
50685074 lilv_node_free (g_lilv_nodes .mod_default_custom );
50695075 lilv_node_free (g_lilv_nodes .mod_maximum );
50705076 lilv_node_free (g_lilv_nodes .mod_minimum );
5077+ lilv_node_free (g_lilv_nodes .noPreRun );
50715078 lilv_node_free (g_lilv_nodes .output );
50725079 lilv_node_free (g_lilv_nodes .patch_readable );
50735080 lilv_node_free (g_lilv_nodes .patch_writable );
@@ -5162,7 +5169,8 @@ int effects_add(const char *uri, int instance, int activate)
51625169 /* Init the struct */
51635170 mod_memset (effect , 0 , sizeof (effect_t ));
51645171 effect -> instance = instance ;
5165- effect -> activated = activate ;
5172+ effect -> jack_activated = activate ;
5173+ effect -> lv2_activated = true;
51665174
51675175 /* Init the pointers */
51685176 plugin_uri = NULL ;
@@ -5254,6 +5262,9 @@ int effects_add(const char *uri, int instance, int activate)
52545262 if (lilv_plugin_has_feature (effect -> lilv_plugin , g_lilv_nodes .is_live ))
52555263 effect -> hints |= HINT_IS_LIVE ;
52565264
5265+ if (lilv_plugin_has_feature (effect -> lilv_plugin , g_lilv_nodes .noPreRun ))
5266+ effect -> hints |= HINT_NO_PRE_RUN ;
5267+
52575268 /* Query plugin extensions/interfaces */
52585269 if (lilv_plugin_has_extension_data (effect -> lilv_plugin , g_lilv_nodes .worker_interface ))
52595270 {
@@ -6470,7 +6481,9 @@ static void effects_remove_inner_loop(int effect_id)
64706481
64716482 if (effect -> lilv_instance )
64726483 {
6473- lilv_instance_deactivate (effect -> lilv_instance );
6484+ if (effect -> lv2_activated )
6485+ lilv_instance_deactivate (effect -> lilv_instance );
6486+
64746487 lilv_instance_free (effect -> lilv_instance );
64756488 }
64766489
@@ -6662,7 +6675,7 @@ int effects_remove_multi(int num_effects, int *effects)
66626675 if (effect -> jack_client == NULL )
66636676 continue ;
66646677
6665- if (effect -> activated )
6678+ if (effect -> jack_activated )
66666679 {
66676680 if (zix_thread_create (& threads [num_threads ], sizeof (void * ), effects_deactivate_thread , effect ) == 0 )
66686681 ++ num_threads ;
@@ -6724,9 +6737,15 @@ int effects_activate(int effect_id, int value)
67246737
67256738 if (value )
67266739 {
6727- if (! effect -> activated )
6740+ if (! effect -> lv2_activated )
67286741 {
6729- effect -> activated = true;
6742+ effect -> lv2_activated = true;
6743+ lilv_instance_activate (effect -> lilv_instance );
6744+ }
6745+
6746+ if (! effect -> jack_activated )
6747+ {
6748+ effect -> jack_activated = true;
67306749
67316750 if (jack_activate (effect -> jack_client ) != 0 )
67326751 {
@@ -6737,16 +6756,22 @@ int effects_activate(int effect_id, int value)
67376756 }
67386757 else
67396758 {
6740- if (effect -> activated )
6759+ if (effect -> jack_activated )
67416760 {
6742- effect -> activated = false;
6761+ effect -> jack_activated = false;
67436762
67446763 if (jack_deactivate (effect -> jack_client ) != 0 )
67456764 {
67466765 fprintf (stderr , "can't deactivate jack_client\n" );
67476766 return ERR_JACK_CLIENT_DEACTIVATION ;
67486767 }
67496768 }
6769+
6770+ if (effect -> lv2_activated && ((effect -> hints & HINT_NO_PRE_RUN ) != 0 ))
6771+ {
6772+ effect -> lv2_activated = false;
6773+ lilv_instance_deactivate (effect -> lilv_instance );
6774+ }
67506775 }
67516776
67526777 return SUCCESS ;
@@ -6756,7 +6781,13 @@ static void* effects_activate_thread(void* arg)
67566781{
67576782 effect_t * effect = arg ;
67586783
6759- effect -> activated = true;
6784+ if (! effect -> lv2_activated )
6785+ {
6786+ effect -> lv2_activated = true;
6787+ lilv_instance_activate (effect -> lilv_instance );
6788+ }
6789+
6790+ effect -> jack_activated = true;
67606791
67616792 if (jack_activate (effect -> jack_client ) != 0 )
67626793 fprintf (stderr , "can't activate jack_client\n" );
@@ -6771,7 +6802,13 @@ static void* effects_deactivate_thread(void* arg)
67716802 if (jack_deactivate (effect -> jack_client ) != 0 )
67726803 fprintf (stderr , "can't deactivate jack_client\n" );
67736804
6774- effect -> activated = false;
6805+ if (effect -> lv2_activated && ((effect -> hints & HINT_NO_PRE_RUN ) != 0 ))
6806+ {
6807+ effect -> lv2_activated = false;
6808+ lilv_instance_deactivate (effect -> lilv_instance );
6809+ }
6810+
6811+ effect -> jack_activated = false;
67756812
67766813 return NULL ;
67776814}
@@ -6804,7 +6841,7 @@ int effects_activate_multi(int value, int num_effects, int *effects)
68046841
68056842 if (value )
68066843 {
6807- if (! effect -> activated )
6844+ if (! effect -> jack_activated )
68086845 {
68096846 if (zix_thread_create (& threads [num_threads ], sizeof (void * ), effects_activate_thread , effect ) == 0 )
68106847 ++ num_threads ;
@@ -6814,7 +6851,7 @@ int effects_activate_multi(int value, int num_effects, int *effects)
68146851 }
68156852 else
68166853 {
6817- if (effect -> activated )
6854+ if (effect -> jack_activated )
68186855 {
68196856 if (zix_thread_create (& threads [num_threads ], sizeof (void * ), effects_deactivate_thread , effect ) == 0 )
68206857 ++ num_threads ;
@@ -7107,7 +7144,7 @@ int effects_flush_parameters_multi(int reset, int param_count, const flushed_par
71077144 {
71087145 effect = & (g_effects [effect_id ]);
71097146
7110- if (! effect -> activated )
7147+ if (! effect -> lv2_activated )
71117148 {
71127149 fprintf (stderr , "multi-param-flush attempted on non-activated plugin #%d\n" , effect -> instance );
71137150 continue ;
@@ -7194,13 +7231,6 @@ int effects_pre_run(int effect_id, int reset, int param_count, const flushed_par
71947231 return ERR_INSTANCE_NON_EXISTS ;
71957232
71967233 effect_t * effect = & (g_effects [effect_id ]);
7197-
7198- if (effect -> activated && ((effect -> hints & HINT_IS_LIVE ) != 0 || g_processing_enabled ))
7199- {
7200- fprintf (stderr , "pre-run attempted on activated plugin #%d\n" , effect_id );
7201- return ERR_INVALID_OPERATION ;
7202- }
7203-
72047234 port_t * port ;
72057235
72067236 for (int i = 0 ; i < param_count ; i ++ )
@@ -7221,6 +7251,20 @@ int effects_pre_run(int effect_id, int reset, int param_count, const flushed_par
72217251 port -> prev_value = * (port -> buffer ) = reset ;
72227252 }
72237253
7254+ if ((effect -> hints & HINT_NO_PRE_RUN ) != 0 )
7255+ return SUCCESS ;
7256+
7257+ if (effect -> jack_activated && ((effect -> hints & HINT_IS_LIVE ) != 0 || g_processing_enabled ))
7258+ {
7259+ fprintf (stderr , "pre-run attempted on jack-activated instance #%d\n" , effect_id );
7260+ return ERR_INVALID_OPERATION ;
7261+ }
7262+ if (! effect -> lv2_activated )
7263+ {
7264+ fprintf (stderr , "pre-run attempted on non lv2-activated instance #%d\n" , effect_id );
7265+ return ERR_INVALID_OPERATION ;
7266+ }
7267+
72247268 PreRunPlugin (effect );
72257269
72267270 return SUCCESS ;
@@ -7244,12 +7288,6 @@ int effects_pre_run_multi(int reset, int param_count, const flushed_param_t *par
72447288 {
72457289 effect = & (g_effects [effect_id ]);
72467290
7247- if (effect -> activated && ((effect -> hints & HINT_IS_LIVE ) != 0 || g_processing_enabled ))
7248- {
7249- fprintf (stderr , "multi-pre-run attempted on activated plugin #%d\n" , effect -> instance );
7250- continue ;
7251- }
7252-
72537291 for (int j = 0 ; j < param_count ; j ++ )
72547292 {
72557293 port = FindEffectInputPortBySymbol (effect , params [j ].symbol );
@@ -7268,6 +7306,20 @@ int effects_pre_run_multi(int reset, int param_count, const flushed_param_t *par
72687306 }
72697307 }
72707308
7309+ if (effect -> jack_activated && ((effect -> hints & HINT_IS_LIVE ) != 0 || g_processing_enabled ))
7310+ {
7311+ fprintf (stderr , "multi-pre-run attempted on jack-activated instance #%d\n" , effect -> instance );
7312+ continue ;
7313+ }
7314+ if (! effect -> lv2_activated )
7315+ {
7316+ fprintf (stderr , "multi-pre-run attempted on non lv2-activated instance #%d\n" , effect -> instance );
7317+ continue ;
7318+ }
7319+
7320+ if ((effect -> hints & HINT_NO_PRE_RUN ) != 0 )
7321+ continue ;
7322+
72717323 PreRunPlugin (effect );
72727324 }
72737325 }
0 commit comments