mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
refactor: atomic timebase
This commit is contained in:
parent
87c5e47b43
commit
f77c84a99c
5 changed files with 116 additions and 99 deletions
|
|
@ -3,7 +3,9 @@ use crate::prelude::*;
|
|||
pub struct Transport {
|
||||
name: String,
|
||||
/// Holds info about tempo
|
||||
timebase: Arc<Mutex<Timebase>>,
|
||||
timebase: Arc<Timebase>,
|
||||
|
||||
transport: ::jack::Transport,
|
||||
}
|
||||
|
||||
impl Transport {
|
||||
|
|
@ -12,11 +14,17 @@ impl Transport {
|
|||
let transport = client.transport();
|
||||
DynamicDevice::new(render, handle, process, Self {
|
||||
name: name.into(),
|
||||
timebase: Timebase {
|
||||
rate: transport.query()?.pos.frame_rate(),
|
||||
tempo: 113000,
|
||||
ppq: 96,
|
||||
},
|
||||
timebase: Arc::new(Timebase {
|
||||
rate: AtomicUsize::new(
|
||||
transport.query()?.pos.frame_rate().map(|x|x as usize).unwrap_or(0)
|
||||
),
|
||||
tempo: AtomicUsize::new(
|
||||
113000
|
||||
),
|
||||
ppq: AtomicUsize::new(
|
||||
96
|
||||
),
|
||||
}),
|
||||
transport
|
||||
}).activate(client)
|
||||
}
|
||||
|
|
@ -39,6 +47,10 @@ impl Transport {
|
|||
pub fn stop (&mut self) -> Result<(), Box<dyn Error>> {
|
||||
Ok(self.transport.stop()?)
|
||||
}
|
||||
|
||||
pub fn timebase (&self) -> Arc<Timebase> {
|
||||
self.timebase.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process (_: &mut Transport, _: &Client, _: &ProcessScope) -> Control {
|
||||
|
|
@ -63,8 +75,8 @@ pub fn render (state: &Transport, buf: &mut Buffer, mut area: Rect)
|
|||
"0.0.00",
|
||||
"0:00.000",
|
||||
&format!("BPM {:03}.{:03}",
|
||||
state.bpm as u64,
|
||||
((state.bpm % 1.0) * 1000.0) as u64
|
||||
state.timebase.tempo() / 1000,
|
||||
state.timebase.tempo() % 1000,
|
||||
)
|
||||
].iter() {
|
||||
buf.set_string(area.x + x, area.y + 2, button, label);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue