mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
MIDI -> Midi
This commit is contained in:
parent
81cb532af3
commit
6ee3abed8c
3 changed files with 19 additions and 19 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::*;
|
||||
use Ordering::Relaxed;
|
||||
|
||||
pub trait MIDIViewport<E: Engine>: MIDIRange + MIDIPoint + HasSize<E> {
|
||||
pub trait MidiViewport<E: Engine>: MidiRange + MidiPoint + HasSize<E> {
|
||||
/// Make sure cursor is within range
|
||||
fn autoscroll (&self) {
|
||||
let note_lo = self.note_lo();
|
||||
|
|
@ -20,7 +20,7 @@ pub trait MIDIViewport<E: Engine>: MIDIRange + MIDIPoint + HasSize<E> {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MIDIRangeModel {
|
||||
pub struct MidiRangeModel {
|
||||
/// Length of visible time axis
|
||||
pub time_axis: Arc<AtomicUsize>,
|
||||
/// Earliest time displayed
|
||||
|
|
@ -34,7 +34,7 @@ pub struct MIDIRangeModel {
|
|||
// Lowest note displayed
|
||||
pub note_lo: Arc<AtomicUsize>,
|
||||
}
|
||||
impl From<(usize, bool)> for MIDIRangeModel {
|
||||
impl From<(usize, bool)> for MidiRangeModel {
|
||||
fn from ((time_zoom, time_lock): (usize, bool)) -> Self {
|
||||
Self {
|
||||
note_axis: Arc::new(0.into()),
|
||||
|
|
@ -46,7 +46,7 @@ impl From<(usize, bool)> for MIDIRangeModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub trait MIDIRange {
|
||||
pub trait MidiRange {
|
||||
fn time_zoom (&self) -> usize;
|
||||
fn set_time_zoom (&self, x: usize);
|
||||
fn time_lock (&self) -> bool;
|
||||
|
|
@ -58,7 +58,7 @@ pub trait MIDIRange {
|
|||
fn note_axis (&self) -> usize;
|
||||
fn note_hi (&self) -> usize { self.note_lo() + self.note_axis() }
|
||||
}
|
||||
impl MIDIRange for MIDIRangeModel {
|
||||
impl MidiRange for MidiRangeModel {
|
||||
fn time_zoom (&self) -> usize { self.time_zoom.load(Relaxed) }
|
||||
fn set_time_zoom (&self, x: usize) { self.time_zoom.store(x, Relaxed); }
|
||||
fn time_lock (&self) -> bool { self.time_lock.load(Relaxed) }
|
||||
|
|
@ -71,7 +71,7 @@ impl MIDIRange for MIDIRangeModel {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MIDIPointModel {
|
||||
pub struct MidiPointModel {
|
||||
/// Time coordinate of cursor
|
||||
pub time_point: Arc<AtomicUsize>,
|
||||
/// Note coordinate of cursor
|
||||
|
|
@ -79,7 +79,7 @@ pub struct MIDIPointModel {
|
|||
/// Length of note that will be inserted, in pulses
|
||||
pub note_len: Arc<AtomicUsize>,
|
||||
}
|
||||
impl Default for MIDIPointModel {
|
||||
impl Default for MidiPointModel {
|
||||
fn default () -> Self {
|
||||
Self {
|
||||
time_point: Arc::new(0.into()),
|
||||
|
|
@ -88,7 +88,7 @@ impl Default for MIDIPointModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub trait MIDIPoint {
|
||||
pub trait MidiPoint {
|
||||
fn note_len (&self) -> usize;
|
||||
fn set_note_len (&self, x: usize);
|
||||
fn note_point (&self) -> usize;
|
||||
|
|
@ -97,7 +97,7 @@ pub trait MIDIPoint {
|
|||
fn set_time_point (&self, x: usize);
|
||||
fn note_end (&self) -> usize { self.note_point() + self.note_len() }
|
||||
}
|
||||
impl MIDIPoint for MIDIPointModel {
|
||||
impl MidiPoint 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) }
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ impl Default for PhraseEditorModel {
|
|||
|
||||
render!(|self: PhraseEditorModel|self.mode);
|
||||
|
||||
pub trait PhraseViewMode: Render<Tui> + HasSize<Tui> + MIDIRange + MIDIPoint + Debug + Send + Sync {
|
||||
pub trait PhraseViewMode: Render<Tui> + HasSize<Tui> + MidiRange + MidiPoint + Debug + Send + Sync {
|
||||
fn buffer_size (&self, phrase: &Phrase) -> (usize, usize);
|
||||
fn redraw (&mut self);
|
||||
fn phrase (&self) -> &Option<Arc<RwLock<Phrase>>>;
|
||||
|
|
@ -128,11 +128,11 @@ pub trait PhraseViewMode: Render<Tui> + HasSize<Tui> + MIDIRange + MIDIPoint + D
|
|||
}
|
||||
}
|
||||
|
||||
impl MIDIViewport<Tui> for PhraseEditorModel {}
|
||||
impl MidiViewport<Tui> for PhraseEditorModel {}
|
||||
|
||||
has_size!(<Tui>|self:PhraseEditorModel|self.mode.size());
|
||||
|
||||
impl MIDIRange for PhraseEditorModel {
|
||||
impl MidiRange for PhraseEditorModel {
|
||||
fn time_zoom (&self) -> usize { self.mode.time_zoom() }
|
||||
fn set_time_zoom (&self, x: usize) { self.mode.set_time_zoom(x); }
|
||||
fn time_lock (&self) -> bool { self.mode.time_lock() }
|
||||
|
|
@ -144,7 +144,7 @@ impl MIDIRange for PhraseEditorModel {
|
|||
fn note_axis (&self) -> usize { self.mode.note_lo() }
|
||||
fn note_hi (&self) -> usize { self.note_lo() + self.note_axis() }
|
||||
}
|
||||
impl MIDIPoint for PhraseEditorModel {
|
||||
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) }
|
||||
fn note_point (&self) -> usize { self.mode.note_point() }
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ pub struct PianoHorizontal {
|
|||
/// Width and height of notes area at last render
|
||||
size: Measure<Tui>,
|
||||
/// The display window
|
||||
range: MIDIRangeModel,
|
||||
range: MidiRangeModel,
|
||||
/// The note cursor
|
||||
point: MIDIPointModel,
|
||||
point: MidiPointModel,
|
||||
/// The highlight color palette
|
||||
color: ItemPalette,
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ pub struct PianoHorizontal {
|
|||
impl PianoHorizontal {
|
||||
pub fn new (phrase: Option<&Arc<RwLock<Phrase>>>) -> Self {
|
||||
let size = Measure::new();
|
||||
let mut range = MIDIRangeModel::from((24, true));
|
||||
let mut range = MidiRangeModel::from((24, true));
|
||||
range.time_axis = size.x.clone();
|
||||
range.note_axis = size.y.clone();
|
||||
let phrase = phrase.map(|p|p.clone());
|
||||
|
|
@ -28,7 +28,7 @@ impl PianoHorizontal {
|
|||
.unwrap_or(ItemPalette::from(ItemColor::from(TuiTheme::g(64))));
|
||||
Self {
|
||||
buffer: Default::default(),
|
||||
point: MIDIPointModel::default(),
|
||||
point: MidiPointModel::default(),
|
||||
size,
|
||||
range,
|
||||
phrase,
|
||||
|
|
@ -243,7 +243,7 @@ impl PianoHorizontal {
|
|||
|
||||
has_size!(<Tui>|self:PianoHorizontal|&self.size);
|
||||
|
||||
impl MIDIRange for PianoHorizontal {
|
||||
impl MidiRange for PianoHorizontal {
|
||||
fn time_zoom (&self) -> usize { self.range.time_zoom() }
|
||||
fn set_time_zoom (&self, x: usize) { self.range.set_time_zoom(x); }
|
||||
fn time_lock (&self) -> bool { self.range.time_lock() }
|
||||
|
|
@ -255,7 +255,7 @@ impl MIDIRange for PianoHorizontal {
|
|||
fn note_axis (&self) -> usize { self.range.note_lo() }
|
||||
fn note_hi (&self) -> usize { self.note_lo() + self.note_axis() }
|
||||
}
|
||||
impl MIDIPoint for PianoHorizontal {
|
||||
impl MidiPoint for PianoHorizontal {
|
||||
fn note_len (&self) -> usize { self.point.note_len()}
|
||||
fn set_note_len (&self, x: usize) { self.point.set_note_len(x) }
|
||||
fn note_point (&self) -> usize { self.point.note_point() }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue