mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
confine the messy part mainly to view::view_ports
This commit is contained in:
parent
3d290a9beb
commit
70ad0b343b
8 changed files with 611 additions and 600 deletions
155
app/src/view.rs
155
app/src/view.rs
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
mod view_arranger; pub use self::view_arranger::*;
|
|
||||||
mod view_clock; pub use self::view_clock::*;
|
mod view_clock; pub use self::view_clock::*;
|
||||||
mod view_color; pub use self::view_color::*;
|
mod view_color; pub use self::view_color::*;
|
||||||
mod view_iter; pub use self::view_iter::*;
|
mod view_iter; pub use self::view_iter::*;
|
||||||
|
|
@ -7,9 +6,7 @@ mod view_memo; pub use self::view_memo::*;
|
||||||
mod view_meter; pub use self::view_meter::*;
|
mod view_meter; pub use self::view_meter::*;
|
||||||
mod view_sizes; pub use self::view_sizes::*;
|
mod view_sizes; pub use self::view_sizes::*;
|
||||||
mod view_track; pub use self::view_track::*;
|
mod view_track; pub use self::view_track::*;
|
||||||
mod view_scene; pub use self::view_scene::*;
|
mod view_ports; pub use self::view_ports::*;
|
||||||
mod view_input; pub use self::view_input::*;
|
|
||||||
mod view_output; pub use self::view_output::*;
|
|
||||||
mod view_layout; pub use self::view_layout::*;
|
mod view_layout; pub use self::view_layout::*;
|
||||||
pub(crate) use std::fmt::Write;
|
pub(crate) use std::fmt::Write;
|
||||||
pub(crate) use ::tengri::tui::ratatui::prelude::Position;
|
pub(crate) use ::tengri::tui::ratatui::prelude::Position;
|
||||||
|
|
@ -21,7 +18,7 @@ view!(TuiOut: |self: Tek| self.size.of(View(self, self.view)); {
|
||||||
//":scene-add" => self.view_scene_add().boxed(),
|
//":scene-add" => self.view_scene_add().boxed(),
|
||||||
//":scenes" => self.view_scenes().boxed(),
|
//":scenes" => self.view_scenes().boxed(),
|
||||||
//":tracks" => self.view_tracks().boxed(),
|
//":tracks" => self.view_tracks().boxed(),
|
||||||
":arranger" => self.view_arranger().boxed(),
|
":arranger" => ArrangerView::new(self).boxed(),
|
||||||
":editor" => self.editor.as_ref().map(|e|Bsp::e(e.clip_status(), e.edit_status())).boxed(),
|
":editor" => self.editor.as_ref().map(|e|Bsp::e(e.clip_status(), e.edit_status())).boxed(),
|
||||||
":sample" => ().boxed(),//self.view_sample(self.is_editing()).boxed(),
|
":sample" => ().boxed(),//self.view_sample(self.is_editing()).boxed(),
|
||||||
":sampler" => ().boxed(),//self.view_sampler(self.is_editing(), &self.editor).boxed(),
|
":sampler" => ().boxed(),//self.view_sampler(self.is_editing(), &self.editor).boxed(),
|
||||||
|
|
@ -41,78 +38,82 @@ provide_num!(u16: |self: Tek| {
|
||||||
":y-outs" => (self.size.h() as u16).saturating_sub(self.h_outputs() + 1),
|
":y-outs" => (self.size.h() as u16).saturating_sub(self.h_outputs() + 1),
|
||||||
":y-samples" => if self.is_editing() { 1 } else { 0 },
|
":y-samples" => if self.is_editing() { 1 } else { 0 },
|
||||||
});
|
});
|
||||||
pub(crate) fn wrap (
|
|
||||||
bg: Color,
|
pub(crate) struct ArrangerView<'a> {
|
||||||
fg: Color,
|
app: &'a Tek,
|
||||||
content: impl Content<TuiOut>
|
|
||||||
) -> impl Content<TuiOut> {
|
is_editing: bool,
|
||||||
Bsp::e(Tui::fg_bg(bg, Reset, "▐"),
|
|
||||||
Bsp::w(Tui::fg_bg(bg, Reset, "▌"),
|
width_total: u16,
|
||||||
Tui::fg_bg(fg, bg, content)))
|
width_mid: u16,
|
||||||
|
width_side: u16,
|
||||||
|
|
||||||
|
inputs_count: usize,
|
||||||
|
inputs_height: u16,
|
||||||
|
|
||||||
|
outputs_count: usize,
|
||||||
|
outputs_height: u16,
|
||||||
|
|
||||||
|
scene_last: u16,
|
||||||
|
scene_scroll: u16,
|
||||||
|
scene_selected: Option<usize>,
|
||||||
|
scenes_height: u16,
|
||||||
|
|
||||||
|
track_scroll: u16,
|
||||||
|
track_selected: Option<usize>,
|
||||||
|
tracks_height: u16,
|
||||||
}
|
}
|
||||||
pub(crate) fn button_2 <'a, K, L> (
|
|
||||||
key: K,
|
impl<'a> Content<TuiOut> for ArrangerView<'a> {
|
||||||
label: L,
|
fn content (&self) -> impl Render<TuiOut> {
|
||||||
editing: bool,
|
Bsp::s(self.inputs(),
|
||||||
) -> impl Content<TuiOut> + 'a where
|
Bsp::s(self.tracks(),
|
||||||
K: Content<TuiOut> + 'a,
|
Bsp::n(self.outputs(), self.scenes())))
|
||||||
L: Content<TuiOut> + 'a,
|
}
|
||||||
{
|
}
|
||||||
let key = Tui::fg_bg(Tui::g(0), Tui::orange(), Bsp::e(
|
|
||||||
Tui::fg_bg(Tui::orange(), Reset, "▐"),
|
impl<'a> ArrangerView<'a> {
|
||||||
Bsp::e(key, Tui::fg(Tui::g(96), "▐"))
|
fn new (app: &'a Tek) -> Self {
|
||||||
));
|
Self {
|
||||||
let label = When::new(!editing, Tui::fg_bg(Tui::g(255), Tui::g(96), label));
|
app,
|
||||||
Tui::bold(true, Bsp::e(key, label))
|
is_editing: app.is_editing(),
|
||||||
}
|
|
||||||
pub(crate) fn button_3 <'a, K, L, V> (
|
width_total: app.w(),
|
||||||
key: K,
|
width_mid: app.w_tracks_area(),
|
||||||
label: L,
|
width_side: app.w_sidebar(),
|
||||||
value: V,
|
|
||||||
editing: bool,
|
inputs_height: app.h_inputs().saturating_sub(1),
|
||||||
) -> impl Content<TuiOut> + 'a where
|
inputs_count: app.midi_ins.len(),
|
||||||
K: Content<TuiOut> + 'a,
|
|
||||||
L: Content<TuiOut> + 'a,
|
outputs_height: app.h_outputs().saturating_sub(1),
|
||||||
V: Content<TuiOut> + 'a,
|
outputs_count: app.midi_outs.len(),
|
||||||
{
|
|
||||||
let key = Tui::fg_bg(Tui::g(0), Tui::orange(),
|
scenes_height: app.h_scenes(),
|
||||||
Bsp::e(Tui::fg_bg(Tui::orange(), Reset, "▐"), Bsp::e(key, Tui::fg(if editing {
|
scene_selected: app.selected().scene(),
|
||||||
Tui::g(128)
|
scene_last: app.scenes.len().saturating_sub(1),
|
||||||
} else {
|
scene_scroll: Fill::y(Fixed::x(1, ScrollbarV {
|
||||||
Tui::g(96)
|
offset: app.scene_scroll,
|
||||||
}, "▐"))));
|
length: app.h_tracks_area() as usize,
|
||||||
let label = Bsp::e(
|
total: app.h_scenes() as usize,
|
||||||
When::new(!editing, Bsp::e(
|
})),
|
||||||
Tui::fg_bg(Tui::g(255), Tui::g(96), label),
|
|
||||||
Tui::fg_bg(Tui::g(128), Tui::g(96), "▐"),
|
tracks_height: app.h_tracks_area(),
|
||||||
)),
|
track_selected: app.selected().track(),
|
||||||
Bsp::e(
|
track_scroll: Fill::y(Fixed::x(1, ScrollbarV {
|
||||||
Tui::fg_bg(Tui::g(224), Tui::g(128), value),
|
offset: app.scene_scroll,
|
||||||
Tui::fg_bg(Tui::g(128), Reset, "▌"),
|
length: app.h_tracks_area() as usize,
|
||||||
));
|
total: app.h_scenes() as usize,
|
||||||
Tui::bold(true, Bsp::e(key, label))
|
})),
|
||||||
}
|
|
||||||
fn heading <'a> (
|
}
|
||||||
key: &'a str,
|
}
|
||||||
label: &'a str,
|
pub(crate) fn inputs_with_sizes (&'a self) -> impl PortsSizes<'a> {
|
||||||
count: usize,
|
self.app.inputs_sizes()
|
||||||
content: impl Content<TuiOut> + Send + Sync + 'a,
|
}
|
||||||
editing: bool,
|
pub(crate) fn outputs_with_sizes (&'a self) -> impl PortsSizes<'a> {
|
||||||
) -> impl Content<TuiOut> + 'a {
|
self.app.outputs_sizes()
|
||||||
let count = format!("{count}");
|
}
|
||||||
Fill::xy(Align::w(Bsp::s(Fill::x(Align::w(button_3(key, label, count, editing))), content)))
|
pub(crate) fn tracks_with_sizes (&'a self) -> impl TracksSizes<'a> {
|
||||||
}
|
self.app.tracks_sizes_scrolled()
|
||||||
#[cfg(test)] mod test {
|
|
||||||
use super::*;
|
|
||||||
#[test] fn test_view () {
|
|
||||||
let _ = button_2("", "", true);
|
|
||||||
let _ = button_2("", "", false);
|
|
||||||
let _ = button_3("", "", "", true);
|
|
||||||
let _ = button_3("", "", "", false);
|
|
||||||
let _ = heading("", "", 0, "", true);
|
|
||||||
let _ = heading("", "", 0, "", false);
|
|
||||||
let _ = wrap(Reset, Reset, "");
|
|
||||||
let _ = row(0, 0, 0, "", "", "");
|
|
||||||
let _ = row_top(0, 0, 0, "", "", "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,130 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
impl Tek {
|
|
||||||
/// Render the arranger.
|
|
||||||
pub fn view_arranger (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
let w = self.w();
|
|
||||||
let w_m = self.w_tracks_area();
|
|
||||||
let w_s = self.w_sidebar();
|
|
||||||
let h_trks = self.h_tracks_area();
|
|
||||||
let h_outs = self.h_outputs().saturating_sub(1);
|
|
||||||
let h_ins = self.h_inputs().saturating_sub(1);
|
|
||||||
let h_scn = self.h_scenes();
|
|
||||||
let n_outs = self.midi_outs.len();
|
|
||||||
let n_ins = self.midi_ins.len();
|
|
||||||
let ins_szs = ||self.inputs_sizes();
|
|
||||||
let outs_szs = ||self.outputs_sizes();
|
|
||||||
let editing = self.is_editing();
|
|
||||||
let scn_scr = self.view_scene_scroll();
|
|
||||||
let scn_sel = self.selected().scene();
|
|
||||||
let scn_last = self.scenes.len().saturating_sub(1);
|
|
||||||
let scns_clrs = move||self.scenes_with_colors(editing, h_trks);
|
|
||||||
let trk_scr = self.view_track_scroll();
|
|
||||||
let trks_szs = ||self.tracks_sizes_scrolled();
|
|
||||||
let trk_sel = self.selected().track();
|
|
||||||
let scns_trk_clrs = move||self.scenes_with_track_colors(
|
|
||||||
editing, self.h_tracks_area(), trk_sel.unwrap_or(0)
|
|
||||||
);
|
|
||||||
let trk_cnt_data = (trk_sel.unwrap_or(0), self.tracks().len());
|
|
||||||
self.fmtd.write().unwrap().trks.update(
|
|
||||||
Some(trk_cnt_data), rewrite!(buf, "{}/{}", trk_cnt_data.0, trk_cnt_data.1)
|
|
||||||
);
|
|
||||||
Bsp::s(view_inputs(
|
|
||||||
w_m, w_s, h_ins, n_ins, trks_szs, ins_szs, trk_sel, editing
|
|
||||||
), Bsp::s(view_tracks(
|
|
||||||
w_m, w_s, &self.fmtd.read().unwrap().trks.view, trks_szs, trk_sel, editing
|
|
||||||
), Bsp::n(view_outputs(
|
|
||||||
w_m, w_s, h_outs, n_outs, trks_szs, outs_szs, trk_sel, editing
|
|
||||||
), view_scenes(
|
|
||||||
w, w_m, w_s, h_scn,
|
|
||||||
trk_scr, trks_szs, trk_sel,
|
|
||||||
scn_scr, scns_clrs, scns_trk_clrs, scn_last, scn_sel,
|
|
||||||
&self.editor, editing
|
|
||||||
))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn view_scene_scroll (&self) -> impl Content<TuiOut> {
|
|
||||||
Fill::y(Fixed::x(1, ScrollbarV {
|
|
||||||
offset: self.scene_scroll,
|
|
||||||
length: self.h_tracks_area() as usize,
|
|
||||||
total: self.h_scenes() as usize,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn view_track_scroll (&self) -> impl Content<TuiOut> {
|
|
||||||
Fill::y(Fixed::x(1, ScrollbarV {
|
|
||||||
offset: self.scene_scroll,
|
|
||||||
length: self.h_tracks_area() as usize,
|
|
||||||
total: self.h_scenes() as usize,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn io_ports <'a, T: PortsSizes<'a>> (
|
|
||||||
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
Map::new(iter,
|
|
||||||
move|(index, name, connections, y, y2), _|map_south(y as u16, (y2-y) as u16, Bsp::s(
|
|
||||||
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(Bsp::e(" ", name))))),
|
|
||||||
Map::new(||connections.iter(), move|connect, index|map_south(index as u16, 1,
|
|
||||||
Fill::x(Align::w(Tui::bold(false, Tui::fg_bg(fg, bg,
|
|
||||||
&connect.info)))))))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn io_conns <'a, T: PortsSizes<'a>> (
|
|
||||||
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
Map::new(iter,
|
|
||||||
move|(index, name, connections, y, y2), _|map_south(y as u16, (y2-y) as u16, Bsp::s(
|
|
||||||
Fill::x(Tui::bold(true, wrap(bg, fg, Fill::x(Align::w("▞▞▞▞ ▞▞▞▞"))))),
|
|
||||||
Map::new(||connections.iter(), move|connect, index|map_south(index as u16, 1,
|
|
||||||
Fill::x(Align::w(Tui::bold(false, wrap(bg, fg, Fill::x(""))))))))))
|
|
||||||
}
|
|
||||||
|
|
||||||
//#[cfg(test)] mod test {
|
|
||||||
//use super::*;
|
|
||||||
//#[test] fn test_view_arranger () {
|
|
||||||
//let mut output = TuiOut::default();
|
|
||||||
//output.area[2] = 9;
|
|
||||||
//output.area[3] = 9;
|
|
||||||
|
|
||||||
//let mut app = Tek::default();
|
|
||||||
//app.editor = Some(Default::default());
|
|
||||||
//app.scenes_add(5);
|
|
||||||
//app.tracks_add(5, Some(5), &[], &[]);
|
|
||||||
|
|
||||||
//Content::render(&io_ports(Reset, Reset, ||app.inputs_sizes()), &mut output);
|
|
||||||
//Content::render(&io_conns(Reset, Reset, ||app.outputs_sizes()), &mut output);
|
|
||||||
//Content::render(&app.per_track(|_, _|()), &mut output);
|
|
||||||
//Content::render(&app.per_track_top(|_, _|()), &mut output);
|
|
||||||
|
|
||||||
//Content::render(&app.view_arranger(), &mut output);
|
|
||||||
//Content::render(&app.view_inputs(), &mut output);
|
|
||||||
//Content::render(&app.view_outputs(), &mut output);
|
|
||||||
//Content::render(&app.view_scenes(), &mut output);
|
|
||||||
|
|
||||||
//Content::render(
|
|
||||||
//&app.view_scene_name(0, 0, 0, 0, &Default::default(), None),
|
|
||||||
//&mut output);
|
|
||||||
|
|
||||||
//Content::render(
|
|
||||||
//&app.view_scene_clip(0, 0, 0, &{
|
|
||||||
//let mut scene: Scene = Default::default();
|
|
||||||
//scene.clips.push(Some(Default::default()));
|
|
||||||
//scene
|
|
||||||
//}, None, 0, 0, false, false, None),
|
|
||||||
//&mut output);
|
|
||||||
|
|
||||||
//Content::render(&view_scene_cell(
|
|
||||||
//false,
|
|
||||||
//None,
|
|
||||||
//false,
|
|
||||||
//0,
|
|
||||||
//&Default::default(),
|
|
||||||
//None,
|
|
||||||
//None,
|
|
||||||
//&"",
|
|
||||||
//Default::default(),
|
|
||||||
//), &mut output);
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
pub(crate) fn view_inputs <'a, T, I> (
|
|
||||||
w_mid: u16,
|
|
||||||
w_side: u16,
|
|
||||||
h_inputs: u16,
|
|
||||||
n_inputs: usize,
|
|
||||||
tracks_sizes: impl (Fn() -> T) + Send + Sync,
|
|
||||||
inputs_sizes: impl (Fn() -> I) + Send + Sync,
|
|
||||||
track_selected: Option<usize>,
|
|
||||||
is_editing: bool,
|
|
||||||
) -> impl Content<TuiOut> where
|
|
||||||
T: TracksSizes<'a>,
|
|
||||||
I: PortsSizes<'a>
|
|
||||||
{
|
|
||||||
view_inputs_layout(
|
|
||||||
view_input_intos(w_mid, w_side, tracks_sizes),
|
|
||||||
view_input_routes(w_mid, w_side, tracks_sizes, h_inputs, inputs_sizes),
|
|
||||||
view_input_ports(w_mid, w_side, tracks_sizes, n_inputs, track_selected, is_editing)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_inputs_layout <'a, T, U, V> (
|
|
||||||
intos: T, routes: U, ports: V,
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U, V> where
|
|
||||||
T: Content<TuiOut> + 'a,
|
|
||||||
U: Content<TuiOut> + 'a,
|
|
||||||
V: Content<TuiOut> + 'a,
|
|
||||||
{
|
|
||||||
Bsp::s(Bsp::s(routes, ports), intos)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_input_intos <'a, T, U> (
|
|
||||||
w_mid: u16, w_side: u16, tracks: U,
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U> where
|
|
||||||
T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a,
|
|
||||||
{
|
|
||||||
Tryptich::top(2)
|
|
||||||
.left(w_side, Bsp::s(Align::e("Input:"), Align::e("Into:")))
|
|
||||||
.middle(w_mid, per_track_top(w_mid, tracks, |_, _|Tui::bg(Reset,
|
|
||||||
Align::c(Bsp::s(OctaveVertical::default(), " ------ ")))))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_input_routes <'a, T, U, V, W> (
|
|
||||||
w_mid: u16, w_side: u16, tracks: U, height: u16, inputs: W
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U, V, W> where
|
|
||||||
T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a,
|
|
||||||
V: PortsSizes<'a>, W: Fn()->T + Send + Sync + 'a,
|
|
||||||
{
|
|
||||||
Tryptich::top(height)
|
|
||||||
.left(w_side, io_ports(Tui::g(224), Tui::g(32), inputs))
|
|
||||||
.middle(w_mid, per_track_top(w_mid, tracks, move|_, &Track { color, .. }|{
|
|
||||||
io_conns(color.dark.rgb, color.darker.rgb, inputs)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_input_ports <'a, T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a> (
|
|
||||||
w_mid: u16,
|
|
||||||
w_side: u16,
|
|
||||||
tracks: U,
|
|
||||||
port_count: usize,
|
|
||||||
selected_track: Option<usize>,
|
|
||||||
editing: bool,
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U> {
|
|
||||||
Tryptich::top(1)
|
|
||||||
.left(w_side, button_3("i", "midi ins", format!("{port_count}"), editing))
|
|
||||||
.right(w_side, button_2("I", "add midi in", editing))
|
|
||||||
.middle(w_mid, per_track_top(w_mid, tracks, move|t, track|{
|
|
||||||
let rec = track.player.recording;
|
|
||||||
let mon = track.player.monitoring;
|
|
||||||
let rec = if rec { White } else { track.color.darkest.rgb };
|
|
||||||
let mon = if mon { White } else { track.color.darkest.rgb };
|
|
||||||
let bg = if selected_track == Some(t) {
|
|
||||||
track.color.light.rgb
|
|
||||||
} else {
|
|
||||||
track.color.base.rgb
|
|
||||||
};
|
|
||||||
//let bg2 = if t > 0 { track.color.base.rgb } else { Reset };
|
|
||||||
wrap(bg, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(
|
|
||||||
Tui::fg_bg(rec, bg, "Rec "),
|
|
||||||
Tui::fg_bg(mon, bg, "Mon "),
|
|
||||||
))))
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)] #[test] fn test_view_inputs () {
|
|
||||||
let mut output = TuiOut::default();
|
|
||||||
output.area[2] = 9;
|
|
||||||
output.area[3] = 9;
|
|
||||||
|
|
||||||
Content::render(&view_inputs(), &mut output);
|
|
||||||
}
|
|
||||||
|
|
@ -53,3 +53,131 @@ where A: Content<TuiOut>, B: Content<TuiOut>, C: Content<TuiOut> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn wrap (
|
||||||
|
bg: Color,
|
||||||
|
fg: Color,
|
||||||
|
content: impl Content<TuiOut>
|
||||||
|
) -> impl Content<TuiOut> {
|
||||||
|
Bsp::e(Tui::fg_bg(bg, Reset, "▐"),
|
||||||
|
Bsp::w(Tui::fg_bg(bg, Reset, "▌"),
|
||||||
|
Tui::fg_bg(fg, bg, content)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn button_2 <'a, K, L> (
|
||||||
|
key: K,
|
||||||
|
label: L,
|
||||||
|
editing: bool,
|
||||||
|
) -> impl Content<TuiOut> + 'a where
|
||||||
|
K: Content<TuiOut> + 'a,
|
||||||
|
L: Content<TuiOut> + 'a,
|
||||||
|
{
|
||||||
|
let key = Tui::fg_bg(Tui::g(0), Tui::orange(), Bsp::e(
|
||||||
|
Tui::fg_bg(Tui::orange(), Reset, "▐"),
|
||||||
|
Bsp::e(key, Tui::fg(Tui::g(96), "▐"))
|
||||||
|
));
|
||||||
|
let label = When::new(!editing, Tui::fg_bg(Tui::g(255), Tui::g(96), label));
|
||||||
|
Tui::bold(true, Bsp::e(key, label))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn button_3 <'a, K, L, V> (
|
||||||
|
key: K,
|
||||||
|
label: L,
|
||||||
|
value: V,
|
||||||
|
editing: bool,
|
||||||
|
) -> impl Content<TuiOut> + 'a where
|
||||||
|
K: Content<TuiOut> + 'a,
|
||||||
|
L: Content<TuiOut> + 'a,
|
||||||
|
V: Content<TuiOut> + 'a,
|
||||||
|
{
|
||||||
|
let key = Tui::fg_bg(Tui::g(0), Tui::orange(),
|
||||||
|
Bsp::e(Tui::fg_bg(Tui::orange(), Reset, "▐"), Bsp::e(key, Tui::fg(if editing {
|
||||||
|
Tui::g(128)
|
||||||
|
} else {
|
||||||
|
Tui::g(96)
|
||||||
|
}, "▐"))));
|
||||||
|
let label = Bsp::e(
|
||||||
|
When::new(!editing, Bsp::e(
|
||||||
|
Tui::fg_bg(Tui::g(255), Tui::g(96), label),
|
||||||
|
Tui::fg_bg(Tui::g(128), Tui::g(96), "▐"),
|
||||||
|
)),
|
||||||
|
Bsp::e(
|
||||||
|
Tui::fg_bg(Tui::g(224), Tui::g(128), value),
|
||||||
|
Tui::fg_bg(Tui::g(128), Reset, "▌"),
|
||||||
|
));
|
||||||
|
Tui::bold(true, Bsp::e(key, label))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn heading <'a> (
|
||||||
|
key: &'a str,
|
||||||
|
label: &'a str,
|
||||||
|
count: usize,
|
||||||
|
content: impl Content<TuiOut> + Send + Sync + 'a,
|
||||||
|
editing: bool,
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
let count = format!("{count}");
|
||||||
|
Fill::xy(Align::w(Bsp::s(Fill::x(Align::w(button_3(key, label, count, editing))), content)))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn io_ports <'a, T: PortsSizes<'a>> (
|
||||||
|
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
Map::new(iter,
|
||||||
|
move|(index, name, connections, y, y2), _|map_south(y as u16, (y2-y) as u16, Bsp::s(
|
||||||
|
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(Bsp::e(" ", name))))),
|
||||||
|
Map::new(||connections.iter(), move|connect, index|map_south(index as u16, 1,
|
||||||
|
Fill::x(Align::w(Tui::bold(false, Tui::fg_bg(fg, bg,
|
||||||
|
&connect.info)))))))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn io_conns <'a, T: PortsSizes<'a>> (
|
||||||
|
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
Map::new(iter,
|
||||||
|
move|(index, name, connections, y, y2), _|map_south(y as u16, (y2-y) as u16, Bsp::s(
|
||||||
|
Fill::x(Tui::bold(true, wrap(bg, fg, Fill::x(Align::w("▞▞▞▞ ▞▞▞▞"))))),
|
||||||
|
Map::new(||connections.iter(), move|connect, index|map_south(index as u16, 1,
|
||||||
|
Fill::x(Align::w(Tui::bold(false, wrap(bg, fg, Fill::x(""))))))))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a> (
|
||||||
|
width: u16,
|
||||||
|
tracks: impl TracksSizes<'a>,
|
||||||
|
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
Align::x(Tui::bg(Reset, Map::new(||tracks, move|(index, track, x1, x2), _|{
|
||||||
|
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<TuiOut> + 'a, U: TracksSizes<'a>> (
|
||||||
|
width: u16,
|
||||||
|
tracks: impl Fn() -> U + Send + Sync + 'a,
|
||||||
|
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
per_track_top(
|
||||||
|
width,
|
||||||
|
tracks,
|
||||||
|
move|index, track|Fill::y(Align::y(callback(index, track)))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)] mod test {
|
||||||
|
use super::*;
|
||||||
|
#[test] fn test_view () {
|
||||||
|
let _ = button_2("", "", true);
|
||||||
|
let _ = button_2("", "", false);
|
||||||
|
let _ = button_3("", "", "", true);
|
||||||
|
let _ = button_3("", "", "", false);
|
||||||
|
let _ = heading("", "", 0, "", true);
|
||||||
|
let _ = heading("", "", 0, "", false);
|
||||||
|
let _ = wrap(Reset, Reset, "");
|
||||||
|
let _ = row(0, 0, 0, "", "", "");
|
||||||
|
let _ = row_top(0, 0, 0, "", "", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
pub(crate) fn view_outputs <'a, T, O> (
|
|
||||||
w_mid: u16,
|
|
||||||
w_side: u16,
|
|
||||||
h_outputs: u16,
|
|
||||||
n_outputs: usize,
|
|
||||||
tracks_sizes: impl (Fn() -> T) + Send + Sync,
|
|
||||||
outputs_sizes: impl (Fn() -> O) + Send + Sync,
|
|
||||||
track_selected: Option<usize>,
|
|
||||||
is_editing: bool,
|
|
||||||
) -> impl Content<TuiOut> where
|
|
||||||
T: TracksSizes<'a>,
|
|
||||||
O: PortsSizes<'a>
|
|
||||||
{
|
|
||||||
view_outputs_layout(
|
|
||||||
view_output_nexts(w_mid, w_side, tracks_sizes),
|
|
||||||
view_output_froms(w_mid, w_side, tracks_sizes),
|
|
||||||
view_output_conns(w_mid, w_side, tracks_sizes, h_outputs, outputs_sizes),
|
|
||||||
view_output_ports(w_mid, w_side, tracks_sizes, n_outputs, track_selected, is_editing)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_outputs_layout <'a, T, U, V, W> (
|
|
||||||
nexts: T, froms: U, conns: V, outputs: W,
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U, V, W> where
|
|
||||||
T: Content<TuiOut> + 'a,
|
|
||||||
U: Content<TuiOut> + 'a,
|
|
||||||
V: Content<TuiOut> + 'a,
|
|
||||||
W: Content<TuiOut> + 'a,
|
|
||||||
{
|
|
||||||
Align::n(Bsp::s(Bsp::s(nexts, froms), Bsp::s(outputs, conns)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_output_nexts <'a, T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a> (
|
|
||||||
w_mid: u16, w_side: u16, tracks: U
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U> {
|
|
||||||
Tryptich::top(2)
|
|
||||||
.left(w_side, Align::ne("From:"))
|
|
||||||
.middle(w_mid, per_track_top(w_mid, tracks, |_, _|Tui::bg(Reset,
|
|
||||||
Align::c(Bsp::s(" ------ ", OctaveVertical::default())))))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_output_froms <'a, T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a> (
|
|
||||||
w_mid: u16, w_side: u16, tracks: U
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U> {
|
|
||||||
Tryptich::top(2)
|
|
||||||
.left(w_side, Align::ne("Next:"))
|
|
||||||
.middle(w_mid, per_track_top(w_mid, tracks, |t, track|Either(
|
|
||||||
track.player.next_clip.is_some(),
|
|
||||||
Thunk::new(||Tui::bg(Reset, format!("{:?}",
|
|
||||||
track.player.next_clip.as_ref()
|
|
||||||
.map(|(moment, clip)|clip.as_ref()
|
|
||||||
.map(|clip|clip.read().unwrap().name.clone()))
|
|
||||||
.flatten().as_ref()))),
|
|
||||||
Thunk::new(||Tui::bg(Reset, " ------ ")))))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_output_conns <'a, T, U, V, W> (
|
|
||||||
w_mid: u16, w_side: u16, tracks: U, height: u16, outputs: W
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U, V, W> where
|
|
||||||
T: PortsSizes<'a>, U: Fn()->T + Send + Sync + 'a,
|
|
||||||
V: PortsSizes<'a>, W: Fn()->T + Send + Sync + 'a,
|
|
||||||
{
|
|
||||||
Tryptich::top(height)
|
|
||||||
.left(w_side, io_ports(Tui::g(224), Tui::g(32), outputs))
|
|
||||||
.middle(w_mid, per_track_top(w_mid, tracks, |_, t|{
|
|
||||||
io_conns(t.color.dark.rgb, t.color.darker.rgb, outputs)
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view_output_ports <'a, T, U> (
|
|
||||||
w_mid: u16,
|
|
||||||
w_side: u16,
|
|
||||||
tracks_sizes: U,
|
|
||||||
port_count: usize,
|
|
||||||
selected_track: Option<usize>,
|
|
||||||
editing: bool,
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U> where
|
|
||||||
T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a
|
|
||||||
{
|
|
||||||
Tryptich::top(1)
|
|
||||||
.left(w_side, button_3("o", "midi outs", format!("{port_count}"), editing))
|
|
||||||
.right(w_side, button_2("O", "add midi out", editing))
|
|
||||||
.middle(w_mid, per_track_top(w_mid, tracks_sizes, move|i, t|{
|
|
||||||
let mute = false;
|
|
||||||
let solo = false;
|
|
||||||
let mute = if mute { White } else { t.color.darkest.rgb };
|
|
||||||
let solo = if solo { White } else { t.color.darkest.rgb };
|
|
||||||
let bg_1 = if selected_track == Some(i) { t.color.light.rgb } else { t.color.base.rgb };
|
|
||||||
let bg_2 = if i > 0 { t.color.base.rgb } else { Reset };
|
|
||||||
let mute = Tui::fg_bg(mute, bg_1, "Play ");
|
|
||||||
let solo = Tui::fg_bg(solo, bg_1, "Solo ");
|
|
||||||
wrap(bg_1, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(mute, solo))))
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)] #[test] fn test_view_outputs () {
|
|
||||||
let mut output = TuiOut::default();
|
|
||||||
output.area[2] = 9;
|
|
||||||
output.area[3] = 9;
|
|
||||||
|
|
||||||
Content::render(&view_outputs(), &mut output);
|
|
||||||
}
|
|
||||||
212
app/src/view/view_ports.rs
Normal file
212
app/src/view/view_ports.rs
Normal file
|
|
@ -0,0 +1,212 @@
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
impl<'a> ArrangerView<'a> {
|
||||||
|
/// Render input matrix.
|
||||||
|
pub(crate) fn inputs (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
inputs_layout(
|
||||||
|
input_intos(
|
||||||
|
self.width_mid,
|
||||||
|
self.width_side,
|
||||||
|
self.tracks_with_sizes(),
|
||||||
|
),
|
||||||
|
input_routes(
|
||||||
|
self.width_mid,
|
||||||
|
self.width_side,
|
||||||
|
self.tracks_with_sizes(),
|
||||||
|
self.inputs_height,
|
||||||
|
self.inputs_with_sizes(),
|
||||||
|
),
|
||||||
|
input_ports(
|
||||||
|
self.width_mid,
|
||||||
|
self.width_side,
|
||||||
|
self.tracks_with_sizes(),
|
||||||
|
self.inputs_count,
|
||||||
|
self.track_selected,
|
||||||
|
self.is_editing
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render output matrix.
|
||||||
|
pub(crate) fn outputs (&'a self) -> impl Content<TuiOut> + 'a {
|
||||||
|
outputs_layout(
|
||||||
|
output_nexts(
|
||||||
|
self.width_mid,
|
||||||
|
self.width_side,
|
||||||
|
self.tracks_sizes
|
||||||
|
),
|
||||||
|
output_froms(
|
||||||
|
self.width_mid,
|
||||||
|
self.width_side,
|
||||||
|
self.tracks_sizes
|
||||||
|
),
|
||||||
|
output_conns(
|
||||||
|
self.width_mid,
|
||||||
|
self.width_side,
|
||||||
|
self.tracks_sizes,
|
||||||
|
self.outputs_height,
|
||||||
|
self.outputs_sizes
|
||||||
|
),
|
||||||
|
output_ports(
|
||||||
|
self.width_mid,
|
||||||
|
self.width_side,
|
||||||
|
self.tracks_sizes,
|
||||||
|
self.outputs_count,
|
||||||
|
self.track_selected,
|
||||||
|
self.is_editing
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inputs_layout <'a> (
|
||||||
|
intos: impl Content<TuiOut>,
|
||||||
|
routes: impl Content<TuiOut>,
|
||||||
|
ports: impl Content<TuiOut>,
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
Bsp::s(Bsp::s(routes, ports), intos)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input_intos <'a> (
|
||||||
|
w_mid: u16,
|
||||||
|
w_side: u16,
|
||||||
|
tracks: impl TracksSizes<'a>,
|
||||||
|
) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
Tryptich::top(2)
|
||||||
|
.left(w_side, Bsp::s(Align::e("Input:"), Align::e("Into:")))
|
||||||
|
.middle(w_mid, per_track_top(w_mid, tracks, |_, _|Tui::bg(Reset,
|
||||||
|
Align::c(Bsp::s(OctaveVertical::default(), " ------ ")))))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input_routes <'a> (
|
||||||
|
w_mid: u16,
|
||||||
|
w_side: u16,
|
||||||
|
tracks: impl TracksSizes<'a>,
|
||||||
|
height: u16,
|
||||||
|
inputs: impl PortsSizes<'a>
|
||||||
|
) -> impl Content<TuiOut> {
|
||||||
|
Tryptich::top(height)
|
||||||
|
.left(w_side, io_ports(Tui::g(224), Tui::g(32), inputs))
|
||||||
|
.middle(w_mid, per_track_top(w_mid, tracks, move|_, &Track { color, .. }|{
|
||||||
|
io_conns(color.dark.rgb, color.darker.rgb, inputs)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input_ports <'a> (
|
||||||
|
w_mid: u16,
|
||||||
|
w_side: u16,
|
||||||
|
tracks: impl TracksSizes<'a>,
|
||||||
|
port_count: usize,
|
||||||
|
selected_track: Option<usize>,
|
||||||
|
editing: bool,
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tryptich::top(1)
|
||||||
|
.left(w_side, button_3("i", "midi ins", format!("{port_count}"), editing))
|
||||||
|
.right(w_side, button_2("I", "add midi in", editing))
|
||||||
|
.middle(w_mid, per_track_top(w_mid, tracks, move|t, track|{
|
||||||
|
let rec = track.player.recording;
|
||||||
|
let mon = track.player.monitoring;
|
||||||
|
let rec = if rec { White } else { track.color.darkest.rgb };
|
||||||
|
let mon = if mon { White } else { track.color.darkest.rgb };
|
||||||
|
let bg = if selected_track == Some(t) {
|
||||||
|
track.color.light.rgb
|
||||||
|
} else {
|
||||||
|
track.color.base.rgb
|
||||||
|
};
|
||||||
|
//let bg2 = if t > 0 { track.color.base.rgb } else { Reset };
|
||||||
|
wrap(bg, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(
|
||||||
|
Tui::fg_bg(rec, bg, "Rec "),
|
||||||
|
Tui::fg_bg(mon, bg, "Mon "),
|
||||||
|
))))
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn outputs_layout <'a, T, U, V, W> (
|
||||||
|
nexts: T, froms: U, conns: V, outputs: W,
|
||||||
|
) -> impl Content<TuiOut> + use<'a, T, U, V, W> where
|
||||||
|
T: Content<TuiOut> + 'a,
|
||||||
|
U: Content<TuiOut> + 'a,
|
||||||
|
V: Content<TuiOut> + 'a,
|
||||||
|
W: Content<TuiOut> + 'a,
|
||||||
|
{
|
||||||
|
Align::n(Bsp::s(Bsp::s(nexts, froms), Bsp::s(outputs, conns)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_nexts <'a, T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a> (
|
||||||
|
w_mid: u16, w_side: u16, tracks: U
|
||||||
|
) -> impl Content<TuiOut> + use<'a, T, U> {
|
||||||
|
Tryptich::top(2)
|
||||||
|
.left(w_side, Align::ne("From:"))
|
||||||
|
.middle(w_mid, per_track_top(w_mid, tracks, |_, _|Tui::bg(Reset,
|
||||||
|
Align::c(Bsp::s(" ------ ", OctaveVertical::default())))))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_froms <'a, T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a> (
|
||||||
|
w_mid: u16, w_side: u16, tracks: U
|
||||||
|
) -> impl Content<TuiOut> + use<'a, T, U> {
|
||||||
|
Tryptich::top(2)
|
||||||
|
.left(w_side, Align::ne("Next:"))
|
||||||
|
.middle(w_mid, per_track_top(w_mid, tracks, |t, track|Either(
|
||||||
|
track.player.next_clip.is_some(),
|
||||||
|
Thunk::new(||Tui::bg(Reset, format!("{:?}",
|
||||||
|
track.player.next_clip.as_ref()
|
||||||
|
.map(|(moment, clip)|clip.as_ref()
|
||||||
|
.map(|clip|clip.read().unwrap().name.clone()))
|
||||||
|
.flatten().as_ref()))),
|
||||||
|
Thunk::new(||Tui::bg(Reset, " ------ ")))))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_conns <'a, T, U, V, W> (
|
||||||
|
w_mid: u16, w_side: u16, tracks: U, height: u16, outputs: W
|
||||||
|
) -> impl Content<TuiOut> + use<'a, T, U, V, W> where
|
||||||
|
T: PortsSizes<'a>, U: Fn()->T + Send + Sync + 'a,
|
||||||
|
V: PortsSizes<'a>, W: Fn()->T + Send + Sync + 'a,
|
||||||
|
{
|
||||||
|
Tryptich::top(height)
|
||||||
|
.left(w_side, io_ports(Tui::g(224), Tui::g(32), outputs))
|
||||||
|
.middle(w_mid, per_track_top(w_mid, tracks, |_, t|{
|
||||||
|
io_conns(t.color.dark.rgb, t.color.darker.rgb, outputs)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_ports <'a, T, U> (
|
||||||
|
w_mid: u16,
|
||||||
|
w_side: u16,
|
||||||
|
tracks_sizes: U,
|
||||||
|
port_count: usize,
|
||||||
|
selected_track: Option<usize>,
|
||||||
|
editing: bool,
|
||||||
|
) -> impl Content<TuiOut> + use<'a, T, U> where
|
||||||
|
T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a
|
||||||
|
{
|
||||||
|
Tryptich::top(1)
|
||||||
|
.left(w_side, button_3("o", "midi outs", format!("{port_count}"), editing))
|
||||||
|
.right(w_side, button_2("O", "add midi out", editing))
|
||||||
|
.middle(w_mid, per_track_top(w_mid, tracks_sizes, move|i, t|{
|
||||||
|
let mute = false;
|
||||||
|
let solo = false;
|
||||||
|
let mute = if mute { White } else { t.color.darkest.rgb };
|
||||||
|
let solo = if solo { White } else { t.color.darkest.rgb };
|
||||||
|
let bg_1 = if selected_track == Some(i) { t.color.light.rgb } else { t.color.base.rgb };
|
||||||
|
let bg_2 = if i > 0 { t.color.base.rgb } else { Reset };
|
||||||
|
let mute = Tui::fg_bg(mute, bg_1, "Play ");
|
||||||
|
let solo = Tui::fg_bg(solo, bg_1, "Solo ");
|
||||||
|
wrap(bg_1, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(mute, solo))))
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)] #[test] fn test_inputs () {
|
||||||
|
let mut output = TuiOut::default();
|
||||||
|
output.area[2] = 9;
|
||||||
|
output.area[3] = 9;
|
||||||
|
|
||||||
|
Content::render(&inputs(), &mut output);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)] #[test] fn test_outputs () {
|
||||||
|
let mut output = TuiOut::default();
|
||||||
|
output.area[2] = 9;
|
||||||
|
output.area[3] = 9;
|
||||||
|
|
||||||
|
Content::render(&outputs(), &mut output);
|
||||||
|
}
|
||||||
|
|
@ -1,149 +0,0 @@
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
impl Tek {
|
|
||||||
pub fn view_scene_add (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
let editing = self.is_editing();
|
|
||||||
let data = (self.selected().scene().unwrap_or(0), self.scenes().len());
|
|
||||||
self.fmtd.write().unwrap().scns.update(Some(data), rewrite!(buf, "({}/{})", data.0, data.1));
|
|
||||||
button_3("S", "add scene", self.fmtd.read().unwrap().scns.view.clone(), editing)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn view_scenes <'a> (
|
|
||||||
w_full: u16,
|
|
||||||
w_mid: u16,
|
|
||||||
w_side: u16,
|
|
||||||
h_scenes: u16,
|
|
||||||
track_scroll: impl Content<TuiOut>,
|
|
||||||
track_sizes: impl TracksSizes<'a>,
|
|
||||||
track_selected: Option<usize>,
|
|
||||||
scene_scroll: impl Content<TuiOut>,
|
|
||||||
scenes_with_scene_colors: impl ScenesColors<'a>,
|
|
||||||
scenes_with_track_colors: impl ScenesColors<'a>,
|
|
||||||
scene_last: usize,
|
|
||||||
scene_selected: Option<usize>,
|
|
||||||
editor: &Option<MidiEditor>,
|
|
||||||
is_editing: bool,
|
|
||||||
) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
Tui::bg(Reset, Bsp::s(track_scroll, Bsp::e(scene_scroll, Fixed::y(h_scenes, Tryptich::center(h_scenes)
|
|
||||||
.left(w_side, Map::new(scenes_with_scene_colors,
|
|
||||||
move|(scene_index, scene, y1, y2, prev_scene): SceneWithColor, _|
|
|
||||||
view_scene_name(
|
|
||||||
w_full,
|
|
||||||
(1 + y2 - y1) as u16,
|
|
||||||
y1 as u16,
|
|
||||||
scene_index,
|
|
||||||
scene,
|
|
||||||
prev_scene,
|
|
||||||
scene_last == scene_index,
|
|
||||||
scene_selected
|
|
||||||
)))
|
|
||||||
.middle(w_mid, per_track(w_mid, track_sizes, move|track_index, track|Map::new(
|
|
||||||
scenes_with_track_colors,
|
|
||||||
move|(scene_index, scene, y1, y2, prev_scene): SceneWithColor, _|
|
|
||||||
view_scene_clip(
|
|
||||||
w_mid,
|
|
||||||
(1 + y2 - y1) as u16,
|
|
||||||
y1 as u16,
|
|
||||||
scene,
|
|
||||||
prev_scene,
|
|
||||||
scene_index,
|
|
||||||
track_index,
|
|
||||||
is_editing,
|
|
||||||
track_selected == Some(track_index),
|
|
||||||
scene_selected,
|
|
||||||
scene_last == scene_index,
|
|
||||||
editor
|
|
||||||
))))))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn view_scene_name (
|
|
||||||
width: u16,
|
|
||||||
height: u16,
|
|
||||||
offset: u16,
|
|
||||||
index: usize,
|
|
||||||
scene: &Scene,
|
|
||||||
prev: Option<ItemPalette>,
|
|
||||||
last: bool,
|
|
||||||
select: Option<usize>,
|
|
||||||
) -> impl Content<TuiOut> {
|
|
||||||
Fill::x(map_south(offset, height, Fixed::y(height, view_scene_cell(
|
|
||||||
last,
|
|
||||||
select,
|
|
||||||
true,
|
|
||||||
index,
|
|
||||||
&scene.color,
|
|
||||||
prev,
|
|
||||||
Some(scene.name.clone()),
|
|
||||||
" ⯈ ",
|
|
||||||
scene.color.lightest.rgb
|
|
||||||
))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn view_scene_clip <'a> (
|
|
||||||
width: u16,
|
|
||||||
height: u16,
|
|
||||||
offset: u16,
|
|
||||||
scene: &Scene,
|
|
||||||
prev: Option<ItemPalette>,
|
|
||||||
scene_index: usize,
|
|
||||||
track_index: usize,
|
|
||||||
editing: bool,
|
|
||||||
same_track: bool,
|
|
||||||
scene_selected: Option<usize>,
|
|
||||||
scene_is_last: bool,
|
|
||||||
editor: &Option<MidiEditor>,
|
|
||||||
) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
let (name, fg, bg) = if let Some(clip) = &scene.clips[track_index] {
|
|
||||||
let clip = clip.read().unwrap();
|
|
||||||
(Some(clip.name.clone()), clip.color.lightest.rgb, clip.color)
|
|
||||||
} else {
|
|
||||||
(None, Tui::g(96), ItemPalette::G[32])
|
|
||||||
};
|
|
||||||
let active = editing && same_track && scene_selected == Some(scene_index);
|
|
||||||
let edit = |x|Bsp::b(x, When(active, editor));
|
|
||||||
map_south(offset, height, edit(Fixed::y(height, view_scene_cell(
|
|
||||||
scene_is_last,
|
|
||||||
scene_selected,
|
|
||||||
same_track,
|
|
||||||
scene_index,
|
|
||||||
&bg,
|
|
||||||
prev,
|
|
||||||
name,
|
|
||||||
" ⏹ ",
|
|
||||||
fg
|
|
||||||
))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn view_scene_cell <'a> (
|
|
||||||
is_last: bool,
|
|
||||||
selected: Option<usize>,
|
|
||||||
same_track: bool,
|
|
||||||
scene: usize,
|
|
||||||
color: &ItemPalette,
|
|
||||||
prev: Option<ItemPalette>,
|
|
||||||
name: Option<Arc<str>>,
|
|
||||||
icon: &'a str,
|
|
||||||
fg: Color,
|
|
||||||
) -> impl Content<TuiOut> + use<'a> {
|
|
||||||
Phat {
|
|
||||||
width: 0,
|
|
||||||
height: 0,
|
|
||||||
content: Fill::x(Align::w(Tui::bold(true, Bsp::e(icon, name)))),
|
|
||||||
colors: Tek::colors(
|
|
||||||
color,
|
|
||||||
prev,
|
|
||||||
same_track && selected == Some(scene),
|
|
||||||
same_track && scene > 0 && selected == Some(scene - 1),
|
|
||||||
is_last
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)] #[test] fn test_view_scene () {
|
|
||||||
let mut output = TuiOut::default();
|
|
||||||
output.area[2] = 9;
|
|
||||||
output.area[3] = 9;
|
|
||||||
|
|
||||||
Content::render(&view_scenes(), &mut output);
|
|
||||||
}
|
|
||||||
|
|
@ -1,52 +1,197 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
|
impl<'a> ArrangerView<'a> {
|
||||||
width: u16,
|
|
||||||
tracks: impl Fn() -> U + Send + Sync + 'a,
|
|
||||||
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
Align::x(Tui::bg(Reset, Map::new(tracks, move|(index, track, x1, x2), _|{
|
|
||||||
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<TuiOut> + 'a, U: TracksSizes<'a>> (
|
/// Render track headers
|
||||||
width: u16,
|
pub(crate) fn tracks (&self) -> impl Content<TuiOut> + 'a {
|
||||||
tracks: impl Fn() -> U + Send + Sync + 'a,
|
|
||||||
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
|
||||||
) -> impl Content<TuiOut> + 'a {
|
|
||||||
per_track_top(width, tracks, move|index, track|Fill::y(Align::y(callback(index, track))))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn view_tracks <'a, T, U> (
|
|
||||||
w_mid: u16,
|
|
||||||
w_side: u16,
|
|
||||||
track_count: &'a Arc<RwLock<String>>,
|
|
||||||
tracks_sizes: U,
|
|
||||||
selected: Option<usize>,
|
|
||||||
editing: bool,
|
|
||||||
) -> impl Content<TuiOut> + use<'a, T, U> where
|
|
||||||
T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a
|
|
||||||
{
|
|
||||||
let callback = |t, track|view_track_header(t, track, selected == Some(t));
|
|
||||||
Tryptich::center(1)
|
Tryptich::center(1)
|
||||||
.left(w_side, button_3("t", "track", track_count, editing))
|
.left(self.width_side,
|
||||||
.middle(w_mid, per_track(w_mid, tracks_sizes, callback))
|
button_3("t", "track", self.track_count, self.is_editing))
|
||||||
.right(w_side, button_2("T", "add track", editing))
|
.right(self.width_side,
|
||||||
|
button_2("T", "add track", self.is_editing))
|
||||||
|
.middle(self.width_middle,
|
||||||
|
per_track(
|
||||||
|
self.width_middle,
|
||||||
|
self.tracks_sizes,
|
||||||
|
|t, track|view_track_header(t, track, self.track_selected == Some(t))))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render scenes with clips
|
||||||
|
pub(crate) fn scenes (&self) -> impl Content<TuiOut> + 'a {
|
||||||
|
Tui::bg(Reset, Bsp::s(self.track_scroll,
|
||||||
|
Bsp::e(self.scene_scroll,
|
||||||
|
Fixed::y(self.scenes_height,
|
||||||
|
Tryptich::center(self.scenes_height)
|
||||||
|
.left(self.width_side,
|
||||||
|
Map::new(self.scenes_with_scene_colors(), self.scene_name()))
|
||||||
|
.middle(self.width_mid,
|
||||||
|
per_track(self.width_mid, self.track_sizes(), self.scene_track()))))))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scene_add (&self) -> impl Content<TuiOut> + 'a {
|
||||||
|
let editing = self.is_editing();
|
||||||
|
let data = (self.selected().scene().unwrap_or(0), self.scenes().len());
|
||||||
|
self.fmtd.write().unwrap().scns.update(Some(data), rewrite!(buf, "({}/{})", data.0, data.1));
|
||||||
|
button_3("S", "add scene", self.fmtd.read().unwrap().scns.view.clone(), editing)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scene_name (&self) -> impl Content<TuiOut> + 'a {
|
||||||
|
let width = self.width_full;
|
||||||
|
let scene_last = self.scene_last;
|
||||||
|
let scene_selected = self.scene_selected;
|
||||||
|
move|(index, scene, y1, y2, previous): SceneWithColor, _|{
|
||||||
|
let offset = y1 as u16;
|
||||||
|
let height = (1 + y2 - y1) as u16;
|
||||||
|
let is_last = scene_last == index;
|
||||||
|
view_scene_name(width, height, offset, index, scene, previous, is_last, scene_selected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scenes_with_scene_colors (&'a self) -> impl ScenesColors<'a> {
|
||||||
|
self.app.scenes_with_colors(
|
||||||
|
self.is_editing,
|
||||||
|
self.tracks_height
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scenes_with_track_colors (&'a self) -> impl ScenesColors<'a> {
|
||||||
|
self.app.scenes_with_track_colors(
|
||||||
|
self.is_editing,
|
||||||
|
self.tracks_height,
|
||||||
|
self.track_selected.unwrap_or(0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn track_counter (&'a self) -> Arc<RwLock<String>> {
|
||||||
|
let track_counter_data = (self.track_selected.unwrap_or(0), self.tracks().len());
|
||||||
|
let track_counter = rewrite!(buf, "{}/{}", track_counter_data.0, track_counter_data.1);
|
||||||
|
self.app.fmtd.write().unwrap().trks.update(Some(track_counter_data), track_counter);
|
||||||
|
self.app.fmtd.read().unwrap().trks.view.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scene_track (&self) -> impl Content<TuiOut> + 'a {
|
||||||
|
move|track_index, track|Map::new(
|
||||||
|
self.scenes_with_track_colors(),
|
||||||
|
move|(scene_index, scene, y1, y2, prev_scene): SceneWithColor, _|view_scene_clip(
|
||||||
|
self.width_mid,
|
||||||
|
(1 + y2 - y1) as u16,
|
||||||
|
y1 as u16,
|
||||||
|
scene,
|
||||||
|
prev_scene,
|
||||||
|
scene_index,
|
||||||
|
track_index,
|
||||||
|
self.is_editing,
|
||||||
|
self.track_selected == Some(track_index),
|
||||||
|
self.scene_selected,
|
||||||
|
self.scene_last == scene_index,
|
||||||
|
self.app.editor
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_track_header <'a> (t: usize, track: &'a Track, active: bool) -> impl Content<TuiOut> + use<'a> {
|
fn view_track_header <'a> (
|
||||||
|
index: usize,
|
||||||
|
track: &'a Track,
|
||||||
|
active: bool
|
||||||
|
) -> impl Content<TuiOut> + use<'a> {
|
||||||
let fg = track.color.lightest.rgb;
|
let fg = track.color.lightest.rgb;
|
||||||
let bg = if active { track.color.light.rgb } else { track.color.base.rgb };
|
let bg = if active { track.color.light.rgb } else { track.color.base.rgb };
|
||||||
let bg2 = Reset;//if t > 0 { self.tracks()[t - 1].color.base.rgb } else { Reset };
|
let bg2 = Reset;//if index > 0 { self.tracks()[index - 1].color.base.rgb } else { Reset };
|
||||||
wrap(bg, fg, Tui::bold(true, Fill::x(Align::nw(&track.name))))
|
wrap(bg, fg, Tui::bold(true, Fill::x(Align::nw(&track.name))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn view_scene_name (
|
||||||
|
width: u16,
|
||||||
|
height: u16,
|
||||||
|
offset: u16,
|
||||||
|
index: usize,
|
||||||
|
scene: &Scene,
|
||||||
|
prev: Option<ItemPalette>,
|
||||||
|
last: bool,
|
||||||
|
select: Option<usize>,
|
||||||
|
) -> impl Content<TuiOut> {
|
||||||
|
Fill::x(map_south(offset, height, Fixed::y(height, view_scene_cell(
|
||||||
|
last,
|
||||||
|
select,
|
||||||
|
true,
|
||||||
|
index,
|
||||||
|
&scene.color,
|
||||||
|
prev,
|
||||||
|
Some(scene.name.clone()),
|
||||||
|
" ⯈ ",
|
||||||
|
scene.color.lightest.rgb
|
||||||
|
))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn view_scene_clip <'a> (
|
||||||
|
width: u16,
|
||||||
|
height: u16,
|
||||||
|
offset: u16,
|
||||||
|
scene: &Scene,
|
||||||
|
prev: Option<ItemPalette>,
|
||||||
|
scene_index: usize,
|
||||||
|
track_index: usize,
|
||||||
|
editing: bool,
|
||||||
|
same_track: bool,
|
||||||
|
scene_selected: Option<usize>,
|
||||||
|
scene_is_last: bool,
|
||||||
|
editor: &Option<MidiEditor>,
|
||||||
|
) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
let (name, fg, bg) = if let Some(clip) = &scene.clips[track_index] {
|
||||||
|
let clip = clip.read().unwrap();
|
||||||
|
(Some(clip.name.clone()), clip.color.lightest.rgb, clip.color)
|
||||||
|
} else {
|
||||||
|
(None, Tui::g(96), ItemPalette::G[32])
|
||||||
|
};
|
||||||
|
let active = editing && same_track && scene_selected == Some(scene_index);
|
||||||
|
let edit = |x|Bsp::b(x, When(active, editor));
|
||||||
|
map_south(offset, height, edit(Fixed::y(height, view_scene_cell(
|
||||||
|
scene_is_last,
|
||||||
|
scene_selected,
|
||||||
|
same_track,
|
||||||
|
scene_index,
|
||||||
|
&bg,
|
||||||
|
prev,
|
||||||
|
name,
|
||||||
|
" ⏹ ",
|
||||||
|
fg
|
||||||
|
))))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn view_scene_cell <'a> (
|
||||||
|
is_last: bool,
|
||||||
|
selected: Option<usize>,
|
||||||
|
same_track: bool,
|
||||||
|
scene: usize,
|
||||||
|
color: &ItemPalette,
|
||||||
|
prev: Option<ItemPalette>,
|
||||||
|
name: Option<Arc<str>>,
|
||||||
|
icon: &'a str,
|
||||||
|
fg: Color,
|
||||||
|
) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
Phat {
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
content: Fill::x(Align::w(Tui::bold(true, Bsp::e(icon, name)))),
|
||||||
|
colors: Tek::colors(
|
||||||
|
color,
|
||||||
|
prev,
|
||||||
|
same_track && selected == Some(scene),
|
||||||
|
same_track && scene > 0 && selected == Some(scene - 1),
|
||||||
|
is_last
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)] #[test] fn test_view_scene () {
|
||||||
|
let mut output = TuiOut::default();
|
||||||
|
output.area[2] = 9;
|
||||||
|
output.area[3] = 9;
|
||||||
|
|
||||||
|
Content::render(&view_scenes(), &mut output);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)] #[test] fn test_view_track () {
|
#[cfg(test)] #[test] fn test_view_track () {
|
||||||
let mut output = TuiOut::default();
|
let mut output = TuiOut::default();
|
||||||
output.area[2] = 9;
|
output.area[2] = 9;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue