tek/crates/tek_snd/src/snd_transport.rs

46 lines
1.6 KiB
Rust

use crate::*;
pub struct TransportAudio(pub Arc<RwLock<Transport>>);
impl Audio for TransportAudio {
fn process (&mut self, client: &Client, scope: &ProcessScope) -> Control {
TransportRefAudio(
&mut*self.0.write().unwrap()
).process(client, scope)
}
}
pub struct TransportRefAudio<'a>(pub &'a mut Transport);
impl<'a> Audio for TransportRefAudio<'a> {
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
let ref state = self.0;
let times = scope.cycle_times().unwrap();
let CycleTimes { current_frames, current_usecs, next_usecs: _, period_usecs: _ } = times;
let _chunk_size = scope.n_frames() as usize;
let transport = state.transport.query().unwrap();
state.clock.current.sample.set(transport.pos.frame() as f64);
let mut playing = state.clock.playing.write().unwrap();
let mut started = state.clock.started.write().unwrap();
if *playing != Some(transport.state) {
match transport.state {
TransportState::Rolling => {
*started = Some((current_frames as usize, current_usecs as usize))
},
TransportState::Stopped => {
*started = None
},
_ => {}
}
};
*playing = Some(transport.state);
if *playing == Some(TransportState::Stopped) {
*started = None;
}
state.clock.current.update_from_usec(match *started {
Some((_, usecs)) => current_usecs as f64 - usecs as f64,
None => 0.
});
Control::Continue
}
}