mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-11 14:16:42 +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
72
crates/tek_api/src/api_playhead.rs
Normal file
72
crates/tek_api/src/api_playhead.rs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum PlayheadCommand {
|
||||
Play(Option<usize>),
|
||||
Pause(Option<usize>),
|
||||
SeekUsec(f64),
|
||||
SeekSample(f64),
|
||||
SeekPulse(f64),
|
||||
}
|
||||
|
||||
impl<T: PlayheadApi> Command<T> for PlayheadCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PlayheadCommand::*;
|
||||
match self {
|
||||
Play(_start) => {
|
||||
todo!()
|
||||
},
|
||||
Pause(_start) => {
|
||||
todo!()
|
||||
},
|
||||
SeekUsec(usec) => {
|
||||
state.current().update_from_usec(usec);
|
||||
},
|
||||
SeekSample(sample) => {
|
||||
state.current().update_from_sample(sample);
|
||||
},
|
||||
SeekPulse(pulse) => {
|
||||
state.current().update_from_pulse(pulse);
|
||||
},
|
||||
};
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PlayheadApi: ClockApi {
|
||||
|
||||
fn playing (&self) -> &Arc<RwLock<TransportState>>;
|
||||
|
||||
fn transport (&self) -> Transport;
|
||||
|
||||
fn pulse (&self) -> f64 {
|
||||
self.current().pulse.get()
|
||||
}
|
||||
fn next_launch_pulse (&self) -> usize {
|
||||
let sync = self.sync().get() as usize;
|
||||
let pulse = self.pulse() as usize;
|
||||
if pulse % sync == 0 { pulse } else { (pulse / sync + 1) * sync }
|
||||
}
|
||||
fn toggle_play (&self) -> Usually<()> {
|
||||
let playing = self.playing().read().unwrap().expect("1st sample has not been processed yet");
|
||||
let playing = match playing {
|
||||
TransportState::Stopped => {
|
||||
self.transport().start()?;
|
||||
Some(TransportState::Starting)
|
||||
},
|
||||
_ => {
|
||||
self.transport().stop()?;
|
||||
self.transport().locate(0)?;
|
||||
Some(TransportState::Stopped)
|
||||
},
|
||||
};
|
||||
*self.playing().write().unwrap() = playing;
|
||||
Ok(())
|
||||
}
|
||||
fn is_stopped (&self) -> bool {
|
||||
*self.playing().read().unwrap() == Some(TransportState::Stopped)
|
||||
}
|
||||
fn is_rolling (&self) -> bool {
|
||||
*self.clock.playing.read().unwrap() == Some(TransportState::Rolling)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue