move started field onto TransportTime

This commit is contained in:
🪞👃🪞 2024-11-02 01:17:02 +02:00
parent 4df15d6bac
commit 3ee9a670da
4 changed files with 40 additions and 48 deletions

View file

@ -1,11 +1,11 @@
use crate::*;
use std::cmp::PartialEq;
/// MIDI message structural
pub type PhraseData = Vec<Vec<MidiMessage>>;
pub type PhraseData = Vec<Vec<MidiMessage>>;
/// MIDI message serialized
pub type PhraseMessage = Vec<u8>;
/// Collection of serialized MIDI messages
pub type PhraseChunk = [Vec<PhraseMessage>];
pub type PhraseChunk = [Vec<PhraseMessage>];
/// Root level object for standalone `tek_sequencer`
pub struct Sequencer<E: Engine> {
/// JACK client handle (needs to not be dropped for standalone mode to work).

View file

@ -1,14 +1,16 @@
use crate::*;
#[derive(Debug, Default)]
pub struct TransportTime {
/// A timer with starting point, current time, and quantization
#[derive(Debug, Default)] pub struct TransportTime {
/// Playback state
pub playing: RwLock<Option<TransportState>>,
/// Global sample and usec at which playback started
pub started: RwLock<Option<(usize, usize)>>,
/// Current moment in time
pub current: Instant,
/// Note quantization factor
pub quant: Quantize,
/// Launch quantization factor
pub sync: LaunchSync,
/// Playback state
pub playing: RwLock<Option<TransportState>>,
}
impl TransportTime {
#[inline] pub fn timebase (&self) -> &Arc<Timebase> { &self.current.timebase }
@ -32,8 +34,6 @@ pub struct TransportToolbar<E: Engine> {
pub jack: Option<Arc<JackClient>>,
/// JACK transport handle.
pub transport: Option<Transport>,
/// Global sample and usec at which playback started
pub started: Option<(usize, usize)>,
/// Whether the toolbar is focused
pub focused: bool,
/// Which part of the toolbar is focused
@ -52,7 +52,6 @@ impl<E: Engine> TransportToolbar<E> {
focused: false,
focus: TransportToolbarFocus::PlayPause,
metronome: false,
started: None,
jack: None,
transport,
clock: match clock {
@ -60,10 +59,11 @@ impl<E: Engine> TransportToolbar<E> {
None => {
let timebase = Arc::new(Timebase::default());
Arc::new(TransportTime {
playing: Some(TransportState::Stopped).into(),
quant: 24.into(),
sync: (timebase.ppq.get() * 4.).into(),
current: Instant::default(),
playing: Some(TransportState::Stopped).into(),
quant: 24.into(),
sync: (timebase.ppq.get() * 4.).into(),
current: Instant::default(),
started: None.into(),
})
}
}

View file

@ -6,18 +6,24 @@ impl<E: Engine> Audio for TransportToolbar<E> {
let _chunk_size = scope.n_frames() as usize;
let transport = self.transport.as_ref().unwrap().query().unwrap();
self.clock.current.sample.set(transport.pos.frame() as f64);
if *self.clock.playing.read().unwrap() != Some(transport.state) {
self.started = match transport.state {
TransportState::Rolling => Some((current_frames as usize, current_usecs as usize)),
TransportState::Stopped => None,
_ => self.started
let mut playing = self.clock.playing.write().unwrap();
let mut started = self.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
},
_ => {}
}
};
*self.clock.playing.write().unwrap() = Some(transport.state);
if *self.clock.playing.read().unwrap() == Some(TransportState::Stopped) {
self.started = None;
*playing = Some(transport.state);
if *playing == Some(TransportState::Stopped) {
*started = None;
}
self.clock.current.update_from_usec(match self.started {
self.clock.current.update_from_usec(match *started {
Some((_, usecs)) => current_usecs as f64 - usecs as f64,
None => 0.
});