unify view_clips

This commit is contained in:
🪞👃🪞 2025-02-08 22:34:32 +01:00
parent 7b3bbc5590
commit d1bb33dc41
11 changed files with 168 additions and 128 deletions

View file

@ -6,8 +6,8 @@ mod keymap; pub use self::keymap::*;
pub(crate) use ::tek_edn::*;
/// Standard error trait.
pub(crate) use std::error::Error;
/// Standard result type.
pub(crate) type Usually<T> = Result<T, Box<dyn Error>>;
///// Standard result type.
//pub(crate) type Usually<T> = Result<T, Box<dyn Error>>;
/// Standard optional result type.
pub(crate) type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
#[cfg(test)] #[test] fn test_stub_input () -> Usually<()> {

View file

@ -7,7 +7,8 @@ pub(crate) use PortConnectScope::*;
pub(crate) use PortConnectStatus::*;
pub(crate) use std::sync::{Arc, RwLock};
pub use ::jack; pub(crate) use ::jack::{
contrib::ClosureProcessHandler, NotificationHandler,
//contrib::ClosureProcessHandler,
NotificationHandler,
Client, AsyncClient, ClientOptions, ClientStatus,
ProcessScope, Control, Frames,
Port, PortId, PortSpec, PortFlags,

View file

@ -9,7 +9,7 @@ pub struct TekCli {
#[arg(short='n', long)] name: Option<String>,
/// Whether to attempt to become transport master
#[arg(short='S', long, default_value_t = false)] sync_lead: bool,
/// Whether to sync to external transport master
/// Whether to sync to external transport master
#[arg(short='s', long, default_value_t = true)] sync_follow: bool,
/// Initial tempo in beats per minute
#[arg(short='b', long, default_value = None)] bpm: Option<f64>,
@ -196,6 +196,10 @@ impl Tek {
arranger.scenes_add(scenes);
arranger.tracks_add(tracks, Some(track_width), &[], &[]);
arranger.selected = Selection::Clip(1, 1);
arranger.arranger = BigBuffer::new(
arranger.w_tracks() as usize,
arranger.h_scenes() as usize,
);
Ok(arranger)
}
}

View file

@ -24,9 +24,8 @@ mod model_select; pub use self::model_select::*;
mod view; pub use self::view::*;
mod view_memo; pub use self::view_memo::*;
mod view_clock; pub use self::view_clock::*;
mod view_clips; pub use self::view_clips::*;
mod view_meter; pub use self::view_meter::*;
mod view_scene; pub use self::view_scene::*;
mod view_track; pub use self::view_track::*;
mod view_input; pub use self::view_input::*;
mod view_output; pub use self::view_output::*;
/// Standard result type.

View file

@ -6,18 +6,25 @@ use crate::*;
pub clock: Clock,
/// Theme
pub color: ItemPalette,
/// Contains all clips in the project
pub pool: Option<MidiPool>,
/// Contains the currently edited MIDI clip
pub editor: Option<MidiEditor>,
pub midi_buf: Vec<Vec<Vec<u8>>>,
/// Contains the project arrangement
pub arranger: BigBuffer,
pub midi_ins: Vec<JackMidiIn>,
pub midi_outs: Vec<JackMidiOut>,
pub audio_ins: Vec<JackAudioIn>,
pub audio_outs: Vec<JackAudioOut>,
pub note_buf: Vec<u8>,
pub midi_buf: Vec<Vec<Vec<u8>>>,
pub tracks: Vec<Track>,
pub track_scroll: usize,
pub scenes: Vec<Scene>,
pub scene_scroll: usize,
pub selected: Selection,
pub size: Measure<TuiOut>,
pub perf: PerfModel,

View file

@ -104,15 +104,15 @@ impl Tek {
content: impl Content<TuiOut> + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
let count = format!("{count}");
Fill::xy(Align::w(Bsp::s(Fill::x(Align::w(self.button3(key, label, count))), content)))
Fill::xy(Align::w(Bsp::s(Fill::x(Align::w(self.button_3(key, label, count))), content)))
}
pub(crate) fn button2 <'a, K, L> (&'a self, key: K, label: L) -> impl Content<TuiOut> + 'a
pub(crate) fn button_2 <'a, K, L> (&'a self, key: K, label: L) -> 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), ""))));
Tui::bold(true, Bsp::e(key,
When::new(!self.is_editing(), Tui::fg_bg(Tui::g(255), Tui::g(96), label)))) }
pub(crate) fn button3 <'a, K, L, V> (&'a self, key: K, label: L, value: V) -> impl Content<TuiOut> + 'a
pub(crate) fn button_3 <'a, K, L, V> (&'a self, key: K, label: L, value: V) -> impl Content<TuiOut> + 'a
where K: Content<TuiOut> + 'a, L: Content<TuiOut> + 'a, V: Content<TuiOut> + 'a {
let editing = self.is_editing();
let key = Tui::fg_bg(Tui::g(0), Tui::orange(),
@ -150,8 +150,8 @@ impl Tek {
let _ = app.row_top(0, 0, "", "", "");
//let _ = app.io_ports(Reset, Reset, ||[].iter());
//let _ = app.io_connections(Reset, Reset, ||[].iter());
let _ = app.button2("", "");
let _ = app.button3("", "", "");
let _ = app.button_2("", "");
let _ = app.button_3("", "", "");
let _ = app.heading("", "", 0, "");
let _ = Tek::wrap(Reset, Reset, "");
}

View file

@ -1,10 +1,53 @@
use crate::*;
impl Tek {
const H_SCENE: usize = 2;
const H_EDITOR: usize = 15;
pub(crate) fn h_scenes (&self, editing: bool, height: usize, larger: usize) -> u16 {
self.scenes_sizes(editing, height, larger).last().map(|(_, _, _, y)|y as u16).unwrap_or(0) }
pub(crate) fn scenes_sizes (&self, editing: bool, height: usize, larger: usize) -> impl ScenesSizes<'_> {
const TAB: &str = " Tab";
const TRACK_SPACING: usize = 0;
const H_SCENE: usize = 2;
const H_EDITOR: usize = 15;
pub(crate) fn w_tracks_area (&self) -> u16 {
self.w().saturating_sub(2 * self.w_sidebar())
}
pub(crate) fn w_tracks (&self) -> u16 {
self.tracks_sizes().last().map(|(_, _, _, x)|x as u16).unwrap_or(0)
}
fn track_scrollbar (&self) -> impl Content<TuiOut> + use<'_> {
Fill::x(Fixed::y(1, ScrollbarH {
offset: self.track_scroll,
length: self.w_tracks_area() as usize,
total: self.w_tracks() as usize,
}))
}
pub(crate) fn h_tracks_area (&self) -> u16 {
self.h().saturating_sub(self.h_inputs() + self.h_outputs() + 10)
}
pub(crate) fn h_scenes (&self) -> u16 {
self.scenes_sizes(self.is_editing(), Self::H_SCENE, Self::H_EDITOR).last().map(|(_, _, _, y)|y as u16).unwrap_or(0)
}
fn scene_scrollbar (&self) -> impl Content<TuiOut> + use<'_> {
Fill::y(Fixed::x(1, ScrollbarV {
offset: self.scene_scroll,
length: self.h_tracks_area() as usize,
total: self.h_scenes() as usize,
}))
}
fn tracks_sizes <'a> (&'a self) -> impl TracksSizes<'a> {
let editing = self.is_editing();
let bigger = self.editor_w();
let mut x = 0;
let active = match self.selected() {
Selection::Track(t) if editing => Some(t),
Selection::Clip(t, _) if editing => Some(t),
_ => None
};
self.tracks().iter().enumerate().map(move |(index, track)|{
let width = if Some(index) == active.copied() { bigger } else { track.width.max(8) };
let data = (index, track, x, x + width);
x += width + Self::TRACK_SPACING;
data
})
}
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),
Selection::Scene(s) => (None, Some(*s)),
@ -17,26 +60,79 @@ impl Tek {
let height = if active { larger } else { height };
let data = (s, scene, y, y + height);
y += height;
data})}
fn scene_scrollbar (&self) -> impl Content<TuiOut> + use<'_> {
Fill::y(Fixed::x(1, ScrollbarV {
offset: self.scene_scroll,
length: self.h_tracks_area() as usize,
total: self.tracks.len()
}))
data
})
}
fn track_scrollbar (&self) -> impl Content<TuiOut> + use<'_> {
Fill::x(Fixed::y(1, ScrollbarH {
offset: self.track_scroll,
length: self.w_tracks() as usize,
total: self.tracks.len()
}))
fn scenes_with_colors (&self, editing: bool, h: u16) -> impl ScenesColors<'_> {
self.scenes_sizes(editing, Self::H_SCENE, Self::H_EDITOR).map_while(
move|(s, scene, y1, y2)|if y2 as u16 > h {
None
} else { Some((s, scene, y1, y2, if s == 0 {
None
} else {
Some(self.scenes[s-1].color)
}))
})
}
fn scenes_with_track_colors (&self, editing: bool, h: u16, t: usize) -> impl ScenesColors<'_> {
self.scenes_sizes(editing, Self::H_SCENE, Self::H_EDITOR).map_while(
move|(s, scene, y1, y2)|if y2 as u16 > h {
None
} else { Some((s, scene, y1, y2, if s == 0 {
None
} else {
Some(self.scenes[s-1].clips[t].as_ref()
.map(|c|c.read().unwrap().color)
.unwrap_or(ItemPalette::G[32]))
}))
})
}
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))))
}
pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a> (
&'a self, f: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
let width = self.w_tracks_area();
let filter = move|(t, track, x1, x2)|if x2 as u16 >= width {None} else {Some((t, track, x1, x2))};
let tracks = move||self.tracks_sizes().map_while(filter);
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,
f(index, track))))
})))
}
pub fn view_tracks (&self) -> impl Content<TuiOut> + use<'_> {
let w = (self.size.w() as u16).saturating_sub(2 * self.w_sidebar());
let data = (self.selected.track().unwrap_or(0), self.tracks().len());
self.fmtd.write().unwrap().trks.update(Some(data), rewrite!(buf, "{}/{}", data.0, data.1));
self.row(w, 1, self.button_3("t", "track", self.fmtd.read().unwrap().trks.view.clone()),
self.per_track(|t, track|self.view_track_header(t, track)),
self.button_2("T", "add track"))
}
fn view_track_header <'a> (&self, t: usize, track: &'a Track) -> impl Content<TuiOut> + use<'a> {
let active = self.selected().track() == Some(t);
let name = &track.name;
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 bfg = if active { Rgb(255,255,255) } else { Rgb(0,0,0) };
Self::wrap(bg, fg, Tui::bold(true, Fill::x(Align::nw(name))))
}
pub fn view_scenes (&self) -> impl Content<TuiOut> + use<'_> {
let editing = self.is_editing();
let w = self.w_tracks_area();
let w_full = self.w();
let h = self.h_scenes(editing, Self::H_SCENE, Self::H_EDITOR);
let h = self.h_scenes();
let h_area = self.h_tracks_area();
let selected_track = self.selected().track();
let selected_scene = self.selected().scene();
@ -51,16 +147,9 @@ impl Tek {
move|(s, scene, y1, y2, prev): SceneColor, _|self.view_scene_clip(
w, (1 + y2 - y1) as u16, y1 as u16,
scene, prev, s, t, editing, selected_track == Some(t), selected_scene))),
() ))))) }
fn scenes_with_colors (&self, editing: bool, h: u16) -> impl ScenesColors<'_> {
self.scenes_sizes(editing, Self::H_SCENE, Self::H_EDITOR).map_while(
move|(s, scene, y1, y2)|if y2 as u16 > h {
None
} else { Some((s, scene, y1, y2, if s == 0 {
None
} else {
Some(self.scenes[s-1].color)
})) }) }
() )))))
}
fn view_scene_name (
&self, width: u16, height: u16, offset: u16,
s: usize, scene: &Scene, prev: Option<ItemPalette>,
@ -69,18 +158,9 @@ impl Tek {
let fg = scene.color.lightest.rgb;
let name = Some(scene.name.clone());
let cell = self.view_scene_cell(true, s, &bg, prev, name, "", fg);
Fill::x(map_south(offset, height, Fixed::y(height, cell))) }
fn scenes_with_track_colors (&self, editing: bool, h: u16, t: usize) -> impl ScenesColors<'_> {
self.scenes_sizes(editing, Self::H_SCENE, Self::H_EDITOR).map_while(
move|(s, scene, y1, y2)|if y2 as u16 > h {
None
} else { Some((s, scene, y1, y2, if s == 0 {
None
} else {
Some(self.scenes[s-1].clips[t].as_ref()
.map(|c|c.read().unwrap().color)
.unwrap_or(ItemPalette::G[32]))
})) }) }
Fill::x(map_south(offset, height, Fixed::y(height, cell)))
}
fn view_scene_clip (
&self, width: u16, height: u16, offset: u16,
scene: &Scene, prev: Option<ItemPalette>, s: usize, t: usize,
@ -95,7 +175,9 @@ impl Tek {
let active = editing && same_track && selected_scene == Some(s);
let edit = |x|Bsp::b(x, When(active, &self.editor));
let cell = self.view_scene_cell(same_track, s, &bg, prev, name, "", fg);
map_south(offset, height, edit(Fixed::y(height, cell))) }
map_south(offset, height, edit(Fixed::y(height, cell)))
}
fn view_scene_cell <'a> (
&self,
same_track: bool,
@ -110,18 +192,21 @@ impl Tek {
let selected = same_track && selected_scene == Some(scene);
let neighbor = same_track && scene > 0 && selected_scene == Some(scene - 1);
let is_last = scene == self.scenes.len().saturating_sub(1);
let colors = Self::colors(color, prev, selected, neighbor, is_last);
Self::cell(icon, name, colors) }
fn cell <'a> (
icon: &'a str, name: Option<Arc<str>>, colors: [Color;4]
) -> impl Content<TuiOut> + use<'a> {
let content = Fill::x(Align::w(Tui::bold(true, Bsp::e(icon, name))));
Phat { width: 0, height: 0, content, colors, } }
const TAB: &str = " Tab";
Phat {
width: 0,
height: 0,
colors: Self::colors(color, prev, selected, neighbor, is_last),
content: Fill::x(Align::w(Tui::bold(true, Bsp::e(icon, name))))
}
}
pub fn view_scene_add (&self) -> impl Content<TuiOut> + use<'_> {
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));
self.button3("S", "add scene", self.fmtd.read().unwrap().scns.view.clone()) }
self.button_3("S", "add scene", self.fmtd.read().unwrap().scns.view.clone())
}
}
impl Tek {
fn colors (
theme: &ItemPalette, prev: Option<ItemPalette>,
selected: bool, neighbor: bool, is_last: bool,

View file

@ -11,7 +11,7 @@ impl Tek {
||self.inputs_sizes()
)), ());
let ports = self.row_top(w, 1,
self.button3("i", "midi ins", format!("{}", self.midi_ins.len())),
self.button_3("i", "midi ins", format!("{}", self.midi_ins.len())),
self.per_track_top(move|t, track|{
let rec = track.player.recording;
let mon = track.player.monitoring;
@ -27,7 +27,7 @@ impl Tek {
Tui::fg_bg(rec, bg, "Rec "),
Tui::fg_bg(mon, bg, "Mon ")))))
}),
self.button2("I", "add midi in"));
self.button_2("I", "add midi in"));
Bsp::s(
Bsp::s(routes, ports),
self.row_top(w, 2,

View file

@ -15,7 +15,7 @@ impl Tek {
let froms = self.per_track_top(|_, _|Tui::bg(Reset, Align::c(Bsp::s(" ------ ", OctaveVertical::default(),))));
let froms = self.row_top(w, 2, Align::ne("From:"), froms, ());
let ports = self.row_top(w, 1,
self.button3("o", "midi outs", format!("{}", self.midi_outs.len())),
self.button_3("o", "midi outs", format!("{}", self.midi_outs.len())),
self.per_track_top(move|t, track|{
let mute = false;
let solo = false;
@ -26,7 +26,7 @@ impl Tek {
Self::wrap(bg, fg, Tui::bold(true, Fill::x(Bsp::e(
Tui::fg_bg(mute, bg, "Play "),
Tui::fg_bg(solo, bg, "Solo ")))))}),
self.button2("O", "add midi out"));
self.button_2("O", "add midi out"));
let routes = self.row_top(w, self.h_outputs() - 1,
self.io_ports(fg, Tui::g(32), ||self.outputs_sizes()),
self.per_track_top(move|t, track|self.io_connections(

View file

@ -1,61 +0,0 @@
use crate::*;
impl Tek {
pub(crate) fn w_tracks (&self, editing: bool, bigger: usize) -> u16 {
self.tracks_sizes(editing, bigger).last().map(|(_, _, _, x)|x as u16).unwrap_or(0)
}
pub(crate) fn w_tracks_area (&self) -> u16 {
self.w().saturating_sub(2 * self.w_sidebar())
}
pub(crate) fn h_tracks_area (&self) -> u16 {
self.h().saturating_sub(self.h_inputs() + self.h_outputs() + 10)
}
pub fn view_tracks (&self) -> impl Content<TuiOut> + use<'_> {
let w = (self.size.w() as u16).saturating_sub(2 * self.w_sidebar());
let data = (self.selected.track().unwrap_or(0), self.tracks().len());
self.fmtd.write().unwrap().trks.update(Some(data), rewrite!(buf, "{}/{}", data.0, data.1));
self.row(w, 1, self.button3("t", "track", self.fmtd.read().unwrap().trks.view.clone()),
self.per_track(|t, track|self.view_track_header(t, track)),
self.button2("T", "add track")) }
fn view_track_header <'a> (&self, t: usize, track: &'a Track) -> impl Content<TuiOut> + use<'a> {
let active = self.selected().track() == Some(t);
let name = &track.name;
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 bfg = if active { Rgb(255,255,255) } else { Rgb(0,0,0) };
Self::wrap(bg, fg, Tui::bold(true, Fill::x(Align::nw(name)))) }
pub(crate) 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))))
}
pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a> (
&'a self, f: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
let width = self.w_tracks_area();
let filter = move|(t, track, x1, x2)|if x2 as u16 >= width {None} else {Some((t, track, x1, x2))};
let tracks = move||self.tracks_sizes(self.is_editing(), self.editor_w()).map_while(filter);
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,
f(index, track)))) }))) }
fn tracks_sizes <'a> (&'a self, editing: bool, bigger: usize) -> impl TracksSizes<'a> {
let mut x = 0;
let active = match self.selected() {
Selection::Track(t) if editing => Some(t),
Selection::Clip(t, _) if editing => Some(t),
_ => None
};
self.tracks().iter().enumerate().map(move |(index, track)|{
let width = if Some(index) == active.copied() { bigger } else { track.width.max(8) };
let data = (index, track, x, x + width);
x += width + Self::TRACK_SPACING;
data
})
}
const TRACK_SPACING: usize = 0;
}

View file

@ -15,6 +15,11 @@ pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut C
pub height: usize,
pub content: Vec<Cell>
}
impl std::fmt::Debug for BigBuffer {
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
write!(f, "[BB {}x{} ({})]", self.width, self.height, self.content.len())
}
}
impl BigBuffer {
pub fn new (width: usize, height: usize) -> Self {
Self { width, height, content: vec![Cell::default(); width*height] }