wip: fix note range

This commit is contained in:
🪞👃🪞 2024-12-16 20:31:23 +01:00
parent 41f17bb0e7
commit ccb4a01a29
2 changed files with 35 additions and 18 deletions

View file

@ -58,8 +58,9 @@ impl<E: Engine, X: Render<E>, Y: Render<E>> Render<E> for Bsp<E, X, Y> {
let s = to.area().wh().into(); let s = to.area().wh().into();
let s_a = a.min_size(s)?.unwrap_or(n); let s_a = a.min_size(s)?.unwrap_or(n);
let s_b = b.min_size(s)?.unwrap_or(n); let s_b = b.min_size(s)?.unwrap_or(n);
to.render_in(to.area().clip(s_a).into(), a)?; let s_y = s_a.h().into();
to.render_in(to.area().push_y(s_a.h().into()).into(), b)?; to.render_in(to.area().clip_h(s_y).into(), a)?;
to.render_in(to.area().push_y(s_y).into(), b)?;
}, },
Self::W(a, b) => { Self::W(a, b) => {
let n = [0.into(), 0.into()].into(); let n = [0.into(), 0.into()].into();

View file

@ -48,7 +48,9 @@ render!(|self: PianoHorizontal|{
let time_point = self.point.time_point(); let time_point = self.point.time_point();
let note_point = self.point.note_point(); let note_point = self.point.note_point();
let note_len = self.point.note_len(); let note_len = self.point.note_len();
let keys = move||PianoHorizontalKeys { color, note_lo, note_hi, note_point: Some(note_point), }; let range = &self.range;
let point = &self.point;
let keys = move||PianoHorizontalKeys { color, range, point }; //note_lo, note_hi, note_point: Some(note_point), };
let timeline = move||PianoHorizontalTimeline { color, time_start, time_zoom, }; let timeline = move||PianoHorizontalTimeline { color, time_start, time_zoom, };
let notes = move||PianoHorizontalNotes { source: &self.buffer, time_start, note_hi, }; let notes = move||PianoHorizontalNotes { source: &self.buffer, time_start, note_hi, };
let cursor = move||PianoHorizontalCursor { time_zoom, time_point, time_start, note_point, note_len, note_hi, note_lo, }; let cursor = move||PianoHorizontalCursor { time_zoom, time_point, time_start, note_point, note_len, note_hi, note_lo, };
@ -56,9 +58,9 @@ render!(|self: PianoHorizontal|{
Tui::fill_xy(Tui::bg(bg, Bsp::s( Tui::fill_xy(Tui::bg(bg, Bsp::s(
Tui::fill_x(Tui::push_x(keys_width, timeline())), Tui::fill_x(Tui::push_x(keys_width, timeline())),
Bsp::w( Bsp::w(
Tui::shrink_x(keys_width, Tui::shrink_x(keys_width, Tui::fill_xy(
Tui::fill_x(Tui::debug(lay!([&self.size, notes(), cursor()]))), lay!([&self.size, Tui::debug(Tui::fill_xy(lay!([notes(), cursor()])))])
), )),
Tui::fixed_x(keys_width, keys()) Tui::fixed_x(keys_width, keys())
), ),
))) )))
@ -75,18 +77,32 @@ render!(|self: PianoHorizontalTimeline|Tui::fg_bg(
format!("{}*{}", self.time_start, self.time_zoom).as_str() format!("{}*{}", self.time_start, self.time_zoom).as_str()
)); ));
pub struct PianoHorizontalKeys { pub struct PianoHorizontalKeys<'a> {
color: ItemPalette, color: ItemPalette,
note_lo: usize, range: &'a MidiRangeModel,
note_hi: usize, point: &'a MidiPointModel,
note_point: Option<usize>,
} }
render!(|self: PianoHorizontalKeys|render(|to|Ok({ render!(|self: PianoHorizontalKeys<'a>|render(|to|Ok({
let [x, y0, _, _] = to.area().xywh(); let color = self.color;
let key_style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0))); let note_lo = self.range.note_lo();
let off_style = Some(Style::default().fg(TuiTheme::g(160))); let note_hi = self.range.note_hi();
let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(self.color.light.rgb).bold()); let note_point = self.point.note_point();
for (y, note) in (self.note_lo..self.note_hi).rev().enumerate().map(|(y, n)|(y0 + y as u16, n)) { 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.light.rgb).bold());
let debug = true;
if debug {
to.blit(&format!("XYU"), x, y0, None);
to.blit(&format!("x={x}"), x, y0+1, None);
to.blit(&format!("y0={y0}"), x, y0+2, None);
to.blit(&format!("note_lo={note_lo}"), x, y0+3, None);
to.blit(&format!("note_hi={note_hi}"), x, y0+4, None);
}
return Ok(());
for (y, note) in (note_lo..note_hi).rev().enumerate().map(|(y, n)|(y0 + y as u16, n)) {
let key = match note % 12 { let key = match note % 12 {
11 => "████▌", 11 => "████▌",
10 => " ", 10 => " ",
@ -104,7 +120,7 @@ render!(|self: PianoHorizontalKeys|render(|to|Ok({
}; };
to.blit(&key, x, y, key_style); to.blit(&key, x, y, key_style);
if Some(note) == self.note_point { if note == note_point {
to.blit(&format!("{:<5}", to_note_name(note)), x, y, on_style) to.blit(&format!("{:<5}", to_note_name(note)), x, y, on_style)
} else { } else {
to.blit(&to_note_name(note), x, y, off_style) to.blit(&to_note_name(note), x, y, off_style)