mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: remodularize 2
This commit is contained in:
parent
3b6ff81dad
commit
d38dc14e84
27 changed files with 564 additions and 563 deletions
|
|
@ -1,12 +1,13 @@
|
|||
mod clock_tui; pub use self::clock_tui::*;
|
||||
mod microsecond; pub use self::microsecond::*;
|
||||
mod moment; pub use self::moment::*;
|
||||
mod perf; pub use self::perf::*;
|
||||
mod pulse; pub use self::pulse::*;
|
||||
mod sample_count; pub use self::sample_count::*;
|
||||
mod sample_rate; pub use self::sample_rate::*;
|
||||
mod timebase; pub use self::timebase::*;
|
||||
mod unit; pub use self::unit::*;
|
||||
mod clock_tui; pub use self::clock_tui::*;
|
||||
mod microsecond; pub use self::microsecond::*;
|
||||
mod moment; pub use self::moment::*;
|
||||
mod note_duration; pub use self::note_duration::*;
|
||||
mod perf; pub use self::perf::*;
|
||||
mod pulse; pub use self::pulse::*;
|
||||
mod sample_count; pub use self::sample_count::*;
|
||||
mod sample_rate; pub use self::sample_rate::*;
|
||||
mod timebase; pub use self::timebase::*;
|
||||
mod unit; pub use self::unit::*;
|
||||
|
||||
pub(crate) use ::tek_jack::{*, jack::{*, contrib::*}};
|
||||
pub(crate) use std::sync::{Arc, Mutex, RwLock, atomic::{AtomicUsize, Ordering::*}};
|
||||
|
|
|
|||
35
time/src/note_duration.rs
Normal file
35
time/src/note_duration.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
pub struct NoteDuration;
|
||||
|
||||
/// (pulses, name), assuming 96 PPQ
|
||||
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"),
|
||||
];
|
||||
|
||||
impl NoteDuration {
|
||||
/// Returns the next shorter length
|
||||
pub fn prev (pulses: usize) -> usize {
|
||||
for (length, _) in NOTE_DURATIONS.iter().rev() { if *length < pulses { return *length } }
|
||||
pulses
|
||||
}
|
||||
/// Returns the next longer length
|
||||
pub fn next (pulses: usize) -> usize {
|
||||
for (length, _) in NOTE_DURATIONS.iter() { if *length > pulses { return *length } }
|
||||
pulses
|
||||
}
|
||||
pub fn pulses_to_name (pulses: usize) -> &'static str {
|
||||
for (length, name) in NOTE_DURATIONS.iter() { if *length == pulses { return name } }
|
||||
""
|
||||
}
|
||||
}
|
||||
|
|
@ -22,10 +22,10 @@ impl_time_unit!(BeatsPerMinute);
|
|||
impl_time_unit!(LaunchSync);
|
||||
impl LaunchSync {
|
||||
pub fn next (&self) -> f64 {
|
||||
Note::next(self.get() as usize) as f64
|
||||
NoteDuration::next(self.get() as usize) as f64
|
||||
}
|
||||
pub fn prev (&self) -> f64 {
|
||||
Note::prev(self.get() as usize) as f64
|
||||
NoteDuration::prev(self.get() as usize) as f64
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,10 +34,10 @@ impl LaunchSync {
|
|||
impl_time_unit!(Quantize);
|
||||
impl Quantize {
|
||||
pub fn next (&self) -> f64 {
|
||||
Note::next(self.get() as usize) as f64
|
||||
NoteDuration::next(self.get() as usize) as f64
|
||||
}
|
||||
pub fn prev (&self) -> f64 {
|
||||
Note::prev(self.get() as usize) as f64
|
||||
NoteDuration::prev(self.get() as usize) as f64
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue