wip: unify apps

This commit is contained in:
🪞👃🪞 2025-01-11 20:16:46 +01:00
parent a9cad18891
commit cff87657b9
12 changed files with 291 additions and 247 deletions

View file

@ -72,10 +72,10 @@ impl<T: HasClock> Command<T> for ClockCommand {
}
}
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct Clock {
/// JACK transport handle.
pub transport: Arc<Transport>,
pub transport: Arc<Option<Transport>>,
/// Global temporal resolution (shared by [Moment] fields)
pub timebase: Arc<Timebase>,
/// Current global sample and usec (monotonic from JACK clock)
@ -102,7 +102,7 @@ from!(|jack: &Arc<RwLock<JackConnection>>| Clock = {
Self {
quant: Arc::new(24.into()),
sync: Arc::new(384.into()),
transport: Arc::new(transport),
transport: Arc::new(Some(transport)),
chunk: Arc::new((chunk as usize).into()),
global: Arc::new(Moment::zero(&timebase)),
playhead: Arc::new(Moment::zero(&timebase)),
@ -154,17 +154,21 @@ impl Clock {
}
/// Start playing, optionally seeking to a given location beforehand
pub fn play_from (&self, start: Option<u32>) -> Usually<()> {
if let Some(start) = start {
self.transport.locate(start)?;
if let Some(transport) = self.transport.as_ref() {
if let Some(start) = start {
transport.locate(start)?;
}
transport.start()?;
}
self.transport.start()?;
Ok(())
}
/// Pause, optionally seeking to a given location afterwards
pub fn pause_at (&self, pause: Option<u32>) -> Usually<()> {
self.transport.stop()?;
if let Some(pause) = pause {
self.transport.locate(pause)?;
if let Some(transport) = self.transport.as_ref() {
transport.stop()?;
if let Some(pause) = pause {
transport.locate(pause)?;
}
}
Ok(())
}
@ -189,21 +193,24 @@ impl Clock {
self.global.sample.set(current_frames as f64);
self.global.usec.set(current_usecs as f64);
let mut started = self.started.write().unwrap();
// If transport has just started or just stopped,
// update starting point:
let mut started = self.started.write().unwrap();
match (self.transport.query_state()?, started.as_ref()) {
(TransportState::Rolling, None) => {
let moment = Moment::zero(&self.timebase);
moment.sample.set(current_frames as f64);
moment.usec.set(current_usecs as f64);
*started = Some(moment);
},
(TransportState::Stopped, Some(_)) => {
*started = None;
},
_ => {}
};
if let Some(transport) = self.transport.as_ref() {
match (transport.query_state()?, started.as_ref()) {
(TransportState::Rolling, None) => {
let moment = Moment::zero(&self.timebase);
moment.sample.set(current_frames as f64);
moment.usec.set(current_usecs as f64);
*started = Some(moment);
},
(TransportState::Stopped, Some(_)) => {
*started = None;
},
_ => {}
};
}
self.playhead.update_from_sample(started.as_ref()
.map(|started|current_frames as f64 - started.sample.get())