mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
make TimeUnit a trait
This commit is contained in:
parent
a31d6389be
commit
4df15d6bac
7 changed files with 238 additions and 220 deletions
|
|
@ -202,8 +202,8 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
|||
// beats until switchover
|
||||
let until_next = player.next_phrase.as_ref()
|
||||
.map(|(t, _)|{
|
||||
let target = t.pulse().get();
|
||||
let current = clock.current.pulse().get();
|
||||
let target = t.pulse.get();
|
||||
let current = clock.current.pulse.get();
|
||||
if target > current {
|
||||
let remaining = target - current;
|
||||
format!("▎-{:>}", clock.timebase().format_beats_0_short(remaining))
|
||||
|
|
|
|||
|
|
@ -418,7 +418,7 @@ impl PhrasePlayer {
|
|||
}
|
||||
pub fn pulses_since_start (&self) -> Option<f64> {
|
||||
if let Some((started, Some(_))) = self.phrase.as_ref() {
|
||||
Some(self.clock.current.pulse().get() - started.pulse().get())
|
||||
Some(self.clock.current.pulse.get() - started.pulse.get())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ impl PhrasePlayer {
|
|||
// If it's time for the next enqueued phrase, handle it here:
|
||||
if next {
|
||||
if let Some((start_at, phrase)) = &self.next_phrase {
|
||||
let start = start_at.sample().get() as usize;
|
||||
let start = start_at.sample.get() as usize;
|
||||
// If it's time to switch to the next phrase:
|
||||
if start <= sample0 {
|
||||
// Samples elapsed since phrase was supposed to start
|
||||
|
|
@ -127,7 +127,7 @@ impl PhrasePlayer {
|
|||
let sample0 = scope.last_frame_time() as usize;
|
||||
if let (true, Some((started, phrase))) = (self.is_rolling(), &self.phrase) {
|
||||
let start = started.sample.get() as usize;
|
||||
let quant = self.clock.quant().get();
|
||||
let quant = self.clock.quant.get();
|
||||
// For highlighting keys and note repeat
|
||||
let mut notes_in = self.notes_in.write().unwrap();
|
||||
// Record from each input
|
||||
|
|
|
|||
|
|
@ -4,23 +4,22 @@ pub struct TransportTime {
|
|||
/// Current moment in time
|
||||
pub current: Instant,
|
||||
/// Note quantization factor
|
||||
pub quant: TimeUnit,
|
||||
pub quant: Quantize,
|
||||
/// Launch quantization factor
|
||||
pub sync: TimeUnit,
|
||||
pub sync: LaunchSync,
|
||||
/// Playback state
|
||||
pub playing: RwLock<Option<TransportState>>,
|
||||
}
|
||||
impl TransportTime {
|
||||
pub fn timebase (&self) -> &Arc<Timebase> { &self.current.timebase }
|
||||
}
|
||||
impl PulsePosition for TransportTime {
|
||||
#[inline] fn pulse (&self) -> &TimeUnit { self.current.pulse() }
|
||||
}
|
||||
impl Quantize for TransportTime {
|
||||
#[inline] fn quant (&self) -> &TimeUnit { &self.quant }
|
||||
}
|
||||
impl LaunchSync for TransportTime {
|
||||
#[inline] fn sync (&self) -> &TimeUnit { &self.sync }
|
||||
#[inline] pub fn timebase (&self) -> &Arc<Timebase> { &self.current.timebase }
|
||||
#[inline] pub fn pulse (&self) -> f64 { self.current.pulse.get() }
|
||||
#[inline] pub fn quant (&self) -> f64 { self.quant.get() }
|
||||
#[inline] pub fn sync (&self) -> f64 { self.sync.get() }
|
||||
#[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 }
|
||||
}
|
||||
}
|
||||
/// Stores and displays time-related state.
|
||||
pub struct TransportToolbar<E: Engine> {
|
||||
|
|
@ -63,7 +62,7 @@ impl<E: Engine> TransportToolbar<E> {
|
|||
Arc::new(TransportTime {
|
||||
playing: Some(TransportState::Stopped).into(),
|
||||
quant: 24.into(),
|
||||
sync: (timebase.ppq().get() * 4.).into(),
|
||||
sync: (timebase.ppq.get() * 4.).into(),
|
||||
current: Instant::default(),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ 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); },
|
||||
|
|
@ -35,7 +35,7 @@ impl TransportToolbar<Tui> {
|
|||
Ok(Some(true))
|
||||
}
|
||||
fn handle_quant (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
let quant = self.clock.quant().get() as usize;
|
||||
let quant = self.clock.quant.get() as usize;
|
||||
match from.event() {
|
||||
key!(KeyCode::Char(',')) => { self.clock.quant.set(prev_note_length(quant) as f64); },
|
||||
key!(KeyCode::Char('.')) => { self.clock.quant.set(next_note_length(quant) as f64); },
|
||||
|
|
@ -44,7 +44,7 @@ impl TransportToolbar<Tui> {
|
|||
return Ok(Some(true))
|
||||
}
|
||||
fn handle_sync (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
let sync = self.clock.sync().get() as usize;
|
||||
let sync = self.clock.sync.get() as usize;
|
||||
match from.event() {
|
||||
key!(KeyCode::Char(',')) => { self.clock.quant.set(prev_note_length(sync) as f64); },
|
||||
key!(KeyCode::Char('.')) => { self.clock.quant.set(next_note_length(sync) as f64); },
|
||||
|
|
|
|||
|
|
@ -15,20 +15,20 @@ 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! {
|
||||
//"QUANT ", ppq_to_name(self.quant as usize)
|
||||
//})),
|
||||
self.focus.wrap(self.focused, TransportToolbarFocus::Sync, &Outset::X(1u16, row! {
|
||||
"SYNC ", pulses_to_name(self.clock.sync().get() as usize)
|
||||
"SYNC ", pulses_to_name(self.clock.sync.get() as usize)
|
||||
}))
|
||||
).align_w().fill_x(),
|
||||
|
||||
self.focus.wrap(self.focused, TransportToolbarFocus::Clock, &{
|
||||
let time1 = self.clock.current.format_beat();
|
||||
let time2 = self.clock.current.format_current_usec();
|
||||
let time2 = self.clock.current.usec.format_msu();
|
||||
row!("B" ,time1.as_str(), " T", time2.as_str()).outset_x(1)
|
||||
}).align_e().fill_x(),
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue