mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
wip: refactor pt.32: 89 errors, traits
This commit is contained in:
parent
8b5931c321
commit
ce78b95d8a
28 changed files with 946 additions and 822 deletions
56
crates/tek_api/src/api_clock.rs
Normal file
56
crates/tek_api/src/api_clock.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ClockCommand {
|
||||
SetBpm(f64),
|
||||
SetQuant(f64),
|
||||
SetSync(f64),
|
||||
}
|
||||
|
||||
impl<T: ClockApi> Command<T> for ClockCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use ClockCommand::*;
|
||||
Ok(Some(match self {
|
||||
SetBpm(bpm) => SetBpm(state.timebase().bpm.set(bpm)),
|
||||
SetQuant(quant) => SetQuant(state.quant().set(quant)),
|
||||
SetSync(sync) => SetSync(state.sync().set(sync)),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ClockApi {
|
||||
fn quant (&self) -> &Quantize;
|
||||
|
||||
fn sync (&self) -> &LaunchSync;
|
||||
|
||||
fn current (&self) -> &Instant;
|
||||
|
||||
fn timebase (&self) -> &Timebase {
|
||||
&self.current().timebase
|
||||
}
|
||||
fn sr (&self) -> &SampleRate {
|
||||
&self.timebase().sr
|
||||
}
|
||||
fn bpm (&self) -> &BeatsPerMinute {
|
||||
&self.timebase().bpm
|
||||
}
|
||||
fn ppq (&self) -> &PulsesPerQuaver {
|
||||
&self.timebase().ppq
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasClock {
|
||||
fn clock (&self) -> &impl ClockApi;
|
||||
}
|
||||
|
||||
impl<T: HasClock> ClockApi for T {
|
||||
fn quant (&self) -> &Quantize {
|
||||
self.clock().quant()
|
||||
}
|
||||
fn sync (&self) -> &LaunchSync {
|
||||
self.clock().sync()
|
||||
}
|
||||
fn current (&self) -> &Instant {
|
||||
self.clock().current()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue