use crate::*; #[derive(Debug, Clone)] pub struct MidiPointModel { /// Time coordinate of cursor pub time_point: Arc, /// Note coordinate of cursor pub note_point: Arc, /// Length of note that will be inserted, in pulses pub note_len: Arc, } impl Default for MidiPointModel { fn default () -> Self { Self { time_point: Arc::new(0.into()), note_point: Arc::new(36.into()), note_len: Arc::new(24.into()), } } } pub trait NotePoint { fn note_len (&self) -> usize; fn set_note_len (&self, x: usize); fn note_point (&self) -> usize; fn set_note_point (&self, x: usize); fn note_end (&self) -> usize { self.note_point() + self.note_len() } } pub trait TimePoint { fn time_point (&self) -> usize; fn set_time_point (&self, x: usize); } pub trait MidiPoint: NotePoint + TimePoint {} impl MidiPoint for T {} impl NotePoint for MidiPointModel { fn note_len (&self) -> usize { self.note_len.load(Relaxed)} fn set_note_len (&self, x: usize) { self.note_len.store(x, Relaxed) } fn note_point (&self) -> usize { self.note_point.load(Relaxed).min(127) } fn set_note_point (&self, x: usize) { self.note_point.store(x.min(127), Relaxed) } } impl TimePoint for MidiPointModel { fn time_point (&self) -> usize { self.time_point.load(Relaxed) } fn set_time_point (&self, x: usize) { self.time_point.store(x, Relaxed) } }