mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
group sample/pulse/usecs into Instant
This commit is contained in:
parent
205dbef9b0
commit
fec6294c7b
4 changed files with 43 additions and 20 deletions
|
|
@ -181,13 +181,13 @@ pub trait Quantize<T> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Keeps track of global time units.
|
||||
/// Defines global temporal resolutions.
|
||||
pub struct Timebase {
|
||||
/// Samples per second
|
||||
/// Audio samples per second
|
||||
pub sr: AtomicF64,
|
||||
/// Beats per minute
|
||||
/// MIDI beats per minute
|
||||
pub bpm: AtomicF64,
|
||||
/// Ticks per beat
|
||||
/// MIDI ticks per beat
|
||||
pub ppq: AtomicF64,
|
||||
}
|
||||
impl Default for Timebase { fn default () -> Self { Self::new(48000f64, 150f64, 96f64) } }
|
||||
|
|
@ -210,6 +210,33 @@ impl PulsesPerQuaver<f64> for Timebase {
|
|||
#[inline] fn set_ppq (&self, ppq: f64) { self.ppq.store(ppq, Ordering::Relaxed); }
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
/// Represents a point in time in all scales
|
||||
pub struct Instant {
|
||||
/// Current time in microseconds
|
||||
pub usec: AtomicUsize,
|
||||
/// Current time in audio samples
|
||||
pub sample: AtomicUsize,
|
||||
/// Current time in MIDI pulses
|
||||
pub pulse: AtomicF64,
|
||||
}
|
||||
impl FramePosition<usize> for Instant {
|
||||
#[inline] fn sample (&self) -> usize { self.sample.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_sample (&self, sample: usize) { self.sample.store(sample, Ordering::Relaxed); }
|
||||
}
|
||||
impl UsecPosition<usize> for Instant {
|
||||
#[inline] fn usec (&self) -> usize { self.usec.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_usec (&self, usec: usize) { self.usec.store(usec, Ordering::Relaxed); }
|
||||
}
|
||||
impl PulsePosition<f64> for Instant {
|
||||
#[inline] fn pulse (&self) -> f64 { self.pulse.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_pulse (&self, usec: f64) { self.pulse.store(usec, Ordering::Relaxed); }
|
||||
}
|
||||
impl PulsePosition<usize> for Instant {
|
||||
#[inline] fn pulse (&self) -> usize { self.pulse.load(Ordering::Relaxed) as usize }
|
||||
#[inline] fn set_pulse (&self, usec: usize) { self.pulse.store(usec as f64, Ordering::Relaxed); }
|
||||
}
|
||||
|
||||
/// (pulses, name)
|
||||
pub const NOTE_DURATIONS: [(usize, &str);26] = [
|
||||
(1, "1/384"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue