editor: add fine time step and overflow

This commit is contained in:
🪞👃🪞 2025-05-11 19:19:14 +03:00
parent d647fc68e9
commit d1be569b48
3 changed files with 18 additions and 3 deletions

View file

@ -1,5 +1,7 @@
(@left editor set-time-pos :time-pos-prev) (@left editor set-time-pos :time-pos-prev)
(@shift-left editor set-time-pos :time-pos-prev-fine)
(@right editor set-time-pos :time-pos-next) (@right editor set-time-pos :time-pos-next)
(@shift-right editor set-time-pos :time-pos-next-fine)
(@equal editor set-time-zoom :time-zoom-prev) (@equal editor set-time-zoom :time-zoom-prev)
(@minus editor set-time-zoom :time-zoom-next) (@minus editor set-time-zoom :time-zoom-next)

View file

@ -5,6 +5,10 @@ use crate::*;
todo!() todo!()
} }
fn clip_length (&self) -> usize {
self.clip().as_ref().map(|p|p.read().unwrap().length).unwrap_or(1)
}
fn note_length (&self) -> usize { fn note_length (&self) -> usize {
self.get_note_len() self.get_note_len()
} }
@ -49,10 +53,19 @@ use crate::*;
self.get_time_pos() self.get_time_pos()
} }
fn time_pos_next (&self) -> usize { fn time_pos_next (&self) -> usize {
self.get_time_pos() + self.get_note_len() (self.get_time_pos() + self.get_note_len()) % self.clip_length()
}
fn time_pos_next_fine (&self) -> usize {
(self.get_time_pos() + 1) % self.clip_length()
} }
fn time_pos_prev (&self) -> usize { fn time_pos_prev (&self) -> usize {
self.get_time_pos().saturating_sub(self.get_note_len()) let step = self.get_note_len();
self.get_time_pos().overflowing_sub(step)
.0.min(self.clip_length().saturating_sub(step))
}
fn time_pos_prev_fine (&self) -> usize {
self.get_time_pos().overflowing_sub(1)
.0.min(self.clip_length().saturating_sub(1))
} }
fn time_zoom (&self) -> usize { fn time_zoom (&self) -> usize {

View file

@ -61,7 +61,7 @@ impl MidiEditor {
clip.notes[note_end].push(note_off); clip.notes[note_end].push(note_off);
} }
if advance { if advance {
self.set_time_pos(note_end + 1); self.set_time_pos((note_end + 1) % clip.length);
} }
redraw = true; redraw = true;
} }