tek/src/piano/piano_h_notes.rs
2025-01-02 17:20:37 +01:00

33 lines
1.3 KiB
Rust

use crate::*;
use super::*;
pub struct PianoHorizontalNotes<'a>(pub(crate) &'a PianoHorizontal);
render!(Tui: |self: PianoHorizontalNotes<'a>, render|{
let time_start = self.0.time_start().get();
let note_axis = self.0.note_axis().get();
let note_lo = self.0.note_lo().get();
let note_hi = self.0.note_hi();
let note_point = self.0.note_point();
let source = self.0.buffer.read().unwrap();
let [x0, y0, w, h] = render.area().xywh();
if h as usize != note_axis {
panic!("area height mismatch: {h} <> {note_axis}");
}
for (area_x, screen_x) in (x0..x0+w).enumerate() {
for (area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {
let source_x = time_start + area_x;
let source_y = note_hi - area_y;
// TODO: enable loop rollover:
//let source_x = (time_start + area_x) % source.width.max(1);
//let source_y = (note_hi - area_y) % source.height.max(1);
let is_in_x = source_x < source.width;
let is_in_y = source_y < source.height;
if is_in_x && is_in_y {
if let Some(source_cell) = source.get(source_x, source_y) {
*render.buffer.get_mut(screen_x, screen_y) = source_cell.clone();
}
}
}
}
});