mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
extract TransportClock
This commit is contained in:
parent
ccc74fd743
commit
85e243f782
6 changed files with 130 additions and 145 deletions
|
|
@ -103,6 +103,16 @@ pub trait UsecPosition<T> {
|
|||
fn set_usec (&self, usec: T);
|
||||
}
|
||||
|
||||
pub trait LaunchSync<T> {
|
||||
fn sync (&self) -> T;
|
||||
fn set_sync (&self, sync: T);
|
||||
}
|
||||
|
||||
pub trait Quantize<T> {
|
||||
fn quant (&self) -> T;
|
||||
fn set_quant (&self, quant: T);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Keeps track of global time units.
|
||||
pub struct Timebase {
|
||||
|
|
@ -133,47 +143,6 @@ impl PulsesPerQuaver<f64> for Timebase {
|
|||
#[inline] fn set_ppq (&self, ppq: f64) { self.ppq.store(ppq, Ordering::Relaxed); }
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TransportTime {
|
||||
/// Current sample sr, tempo, and PPQ.
|
||||
pub timebase: Arc<Timebase>,
|
||||
/// Note quantization factor
|
||||
pub quant: usize,
|
||||
/// Launch quantization factor
|
||||
pub sync: usize,
|
||||
/// Current time in frames
|
||||
pub frame: usize,
|
||||
/// Current time in pulses
|
||||
pub pulse: usize,
|
||||
/// Current time in microseconds
|
||||
pub usecs: usize,
|
||||
/// Pulses per quarter note
|
||||
pub ppq: usize,
|
||||
}
|
||||
impl SampleRate<f64> for TransportTime {
|
||||
#[inline] fn sr (&self) -> f64 { self.timebase.sr() }
|
||||
#[inline] fn set_sr (&self, sr: f64) { self.timebase.set_sr(sr); }
|
||||
}
|
||||
impl BeatsPerMinute<f64> for TransportTime {
|
||||
#[inline] fn bpm (&self) -> f64 { self.timebase.bpm() }
|
||||
#[inline] fn set_bpm (&self, bpm: f64) { self.timebase.set_bpm(bpm); }
|
||||
}
|
||||
impl PulsesPerQuaver<f64> for TransportTime {
|
||||
const DEFAULT_PPQ: f64 = Timebase::DEFAULT_PPQ;
|
||||
#[inline] fn ppq (&self) -> f64 { self.timebase.ppq() }
|
||||
#[inline] fn set_ppq (&self, ppq: f64) { self.timebase.set_ppq(ppq); }
|
||||
}
|
||||
|
||||
pub trait LaunchSync<T> {
|
||||
fn sync (&self) -> T;
|
||||
fn set_sync (&self, sync: T) -> T;
|
||||
}
|
||||
|
||||
pub trait Quantize<T> {
|
||||
fn quant (&self) -> T;
|
||||
fn set_quant (&self, quant: T);
|
||||
}
|
||||
|
||||
/// (pulses, name)
|
||||
pub const NOTE_DURATIONS: [(usize, &str);26] = [
|
||||
(1, "1/384"),
|
||||
|
|
@ -205,32 +174,22 @@ pub const NOTE_DURATIONS: [(usize, &str);26] = [
|
|||
];
|
||||
|
||||
/// Returns the next shorter length
|
||||
pub fn prev_note_length (ppq: usize) -> usize {
|
||||
pub fn prev_note_length (pulses: usize) -> usize {
|
||||
for i in 1..=16 {
|
||||
let length = NOTE_DURATIONS[16-i].0;
|
||||
if length < ppq {
|
||||
return length
|
||||
}
|
||||
if length < pulses { return length }
|
||||
}
|
||||
ppq
|
||||
pulses
|
||||
}
|
||||
|
||||
/// 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 next_note_length (pulses: usize) -> usize {
|
||||
for (length, _) in &NOTE_DURATIONS { if *length > pulses { return *length } }
|
||||
pulses
|
||||
}
|
||||
|
||||
pub fn ppq_to_name (ppq: usize) -> &'static str {
|
||||
for (length, name) in &NOTE_DURATIONS {
|
||||
if *length == ppq {
|
||||
return name
|
||||
}
|
||||
}
|
||||
pub fn pulses_to_name (pulses: usize) -> &'static str {
|
||||
for (length, name) in &NOTE_DURATIONS { if *length == pulses { return name } }
|
||||
""
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue