wip: highlight keys

This commit is contained in:
🪞👃🪞 2024-07-08 20:57:10 +03:00
parent dff42ca5a7
commit 1e3d96e64e
5 changed files with 124 additions and 35 deletions

View file

@ -20,7 +20,12 @@ pub struct SequencerView<'a> {
/// Position of cursor within time range
pub time_cursor: usize,
/// Current time
pub now: usize
pub now: usize,
/// Highlight input keys
pub notes_in: &'a [bool; 128],
/// Highlight output keys
pub notes_out: &'a [bool; 128],
}
impl<'a> Render for SequencerView<'a> {
@ -39,8 +44,7 @@ impl<'a> SequencerView<'a> {
} else {
Style::default().green().dim()
});
let notes = &[];
self::horizontal::keys(buf, area, self.note_start, notes)?;
self::horizontal::keys(buf, area, self.note_start, self.notes_in, self.notes_out)?;
let quant = ppq_to_name(self.time_zoom);
quant.blit(
buf,
@ -76,10 +80,17 @@ mod horizontal {
}
}
pub fn keys (buf: &mut Buffer, area: Rect, note0: usize, _notes: &[bool])
-> Usually<Rect>
{
let dim = Style::default().dim();
pub fn keys (
buf: &mut Buffer,
area: Rect,
note0: usize,
notes_in: &[bool;128],
notes_out: &[bool;128],
) -> Usually<Rect> {
let dim = Style::default().not_dim();
let red = Style::default().red();
let yellow = Style::default().yellow();
let green = Style::default().green();
let mut cell_bg = Cell::default();
cell_bg.set_char('░');
@ -102,12 +113,82 @@ mod horizontal {
let Rect { x, y, width, height } = area;
let height = height.min(128);
let h = height.saturating_sub(2);
let index_to_color = |index: usize, default: Color|
if notes_in[index] && notes_out[index] {
Color::Yellow
} else if notes_in[index] {
Color::Red
} else if notes_out[index] {
Color::Green
} else {
default
};
for index in 0..h {
let y = y + h - index;
let key1 = buf.get_mut(x + 1, y);
*key1 = cell_keys[(index % 6) as usize].clone();
let key2 = buf.get_mut(x + 2, y);
*key2 = cell_full.clone();
match index % 6 {
0 => {
let key1 = buf.get_mut(x + 1, y);
*key1 = cell_lo.clone();
key1.set_fg(index_to_color(index as usize * 2, Color::White));
key1.set_bg(index_to_color(index as usize * 2 + 1, Color::Black));
let key2 = buf.get_mut(x + 2, y);
*key2 = cell_lo.clone();
key2.set_fg(index_to_color(index as usize * 2, Color::White));
key2.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
},
1 => {
let key1 = buf.get_mut(x + 1, y);
*key1 = cell_lo.clone();
key1.set_fg(index_to_color(index as usize * 2, Color::White));
key1.set_bg(index_to_color(index as usize * 2 + 1, Color::Black));
let key2 = buf.get_mut(x + 2, y);
*key2 = cell_lo.clone();
key2.set_fg(index_to_color(index as usize * 2, Color::White));
key2.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
},
2 => {
let key1 = buf.get_mut(x + 1, y);
*key1 = cell_lo.clone();
key1.set_fg(index_to_color(index as usize * 2, Color::White));
key1.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
let key2 = buf.get_mut(x + 2, y);
*key2 = cell_lo.clone();
key2.set_fg(index_to_color(index as usize * 2, Color::White));
key2.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
},
3 => {
let key1 = buf.get_mut(x + 1, y);
*key1 = cell_lo.clone();
key1.set_fg(index_to_color(index as usize * 2, Color::Black));
key1.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
let key2 = buf.get_mut(x + 2, y);
*key2 = cell_lo.clone();
key2.set_fg(index_to_color(index as usize * 2, Color::White));
key2.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
},
4 => {
let key1 = buf.get_mut(x + 1, y);
*key1 = cell_lo.clone();
key1.set_fg(index_to_color(index as usize * 2, Color::Black));
key1.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
let key2 = buf.get_mut(x + 2, y);
*key2 = cell_lo.clone();
key2.set_fg(index_to_color(index as usize * 2, Color::White));
key2.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
},
5 => {
let key1 = buf.get_mut(x + 1, y);
*key1 = cell_lo.clone();
key1.set_fg(index_to_color(index as usize * 2, Color::Black));
key1.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
let key2 = buf.get_mut(x + 2, y);
*key2 = cell_lo.clone();
key2.set_fg(index_to_color(index as usize * 2, Color::White));
key2.set_bg(index_to_color(index as usize * 2 + 1, Color::White));
},
_ => { unreachable!(); }
}
for x in x+5..x+width-1 {
*buf.get_mut(x, y) = cell_bg.clone();
}