launch countdown, pt.1

This commit is contained in:
🪞👃🪞 2024-11-01 16:23:47 +02:00
parent 9a1616904c
commit b8047ab1ef
3 changed files with 12 additions and 14 deletions

View file

@ -77,7 +77,7 @@ impl Timebase {
TicksIterator { fpt: self.samples_per_pulse(), sample: start, start, end }
}
}
impl Default for Timebase { fn default () -> Self { Self::new(48000f64, 150f64, 96f64) } }
impl Default for Timebase { fn default () -> Self { Self::new(48000f64, 150f64, DEFAULT_PPQ) } }
impl Instant {
pub fn zero (timebase: &Arc<Timebase>) -> Self {
Self { usec: 0.into(), sample: 0.into(), pulse: 0.into(), timebase: timebase.clone() }
@ -126,12 +126,7 @@ impl Instant {
}
}
/// Iterator that emits subsequent ticks within a range.
pub struct TicksIterator {
fpt: f64,
sample: usize,
start: usize,
end: usize,
}
pub struct TicksIterator { fpt: f64, sample: usize, start: usize, end: usize, }
impl Iterator for TicksIterator {
type Item = (usize, usize);
fn next (&mut self) -> Option<Self::Item> {
@ -305,10 +300,7 @@ pub const NOTE_DURATIONS: [(usize, &str);26] = [
];
/// Returns the next shorter length
pub fn prev_note_length (pulses: usize) -> usize {
for i in 1..=16 {
let length = NOTE_DURATIONS[16-i].0;
if length < pulses { return length }
}
for i in 1..=16 { let length = NOTE_DURATIONS[16-i].0; if length < pulses { return length } }
pulses
}
/// Returns the next longer length

View file

@ -141,6 +141,7 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
let track_title_h = 2u16;
let tracks_footer = 3u16;
let scene_title_w = 3 + Scene::longest_name(scenes) as u16; // x of 1st track
let clock = &self.0.clock;
let arrangement = Layers::new(move |add|{
let rows: &[(usize, usize)] = rows.as_ref();
let cols: &[(usize, usize)] = cols.as_ref();
@ -187,15 +188,19 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
});
// track controls
let footer = row!((track, w) in tracks.iter().zip(cols.iter().map(|col|col.0))=>{
let player = &track.player;
let clock = &player.clock;
let player = &track.player;
let elapsed = player.phrase.as_ref()
.map(|_|player.samples_since_start())
.flatten()
.map(|t|format!("{t:>}"))
.unwrap_or(String::from(""));
let until_next = player.next_phrase.as_ref()
.map(|(t, _)|format!("▎-{:>}", t.format_beat()))
.map(|(t, _)|{
let target = t.pulse().get();
let current = clock.instant.pulse().get();
let remaining = clock.timebase().format_beats(target - current);
format!("{remaining:>}")
})
.unwrap_or(String::from(""));
let output_name = track.player.midi_outputs.get(0)
.map(|port|port.short_name())

View file

@ -15,6 +15,7 @@ submod! {
transport transport_cmd transport_tui transport_snd
}
/// FIXME: use PPQ value from global timebase
pub const PPQ: usize = 96;
pub const CORNERS: CornersTall = CornersTall(CORNERS_STYLE);