From cfbb9722afbb9a30f7bc93d46d7d6811d7030eb3 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 29 Dec 2024 13:54:56 +0100 Subject: [PATCH] wip: now following transport position --- bin/cli_groovebox.rs | 29 ++++++++++++++++++----------- rust-jack | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/bin/cli_groovebox.rs b/bin/cli_groovebox.rs index 6686d674..15a9912b 100644 --- a/bin/cli_groovebox.rs +++ b/bin/cli_groovebox.rs @@ -44,21 +44,28 @@ impl GrooveboxCli { jack.connect_audio_to(&app.sampler.audio_outs[0], &self.l_to)?; jack.connect_audio_to(&app.sampler.audio_outs[1], &self.r_to)?; if self.sync { - jack.read().unwrap().client().register_timebase_callback(false, |bbt, state, nframes, new_pos|{ + jack.read().unwrap().client().register_timebase_callback(false, |state|{ + let ::jack::contrib::TimebaseInfo { state, new_pos, nframes, mut position } = state; if new_pos { - let ppq = bbt.ticks_per_beat; - let pulse = bbt.bar as f64 * 4. * ppq + bbt.beat as f64 * ppq + bbt.tick as f64; - app.clock().playhead.update_from_pulse(pulse) + app.clock().playhead.update_from_sample(position.frame() as f64) } else { - let pulse = app.clock().playhead.pulse.get(); - let ppq = app.clock().timebase.ppq.get(); + println!("\n\r{state:?} {new_pos} {nframes} {position:?}"); + let pulse = app.clock().playhead.pulse.get() as i32; + let ppq = app.clock().timebase.ppq.get() as i32; let bpm = app.clock().timebase.bpm.get(); - bbt.bar = (pulse / ppq) as usize / 4; - bbt.beat = (pulse / ppq) as usize % 4; - bbt.tick = (pulse % ppq) as usize; - bbt.ticks_per_beat = ppq; - bbt.bpm = bpm; + position.bbt = Some(::jack::contrib::PositionBBT { + bar: 1 + (pulse / ppq) / 4, + beat: 1 + (pulse / ppq) % 4, + tick: (pulse % ppq), + bar_start_tick: 0., + beat_type: 4., + beats_per_bar: 4., + beats_per_minute: bpm, + ticks_per_beat: ppq as f64 + }); + println!("\n\r{:?}", position.bbt); } + position })? } Ok(app) diff --git a/rust-jack b/rust-jack index 9a94493e..de9a6b4e 160000 --- a/rust-jack +++ b/rust-jack @@ -1 +1 @@ -Subproject commit 9a94493e6efffd2137a5c7f54baa85e42d12a13f +Subproject commit de9a6b4e46c403b08703b272b5b2ee353aa6cb53