From 36707fc7eb0d025dbb13e9f92b054811ea3fbf6c Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 10 Jan 2025 02:20:34 +0100 Subject: [PATCH] the freeze was the autozoom --- Cargo.toml | 3 ++ midi/src/midi_editor.rs | 2 +- midi/src/piano_h.rs | 101 ++++++++++++++++++---------------------- tek/Cargo.toml | 3 -- 4 files changed, 50 insertions(+), 59 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1cb93658..7c7fcf4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,6 @@ members = [ "./time", "./tui" ] + +[profile.release] +lto = true diff --git a/midi/src/midi_editor.rs b/midi/src/midi_editor.rs index 53214825..d8f997bd 100644 --- a/midi/src/midi_editor.rs +++ b/midi/src/midi_editor.rs @@ -38,7 +38,7 @@ impl Default for MidiEditor { has_size!(|self: MidiEditor|&self.size); render!(TuiOut: (self: MidiEditor) => { self.autoscroll(); - self.autozoom(); + //self.autozoom(); Fill::xy(Bsp::b(&self.size, &self.mode)) }); impl TimeRange for MidiEditor { diff --git a/midi/src/piano_h.rs b/midi/src/piano_h.rs index f3984318..aa0e3b00 100644 --- a/midi/src/piano_h.rs +++ b/midi/src/piano_h.rs @@ -22,7 +22,7 @@ impl PianoHorizontal { let mut range = MidiRangeModel::from((24, true)); range.time_axis = size.x.clone(); range.note_axis = size.y.clone(); - let mut piano = Self { + let piano = Self { keys_width: 5, size, range, @@ -40,19 +40,14 @@ impl PianoHorizontal { pub(crate) fn note_y_iter (note_lo: usize, note_hi: usize, y0: u16) -> impl Iterator { (note_lo..=note_hi).rev().enumerate().map(move|(y, n)|(y, y0 + y as u16, n)) } -render!(TuiOut: (self: PianoHorizontal) => Bsp::s( // the freeze is in the piano +render!(TuiOut: (self: PianoHorizontal) => Bsp::s( // the freeze is in the Measure Fixed::y(1, Bsp::e( Fixed::x(self.keys_width, ""), Fill::x(PianoHorizontalTimeline(self)), )), Fill::xy(Bsp::e( Fixed::x(self.keys_width, PianoHorizontalKeys(self)), - Fill::xy(self.size.of("")), - //"", - //Fill::xy(self.size.of(lay!( - ////self.notes(), - ////self.cursor() - //))), + Fill::xy(self.size.of(lay!(self.notes(), self.cursor()))), )), )); impl PianoHorizontal { @@ -84,7 +79,6 @@ impl PianoHorizontal { let style = Style::default().fg(clip.color.base.rgb);//.bg(Color::Rgb(0, 0, 0)); let mut notes_on = [false;128]; for (x, time_start) in (0..clip.length).step_by(zoom).enumerate() { - for (y, note) in (0..=127).rev().enumerate() { if let Some(cell) = buf.get_mut(x, note) { if notes_on[note] { @@ -93,7 +87,6 @@ impl PianoHorizontal { } } } - let time_end = time_start + zoom; for time in time_start..time_end.min(clip.length) { for event in clip.notes[time].iter() { @@ -122,32 +115,31 @@ impl PianoHorizontal { let note_hi = self.note_hi(); let note_point = self.note_point(); let buffer = self.buffer.clone(); - return "" - //RenderThunk::new(move|render: &mut TuiOut|{ - //let source = buffer.read().unwrap(); - //let [x0, y0, w, h] = render.area().xywh(); + RenderThunk::new(move|render: &mut TuiOut|{ + let source = 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) { - //if let Some(cell) = render.buffer.cell_mut(ratatui::prelude::Position::from((screen_x, screen_y))) { - //*cell = source_cell.clone(); - //} - //} - //} - //} - //} - //}) + 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) { + if let Some(cell) = render.buffer.cell_mut(ratatui::prelude::Position::from((screen_x, screen_y))) { + *cell = source_cell.clone(); + } + } + } + } + } + }) } fn cursor (&self) -> impl Content { let style = Some(Style::default().fg(self.color.lightest.rgb)); @@ -158,28 +150,27 @@ impl PianoHorizontal { let time_point = self.time_point(); let time_start = self.time_start().get(); let time_zoom = self.time_zoom().get(); - "" - //RenderThunk::new(move|render: &mut TuiOut|{ - ////let [x0, y0, w, _] = render.area().xywh(); - ////for (_area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) { - ////if note == note_point { - ////for x in 0..w { - ////let screen_x = x0 + x; - ////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 { - ////render.blit(&"█", screen_x, screen_y, style); - ////let tail = note_len as u16 / time_zoom as u16; - ////for x_tail in (screen_x + 1)..(screen_x + tail) { - ////render.blit(&"▂", x_tail, screen_y, style); - ////} - ////break - ////} - ////} - ////break - ////} - ////} - //}) + RenderThunk::new(move|render: &mut TuiOut|{ + let [x0, y0, w, _] = render.area().xywh(); + for (_area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) { + if note == note_point { + for x in 0..w { + let screen_x = x0 + x; + 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 { + render.blit(&"█", screen_x, screen_y, style); + let tail = note_len as u16 / time_zoom as u16; + for x_tail in (screen_x + 1)..(screen_x + tail) { + render.blit(&"▂", x_tail, screen_y, style); + } + break + } + } + break + } + } + }) } } diff --git a/tek/Cargo.toml b/tek/Cargo.toml index 54532b66..3c593ae8 100644 --- a/tek/Cargo.toml +++ b/tek/Cargo.toml @@ -25,6 +25,3 @@ wavers = "1.4.3" [features] default = [] - -[profile.release] -lto = true