diff --git a/bin/cli_groovebox.rs b/bin/cli_groovebox.rs index 15a9912b..e68776c9 100644 --- a/bin/cli_groovebox.rs +++ b/bin/cli_groovebox.rs @@ -46,24 +46,11 @@ impl GrooveboxCli { if self.sync { jack.read().unwrap().client().register_timebase_callback(false, |state|{ let ::jack::contrib::TimebaseInfo { state, new_pos, nframes, mut position } = state; + println!("\n\r{state:?} {new_pos} {nframes} {position:?}"); + position.bbt = Some(app.clock().bbt()); + println!("\r{:?}", position.bbt); if new_pos { app.clock().playhead.update_from_sample(position.frame() as f64) - } else { - 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(); - 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 })? diff --git a/rust-jack b/rust-jack index de9a6b4e..cfd2a62e 160000 --- a/rust-jack +++ b/rust-jack @@ -1 +1 @@ -Subproject commit de9a6b4e46c403b08703b272b5b2ee353aa6cb53 +Subproject commit cfd2a62e959f2a0f5569a129790cfdb316570a7f diff --git a/src/time.rs b/src/time.rs index 5b3b8c35..0f1241c8 100644 --- a/src/time.rs +++ b/src/time.rs @@ -199,6 +199,23 @@ impl ClockModel { Ok(()) } + + pub fn bbt (&self) -> ::jack::contrib::PositionBBT { + let pulse = self.playhead.pulse.get() as i32; + let ppq = self.timebase.ppq.get() as i32; + let bpm = self.timebase.bpm.get(); + let bar = (pulse / ppq) / 4; + ::jack::contrib::PositionBBT { + bar: 1 + bar, + beat: 1 + (pulse / ppq) % 4, + tick: (pulse % ppq), + bar_start_tick: (bar * 4 * ppq) as f64, + beat_type: 4., + beats_per_bar: 4., + beats_per_minute: bpm, + ticks_per_beat: ppq as f64 + } + } } //#[cfg(test)]