FocusCommand, Command::translate, ret old from TimeUnit::set

This commit is contained in:
🪞👃🪞 2024-11-08 22:53:08 +01:00
parent 2b78339e61
commit fe25da4f53
9 changed files with 249 additions and 261 deletions

View file

@ -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>;

View file

@ -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);

View file

@ -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});