diff --git a/crates/tek_timer/Cargo.toml b/crates/tek_timer/Cargo.toml index 3842b486..c00587d4 100644 --- a/crates/tek_timer/Cargo.toml +++ b/crates/tek_timer/Cargo.toml @@ -7,3 +7,10 @@ version = "0.1.0" tek_core = { path = "../tek_core" } tek_jack = { path = "../tek_jack" } atomic_float = "1.0.0" + +[lib] +path = "src/lib.rs" + +[[bin]] +name = "tek_timer" +path = "src/main.rs" diff --git a/crates/tek_timer/src/bin/mod.rs b/crates/tek_timer/src/bin/mod.rs deleted file mode 100644 index da3bfb60..00000000 --- a/crates/tek_timer/src/bin/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -/// Application entrypoint. -pub fn main () -> Usually<()> { - run(Arc::new(RwLock::new(TransportToolbar::standalone())))?; - Ok(()) -} diff --git a/crates/tek_timer/src/main.rs b/crates/tek_timer/src/main.rs new file mode 100644 index 00000000..712f90b2 --- /dev/null +++ b/crates/tek_timer/src/main.rs @@ -0,0 +1,17 @@ +pub(crate) use tek_core::*; +pub(crate) use tek_core::ratatui::prelude::*; +pub(crate) use tek_core::crossterm::event::{KeyCode, KeyModifiers}; +pub(crate) use tek_jack::jack::*; +pub(crate) use std::sync::{Arc, atomic::Ordering}; +pub(crate) use atomic_float::AtomicF64; +submod! { + timebase + ticks + transport + transport_focus +} +/// Application entrypoint. +pub fn main () -> Usually<()> { + run(Arc::new(RwLock::new(TransportToolbar::standalone())))?; + Ok(()) +} diff --git a/crates/tek_timer/src/ticks.rs b/crates/tek_timer/src/ticks.rs index 590631ef..2f3c4d00 100644 --- a/crates/tek_timer/src/ticks.rs +++ b/crates/tek_timer/src/ticks.rs @@ -48,3 +48,63 @@ mod test { } } + +/// (pulses, name) +pub const NOTE_DURATIONS: [(usize, &str);26] = [ + (1, "1/384"), + (2, "1/192"), + (3, "1/128"), + (4, "1/96"), + (6, "1/64"), + (8, "1/48"), + (12, "1/32"), + (16, "1/24"), + (24, "1/16"), + (32, "1/12"), + (48, "1/8"), + (64, "1/6"), + (96, "1/4"), + (128, "1/3"), + (192, "1/2"), + (256, "2/3"), + (384, "1/1"), + (512, "4/3"), + (576, "3/2"), + (768, "2/1"), + (1152, "3/1"), + (1536, "4/1"), + (2304, "6/1"), + (3072, "8/1"), + (3456, "9/1"), + (6144, "16/1"), +]; + +/// Returns the next shorter length +pub fn prev_note_length (ppq: usize) -> usize { + for i in 1..=16 { + let length = NOTE_DURATIONS[16-i].0; + if length < ppq { + return length + } + } + ppq +} + +/// Returns the next longer length +pub fn next_note_length (ppq: usize) -> usize { + for (length, _) in &NOTE_DURATIONS { + if *length > ppq { + return *length + } + } + ppq +} + +pub fn ppq_to_name (ppq: usize) -> &'static str { + for (length, name) in &NOTE_DURATIONS { + if *length == ppq { + return name + } + } + "" +}