refactor control and sequencer rendering

This commit is contained in:
🪞👃🪞 2024-07-07 23:28:07 +03:00
parent 20b7267225
commit 14d9116c7c
10 changed files with 370 additions and 405 deletions

View file

@ -17,7 +17,7 @@ impl<'a> SceneGridViewVertical<'a> {
pub fn draw (&mut self) -> Usually<Rect> {
self.area.height = self.scenes.len() as u16 + 3;
let Rect { x, y, width, height } = self.area;
let style = Some(Style::default().green().dim());
//let style = Some(Style::default().green().dim());
fill_bg(&mut self.buf, self.area, if self.focused && self.entered {
Color::Rgb(25, 60, 15)
} else if self.focused {
@ -160,7 +160,11 @@ impl<'a> SceneGridViewVertical<'a> {
let index = index as u16;
let label = if let Some(Some(clip)) = clip {
if let Some(phrase) = self.tracks[track].phrases.get(*clip) {
format!("{}", phrase.name)
format!("{} {}", if self.tracks[track].sequence == Some(*clip) {
""
} else {
" "
}, phrase.name)
} else {
format!("????")
}
@ -200,7 +204,7 @@ impl<'a> SceneGridViewHorizontal<'a> {
}
pub fn draw (&mut self) -> Usually<Rect> {
self.area.height = self.tracks.len() as u16 * 2 + 2;
let style = Some(Style::default().green().dim());
//let style = Some(Style::default().green().dim());
let Rect { x, y, width, height } = self.area;
fill_bg(&mut self.buf, self.area, if self.focused && self.entered {
Color::Rgb(25, 60, 15)

View file

@ -1,4 +1,4 @@
use crate::{core::*,model::*,view::*};
use crate::{core::*,model::*};
#[derive(Debug, Clone)]
pub enum SequencerMode { Tiny, Compact, Horizontal, Vertical, }
@ -136,41 +136,81 @@ mod horizontal {
time0: usize,
note0: usize,
) {
let Rect { x, y, width, height } = area;
//let time0 = time0 / time_z;
//let time1 = time0 + width as usize;
//let note1 = note0 + height as usize;
let bg = Style::default();
let bg = Style::default();
let (bw, wh) = (bg.dim(), bg.white().not_dim());
let Rect { x, y, width, height } = area;
let offset = 5;
for x in x+offset..x+width-offset {
let phrase_area = Rect {
x: x + offset, y, width: width - offset, height: height - 2
};
let mut cell_bg = Cell::default();
cell_bg.set_char('·');
cell_bg.set_style(bw);
let mut cell_bg_tick = Cell::default();
cell_bg_tick.set_char('|');
cell_bg_tick.set_style(bw);
let mut cell_a = Cell::default();
cell_a.set_char('▀');
cell_a.set_style(wh);
let mut cell_b = Cell::default();
cell_b.set_char('▄');
cell_b.set_style(wh);
let mut cell_ab = Cell::default();
cell_ab.set_char('█');
cell_ab.set_style(wh);
let mut steps = vec![];
for x in phrase_area.x .. phrase_area.x + phrase_area.width {
let step = (time0 + (x-offset) as usize) * time_z;
let next_step = (1 + time0 + (x-offset) as usize) * time_z;
if step > phrase.length {
break
}
let next_step = (time0 + (x-offset) as usize + 1) * time_z;
if step % ppq == 0 {
"|".blit(buf, x as u16, y, Some(Style::default().dim()));
steps.push((x, step, next_step));
let cell = if step % ppq == 0 {
&cell_bg_tick
} else {
&cell_bg
};
for y in phrase_area.y .. phrase_area.y + phrase_area.height {
if y == phrase_area.y {
if step % (4 * ppq) == 0 {
format!("{}", 1 + step / (4 * ppq)).blit(buf, x, y, None);
} else if step % ppq == 0 {
*buf.get_mut(x, y) = cell.clone();
}
} else {
*buf.get_mut(x, y) = cell.clone();
}
}
let bar = 4 * ppq;
if step % bar == 0 {
format!("{}", (step/bar)+1)
.blit(buf, x as u16, y, Some(Style::default().bold().not_dim()));
}
for index in 0..height-2 {
let note_a = note0 + index as usize * 2;
let note_b = note0 + index as usize * 2 + 1;
let (character, mut style) = match (
phrase.contains_note_on(u7::from_int_lossy(note_a as u8), step, next_step),
phrase.contains_note_on(u7::from_int_lossy(note_b as u8), step, next_step),
) {
(true, true) => ("", wh),
(false, true) => ("", wh),
(true, false) => ("", wh),
(false, false) => (if step % ppq == 0 { "|" } else { "·" }, bw),
}
for index in 0..height-2 {
let note_a = note0 + index as usize * 2;
let note_b = note0 + index as usize * 2 + 1;
for (x, step, next_step) in steps.iter() {
let (a, b) = (
phrase.contains_note_on(u7::from_int_lossy(note_a as u8), *step, *next_step),
phrase.contains_note_on(u7::from_int_lossy(note_b as u8), *step, *next_step),
);
let cell = if a && b {
&cell_ab
} else if a {
&cell_a
} else if b {
&cell_b
} else {
continue
};
let y = y + height.saturating_sub(index+2) as u16;
character.blit(buf, x, y, Some(style));
*buf.get_mut(*x, y) = cell.clone()
}
}
}