From fd26b129557d852f46390b51132fb6ec29cb26b6 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 2 Sep 2025 22:39:04 +0300 Subject: [PATCH] still 91 until happiness :( --- crates/app/tek.rs | 2 +- crates/app/tek_bind.rs | 7 +- crates/app/tek_data.rs | 121 +++++++++++---- crates/app/tek_view.rs | 139 +++++++++--------- crates/config/config.rs | 4 +- crates/device/src/arranger.rs | 2 +- crates/device/src/arranger/arranger_tracks.rs | 18 +-- crates/device/src/arranger/arranger_view.rs | 60 ++++---- crates/device/src/clock/clock_view.rs | 10 +- crates/device/src/editor/editor_view.rs | 4 +- crates/device/src/editor/editor_view_h.rs | 8 +- crates/device/src/lib.rs | 20 ++- crates/device/src/lv2/lv2_tui.rs | 2 +- crates/device/src/meter.rs | 4 +- crates/device/src/sampler/sampler_browse.rs | 2 +- crates/device/src/sampler/sampler_view.rs | 28 ++-- crates/device/src/sequencer/seq_launch.rs | 4 +- deps/tengri | 2 +- 18 files changed, 243 insertions(+), 194 deletions(-) diff --git a/crates/app/tek.rs b/crates/app/tek.rs index 12f52769..e7253bca 100644 --- a/crates/app/tek.rs +++ b/crates/app/tek.rs @@ -133,7 +133,7 @@ impl App { } } -fn wrap_dialog (dialog: impl Content) -> impl Content { +fn wrap_dialog (dialog: impl Render) -> impl Render { Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b( Repeat(" "), Outer(true, Style::default().fg(Tui::g(96))).enclose(dialog)))) } diff --git a/crates/app/tek_bind.rs b/crates/app/tek_bind.rs index c0c4a7a7..b6b02d01 100644 --- a/crates/app/tek_bind.rs +++ b/crates/app/tek_bind.rs @@ -33,9 +33,10 @@ handle!(TuiIn:|self: App, input|{ #[derive(Debug, Copy, Clone)] pub enum Axis { X, Y, Z, I } -impl<'t> DslNs<'t, AppCommand> for App { - dsl_exprs!(|app| -> AppCommand { /* TODO */ }); - dsl_words!(|app| -> AppCommand { +impl<'a> DslNs<'a, AppCommand> for App {} +impl<'a> DslNsExprs<'a, AppCommand> for App {} +impl<'a> DslNsWords<'a, AppCommand> for App { + dsl_words!('a |app| -> AppCommand { "x/inc" => AppCommand::Inc { axis: Axis::X }, "x/dec" => AppCommand::Dec { axis: Axis::X }, "y/inc" => AppCommand::Inc { axis: Axis::Y }, diff --git a/crates/app/tek_data.rs b/crates/app/tek_data.rs index 2b27fbb8..0f922189 100644 --- a/crates/app/tek_data.rs +++ b/crates/app/tek_data.rs @@ -1,15 +1,17 @@ use crate::*; -impl<'t> DslNs<'t, Arc> for App { - dsl_exprs!(|app| -> Arc {}); - dsl_words!(|app| -> Arc {}); - fn from_literal (&self, dsl: &D) -> Perhaps> { +impl<'a> DslNs<'a, Arc> for App { + fn from_literal (&self, dsl: impl Dsl) -> Perhaps> { Ok(dsl.src()?.map(|x|x.into())) } } +impl<'a> DslNsWords<'a, Arc> for App {} +impl<'a> DslNsExprs<'a, Arc> for App {} -impl<'t> DslNs<'t, bool> for App { - dsl_words!(|app| -> bool { +impl<'a> DslNs<'a, bool> for App {} +impl<'a> DslNsExprs<'a, bool> for App {} +impl<'a> DslNsWords<'a, bool> for App { + dsl_words!('a |app| -> bool { ":mode/editor" => app.project.editor.is_some(), ":focused/dialog" => !matches!(app.dialog, Dialog::None), @@ -29,15 +31,16 @@ impl<'t> DslNs<'t, bool> for App { ":focused/mix" => !app.editor_focused() && matches!(app.selection(), Selection::Mix), }); - //fn from_literal (&self, dsl: &D) -> Perhaps> { - //TODO - //} } -impl<'t> DslNs<'t, ItemTheme> for App {} +impl<'a> DslNs<'a, ItemTheme> for App {} +impl<'a> DslNsWords<'a, ItemTheme> for App {} +impl<'a> DslNsExprs<'a, ItemTheme> for App {} -impl<'t> DslNs<'t, Dialog> for App { - dsl_words!(|app| -> Dialog { +impl<'a> DslNs<'a, Dialog> for App {} +impl<'a> DslNsExprs<'a, Dialog> for App {} +impl<'a> DslNsWords<'a, Dialog> for App { + dsl_words!('a |app| -> Dialog { ":dialog/none" => Dialog::None, ":dialog/options" => Dialog::Options, ":dialog/device" => Dialog::Device(0), @@ -59,8 +62,10 @@ impl<'t> DslNs<'t, Dialog> for App { }); } -impl<'t> DslNs<'t, Selection> for App { - dsl_words!(|app| -> Selection { +impl<'a> DslNs<'a, Selection> for App {} +impl<'a> DslNsExprs<'a, Selection> for App {} +impl<'a> DslNsWords<'a, Selection> for App { + dsl_words!('a |app| -> Selection { ":select/scene" => app.selection().select_scene(app.tracks().len()), ":select/scene/next" => app.selection().select_scene_next(app.scenes().len()), ":select/scene/prev" => app.selection().select_scene_prev(), @@ -70,33 +75,42 @@ impl<'t> DslNs<'t, Selection> for App { }); } -impl<'t> DslNs<'t, Color> for App { - dsl_words!(|app| -> Color { +impl<'a> DslNs<'a, Color> for App {} +impl<'a> DslNsWords<'a, Color> for App { + dsl_words!('a |app| -> Color { ":color/bg" => Color::Rgb(28, 32, 36), }); - dsl_exprs!(|app| -> Color { - "g" (n: u8) => Color::Rgb(n, n, n), +} +impl<'a> DslNsExprs<'a, Color> for App { + dsl_exprs!('a |app| -> Color { + "g" (n: u8) => Color::Rgb(n, n, n), "rgb" (r: u8, g: u8, b: u8) => Color::Rgb(r, g, b), }); } -impl<'t> DslNs<'t, Option> for App { - dsl_words!(|app| -> Option { +impl<'a> DslNs<'a, Option> for App {} +impl<'a> DslNsExprs<'a, Option> for App {} +impl<'a> DslNsWords<'a, Option> for App { + dsl_words!('a |app| -> Option { ":editor/pitch" => Some( (app.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8).into() ) }); } -impl<'t> DslNs<'t, Option> for App { - dsl_words!(|app| -> Option { +impl<'a> DslNs<'a, Option> for App {} +impl<'a> DslNsExprs<'a, Option> for App {} +impl<'a> DslNsWords<'a, Option> for App { + dsl_words!('a |app| -> Option { ":selected/scene" => app.selection().scene(), ":selected/track" => app.selection().track(), }); } -impl<'t> DslNs<'t, Option>>> for App { - dsl_words!(|app| -> Option>> { +impl<'a> DslNs<'a, Option>>> for App {} +impl<'a> DslNsExprs<'a, Option>>> for App {} +impl<'a> DslNsWords<'a, Option>>> for App { + dsl_words!('a |app| -> Option>> { ":selected/clip" => if let Selection::TrackClip { track, scene } = app.selection() { app.scenes()[*scene].clips[*track].clone() } else { @@ -105,18 +119,63 @@ impl<'t> DslNs<'t, Option>>> for App { }); } -dsl_ns! { num |app: App| - u8; - u16 => { +impl<'a> DslNs<'a, u8> for App { + fn from_literal (&self, dsl: impl Dsl) -> Perhaps { + Ok(if let Some(src) = dsl.src()? { + Some(to_number(src)? as u8) + } else { + None + }) + } +} +impl<'a> DslNsWords<'a, u8> for App {} +impl<'a> DslNsExprs<'a, u8> for App {} + +impl<'a> DslNs<'a, u16> for App { + fn from_literal (&self, dsl: impl Dsl) -> Perhaps { + Ok(if let Some(src) = dsl.src()? { + Some(to_number(src)? as u16) + } else { + None + }) + } +} +impl<'a> DslNsWords<'a, u16> for App { + dsl_words!('a |app| -> u16 { ":w/sidebar" => app.project.w_sidebar(app.editor().is_some()), ":h/sample-detail" => 6.max(app.height() as u16 * 3 / 9), - }; - usize => { + }); +} +impl<'a> DslNsExprs<'a, u16> for App {} + +impl<'a> DslNs<'a, usize> for App { + fn from_literal (&self, dsl: impl Dsl) -> Perhaps { + Ok(if let Some(src) = dsl.src()? { + Some(to_number(src)? as usize) + } else { + None + }) + } +} +impl<'a> DslNsWords<'a, usize> for App { + dsl_words!('a |app| -> usize { ":scene-count" => app.scenes().len(), ":track-count" => app.tracks().len(), ":device-kind" => app.dialog.device_kind().unwrap_or(0), ":device-kind/next" => app.dialog.device_kind_next().unwrap_or(0), ":device-kind/prev" => app.dialog.device_kind_prev().unwrap_or(0), - }; - isize; + }); } +impl<'a> DslNsExprs<'a, usize> for App {} + +impl<'a> DslNs<'a, isize> for App { + fn from_literal (&self, dsl: impl Dsl) -> Perhaps { + Ok(if let Some(src) = dsl.src()? { + Some(to_number(src)? as isize) + } else { + None + }) + } +} +impl<'a> DslNsWords<'a, isize> for App {} +impl<'a> DslNsExprs<'a, isize> for App {} diff --git a/crates/app/tek_view.rs b/crates/app/tek_view.rs index 880bdf6f..8308b1dd 100644 --- a/crates/app/tek_view.rs +++ b/crates/app/tek_view.rs @@ -1,97 +1,103 @@ use crate::*; -impl Content for App { - fn content (&self) -> impl Render + '_ { - Stack::above(move|add|for dsl in self.mode.view.iter() { - add(&Fill::xy(self.view(dsl.as_ref()))); - }) +impl Render for App { + fn render (&self, to: &mut TuiOut) { + to.place(to.area(), &Stack::above(|add|for dsl in self.mode.view.iter() { + add(&self.view(dsl)) + })) } } impl App { - fn view <'t, D: Dsl> (&'t self, index: D) -> TuiBox<'t> { - match index.src() { - Ok(Some(src)) => render_dsl(self, src), - Ok(None) => Box::new(Tui::fg(Color::Rgb(192, 192, 192), "empty view")), - Err(e) => Box::new(format!("{e}")), - } + fn view <'a> (&'a self, dsl: impl Dsl + 'a) -> TuiBox<'a> { + self.from(dsl).unwrap().unwrap() } pub fn update_clock (&self) { ViewCache::update_clock(&self.project.clock.view_cache, self.clock(), self.size.w() > 80) } } -type TuiBox<'t> = Box + 't>; +type TuiBox<'a> = Box + 'a>; -fn render_dsl <'t> ( - state: &'t impl DslNs<'t, TuiBox<'t>>, - src: &str -) -> TuiBox<'t> { - let err: Option> = match state.from(&src) { - Ok(Some(value)) => return value, Ok(None) => None, Err(e) => Some(e), - }; +fn render_error (err: impl Error, src: &str) -> impl Render { let (fg_1, bg_1) = (Color::Rgb(240, 160, 100), Color::Rgb(48, 0, 0)); let (fg_2, bg_2) = (Color::Rgb(250, 200, 180), Color::Rgb(48, 0, 0)); let (fg_3, bg_3) = (Color::Rgb(250, 200, 120), Color::Rgb(0, 0, 0)); let bg = Color::Rgb(24, 0, 0); - Box::new(col! { + col! { Tui::fg(bg, Fixed::y(1, Fill::x(RepeatH("▄")))), Tui::bg(bg, col! { Fill::x(Bsp::e( Tui::bold(true, Tui::fg_bg(fg_1, bg_1, " Render error: ")), - Tui::fg_bg(fg_2, bg_2, err.map(|e|format!(" {e} "))), + Tui::fg_bg(fg_2, bg_2, format!(" {err} ")), )), Fill::x(Align::x(Tui::fg_bg(fg_3, bg_3, format!(" {src} ")))), }), Tui::fg(bg, Fixed::y(1, Fill::x(RepeatH("▀")))), - }) + } } -impl<'t> DslNs<'t, TuiBox<'t>> for App { - dsl_exprs!(|app| -> TuiBox<'t> { - "text" (tail: Arc) => Box::new(tail), +impl<'a> DslNs<'a, TuiBox<'a>> for App {} - "fg" (color: Color, x: TuiBox<'t>) => Box::new(Tui::fg(color, x)), - "bg" (color: Color, x: TuiBox<'t>) => Box::new(Tui::bg(color, x)), - "fg/bg" (fg: Color, bg: Color, x: TuiBox<'t>) => Box::new(Tui::fg_bg(fg, bg, x)), +impl<'a> DslNsExprs<'a, TuiBox<'a>> for App { + dsl_exprs!('a |app| -> TuiBox<'a> { + "text" (tail: Arc) => tail.boxed(), - "either" (cond: bool, a: TuiBox<'t>, b: TuiBox<'t>) => + "fg" (color: Color, x: TuiBox<'a>) => Tui::fg(color, x).boxed(), + "bg" (color: Color, x: TuiBox<'a>) => Tui::bg(color, x).boxed(), + "fg/bg" (fg: Color, bg: Color, x: TuiBox<'a>) => Box::new(Tui::fg_bg(fg, bg, x)), + + "either" (cond: bool, a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Either(cond, a, b)), - "bsp/n" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::n(a, b)), - "bsp/s" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::s(a, b)), - "bsp/e" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::e(a, b)), - "bsp/w" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::w(a, b)), - "bsp/a" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::a(a, b)), - "bsp/b" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::b(a, b)), + "bsp/n" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::n(a, b)), + "bsp/s" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::s(a, b)), + "bsp/e" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::e(a, b)), + "bsp/w" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::w(a, b)), + "bsp/a" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::a(a, b)), + "bsp/b" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::b(a, b)), - "align/nw" (x: TuiBox<'t>) => Box::new(Align::nw(x)), - "align/ne" (x: TuiBox<'t>) => Box::new(Align::ne(x)), - "align/n" (x: TuiBox<'t>) => Box::new(Align::n(x)), - "align/s" (x: TuiBox<'t>) => Box::new(Align::s(x)), - "align/e" (x: TuiBox<'t>) => Box::new(Align::e(x)), - "align/w" (x: TuiBox<'t>) => Box::new(Align::w(x)), - "align/x" (x: TuiBox<'t>) => Box::new(Align::x(x)), - "align/y" (x: TuiBox<'t>) => Box::new(Align::y(x)), - "align/c" (x: TuiBox<'t>) => Box::new(Align::c(x)), + "align/nw" (x: TuiBox<'a>) => Box::new(Align::nw(x)), + "align/ne" (x: TuiBox<'a>) => Box::new(Align::ne(x)), + "align/n" (x: TuiBox<'a>) => Box::new(Align::n(x)), + "align/s" (x: TuiBox<'a>) => Box::new(Align::s(x)), + "align/e" (x: TuiBox<'a>) => Box::new(Align::e(x)), + "align/w" (x: TuiBox<'a>) => Box::new(Align::w(x)), + "align/x" (x: TuiBox<'a>) => Box::new(Align::x(x)), + "align/y" (x: TuiBox<'a>) => Box::new(Align::y(x)), + "align/c" (x: TuiBox<'a>) => Box::new(Align::c(x)), - "fill/x" (x: TuiBox<'t>) => Box::new(Fill::x(x)), - "fill/y" (x: TuiBox<'t>) => Box::new(Fill::y(x)), - "fill/xy" (x: TuiBox<'t>) => Box::new(Fill::xy(x)), + "fill/x" (x: TuiBox<'a>) => Box::new(Fill::x(x)), + "fill/y" (x: TuiBox<'a>) => Box::new(Fill::y(x)), + "fill/xy" (x: TuiBox<'a>) => Box::new(Fill::xy(x)), - "fixed/x" (x: u16, c: TuiBox<'t>) => Box::new(Fixed::x(x, c)), - "fixed/y" (y: u16, c: TuiBox<'t>) => Box::new(Fixed::y(y, c)), - "fixed/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Fixed::xy(x, y, c)), + "fixed/x" (x: u16, c: TuiBox<'a>) => Box::new(Fixed::x(x, c)), + "fixed/y" (y: u16, c: TuiBox<'a>) => Box::new(Fixed::y(y, c)), + "fixed/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Fixed::xy(x, y, c)), - "min/x" (x: u16, c: TuiBox<'t>) => Box::new(Min::x(x, c)), - "min/y" (y: u16, c: TuiBox<'t>) => Box::new(Min::y(y, c)), - "min/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Min::xy(x, y, c)), + "min/x" (x: u16, c: TuiBox<'a>) => Box::new(Min::x(x, c)), + "min/y" (y: u16, c: TuiBox<'a>) => Box::new(Min::y(y, c)), + "min/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Min::xy(x, y, c)), - "max/x" (x: u16, c: TuiBox<'t>) => Box::new(Max::x(x, c)), - "max/y" (y: u16, c: TuiBox<'t>) => Box::new(Max::y(y, c)), - "max/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Max::xy(x, y, c)), + "max/x" (x: u16, c: TuiBox<'a>) => Box::new(Max::x(x, c)), + "max/y" (y: u16, c: TuiBox<'a>) => Box::new(Max::y(y, c)), + "max/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Max::xy(x, y, c)), }); - dsl_words!(|app| -> TuiBox<'t> { + /// Resolve an expression if known. + fn from_expr (&'a self, dsl: impl Dsl) -> Perhaps> { + if let Some(head) = dsl.expr().head()? { + for (key, value) in Self::EXPRS.iter() { + if head == *key { + return value(self, dsl.expr().tail()?.unwrap_or("")) + } + } + } + return Ok(None) + } +} + +impl<'a> DslNsWords<'a, TuiBox<'a>> for App { + dsl_words!('a |app| -> TuiBox<'a> { ":logo" => Box::new(Fixed::xy(32, 7, Tui::bold(true, Tui::fg(Rgb(240,200,180), Stack::south(|add|{ add(&Fixed::y(1, "")); add(&Fixed::y(1, "")); @@ -168,27 +174,14 @@ impl<'t> DslNs<'t, TuiBox<'t>> for App { let rb = if i == selected { " ]" } else { " " }; Fill::x(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name")))) }))) }, }); - /// Resolve an expression if known. - fn from_expr (&self, dsl: &D) -> Perhaps> { - if let Some(head) = dsl.expr().head()? { - for (key, value) in Self::EXPRS.0.iter() { - if head == *key { - return value(self, dsl.expr().tail()?.unwrap_or("")) - } - } - } - return Ok(None) - } /// Resolve a symbol if known. - fn from_word (&self, dsl: &D) -> Perhaps> { + fn from_word (&'a self, dsl: impl Dsl) -> Perhaps> { if let Some(dsl) = dsl.word()? { let views = self.config.views.read().unwrap(); if let Some(view) = views.get(dsl) { - let view = view.clone(); - std::mem::drop(views); - return Ok(Some(render_dsl(self, view.as_ref()))) + return Ok(Some(self.view(view).boxed())) } - for (word, get) in Self::WORDS.0 { + for (word, get) in Self::WORDS { if dsl == *word { return get(self) } diff --git a/crates/config/config.rs b/crates/config/config.rs index 3b23f99d..c9bb65b5 100644 --- a/crates/config/config.rs +++ b/crates/config/config.rs @@ -74,7 +74,7 @@ impl Config { } } pub fn init (&mut self) -> Usually<()> { - self.init_file(Self::CONFIG, Self::DEFAULTS, |cfgs, dsl|cfgs.load(dsl))?; + self.init_file(Self::CONFIG, Self::DEFAULTS, |cfgs, dsl|cfgs.load(&dsl))?; Ok(()) } pub fn init_file ( @@ -82,7 +82,7 @@ impl Config { ) -> Usually<()> { if self.dirs.find_config_file(path).is_none() { println!("Creating {path:?}"); - std::fs::write(self.dirs.place_config_file(path)?, defaults); + std::fs::write(self.dirs.place_config_file(path)?, defaults)?; } Ok(if let Some(path) = self.dirs.find_config_file(path) { println!("Loading {path:?}"); diff --git a/crates/device/src/arranger.rs b/crates/device/src/arranger.rs index 56ac336b..54f9b6f2 100644 --- a/crates/device/src/arranger.rs +++ b/crates/device/src/arranger.rs @@ -13,7 +13,7 @@ def_sizes_iter!(InputsSizes => MidiInput); def_sizes_iter!(OutputsSizes => MidiOutput); def_sizes_iter!(PortsSizes => Arc, [Connect]); -pub(crate) fn wrap (bg: Color, fg: Color, content: impl Content) -> impl Content { +pub(crate) fn wrap (bg: Color, fg: Color, content: impl Render) -> impl Render { let left = Tui::fg_bg(bg, Reset, Fixed::x(1, RepeatV("▐"))); let right = Tui::fg_bg(bg, Reset, Fixed::x(1, RepeatV("▌"))); Bsp::e(left, Bsp::w(right, Tui::fg_bg(fg, bg, content))) diff --git a/crates/device/src/arranger/arranger_tracks.rs b/crates/device/src/arranger/arranger_tracks.rs index 364ffab8..bde98eaf 100644 --- a/crates/device/src/arranger/arranger_tracks.rs +++ b/crates/device/src/arranger/arranger_tracks.rs @@ -241,7 +241,7 @@ impl Track { pub trait HasTrack { fn track (&self) -> Option<&Track>; fn track_mut (&mut self) -> Option<&mut Track>; - fn view_midi_ins_status (&self, theme: ItemTheme) -> impl Content { + fn view_midi_ins_status (&self, theme: ItemTheme) -> impl Render { self.track().map(|track|{ let ins = track.sequencer.midi_ins.len() as u16; Fixed::xy(20, 1 + ins, Outer(true, Style::default().fg(Tui::g(96))).enclose( @@ -249,7 +249,7 @@ pub trait HasTrack { Map::south(1, ||track.sequencer.midi_ins.iter(), |port, index|Fill::x(Align::w(format!(" {index} {}", port.port_name()))))))))}) } - fn view_midi_outs_status (&self, theme: ItemTheme) -> impl Content { + fn view_midi_outs_status (&self, theme: ItemTheme) -> impl Render { self.track().map(|track|{ let outs = track.sequencer.midi_outs.len() as u16; Fixed::xy(20, 1 + outs, Outer(true, Style::default().fg(Tui::g(96))).enclose( @@ -257,7 +257,7 @@ pub trait HasTrack { Map::south(1, ||track.sequencer.midi_outs.iter(), |port, index|Fill::x(Align::w(format!(" {index} {}", port.port_name()))))))))}) } - fn view_audio_ins_status (&self, theme: ItemTheme) -> impl Content { + fn view_audio_ins_status (&self, theme: ItemTheme) -> impl Render { self.track().and_then(|track|track.devices.get(0)).map(|device|{ let ins = device.audio_ins().len() as u16; Fixed::xy(20, 1 + ins, Outer(true, Style::default().fg(Tui::g(96))).enclose( @@ -265,7 +265,7 @@ pub trait HasTrack { Map::south(1, ||device.audio_ins().iter(), |port, index|Fill::x(Align::w(format!(" {index} {}", port.port_name()))))))))}) } - fn view_audio_outs_status (&self, theme: ItemTheme) -> impl Content { + fn view_audio_outs_status (&self, theme: ItemTheme) -> impl Render { self.track().and_then(|track|track.devices.last()).map(|device|{ let outs = device.audio_outs().len() as u16; Fixed::xy(20, 1 + outs, Outer(true, Style::default().fg(Tui::g(96))).enclose( @@ -279,7 +279,7 @@ impl Track { pub fn per <'a, T: Content + 'a, U: TracksSizes<'a>> ( tracks: impl Fn() -> U + Send + Sync + 'a, callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a - ) -> impl Content + 'a { + ) -> impl Render + 'a { Map::new(tracks, move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{ let width = (x2 - x1) as u16; @@ -293,7 +293,7 @@ impl Track { pub(crate) fn per_track_top <'a, T: Content + 'a, U: TracksSizes<'a>> ( tracks: impl Fn() -> U + Send + Sync + 'a, callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a -) -> impl Content + 'a { +) -> impl Render + 'a { Align::x(Tui::bg(Reset, Map::new(tracks, move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{ let width = (x2 - x1) as u16; @@ -306,13 +306,13 @@ pub(crate) fn per_track_top <'a, T: Content + 'a, U: TracksSizes<'a>> ( pub(crate) fn per_track <'a, T: Content + 'a, U: TracksSizes<'a>> ( tracks: impl Fn() -> U + Send + Sync + 'a, callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a -) -> impl Content + 'a { +) -> impl Render + 'a { per_track_top(tracks, move|index, track|Fill::y(Align::y(callback(index, track)))) } pub(crate) fn io_ports <'a, T: PortsSizes<'a>> ( fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a -) -> impl Content + 'a { +) -> impl Render + 'a { Map::new(iter, move|( _index, name, connections, y, y2 ): (usize, &'a Arc, &'a [Connect], usize, usize), _| @@ -325,7 +325,7 @@ pub(crate) fn io_ports <'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 + 'a { +) -> impl Render + 'a { Map::new(iter, move|( _index, _name, connections, y, y2 ): (usize, &'a Arc, &'a [Connect], usize, usize), _| diff --git a/crates/device/src/arranger/arranger_view.rs b/crates/device/src/arranger/arranger_view.rs index 3daf8ed0..be11cb25 100644 --- a/crates/device/src/arranger/arranger_view.rs +++ b/crates/device/src/arranger/arranger_view.rs @@ -1,38 +1,36 @@ use crate::*; +type Add<'a> = &'a dyn FnMut(&dyn Render); + impl Arrangement { - pub fn view_inputs <'a> (&'a self, _theme: ItemTheme) -> impl Content + 'a { + pub fn view_inputs (&self, _theme: ItemTheme) -> impl Render + '_ { Stack::south(move|add|{ add(&Fixed::y(1, Bsp::e(Fixed::x(20, Align::w(button_3("i", "nput ", format!("{}", self.midi_ins.len()), false))), Bsp::w(Fixed::x(4, button_2("I", "+", false)), - Stack::east(move|add|{ - for (_index, track, _x1, _x2) in self.tracks_with_sizes() { - add(&Tui::bg(track.color.dark.rgb, Align::w(Fixed::x(track.width as u16, row!( - Either(track.sequencer.monitoring, Tui::fg(Green, "mon "), "mon "), - Either(track.sequencer.recording, Tui::fg(Red, "rec "), "rec "), - Either(track.sequencer.overdub, Tui::fg(Yellow, "dub "), "dub "), - ))))) - } + Stack::east(move|add|for (_index, track, _x1, _x2) in self.tracks_with_sizes() { + add(&Tui::bg(track.color.dark.rgb, Align::w(Fixed::x(track.width as u16, row!( + Either(track.sequencer.monitoring, Tui::fg(Green, "mon "), "mon "), + Either(track.sequencer.recording, Tui::fg(Red, "rec "), "rec "), + Either(track.sequencer.overdub, Tui::fg(Yellow, "dub "), "dub "), + ))))) }))))); for (_index, port) in self.midi_ins().iter().enumerate() { add(&Fixed::y(1, Bsp::e( Fixed::x(20, Align::w(Bsp::e(" ● ", Tui::bold(true, Tui::fg(Rgb(255,255,255), port.port_name()))))), Bsp::w(Fixed::x(4, ()), - Stack::east(move|add|{ - for (_index, track, _x1, _x2) in self.tracks_with_sizes() { - add(&Tui::bg(track.color.darker.rgb, Align::w(Fixed::x(track.width as u16, row!( - Either(track.sequencer.monitoring, Tui::fg(Green, " ● "), " · "), - Either(track.sequencer.recording, Tui::fg(Red, " ● "), " · "), - Either(track.sequencer.overdub, Tui::fg(Yellow, " ● "), " · "), - ))))) - } + Stack::east(move|add|for (_index, track, _x1, _x2) in self.tracks_with_sizes() { + add(&Tui::bg(track.color.darker.rgb, Align::w(Fixed::x(track.width as u16, row!( + Either(track.sequencer.monitoring, Tui::fg(Green, " ● "), " · "), + Either(track.sequencer.recording, Tui::fg(Red, " ● "), " · "), + Either(track.sequencer.overdub, Tui::fg(Yellow, " ● "), " · "), + ))))) }))))); } }) } - pub fn view_outputs <'a> (&'a self, theme: ItemTheme) -> impl Content + 'a { + pub fn view_outputs <'a> (&'a self, theme: ItemTheme) -> impl Render + 'a { let mut h = 1; for output in self.midi_outs().iter() { h += 1 + output.connections.len(); @@ -72,7 +70,7 @@ impl Arrangement { } }})))}})))))) } - pub fn view_track_devices <'a> (&'a self, theme: ItemTheme) -> impl Content + 'a { + pub fn view_track_devices <'a> (&'a self, theme: ItemTheme) -> impl Render + 'a { let mut h = 2u16; for track in self.tracks().iter() { h = h.max(track.devices.len() as u16 * 2); @@ -137,19 +135,19 @@ pub trait TracksView: } fn view_track_row_section ( _theme: ItemTheme, - button: impl Content, - button_add: impl Content, - content: impl Content - ) -> impl Content { + button: impl Render, + button_add: impl Render, + content: impl Render + ) -> impl Render { Bsp::w(Fill::y(Fixed::x(4, Align::nw(button_add))), Bsp::e(Fixed::x(20, Fill::y(Align::nw(button))), Fill::xy(Align::c(content)))) } fn view_track_header <'a, T: Content> ( &'a self, theme: ItemTheme, content: T - ) -> impl Content { + ) -> impl Render { Fixed::x(12, Tui::bg(theme.darker.rgb, Fill::x(Align::e(content)))) } - fn view_track_names (&self, theme: ItemTheme) -> impl Content { + fn view_track_names (&self, theme: ItemTheme) -> impl Render { let track_count = self.tracks().len(); let scene_count = self.scenes().len(); let selected = self.selection(); @@ -176,7 +174,7 @@ pub trait TracksView: } }))))) } - fn view_track_outputs <'a> (&'a self, theme: ItemTheme, _h: u16) -> impl Content { + fn view_track_outputs <'a> (&'a self, theme: ItemTheme, _h: u16) -> impl Render { Self::view_track_row_section(theme, Bsp::s( Fill::x(Align::w(button_2("o", "utput", false))), @@ -197,7 +195,7 @@ pub trait TracksView: } }))))) } - fn view_track_inputs <'a> (&'a self, theme: ItemTheme) -> impl Content { + fn view_track_inputs <'a> (&'a self, theme: ItemTheme) -> impl Render { let mut h = 0u16; for track in self.tracks().iter() { h = h.max(track.sequencer.midi_ins.len() as u16); @@ -259,14 +257,14 @@ pub trait ScenesView: } }) } - fn view_scenes_names (&self) -> impl Content { + fn view_scenes_names (&self) -> impl Render { Fixed::x(20, Stack::south(move|add|{ for (index, scene, ..) in self.scenes_with_sizes() { add(&self.view_scene_name(index, scene)); } })) } - fn view_scene_name (&self, index: usize, scene: &Scene) -> impl Content { + fn view_scene_name (&self, index: usize, scene: &Scene) -> impl Render { let h = if self.selection().scene() == Some(index) && let Some(_editor) = self.editor() { 7 } else { @@ -297,7 +295,7 @@ pub trait ClipsView: Sync { fn view_scenes_clips <'a> (&'a self) - -> impl Content + 'a + -> impl Render + 'a { self.clips_size().of(Fill::xy(Bsp::a( Fill::xy(Align::se(Tui::fg(Green, format!("{}x{}", self.clips_size().w(), self.clips_size().h())))), @@ -312,7 +310,7 @@ pub trait ClipsView: })))) } - fn view_track_clips <'a> (&'a self, track_index: usize, track: &'a Track) -> impl Content + 'a { + fn view_track_clips <'a> (&'a self, track_index: usize, track: &'a Track) -> impl Render + 'a { Stack::south(move|cell|{ for (scene_index, scene, ..) in self.scenes_with_sizes() { let (name, theme): (Arc, ItemTheme) = if let Some(Some(clip)) = &scene.clips.get(track_index) { diff --git a/crates/device/src/clock/clock_view.rs b/crates/device/src/clock/clock_view.rs index b839a3ca..1f6c925c 100644 --- a/crates/device/src/clock/clock_view.rs +++ b/crates/device/src/clock/clock_view.rs @@ -6,7 +6,7 @@ pub fn view_transport ( bpm: Arc>, beat: Arc>, time: Arc>, -) -> impl Content { +) -> impl Render { let theme = ItemTheme::G[96]; Tui::bg(Black, row!(Bsp::a( Fill::xy(Align::w(button_play_pause(play))), @@ -23,7 +23,7 @@ pub fn view_status ( sr: Arc>, buf: Arc>, lat: Arc>, -) -> impl Content { +) -> impl Render { let theme = ItemTheme::G[96]; Tui::bg(Black, row!(Bsp::a( Fill::xy(Align::w(sel.map(|sel|FieldH(theme, "Selected", sel)))), @@ -35,7 +35,7 @@ pub fn view_status ( ))) } -pub(crate) fn button_play_pause (playing: bool) -> impl Content { +pub(crate) fn button_play_pause (playing: bool) -> impl Render { let compact = true;//self.is_editing(); Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) }, Either::new(compact, @@ -93,7 +93,7 @@ impl ViewCache { //} //pub fn scene_add (cache: &Arc>, scene: usize, scenes: usize, is_editing: bool) - //-> impl Content + //-> impl Render //{ //let data = (scene, scenes); //cache.write().unwrap().scns.update(Some(data), rewrite!(buf, "({}/{})", data.0, data.1)); @@ -133,7 +133,7 @@ impl ViewCache { } } - //pub fn view_h2 (&self) -> impl Content { + //pub fn view_h2 (&self) -> impl Render { //let cache = self.project.clock.view_cache.clone(); //let cache = cache.read().unwrap(); //add(&Fixed::x(15, Align::w(Bsp::s( diff --git a/crates/device/src/editor/editor_view.rs b/crates/device/src/editor/editor_view.rs index 0a11c72c..ee45603e 100644 --- a/crates/device/src/editor/editor_view.rs +++ b/crates/device/src/editor/editor_view.rs @@ -8,7 +8,7 @@ content!(TuiOut: |self: MidiEditor| { impl MidiEditor { - pub fn clip_status (&self) -> impl Content + '_ { + pub fn clip_status (&self) -> impl Render + '_ { let (_color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) { (clip.color, clip.name.clone(), clip.length, clip.looped) } else { (ItemTheme::G[64], String::new().into(), 0, false) }; @@ -25,7 +25,7 @@ impl MidiEditor { )) } - pub fn edit_status (&self) -> impl Content + '_ { + pub fn edit_status (&self) -> impl Render + '_ { let (_color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) { (clip.color, clip.length) } else { (ItemTheme::G[64], 0) }; diff --git a/crates/device/src/editor/editor_view_h.rs b/crates/device/src/editor/editor_view_h.rs index bf04f16f..fe28ffa8 100644 --- a/crates/device/src/editor/editor_view_h.rs +++ b/crates/device/src/editor/editor_view_h.rs @@ -139,7 +139,7 @@ impl PianoHorizontal { } } - fn notes (&self) -> impl Content { + fn notes (&self) -> impl Render { let time_start = self.get_time_start(); let note_lo = self.get_note_lo(); let note_hi = self.get_note_hi(); @@ -170,7 +170,7 @@ impl PianoHorizontal { } }) } - fn cursor (&self) -> impl Content { + fn cursor (&self) -> impl Render { let note_hi = self.get_note_hi(); let note_lo = self.get_note_lo(); let note_pos = self.get_note_pos(); @@ -201,7 +201,7 @@ impl PianoHorizontal { } }) } - fn keys (&self) -> impl Content { + fn keys (&self) -> impl Render { let state = self; let color = state.color; let note_lo = state.get_note_lo(); @@ -225,7 +225,7 @@ impl PianoHorizontal { } }))) } - fn timeline (&self) -> impl Content + '_ { + fn timeline (&self) -> impl Render + '_ { Fill::x(Fixed::y(1, ThunkRender::new(move|to: &mut TuiOut|{ let [x, y, w, _h] = to.area(); let style = Some(Style::default().dim()); diff --git a/crates/device/src/lib.rs b/crates/device/src/lib.rs index 22edce2e..a81ce6d2 100644 --- a/crates/device/src/lib.rs +++ b/crates/device/src/lib.rs @@ -48,8 +48,10 @@ macro_rules! def_sizes_iter { #[cfg(feature = "vst3")] mod vst3; #[cfg(feature = "vst3")] pub use self::vst3::*; pub fn button_2 <'a> ( - key: impl Content + 'a, label: impl Content + 'a, editing: bool, -) -> impl Content + 'a { + key: impl Render + 'a, + label: impl Render + 'a, + editing: bool, +) -> impl Render + 'a { let key = Tui::fg_bg(Tui::orange(), Tui::g(0), Bsp::e( Tui::fg(Tui::g(0), "▐"), Bsp::e(key, Tui::fg(Tui::g(96), "▐")) @@ -58,16 +60,12 @@ pub fn button_2 <'a> ( Tui::bold(true, Bsp::e(key, label)) } -pub fn button_3 <'a, K, L, V> ( - key: K, - label: L, - value: V, +pub fn button_3 <'a> ( + key: impl Render + 'a, + label: impl Render + 'a, + value: impl Render + 'a, editing: bool, -) -> impl Content + 'a where - K: Content + 'a, - L: Content + 'a, - V: Content + 'a, -{ +) -> impl Render + 'a { let key = Tui::fg_bg(Tui::orange(), Tui::g(0), Bsp::e(Tui::fg(Tui::g(0), "▐"), Bsp::e(key, Tui::fg(if editing { Tui::g(128) diff --git a/crates/device/src/lv2/lv2_tui.rs b/crates/device/src/lv2/lv2_tui.rs index 0c76a1c9..8ac3b656 100644 --- a/crates/device/src/lv2/lv2_tui.rs +++ b/crates/device/src/lv2/lv2_tui.rs @@ -1,7 +1,7 @@ use crate::*; use super::*; -impl Content for Lv2 { +impl Render for Lv2 { fn render (&self, to: &mut TuiOut) { let area = to.area(); let [x, y, _, height] = area; diff --git a/crates/device/src/meter.rs b/crates/device/src/meter.rs index 106975c7..3dde76a4 100644 --- a/crates/device/src/meter.rs +++ b/crates/device/src/meter.rs @@ -53,7 +53,7 @@ pub fn to_rms (samples: &[f32]) -> f32 { (sum / samples.len() as f32).sqrt() } -pub fn view_meter <'a> (label: &'a str, value: f32) -> impl Content + 'a { +pub fn view_meter <'a> (label: &'a str, value: f32) -> impl Render + 'a { col!( FieldH(ItemTheme::G[128], label, format!("{:>+9.3}", value)), Fixed::xy(if value >= 0.0 { 13 } @@ -74,7 +74,7 @@ pub fn view_meter <'a> (label: &'a str, value: f32) -> impl Content + 'a else { Green }, ()))) } -pub fn view_meters (values: &[f32;2]) -> impl Content + use<'_> { +pub fn view_meters (values: &[f32;2]) -> impl Render + use<'_> { let left = format!("L/{:>+9.3}", values[0]); let right = format!("R/{:>+9.3}", values[1]); Bsp::s(left, right) diff --git a/crates/device/src/sampler/sampler_browse.rs b/crates/device/src/sampler/sampler_browse.rs index f239767c..6f78d24d 100644 --- a/crates/device/src/sampler/sampler_browse.rs +++ b/crates/device/src/sampler/sampler_browse.rs @@ -143,7 +143,7 @@ fn scan (dir: &PathBuf) -> Usually<(Vec, Vec)> { Ok((subdirs, files)) } -impl Content for AddSampleModal { +impl Render for AddSampleModal { fn render (&self, _to: &mut TuiOut) { todo!() //let area = to.area(); diff --git a/crates/device/src/sampler/sampler_view.rs b/crates/device/src/sampler/sampler_view.rs index 90999e2c..a2a78368 100644 --- a/crates/device/src/sampler/sampler_view.rs +++ b/crates/device/src/sampler/sampler_view.rs @@ -2,7 +2,7 @@ use crate::*; impl Sampler { - pub fn view_grid (&self) -> impl Content + use<'_> { + pub fn view_grid (&self) -> impl Render + use<'_> { let cells_x = 8u16; let cells_y = 8u16; let cell_width = 10u16; @@ -23,7 +23,7 @@ impl Sampler { pub fn view_grid_cell <'a> ( &'a self, name: &'a str, x: u16, y: u16, w: u16, h: u16 - ) -> impl Content + use<'a> { + ) -> impl Render + use<'a> { let cursor = self.cursor(); let hi_fg = Color::Rgb(64, 64, 64); let hi_bg = if y == 0 { Color::Reset } else { Color::Rgb(64, 64, 64) /*prev*/ }; @@ -55,7 +55,7 @@ impl Sampler { pub fn view_list <'a, T: NotePoint + NoteRange> ( &'a self, compact: bool, editor: &T - ) -> impl Content + 'a { + ) -> impl Render + 'a { let note_lo = editor.get_note_lo(); let note_pt = editor.get_note_pos(); let note_hi = editor.get_note_hi(); @@ -97,7 +97,7 @@ impl Sampler { } } - pub fn view_sample (&self, note_pt: usize) -> impl Content + use<'_> { + pub fn view_sample (&self, note_pt: usize) -> impl Render + use<'_> { Outer(true, Style::default().fg(Tui::g(96))) .enclose(Fill::xy(draw_viewer(if let Some((_, Some(sample))) = &self.recording { Some(sample) @@ -108,7 +108,7 @@ impl Sampler { }))) } - pub fn view_sample_info (&self, note_pt: usize) -> impl Content + use<'_> { + pub fn view_sample_info (&self, note_pt: usize) -> impl Render + use<'_> { Fill::x(Fixed::y(1, draw_info(if let Some((_, Some(sample))) = &self.recording { Some(sample) } else if let Some(sample) = &self.mapped[note_pt] { @@ -118,7 +118,7 @@ impl Sampler { }))) } - pub fn view_sample_status (&self, note_pt: usize) -> impl Content + use<'_> { + pub fn view_sample_status (&self, note_pt: usize) -> impl Render + use<'_> { Fixed::x(20, draw_info_v(if let Some((_, Some(sample))) = &self.recording { Some(sample) } else if let Some(sample) = &self.mapped[note_pt] { @@ -128,20 +128,20 @@ impl Sampler { })) } - pub fn view_status (&self, index: usize) -> impl Content { + pub fn view_status (&self, index: usize) -> impl Render { draw_status(self.mapped[index].as_ref()) } - pub fn view_meters_input (&self) -> impl Content + use<'_> { + pub fn view_meters_input (&self) -> impl Render + use<'_> { draw_meters(&self.input_meters) } - pub fn view_meters_output (&self) -> impl Content + use<'_> { + pub fn view_meters_output (&self) -> impl Render + use<'_> { draw_meters(&self.output_meters) } } -fn draw_meters (meters: &[f32]) -> impl Content + use<'_> { +fn draw_meters (meters: &[f32]) -> impl Render + use<'_> { Tui::bg(Black, Fixed::x(2, Map::east(1, ||meters.iter(), |value, _index|{ Fill::y(RmsMeter(*value)) }))) @@ -163,7 +163,7 @@ fn draw_list_item (sample: &Option>>) -> String { } } -fn draw_viewer (sample: Option<&Arc>>) -> impl Content + use<'_> { +fn draw_viewer (sample: Option<&Arc>>) -> impl Render + use<'_> { let min_db = -64.0; ThunkRender::new(move|to: &mut TuiOut|{ let [x, y, width, height] = to.area(); @@ -218,7 +218,7 @@ fn draw_viewer (sample: Option<&Arc>>) -> impl Content + }) } -fn draw_info (sample: Option<&Arc>>) -> impl Content + use<'_> { +fn draw_info (sample: Option<&Arc>>) -> impl Render + use<'_> { When(sample.is_some(), Thunk::new(move||{ let sample = sample.unwrap().read().unwrap(); let theme = sample.color; @@ -233,7 +233,7 @@ fn draw_info (sample: Option<&Arc>>) -> impl Content + us })) } -fn draw_info_v (sample: Option<&Arc>>) -> impl Content + use<'_> { +fn draw_info_v (sample: Option<&Arc>>) -> impl Render + use<'_> { Either(sample.is_some(), Thunk::new(move||{ let sample = sample.unwrap().read().unwrap(); let theme = sample.color; @@ -252,7 +252,7 @@ fn draw_info_v (sample: Option<&Arc>>) -> impl Content + )))) } -fn draw_status (sample: Option<&Arc>>) -> impl Content { +fn draw_status (sample: Option<&Arc>>) -> impl Render { Tui::bold(true, Tui::fg(Tui::g(224), sample .map(|sample|{ let sample = sample.read().unwrap(); diff --git a/crates/device/src/sequencer/seq_launch.rs b/crates/device/src/sequencer/seq_launch.rs index 48d30f1c..38ec1a42 100644 --- a/crates/device/src/sequencer/seq_launch.rs +++ b/crates/device/src/sequencer/seq_launch.rs @@ -38,7 +38,7 @@ pub trait HasPlayClip: HasClock { *self.reset_mut() = true; } - fn play_status (&self) -> impl Content { + fn play_status (&self) -> impl Render { let (name, color): (Arc, ItemTheme) = if let Some((_, Some(clip))) = self.play_clip() { let MidiClip { ref name, color, .. } = *clip.read().unwrap(); (name.clone(), color) @@ -51,7 +51,7 @@ pub trait HasPlayClip: HasClock { FieldV(color, "Now:", format!("{} {}", time, name)) } - fn next_status (&self) -> impl Content { + fn next_status (&self) -> impl Render { let mut time: Arc = String::from("--.-.--").into(); let mut name: Arc = String::from("").into(); let mut color = ItemTheme::G[64]; diff --git a/deps/tengri b/deps/tengri index b98fccd9..194f2f98 160000 --- a/deps/tengri +++ b/deps/tengri @@ -1 +1 @@ -Subproject commit b98fccd98ba13be8eabe29d66621a15d025b2042 +Subproject commit 194f2f9874a134039f49856d832e710d31cc55b2