mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
This commit is contained in:
parent
2c3bfe4ebb
commit
ef81b085a0
106 changed files with 6866 additions and 7106 deletions
79
engine/note/note_point.rs
Normal file
79
engine/note/note_point.rs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MidiPointModel {
|
||||
/// Time coordinate of cursor
|
||||
pub time_pos: Arc<AtomicUsize>,
|
||||
/// Note coordinate of cursor
|
||||
pub note_pos: Arc<AtomicUsize>,
|
||||
/// Length of note that will be inserted, in pulses
|
||||
pub note_len: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl Default for MidiPointModel {
|
||||
fn default () -> Self {
|
||||
Self {
|
||||
time_pos: Arc::new(0.into()),
|
||||
note_pos: Arc::new(36.into()),
|
||||
note_len: Arc::new(24.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NotePoint for MidiPointModel {
|
||||
fn note_len (&self) -> &AtomicUsize {
|
||||
&self.note_len
|
||||
}
|
||||
fn note_pos (&self) -> &AtomicUsize {
|
||||
&self.note_pos
|
||||
}
|
||||
}
|
||||
|
||||
impl TimePoint for MidiPointModel {
|
||||
fn time_pos (&self) -> &AtomicUsize {
|
||||
self.time_pos.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NotePoint {
|
||||
fn note_len (&self) -> &AtomicUsize;
|
||||
/// Get the current length of the note cursor.
|
||||
fn get_note_len (&self) -> usize {
|
||||
self.note_len().load(Relaxed)
|
||||
}
|
||||
/// Set the length of the note cursor, returning the previous value.
|
||||
fn set_note_len (&self, x: usize) -> usize {
|
||||
self.note_len().swap(x, Relaxed)
|
||||
}
|
||||
|
||||
fn note_pos (&self) -> &AtomicUsize;
|
||||
/// Get the current pitch of the note cursor.
|
||||
fn get_note_pos (&self) -> usize {
|
||||
self.note_pos().load(Relaxed).min(127)
|
||||
}
|
||||
/// Set the current pitch fo the note cursor, returning the previous value.
|
||||
fn set_note_pos (&self, x: usize) -> usize {
|
||||
self.note_pos().swap(x.min(127), Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TimePoint {
|
||||
fn time_pos (&self) -> &AtomicUsize;
|
||||
/// Get the current time position of the note cursor.
|
||||
fn get_time_pos (&self) -> usize {
|
||||
self.time_pos().load(Relaxed)
|
||||
}
|
||||
/// Set the current time position of the note cursor, returning the previous value.
|
||||
fn set_time_pos (&self, x: usize) -> usize {
|
||||
self.time_pos().swap(x, Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MidiPoint: NotePoint + TimePoint {
|
||||
/// Get the current end of the note cursor.
|
||||
fn get_note_end (&self) -> usize {
|
||||
self.get_time_pos() + self.get_note_len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: NotePoint + TimePoint> MidiPoint for T {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue