mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
185 lines
5.6 KiB
Rust
185 lines
5.6 KiB
Rust
use crate::core::*;
|
|
use super::*;
|
|
|
|
pub fn draw (
|
|
buf: &mut Buffer,
|
|
area: Rect,
|
|
phrase: Option<&Phrase>,
|
|
ppq: usize,
|
|
time: usize,
|
|
time0: usize,
|
|
time_z: usize,
|
|
note: usize,
|
|
note0: usize,
|
|
style: Option<Style>,
|
|
) -> Usually<Rect> {
|
|
let now = 0;
|
|
let notes = &[];
|
|
match time_z {
|
|
1 => "1/384",
|
|
2 => "1/192",
|
|
3 => "1/128",
|
|
4 => "1/96",
|
|
6 => "1/64",
|
|
8 => "1/48",
|
|
12 => "1/32",
|
|
16 => "1/24",
|
|
24 => "1/16",
|
|
32 => "1/12",
|
|
48 => "1/8",
|
|
64 => "1/6",
|
|
96 => "1/4",
|
|
128 => "1/3",
|
|
192 => "1/2",
|
|
384 => "1/1",
|
|
_ => ""
|
|
}.blit(buf, area.x, area.y, Some(Style::default().dim()));
|
|
keys(buf, area, note0, notes)?;
|
|
timer(buf, area, time0, now);
|
|
if let Some(phrase) = phrase {
|
|
lanes(buf, area, phrase, ppq, time_z, time0, note0);
|
|
}
|
|
let style = style.unwrap_or_else(||{Style::default().green().not_dim()});
|
|
cursor(buf, area, style, time, note);
|
|
//footer(buf, area, note0, note, time0, time, time_z);
|
|
Ok(area)
|
|
}
|
|
|
|
pub fn timer (
|
|
buf: &mut Buffer,
|
|
area: Rect,
|
|
time0: usize,
|
|
now: usize
|
|
) {
|
|
let x = area.x + 5;
|
|
for step in time0..(time0+area.width as usize).saturating_sub(5) {
|
|
buf.set_string(x + step as u16, area.y, &"-", if step == now {
|
|
Style::default().yellow().bold().not_dim()
|
|
} else {
|
|
Style::default()
|
|
});
|
|
}
|
|
}
|
|
|
|
pub fn keys (
|
|
buf: &mut Buffer,
|
|
area: Rect,
|
|
note0: usize,
|
|
notes: &[bool],
|
|
) -> Usually<Rect> {
|
|
let bw = Style::default().dim();
|
|
let Rect { x, y, width, height } = area;
|
|
let h = height.saturating_sub(2);
|
|
for index in 0..h {
|
|
let y = y + h - index;
|
|
let key = KEYS_VERTICAL[(index % 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()));
|
|
let note_a = note0 + (index * 2) as usize;
|
|
if note_a % 12 == 0 {
|
|
let octave = format!("C{}", (note_a / 12) as i8 - 2);
|
|
octave.blit(buf, x + 3, y, None);
|
|
continue
|
|
}
|
|
let note_b = note0 + (index * 2) as usize;
|
|
if note_b % 12 == 0 {
|
|
let octave = format!("C{}", (note_b / 12) as i8 - 2);
|
|
octave.blit(buf, x + 3, y, None);
|
|
continue
|
|
}
|
|
}
|
|
Ok(area)
|
|
}
|
|
|
|
pub fn lanes (
|
|
buf: &mut Buffer,
|
|
area: Rect,
|
|
phrase: &Phrase,
|
|
ppq: usize,
|
|
time_z: usize,
|
|
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 (bw, wh) = (bg.dim(), bg.white());
|
|
let offset = 5;
|
|
for x in x+offset..x+width-offset {
|
|
let step = (x-offset) as usize * time_z;
|
|
if step % ppq == 0 {
|
|
"|".blit(buf, x as u16, y, Some(Style::default().dim()));
|
|
}
|
|
let bar = 4 * ppq;
|
|
if step % bar == 0 {
|
|
format!("{}", (step/bar)+1)
|
|
.blit(buf, x as u16, y, Some(Style::default().bold().not_dim()));
|
|
}
|
|
let (a, b) = (step, step + time_z);
|
|
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, style) = match (
|
|
contains_note_on(phrase, u7::from_int_lossy(note_a as u8), a, b),
|
|
contains_note_on(phrase, u7::from_int_lossy(note_b as u8), a, b),
|
|
) {
|
|
(true, true) => ("█", wh),
|
|
(false, true) => ("▄", wh),
|
|
(true, false) => ("▀", wh),
|
|
(false, false) => ("·", bw),
|
|
};
|
|
let y = y + height.saturating_sub(index+2) as u16;
|
|
character.blit(buf, x, y, Some(style));
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn cursor (
|
|
buf: &mut Buffer,
|
|
area: Rect,
|
|
style: Style,
|
|
time: usize,
|
|
note: usize
|
|
) {
|
|
let x = area.x + 5 + time as u16;
|
|
let y = area.y + 1 + note as u16 / 2;
|
|
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
|
c.blit(buf, x, y, Some(style));
|
|
}
|
|
|
|
pub fn footer (
|
|
buf: &mut Buffer,
|
|
area: Rect,
|
|
note0: usize,
|
|
note: usize,
|
|
time0: usize,
|
|
time: usize,
|
|
time_z: usize,
|
|
) {
|
|
let Rect { mut x, y, width, height } = area;
|
|
buf.set_string(x, y + height, format!("├{}┤", "-".repeat((width - 2).into())),
|
|
Style::default().dim());
|
|
buf.set_string(x, y + height + 2, format!("├{}┤", "-".repeat((width - 2).into())),
|
|
Style::default().dim());
|
|
x = x + 2;
|
|
{
|
|
for (_, [letter, title, value]) in [
|
|
["S", &format!("ync"), &format!("<4/4>")],
|
|
["Q", &format!("uant"), &format!("<1/{}>", 4 * time_z)],
|
|
["N", &format!("ote"), &format!("{} ({}-{})", note0 + note, note0, "X")],
|
|
["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")],
|
|
].iter().enumerate() {
|
|
buf.set_string(x, y + height + 1, letter, Style::default().bold().yellow().dim());
|
|
x = x + 1;
|
|
buf.set_string(x, y + height + 1, &title, Style::default().bold().dim());
|
|
x = x + title.len() as u16 + 1;
|
|
buf.set_string(x, y + height + 1, &value, Style::default().not_dim());
|
|
x = x + value.len() as u16;
|
|
buf.set_string(x, y + height + 1, " ", Style::default().dim());
|
|
x = x + 2;
|
|
}
|
|
}
|
|
}
|