From 501e47cd857d103a96ec9721d98f9947c78b4a42 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 4 Dec 2024 01:00:05 +0100 Subject: [PATCH] full block piano roll, pt.3 --- crates/tek_tui/src/tui_view_phrase_editor.rs | 23 ++++++++------------ 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/tek_tui/src/tui_view_phrase_editor.rs b/crates/tek_tui/src/tui_view_phrase_editor.rs index c2dee9cd..db596c84 100644 --- a/crates/tek_tui/src/tui_view_phrase_editor.rs +++ b/crates/tek_tui/src/tui_view_phrase_editor.rs @@ -307,29 +307,24 @@ impl PhraseViewMode { } /// Draw the piano roll using full blocks on note on and half blocks on legato: █▄ █▄ █▄ fn draw_piano_horizontal ( - buffer: &mut BigBuffer, phrase: &Phrase, time_zoom: usize, _: usize + target: &mut BigBuffer, phrase: &Phrase, time_zoom: usize, _: usize ) { let mut notes_on = [false;128]; - for col in 0..buffer.width { - let time_start = time_zoom * col; - let time_end = time_zoom * (col + 1); + for (x, time_start) in (0..phrase.length).step_by(time_zoom).enumerate() { + let time_end = time_start + time_zoom; for time in time_start..time_end { - for row in 0..buffer.height { - let cell = buffer.get_mut(row, col).unwrap(); - if notes_on[row] { - cell.set_char('▄'); - } else { - cell.set_char(' '); - } + for (y, note) in (127..0).enumerate() { + let cell = target.get_mut(x, y).unwrap(); cell.set_fg(Color::Rgb(255, 255, 255)); cell.set_bg(Color::Rgb(28, 35, 25)); + cell.set_char(if notes_on[note] { '▄' } else { '?' }); } for event in phrase.notes[time].iter() { match event { MidiMessage::NoteOn { key, .. } => { - let row = key.as_int() as usize; - buffer.get_mut(row, col).unwrap().set_char('█'); - notes_on[row] = true + let note = key.as_int() as usize; + target.get_mut(x, 127 - note).unwrap().set_char('█'); + notes_on[note] = true }, MidiMessage::NoteOff { key, .. } => { notes_on[key.as_int() as usize] = false