separate viewing/playing phrase + format

This commit is contained in:
🪞👃🪞 2024-10-03 21:41:14 +03:00
parent 6f91eb085d
commit ae60b792d6
4 changed files with 127 additions and 138 deletions

View file

@ -180,7 +180,7 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
let name = name.read().unwrap();
let name = format!("{clip:02} {}", name);
add(&name.as_str().push_x(1))?;
if (track as &Sequencer<_>).sequence == Some(*clip) {
if (track as &Sequencer<_>).playing_phrase == Some(*clip) {
color = COLOR_PLAYING
} else {
color = COLOR_BG1
@ -473,10 +473,6 @@ impl<'a> Content for HorizontalArranger<'a, Tui> {
todo!()
}, |_: &mut TuiOutput|{
todo!()
}),
// gain
CustomWidget::new(|_|{
todo!()
//let Self(tracks) = self;
//let mut area = to.area();
//let off = Some(Style::default().dim());
@ -496,6 +492,10 @@ impl<'a> Content for HorizontalArranger<'a, Tui> {
//}
//area.width = 4;
//Ok(Some(area))
}),
// gain
CustomWidget::new(|_|{
todo!()
}, |_: &mut TuiOutput|{
todo!()
//let Self(tracks) = self;
@ -772,12 +772,12 @@ impl Content for Sequencer<Tui> {
let length = phrase.length;
let looped = phrase.looped;
add(&"")?;
add(&col! {"Length: ", format!("{length}").as_str(),})?;
add(&col!("Length: ", format!("{length}").as_str()))?;
add(&"")?;
add(&col! { "Loop [ ]", "From: ", " 1.1.1", "Length: ", " 1.0.0", })?;
add(&col!("Loop [ ]", "From: ", " 1.1.1", "Length: ", " 1.0.0"))?;
add(&"")?;
add(&col! { "Notes: ", "C#0-C#9 ", "[ /2 ]", "[ x2 ]"
, "[ Rev ]", "[ Inv ]", "[ Dup ]" })?;
add(&col!("Notes: ", "C#0-C#9 ", "[ /2 ]", "[ x2 ]",
"[ Rev ]", "[ Inv ]", "[ Dup ]"))?;
}
Ok(())
}).min_x(10);
@ -785,13 +785,12 @@ impl Content for Sequencer<Tui> {
// keys
CustomWidget::new(|_|Ok(Some([32,4])), |to: &mut TuiOutput|{
if to.area().h() < 2 { return Ok(()) }
to.buffer_update(to.area().set_w(5).shrink_y(2), &|cell, x, y|{
Ok(to.buffer_update(to.area().set_w(5).shrink_y(2), &|cell, x, y|{
let y = y + self.note_axis.start as u16;
if x < self.keys.area.width && y < self.keys.area.height {
*cell = self.keys.get(x, y).clone()
}
});
Ok(())
}))
}).fill_y(),
// playhead
CustomWidget::new(|_|Ok(Some([32,2])), |to: &mut TuiOutput|{
@ -817,7 +816,7 @@ impl Content for Sequencer<Tui> {
let offset = Sequencer::H_KEYS_OFFSET as u16;
if to.area().h() < 2 || to.area().w() < offset { return Ok(()) }
let area = to.area().push_x(offset).shrink_x(offset).shrink_y(2);
to.buffer_update(area, &move |cell, x, y|{
Ok(to.buffer_update(area, &move |cell, x, y|{
cell.set_bg(Color::Rgb(20, 20, 20));
let src_x = ((x as usize + self.time_axis.start) * self.time_axis.scale) as usize;
let src_y = (y as usize + self.note_axis.start) as usize;
@ -825,8 +824,7 @@ impl Content for Sequencer<Tui> {
let src = self.buffer.get(src_x, self.buffer.height - src_y);
src.map(|src|{ cell.set_symbol(src.symbol()); cell.set_fg(src.fg); });
}
});
Ok(())
}))
}).fill_x(),
// note cursor
CustomWidget::new(|_|Ok(Some([1,1])), |to: &mut TuiOutput|{
@ -839,14 +837,16 @@ impl Content for Sequencer<Tui> {
}
Ok(())
}),
//zoom
// zoom
CustomWidget::new(|_|Ok(Some([10,1])), |to: &mut TuiOutput|{
let [x, y, w, h] = to.area.xywh();
let quant = ppq_to_name(self.time_axis.scale);
let x = x + w - 1 - quant.len() as u16;
let y = y + h - 2;
to.blit(&quant, x, y, self.style_focus());
Ok(())
Ok(to.blit(
&quant,
x + w - 1 - quant.len() as u16,
y + h - 2,
self.style_focus()
))
}),
);
row!(toolbar, content).fill_x()
@ -910,45 +910,30 @@ const NTH_OCTAVE: [&'static str;11] = [
impl Handle<Tui> for Sequencer<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
match from.event() {
// NONE, "seq_cursor_up", "move cursor up", |sequencer: &mut Sequencer| {
key!(KeyCode::Up) => {
match self.entered {
true => { self.note_axis.point_dec(); },
false => { self.note_axis.start_dec(); },
}
Ok(Some(true))
},
// NONE, "seq_cursor_down", "move cursor down", |self: &mut Sequencer| {
key!(KeyCode::Down) => {
match self.entered {
true => { self.note_axis.point_inc(); },
false => { self.note_axis.start_inc(); },
}
Ok(Some(true))
},
// NONE, "seq_cursor_left", "move cursor up", |self: &mut Sequencer| {
key!(KeyCode::Left) => {
match self.entered {
true => { self.time_axis.point_dec(); },
false => { self.time_axis.start_dec(); },
}
Ok(Some(true))
},
// NONE, "seq_cursor_right", "move cursor up", |self: &mut Sequencer| {
key!(KeyCode::Right) => {
match self.entered {
true => { self.time_axis.point_inc(); },
false => { self.time_axis.start_inc(); },
}
Ok(Some(true))
},
// NONE, "seq_mode_switch", "switch the display mode", |self: &mut Sequencer| {
key!(KeyCode::Char('`')) => {
self.mode = !self.mode;
Ok(Some(true))
},
_ => Ok(None)
key!(KeyCode::Up) => match self.entered {
true => { self.note_axis.point_dec(); },
false => { self.note_axis.start_dec(); },
},
key!(KeyCode::Down) => match self.entered {
true => { self.note_axis.point_inc(); },
false => { self.note_axis.start_inc(); },
},
key!(KeyCode::Left) => match self.entered {
true => { self.time_axis.point_dec(); },
false => { self.time_axis.start_dec(); },
},
key!(KeyCode::Right) => match self.entered {
true => { self.time_axis.point_inc(); },
false => { self.time_axis.start_inc(); },
},
_ => {
return Ok(None)
}
}
return Ok(Some(true))
}
}
@ -1013,9 +998,7 @@ impl Handle<Tui> for TransportToolbar<Tui> {
impl Content for TransportToolbar<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
row! {
// play/pause
row!(
self.focus.wrap(self.focused, TransportToolbarFocus::PlayPause, &Styled(
match self.playing {
Some(TransportState::Stopped) => Some(GRAY_DIM.bold()),
@ -1030,37 +1013,26 @@ impl Content for TransportToolbar<Tui> {
_ => unreachable!(),
}
).min_xy(11, 2).push_x(1)),
// bpm
self.focus.wrap(self.focused, TransportToolbarFocus::Bpm, &Outset::X(1u16, col! {
"BPM",
format!("{}.{:03}", self.bpm as usize, (self.bpm * 1000.0) % 1000.0).as_str()
"BPM", format!("{}.{:03}", self.bpm as usize, (self.bpm * 1000.0) % 1000.0)
})),
// quant
self.focus.wrap(self.focused, TransportToolbarFocus::Quant, &Outset::X(1u16, col! {
"QUANT", ppq_to_name(self.quant as usize)
})),
// sync
self.focus.wrap(self.focused, TransportToolbarFocus::Sync, &Outset::X(1u16, col! {
"SYNC", ppq_to_name(self.sync as usize)
"SYNC", ppq_to_name(self.sync as usize)
})),
// clock
self.focus.wrap(self.focused, TransportToolbarFocus::Clock, &{
let Self { frame: _frame, pulse, ppq, usecs, .. } = self;
let (beats, pulses) = if *ppq > 0 { (pulse / ppq, pulse % ppq) } else { (0, 0) };
let (bars, beats) = ((beats / 4) + 1, (beats % 4) + 1);
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
let (minutes, seconds) = (seconds / 60, seconds % 60);
Outset::X(1u16, col! {
format!("{bars}.{beats}.{pulses:02}").as_str(),
format!("{minutes}:{seconds:02}:{msecs:03}").as_str(),
})
let time1 = format!("{bars}.{beats}.{pulses:02}");
let time2 = format!("{minutes}:{seconds:02}:{msecs:03}");
col!(time1.as_str(), time2.as_str()).outset_x(1)
}),
}.fill_x().bg(Color::Rgb(40, 50, 30))
).fill_x().bg(Color::Rgb(40, 50, 30))
}
}