This commit is contained in:
🪞👃🪞 2024-06-29 14:12:21 +03:00
parent f48f17e9a4
commit 4ebecc2427
7 changed files with 107 additions and 71 deletions

View file

@ -9,11 +9,23 @@ pub fn draw (
) -> Usually<Rect> {
area.x = area.x + 13;
let Rect { x, y, width, .. } = area;
keys(s, buf, area)?;
keys(buf, area, s.note_axis.1)?;
timer(s, buf, x, y, beat);
let height = 32.max(s.note_axis.1 - s.note_axis.0) / 2;
lanes(s, buf, x, y, width);
cursor(s, buf, x, y, Style::default().green().not_dim());
if let Some(phrase) = s.phrase() {
lanes(buf, x, y,
phrase,
s.timebase.ppq() as u32,
s.resolution 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,
);
}
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,
@ -24,7 +36,6 @@ pub fn draw (
}
pub fn timer (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, beat: usize) {
let bw = Style::default().dim();
let (time0, time1) = s.time_axis;
for step in time0..time1 {
buf.set_string(x + 6 + step, y - 1, &"-", if beat % s.steps == step as usize {
@ -35,11 +46,9 @@ pub fn timer (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, beat: usize) {
}
}
pub fn keys (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
pub fn keys (buf: &mut Buffer, area: Rect, note1: u16) -> Usually<Rect> {
let bw = Style::default().dim();
let Rect { x, y, width, height } = area;
let (note0, note1) = s.note_axis;
let (time0, time1) = s.time_axis;
let h = 32.max(height.saturating_sub(2)*2)/2;
for i in 0..h {
let y = y + i;
@ -55,68 +64,64 @@ pub fn keys (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
Ok(area)
}
pub fn lanes (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, width: u16) {
pub fn lanes (
buf: &mut Buffer,
x: u16,
y: u16,
phrase: &Phrase,
ppq: u32,
time_zoom: u32,
time0: u32,
time1: u32,
note0: u32,
note1: u32,
) {
let bg = Style::default();
let bw = bg.dim();
let wh = bg.white();
let ppq = s.timebase.ppq() as u32;
let (time0, time1) = s.time_axis;
let (note0, note1) = s.note_axis;
let notes = &s.sequences[s.sequence].notes;
//let (time0, time1) = s.time_axis;
//let (note0, note1) = s.note_axis;
//let resolution = s.resolution;
for step in time0..time1 {
let (a, b) = (
(step + 0) as u32 * ppq / s.resolution as u32,
(step + 1) as u32 * ppq / s.resolution as u32,
);
if step % s.resolution as u16 == 0 {
buf.set_string(x + 5 + step, y - 1, &format!("{}", step + 1), Style::default());
let x = x as u32 + 5 + step;
let (a, b) = ((step + 0) * ppq / time_zoom, (step + 1) * ppq / time_zoom,);
if step % time_zoom == 0 {
format!("{}", step + 1).blit(buf, x as u16, y - 1, None);
}
let h = (note1 - note0)/2;
let h = (note1-note0)/2;
for k in 0..h {
let (character, style) = match (
contains_note_on(&s.sequences[s.sequence],
::midly::num::u7::from_int_lossy((note0 + k * 2 + 0) as u8),
a, b),
contains_note_on(&s.sequences[s.sequence],
::midly::num::u7::from_int_lossy((note0 + k * 2 + 1) as u8),
a, b),
contains_note_on(phrase, u7::from_int_lossy((note0 + k * 2 + 0) as u8), a, b),
contains_note_on(phrase, u7::from_int_lossy((note0 + k * 2 + 1) as u8), a, b),
) {
(true, true) => ("", wh),
(true, false) => ("", wh),
(false, true) => ("", wh),
(false, false) => ("·", bw),
};
//let (character, style) = ("▄", bg);
buf.set_string(x + 5 + step, y + h - k, character, style);
let y = y as u32 + h + k;
character.blit(buf, x as u16, y as u16, Some(style));
}
//for (_, (_, events)) in notes.range(time_start..time_end).enumerate() {
//if events.len() > 0 {
//buf.set_string(x + 6 + step as u16, y, "█", wh);
//}
//}
}
}
pub fn cursor (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, style: Style) {
pub fn cursor (buf: &mut Buffer, x: u16, y: u16, style: Style, time_cursor: u16, note_cursor: u16) {
buf.set_string(
x + 5 + s.time_cursor,
y + s.note_cursor / 2,
if s.note_cursor % 2 == 0 { "" } else { "" },
x + 5 + time_cursor,
y + note_cursor / 2,
if note_cursor % 2 == 0 { "" } else { "" },
style
);
}
pub fn footer (s: &Sequencer, buf: &mut Buffer, mut x: u16, y: u16, width: u16, height: u16) {
let bw = Style::default().dim();
let bg = Style::default();
let (note0, note1) = s.note_axis;
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 (i, [letter, title, value]) in [
for (_, [letter, title, value]) in [
["S", &format!("ync"), &format!("<4/4>")],
["Q", &format!("uant"), &format!("<1/{}>", 4 * s.resolution)],
["N", &format!("ote"), &format!("{} ({}-{})",