@@ -35,6 +35,8 @@ pub struct Gain {
3535
3636 // Syncing for beats
3737 sync_var : Arc < Mutex < bool > > ,
38+ alt_sync : Arc < Mutex < bool > > ,
39+ alt_sync_beat : Arc < Mutex < i64 > > ,
3840 in_place_index : Arc < AtomicI32 > ,
3941}
4042
@@ -72,6 +74,8 @@ impl Default for Gain {
7274 samples : Arc :: new ( Mutex :: new ( VecDeque :: with_capacity ( 130 ) ) ) ,
7375 aux_samples : Arc :: new ( Mutex :: new ( VecDeque :: with_capacity ( 130 ) ) ) ,
7476 sync_var : Arc :: new ( Mutex :: new ( false ) ) ,
77+ alt_sync : Arc :: new ( Mutex :: new ( false ) ) ,
78+ alt_sync_beat : Arc :: new ( Mutex :: new ( 0 ) ) ,
7579 in_place_index : Arc :: new ( AtomicI32 :: new ( 0 ) ) ,
7680 }
7781 }
@@ -145,6 +149,7 @@ impl Plugin for Gain {
145149 let ontop = self . swap_draw_order . clone ( ) ;
146150 let is_clipping = self . is_clipping . clone ( ) ;
147151 let sync_var = self . sync_var . clone ( ) ;
152+ let alt_sync = self . alt_sync . clone ( ) ;
148153 let dir_var = self . direction . clone ( ) ;
149154 let user_color_primary = self . user_color_primary . clone ( ) ;
150155 let user_color_secondary = self . user_color_secondary . clone ( ) ;
@@ -221,14 +226,15 @@ impl Plugin for Gain {
221226 let _swap_response = ui. checkbox ( & mut ontop. lock ( ) , "Swap" ) . on_hover_text ( "Change the drawing order of waveforms" ) ;
222227
223228 let sync_response = ui. checkbox ( & mut sync_var. lock ( ) , "Sync Beat" ) . on_hover_text ( "Lock drawing to beat" ) ;
229+ let alt_sync = ui. checkbox ( & mut alt_sync. lock ( ) , "Alt. Sync" ) . on_hover_text ( "Try this if Sync doesn't work" ) ;
224230
225231 let dir_response = ui. checkbox ( & mut dir_var. lock ( ) , "Flip" ) . on_hover_text ( "Flip direction of oscilloscope" ) ;
226232
227233 if gain_handle. changed ( ) {
228234 sum_line = Line :: new ( PlotPoints :: default ( ) ) ;
229235 }
230236 // Reset our line on change
231- if sync_response. clicked ( ) || dir_response. clicked ( )
237+ if sync_response. clicked ( ) || dir_response. clicked ( ) || alt_sync . clicked ( )
232238 {
233239 sum_line = Line :: new ( PlotPoints :: default ( ) ) ;
234240 aux_line = Line :: new ( PlotPoints :: default ( ) ) ;
@@ -367,12 +373,27 @@ impl Plugin for Gain {
367373 // If we are beat syncing - this resets our position in time accordingly
368374 if * self . sync_var . lock ( ) {
369375 // Make the current bar precision a one thousandth of a beat - I couldn't find a better way to do this
370- let mut current_bar_position: f64 = context. transport ( ) . pos_beats ( ) . unwrap ( ) ;
371- current_bar_position = ( current_bar_position * 10000.0 as f64 ) . round ( ) / 10000.0 as f64 ;
372- if current_bar_position % 1.0 == 0.0 {
373- // Reset our index to the sample vecdeques
374- self . in_place_index = Arc :: new ( AtomicI32 :: new ( 0 ) ) ;
375- self . skip_counter = 0 ;
376+ let mut current_beat: f64 = context. transport ( ) . pos_beats ( ) . unwrap ( ) ;
377+
378+ if * self . alt_sync . lock ( ) {
379+ // This is scaled a little more to catch things earlier due to thread timing in Ardour
380+ // This should still play well with other DAWs using this timing
381+ current_beat = ( ( current_beat + 0.036 ) * 100.0 as f64 ) . round ( ) / 100.0 as f64 ;
382+ let current_bar = current_beat as i64 ;
383+ // Tracks based off beat number for other daws - this is a mutex instead of atomic for locking
384+ if * self . alt_sync_beat . lock ( ) != current_bar {
385+ self . in_place_index = Arc :: new ( AtomicI32 :: new ( 0 ) ) ;
386+ self . skip_counter = 0 ;
387+ * self . alt_sync_beat . lock ( ) = current_bar;
388+ }
389+ } else {
390+ // Works in FL Studio but not other daws, hence the previous couple of lines
391+ current_beat = ( current_beat * 10000.0 as f64 ) . round ( ) / 10000.0 as f64 ;
392+ if current_beat % 1.0 == 0.0 {
393+ // Reset our index to the sample vecdeques
394+ self . in_place_index = Arc :: new ( AtomicI32 :: new ( 0 ) ) ;
395+ self . skip_counter = 0 ;
396+ }
376397 }
377398 }
378399
0 commit comments