use Arc<str> where applicable; use konst split_at

This commit is contained in:
🪞👃🪞 2025-01-08 00:24:40 +01:00
parent 411fc0c4bc
commit 305481adee
35 changed files with 286 additions and 273 deletions

View file

@ -46,17 +46,20 @@ render!(TuiOut: (self: PlayPause) => Tui::bg(
Tui::fg(Color::Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
Tui::fg(Color::Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",))))))));
pub struct BeatStats { compact: bool, bpm: String, beat: String, time: String, }
pub struct BeatStats { compact: bool, bpm: Arc<str>, beat: Arc<str>, time: Arc<str>, }
impl BeatStats {
fn new (compact: bool, clock: &Clock) -> Self {
let (beat, time) = clock.started.read().unwrap().as_ref().map(|started|{
let current_usec = clock.global.usec.get() - started.usec.get();
let bpm = format!("{:.3}", clock.timebase.bpm.get()).into();
let (beat, time) = if let Some(started) = clock.started.read().unwrap().as_ref() {
let now = clock.global.usec.get() - started.usec.get();
(
clock.timebase.format_beats_1(clock.timebase.usecs_to_pulse(current_usec)),
format!("{:.3}s", current_usec/1000000.)
clock.timebase.format_beats_1(clock.timebase.usecs_to_pulse(now)).into(),
format!("{:.3}s", now/1000000.).into()
)
}).unwrap_or_else(||("-.-.--".to_string(), "-.---s".to_string()));
Self { compact, bpm: format!("{:.3}", clock.timebase.bpm.get()), beat, time }
} else {
("-.-.--".to_string().into(), "-.---s".to_string().into())
};
Self { compact, bpm, beat, time }
}
}
render!(TuiOut: (self: BeatStats) => Either(self.compact,
@ -71,7 +74,7 @@ render!(TuiOut: (self: BeatStats) => Either(self.compact,
Bsp::e("Time ", Tui::fg(TuiTheme::g(255), &self.time)),
)));
pub struct OutputStats { compact: bool, sample_rate: String, buffer_size: String, latency: String, }
pub struct OutputStats { compact: bool, sample_rate: Arc<str>, buffer_size: Arc<str>, latency: Arc<str>, }
impl OutputStats {
fn new (compact: bool, clock: &Clock) -> Self {
let rate = clock.timebase.sr.get();
@ -82,9 +85,9 @@ impl OutputStats {
format!("{:.1}kHz", rate / 1000.)
} else {
format!("{:.0}Hz", rate)
},
buffer_size: format!("{chunk}"),
latency: format!("{:.1}ms", chunk as f64 / rate * 1000.),
}.into(),
buffer_size: format!("{chunk}").into(),
latency: format!("{:.1}ms", chunk as f64 / rate * 1000.).into(),
}
}
}