mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
simplify time traits
This commit is contained in:
parent
ad2f75bee6
commit
66f9afe500
7 changed files with 151 additions and 165 deletions
|
|
@ -179,7 +179,7 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
|||
.map(|port|port.short_name())
|
||||
.transpose()?
|
||||
.unwrap_or("(none)".into());
|
||||
let input = format!("▎>{}", input_name);
|
||||
let input = format!("▎>{}", input_name);
|
||||
col!(name, input)
|
||||
.min_xy(w as u16, track_title_h)
|
||||
.bg(track.color)
|
||||
|
|
|
|||
|
|
@ -401,7 +401,7 @@ impl PhrasePlayer {
|
|||
pub fn samples_since_start (&self) -> Option<usize> {
|
||||
self.phrase.as_ref()
|
||||
.map(|(started,_)|started.sample())
|
||||
.map(|started|started - self.clock.sample())
|
||||
.map(|started|started - self.clock.instant.sample())
|
||||
}
|
||||
pub fn playing_phrase (&self) -> Option<(usize, Arc<RwLock<Phrase>>)> {
|
||||
if let (
|
||||
|
|
|
|||
|
|
@ -12,32 +12,6 @@ pub struct TransportTime {
|
|||
/// Launch quantization factor
|
||||
pub sync: AtomicUsize,
|
||||
}
|
||||
impl SampleRate<f64> for TransportTime {
|
||||
#[inline] fn sr (&self) -> f64 { self.timebase.sr() }
|
||||
#[inline] fn set_sr (&self, sr: f64) { self.timebase.set_sr(sr); }
|
||||
}
|
||||
impl BeatsPerMinute<f64> for TransportTime {
|
||||
#[inline] fn bpm (&self) -> f64 { self.timebase.bpm() }
|
||||
#[inline] fn set_bpm (&self, bpm: f64) { self.timebase.set_bpm(bpm); }
|
||||
}
|
||||
impl PulsesPerQuaver<f64> for TransportTime {
|
||||
const DEFAULT_PPQ: f64 = Timebase::DEFAULT_PPQ;
|
||||
#[inline] fn ppq (&self) -> f64 { self.timebase.ppq() }
|
||||
#[inline] fn set_ppq (&self, ppq: f64) { self.timebase.set_ppq(ppq); }
|
||||
}
|
||||
impl PulsesPerQuaver<usize> for TransportTime {
|
||||
const DEFAULT_PPQ: usize = Timebase::DEFAULT_PPQ as usize;
|
||||
#[inline] fn ppq (&self) -> usize { self.timebase.ppq() as usize }
|
||||
#[inline] fn set_ppq (&self, ppq: usize) { self.timebase.set_ppq(ppq as f64); }
|
||||
}
|
||||
impl SamplePosition<usize> for TransportTime {
|
||||
#[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.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.instant.pulse() }
|
||||
#[inline] fn set_pulse (&self, usec: usize) { self.instant.set_pulse(usec); }
|
||||
|
|
|
|||
|
|
@ -24,11 +24,12 @@ impl TransportToolbar<Tui> {
|
|||
Ok(Some(true))
|
||||
}
|
||||
fn handle_bpm (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
let bpm = self.clock.timebase.bpm();
|
||||
match from.event() {
|
||||
key!(KeyCode::Char(',')) => { self.clock.set_bpm(self.clock.bpm() - 1.0); },
|
||||
key!(KeyCode::Char('.')) => { self.clock.set_bpm(self.clock.bpm() + 1.0); },
|
||||
key!(KeyCode::Char('<')) => { self.clock.set_bpm(self.clock.bpm() - 0.001); },
|
||||
key!(KeyCode::Char('>')) => { self.clock.set_bpm(self.clock.bpm() + 0.001); },
|
||||
key!(KeyCode::Char(',')) => { self.clock.timebase.set_bpm(bpm - 1.0); },
|
||||
key!(KeyCode::Char('.')) => { self.clock.timebase.set_bpm(bpm + 1.0); },
|
||||
key!(KeyCode::Char('<')) => { self.clock.timebase.set_bpm(bpm - 0.001); },
|
||||
key!(KeyCode::Char('>')) => { self.clock.timebase.set_bpm(bpm + 0.001); },
|
||||
_ => return Ok(None)
|
||||
}
|
||||
Ok(Some(true))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ impl<E: Engine> Audio for TransportToolbar<E> {
|
|||
let CycleTimes { current_frames, current_usecs, next_usecs: _, period_usecs: _ } = times;
|
||||
let _chunk_size = scope.n_frames() as usize;
|
||||
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
||||
self.clock.set_sample(transport.pos.frame() as usize);
|
||||
self.clock.instant.set_sample(transport.pos.frame() as usize);
|
||||
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)),
|
||||
|
|
|
|||
|
|
@ -19,11 +19,9 @@ impl Content for TransportToolbar<Tui> {
|
|||
).min_xy(11, 2).push_x(1)).align_x().fill_x(),
|
||||
|
||||
row!(
|
||||
self.focus.wrap(self.focused, TransportToolbarFocus::Bpm, &Outset::X(1u16, row! {
|
||||
"BPM ", format!("{}.{:03}",
|
||||
self.clock.bpm() as usize,
|
||||
(self.clock.bpm() * 1000.0) % 1000.0
|
||||
)
|
||||
self.focus.wrap(self.focused, TransportToolbarFocus::Bpm, &Outset::X(1u16, {
|
||||
let bpm = self.clock.timebase.bpm();
|
||||
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)
|
||||
|
|
@ -34,8 +32,8 @@ impl Content for TransportToolbar<Tui> {
|
|||
).align_w().fill_x(),
|
||||
|
||||
self.focus.wrap(self.focused, TransportToolbarFocus::Clock, &{
|
||||
let time1 = self.clock.format_beat();
|
||||
let time2 = self.clock.format_current_usec();
|
||||
let time1 = self.clock.instant.format_beat();
|
||||
let time2 = self.clock.instant.format_current_usec();
|
||||
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