wip: removing format calls from render loop

This commit is contained in:
🪞👃🪞 2025-01-20 16:52:07 +01:00
parent 7ad574cf2a
commit 209f35440a
2 changed files with 31 additions and 10 deletions

View file

@ -93,10 +93,16 @@ impl Timebase {
}
/// Format a number of pulses into Beat.Bar.Pulse starting from 1
#[inline] pub fn format_beats_1 (&self, pulse: f64) -> Arc<str> {
let mut string = String::with_capacity(16);
self.format_beats_1_to(&mut string, pulse).expect("failed to format {pulse} into beat");
string.into()
}
/// Format a number of pulses into Beat.Bar.Pulse starting from 1
#[inline] pub fn format_beats_1_to (&self, w: &mut impl std::fmt::Write, pulse: f64) -> Result<(), std::fmt::Error> {
let pulse = pulse as usize;
let ppq = self.ppq.get() as usize;
let (beats, pulses) = if ppq > 0 { (pulse / ppq, pulse % ppq) } else { (0, 0) };
format!("{}.{}.{pulses:02}", beats / 4 + 1, beats % 4 + 1).into()
write!(w, "{}.{}.{pulses:02}", beats / 4 + 1, beats % 4 + 1)
}
/// Format a number of pulses into Beat.Bar.Pulse starting from 1
#[inline] pub fn format_beats_1_short (&self, pulse: f64) -> Arc<str> {