colorize notes in editor

This commit is contained in:
🪞👃🪞 2024-12-10 15:18:16 +01:00
parent 1aa4386e42
commit a91b539cd0

View file

@ -289,7 +289,7 @@ impl PhraseViewMode {
match self { match self {
Self::PianoHorizontal { time_zoom, note_zoom } => match note_zoom { Self::PianoHorizontal { time_zoom, note_zoom } => match note_zoom {
PhraseViewNoteZoom::N(_) => Self::draw_piano_horizontal( PhraseViewNoteZoom::N(_) => Self::draw_piano_horizontal(
&mut buffer, phrase, *time_zoom, 1 &mut buffer, phrase, *time_zoom
), ),
_ => unimplemented!(), _ => unimplemented!(),
}, },
@ -424,9 +424,12 @@ impl PhraseViewMode {
} }
/// Draw the piano roll using full blocks on note on and half blocks on legato: █▄ █▄ █▄ /// Draw the piano roll using full blocks on note on and half blocks on legato: █▄ █▄ █▄
fn draw_piano_horizontal ( fn draw_piano_horizontal (
target: &mut BigBuffer, phrase: &Phrase, time_zoom: usize, _: usize target: &mut BigBuffer,
phrase: &Phrase,
time_zoom: usize,
) { ) {
let style = Style::default().fg(Color::Rgb(255, 255, 255)); let color = phrase.color.light.rgb;
let style = Style::default().fg(color);//.bg(Color::Rgb(0, 0, 0));
for (y, note) in (0..127).rev().enumerate() { for (y, note) in (0..127).rev().enumerate() {
for (x, time) in (0..target.width).map(|x|(x, x*time_zoom)) { for (x, time) in (0..target.width).map(|x|(x, x*time_zoom)) {
let cell = target.get_mut(x, y).unwrap(); let cell = target.get_mut(x, y).unwrap();
@ -448,8 +451,6 @@ impl PhraseViewMode {
for (y, note) in (0..127).rev().enumerate() { for (y, note) in (0..127).rev().enumerate() {
let cell = target.get_mut(x, note).unwrap(); let cell = target.get_mut(x, note).unwrap();
if notes_on[note] { if notes_on[note] {
cell.set_fg(Color::Rgb(255, 255, 255));
cell.set_bg(Color::Rgb(0, 0, 0));
cell.set_char('▄'); cell.set_char('▄');
cell.set_style(style); cell.set_style(style);
} }
@ -487,107 +488,6 @@ impl PhraseViewMode {
} }
} }
//impl PhraseEditorModel {
//pub(crate) fn redraw (phrase: &Phrase, mode: PhraseViewMode) -> BigBuffer {
//let mut buf = BigBuffer::new(usize::MAX.min(phrase.length), 65);
//Self::fill_seq_bg(mode, &mut buf, phrase.length, phrase.ppq);
//Self::fill_seq_fg(mode, &mut buf, &phrase);
//buf
//}
//fn fill_seq_bg (_mode: PhraseViewMode, buf: &mut BigBuffer, length: usize, ppq: usize) {
//for x in 0..buf.width {
//// Only fill as far as phrase length
//if x as usize >= length { break }
//// Fill each row with background characters
//for y in 0..buf.height {
//if y >= 64 {
//break
//}
//buf.get_mut(x, y).map(|cell|{
//cell.set_char(if ppq == 0 {
//'·'
//} else if x % (4 * ppq) == 0 {
//'│'
//} else if x % ppq == 0 {
//'╎'
//} else {
//'·'
//});
//cell.set_fg(Color::Rgb(48, 64, 56));
//cell.modifier = Modifier::DIM;
//});
//}
//}
//}
//fn fill_seq_fg (mode: PhraseViewMode, buf: &mut BigBuffer, phrase: &Phrase) {
//match mode {
//PhraseViewMode::Horizontal =>
//Self::fill_seq_fg_horizontal(buf, phrase),
//PhraseViewMode::HorizontalHalf =>
//Self::fill_seq_fg_horizontal_half(buf, phrase),
//PhraseViewMode::Vertical =>
//Self::fill_seq_fg_vertical(buf, phrase),
//}
//}
//fn fill_seq_fg_horizontal (buf: &mut BigBuffer, phrase: &Phrase) {
//let mut notes_on = [false;128];
//for x in 0..buf.width {
//}
//}
//fn fill_seq_fg_horizontal_half (buf: &mut BigBuffer, phrase: &Phrase) {
//let mut notes_on = [false;128];
//for x in 0..buf.width {
//if x as usize >= phrase.length {
//break
//}
//if let Some(notes) = phrase.notes.get(x as usize) {
//if phrase.percussive {
//for note in notes {
//match note {
//MidiMessage::NoteOn { key, .. } =>
//notes_on[key.as_int() as usize] = true,
//_ => {}
//}
//}
//} else {
//for note in notes {
//match note {
//MidiMessage::NoteOn { key, .. } =>
//notes_on[key.as_int() as usize] = true,
//MidiMessage::NoteOff { key, .. } =>
//notes_on[key.as_int() as usize] = false,
//_ => {}
//}
//}
//}
//for y in 0..buf.height {
//if y > 63 {
//break
//}
//let y = 63 - y;
//if let Some(block) = half_block(
//notes_on[y as usize * 2 + 1],
//notes_on[y as usize * 2],
//) {
//buf.get_mut(x, y).map(|cell|{
//cell.set_char(block);
//cell.set_fg(Color::White);
//});
//}
//}
//if phrase.percussive {
//notes_on.fill(false);
//}
//}
//}
//}
//}
////const NTH_OCTAVE: [&'static str; 11] = [
////"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "X",
//////"-2", "-1", "0", "1", "2", "3", "4", "5", "6", "7", "8",
////];
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum PhraseCommand { pub enum PhraseCommand {
// TODO: 1-9 seek markers that by default start every 8th of the phrase // TODO: 1-9 seek markers that by default start every 8th of the phrase