mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
use Arc<str> where applicable; use konst split_at
This commit is contained in:
parent
411fc0c4bc
commit
305481adee
35 changed files with 286 additions and 273 deletions
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ use crate::*;
|
|||
impl_time_unit!(Microsecond);
|
||||
|
||||
impl Microsecond {
|
||||
#[inline] pub fn format_msu (&self) -> String {
|
||||
#[inline] pub fn format_msu (&self) -> Arc<str> {
|
||||
let usecs = self.get() as usize;
|
||||
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
|
||||
let (minutes, seconds) = (seconds / 60, seconds % 60);
|
||||
format!("{minutes}:{seconds:02}:{msecs:03}")
|
||||
format!("{minutes}:{seconds:02}:{msecs:03}").into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ impl Moment {
|
|||
self.pulse.set(pulse);
|
||||
self.sample.set(self.timebase.pulses_to_sample(pulse));
|
||||
}
|
||||
#[inline] pub fn format_beat (&self) -> String {
|
||||
self.timebase.format_beats_1(self.pulse.get())
|
||||
#[inline] pub fn format_beat (&self) -> Arc<str> {
|
||||
self.timebase.format_beats_1(self.pulse.get()).into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,32 +78,32 @@ impl Timebase {
|
|||
events.map(|(time, event)|(self.quantize(step, time).0, event)).collect()
|
||||
}
|
||||
/// Format a number of pulses into Beat.Bar.Pulse starting from 0
|
||||
#[inline] pub fn format_beats_0 (&self, pulse: f64) -> String {
|
||||
#[inline] pub fn format_beats_0 (&self, pulse: f64) -> Arc<str> {
|
||||
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, beats % 4)
|
||||
format!("{}.{}.{pulses:02}", beats / 4, beats % 4).into()
|
||||
}
|
||||
/// Format a number of pulses into Beat.Bar starting from 0
|
||||
#[inline] pub fn format_beats_0_short (&self, pulse: f64) -> String {
|
||||
#[inline] pub fn format_beats_0_short (&self, pulse: f64) -> Arc<str> {
|
||||
let pulse = pulse as usize;
|
||||
let ppq = self.ppq.get() as usize;
|
||||
let beats = if ppq > 0 { pulse / ppq } else { 0 };
|
||||
format!("{}.{}", beats / 4, beats % 4)
|
||||
format!("{}.{}", beats / 4, beats % 4).into()
|
||||
}
|
||||
/// Format a number of pulses into Beat.Bar.Pulse starting from 1
|
||||
#[inline] pub fn format_beats_1 (&self, pulse: f64) -> String {
|
||||
#[inline] pub fn format_beats_1 (&self, pulse: f64) -> Arc<str> {
|
||||
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)
|
||||
format!("{}.{}.{pulses:02}", beats / 4 + 1, beats % 4 + 1).into()
|
||||
}
|
||||
/// Format a number of pulses into Beat.Bar.Pulse starting from 1
|
||||
#[inline] pub fn format_beats_1_short (&self, pulse: f64) -> String {
|
||||
#[inline] pub fn format_beats_1_short (&self, pulse: f64) -> Arc<str> {
|
||||
let pulse = pulse as usize;
|
||||
let ppq = self.ppq.get() as usize;
|
||||
let beats = if ppq > 0 { pulse / ppq } else { 0 };
|
||||
format!("{}.{}", beats / 4 + 1, beats % 4 + 1)
|
||||
format!("{}.{}", beats / 4 + 1, beats % 4 + 1).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue