mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
fix timer of horizontal sequencer
This commit is contained in:
parent
2601592d17
commit
1259176576
6 changed files with 293 additions and 254 deletions
|
|
@ -17,6 +17,9 @@ pub struct SequencerView<'a> {
|
|||
pub time_start: usize,
|
||||
/// Position of cursor within time range
|
||||
pub time_cursor: usize,
|
||||
|
||||
/// Current time
|
||||
pub now: usize
|
||||
}
|
||||
|
||||
impl<'a> Render for SequencerView<'a> {
|
||||
|
|
@ -27,82 +30,70 @@ impl<'a> Render for SequencerView<'a> {
|
|||
lozenge_left(buf, x, y, height, style);
|
||||
lozenge_right(buf, x + width - 1, y, height, style);
|
||||
}
|
||||
self::horizontal::draw(
|
||||
buf,
|
||||
area,
|
||||
self.phrase,
|
||||
self.ppq,
|
||||
self.time_cursor,
|
||||
self.time_start,
|
||||
self.time_zoom,
|
||||
self.note_cursor,
|
||||
self.note_start,
|
||||
Some(if self.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
})
|
||||
)?;
|
||||
self.draw_horizontal(buf, area)?;
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SequencerView<'a> {
|
||||
fn draw_horizontal (&self, buf: &mut Buffer, area: Rect) -> Usually<()> {
|
||||
let style = Some(if self.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
});
|
||||
let notes = &[];
|
||||
pulse_to_note_length(self.time_zoom)
|
||||
.blit(buf, area.x, area.y, Some(Style::default().dim()));
|
||||
self::horizontal::keys(buf, area, self.note_start, notes)?;
|
||||
if let Some(phrase) = self.phrase {
|
||||
self::horizontal::timer(buf, area, self.time_start, self.time_zoom, self.now % phrase.length);
|
||||
self::horizontal::lanes(buf, area, phrase, self.ppq, self.time_zoom, self.time_start, self.note_start);
|
||||
}
|
||||
let style = style.unwrap_or_else(||{Style::default().green().not_dim()});
|
||||
self::horizontal::cursor(buf, area, style, self.time_cursor, self.note_cursor);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn pulse_to_note_length (time_z: usize) -> &'static str {
|
||||
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",
|
||||
_ => ""
|
||||
}
|
||||
}
|
||||
|
||||
mod horizontal {
|
||||
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 {
|
||||
pub fn timer (buf: &mut Buffer, area: Rect, time0: usize, time_z: usize, now: usize) {
|
||||
let Rect { x, width, .. } = area;
|
||||
let offset = 5;
|
||||
for x in x+offset..x+width-offset {
|
||||
let step = (time0 + (x-offset) as usize) * time_z;
|
||||
let next_step = (time0 + (x-offset) as usize + 1) * time_z;
|
||||
let style = if step <= now && now < next_step {
|
||||
Style::default().yellow().bold().not_dim()
|
||||
} else {
|
||||
Style::default()
|
||||
});
|
||||
};
|
||||
"-".blit(buf, x, area.y, Some(style))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,16 +155,19 @@ mod horizontal {
|
|||
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 (
|
||||
let (character, mut style) = match (
|
||||
phrase.contains_note_on(u7::from_int_lossy(note_a as u8), a, b),
|
||||
phrase.contains_note_on(u7::from_int_lossy(note_b as u8), a, b),
|
||||
) {
|
||||
(true, true) => ("█", wh),
|
||||
(false, true) => ("▀", wh),
|
||||
(true, false) => ("▄", wh),
|
||||
(false, false) => ("·", bw),
|
||||
(false, false) => (if step % ppq == 0 { "|" } else { "·" }, bw),
|
||||
};
|
||||
let y = y + height.saturating_sub(index+2) as u16;
|
||||
if step > phrase.length {
|
||||
style = Style::default().gray()
|
||||
}
|
||||
character.blit(buf, x, y, Some(style));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue