use crate::*; pub struct ClipSelected { pub(crate) title: &'static str, pub(crate) name: Arc, pub(crate) color: ItemPalette, pub(crate) time: Arc, } content!(TuiOut: |self: ClipSelected|FieldV( self.color, self.title, format!("{} {}", self.time, self.name) )); impl ClipSelected { /// Shows currently playing clip with beats elapsed pub fn play_clip (state: &T) -> Self { let (name, color) = if let Some((_, Some(clip))) = state.play_clip() { let MidiClip { ref name, color, .. } = *clip.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 clip with beats remaining until switchover pub fn next_clip (state: &T) -> Self { let mut time: Arc = String::from("--.-.--").into(); let mut name: Arc = String::from("").into(); let mut color = ItemPalette::from(TuiTheme::g(64)); if let Some((t, Some(clip))) = state.next_clip() { let clip = clip.read().unwrap(); name = clip.name.clone(); color = clip.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(clip))) = state.play_clip() { let clip = clip.read().unwrap(); if clip.looped { name = clip.name.clone(); color = clip.color.clone(); let target = t.pulse.get() + clip.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, } } }