From d806014df219f25abebb1e8893ce75e6c7b9a32e Mon Sep 17 00:00:00 2001 From: unspeaker Date: Thu, 19 Dec 2024 17:04:34 +0100 Subject: [PATCH] trim arranger view names --- crates/tek/src/tui/app_arranger.rs | 10 ++--- crates/tek/src/tui/arranger_mode_v.rs | 61 +++++++++++++++------------ crates/tek/src/tui/arranger_track.rs | 2 +- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/crates/tek/src/tui/app_arranger.rs b/crates/tek/src/tui/app_arranger.rs index 5eccb290..90fd03ea 100644 --- a/crates/tek/src/tui/app_arranger.rs +++ b/crates/tek/src/tui/app_arranger.rs @@ -46,16 +46,16 @@ from_jack!(|jack| ArrangerTui { render!(|self: ArrangerTui|{ let arranger = ||lay!(|add|{ let color = self.color; - add(&Fill::wh(Tui::bg(color.darkest.rgb, "x")))?; + add(&Fill::wh(Tui::bg(color.darkest.rgb, ())))?; add(&Fill::wh(Lozenge(Style::default().fg(color.light.rgb).bg(color.darker.rgb))))?; match self.mode { ArrangerMode::H => todo!("horizontal arranger"), ArrangerMode::V(factor) => add(&lay!(![ - ArrangerVColumnSeparator::from(self), - ArrangerVRowSeparator::from((self, factor)), + ArrangerVColSep::from(self), + ArrangerVRowSep::from((self, factor)), col!(![ - ArrangerVHeader::from(self), - ArrangerVContent::from((self, factor)), + ArrangerVHead::from(self), + ArrangerVBody::from((self, factor)), ]), ArrangerVCursor::from((self, factor)), ])), diff --git a/crates/tek/src/tui/arranger_mode_v.rs b/crates/tek/src/tui/arranger_mode_v.rs index dc95b787..92cb17d1 100644 --- a/crates/tek/src/tui/arranger_mode_v.rs +++ b/crates/tek/src/tui/arranger_mode_v.rs @@ -1,12 +1,12 @@ use crate::*; -pub struct ArrangerVColumnSeparator { +pub struct ArrangerVColSep { cols: Vec<(usize, usize)>, scenes_w: u16, sep_fg: Color, } -impl From<&ArrangerTui> for ArrangerVColumnSeparator { +impl From<&ArrangerTui> for ArrangerVColSep { fn from (state: &ArrangerTui) -> Self { Self { cols: track_widths(state.tracks()), @@ -16,7 +16,7 @@ impl From<&ArrangerTui> for ArrangerVColumnSeparator { } } -render!(|self: ArrangerVColumnSeparator|render(move|to: &mut TuiOutput|{ +render!(|self: ArrangerVColSep|render(move|to: &mut TuiOutput|{ let style = Some(Style::default().fg(self.sep_fg)); Ok(for x in self.cols.iter().map(|col|col.1) { let x = self.scenes_w + to.area().x() + x as u16; @@ -26,12 +26,12 @@ render!(|self: ArrangerVColumnSeparator|render(move|to: &mut TuiOutput|{ }) })); -pub struct ArrangerVRowSeparator { +pub struct ArrangerVRowSep { rows: Vec<(usize, usize)>, sep_fg: Color, } -impl From<(&ArrangerTui, usize)> for ArrangerVRowSeparator { +impl From<(&ArrangerTui, usize)> for ArrangerVRowSep { fn from ((state, factor): (&ArrangerTui, usize)) -> Self { Self { rows: ArrangerScene::ppqs(state.scenes(), factor), @@ -40,7 +40,7 @@ impl From<(&ArrangerTui, usize)> for ArrangerVRowSeparator { } } -render!(|self: ArrangerVRowSeparator|render(move|to: &mut TuiOutput|{ +render!(|self: ArrangerVRowSep|render(move|to: &mut TuiOutput|{ Ok(for y in self.rows.iter().map(|row|row.1) { let y = to.area().y() + (y / PPQ) as u16 + 1; if y >= to.buffer.area.height { break } @@ -135,7 +135,7 @@ render!(|self: ArrangerVCursor|render(move|to: &mut TuiOutput|{ }) })); -pub struct ArrangerVHeader<'a> { +pub struct ArrangerVHead<'a> { tracks: &'a Vec, cols: Vec<(usize, usize)>, focused: bool, @@ -146,7 +146,7 @@ pub struct ArrangerVHeader<'a> { current: &'a Arc, } -impl<'a> From<&'a ArrangerTui> for ArrangerVHeader<'a> { +impl<'a> From<&'a ArrangerTui> for ArrangerVHead<'a> { fn from (state: &'a ArrangerTui) -> Self { Self { tracks: &state.tracks, @@ -161,12 +161,20 @@ impl<'a> From<&'a ArrangerTui> for ArrangerVHeader<'a> { } } -render!(|self: ArrangerVHeader<'a>|row!( +render!(|self: ArrangerVHead<'a>|row!( (track, w) in self.tracks.iter().zip(self.cols.iter().map(|col|col.0)) => { + // name and width of track - let name = track.name().read().unwrap(); - let max_w = w.saturating_sub(1).min(name.len()).max(2); - let name = Tui::bold(true, Tui::fg(track.color.lightest.rgb, format!("▎{}", &name[0..max_w]))); + let name = track.name().read().unwrap(); + let max_w = w.saturating_sub(1).min(name.len()).max(2); + let name = Tui::bold(true, Tui::fg(track.color.lightest.rgb, format!("▎{}", &name[0..max_w]))); + + // name of active MIDI input + let input = format!(">{}", track.player.midi_ins().get(0) + .map(|port|port.short_name()) + .transpose()? + .unwrap_or("(none)".into())); + // beats elapsed let elapsed = if let Some((_, Some(phrase))) = track.player.play_phrase().as_ref() { let length = phrase.read().unwrap().length; @@ -174,40 +182,37 @@ render!(|self: ArrangerVHeader<'a>|row!( let elapsed = self.timebase.format_beats_1_short( (elapsed as usize % length) as f64 ); - format!("▎+{elapsed:>}") + format!("+{elapsed:>}") } else { - String::from("▎") + String::new() }; + // beats until switchover let until_next = track.player.next_phrase().as_ref().map(|(t, _)|{ let target = t.pulse.get(); let current = self.current.pulse.get(); if target > current { let remaining = target - current; - format!("▎-{:>}", self.timebase.format_beats_0_short(remaining)) + format!("-{:>}", self.timebase.format_beats_0_short(remaining)) } else { String::new() } - }).unwrap_or(String::from("▎")); - let timer = col!([until_next, elapsed]); - // name of active MIDI input - let _input = format!("▎>{}", track.player.midi_ins().get(0) - .map(|port|port.short_name()) - .transpose()? - .unwrap_or("(none)".into())); + }); + // name of active MIDI output - let _output = format!("▎<{}", track.player.midi_outs().get(0) + let output = format!("<{}", track.player.midi_outs().get(0) .map(|port|port.short_name()) .transpose()? .unwrap_or("(none)".into())); Tui::push_x(self.scenes_w, Tui::bg(track.color().base.rgb, - Tui::min_xy(w as u16, self.header_h, - col!([name, timer])))) + Tui::min_xy(w as u16, self.header_h, row!([ + col!(!["▎", "▎", "▎", "▎", "▎", "▎",]), + col!(![name, input, output, elapsed, until_next, output])])))) } )); -pub struct ArrangerVContent<'a> { +pub struct ArrangerVBody<'a> { size: &'a Measure, scenes: &'a Vec, tracks: &'a Vec, @@ -216,7 +221,7 @@ pub struct ArrangerVContent<'a> { header_h: u16, } -impl<'a> From<(&'a ArrangerTui, usize)> for ArrangerVContent<'a> { +impl<'a> From<(&'a ArrangerTui, usize)> for ArrangerVBody<'a> { fn from ((state, factor): (&'a ArrangerTui, usize)) -> Self { Self { size: &state.size, @@ -229,7 +234,7 @@ impl<'a> From<(&'a ArrangerTui, usize)> for ArrangerVContent<'a> { } } -render!(|self: ArrangerVContent<'a>|Fixed::h( +render!(|self: ArrangerVBody<'a>|Fixed::h( (self.size.h() as u16).saturating_sub(self.header_h), col!((scene, pulses) in self.scenes.iter().zip(self.rows.iter().map(|row|row.0)) => { let height = 1.max((pulses / PPQ) as u16); diff --git a/crates/tek/src/tui/arranger_track.rs b/crates/tek/src/tui/arranger_track.rs index e99950df..41dee088 100644 --- a/crates/tek/src/tui/arranger_track.rs +++ b/crates/tek/src/tui/arranger_track.rs @@ -48,7 +48,7 @@ pub trait ArrangerTrackApi: HasPlayer + Send + Sync + Sized { tracks.iter().map(|s|s.name().read().unwrap().len()).fold(0, usize::max) } - const MIN_WIDTH: usize = 3; + const MIN_WIDTH: usize = 6; fn width_inc (&mut self) { *self.width_mut() += 1;