refactor app_sequencer

This commit is contained in:
🪞👃🪞 2024-12-15 19:08:17 +01:00
parent f5dcd3cba1
commit 9dd1d62de3
5 changed files with 54 additions and 74 deletions

View file

@ -149,33 +149,24 @@ audio!(|self:SequencerTui, client, scope|{
Control::Continue Control::Continue
}); });
render!(|self: SequencerTui|lay!([self.size, Tui::split_n(false, 5, render!(|self: SequencerTui|{
Tui::fill_xy(col!([ let w = self.size.w();
PhraseEditStatus(&self.editor), let phrase_w = if w > 60 { 20 } else if w > 40 { 15 } else { 10 };
SequencerStatusBar::from(self), let pool_w = if self.show_pool { phrase_w } else { 0 };
])), let pool = Tui::fill_y(Tui::at_e(PhraseListView::from(self)));
Tui::split_w(false, if !self.show_pool{ let with_pool = move|x|Tui::split_w(false, pool_w, pool, x);
0 let with_status = |x|Tui::split_n(false, 2, SequencerStatusBar::from(self), x);
} else if self.size.w() > 60 { let with_bar = |x|Tui::split_n(false, 3, PhraseEditStatus(&self.editor), x);
20 let with_size = |x|lay!([self.size, x]);
} else if self.size.w() > 40 { let editor = with_bar(with_pool(Tui::fill_xy(&self.editor)));
15 let color = self.player.play_phrase().as_ref().map(|(_,p)|p.as_ref().map(|p|p.read().unwrap().color)).flatten().clone();
} else { let play = Tui::fixed_xy(11, 2, PlayPause(self.clock.is_rolling()));
10 let playing = Tui::fixed_xy(14, 2, PhraseSelector::play_phrase(&self.player));
}, Tui::fixed_x(20, col!([ let next = Tui::fixed_xy(14, 2, PhraseSelector::next_phrase(&self.player));
PhraseSelector::play_phrase(&self.player), let transport = Tui::fixed_y(2, TransportView::from((self, color, true)));
PhraseSelector::next_phrase(&self.player), let toolbar = row!([play, playing, next, transport]);
PhraseListView::from(self), with_size(with_status(col!([ toolbar, editor, ])))
])), col!([ });
Tui::fixed_y(2, TransportView::from((
self,
self.player.play_phrase().as_ref().map(|(_,p)|p.as_ref().map(|p|p.read().unwrap().color)).flatten().clone(),
true
))),
Tui::fill_xy(&self.editor)
]),
)
)]));
pub struct PhraseSelector { pub struct PhraseSelector {
pub(crate) title: &'static str, pub(crate) title: &'static str,
@ -305,9 +296,7 @@ impl From<&SequencerTui> for SequencerStatusBar {
} }
} }
render!(|self: SequencerStatusBar|Tui::fixed_y(2, row!([ render!(|self: SequencerStatusBar|Tui::fixed_y(2, lay!([
Tui::fixed_xy(11, 2, PlayPause(self.playing)),
lay!([
{ {
let single = |binding, command|row!([" ", col!([ let single = |binding, command|row!([" ", col!([
Tui::fg(TuiTheme::yellow(), binding), Tui::fg(TuiTheme::yellow(), binding),
@ -332,5 +321,4 @@ render!(|self: SequencerStatusBar|Tui::fixed_y(2, row!([
Tui::fg(TuiTheme::orange(), &self.size), Tui::fg(TuiTheme::orange(), &self.size),
])) ]))
})), })),
])
]))); ])));

View file

@ -65,18 +65,14 @@ impl<T: HasClock> From<(&T, Option<ItemPalette>, bool)> for TransportView {
let sr = format!("{:.1}k", clock.timebase.sr.get() / 1000.0); let sr = format!("{:.1}k", clock.timebase.sr.get() / 1000.0);
let bpm = format!("{:.3}", clock.timebase.bpm.get()); let bpm = format!("{:.3}", clock.timebase.bpm.get());
let ppq = format!("{:.0}", clock.timebase.ppq.get()); let ppq = format!("{:.0}", clock.timebase.ppq.get());
let color = color.unwrap_or(ItemPalette::from(ItemColor::from(TuiTheme::g(32)))); let color = color.unwrap_or(ItemPalette::from(TuiTheme::g(32)));
let bg = if focused { color.light.rgb } else { color.dark.rgb }; let bg = color.dark.rgb;
if let Some(started) = clock.started.read().unwrap().as_ref() { if let Some(started) = clock.started.read().unwrap().as_ref() {
let current_sample = (clock.global.sample.get() - started.sample.get())/1000.; let current_sample = (clock.global.sample.get() - started.sample.get())/1000.;
let current_usec = clock.global.usec.get() - started.usec.get(); let current_usec = clock.global.usec.get() - started.usec.get();
let current_second = current_usec/1000000.; let current_second = current_usec/1000000.;
Self { Self {
bg, bg, focused, sr, bpm, ppq,
focused,
sr,
bpm,
ppq,
started: true, started: true,
global_sample: format!("{:.0}k", started.sample.get()/1000.), global_sample: format!("{:.0}k", started.sample.get()/1000.),
global_second: format!("{:.1}s", started.usec.get()/1000.), global_second: format!("{:.1}s", started.usec.get()/1000.),
@ -88,11 +84,7 @@ impl<T: HasClock> From<(&T, Option<ItemPalette>, bool)> for TransportView {
} }
} else { } else {
Self { Self {
bg, bg, focused, sr, bpm, ppq,
focused,
sr,
bpm,
ppq,
started: false, started: false,
global_sample: format!("{:.0}k", clock.global.sample.get()/1000.), global_sample: format!("{:.0}k", clock.global.sample.get()/1000.),
global_second: format!("{:.1}s", clock.global.usec.get()/1000000.), global_second: format!("{:.1}s", clock.global.usec.get()/1000000.),

View file

@ -234,7 +234,7 @@ render!(|self:PhraseEditStatus<'a>|row!(|add|{
} else { } else {
(ItemPalette::from(TuiTheme::g(64)), String::new(), 0) (ItemPalette::from(TuiTheme::g(64)), String::new(), 0)
}; };
let bg = color.darker.rgb; let bg = color.base.rgb;
let fg = color.lightest.rgb; let fg = color.lightest.rgb;
add(&Tui::fill_x(Tui::bg(bg, row!(|add|{ add(&Tui::fill_x(Tui::bg(bg, row!(|add|{
add(&Tui::fixed_xy(26, 3, col!(![ add(&Tui::fixed_xy(26, 3, col!(![

View file

@ -271,7 +271,7 @@ render!(|self: PhraseListView<'a>|{
}))?; }))?;
}) })
}))))?; }))))?;
add(&Tui::fill_xy(Tui::at_nw(Tui::push_x(1, Tui::fg(title_color, upper_left.to_string())))))?; add(&Tui::fill_x(Tui::at_nw(Tui::push_x(1, Tui::fg(title_color, upper_left.to_string())))))?;
add(&Tui::fill_xy(Tui::at_ne(Tui::pull_x(1, Tui::fg(title_color, upper_right.to_string()))))) add(&Tui::fill_x(Tui::at_ne(Tui::pull_x(1, Tui::fg(title_color, upper_right.to_string())))))
})) }))
}); });

View file

@ -98,7 +98,7 @@ render!(|self: PianoHorizontalKeys|render(|to|Ok({
let [x, y0, _, _] = to.area().xywh(); let [x, y0, _, _] = to.area().xywh();
let key_style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0))); let key_style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0)));
let off_style = Some(Style::default().fg(TuiTheme::g(160))); let off_style = Some(Style::default().fg(TuiTheme::g(160)));
let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(self.color.base.rgb).bold()); let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(self.color.light.rgb).bold());
for (y, note) in (self.note_lo..self.note_hi).rev().enumerate().map(|(y, n)|(y0 + y as u16, n)) { for (y, note) in (self.note_lo..self.note_hi).rev().enumerate().map(|(y, n)|(y0 + y as u16, n)) {
let key = match note % 12 { let key = match note % 12 {
11 => "████▌", 11 => "████▌",