wip: remodularize 2

This commit is contained in:
🪞👃🪞 2025-01-08 19:19:35 +01:00
parent 3b6ff81dad
commit d38dc14e84
27 changed files with 564 additions and 563 deletions

73
midi/src/midi_select.rs Normal file
View file

@ -0,0 +1,73 @@
use crate::*;
pub struct ClipSelected {
pub(crate) title: &'static str,
pub(crate) name: Arc<str>,
pub(crate) color: ItemPalette,
pub(crate) time: Arc<str>,
}
render!(TuiOut: (self: ClipSelected) =>
FieldV(self.color, self.title, format!("{} {}", self.time, self.name)));
impl ClipSelected {
/// Shows currently playing phrase with beats elapsed
pub fn play_phrase <T: HasPlayPhrase + HasClock> (state: &T) -> Self {
let (name, color) = if let Some((_, Some(phrase))) = state.play_phrase() {
let MidiClip { ref name, color, .. } = *phrase.read().unwrap();
(name.clone().into(), color)
} else {
("".to_string().into(), TuiTheme::g(64).into())
};
Self {
title: "Now",
name,
color,
time: state.pulses_since_start_looped()
.map(|(times, time)|format!("{:>3}x {:>}",
times+1.0,
state.clock().timebase.format_beats_1(time)))
.unwrap_or_else(||String::from(" ")).into()
}
}
/// Shows next phrase with beats remaining until switchover
pub fn next_phrase <T: HasPlayPhrase> (state: &T) -> Self {
let mut time: Arc<str> = String::from("--.-.--").into();
let mut name: Arc<str> = String::from("").into();
let mut color = ItemPalette::from(TuiTheme::g(64));
if let Some((t, Some(phrase))) = state.next_phrase() {
let phrase = phrase.read().unwrap();
name = phrase.name.clone();
color = phrase.color.clone();
time = {
let target = t.pulse.get();
let current = state.clock().playhead.pulse.get();
if target > current {
let remaining = target - current;
format!("-{:>}", state.clock().timebase.format_beats_1(remaining))
} else {
String::new()
}
}.into()
} else if let Some((t, Some(phrase))) = state.play_phrase() {
let phrase = phrase.read().unwrap();
if phrase.looped {
name = phrase.name.clone();
color = phrase.color.clone();
let target = t.pulse.get() + phrase.length as f64;
let current = state.clock().playhead.pulse.get();
if target > current {
time = format!("-{:>}", state.clock().timebase.format_beats_0(
target - current
)).into()
}
} else {
name = "Stop".to_string().into();
}
};
Self { title: "Next", time, name, color, }
}
}