mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-05-02 14:50:14 +02:00
wip: build arranger out of freestanding functions
This commit is contained in:
parent
4dbbe0340a
commit
4229364363
|
@ -6,7 +6,6 @@ atom_command!(InputCommand: |app: Tek| {
|
|||
command!(|self: InputCommand, app: Tek|match self {
|
||||
Self::Add => {
|
||||
app.midi_ins.push(JackMidiIn::new(&app.jack, &format!("M/{}", app.midi_ins.len()), &[])?);
|
||||
app.redraw_arranger();
|
||||
None
|
||||
},
|
||||
});
|
||||
|
|
|
@ -6,7 +6,6 @@ atom_command!(OutputCommand: |app: Tek| {
|
|||
command!(|self: OutputCommand, app: Tek|match self {
|
||||
Self::Add => {
|
||||
app.midi_outs.push(JackMidiOut::new(&app.jack, &format!("{}/M", app.midi_outs.len()), &[])?);
|
||||
app.redraw_arranger();
|
||||
None
|
||||
},
|
||||
});
|
||||
|
|
|
@ -8,7 +8,6 @@ impl Tek {
|
|||
scene_color_1.mix(scene_color_2, i as f32 / n as f32).into()
|
||||
))?;
|
||||
}
|
||||
self.redraw_arranger();
|
||||
Ok(())
|
||||
}
|
||||
pub fn scene_add (&mut self, name: Option<&str>, color: Option<ItemPalette>)
|
||||
|
|
|
@ -14,7 +14,6 @@ impl Tek {
|
|||
track.width = width;
|
||||
}
|
||||
}
|
||||
self.redraw_arranger();
|
||||
Ok(())
|
||||
}
|
||||
pub fn track_add (
|
||||
|
|
|
@ -6,22 +6,27 @@ mod view_iter; pub use self::view_iter::*;
|
|||
mod view_memo; pub use self::view_memo::*;
|
||||
mod view_meter; pub use self::view_meter::*;
|
||||
mod view_sizes; pub use self::view_sizes::*;
|
||||
mod view_track; pub use self::view_track::*;
|
||||
mod view_scene; pub use self::view_scene::*;
|
||||
mod view_input; pub use self::view_input::*;
|
||||
mod view_output; pub use self::view_output::*;
|
||||
mod view_layout; pub use self::view_layout::*;
|
||||
pub(crate) use std::fmt::Write;
|
||||
pub(crate) use ::tek_tui::ratatui::prelude::Position;
|
||||
pub(crate) trait ScenesColors<'a> = Iterator<Item=SceneWithColor<'a>>;
|
||||
pub(crate) trait ScenesColors<'a> = Iterator<Item=SceneWithColor<'a>>;
|
||||
pub(crate) type SceneWithColor<'a> = (usize, &'a Scene, usize, usize, Option<ItemPalette>);
|
||||
view!(TuiOut: |self: Tek| self.size.of(View(self, self.view)); {
|
||||
//":inputs" => self.view_inputs().boxed(),
|
||||
//":outputs" => self.view_outputs().boxed(),
|
||||
//":scene-add" => self.view_scene_add().boxed(),
|
||||
//":scenes" => self.view_scenes().boxed(),
|
||||
//":tracks" => self.view_tracks().boxed(),
|
||||
":arranger" => self.view_arranger().boxed(),
|
||||
":editor" => self.editor.as_ref().map(|e|Bsp::e(e.clip_status(), e.edit_status())).boxed(),
|
||||
":inputs" => self.view_inputs().boxed(),
|
||||
":outputs" => self.view_outputs().boxed(),
|
||||
":sample" => ().boxed(),//self.view_sample(self.is_editing()).boxed(),
|
||||
":sampler" => ().boxed(),//self.view_sampler(self.is_editing(), &self.editor).boxed(),
|
||||
":scene-add" => self.view_scene_add().boxed(),
|
||||
":scenes" => self.view_scenes().boxed(),
|
||||
":transport" => self.view_transport().boxed(),
|
||||
":status" => self.view_status().boxed(),
|
||||
":tracks" => self.view_tracks().boxed(),
|
||||
":transport" => self.view_transport().boxed(),
|
||||
":pool" => self.pool.as_ref()
|
||||
.map(|pool|Fixed::x(self.w_sidebar(), PoolView(self.is_editing(), pool)))
|
||||
.boxed(),
|
||||
|
|
|
@ -1,417 +1,66 @@
|
|||
use crate::*;
|
||||
|
||||
/// A three-column row.
|
||||
struct Tryptich<A, B, C> {
|
||||
pub top: bool,
|
||||
pub h: u16,
|
||||
pub left: (u16, A),
|
||||
pub middle: (u16, B),
|
||||
pub right: (u16, C),
|
||||
}
|
||||
impl Tryptich<(), (), ()> {
|
||||
fn center (h: u16) -> Self {
|
||||
Self { h, top: false, left: (0, ()), middle: (0, ()), right: (0, ()) }
|
||||
}
|
||||
fn top (h: u16) -> Self {
|
||||
Self { h, top: true, left: (0, ()), middle: (0, ()), right: (0, ()) }
|
||||
}
|
||||
}
|
||||
impl<A, B, C> Tryptich<A, B, C> {
|
||||
fn left <D> (self, w: u16, content: D) -> Tryptich<D, B, C> {
|
||||
Tryptich { left: (w, content), ..self }
|
||||
}
|
||||
fn middle <D> (self, w: u16, content: D) -> Tryptich<A, D, C> {
|
||||
Tryptich { middle: (w, content), ..self }
|
||||
}
|
||||
fn right <D> (self, w: u16, content: D) -> Tryptich<A, B, D> {
|
||||
Tryptich { right: (w, content), ..self }
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, B, C> Content<TuiOut> for Tryptich<A, B, C>
|
||||
where A: Content<TuiOut>, B: Content<TuiOut>, C: Content<TuiOut> {
|
||||
fn content (&self) -> impl Render<TuiOut> {
|
||||
let Self { top, h, left: (w_a, ref a), middle: (w_b, ref b), right: (w_c, ref c) } = *self;
|
||||
if top {
|
||||
Fixed::y(h, Bsp::a(
|
||||
Fill::x(Align::n(Fixed::x(w_b, Align::x(Tui::bg(Reset, b))))),
|
||||
Bsp::a(
|
||||
Fill::x(Align::nw(Fixed::x(w_a, Tui::bg(Reset, a)))),
|
||||
Fill::x(Align::ne(Fixed::x(w_c, Tui::bg(Reset, c)))),
|
||||
),
|
||||
))
|
||||
} else {
|
||||
Fixed::y(h, Bsp::a(
|
||||
Fill::xy(Align::c(Fixed::x(w_b, Align::x(Tui::bg(Reset, b))))),
|
||||
Bsp::a(
|
||||
Fill::xy(Align::w(Fixed::x(w_a, Tui::bg(Reset, a)))),
|
||||
Fill::xy(Align::e(Fixed::x(w_c, Tui::bg(Reset, c)))),
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Tek {
|
||||
|
||||
pub fn redraw_arranger (&self) { /*FIXME: remove*/ }
|
||||
|
||||
/// Render the arranger.
|
||||
pub fn view_arranger (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
let inputs = self.view_inputs();
|
||||
let tracks = self.view_tracks();
|
||||
let scenes = self.view_scenes();
|
||||
let outputs = self.view_outputs();
|
||||
Bsp::s(inputs, Bsp::s(tracks, Bsp::n(outputs, scenes)))
|
||||
}
|
||||
|
||||
pub fn view_tracks (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
let w = (self.size.w() as u16).saturating_sub(2 * self.w_sidebar());
|
||||
let s = self.w_sidebar() as u16;
|
||||
let data = (self.selected.track().unwrap_or(0), self.tracks().len());
|
||||
let editing = self.is_editing();
|
||||
self.fmtd.write().unwrap().trks.update(Some(data), rewrite!(buf, "{}/{}", data.0, data.1));
|
||||
Tryptich::center(1)
|
||||
.left(s,
|
||||
button_3("t", "track", self.fmtd.read().unwrap().trks.view.clone(), editing))
|
||||
.middle(w,
|
||||
self.per_track(|t, track|track_header(t, track, self.selected().track() == Some(t))))
|
||||
.right(s,
|
||||
button_2("T", "add track", editing))
|
||||
}
|
||||
|
||||
pub fn view_scenes (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
let editing = self.is_editing();
|
||||
let s = self.w_sidebar() as u16;
|
||||
let w = self.w_tracks_area();
|
||||
let w_full = self.w();
|
||||
let h = self.h_scenes();
|
||||
let h_area = self.h_tracks_area();
|
||||
let st = self.selected().track();
|
||||
let ss = self.selected().scene();
|
||||
let track_scroll = {
|
||||
let offset = self.track_scroll;
|
||||
let length = self.w_tracks_area() as usize;
|
||||
let total = self.w_tracks() as usize;
|
||||
Fill::x(Fixed::y(1, ScrollbarH { offset, length, total }))
|
||||
};
|
||||
let scene_scroll = {
|
||||
let offset = self.scene_scroll;
|
||||
let length = self.h_tracks_area() as usize;
|
||||
let total = self.h_scenes() as usize;
|
||||
Fill::y(Fixed::x(1, ScrollbarV { offset, length, total }))
|
||||
};
|
||||
let row = Tryptich::center(h)
|
||||
.left(s, Map::new(
|
||||
move||self.scenes_with_colors(editing, h_area),
|
||||
move|(s, scene, y1, y2, prev): SceneWithColor, _|view_scene_name(
|
||||
w_full,
|
||||
(1 + y2 - y1) as u16,
|
||||
y1 as u16,
|
||||
s,
|
||||
scene,
|
||||
prev,
|
||||
s == self.scenes.len().saturating_sub(1),
|
||||
self.selected().scene(),
|
||||
)
|
||||
))
|
||||
.middle(w, self.per_track(move|t, track|Map::new(
|
||||
move||self.scenes_with_track_colors(editing, h_area, t),
|
||||
move|(s, scene, y1, y2, prev): SceneWithColor, _|self.view_scene_clip(
|
||||
w, (1 + y2 - y1) as u16, y1 as u16,
|
||||
scene, prev, s, t, editing, st == Some(t), ss)
|
||||
)));
|
||||
Tui::bg(Reset, Bsp::s(track_scroll, Bsp::e(scene_scroll, Fixed::y(h_area, row))))
|
||||
}
|
||||
|
||||
fn view_scene_clip (
|
||||
&self,
|
||||
width: u16,
|
||||
height: u16,
|
||||
offset: u16,
|
||||
scene: &Scene,
|
||||
prev: Option<ItemPalette>,
|
||||
scene_index: usize,
|
||||
track_index: usize,
|
||||
editing: bool,
|
||||
same_track: bool,
|
||||
selected_scene: Option<usize>
|
||||
) -> impl Content<TuiOut> + use<'_> {
|
||||
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 && selected_scene == Some(scene_index);
|
||||
let edit = |x|Bsp::b(x, When(active, &self.editor));
|
||||
map_south(offset, height, edit(Fixed::y(height, scene_cell(
|
||||
scene_index == self.scenes.len().saturating_sub(1),
|
||||
self.selected().scene(),
|
||||
same_track,
|
||||
scene_index,
|
||||
&bg,
|
||||
prev,
|
||||
name,
|
||||
" ⏹ ",
|
||||
fg
|
||||
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 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 fn view_outputs (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
let height = self.h_outputs().saturating_sub(1);
|
||||
let w_mid = self.w_tracks_area();
|
||||
let w_side = self.w_sidebar() as u16;
|
||||
let tracks = ||self.tracks_sizes_scrolled();
|
||||
view_outputs(
|
||||
view_output_nexts(w_mid, w_side, tracks),
|
||||
view_output_froms(w_mid, w_side, tracks),
|
||||
view_output_conns(w_mid, w_side, tracks, height, ||self.outputs_sizes()),
|
||||
view_output_ports(w_mid, w_side, tracks,
|
||||
self.midi_outs.len(), self.selected().track(), self.is_editing()))
|
||||
}
|
||||
|
||||
pub fn view_inputs (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
let height = self.h_inputs().saturating_sub(1);
|
||||
let w_mid = self.w_tracks_area();
|
||||
let w_side = self.w_sidebar() as u16;
|
||||
let tracks = ||self.tracks_sizes_scrolled();
|
||||
view_inputs(
|
||||
view_input_intos(w_mid, w_side, tracks),
|
||||
view_input_routes(w_mid, w_side, tracks, height, ||self.inputs_sizes()),
|
||||
view_input_ports(w_mid, w_side, tracks,
|
||||
self.midi_ins.len(), self.selected().track(), self.is_editing()))
|
||||
}
|
||||
|
||||
/// Render something centered for each track.
|
||||
fn per_track <'a, T: Content<TuiOut> + 'a> (
|
||||
&'a self, f: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
||||
) -> impl Content<TuiOut> + 'a {
|
||||
self.per_track_top(move|index, track|Fill::y(Align::y(f(index, track))))
|
||||
}
|
||||
|
||||
/// Render something top-aligned for each track.
|
||||
fn per_track_top <'a, T: Content<TuiOut> + 'a> (
|
||||
&'a self, callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
|
||||
) -> impl Content<TuiOut> + 'a {
|
||||
per_track_top(self.w_tracks_area(), move||self.tracks_sizes_scrolled(), callback)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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, scene_cell(
|
||||
last,
|
||||
select,
|
||||
true,
|
||||
index,
|
||||
&scene.color,
|
||||
prev,
|
||||
Some(scene.name.clone()),
|
||||
" ⯈ ",
|
||||
scene.color.lightest.rgb
|
||||
))))
|
||||
}
|
||||
|
||||
fn view_inputs <'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: 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, 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> 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)
|
||||
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,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
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 "),
|
||||
))))
|
||||
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,
|
||||
}))
|
||||
}
|
||||
|
||||
fn view_outputs <'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: 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), 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: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a> (
|
||||
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> {
|
||||
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|t, track|{
|
||||
let mute = false;
|
||||
let solo = false;
|
||||
let mute = if mute { White } else { track.color.darkest.rgb };
|
||||
let solo = if solo { White } else { track.color.darkest.rgb };
|
||||
let bg1 = 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(bg1, Tui::g(224), Tui::bold(true, Fill::x(Bsp::e(
|
||||
Tui::fg_bg(mute, bg1, "Play "),
|
||||
Tui::fg_bg(solo, bg1, "Solo "),
|
||||
))))
|
||||
}))
|
||||
}
|
||||
|
||||
fn per_track_top <'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 {
|
||||
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)
|
||||
)))
|
||||
})))
|
||||
}
|
||||
|
||||
fn 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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn track_header <'a> (t: usize, track: &'a Track, active: bool) -> impl Content<TuiOut> + use<'a> {
|
||||
let fg = track.color.lightest.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 };
|
||||
wrap(bg, fg, Tui::bold(true, Fill::x(Align::nw(&track.name))))
|
||||
}
|
||||
|
||||
fn io_ports <'a, T: PortsSizes<'a>> (
|
||||
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,
|
||||
|
@ -422,7 +71,7 @@ fn io_ports <'a, T: PortsSizes<'a>> (
|
|||
&connect.info)))))))))
|
||||
}
|
||||
|
||||
fn io_conns <'a, T: PortsSizes<'a>> (
|
||||
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,
|
||||
|
@ -432,55 +81,50 @@ fn io_conns <'a, T: PortsSizes<'a>> (
|
|||
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;
|
||||
//#[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), &[], &[]);
|
||||
//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(&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);
|
||||
|
||||
app.redraw_arranger();
|
||||
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_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_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(
|
||||
//&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(
|
||||
&track_header(0, &Default::default(), true),
|
||||
&mut output);
|
||||
|
||||
Content::render(&scene_cell(
|
||||
false,
|
||||
None,
|
||||
false,
|
||||
0,
|
||||
&Default::default(),
|
||||
None,
|
||||
None,
|
||||
&"",
|
||||
Default::default(),
|
||||
), &mut output);
|
||||
}
|
||||
}
|
||||
//Content::render(&view_scene_cell(
|
||||
//false,
|
||||
//None,
|
||||
//false,
|
||||
//0,
|
||||
//&Default::default(),
|
||||
//None,
|
||||
//None,
|
||||
//&"",
|
||||
//Default::default(),
|
||||
//), &mut output);
|
||||
//}
|
||||
//}
|
||||
|
|
92
app/src/view/view_input.rs
Normal file
92
app/src/view/view_input.rs
Normal file
|
@ -0,0 +1,92 @@
|
|||
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);
|
||||
}
|
55
app/src/view/view_layout.rs
Normal file
55
app/src/view/view_layout.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use crate::*;
|
||||
|
||||
/// A three-column layout.
|
||||
pub(crate) struct Tryptich<A, B, C> {
|
||||
pub top: bool,
|
||||
pub h: u16,
|
||||
pub left: (u16, A),
|
||||
pub middle: (u16, B),
|
||||
pub right: (u16, C),
|
||||
}
|
||||
|
||||
impl Tryptich<(), (), ()> {
|
||||
pub fn center (h: u16) -> Self {
|
||||
Self { h, top: false, left: (0, ()), middle: (0, ()), right: (0, ()) }
|
||||
}
|
||||
pub fn top (h: u16) -> Self {
|
||||
Self { h, top: true, left: (0, ()), middle: (0, ()), right: (0, ()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, B, C> Tryptich<A, B, C> {
|
||||
pub fn left <D> (self, w: u16, content: D) -> Tryptich<D, B, C> {
|
||||
Tryptich { left: (w, content), ..self }
|
||||
}
|
||||
pub fn middle <D> (self, w: u16, content: D) -> Tryptich<A, D, C> {
|
||||
Tryptich { middle: (w, content), ..self }
|
||||
}
|
||||
pub fn right <D> (self, w: u16, content: D) -> Tryptich<A, B, D> {
|
||||
Tryptich { right: (w, content), ..self }
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, B, C> Content<TuiOut> for Tryptich<A, B, C>
|
||||
where A: Content<TuiOut>, B: Content<TuiOut>, C: Content<TuiOut> {
|
||||
fn content (&self) -> impl Render<TuiOut> {
|
||||
let Self { top, h, left: (w_a, ref a), middle: (w_b, ref b), right: (w_c, ref c) } = *self;
|
||||
if top {
|
||||
Fixed::y(h, Bsp::a(
|
||||
Fill::x(Align::n(Fixed::x(w_b, Align::x(Tui::bg(Reset, b))))),
|
||||
Bsp::a(
|
||||
Fill::x(Align::nw(Fixed::x(w_a, Tui::bg(Reset, a)))),
|
||||
Fill::x(Align::ne(Fixed::x(w_c, Tui::bg(Reset, c)))),
|
||||
),
|
||||
))
|
||||
} else {
|
||||
Fixed::y(h, Bsp::a(
|
||||
Fill::xy(Align::c(Fixed::x(w_b, Align::x(Tui::bg(Reset, b))))),
|
||||
Bsp::a(
|
||||
Fill::xy(Align::w(Fixed::x(w_a, Tui::bg(Reset, a)))),
|
||||
Fill::xy(Align::e(Fixed::x(w_c, Tui::bg(Reset, c)))),
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
104
app/src/view/view_output.rs
Normal file
104
app/src/view/view_output.rs
Normal file
|
@ -0,0 +1,104 @@
|
|||
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);
|
||||
}
|
149
app/src/view/view_scene.rs
Normal file
149
app/src/view/view_scene.rs
Normal file
|
@ -0,0 +1,149 @@
|
|||
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);
|
||||
}
|
|
@ -57,17 +57,14 @@ impl Tek {
|
|||
.map(|(_, _, _, y)|y as u16).unwrap_or(0)
|
||||
}
|
||||
}
|
||||
#[cfg(test)] mod test {
|
||||
use super::*;
|
||||
#[test] fn test_view_size () {
|
||||
let app = Tek::default();
|
||||
let _ = app.w();
|
||||
let _ = app.w_sidebar();
|
||||
let _ = app.w_tracks_area();
|
||||
let _ = app.h();
|
||||
let _ = app.h_tracks_area();
|
||||
let _ = app.h_inputs();
|
||||
let _ = app.h_outputs();
|
||||
let _ = app.h_scenes();
|
||||
}
|
||||
#[cfg(test)] #[test] fn test_view_sizes () {
|
||||
let app = Tek::default();
|
||||
let _ = app.w();
|
||||
let _ = app.w_sidebar();
|
||||
let _ = app.w_tracks_area();
|
||||
let _ = app.h();
|
||||
let _ = app.h_tracks_area();
|
||||
let _ = app.h_inputs();
|
||||
let _ = app.h_outputs();
|
||||
let _ = app.h_scenes();
|
||||
}
|
||||
|
|
56
app/src/view/view_track.rs
Normal file
56
app/src/view/view_track.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use crate::*;
|
||||
|
||||
pub(crate) fn per_track_top <'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 {
|
||||
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))))
|
||||
}
|
||||
|
||||
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)
|
||||
.left(w_side, button_3("t", "track", track_count, editing))
|
||||
.middle(w_mid, per_track(w_mid, tracks_sizes, callback))
|
||||
.right(w_side, button_2("T", "add track", editing))
|
||||
}
|
||||
|
||||
fn view_track_header <'a> (t: usize, track: &'a Track, active: bool) -> impl Content<TuiOut> + use<'a> {
|
||||
let fg = track.color.lightest.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 };
|
||||
wrap(bg, fg, Tui::bold(true, Fill::x(Align::nw(&track.name))))
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_view_track () {
|
||||
let mut output = TuiOut::default();
|
||||
output.area[2] = 9;
|
||||
output.area[3] = 9;
|
||||
|
||||
Content::render(&view_tracks(), &mut output);
|
||||
}
|
Loading…
Reference in a new issue