mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
refactor: separate Render from Handle
This commit is contained in:
parent
d9b3bd150e
commit
72ead536be
12 changed files with 255 additions and 212 deletions
|
|
@ -7,17 +7,26 @@ pub fn draw_horizontal (
|
|||
mut area: Rect,
|
||||
beat: usize
|
||||
) -> Usually<Rect> {
|
||||
let ppq = s.timebase.ppq() as u32;
|
||||
area.x = area.x + 13;
|
||||
|
||||
draw_keys_horizontal(s, buf, area)?;
|
||||
|
||||
let Rect { x, y, width, .. } = area;
|
||||
let (time0, time1) = s.time_axis;
|
||||
let (note0, note1) = s.note_axis;
|
||||
keys(s, buf, area)?;
|
||||
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);
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
fn timer (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, beat: usize) {
|
||||
let bw = Style::default().dim();
|
||||
let bg = Style::default().on_black();
|
||||
|
||||
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 {
|
||||
Style::default().yellow().bold().not_dim()
|
||||
|
|
@ -25,6 +34,13 @@ pub fn draw_horizontal (
|
|||
Style::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn lanes (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, width: u16) {
|
||||
let bw = Style::default().dim();
|
||||
let bg = Style::default().on_black();
|
||||
let ppq = s.timebase.ppq() as u32;
|
||||
let (time0, time1) = s.time_axis;
|
||||
for step in time0..time1 {
|
||||
let time_start = step as u32 * ppq;
|
||||
let time_end = (step + 1) as u32 * ppq;
|
||||
|
|
@ -33,12 +49,16 @@ pub fn draw_horizontal (
|
|||
}
|
||||
for (_, (_, events)) in s.sequences[s.sequence].range(time_start..time_end).enumerate() {
|
||||
if events.len() > 0 {
|
||||
buf.set_string(x + 5 + step as u16, y, "█", bw);
|
||||
buf.set_string(x + 6 + step as u16, y, "█", bw);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let height = 32.max(note1 - note0) / 2;
|
||||
fn footer (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, width: u16, height: u16) {
|
||||
let bw = Style::default().dim();
|
||||
let bg = Style::default().on_black();
|
||||
let (note0, note1) = s.note_axis;
|
||||
buf.set_string(x - 13, y + height, format!("├{}┤", "-".repeat((width - 2).into())),
|
||||
Style::default().dim());
|
||||
{
|
||||
|
|
@ -65,26 +85,25 @@ pub fn draw_horizontal (
|
|||
x = x + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cursor (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16) {
|
||||
let bw = Style::default().dim();
|
||||
let bg = Style::default().on_black();
|
||||
buf.set_string(
|
||||
x + 6 + s.time_cursor,
|
||||
y + s.note_cursor / 2,
|
||||
if s.note_cursor % 2 == 0 { "▀" } else { "▄" },
|
||||
Style::default()
|
||||
);
|
||||
Ok(Rect {
|
||||
x: x - 13,
|
||||
y,
|
||||
width: time1 - time0 + 19,
|
||||
height: height + 3
|
||||
})
|
||||
}
|
||||
|
||||
pub fn draw_keys_horizontal (s: &Sequencer, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
|
||||
fn keys (s: &Sequencer, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
|
||||
let bw = Style::default().dim();
|
||||
let bg = Style::default().on_black();
|
||||
let Rect { x, y, .. } = area;
|
||||
let (note0, note1) = s.note_axis;
|
||||
let (time0, time1) = s.time_axis;
|
||||
let bw = Style::default().dim();
|
||||
let bg = Style::default().on_black();
|
||||
for i in 0..32.max(note1-note0)/2 {
|
||||
let y = y + i;
|
||||
buf.set_string(x + 2, y, KEYS_VERTICAL[(i % 6) as usize], bw);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue