move started field onto TransportTime

This commit is contained in:
🪞👃🪞 2024-11-02 01:17:02 +02:00
parent 4df15d6bac
commit 3ee9a670da
4 changed files with 40 additions and 48 deletions

View file

@ -59,13 +59,21 @@ macro_rules! time_unit {
time_unit!(SampleRate);
impl SampleRate {
/// Return the duration of a sample in microseconds (floating)
#[inline] pub fn usec_per_sample (&self) -> f64 { 1_000_000f64 / self.get() }
#[inline] pub fn usec_per_sample (&self) -> f64 {
1_000_000f64 / self.get()
}
/// Return the duration of a sample in microseconds (floating)
#[inline] pub fn sample_per_usec (&self) -> f64 { self.get() / 1_000_000f64 }
#[inline] pub fn sample_per_usec (&self) -> f64 {
self.get() / 1_000_000f64
}
/// Convert a number of samples to microseconds (floating)
#[inline] pub fn samples_to_usec (&self, samples: f64) -> f64 { samples * self.usec_per_sample() }
#[inline] pub fn samples_to_usec (&self, samples: f64) -> f64 {
self.usec_per_sample() * samples
}
/// Convert a number of microseconds to samples (floating)
#[inline] pub fn usecs_to_sample (&self, usecs: f64) -> f64 { usecs * self.sample_per_usec() }
#[inline] pub fn usecs_to_sample (&self, usecs: f64) -> f64 {
self.sample_per_usec() * usecs
}
}
time_unit!(BeatsPerMinute);
@ -256,28 +264,6 @@ impl Instant {
self.timebase.format_beats_1(self.pulse.get())
}
}
/// A timer with starting point, current time, and quantization
pub struct Timer {
pub timebase: Arc<Timebase>,
/// Starting point in global time
pub started: Option<Instant>,
/// Current moment in global time
pub current: Instant,
/// Note quantization factor
pub quant: Quantize,
/// Launch quantization factor
pub sync: LaunchSync,
/// Playback state
pub playing: RwLock<Option<jack::TransportState>>,
}
/// Something that defines launch quantization
impl Timer {
#[inline] pub fn next_launch_pulse (&self) -> usize {
let sync = self.sync.get() as usize;
let pulse = self.current.pulse.get() as usize;
if pulse % sync == 0 { pulse } else { (pulse / sync + 1) * sync }
}
}
/// Iterator that emits subsequent ticks within a range.
pub struct TicksIterator {
spp: f64,