From a67481ab044e5abbfef81575a64ad707ecde28c6 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 3 May 2025 14:33:44 +0300 Subject: [PATCH] swap ins/outs; start adding device slots --- crates/app/src/view.rs | 125 ++++++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 51 deletions(-) diff --git a/crates/app/src/view.rs b/crates/app/src/view.rs index 40df4953..b2b8b9e9 100644 --- a/crates/app/src/view.rs +++ b/crates/app/src/view.rs @@ -134,24 +134,35 @@ impl Tek { /// Height available to display track headers. pub(crate) fn h_tracks_area (&self) -> u16 { - 5 + 5 // FIXME //self.h().saturating_sub(self.h_inputs() + self.h_outputs()) } /// Height available to display tracks. pub(crate) fn h_scenes_area (&self) -> u16 { //15 - self.h().saturating_sub(self.h_inputs() + self.h_outputs() + 11) + self.h().saturating_sub( + self.h_inputs() + + self.h_outputs() + + self.h_devices() + + 13 // FIXME + ) } /// Height taken by all inputs. pub(crate) fn h_inputs (&self) -> u16 { - 1 + self.inputs_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0) + self.inputs_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0) } /// Height taken by all outputs. pub(crate) fn h_outputs (&self) -> u16 { - 1 + self.outputs_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0) + self.outputs_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0) + } + + /// Height taken by visible device slots. + pub(crate) fn h_devices (&self) -> u16 { + 2 + //1 + self.devices_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0) } /// Height taken by all scenes. @@ -255,13 +266,14 @@ pub(crate) struct ArrangerView<'a> { impl<'a> Content for ArrangerView<'a> { fn content (&self) -> impl Render { - let ins = |x|Bsp::s(self.inputs(), x); - let tracks = |x|Bsp::s(self.tracks(), x); - let outs = |x|Bsp::n(self.outputs(), x); - let bg = |x|Tui::bg(Reset, x); + let ins = |x|Bsp::n(self.inputs(), x); + let tracks = |x|Bsp::s(self.tracks(), x); + let devices = |x|Bsp::s(self.devices(), x); + let outs = |x|Bsp::s(self.outputs(), x); + let bg = |x|Tui::bg(Reset, x); //let track_scroll = |x|Bsp::s(&self.track_scroll, x); //let scene_scroll = |x|Bsp::e(&self.scene_scroll, x); - ins(tracks(outs(bg(self.scenes())))) + outs(tracks(devices(ins(bg(self.scenes()))))) } } @@ -275,10 +287,10 @@ impl<'a> ArrangerView<'a> { width_mid: app.w_tracks_area(), width_side: app.w_sidebar(), - inputs_height: app.h_inputs().saturating_sub(1), + inputs_height: app.h_inputs(), inputs_count: app.midi_ins.len(), - outputs_height: app.h_outputs().saturating_sub(1), + outputs_height: app.h_outputs(), outputs_count: app.midi_outs.len(), scenes_height: app.h_scenes_area(), @@ -307,11 +319,56 @@ impl<'a> ArrangerView<'a> { /// Render input matrix. pub(crate) fn inputs (&'a self) -> impl Content + 'a { Tui::bg(Reset, Bsp::s( + self.input_intos(), Bsp::s(self.input_routes(), self.input_ports()), - self.input_intos() )) } + /// Render output matrix. + pub(crate) fn outputs (&'a self) -> impl Content + 'a { + Tui::bg(Reset, Align::n(Bsp::s( + Bsp::s(self.output_ports(), self.output_conns()), + Bsp::s(self.output_nexts(), self.output_froms()), + ))) + } + + /// Render device switches. + pub(crate) fn devices (&'a self) -> impl Content + 'a { + let Self { width_side, width_mid, track_count, track_selected, is_editing, .. } = self; + Tryptich::top(1) + .left(*width_side, button_3("x", "devices", format!("{}", 0), *is_editing)) + .right(*width_side, button_2("X", "add device", *is_editing)) + .middle(*width_mid, per_track_top(*width_mid, ||self.tracks_with_sizes_scrolled(), + move|index, track|{ + wrap(if *track_selected == Some(index) { + track.color.light + } else { + track.color.base + }.rgb, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e( + Tui::fg_bg(Reset, Reset, "[ "), + Tui::fg_bg(Reset, Reset, " ]"), + )))) + })) + } + + /// Render track headers + pub(crate) fn tracks (&'a self) -> impl Content + 'a { + let Self { width_side, width_mid, track_count, track_selected, is_editing, .. } = self; + Tryptich::center(3) + .left(*width_side, button_3("t", "track", format!("{}", *track_count), *is_editing)) + .right(*width_side, button_2("T", "add track", *is_editing)) + .middle(*width_mid, per_track(*width_mid, ||self.tracks_with_sizes_scrolled(), + |index, track|wrap( + if *track_selected == Some(index) { + track.color.light + } else { + track.color.base + }.rgb, + track.color.lightest.rgb, + Tui::bold(true, Fill::xy(Align::nw(&track.name))) + ))) + } + fn input_routes (&'a self) -> impl Content + 'a { Tryptich::top(self.inputs_height) .left(self.width_side, @@ -364,14 +421,6 @@ impl<'a> ArrangerView<'a> { |_, _|Tui::bg(Reset, Align::c(Bsp::s(OctaveVertical::default(), " ------ "))))) } - /// Render output matrix. - pub(crate) fn outputs (&'a self) -> impl Content + 'a { - Tui::bg(Reset, Align::n(Bsp::s( - Bsp::s(self.output_nexts(), self.output_froms()), - Bsp::s(self.output_ports(), self.output_conns()), - ))) - } - fn output_nexts (&'a self) -> impl Content + 'a { Tryptich::top(2) .left(self.width_side, Align::ne("From clip:")) @@ -438,24 +487,6 @@ impl<'a> ArrangerView<'a> { ))) } - /// Render track headers - pub(crate) fn tracks (&'a self) -> impl Content + 'a { - let Self { width_side, width_mid, track_count, track_selected, is_editing, .. } = self; - Tryptich::center(3) - .left(*width_side, button_3("t", "track", format!("{}", *track_count), *is_editing)) - .right(*width_side, button_2("T", "add track", *is_editing)) - .middle(*width_mid, per_track(*width_mid, ||self.tracks_with_sizes_scrolled(), - |index, track|wrap( - if *track_selected == Some(index) { - track.color.light - } else { - track.color.base - }.rgb, - track.color.lightest.rgb, - Tui::bold(true, Fill::xy(Align::nw(&track.name))) - ))) - } - /// Render scenes with clips pub(crate) fn scenes (&'a self) -> impl Content + 'a { @@ -988,7 +1019,9 @@ impl PianoHorizontal { } } -pub(crate) fn note_y_iter (note_lo: usize, note_hi: usize, y0: u16) -> impl Iterator { +pub(crate) fn note_y_iter (note_lo: usize, note_hi: usize, y0: u16) + -> impl Iterator +{ (note_lo..=note_hi).rev().enumerate().map(move|(y, n)|(y, y0 + y as u16, n)) } @@ -1259,18 +1292,8 @@ impl std::fmt::Debug for PianoHorizontal { fn to_key (note: usize) -> &'static str { match note % 12 { - 11 => "████▌", - 10 => " ", - 9 => "████▌", - 8 => " ", - 7 => "████▌", - 6 => " ", - 5 => "████▌", - 4 => "████▌", - 3 => " ", - 2 => "████▌", - 1 => " ", - 0 => "████▌", + 11 | 9 | 7 | 5 | 4 | 2 | 0 => "████▌", + 10 | 8 | 6 | 3 | 1 => " ", _ => unreachable!(), } }