cleanup sequencer rendering

This commit is contained in:
🪞👃🪞 2024-10-17 22:43:45 +03:00
parent 0af5f97244
commit a7a9f26585

View file

@ -71,6 +71,7 @@ impl Content for PhrasePool<Tui> {
impl Content for PhraseEditor<Tui> { impl Content for PhraseEditor<Tui> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Widget<Engine = Tui> {
let Self { focused, entered, time_axis, note_axis, keys, phrase, buffer, .. } = self;
//let field_bg = Color::Rgb(28, 35, 25); //let field_bg = Color::Rgb(28, 35, 25);
//let toolbar = Stack::down(move|add|{ //let toolbar = Stack::down(move|add|{
////let name = format!("{:>9}", self.name.read().unwrap().as_str()); ////let name = format!("{:>9}", self.name.read().unwrap().as_str());
@ -95,17 +96,17 @@ impl Content for PhraseEditor<Tui> {
CustomWidget::new(|_|Ok(Some([32u16,4u16])), |to: &mut TuiOutput|{ CustomWidget::new(|_|Ok(Some([32u16,4u16])), |to: &mut TuiOutput|{
if to.area().h() < 2 { return Ok(()) } if to.area().h() < 2 { return Ok(()) }
Ok(to.buffer_update(to.area().set_w(5), &|cell, x, y|{ Ok(to.buffer_update(to.area().set_w(5), &|cell, x, y|{
let y = y + self.note_axis.start as u16; let y = y + note_axis.start as u16;
if x < self.keys.area.width && y < self.keys.area.height { if x < keys.area.width && y < keys.area.height {
*cell = self.keys.get(x, y).clone() *cell = keys.get(x, y).clone()
} }
})) }))
}).fill_y(), }).fill_y(),
// playhead // playhead
CustomWidget::new(|_|Ok(Some([32u16,2u16])), |to: &mut TuiOutput|{ CustomWidget::new(|_|Ok(Some([32u16,2u16])), |to: &mut TuiOutput|{
if let Some(phrase) = &self.phrase { if let Some(phrase) = phrase {
let time_0 = self.time_axis.start; let time_0 = time_axis.start;
let time_z = self.time_axis.scale; let time_z = time_axis.scale;
let now = 0; // TODO FIXME: self.now % phrase.read().unwrap().length; let now = 0; // TODO FIXME: self.now % phrase.read().unwrap().length;
let [x, y, width, _] = to.area(); let [x, y, width, _] = to.area();
let x2 = x as usize + Self::H_KEYS_OFFSET; let x2 = x as usize + Self::H_KEYS_OFFSET;
@ -127,19 +128,19 @@ impl Content for PhraseEditor<Tui> {
let area = to.area().push_x(offset).shrink_x(offset); let area = to.area().push_x(offset).shrink_x(offset);
Ok(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)); 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_x = ((x as usize + time_axis.start) * time_axis.scale) as usize;
let src_y = (y as usize + self.note_axis.start) as usize; let src_y = (y as usize + note_axis.start) as usize;
if src_x < self.buffer.width && src_y < self.buffer.height - 1 { if src_x < buffer.width && src_y < buffer.height - 1 {
let src = self.buffer.get(src_x, self.buffer.height - src_y); let src = buffer.get(src_x, buffer.height - src_y);
src.map(|src|{ cell.set_symbol(src.symbol()); cell.set_fg(src.fg); }); src.map(|src|{ cell.set_symbol(src.symbol()); cell.set_fg(src.fg); });
} }
})) }))
}).fill_x(), }).fill_x(),
// note cursor // note cursor
CustomWidget::new(|_|Ok(Some([1u16,1u16])), |to: &mut TuiOutput|{ CustomWidget::new(|_|Ok(Some([1u16,1u16])), |to: &mut TuiOutput|{
if self.entered { if *entered {
let area = to.area(); let area = to.area();
if let (Some(time), Some(note)) = (self.time_axis.point, self.note_axis.point) { if let (Some(time), Some(note)) = (time_axis.point, note_axis.point) {
let x = area.x() + Self::H_KEYS_OFFSET as u16 + time as u16; let x = area.x() + Self::H_KEYS_OFFSET as u16 + time as u16;
let y = area.y() + 1 + note as u16 / 2; let y = area.y() + 1 + note as u16 / 2;
let c = if note % 2 == 0 { "" } else { "" }; let c = if note % 2 == 0 { "" } else { "" };
@ -149,26 +150,27 @@ impl Content for PhraseEditor<Tui> {
Ok(()) Ok(())
}), }),
); );
let border_color = let border_color = if *focused{Color::Rgb(100, 110, 40)}else{Color::Rgb(70, 80, 50)};
if self.focused { Color::Rgb(100, 110, 40) } else { Color::Rgb(70, 80, 50) }; let title_color = if *focused{Color::Rgb(150, 160, 90)}else{Color::Rgb(120, 130, 100)};
let title_color = let border = Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color));
if self.focused { Color::Rgb(150, 160, 90) } else { Color::Rgb(120, 130, 100) }; let content = piano_roll.fill_x().bg(Color::Rgb(40, 50, 30)).border(border);
let border = let mut lower_left = String::new();
Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color)); let mut lower_right = format!("Zoom: {}", ppq_to_name(time_axis.scale));
let content = if *focused {
piano_roll.fill_x().bg(Color::Rgb(40, 50, 30)).border(border); if *entered {
let title = TuiStyle::fg("Sequencer", title_color) lower_left = "[Esc] Exit edit mode [A]ppend [I]nsert".to_string();
.push_x(1); lower_right = format!("[,.] Length: ?? {}", lower_right);
let zoom = TuiStyle::fg(format!("{}Zoom: {}", } else {
if self.focused && !self.entered { "[,.] " } else { "" }, lower_left = "[Enter] Edit notes".to_string();
ppq_to_name(self.time_axis.scale), lower_right = format!("[,.] {}", lower_right);
), title_color).pull_x(1).align_se().fill_xy();
let enter = TuiStyle::fg(if self.focused {
if self.entered { "[Esc] Exit edit mode [A]ppend [I]nsert" } else {
"[Enter] Edit notes"
} }
} else { "" }, title_color).push_x(1).align_sw().fill_xy(); }
lay!(content, title, enter, zoom) lay!(
content,
TuiStyle::fg("Sequencer", title_color).push_x(1).align_nw().fill_xy(),
TuiStyle::fg(lower_left.to_string(), title_color).push_x(1).align_sw().fill_xy(),
TuiStyle::fg(lower_right.to_string(), title_color).pull_x(1).align_se().fill_xy(),
)
} }
} }
impl PhraseEditor<Tui> { impl PhraseEditor<Tui> {