mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
wip: update all command definitions to use proc macro
This commit is contained in:
parent
a8be2e9dad
commit
ee7f9dcf12
3 changed files with 455 additions and 436 deletions
|
|
@ -1,55 +1,52 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ClockCommand {
|
||||
Play(Option<u32>),
|
||||
Pause(Option<u32>),
|
||||
SeekUsec(f64),
|
||||
SeekSample(f64),
|
||||
SeekPulse(f64),
|
||||
SetBpm(f64),
|
||||
SetQuant(f64),
|
||||
SetSync(f64),
|
||||
}
|
||||
|
||||
provide_num!(u32: |self: Clock| {});
|
||||
|
||||
provide!(Option<u32>: |self: Clock| {});
|
||||
provide!(f64: |self: Clock| {});
|
||||
|
||||
atom_command!(ClockCommand: |state: Clock| {
|
||||
("play" [] Some(Self::Play(None)))
|
||||
("play" [t: u32] Some(Self::Play(t)))
|
||||
("pause" [] Some(Self::Pause(None)))
|
||||
("pause" [t: u32] Some(Self::Pause(t)))
|
||||
("toggle" [] Some(if state.is_rolling() { Self::Pause(None) } else { Self::Play(None) }))
|
||||
("toggle" [t: u32] Some(if state.is_rolling() { Self::Pause(t) } else { Self::Play(t) }))
|
||||
("seek/usec" [t: f64] Some(Self::SeekUsec(t.expect("no usec"))))
|
||||
("seek/pulse" [t: f64] Some(Self::SeekPulse(t.expect("no pulse"))))
|
||||
("seek/sample" [t: f64] Some(Self::SeekSample(t.expect("no sample"))))
|
||||
("set/bpm" [t: f64] Some(Self::SetBpm(t.expect("no bpm"))))
|
||||
("set/sync" [t: f64] Some(Self::SetSync(t.expect("no sync"))))
|
||||
("set/quant" [t: f64] Some(Self::SetQuant(t.expect("no quant"))))
|
||||
});
|
||||
|
||||
impl<T: HasClock> Command<T> for ClockCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
self.execute(state.clock_mut())
|
||||
self.execute(state.clock_mut()) // awesome
|
||||
}
|
||||
}
|
||||
|
||||
impl Command<Clock> for ClockCommand {
|
||||
fn execute (self, state: &mut Clock) -> Perhaps<Self> {
|
||||
use ClockCommand::*;
|
||||
match self {
|
||||
Play(start) => state.play_from(start)?,
|
||||
Pause(pause) => state.pause_at(pause)?,
|
||||
SeekUsec(usec) => state.playhead.update_from_usec(usec),
|
||||
SeekSample(sample) => state.playhead.update_from_sample(sample),
|
||||
SeekPulse(pulse) => state.playhead.update_from_pulse(pulse),
|
||||
SetBpm(bpm) => return Ok(Some(SetBpm(state.timebase().bpm.set(bpm)))),
|
||||
SetQuant(quant) => return Ok(Some(SetQuant(state.quant.set(quant)))),
|
||||
SetSync(sync) => return Ok(Some(SetSync(state.sync.set(sync)))),
|
||||
};
|
||||
#[tengri_proc::command(Clock)]
|
||||
impl ClockCommand {
|
||||
fn play (self, state: &mut Clock, position: Option<u32>) -> Perhaps<Self> {
|
||||
state.play_from(position)?;
|
||||
Ok(None) // TODO Some(Pause(previousPosition))
|
||||
}
|
||||
fn pause (self, state: &mut Clock, position: Option<u32>) -> Perhaps<Self> {
|
||||
state.pause_at(position)?;
|
||||
Ok(None)
|
||||
}
|
||||
fn toggle_playback (self, state: &mut Clock, position: Option<u32>) -> Perhaps<Self> {
|
||||
if state.is_rolling() {
|
||||
state.pause_at(position)?;
|
||||
} else {
|
||||
state.play_from(position)?;
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
fn seek_usec (self, state: &mut Clock, usec: f64) -> Perhaps<Self> {
|
||||
state.playhead.update_from_usec(usec);
|
||||
Ok(None)
|
||||
}
|
||||
fn seek_sample (self, state: &mut Clock, sample: f64) -> Perhaps<Self> {
|
||||
state.playhead.update_from_sample(sample);
|
||||
Ok(None)
|
||||
}
|
||||
fn seek_pulse (self, state: &mut Clock, pulse: f64) -> Perhaps<Self> {
|
||||
state.playhead.update_from_pulse(pulse);
|
||||
Ok(None)
|
||||
}
|
||||
fn set_bpm (self, state: &mut Clock, bpm: f64) -> Perhaps<Self> {
|
||||
Ok(Some(Self::SetBpm { bpm: state.timebase().bpm.set(bpm) }))
|
||||
}
|
||||
fn set_quant (self, state: &mut Clock, quant: f64) -> Perhaps<Self> {
|
||||
Ok(Some(Self::SetQuant { quant: state.quant.set(quant) }))
|
||||
}
|
||||
fn set_sync (self, state: &mut Clock, sync: f64) -> Perhaps<Self> {
|
||||
Ok(Some(Self::SetSync { sync: state.sync.set(sync) }))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue