mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
move started field onto TransportTime
This commit is contained in:
parent
4df15d6bac
commit
3ee9a670da
4 changed files with 40 additions and 48 deletions
|
|
@ -59,13 +59,21 @@ macro_rules! time_unit {
|
|||
time_unit!(SampleRate);
|
||||
impl SampleRate {
|
||||
/// Return the duration of a sample in microseconds (floating)
|
||||
#[inline] pub fn usec_per_sample (&self) -> f64 { 1_000_000f64 / self.get() }
|
||||
#[inline] pub fn usec_per_sample (&self) -> f64 {
|
||||
1_000_000f64 / self.get()
|
||||
}
|
||||
/// Return the duration of a sample in microseconds (floating)
|
||||
#[inline] pub fn sample_per_usec (&self) -> f64 { self.get() / 1_000_000f64 }
|
||||
#[inline] pub fn sample_per_usec (&self) -> f64 {
|
||||
self.get() / 1_000_000f64
|
||||
}
|
||||
/// Convert a number of samples to microseconds (floating)
|
||||
#[inline] pub fn samples_to_usec (&self, samples: f64) -> f64 { samples * self.usec_per_sample() }
|
||||
#[inline] pub fn samples_to_usec (&self, samples: f64) -> f64 {
|
||||
self.usec_per_sample() * samples
|
||||
}
|
||||
/// Convert a number of microseconds to samples (floating)
|
||||
#[inline] pub fn usecs_to_sample (&self, usecs: f64) -> f64 { usecs * self.sample_per_usec() }
|
||||
#[inline] pub fn usecs_to_sample (&self, usecs: f64) -> f64 {
|
||||
self.sample_per_usec() * usecs
|
||||
}
|
||||
}
|
||||
|
||||
time_unit!(BeatsPerMinute);
|
||||
|
|
@ -256,28 +264,6 @@ impl Instant {
|
|||
self.timebase.format_beats_1(self.pulse.get())
|
||||
}
|
||||
}
|
||||
/// A timer with starting point, current time, and quantization
|
||||
pub struct Timer {
|
||||
pub timebase: Arc<Timebase>,
|
||||
/// Starting point in global time
|
||||
pub started: Option<Instant>,
|
||||
/// Current moment in global time
|
||||
pub current: Instant,
|
||||
/// Note quantization factor
|
||||
pub quant: Quantize,
|
||||
/// Launch quantization factor
|
||||
pub sync: LaunchSync,
|
||||
/// Playback state
|
||||
pub playing: RwLock<Option<jack::TransportState>>,
|
||||
}
|
||||
/// Something that defines launch quantization
|
||||
impl Timer {
|
||||
#[inline] pub fn next_launch_pulse (&self) -> usize {
|
||||
let sync = self.sync.get() as usize;
|
||||
let pulse = self.current.pulse.get() as usize;
|
||||
if pulse % sync == 0 { pulse } else { (pulse / sync + 1) * sync }
|
||||
}
|
||||
}
|
||||
/// Iterator that emits subsequent ticks within a range.
|
||||
pub struct TicksIterator {
|
||||
spp: f64,
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue