mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
refactor app_sequencer
This commit is contained in:
parent
f5dcd3cba1
commit
9dd1d62de3
5 changed files with 54 additions and 74 deletions
|
|
@ -149,33 +149,24 @@ audio!(|self:SequencerTui, client, scope|{
|
|||
Control::Continue
|
||||
});
|
||||
|
||||
render!(|self: SequencerTui|lay!([self.size, Tui::split_n(false, 5,
|
||||
Tui::fill_xy(col!([
|
||||
PhraseEditStatus(&self.editor),
|
||||
SequencerStatusBar::from(self),
|
||||
])),
|
||||
Tui::split_w(false, if !self.show_pool{
|
||||
0
|
||||
} else if self.size.w() > 60 {
|
||||
20
|
||||
} else if self.size.w() > 40 {
|
||||
15
|
||||
} else {
|
||||
10
|
||||
}, Tui::fixed_x(20, col!([
|
||||
PhraseSelector::play_phrase(&self.player),
|
||||
PhraseSelector::next_phrase(&self.player),
|
||||
PhraseListView::from(self),
|
||||
])), 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)
|
||||
]),
|
||||
)
|
||||
)]));
|
||||
render!(|self: SequencerTui|{
|
||||
let w = self.size.w();
|
||||
let phrase_w = if w > 60 { 20 } else if w > 40 { 15 } else { 10 };
|
||||
let pool_w = if self.show_pool { phrase_w } else { 0 };
|
||||
let pool = Tui::fill_y(Tui::at_e(PhraseListView::from(self)));
|
||||
let with_pool = move|x|Tui::split_w(false, pool_w, pool, x);
|
||||
let with_status = |x|Tui::split_n(false, 2, SequencerStatusBar::from(self), x);
|
||||
let with_bar = |x|Tui::split_n(false, 3, PhraseEditStatus(&self.editor), x);
|
||||
let with_size = |x|lay!([self.size, x]);
|
||||
let editor = with_bar(with_pool(Tui::fill_xy(&self.editor)));
|
||||
let color = self.player.play_phrase().as_ref().map(|(_,p)|p.as_ref().map(|p|p.read().unwrap().color)).flatten().clone();
|
||||
let play = Tui::fixed_xy(11, 2, PlayPause(self.clock.is_rolling()));
|
||||
let playing = Tui::fixed_xy(14, 2, PhraseSelector::play_phrase(&self.player));
|
||||
let next = Tui::fixed_xy(14, 2, PhraseSelector::next_phrase(&self.player));
|
||||
let transport = Tui::fixed_y(2, TransportView::from((self, color, true)));
|
||||
let toolbar = row!([play, playing, next, transport]);
|
||||
with_size(with_status(col!([ toolbar, editor, ])))
|
||||
});
|
||||
|
||||
pub struct PhraseSelector {
|
||||
pub(crate) title: &'static str,
|
||||
|
|
@ -305,32 +296,29 @@ impl From<&SequencerTui> for SequencerStatusBar {
|
|||
}
|
||||
}
|
||||
|
||||
render!(|self: SequencerStatusBar|Tui::fixed_y(2, row!([
|
||||
Tui::fixed_xy(11, 2, PlayPause(self.playing)),
|
||||
lay!([
|
||||
{
|
||||
let single = |binding, command|row!([" ", col!([
|
||||
Tui::fg(TuiTheme::yellow(), binding),
|
||||
command
|
||||
])]);
|
||||
let double = |(b1, c1), (b2, c2)|col!([
|
||||
row!([" ", Tui::fg(TuiTheme::yellow(), b1), " ", c1,]),
|
||||
row!([" ", Tui::fg(TuiTheme::yellow(), b2), " ", c2,]),
|
||||
]);
|
||||
Tui::bg(TuiTheme::g(50), Tui::fg(TuiTheme::g(255), row!([
|
||||
single("SPACE", "play/pause"),
|
||||
double((" ✣", "cursor"), ("C-✣", "scroll"), ),
|
||||
double((",.", "note"), ("<>", "triplet"),),
|
||||
double(("[]", "phrase"), ("{}", "order"), ),
|
||||
double(("q", "enqueue"), ("e", "edit"), ),
|
||||
])))
|
||||
},
|
||||
Tui::fill_xy(Tui::at_se({
|
||||
Tui::bg(TuiTheme::g(25), row!([
|
||||
Tui::fg(TuiTheme::orange(), &self.cpu),
|
||||
Tui::fg(TuiTheme::orange(), &self.res),
|
||||
Tui::fg(TuiTheme::orange(), &self.size),
|
||||
]))
|
||||
})),
|
||||
])
|
||||
render!(|self: SequencerStatusBar|Tui::fixed_y(2, lay!([
|
||||
{
|
||||
let single = |binding, command|row!([" ", col!([
|
||||
Tui::fg(TuiTheme::yellow(), binding),
|
||||
command
|
||||
])]);
|
||||
let double = |(b1, c1), (b2, c2)|col!([
|
||||
row!([" ", Tui::fg(TuiTheme::yellow(), b1), " ", c1,]),
|
||||
row!([" ", Tui::fg(TuiTheme::yellow(), b2), " ", c2,]),
|
||||
]);
|
||||
Tui::bg(TuiTheme::g(50), Tui::fg(TuiTheme::g(255), row!([
|
||||
single("SPACE", "play/pause"),
|
||||
double((" ✣", "cursor"), ("C-✣", "scroll"), ),
|
||||
double((",.", "note"), ("<>", "triplet"),),
|
||||
double(("[]", "phrase"), ("{}", "order"), ),
|
||||
double(("q", "enqueue"), ("e", "edit"), ),
|
||||
])))
|
||||
},
|
||||
Tui::fill_xy(Tui::at_se({
|
||||
Tui::bg(TuiTheme::g(25), row!([
|
||||
Tui::fg(TuiTheme::orange(), &self.cpu),
|
||||
Tui::fg(TuiTheme::orange(), &self.res),
|
||||
Tui::fg(TuiTheme::orange(), &self.size),
|
||||
]))
|
||||
})),
|
||||
])));
|
||||
|
|
|
|||
|
|
@ -62,21 +62,17 @@ pub struct TransportView {
|
|||
impl<T: HasClock> From<(&T, Option<ItemPalette>, bool)> for TransportView {
|
||||
fn from ((state, color, focused): (&T, Option<ItemPalette>, bool)) -> Self {
|
||||
let clock = state.clock();
|
||||
let sr = format!("{:.1}k", clock.timebase.sr.get() / 1000.0);
|
||||
let bpm = format!("{:.3}", clock.timebase.bpm.get());
|
||||
let ppq = format!("{:.0}", clock.timebase.ppq.get());
|
||||
let color = color.unwrap_or(ItemPalette::from(ItemColor::from(TuiTheme::g(32))));
|
||||
let bg = if focused { color.light.rgb } else { color.dark.rgb };
|
||||
let sr = format!("{:.1}k", clock.timebase.sr.get() / 1000.0);
|
||||
let bpm = format!("{:.3}", clock.timebase.bpm.get());
|
||||
let ppq = format!("{:.0}", clock.timebase.ppq.get());
|
||||
let color = color.unwrap_or(ItemPalette::from(TuiTheme::g(32)));
|
||||
let bg = color.dark.rgb;
|
||||
if let Some(started) = clock.started.read().unwrap().as_ref() {
|
||||
let current_sample = (clock.global.sample.get() - started.sample.get())/1000.;
|
||||
let current_usec = clock.global.usec.get() - started.usec.get();
|
||||
let current_second = current_usec/1000000.;
|
||||
Self {
|
||||
bg,
|
||||
focused,
|
||||
sr,
|
||||
bpm,
|
||||
ppq,
|
||||
bg, focused, sr, bpm, ppq,
|
||||
started: true,
|
||||
global_sample: format!("{:.0}k", started.sample.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 {
|
||||
Self {
|
||||
bg,
|
||||
focused,
|
||||
sr,
|
||||
bpm,
|
||||
ppq,
|
||||
bg, focused, sr, bpm, ppq,
|
||||
started: false,
|
||||
global_sample: format!("{:.0}k", clock.global.sample.get()/1000.),
|
||||
global_second: format!("{:.1}s", clock.global.usec.get()/1000000.),
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ render!(|self:PhraseEditStatus<'a>|row!(|add|{
|
|||
} else {
|
||||
(ItemPalette::from(TuiTheme::g(64)), String::new(), 0)
|
||||
};
|
||||
let bg = color.darker.rgb;
|
||||
let bg = color.base.rgb;
|
||||
let fg = color.lightest.rgb;
|
||||
add(&Tui::fill_x(Tui::bg(bg, row!(|add|{
|
||||
add(&Tui::fixed_xy(26, 3, col!(![
|
||||
|
|
|
|||
|
|
@ -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_xy(Tui::at_ne(Tui::pull_x(1, Tui::fg(title_color, upper_right.to_string())))))
|
||||
add(&Tui::fill_x(Tui::at_nw(Tui::push_x(1, Tui::fg(title_color, upper_left.to_string())))))?;
|
||||
add(&Tui::fill_x(Tui::at_ne(Tui::pull_x(1, Tui::fg(title_color, upper_right.to_string())))))
|
||||
}))
|
||||
});
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ render!(|self: PianoHorizontalKeys|render(|to|Ok({
|
|||
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 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)) {
|
||||
let key = match note % 12 {
|
||||
11 => "████▌",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue