wip: decruft

This commit is contained in:
🪞👃🪞 2024-07-01 14:35:02 +03:00
parent 78e5469b32
commit 55a8b67bfb
7 changed files with 125 additions and 180 deletions

View file

@ -5,40 +5,44 @@ pub fn draw (
s: &Sequencer,
buf: &mut Buffer,
mut area: Rect,
beat: usize
) -> Usually<Rect> {
area.x = area.x + 13;
let Rect { x, y, width, .. } = area;
keys(buf, area, s.note_axis.1)?;
timer(buf, x+6, y-1, s.time_axis.0, s.time_axis.1, beat as u16);
let height = 32.max(s.note_axis.1 - s.note_axis.0) / 2;
let Rect { x, y, width, height } = area;
keys(buf, area, s.note_start)?;
timer(buf, x+6, y-1, s.time_start, s.time_start + area.width as usize, 0);
if let Some(phrase) = s.phrase() {
lanes(buf, x, y,
phrase,
s.timebase.ppq() as u32,
s.time_zoom as u32,
s.time_axis.0 as u32,
s.time_axis.1 as u32,
s.note_axis.0 as u32,
s.note_axis.1 as u32,
s.time_zoom as u32,
s.time_start as u32,
s.time_start as u32 + area.width as u32,
s.note_start as u32,
s.note_start as u32 + area.height as u32,
);
}
cursor(buf, x, y, Style::default().green().not_dim(),
cursor(
buf,
x,
y,
Style::default().green().not_dim(),
s.time_cursor,
s.note_cursor
);
footer(s, buf, x, y, width, height);
Ok(Rect {
x: x - 13,
y: y,
width: s.time_axis.1 - s.time_axis.0 + 19,
height: height + 3
})
Ok(Rect { x: x - 13, y, width, height })
}
pub fn timer (buf: &mut Buffer, x: u16, y: u16, time0: u16, time1: u16, now: u16) {
pub fn timer (
buf: &mut Buffer,
x: u16,
y: u16,
time0: usize,
time1: usize,
now: usize
) {
for step in time0..time1 {
buf.set_string(x + step, y, &"-", if step == now {
buf.set_string(x + step as u16, y, &"-", if step == now {
Style::default().yellow().bold().not_dim()
} else {
Style::default()
@ -46,18 +50,21 @@ pub fn timer (buf: &mut Buffer, x: u16, y: u16, time0: u16, time1: u16, now: u16
}
}
pub fn keys (buf: &mut Buffer, area: Rect, note1: u16) -> Usually<Rect> {
pub fn keys (
buf: &mut Buffer, area: Rect, note_start: usize
) -> Usually<Rect> {
let bw = Style::default().dim();
let Rect { x, y, width, height } = area;
let h = height.saturating_sub(2);
for i in 0..h {
let y = y + i;
buf.set_string(x + 1, y, KEYS_VERTICAL[(i % 6) as usize], bw);
buf.set_string(x + 2, y, "", bw);
buf.set_string(x + 5, y, &"·".repeat(width.saturating_sub(6) as usize), bw.black());
let key = KEYS_VERTICAL[(i % 6) as usize];
key.blit(buf, x + 1, y, Some(bw));
"".blit(buf, x + 2, y, Some(bw));
"·".repeat(width.saturating_sub(6) as usize).blit(buf, x + 5, y, Some(bw.black()));
//buf.set_string(x + 3, y, &format!("{i}"), Style::default());
if i % 6 == 0 {
let octave = format!("C{}", ((note1 - i) / 6) as i8 - 4);
let octave = format!("C{}", ((note_start - i as usize) / 6) as i8 - 4);
buf.set_string(x + 3, y, &octave, Style::default());
}
}
@ -105,13 +112,11 @@ pub fn lanes (
}
}
pub fn cursor (buf: &mut Buffer, x: u16, y: u16, style: Style, time_cursor: u16, note_cursor: u16) {
buf.set_string(
x + 5 + time_cursor,
y + note_cursor / 2,
if note_cursor % 2 == 0 { "" } else { "" },
style
);
pub fn cursor (buf: &mut Buffer, x: u16, y: u16, style: Style, time: usize, note: usize) {
let x = x + 5 + time as u16;
let y = y + note as u16 / 2;
let c = if note % 2 == 0 { "" } else { "" };
c.blit(buf, x, y, Some(style));
}
pub fn footer (s: &Sequencer, buf: &mut Buffer, mut x: u16, y: u16, width: u16, height: u16) {
@ -125,13 +130,13 @@ pub fn footer (s: &Sequencer, buf: &mut Buffer, mut x: u16, y: u16, width: u16,
["S", &format!("ync"), &format!("<4/4>")],
["Q", &format!("uant"), &format!("<1/{}>", 4 * s.time_zoom)],
["N", &format!("ote"), &format!("{} ({}-{})",
s.note_axis.0 + s.note_cursor,
s.note_axis.0,
s.note_axis.1 - 1)],
s.note_start + s.note_cursor,
s.note_start,
"X")],
["T", &format!("ime"), &format!("{} ({}-{})",
s.time_axis.0 + s.time_cursor + 1,
s.time_axis.0 + 1,
s.time_axis.1)],
s.time_start + s.time_cursor + 1,
s.time_start + 1,
"X")],
].iter().enumerate() {
buf.set_string(x, y + height + 1, letter, Style::default().bold().yellow().dim());
x = x + 1;