mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
use def_command
This commit is contained in:
parent
5ccbb9719f
commit
cfd19062fd
37 changed files with 1578 additions and 1594 deletions
|
|
@ -14,48 +14,33 @@ impl Clock {
|
|||
}
|
||||
|
||||
impl<T: HasClock> Command<T> for ClockCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
fn execute (&self, state: &mut T) -> Perhaps<Self> {
|
||||
self.execute(state.clock_mut()) // awesome
|
||||
}
|
||||
}
|
||||
|
||||
#[tengri_proc::command(Clock)]
|
||||
impl ClockCommand {
|
||||
fn play (state: &mut Clock, position: Option<u32>) -> Perhaps<Self> {
|
||||
state.play_from(position)?;
|
||||
Ok(None) // TODO Some(Pause(previousPosition))
|
||||
}
|
||||
fn pause (state: &mut Clock, position: Option<u32>) -> Perhaps<Self> {
|
||||
state.pause_at(position)?;
|
||||
Ok(None)
|
||||
}
|
||||
fn toggle_playback (state: &mut Clock, position: u32) -> Perhaps<Self> {
|
||||
if state.is_rolling() {
|
||||
state.pause_at(Some(position))?;
|
||||
} else {
|
||||
state.play_from(Some(position))?;
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
fn seek_usec (state: &mut Clock, usec: f64) -> Perhaps<Self> {
|
||||
state.playhead.update_from_usec(usec);
|
||||
Ok(None)
|
||||
}
|
||||
fn seek_sample (state: &mut Clock, sample: f64) -> Perhaps<Self> {
|
||||
state.playhead.update_from_sample(sample);
|
||||
Ok(None)
|
||||
}
|
||||
fn seek_pulse (state: &mut Clock, pulse: f64) -> Perhaps<Self> {
|
||||
state.playhead.update_from_pulse(pulse);
|
||||
Ok(None)
|
||||
}
|
||||
fn set_bpm (state: &mut Clock, bpm: f64) -> Perhaps<Self> {
|
||||
Ok(Some(Self::SetBpm { bpm: state.timebase().bpm.set(bpm) }))
|
||||
}
|
||||
fn set_quant (state: &mut Clock, quant: f64) -> Perhaps<Self> {
|
||||
Ok(Some(Self::SetQuant { quant: state.quant.set(quant) }))
|
||||
}
|
||||
fn set_sync (state: &mut Clock, sync: f64) -> Perhaps<Self> {
|
||||
Ok(Some(Self::SetSync { sync: state.sync.set(sync) }))
|
||||
}
|
||||
}
|
||||
def_command!(ClockCommand: |clock: Clock| {
|
||||
SeekUsec { usec: f64 } => {
|
||||
clock.playhead.update_from_usec(*usec); Ok(None) },
|
||||
SeekSample { sample: f64 } => {
|
||||
clock.playhead.update_from_sample(*sample); Ok(None) },
|
||||
SeekPulse { pulse: f64 } => {
|
||||
clock.playhead.update_from_pulse(*pulse); Ok(None) },
|
||||
SetBpm { bpm: f64 } => Ok(Some(
|
||||
Self::SetBpm { bpm: clock.timebase().bpm.set(*bpm) })),
|
||||
SetQuant { quant: f64 } => Ok(Some(
|
||||
Self::SetQuant { quant: clock.quant.set(*quant) })),
|
||||
SetSync { sync: f64 } => Ok(Some(
|
||||
Self::SetSync { sync: clock.sync.set(*sync) })),
|
||||
|
||||
Play { position: Option<u32> } => {
|
||||
clock.play_from(*position)?; Ok(None) /* TODO Some(Pause(previousPosition)) */ },
|
||||
Pause { position: Option<u32> } => {
|
||||
clock.pause_at(*position)?; Ok(None) },
|
||||
|
||||
TogglePlayback { position: u32 } => Ok(if clock.is_rolling() {
|
||||
clock.pause_at(Some(*position))?; None
|
||||
} else {
|
||||
clock.play_from(Some(*position))?; None
|
||||
}),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue