Skip to content

Commit 86ad448

Browse files
committed
Testing somewhat of a solution
1 parent 4314374 commit 86ad448

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "scrollscope"
3-
version = "0.1.0"
3+
version = "1.1.1"
44
edition = "2021"
55
authors = ["Ardura <azviscarra@gmail.com>"]
66
license = "GPL-3.0-or-later"

src/lib.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct Gain {
3636
// Syncing for beats
3737
sync_var: Arc<Mutex<bool>>,
3838
alt_sync: Arc<Mutex<bool>>,
39-
alt_sync_beat: Arc<AtomicI32>,
39+
alt_sync_beat: Arc<Mutex<i64>>,
4040
in_place_index: Arc<AtomicI32>,
4141
}
4242

@@ -75,7 +75,7 @@ impl Default for Gain {
7575
aux_samples: Arc::new(Mutex::new(VecDeque::with_capacity(130))),
7676
sync_var: Arc::new(Mutex::new(false)),
7777
alt_sync: Arc::new(Mutex::new(false)),
78-
alt_sync_beat: Arc::new(AtomicI32::new(0)),
78+
alt_sync_beat: Arc::new(Mutex::new(0)),
7979
in_place_index: Arc::new(AtomicI32::new(0)),
8080
}
8181
}
@@ -373,23 +373,24 @@ impl Plugin for Gain {
373373
// If we are beat syncing - this resets our position in time accordingly
374374
if *self.sync_var.lock() {
375375
// Make the current bar precision a one thousandth of a beat - I couldn't find a better way to do this
376-
let mut current_bar_position: f64 = context.transport().pos_beats().unwrap();
376+
let mut current_beat: f64 = context.transport().pos_beats().unwrap();
377377

378378
if *self.alt_sync.lock() {
379-
// Tracks based off beat floor number
380-
if self.alt_sync_beat.load(Ordering::Relaxed) != current_bar_position.floor() as i32 {
381-
self.alt_sync_beat.store(current_bar_position.floor() as i32,Ordering::Relaxed);
379+
let current_bar = current_beat as i64;
380+
// Tracks based off beat number for other daws - this is a mutex instead of atomic for locking
381+
if *self.alt_sync_beat.lock() != current_bar {
382+
self.in_place_index = Arc::new(AtomicI32::new(0));
383+
self.skip_counter = 0;
384+
*self.alt_sync_beat.lock() = current_bar;
382385
}
383-
current_bar_position = 1.0;
384386
} else {
385387
// Works in FL Studio but not other daws, hence the previous couple of lines
386-
current_bar_position = (current_bar_position * 1000.0 as f64).round() / 1000.0 as f64;
387-
}
388-
389-
if current_bar_position % 1.0 == 0.0 {
390-
// Reset our index to the sample vecdeques
391-
self.in_place_index = Arc::new(AtomicI32::new(0));
392-
self.skip_counter = 0;
388+
current_beat = (current_beat * 1000.0 as f64).round() / 1000.0 as f64;
389+
if current_beat % 1.0 == 0.0 {
390+
// Reset our index to the sample vecdeques
391+
self.in_place_index = Arc::new(AtomicI32::new(0));
392+
self.skip_counter = 0;
393+
}
393394
}
394395
}
395396

0 commit comments

Comments
 (0)