rework status bar

This commit is contained in:
🪞👃🪞 2024-12-15 01:09:10 +01:00
parent 999dc5906e
commit a25272ad1b
2 changed files with 54 additions and 99 deletions

View file

@ -173,10 +173,10 @@ audio!(|self:SequencerTui,client,scope|{
Control::Continue Control::Continue
}); });
render!(|self: SequencerTui|lay!([self.size, Tui::split_n(false, 3, render!(|self: SequencerTui|lay!([self.size, Tui::split_n(false, 4,
Tui::fill_xy(col!([ Tui::fill_xy(col!([
PhraseEditStatus(&self.editor), PhraseEditStatus(&self.editor),
SequencerStatusBar::from(self) SequencerStatusBar::from(self),
])), ])),
Tui::split_e(false, if self.size.w() > 60 { Tui::split_e(false, if self.size.w() > 60 {
20 20
@ -326,12 +326,11 @@ impl Handle<Tui> for SequencerTui {
/// Status bar for sequencer app /// Status bar for sequencer app
#[derive(Clone)] #[derive(Clone)]
pub struct SequencerStatusBar { pub struct SequencerStatusBar {
pub(crate) width: usize, pub(crate) width: usize,
pub(crate) cpu: Option<String>, pub(crate) cpu: Option<String>,
pub(crate) size: String, pub(crate) size: String,
pub(crate) res: String, pub(crate) res: String,
pub(crate) mode: &'static str, pub(crate) playing: bool,
pub(crate) help: &'static [(&'static str, &'static str, &'static str)]
} }
impl StatusBar for SequencerStatusBar { impl StatusBar for SequencerStatusBar {
@ -352,91 +351,47 @@ impl From<&SequencerTui> for SequencerStatusBar {
let width = state.size.w(); let width = state.size.w();
Self { Self {
width, width,
playing: state.clock.is_rolling(),
cpu: state.perf.percentage().map(|cpu|format!("{cpu:.01}%")), cpu: state.perf.percentage().map(|cpu|format!("{cpu:.01}%")),
size: format!("{}x{}│", width, state.size.h()), size: format!("{}x{}│", width, state.size.h()),
res: format!("│{}s│{:.1}kHz│{:.1}ms│", samples, rate / 1000., buffer * 1000.), res: format!("│{}s│{:.1}kHz│{:.1}ms│", samples, rate / 1000., buffer * 1000.),
mode: " SEQUENCER ",
help: &[
("", "SPACE", " play/pause"),
("", "", " cursor"),
("", "Ctrl-✣", " scroll"),
("", ".,", " length"),
("", "><", " triplet"),
("", "[]", " phrase"),
("", "{}", " order"),
("en", "q", "ueue"),
("", "e", "dit"),
("", "a", "dd note"),
("", "A", "dd phrase"),
("", "D", "uplicate phrase"),
]
} }
} }
} }
render!(|self: SequencerStatusBar|{ render!(|self: SequencerStatusBar|Tui::fixed_y(2, row!([
lay!(|add|if self.width > 40 { Tui::fixed_xy(11, 2, PlayPause(self.playing)),
add(&Tui::fill_x(Tui::fixed_y(1, lay!([ lay!([
Tui::fill_x(Tui::at_w(SequencerModeline::from(self))), {
Tui::fill_x(Tui::at_e(SequencerStats::from(self))), let bg = TuiTheme::g(50);
])))) let fg = TuiTheme::g(255);
} else { let single = |binding, command|row!([" ", col!([
add(&Tui::fill_x(Tui::fixed_y(2, col!(![ Tui::fg(TuiTheme::yellow(), binding),
Tui::fill_x(Tui::center_x(SequencerModeline::from(self))), command
Tui::fill_x(Tui::center_x(SequencerStats::from(self))), ])]);
])))) let double = |(b1, c1), (b2, c2)|col!([
}) row!([" ", Tui::fg(TuiTheme::yellow(), b1), " ", c1, " "]),
}); row!([" ", Tui::fg(TuiTheme::yellow(), b2), " ", c2, " "]),
]);
struct SequencerModeline { Tui::bg(bg, Tui::fg(fg, row!([
mode: &'static str, single("SPACE", "play/pause"),
help: &'static [(&'static str, &'static str, &'static str)] double(("", "cursor"), ("C-✣", "scroll"), ),
} double((",.", "note"), ("<>", "triplet"),),
impl From<&SequencerStatusBar> for SequencerModeline { double(("[]", "phrase"), ("{}", "order"), ),
fn from (state: &SequencerStatusBar) -> Self { double(("q", "enqueue"), ("e", "edit"), ),
Self { ])))
mode: state.mode, },
help: state.help, Tui::fill_xy(Tui::at_se({
} let orange = TuiTheme::orange();
} let dark = TuiTheme::g(25);
} //let cpu = &self.cpu;
render!(|self: SequencerModeline|{ //let res = &self.res;
let black = TuiTheme::g(0); let size = &self.size;
let light = TuiTheme::g(50); Tui::bg(dark, row!([
let white = TuiTheme::g(255); //Tui::fg(orange, cpu),
let orange = TuiTheme::orange(); //Tui::fg(orange, res),
let yellow = TuiTheme::yellow(); Tui::fg(orange, size),
row!([ ]))
//Tui::bg(orange, Tui::fg(black, Tui::bold(true, self.mode))), })),
Tui::bg(light, Tui::fg(white, row!((prefix, hotkey, suffix) in self.help.iter() => {
row!([" ", prefix, Tui::fg(yellow, *hotkey), suffix])
})))
]) ])
}); ])));
struct SequencerStats<'a> {
cpu: &'a Option<String>,
size: &'a String,
res: &'a String,
}
impl<'a> From<&'a SequencerStatusBar> for SequencerStats<'a> {
fn from (state: &'a SequencerStatusBar) -> Self {
Self {
cpu: &state.cpu,
size: &state.size,
res: &state.res,
}
}
}
render!(|self:SequencerStats<'a>|{
let orange = TuiTheme::orange();
let dark = TuiTheme::g(25);
let cpu = &self.cpu;
let res = &self.res;
let size = &self.size;
Tui::bg(dark, row!([
Tui::fg(orange, cpu),
Tui::fg(orange, res),
Tui::fg(orange, size),
]))
});

View file

@ -114,18 +114,8 @@ render!(|self: TransportView|{
Tui::bold(true, Tui::fg(Color::Rgb(220, 220, 220), self.1)), Tui::bold(true, Tui::fg(Color::Rgb(220, 220, 220), self.1)),
])); ]));
struct PlayPause(bool);
render!(|self: PlayPause|Tui::bg(
if self.0{Color::Rgb(0,128,0)}else{Color::Rgb(128,64,0)},
Tui::outset_x(1, Tui::fixed_x(9, col!(|add|if self.0 {
add(&Tui::fg(Color::Rgb(0, 255, 0), col!(["▶ PLAYING", "▒ ▒ ▒ ▒ ▒"])))
} else {
add(&Tui::fg(Color::Rgb(255, 128, 0), col!(["▒ ▒ ▒ ▒ ▒", "⏹ STOPPED"])))
})))
));
Tui::bg(self.bg, Tui::fill_x(row!([ Tui::bg(self.bg, Tui::fill_x(row!([
PlayPause(self.started), " ", //PlayPause(self.started), " ",
col!([ col!([
Field("Beat", self.beat.as_str()), Field("Beat", self.beat.as_str()),
Field("BPM ", self.bpm.as_str()), Field("BPM ", self.bpm.as_str()),
@ -139,6 +129,16 @@ render!(|self: TransportView|{
}); });
pub struct PlayPause(pub bool);
render!(|self: PlayPause|Tui::bg(
if self.0{Color::Rgb(0,128,0)}else{Color::Rgb(128,64,0)},
Tui::outset_x(1, Tui::fixed_x(9, col!(|add|if self.0 {
add(&Tui::fg(Color::Rgb(0, 255, 0), col!(["▶ PLAYING", "▒ ▒ ▒ ▒ ▒"])))
} else {
add(&Tui::fg(Color::Rgb(255, 128, 0), col!(["▒ ▒ ▒ ▒ ▒", "⏹ STOPPED"])))
})))
));
impl HasFocus for TransportTui { impl HasFocus for TransportTui {
type Item = TransportFocus; type Item = TransportFocus;
fn focused (&self) -> Self::Item { fn focused (&self) -> Self::Item {