From 2198d14a406a6ee6a478594c6e5d1460ad8a8bef Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 15 Dec 2024 16:00:46 +0100 Subject: [PATCH] fix autoscroll keys range --- crates/tek/src/api/note.rs | 6 +++--- crates/tek/src/tui/app_sequencer.rs | 2 +- crates/tek/src/tui/phrase_editor.rs | 5 +++-- crates/tek/src/tui/piano_horizontal.rs | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/tek/src/api/note.rs b/crates/tek/src/api/note.rs index 3429cb77..3d4e1e49 100644 --- a/crates/tek/src/api/note.rs +++ b/crates/tek/src/api/note.rs @@ -6,12 +6,12 @@ pub trait MidiViewport: MidiRange + MidiPoint + HasSize { fn autoscroll (&self) { let note_lo = self.note_lo(); let note_axis = self.note_axis(); - let note_hi = (note_lo + note_axis).min(127); + let note_hi = self.note_hi().saturating_sub(1); let note_point = self.note_point().min(127); if note_point < note_lo { self.set_note_lo(note_point); } else if note_point > note_hi { - self.set_note_lo(note_lo + note_point - note_hi); + self.set_note_lo((note_lo + note_point).saturating_sub(note_hi)); } } /// Make sure best usage of screen space is achieved by default @@ -57,7 +57,7 @@ pub trait MidiRange { fn set_note_lo (&self, x: usize); fn note_axis (&self) -> usize; fn time_axis (&self) -> usize; - fn note_hi (&self) -> usize { self.note_lo() + self.note_axis() } + fn note_hi (&self) -> usize { self.note_lo() + self.note_axis().saturating_sub(1) } fn time_end (&self) -> usize { self.time_start() + self.time_axis() * self.time_zoom() } } impl MidiRange for MidiRangeModel { diff --git a/crates/tek/src/tui/app_sequencer.rs b/crates/tek/src/tui/app_sequencer.rs index e4862f3a..cc13e803 100644 --- a/crates/tek/src/tui/app_sequencer.rs +++ b/crates/tek/src/tui/app_sequencer.rs @@ -188,7 +188,7 @@ render!(|self: SequencerTui|lay!([self.size, Tui::split_n(false, 5, PhraseEditStatus(&self.editor), SequencerStatusBar::from(self), ])), - Tui::split_e(false, if self.size.w() > 60 { + Tui::split_w(false, if self.size.w() > 60 { 20 } else if self.size.w() > 40 { 15 diff --git a/crates/tek/src/tui/phrase_editor.rs b/crates/tek/src/tui/phrase_editor.rs index bdc6c307..6d45b62f 100644 --- a/crates/tek/src/tui/phrase_editor.rs +++ b/crates/tek/src/tui/phrase_editor.rs @@ -143,8 +143,8 @@ impl MidiRange for PhraseEditorModel { fn note_lo (&self) -> usize { self.mode.note_lo() } fn note_axis (&self) -> usize { self.mode.note_axis() } fn time_axis (&self) -> usize { self.mode.time_axis() } - fn note_hi (&self) -> usize { self.note_lo() + self.note_axis() } } + impl MidiPoint for PhraseEditorModel { fn note_len (&self) -> usize { self.mode.note_len()} fn set_note_len (&self, x: usize) { self.mode.set_note_len(x) } @@ -153,6 +153,7 @@ impl MidiPoint for PhraseEditorModel { fn time_point (&self) -> usize { self.mode.time_point() } fn set_time_point (&self, x: usize) { self.mode.set_time_point(x) } } + impl PhraseViewMode for PhraseEditorModel { fn buffer_size (&self, phrase: &Phrase) -> (usize, usize) { self.mode.buffer_size(phrase) @@ -221,7 +222,7 @@ impl From>>> for PhraseEditorModel { impl std::fmt::Debug for PhraseEditorModel { fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { f.debug_struct("PhraseEditorModel") - .field("point", &self) + .field("mode", &self.mode) .finish() } } diff --git a/crates/tek/src/tui/piano_horizontal.rs b/crates/tek/src/tui/piano_horizontal.rs index ff048a0b..748b7799 100644 --- a/crates/tek/src/tui/piano_horizontal.rs +++ b/crates/tek/src/tui/piano_horizontal.rs @@ -99,7 +99,7 @@ render!(|self: PianoHorizontalKeys|render(|to|Ok({ let key_style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0))); let off_style = Some(Style::default().fg(TuiTheme::g(160))); let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(self.color.base.rgb).bold()); - for (y, note) in (self.note_lo..=self.note_hi).rev().enumerate().map(|(y, n)|(y0 + y as u16, n)) { + for (y, note) in (self.note_lo..self.note_hi).rev().enumerate().map(|(y, n)|(y0 + y as u16, n)) { let key = match note % 12 { 11 => "████▌", 10 => " ",