freestanding input_ports

This commit is contained in:
🪞👃🪞 2025-03-05 00:41:47 +02:00
parent b9d1a82314
commit 7633813ab2
2 changed files with 91 additions and 44 deletions

View file

@ -182,7 +182,9 @@ impl Tek {
.flatten().as_ref()))),
Thunk::new(||Tui::bg(Reset, " ------ "))));
let nexts = row_top(w, 2, s, Align::ne("Next:"), nexts, ());
let froms = self.per_track_top(|_, _|Tui::bg(Reset, Align::c(Bsp::s(" ------ ", OctaveVertical::default(),))));
let froms = self.per_track_top(
|_, _|Tui::bg(Reset, Align::c(Bsp::s(" ------ ", OctaveVertical::default(),)))
);
let froms = row_top(w, 2, s, Align::ne("From:"), froms, ());
let ports = row_top(w, 1, s,
button_3("o", "midi outs", format!("{}", self.midi_outs.len()), editing),
@ -209,43 +211,23 @@ impl Tek {
}
pub fn view_inputs (&self) -> impl Content<TuiOut> + use<'_> {
let editing = self.is_editing();
let w = (self.size.w() as u16).saturating_sub(2 * self.w_sidebar());
let s = self.w_sidebar() as u16;
let fg = Tui::g(224);
let routes = row_top(w, self.h_inputs() - 1, s,
io_ports(fg, Tui::g(32), ||self.inputs_sizes()),
self.per_track_top(move|t, track|io_conns(
track.color.dark.rgb,
track.color.darker.rgb,
||self.inputs_sizes()
)), ());
let ports = row_top(w, 1, s,
button_3("i", "midi ins", format!("{}", self.midi_ins.len()), editing),
self.per_track_top(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 self.selected().track() == Some(t) {
track.color.light.rgb
} else {
track.color.base.rgb
};
let bg2 = if t > 0 { self.tracks()[t - 1].color.base.rgb } else { Reset };
wrap(bg, fg, Tui::bold(true, Fill::x(Bsp::e(
Tui::fg_bg(rec, bg, "Rec "),
Tui::fg_bg(mon, bg, "Mon ")))))
}),
button_2("I", "add midi in", editing));
Bsp::s(
Bsp::s(routes, ports),
row_top(w, 2, s,
Bsp::s(Align::e("Input:"), Align::e("Into:")),
self.per_track_top(|_, _|Tui::bg(Reset, Align::c(Bsp::s(
OctaveVertical::default(),
" ------ ")))), ())
)
let bg = Tui::g(32);
let ws = self.w_sidebar() as u16;
let w = (self.size.w() as u16).saturating_sub(2 * ws);
let wt = self.w_tracks_area();
let ts = move||self.tracks_sizes_scrolled();
let is = ||self.inputs_sizes();
let ins = self.midi_ins.len();
let sel = self.selected().track();
let tr = self.tracks().as_ref();
let ed = self.is_editing();
let hi = self.h_inputs() - 1;
let pts = io_ports(fg, bg, is);
let to_conns = move|_, &Track { color, .. }|io_conns(color.dark.rgb, color.darker.rgb, is);
view_inputs(w, ws, wt, ts,
row_top(w, hi, ws, pts, per_track_top(wt, ts, to_conns), ()),
input_ports(w, ws, ins, wt, ts, sel, tr, ed))
}
/// Render something centered for each track.
@ -261,15 +243,73 @@ impl Tek {
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 {
let width = self.w_tracks_area();
let sizes = move||self.tracks_sizes().map_while(move|(t, track, x1, x2)|{
(width > x2 as u16).then_some((t, track, x1, x2))
});
per_track_top(width, sizes, callback)
per_track_top(
self.w_tracks_area(),
move||self.tracks_sizes_scrolled(),
callback
)
}
}
fn view_inputs <'a, T, U, V, W> (
w: u16,
s: u16,
w_tracks_area: u16,
tracks_sizes: U,
routes: V,
ports: W,
) -> impl Content<TuiOut> + use<'a, T, U, V, W> where
T: TracksSizes<'a>,
U: Fn()->T + Send + Sync + 'a,
V: Content<TuiOut>,
W: Content<TuiOut>,
{
let headers = Bsp::s(Align::e("Input:"), Align::e("Into:"));
let separators = per_track_top(
w_tracks_area,
tracks_sizes,
|_, _|Tui::bg(Reset, Align::c(Bsp::s( OctaveVertical::default(), " ------ ")))
);
Bsp::s(Bsp::s(routes, ports), row_top(w, 2, s, headers, separators, ()))
}
fn input_ports <'a, T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a> (
w: u16,
s: u16,
midi_ins: usize,
w_tracks_area: u16,
tracks_sizes: U,
selected_track: Option<usize>,
tracks: &'a [Track],
editing: bool,
) -> impl Content<TuiOut> + use<'a, T, U> {
let fg = Tui::g(224);
let btn_ins = button_3("i", "midi ins", format!("{}", midi_ins), editing);
let btn_add = button_2("I", "add midi in", editing);
let inputs = per_track_top(
w_tracks_area,
tracks_sizes,
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 { tracks[t - 1].color.base.rgb } else { Reset };
wrap(bg, fg, Tui::bold(true, Fill::x(Bsp::e(
Tui::fg_bg(rec, bg, "Rec "),
Tui::fg_bg(mon, bg, "Mon "))
)))
}
);
row_top(w, 1, s, btn_ins, inputs, btn_add)
}
fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
width: u16,
tracks: impl Fn() -> U + Send + Sync + 'a,
@ -280,7 +320,8 @@ fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
map_east(x1 as u16, width, Fixed::x(width, Tui::fg_bg(
track.color.lightest.rgb,
track.color.base.rgb,
callback(index, track))))
callback(index, track)
)))
})))
}

View file

@ -34,6 +34,12 @@ impl Tek {
data
})
}
pub(crate) fn tracks_sizes_scrolled <'a> (&'a self) -> impl TracksSizes<'a> {
let width = self.w_tracks_area();
self.tracks_sizes().map_while(move|(t, track, x1, x2)|{
(width > x2 as u16).then_some((t, track, x1, x2))
})
}
pub(crate) fn scenes_sizes (&self, editing: bool, height: usize, larger: usize) -> impl ScenesSizes<'_> {
let (selected_track, selected_scene) = match self.selected() {
Selection::Track(t) => (Some(*t), None),