refactor tick timer to make sense

This commit is contained in:
🪞👃🪞 2024-07-06 14:13:31 +03:00
parent b3e6206b08
commit 597c3fa903
4 changed files with 82 additions and 80 deletions

View file

@ -13,7 +13,7 @@ impl Default for Timebase {
fn default () -> Self {
Self {
rate: 48000f64.into(),
bpm: 125f64.into(),
bpm: 100f64.into(),
ppq: 96f64.into(),
}
}
@ -49,12 +49,12 @@ impl Timebase {
#[inline] pub fn ppq (&self) -> f64 {
self.ppq.load(Ordering::Relaxed)
}
#[inline] fn usec_per_pulse (&self) -> f64 {
self.usec_per_beat() / self.ppq() as f64
}
#[inline] pub fn pulse_per_frame (&self) -> f64 {
self.usec_per_pulse() / self.usec_per_frame() as f64
}
#[inline] fn usec_per_pulse (&self) -> f64 {
self.usec_per_beat() / self.ppq() as f64
}
#[inline] pub fn frame_to_pulse (&self, pulses: f64) -> f64 {
self.pulse_per_frame() * pulses
}
@ -64,19 +64,19 @@ impl Timebase {
#[inline] pub fn note_to_usec (&self, (num, den): (f64, f64)) -> f64 {
4.0 * self.usec_per_beat() * num / den
}
#[inline] fn pulses_per_second (&self) -> f64 {
self.beat_per_second() * self.ppq() as f64
}
#[inline] pub fn frames_per_pulse (&self) -> f64 {
self.rate() as f64 / self.pulses_per_second()
}
#[inline] fn usec_to_frame (&self, usec: f64) -> f64 {
usec * self.rate() / 1000.0
#[inline] fn pulses_per_second (&self) -> f64 {
self.beat_per_second() * self.ppq() as f64
}
#[inline] pub fn note_to_frame (&self, note: (f64, f64)) -> f64 {
self.usec_to_frame(self.note_to_usec(note))
}
#[inline] fn usec_to_frame (&self, usec: f64) -> f64 {
usec * self.rate() / 1000.0
}
#[inline] pub fn quantize (
&self, step: (f64, f64), time: f64