Skip to content

Commit 34342d5

Browse files
authored
Merge pull request #14 from ardura/fixing-sync-other-daws
Fixing sync other daws
2 parents 623bbe0 + c1fb771 commit 34342d5

File tree

4 files changed

+107
-10
lines changed

4 files changed

+107
-10
lines changed

.vscode/launch.json

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "cppvsdbg",
9+
"request": "attach",
10+
"name": "Debug the plugin inside a DAW",
11+
"processId": "${command:pickProcess}",
12+
"internalConsoleOptions": "openOnSessionStart",
13+
"symbolOptions": {
14+
"searchPaths": ["${workspaceFolder}/target/debug", "${workspaceFolder}/target/profiling"],
15+
"searchMicrosoftSymbolServer": false
16+
}
17+
},
18+
{
19+
"type": "lldb",
20+
"request": "launch",
21+
"name": "Debug executable 'xtask'",
22+
"cargo": {
23+
"args": [
24+
"build",
25+
"--bin=xtask",
26+
"--package=xtask"
27+
],
28+
"filter": {
29+
"name": "xtask",
30+
"kind": "bin"
31+
}
32+
},
33+
"args": [],
34+
"cwd": "${workspaceFolder}"
35+
},
36+
{
37+
"type": "lldb",
38+
"request": "launch",
39+
"name": "Debug unit tests in executable 'xtask'",
40+
"cargo": {
41+
"args": [
42+
"test",
43+
"--no-run",
44+
"--bin=xtask",
45+
"--package=xtask"
46+
],
47+
"filter": {
48+
"name": "xtask",
49+
"kind": "bin"
50+
}
51+
},
52+
"args": [],
53+
"cwd": "${workspaceFolder}"
54+
},
55+
{
56+
"type": "lldb",
57+
"request": "launch",
58+
"name": "Debug unit tests in library 'Subhoofer'",
59+
"cargo": {
60+
"args": [
61+
"test",
62+
"--no-run",
63+
"--lib",
64+
"--package=Subhoofer"
65+
],
66+
"filter": {
67+
"name": "Subhoofer",
68+
"kind": "lib"
69+
}
70+
},
71+
"args": [],
72+
"cwd": "${workspaceFolder}"
73+
}
74+
]
75+
}

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: 3 additions & 2 deletions
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"
@@ -25,6 +25,7 @@ strip = "symbols"
2525

2626
[profile.profiling]
2727
inherits = "release"
28-
opt-level = 2
28+
lto = "off"
29+
opt-level = 0
2930
debug = true
3031
strip = "none"

src/lib.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)