mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
bring the keys back
This commit is contained in:
parent
ccb4a01a29
commit
377a637eec
1 changed files with 49 additions and 45 deletions
|
|
@ -50,10 +50,11 @@ render!(|self: PianoHorizontal|{
|
|||
let note_len = self.point.note_len();
|
||||
let range = &self.range;
|
||||
let point = &self.point;
|
||||
let keys = move||PianoHorizontalKeys { color, range, point }; //note_lo, note_hi, note_point: Some(note_point), };
|
||||
let timeline = move||PianoHorizontalTimeline { color, time_start, time_zoom, };
|
||||
let notes = move||PianoHorizontalNotes { source: &self.buffer, time_start, note_hi, };
|
||||
let cursor = move||PianoHorizontalCursor { time_zoom, time_point, time_start, note_point, note_len, note_hi, note_lo, };
|
||||
let buffer = &self.buffer;
|
||||
let keys = move||PianoHorizontalKeys { range, point, color }; //note_lo, note_hi, note_point: Some(note_point), };
|
||||
let timeline = move||PianoHorizontalTimeline { range, color };
|
||||
let notes = move||PianoHorizontalNotes { range, buffer };
|
||||
let cursor = move||PianoHorizontalCursor { range, point };
|
||||
let keys_width = 5;
|
||||
Tui::fill_xy(Tui::bg(bg, Bsp::s(
|
||||
Tui::fill_x(Tui::push_x(keys_width, timeline())),
|
||||
|
|
@ -66,15 +67,14 @@ render!(|self: PianoHorizontal|{
|
|||
)))
|
||||
});
|
||||
|
||||
pub struct PianoHorizontalTimeline {
|
||||
color: ItemPalette,
|
||||
time_start: usize,
|
||||
time_zoom: usize,
|
||||
pub struct PianoHorizontalTimeline<'a> {
|
||||
color: ItemPalette,
|
||||
range: &'a MidiRangeModel,
|
||||
}
|
||||
render!(|self: PianoHorizontalTimeline|Tui::fg_bg(
|
||||
render!(|self: PianoHorizontalTimeline<'a>|Tui::fg_bg(
|
||||
self.color.lightest.rgb,
|
||||
self.color.darkest.rgb,
|
||||
format!("{}*{}", self.time_start, self.time_zoom).as_str()
|
||||
format!("{}*{}", self.range.time_start(), self.range.time_zoom()).as_str()
|
||||
));
|
||||
|
||||
pub struct PianoHorizontalKeys<'a> {
|
||||
|
|
@ -92,16 +92,6 @@ render!(|self: PianoHorizontalKeys<'a>|render(|to|Ok({
|
|||
let off_style = Some(Style::default().fg(TuiTheme::g(160)));
|
||||
let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(self.color.light.rgb).bold());
|
||||
|
||||
let debug = true;
|
||||
if debug {
|
||||
to.blit(&format!("XYU"), x, y0, None);
|
||||
to.blit(&format!("x={x}"), x, y0+1, None);
|
||||
to.blit(&format!("y0={y0}"), x, y0+2, None);
|
||||
to.blit(&format!("note_lo={note_lo}"), x, y0+3, None);
|
||||
to.blit(&format!("note_hi={note_hi}"), x, y0+4, None);
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
for (y, note) in (note_lo..note_hi).rev().enumerate().map(|(y, n)|(y0 + y as u16, n)) {
|
||||
let key = match note % 12 {
|
||||
11 => "████▌",
|
||||
|
|
@ -126,28 +116,39 @@ render!(|self: PianoHorizontalKeys<'a>|render(|to|Ok({
|
|||
to.blit(&to_note_name(note), x, y, off_style)
|
||||
};
|
||||
}
|
||||
|
||||
let debug = true;
|
||||
if debug {
|
||||
to.blit(&format!("XYU"), x, y0, None);
|
||||
to.blit(&format!("x={x}"), x, y0+1, None);
|
||||
to.blit(&format!("y0={y0}"), x, y0+2, None);
|
||||
to.blit(&format!("note_lo={note_lo}"), x, y0+3, None);
|
||||
to.blit(&format!("note_hi={note_hi}"), x, y0+4, None);
|
||||
}
|
||||
})));
|
||||
|
||||
pub struct PianoHorizontalCursor {
|
||||
time_zoom: usize,
|
||||
time_point: usize,
|
||||
time_start: usize,
|
||||
note_point: usize,
|
||||
note_len: usize,
|
||||
note_hi: usize,
|
||||
note_lo: usize,
|
||||
pub struct PianoHorizontalCursor<'a> {
|
||||
range: &'a MidiRangeModel,
|
||||
point: &'a MidiPointModel,
|
||||
}
|
||||
render!(|self: PianoHorizontalCursor|render(|to|Ok({
|
||||
render!(|self: PianoHorizontalCursor<'a>|render(|to|Ok({
|
||||
let [x0, y0, w, _] = to.area().xywh();
|
||||
let note_hi = self.range.note_hi();
|
||||
let note_len = self.point.note_len();
|
||||
let note_lo = self.range.note_lo();
|
||||
let note_point = self.point.note_point();
|
||||
let time_point = self.point.time_point();
|
||||
let time_start = self.range.time_start();
|
||||
let time_zoom = self.range.time_zoom();
|
||||
let style = Some(Style::default().fg(Color::Rgb(0,255,0)));
|
||||
for (y, note) in (self.note_lo..=self.note_hi).rev().enumerate() {
|
||||
if note == self.note_point {
|
||||
for (y, note) in (note_lo..=note_hi).rev().enumerate() {
|
||||
if note == note_point {
|
||||
for x in 0..w {
|
||||
let time_1 = self.time_start + x as usize * self.time_zoom;
|
||||
let time_2 = time_1 + self.time_zoom;
|
||||
if time_1 <= self.time_point && self.time_point < time_2 {
|
||||
let time_1 = time_start + x as usize * time_zoom;
|
||||
let time_2 = time_1 + time_zoom;
|
||||
if time_1 <= time_point && time_point < time_2 {
|
||||
to.blit(&"█", x0 + x as u16, y0 + y as u16, style);
|
||||
let tail = self.note_len as u16 / self.time_zoom as u16;
|
||||
let tail = note_len as u16 / time_zoom as u16;
|
||||
for x_tail in (x0 + x + 1)..(x0 + x + tail) {
|
||||
to.blit(&"▂", x_tail, y0 + y as u16, style);
|
||||
}
|
||||
|
|
@ -160,26 +161,29 @@ render!(|self: PianoHorizontalCursor|render(|to|Ok({
|
|||
})));
|
||||
|
||||
pub struct PianoHorizontalNotes<'a> {
|
||||
source: &'a BigBuffer,
|
||||
time_start: usize,
|
||||
note_hi: usize,
|
||||
range: &'a MidiRangeModel,
|
||||
buffer: &'a BigBuffer,
|
||||
}
|
||||
render!(|self: PianoHorizontalNotes<'a>|render(|to|Ok({
|
||||
let note_hi = self.range.note_hi();
|
||||
let time_start = self.range.time_start();
|
||||
let source = &self.buffer;
|
||||
let [x0, y0, w, h] = to.area().xywh();
|
||||
let target = &mut to.buffer;
|
||||
for (x, target_x) in (x0..x0+w).enumerate() {
|
||||
for (y, target_y) in (y0..y0+h).enumerate() {
|
||||
if y > self.note_hi {
|
||||
if y > note_hi {
|
||||
break
|
||||
}
|
||||
let source_x = self.time_start + x;
|
||||
let source_y = self.note_hi - y;
|
||||
let source_x = time_start + x;
|
||||
let source_y = note_hi - y;
|
||||
// TODO: enable loop rollover:
|
||||
//let source_x = (time_start + x) % source.width.max(1);
|
||||
//let source_y = (note_hi - y) % source.height.max(1);
|
||||
if source_x < self.source.width && source_y < self.source.height {
|
||||
let target_cell = target.get_mut(target_x, target_y);
|
||||
if let Some(source_cell) = self.source.get(source_x, source_y) {
|
||||
let in_x = source_x < source.width;
|
||||
let in_y = source_y < source.height;
|
||||
if in_x && in_y {
|
||||
let target_cell = to.buffer.get_mut(target_x, target_y);
|
||||
if let Some(source_cell) = source.get(source_x, source_y) {
|
||||
*target_cell = source_cell.clone();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue