mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
FocusCommand, Command::translate, ret old from TimeUnit::set
This commit is contained in:
parent
2b78339e61
commit
fe25da4f53
9 changed files with 249 additions and 261 deletions
|
|
@ -1,7 +1,8 @@
|
|||
use crate::*;
|
||||
|
||||
pub trait Command<S>: Sized {
|
||||
fn run (&self, state: &mut S) -> Perhaps<Self>;
|
||||
fn translate (self, _: &S) -> Self { self }
|
||||
fn execute (self, state: &mut S) -> Perhaps<Self>;
|
||||
}
|
||||
pub trait MatchInput<E: Engine, S>: Sized {
|
||||
fn match_input (state: &S, input: &E::Input) -> Option<Self>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,15 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum FocusCommand {
|
||||
Next,
|
||||
Prev,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
pub trait FocusGrid<T: Copy + PartialEq> {
|
||||
fn layout (&self) -> &[&[T]];
|
||||
fn cursor (&self) -> (usize, usize);
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@ pub const PPQ: usize = 96;
|
|||
/// This should mean that, even at 192kHz sampling rate, over 1 year of audio
|
||||
/// can be clocked in microseconds with f64 without losing precision.
|
||||
pub trait TimeUnit {
|
||||
fn get (&self) -> f64;// { self.0.load(Ordering::Relaxed) }
|
||||
fn set (&self, value: f64);// { self.0.store(value, Ordering::Relaxed) }
|
||||
/// Returns current value
|
||||
fn get (&self) -> f64;
|
||||
/// Sets new value, returns old
|
||||
fn set (&self, value: f64) -> f64;
|
||||
}
|
||||
/// Implement arithmetic for a unit of time
|
||||
macro_rules! impl_op {
|
||||
|
|
@ -40,7 +42,11 @@ macro_rules! impl_time_unit {
|
|||
($T:ident) => {
|
||||
impl TimeUnit for $T {
|
||||
fn get (&self) -> f64 { self.0.load(Ordering::Relaxed) }
|
||||
fn set (&self, value: f64) { self.0.store(value, Ordering::Relaxed) }
|
||||
fn set (&self, value: f64) -> f64 {
|
||||
let old = self.get();
|
||||
self.0.store(value, Ordering::Relaxed);
|
||||
old
|
||||
}
|
||||
}
|
||||
impl_op!($T, Add, add, |a, b|{a + b});
|
||||
impl_op!($T, Sub, sub, |a, b|{a - b});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue