mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +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
|
|
@ -1,52 +1,197 @@
|
|||
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)
|
||||
)))
|
||||
})))
|
||||
impl<'a> ArrangerView<'a> {
|
||||
|
||||
/// Render track headers
|
||||
pub(crate) fn tracks (&self) -> impl Content<TuiOut> + 'a {
|
||||
Tryptich::center(1)
|
||||
.left(self.width_side,
|
||||
button_3("t", "track", self.track_count, self.is_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
|
||||
))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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> {
|
||||
fn view_track_header <'a> (
|
||||
index: 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 };
|
||||
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))))
|
||||
}
|
||||
|
||||
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 () {
|
||||
let mut output = TuiOut::default();
|
||||
output.area[2] = 9;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue