use crate::*; pub struct ArrangerView<'a> { pub arrangement: &'a Arrangement, pub is_editing: bool, pub width: u16, pub width_mid: u16, pub width_side: u16, pub scene_last: usize, pub scene_scroll: Fill>, pub scene_selected: Option, /// Height available to display scene/track content. pub scenes_height: u16, pub track_scroll: Fill>, pub track_selected: Option, /// Height available to display track headers. pub tracks_height: u16, } impl<'a> Has> for ArrangerView<'a> { fn get (&self) -> &Vec { &self.arrangement.scenes } fn get_mut (&mut self) -> &mut Vec { &mut self.arrangement.scenes } } impl<'a> ArrangerView<'a> { pub fn new ( arrangement: &'a Arrangement, editor: Option<&'a MidiEditor> ) -> Self { let is_editing = editor.is_some(); let h_tracks_area = 5; let h_scenes_area = (arrangement.height() as u16).saturating_sub(20); let h_scenes = arrangement.h_scenes(is_editing); Self { arrangement, is_editing, width: arrangement.w_tracks_area(is_editing), width_mid: arrangement.w_tracks_area(is_editing).saturating_sub(20), width_side: 20, scenes_height: h_scenes_area, scene_selected: arrangement.selection().scene(), scene_last: arrangement.scenes.len().saturating_sub(1), scene_scroll: Fill::y(Fixed::x(1, ScrollbarV { offset: arrangement.scene_scroll, length: h_scenes_area as usize, total: h_scenes as usize, })), tracks_height: h_tracks_area, track_selected: arrangement.selection().track(), track_scroll: Fill::x(Fixed::y(1, ScrollbarH { offset: arrangement.track_scroll, length: h_tracks_area as usize, total: h_scenes as usize, })), } } } impl<'a> Content for ArrangerView<'a> { fn content (&self) -> impl Render { 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); self.arrangement.size.of(outs(tracks(devices(ins(bg(self.scenes_view(&None))))))) } } 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()), )) } /// 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 track headers pub(crate) fn tracks (&'a self) -> impl Content + 'a { let Self { width_side, width_mid, track_selected, is_editing, .. } = self; Tryptich::center(3) .left(*width_side, button_3("t", "track", format!("{}", self.arrangement.tracks.len()), *is_editing)) .right(*width_side, button_2("T", "add track", *is_editing)) .middle(*width_mid, per_track(||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 device switches. pub(crate) fn devices (&'a self) -> impl Content + 'a { let Self { width_side, width_mid, track_selected, is_editing, .. } = self; Tryptich::top(1) .left(*width_side, button_3("d", "devices", format!("{}", 0), *is_editing)) .right(*width_side, button_2("D", "add device", *is_editing)) .middle(*width_mid, per_track_top(||self.tracks_with_sizes_scrolled(), move|index, track|{ let bg = if *track_selected == Some(index) { track.color.light } else { track.color.base }; let fg = Tui::g(224); track.devices.get(0).map(|device|wrap(bg.rgb, fg, device.name())) })) } } pub(crate) fn per_track_top <'a, T: Content + 'a, U: TracksSizes<'a>> ( tracks: impl Fn() -> U + Send + Sync + 'a, callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a ) -> impl Content + 'a { Align::x(Tui::bg(Reset, Map::new(tracks, move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{ let width = (x2 - x1) as u16; map_east(x1 as u16, width, Fixed::x(width, Tui::fg_bg( track.color.lightest.rgb, track.color.base.rgb, callback(index, track))))}))) } pub(crate) fn per_track <'a, T: Content + 'a, U: TracksSizes<'a>> ( tracks: impl Fn() -> U + Send + Sync + 'a, callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a ) -> impl Content + 'a { per_track_top(tracks, move|index, track|Fill::y(Align::y(callback(index, track)))) }