mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
wip: f64 timebase (sloooo)
This commit is contained in:
parent
c4d8692b71
commit
4055662bbd
12 changed files with 206 additions and 142 deletions
|
|
@ -2,10 +2,10 @@ use crate::core::*;
|
|||
use crate::layout::*;
|
||||
|
||||
pub fn draw_timer (buf: &mut Buffer, x: u16, y: u16, timebase: &Arc<Timebase>, frame: usize) {
|
||||
let tick = (frame as f64 / timebase.frames_per_tick()) as usize;
|
||||
let tick = (frame as f64 / timebase.frames_per_tick());
|
||||
let (beats, ticks) = (tick / timebase.ppq(), tick % timebase.ppq());
|
||||
let (bars, beats) = (beats / 4, beats % 4);
|
||||
let timer = format!("{}.{}.{ticks:02}", bars + 1, beats + 1);
|
||||
let (bars, beats) = (beats / 4.0, beats % 4.0);
|
||||
let timer = format!("{}.{}.{ticks:02}", bars as usize + 1, beats as usize + 1);
|
||||
timer.blit(buf, x - timer.len() as u16, y, Some(Style::default().not_dim()));
|
||||
}
|
||||
pub fn draw_play_stop (buf: &mut Buffer, x: u16, y: u16, state: &TransportState) {
|
||||
|
|
@ -66,17 +66,11 @@ pub struct Transport {
|
|||
}
|
||||
|
||||
impl Transport {
|
||||
pub fn new (name: &str) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
|
||||
pub fn new (name: &str, timebase: &Arc<Timebase>) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
|
||||
let (client, _) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
||||
let transport = client.transport();
|
||||
DynamicDevice::new(render, handle, process, Self {
|
||||
name: name.into(),
|
||||
timebase: Arc::new(Timebase {
|
||||
rate: AtomicUsize::new(client.sample_rate()),
|
||||
bpm: AtomicUsize::new(113000),
|
||||
ppq: AtomicUsize::new(96),
|
||||
}),
|
||||
transport
|
||||
name: name.into(), timebase: timebase.clone(), transport
|
||||
}).activate(client)
|
||||
}
|
||||
|
||||
|
|
@ -128,8 +122,8 @@ pub fn render (state: &Transport, buf: &mut Buffer, mut area: Rect)
|
|||
"REC",
|
||||
"DUB",
|
||||
&format!("BPM {:03}.{:03}",
|
||||
state.timebase.bpm() / 1000,
|
||||
state.timebase.bpm() % 1000,
|
||||
state.timebase.bpm() / 1000.0,
|
||||
state.timebase.bpm() % 1000.0,
|
||||
),
|
||||
"0.0+00",
|
||||
"0:00.000",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue