mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
group sample/pulse/usecs into Instant
This commit is contained in:
parent
205dbef9b0
commit
fec6294c7b
4 changed files with 43 additions and 20 deletions
|
|
@ -181,13 +181,13 @@ pub trait Quantize<T> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Keeps track of global time units.
|
||||
/// Defines global temporal resolutions.
|
||||
pub struct Timebase {
|
||||
/// Samples per second
|
||||
/// Audio samples per second
|
||||
pub sr: AtomicF64,
|
||||
/// Beats per minute
|
||||
/// MIDI beats per minute
|
||||
pub bpm: AtomicF64,
|
||||
/// Ticks per beat
|
||||
/// MIDI ticks per beat
|
||||
pub ppq: AtomicF64,
|
||||
}
|
||||
impl Default for Timebase { fn default () -> Self { Self::new(48000f64, 150f64, 96f64) } }
|
||||
|
|
@ -210,6 +210,33 @@ impl PulsesPerQuaver<f64> for Timebase {
|
|||
#[inline] fn set_ppq (&self, ppq: f64) { self.ppq.store(ppq, Ordering::Relaxed); }
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
/// Represents a point in time in all scales
|
||||
pub struct Instant {
|
||||
/// Current time in microseconds
|
||||
pub usec: AtomicUsize,
|
||||
/// Current time in audio samples
|
||||
pub sample: AtomicUsize,
|
||||
/// Current time in MIDI pulses
|
||||
pub pulse: AtomicF64,
|
||||
}
|
||||
impl FramePosition<usize> for Instant {
|
||||
#[inline] fn sample (&self) -> usize { self.sample.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_sample (&self, sample: usize) { self.sample.store(sample, Ordering::Relaxed); }
|
||||
}
|
||||
impl UsecPosition<usize> for Instant {
|
||||
#[inline] fn usec (&self) -> usize { self.usec.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_usec (&self, usec: usize) { self.usec.store(usec, Ordering::Relaxed); }
|
||||
}
|
||||
impl PulsePosition<f64> for Instant {
|
||||
#[inline] fn pulse (&self) -> f64 { self.pulse.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_pulse (&self, usec: f64) { self.pulse.store(usec, Ordering::Relaxed); }
|
||||
}
|
||||
impl PulsePosition<usize> for Instant {
|
||||
#[inline] fn pulse (&self) -> usize { self.pulse.load(Ordering::Relaxed) as usize }
|
||||
#[inline] fn set_pulse (&self, usec: usize) { self.pulse.store(usec as f64, Ordering::Relaxed); }
|
||||
}
|
||||
|
||||
/// (pulses, name)
|
||||
pub const NOTE_DURATIONS: [(usize, &str);26] = [
|
||||
(1, "1/384"),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ impl<E: Engine> Audio for Arranger<E> {
|
|||
if let Some(ref transport) = self.transport {
|
||||
transport.write().unwrap().process(client, scope);
|
||||
}
|
||||
//for track in self.arrangement.tracks.iter_mut() {
|
||||
//track.player.process(client, scope)
|
||||
//}
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ impl<E: Engine> Audio for Sequencer<E> {
|
|||
Control::Continue
|
||||
}
|
||||
}
|
||||
|
||||
impl Phrase {
|
||||
/// Write a chunk of MIDI events to an output port.
|
||||
pub fn process_out (
|
||||
|
|
|
|||
|
|
@ -3,14 +3,10 @@ use crate::*;
|
|||
pub struct TransportTime {
|
||||
/// Current sample sr, tempo, and PPQ.
|
||||
pub timebase: Timebase,
|
||||
/// Current moment in time
|
||||
pub instant: Instant,
|
||||
/// Playback state
|
||||
pub playing: RwLock<Option<TransportState>>,
|
||||
/// Current time in samples
|
||||
pub sample: AtomicUsize,
|
||||
/// Current time in pulses
|
||||
pub pulse: AtomicUsize,
|
||||
/// Current time in microseconds
|
||||
pub usecs: AtomicUsize,
|
||||
/// Note quantization factor
|
||||
pub quant: AtomicUsize,
|
||||
/// Launch quantization factor
|
||||
|
|
@ -57,16 +53,16 @@ impl PulsesPerQuaver<usize> for TransportTime {
|
|||
#[inline] fn set_ppq (&self, ppq: usize) { self.timebase.set_ppq(ppq as f64); }
|
||||
}
|
||||
impl FramePosition<usize> for TransportTime {
|
||||
#[inline] fn sample (&self) -> usize { self.sample.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_sample (&self, sample: usize) { self.sample.store(sample, Ordering::Relaxed); }
|
||||
#[inline] fn sample (&self) -> usize { self.instant.sample() }
|
||||
#[inline] fn set_sample (&self, sample: usize) { self.instant.set_sample(sample) }
|
||||
}
|
||||
impl UsecPosition<usize> for TransportTime {
|
||||
#[inline] fn usec (&self) -> usize { self.usecs.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_usec (&self, usec: usize) { self.usecs.store(usec, Ordering::Relaxed); }
|
||||
#[inline] fn usec (&self) -> usize { self.instant.usec() }
|
||||
#[inline] fn set_usec (&self, usec: usize) { self.instant.set_usec(usec) }
|
||||
}
|
||||
impl PulsePosition<usize> for TransportTime {
|
||||
#[inline] fn pulse (&self) -> usize { self.pulse.load(Ordering::Relaxed) }
|
||||
#[inline] fn set_pulse (&self, usec: usize) { self.pulse.store(usec, Ordering::Relaxed); }
|
||||
#[inline] fn pulse (&self) -> usize { self.instant.pulse() }
|
||||
#[inline] fn set_pulse (&self, usec: usize) { self.instant.set_pulse(usec); }
|
||||
}
|
||||
impl Quantize<usize> for TransportTime {
|
||||
#[inline] fn quant (&self) -> usize { self.quant.load(Ordering::Relaxed) }
|
||||
|
|
@ -97,9 +93,7 @@ impl<E: Engine> TransportToolbar<E> {
|
|||
playing: Some(TransportState::Stopped).into(),
|
||||
quant: 24.into(),
|
||||
sync: (timebase.ppq() as usize * 4).into(),
|
||||
sample: 0.into(),
|
||||
pulse: 0.into(),
|
||||
usecs: 0.into(),
|
||||
instant: Instant::default(),
|
||||
timebase,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue