mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
fix transport clock timebase
This commit is contained in:
parent
ff7ae12405
commit
21b08bf3df
6 changed files with 22 additions and 14 deletions
|
|
@ -79,6 +79,14 @@ impl Timebase {
|
|||
}
|
||||
impl Default for Timebase { fn default () -> Self { Self::new(48000f64, 150f64, 96f64) } }
|
||||
impl Instant {
|
||||
pub fn zero (timebase: &Arc<Timebase>) -> Self {
|
||||
Self {
|
||||
usec: 0.into(),
|
||||
sample: 0.into(),
|
||||
pulse: 0.into(),
|
||||
timebase: timebase.clone(),
|
||||
}
|
||||
}
|
||||
pub fn from_usec (timebase: &Arc<Timebase>, usec: f64) -> Self {
|
||||
Self {
|
||||
usec: usec.into(),
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ impl PhrasePlayer {
|
|||
pub fn enqueue_next (&mut self, phrase: Option<&Arc<RwLock<Phrase>>>) {
|
||||
let start = self.clock.next_launch_pulse();
|
||||
self.next_phrase = Some((
|
||||
Instant::from_pulse(&self.clock.timebase, start as f64),
|
||||
Instant::from_pulse(&self.clock.timebase(), start as f64),
|
||||
phrase.map(|p|p.clone())
|
||||
));
|
||||
self.reset = true;
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ impl Audio for PhrasePlayer {
|
|||
let output = &mut self.midi_out_buf;
|
||||
let notes_on = &mut self.notes_out.write().unwrap();
|
||||
let frame0 = frame0.saturating_sub(start_frame);
|
||||
let frameN = frame0 + frames;
|
||||
let ticks = self.clock.timebase.pulses_between_samples(frame0, frameN);
|
||||
let frame_n = frame0 + frames;
|
||||
let ticks = self.clock.timebase().pulses_between_samples(frame0, frame_n);
|
||||
let mut buf = Vec::with_capacity(8);
|
||||
for (sample, tick) in ticks {
|
||||
let tick = tick % phrase.length;
|
||||
|
|
@ -55,7 +55,7 @@ impl Audio for PhrasePlayer {
|
|||
if self.monitoring { self.midi_out_buf[frame].push(bytes.to_vec()) }
|
||||
if self.recording {
|
||||
phrase.record_event({
|
||||
let pulse = self.clock.timebase.samples_to_pulse(
|
||||
let pulse = self.clock.timebase().samples_to_pulse(
|
||||
(frame0 + frame - start_frame) as f64
|
||||
);
|
||||
let quantized = (pulse / quant).round() * quant;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
use crate::*;
|
||||
#[derive(Debug, Default)]
|
||||
pub struct TransportTime {
|
||||
/// Current sample sr, tempo, and PPQ.
|
||||
pub timebase: Arc<Timebase>,
|
||||
/// Current moment in time
|
||||
pub instant: Instant,
|
||||
/// Note quantization factor
|
||||
|
|
@ -12,6 +10,9 @@ pub struct TransportTime {
|
|||
/// Playback state
|
||||
pub playing: RwLock<Option<TransportState>>,
|
||||
}
|
||||
impl TransportTime {
|
||||
pub fn timebase (&self) -> &Arc<Timebase> { &self.instant.timebase }
|
||||
}
|
||||
impl PulsePosition for TransportTime {
|
||||
#[inline] fn pulse (&self) -> &TimeUnit { self.instant.pulse() }
|
||||
}
|
||||
|
|
@ -58,13 +59,12 @@ impl<E: Engine> TransportToolbar<E> {
|
|||
clock: match clock {
|
||||
Some(clock) => clock.clone(),
|
||||
None => {
|
||||
let timebase = Timebase::default();
|
||||
let timebase = Arc::new(Timebase::default());
|
||||
Arc::new(TransportTime {
|
||||
playing: Some(TransportState::Stopped).into(),
|
||||
quant: 24.into(),
|
||||
sync: (timebase.ppq().get() * 4.).into(),
|
||||
instant: Instant::default(),
|
||||
timebase: timebase.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ impl TransportToolbar<Tui> {
|
|||
Ok(Some(true))
|
||||
}
|
||||
fn handle_bpm (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
let bpm = self.clock.timebase.bpm().get();
|
||||
let bpm = self.clock.timebase().bpm().get();
|
||||
match from.event() {
|
||||
key!(KeyCode::Char(',')) => { self.clock.timebase.bpm.set(bpm - 1.0); },
|
||||
key!(KeyCode::Char('.')) => { self.clock.timebase.bpm.set(bpm + 1.0); },
|
||||
key!(KeyCode::Char('<')) => { self.clock.timebase.bpm.set(bpm - 0.001); },
|
||||
key!(KeyCode::Char('>')) => { self.clock.timebase.bpm.set(bpm + 0.001); },
|
||||
key!(KeyCode::Char(',')) => { self.clock.timebase().bpm.set(bpm - 1.0); },
|
||||
key!(KeyCode::Char('.')) => { self.clock.timebase().bpm.set(bpm + 1.0); },
|
||||
key!(KeyCode::Char('<')) => { self.clock.timebase().bpm.set(bpm - 0.001); },
|
||||
key!(KeyCode::Char('>')) => { self.clock.timebase().bpm.set(bpm + 0.001); },
|
||||
_ => return Ok(None)
|
||||
}
|
||||
Ok(Some(true))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ impl Content for TransportToolbar<Tui> {
|
|||
|
||||
row!(
|
||||
self.focus.wrap(self.focused, TransportToolbarFocus::Bpm, &Outset::X(1u16, {
|
||||
let bpm = self.clock.timebase.bpm().get();
|
||||
let bpm = self.clock.timebase().bpm().get();
|
||||
row! { "BPM ", format!("{}.{:03}", bpm as usize, (bpm * 1000.0) % 1000.0) }
|
||||
})),
|
||||
//let quant = self.focus.wrap(self.focused, TransportToolbarFocus::Quant, &Outset::X(1u16, row! {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue