@@ -911,6 +911,7 @@ static void* PostPonedEventsThread(void* arg);
911911#ifdef MOD_HMI_CONTROL_ENABLED
912912static void * HMIClientThread (void * arg );
913913#endif
914+ static void PreRunPlugin (effect_t * effect );
914915static int ProcessPlugin (jack_nframes_t nframes , void * arg );
915916static bool SetPortValue (port_t * port , float value , int effect_id , bool is_bypass , bool from_ui );
916917static float UpdateValueFromMidi (midi_cc_t * mcc , uint16_t mvalue , bool highres );
@@ -1137,7 +1138,10 @@ static int BufferSize(jack_nframes_t nframes, void* data)
11371138 effect -> options_interface -> set (effect -> lilv_instance -> lv2_handle , options );
11381139
11391140 if (effect -> activated )
1141+ {
11401142 lilv_instance_activate (effect -> lilv_instance );
1143+ PreRunPlugin (effect );
1144+ }
11411145 }
11421146 }
11431147#ifdef HAVE_HYLIA
@@ -1897,6 +1901,126 @@ static void* HMIClientThread(void* arg)
18971901}
18981902#endif
18991903
1904+ static void PreRunPlugin (effect_t * effect )
1905+ {
1906+ if ((effect -> hints & HINT_IS_LIVE ) == 0 &&
1907+ (!g_processing_enabled || (
1908+ (effect -> hints & HINT_STATE_UNSAFE ) && pthread_mutex_lock (& effect -> state_restore_mutex ) != 0 )))
1909+ {
1910+ return ;
1911+ }
1912+
1913+ /* common variables */
1914+ port_t * port ;
1915+ unsigned int i ;
1916+ float value ;
1917+ bool needs_post = false;
1918+
1919+ if (effect -> hints & HINT_TRANSPORT )
1920+ {
1921+ effect -> transport_rolling = g_jack_rolling ;
1922+ // effect->transport_frame = pos.frame;
1923+ effect -> transport_bpb = g_transport_bpb ;
1924+ effect -> transport_bpm = g_transport_bpm ;
1925+ }
1926+ if (effect -> bpb_index >= 0 )
1927+ {
1928+ * (effect -> ports [effect -> bpb_index ]-> buffer ) = g_transport_bpb ;
1929+ }
1930+ if (effect -> bpm_index >= 0 )
1931+ {
1932+ * (effect -> ports [effect -> bpm_index ]-> buffer ) = g_transport_bpm ;
1933+ }
1934+ if (effect -> speed_index >= 0 )
1935+ {
1936+ * (effect -> ports [effect -> speed_index ]-> buffer ) = g_jack_rolling ? 1.0f : 0.0f ;
1937+ }
1938+
1939+ /* Prepare midi/event ports */
1940+ for (i = 0 ; i < effect -> input_event_ports_count ; i ++ )
1941+ {
1942+ port = effect -> input_event_ports [i ];
1943+ lv2_evbuf_reset (port -> evbuf , true);
1944+ }
1945+
1946+ for (i = 0 ; i < effect -> output_event_ports_count ; i ++ )
1947+ lv2_evbuf_reset (effect -> output_event_ports [i ]-> evbuf , false);
1948+
1949+ /* Bypass */
1950+ if (effect -> bypass > 0.5f && effect -> enabled_index < 0 )
1951+ {
1952+ lilv_instance_run (effect -> lilv_instance , 0 );
1953+ }
1954+ /* Effect process */
1955+ else
1956+ {
1957+ /* Run the effect */
1958+ lilv_instance_run (effect -> lilv_instance , 0 );
1959+
1960+ /* Notify the plugin the run() cycle is finished */
1961+ if (effect -> worker .iface )
1962+ {
1963+ /* Process any replies from the worker. */
1964+ worker_emit_responses (& effect -> worker );
1965+ if (effect -> worker .iface -> end_run )
1966+ {
1967+ effect -> worker .iface -> end_run (effect -> lilv_instance -> lv2_handle );
1968+ }
1969+ }
1970+ }
1971+
1972+ if (effect -> hints & HINT_TRIGGERS )
1973+ {
1974+ for (i = 0 ; i < effect -> input_control_ports_count ; i ++ )
1975+ {
1976+ port = effect -> input_control_ports [i ];
1977+
1978+ if ((port -> hints & HINT_TRIGGER ) && floats_differ_enough (port -> prev_value , port -> def_value ))
1979+ port -> prev_value = * (port -> buffer ) = port -> def_value ;
1980+ }
1981+ }
1982+
1983+ if (effect -> hints & HINT_OUTPUT_MONITORS )
1984+ {
1985+ for (i = 0 ; i < effect -> output_control_ports_count ; i ++ )
1986+ {
1987+ port = effect -> output_control_ports [i ];
1988+
1989+ if ((port -> hints & HINT_MONITORED ) == 0 )
1990+ continue ;
1991+
1992+ value = * (port -> buffer );
1993+
1994+ if (! floats_differ_enough (port -> prev_value , value ))
1995+ continue ;
1996+
1997+ postponed_event_list_data * const posteventptr = rtsafe_memory_pool_allocate_atomic (g_rtsafe_mem_pool );
1998+
1999+ if (posteventptr == NULL )
2000+ continue ;
2001+
2002+ port -> prev_value = value ;
2003+
2004+ posteventptr -> event .type = POSTPONED_OUTPUT_MONITOR ;
2005+ posteventptr -> event .parameter .effect_id = effect -> instance ;
2006+ posteventptr -> event .parameter .symbol = port -> symbol ;
2007+ posteventptr -> event .parameter .value = value ;
2008+
2009+ pthread_mutex_lock (& g_rtsafe_mutex );
2010+ list_add_tail (& posteventptr -> siblings , & g_rtsafe_list );
2011+ pthread_mutex_unlock (& g_rtsafe_mutex );
2012+
2013+ needs_post = true;
2014+ }
2015+ }
2016+
2017+ if (effect -> hints & HINT_STATE_UNSAFE )
2018+ pthread_mutex_unlock (& effect -> state_restore_mutex );
2019+
2020+ if (needs_post )
2021+ sem_post (& g_postevents_semaphore );
2022+ }
2023+
19002024static int ProcessPlugin (jack_nframes_t nframes , void * arg )
19012025{
19022026 effect_t * effect ;
@@ -5122,7 +5246,7 @@ int effects_add(const char *uri, int instance, int activate)
51225246 if (lilv_plugin_has_extension_data (effect -> lilv_plugin , g_lilv_nodes .worker_interface ))
51235247 {
51245248 const LV2_Worker_Interface * worker_interface =
5125- (const LV2_Worker_Interface * ) lilv_instance_get_extension_data (effect -> lilv_instance ,
5249+ (const LV2_Worker_Interface * ) lilv_instance_get_extension_data (lilv_instance ,
51265250 LV2_WORKER__interface );
51275251
51285252 worker_init (& effect -> worker , lilv_instance , worker_interface , worker_buf_size );
@@ -5131,21 +5255,21 @@ int effects_add(const char *uri, int instance, int activate)
51315255 if (lilv_plugin_has_extension_data (effect -> lilv_plugin , g_lilv_nodes .options_interface ))
51325256 {
51335257 effect -> options_interface =
5134- (const LV2_Options_Interface * ) lilv_instance_get_extension_data (effect -> lilv_instance ,
5258+ (const LV2_Options_Interface * ) lilv_instance_get_extension_data (lilv_instance ,
51355259 LV2_OPTIONS__interface );
51365260 }
51375261
51385262 if (lilv_plugin_has_extension_data (effect -> lilv_plugin , g_lilv_nodes .license_interface ))
51395263 {
51405264 effect -> license_iface =
5141- (const MOD_License_Interface * ) lilv_instance_get_extension_data (effect -> lilv_instance ,
5265+ (const MOD_License_Interface * ) lilv_instance_get_extension_data (lilv_instance ,
51425266 MOD_LICENSE__interface );
51435267 }
51445268
51455269 if (lilv_plugin_has_extension_data (effect -> lilv_plugin , g_lilv_nodes .state_interface ))
51465270 {
51475271 effect -> state_iface =
5148- (const LV2_State_Interface * ) lilv_instance_get_extension_data (effect -> lilv_instance ,
5272+ (const LV2_State_Interface * ) lilv_instance_get_extension_data (lilv_instance ,
51495273 LV2_STATE__interface );
51505274 effect -> hints |= HINT_HAS_STATE ;
51515275
@@ -5160,7 +5284,7 @@ int effects_add(const char *uri, int instance, int activate)
51605284 LilvState * state = lilv_state_new_from_world (g_lv2_data , & g_urid_map , plugin_uri );
51615285
51625286 if (state != NULL ) {
5163- lilv_state_restore (state , effect -> lilv_instance , NULL , NULL ,
5287+ lilv_state_restore (state , lilv_instance , NULL , NULL ,
51645288 LV2_STATE_IS_POD |LV2_STATE_IS_PORTABLE , effect -> features );
51655289 lilv_state_free (state );
51665290 }
@@ -5171,7 +5295,7 @@ int effects_add(const char *uri, int instance, int activate)
51715295 if (lilv_plugin_has_extension_data (effect -> lilv_plugin , g_lilv_nodes .hmi_interface ))
51725296 {
51735297 effect -> hmi_notif =
5174- (const LV2_HMI_PluginNotification * ) lilv_instance_get_extension_data (effect -> lilv_instance ,
5298+ (const LV2_HMI_PluginNotification * ) lilv_instance_get_extension_data (lilv_instance ,
51755299 LV2_HMI__PluginNotification );
51765300 }
51775301#endif
@@ -5890,6 +6014,7 @@ int effects_add(const char *uri, int instance, int activate)
58906014 if (activate )
58916015 {
58926016 lilv_instance_activate (lilv_instance );
6017+ PreRunPlugin (effect );
58936018
58946019 /* Try activate the Jack client */
58956020 if (jack_activate (jack_client ) != 0 )
@@ -6586,6 +6711,7 @@ int effects_activate(int effect_id, int value)
65866711 {
65876712 effect -> activated = true;
65886713 lilv_instance_activate (effect -> lilv_instance );
6714+ PreRunPlugin (effect );
65896715
65906716 if (jack_activate (effect -> jack_client ) != 0 )
65916717 {
@@ -6615,9 +6741,11 @@ int effects_activate(int effect_id, int value)
66156741
66166742static void * effects_activate_thread (void * arg )
66176743{
6618- jack_client_t * jack_client = arg ;
6744+ effect_t * effect = arg ;
66196745
6620- if (jack_activate (jack_client ) != 0 )
6746+ PreRunPlugin (effect );
6747+
6748+ if (jack_activate (effect -> jack_client ) != 0 )
66216749 fprintf (stderr , "can't activate jack_client\n" );
66226750
66236751 return NULL ;
@@ -6666,10 +6794,15 @@ int effects_activate_multi(int value, int num_effects, int *effects)
66666794 effect -> activated = true;
66676795 lilv_instance_activate (effect -> lilv_instance );
66686796
6669- if (zix_thread_create (& threads [num_threads ], sizeof (void * ), effects_activate_thread , effect -> jack_client ) == 0 )
6797+ if (zix_thread_create (& threads [num_threads ], sizeof (void * ), effects_activate_thread , effect ) == 0 )
6798+ {
66706799 ++ num_threads ;
6800+ }
66716801 else
6802+ {
6803+ PreRunPlugin (effect );
66726804 jack_activate (effect -> jack_client );
6805+ }
66736806 }
66746807 }
66756808 else
0 commit comments