From 7eef0cfb624737776eef32b14d61ef6cb4b7e559 Mon Sep 17 00:00:00 2001 From: i do not exist Date: Tue, 15 Sep 2026 00:41:05 +0300 Subject: [PATCH] finally adequate performance --- Justfile | 2 +- src/config.rs | 29 +++++++++++++++-------------- src/device/arrange/clip.rs | 8 ++++++-- src/device/editor/piano.rs | 14 +++++++------- src/device/sampler.rs | 8 ++++---- src/tek.edn | 4 ++-- tengri | 2 +- 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Justfile b/Justfile index 0d6c64be..4cf8f59d 100644 --- a/Justfile +++ b/Justfile @@ -53,7 +53,7 @@ prof +ARGS="new": tracy +ARGS="new": {{release}} -F prof {{ARGS}} samply +ARGS="new": - samply record target/release/tek {{ARGS}} + samply record -r 8987 target/release/tek {{ARGS}} release := "reset && cargo run --release" release +ARGS="new": diff --git a/src/config.rs b/src/config.rs index dca95edb..0a1e29bd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -38,8 +38,8 @@ pub fn config_load_kind , L: Language> (config: C, src: L) -> U //if let Some(tail) = src.tail()? { match src.head()? { Some("mode") => modes_add(&config.as_ref().modes, src.tail()), - Some("keys") => load_bind(&config.as_ref().binds, src.tail()), - Some("view") => load_view(&config.as_ref().views, src.tail()), + Some("keys") => binds_add(&config.as_ref().binds, src.tail()), + Some("view") => views_add(&config.as_ref().views, src.tail()), _ => return Err(format!("Config::load: expected view/keys/mode expr, got: {src:?}").into()) }?; //} @@ -140,8 +140,8 @@ pub fn mode_add > (mut mode: T, dsl: impl Language) -> Usually }) } -pub fn load_bind <'a> (binds: &Binds, expr: impl Language) -> UsuallyRef<'a, ()> { - //println!("\n\rload_bind: {expr:?}"); +pub fn binds_add <'a> (binds: &Binds, expr: impl Language) -> UsuallyRef<'a, ()> { + //println!("\n\rbinds_add: {expr:?}"); let name = expr.head()?.ok_or("bind: missing name")?; let body = expr.tail()?.unwrap_or(""); binds.try_write().unwrap().insert(name.into(), { @@ -164,10 +164,10 @@ pub fn load_bind <'a> (binds: &Binds, expr: impl Language) -> UsuallyRef<'a, ()> // TODO return Ok(()) } else { - return Err(format!("load_bind: invalid key: {:?}", item.expr()?.head()?).into()) + return Err(format!("binds_add: invalid key: {:?}", item.expr()?.head()?).into()) } } else { - return Err(format!("load_bind: unexpected: {item:?}").into()) + return Err(format!("binds_add: unexpected: {item:?}").into()) })?; map }); @@ -177,15 +177,16 @@ pub fn load_bind <'a> (binds: &Binds, expr: impl Language) -> UsuallyRef<'a, ()> /// Configuration: mode, view, and bind definitions. /// /// ``` -/// let source = stringify!( +/// use ::{std::sync::Arc, tek::{Config, modes_add, Mode}}; +/// let config: Config = Default::default(); +/// modes_add(&config.modes, stringify!( /// (mode :menu (name Menu) /// (info Mode selector.) (keys :axis/y :confirm) /// (view (bg (g 0) (bsp/s :ports/out /// (bsp/n :ports/in /// (bg (g 30) (bsp/s (fixed/y 7 :logo) -/// (fill :dialog/menu))))))))); -/// let config: tek::Config = tek::modes_add(tek::Config::default(), source).unwrap(); -/// let mode: tek::Mode = config.get_mode(":menu").unwrap(); +/// (fill :dialog/menu)))))))))).unwrap(); +/// let mode: Arc = config.get_mode(":menu").unwrap(); /// ``` #[derive(Default, Debug)] pub struct Config { @@ -526,7 +527,7 @@ impl View { } /// Load custom view definition. -pub fn load_view <'a> (views: &Views, expr: impl Language) -> UsuallyRef<'a, ()> { +pub fn views_add <'a> (views: &Views, expr: impl Language) -> UsuallyRef<'a, ()> { views.try_write().unwrap().insert( expr.head()?.ok_or("view: missing name")?.into(), View::new(expr.tail()?.ok_or("view: missing body")?)?.into() @@ -637,10 +638,10 @@ mod bind { /// An map of input events (e.g. [TuiEvent]) to [Binding]s. /// /// ``` - /// let lang = stringify!( + /// use ::{std::sync::Arc, tek::{Bind, tengri::TuiEvent}}; + /// let bind = Bind::>::load(&stringify!( /// (@x (nop)) - /// (@y (nop) (nop))); - /// let bind = tek::Bind::>::load(&lang).unwrap(); + /// (@y (nop) (nop)))).unwrap(); /// assert_eq!(bind.query(&'x'.into()).map(|x|x.len()), Some(1)); /// //assert_eq!(bind.query(&'y'.into()).map(|x|x.len()), Some(2)); /// ``` diff --git a/src/device/arrange/clip.rs b/src/device/arrange/clip.rs index dd728264..9b696434 100644 --- a/src/device/arrange/clip.rs +++ b/src/device/arrange/clip.rs @@ -89,8 +89,12 @@ fn view_scene_name_theme (scene: &Scene, track_index: usize) -> (Arc, ItemT } fn with_clips_size (show: bool, size: &Sizer, content: impl Draw) -> impl Draw { - let wh = east!(size.w() as usize, "x", size.h() as usize); - size.of(above(when(show, fg(Green, wh).align_se().full_wh()), content)) + size.of(above( + when(show, fg(Green, east!( + size.w() as usize, "x", size.h() as usize + )).align_se()), + content.align_c().full_wh() + )) } fn view_scene_bg ( diff --git a/src/device/editor/piano.rs b/src/device/editor/piano.rs index 36e2b8f2..a2e9d8f4 100644 --- a/src/device/editor/piano.rs +++ b/src/device/editor/piano.rs @@ -139,12 +139,12 @@ impl PianoHorizontal { let buffer = self.buffer.clone(); draw(move|to: &mut Tui|{ let xywh = to.area().into(); - let XYWH(x0, y0, w, _h) = xywh; - let source = buffer.try_read().unwrap(); - //if h as usize != note_axis { - //panic!("area height mismatch: {h} <> {note_axis}"); - //} - if let Tui::Draw(to, ..) = to { + to.buffer().map(|to|{ + let XYWH(x0, y0, w, _h) = xywh; + let source = buffer.try_read().unwrap(); + //if h as usize != note_axis { + //panic!("area height mismatch: {h} <> {note_axis}"); + //} for (area_x, screen_x) in (x0..x0+w).enumerate() { for (area_y, screen_y, _note) in note_y_iter(note_lo, note_hi, y0) { let source_x = time_start + area_x; @@ -163,7 +163,7 @@ impl PianoHorizontal { } } } - } + }); Ok(Some(xywh)) }) } diff --git a/src/device/sampler.rs b/src/device/sampler.rs index 5f568f5c..4f702894 100644 --- a/src/device/sampler.rs +++ b/src/device/sampler.rs @@ -354,7 +354,7 @@ fn draw_viewer (sample: Option<&Arc>>) -> impl Draw + use<'_ lines.push(Line::new(x, min_db, x, y, Color::Green)); t += step / 2.; } - if let Tui::Draw(buf, ..) = to { + to.buffer().map(|buf|{ Canvas::default() .x_bounds([sample.start as f64, sample.end as f64]) .y_bounds([min_db, 0.]) @@ -371,9 +371,9 @@ fn draw_viewer (sample: Option<&Arc>>) -> impl Draw + use<'_ //); }) .render(area, buf); - } + }); } else { - if let Tui::Draw(buf, ..) = to { + to.buffer().map(|buf|{ Canvas::default() .x_bounds([0.0, width as f64]) .y_bounds([0.0, height as f64]) @@ -386,7 +386,7 @@ fn draw_viewer (sample: Option<&Arc>>) -> impl Draw + use<'_ //); }) .render(area, buf); - } + }); } Ok(Some(xywh)) }) diff --git a/src/tek.edn b/src/tek.edn index 37f3a9b4..02148715 100644 --- a/src/tek.edn +++ b/src/tek.edn @@ -34,7 +34,7 @@ (mode :scene (keys :scene)) (mode :mix (keys :mix)) (view - (bsp/n (bsp/e :transport :status) + (bar/n 2 (bsp/e :transport :status) (bar/w 2 (align/ne :meters/output) (bar/e 2 (align/nw :meters/input) (full/xy (pad/xy 2 1 (align/c @@ -42,7 +42,7 @@ (bar/s 2 :tracks/devices (bar/s 2 :tracks/names (bar/n 2 :tracks/inputs - (bar/e 16 (bg (g 50) :scenes/names) + (bar/e 12 (bg (g 50) :scenes/names) (align/c :scenes/clips)))))))))))))) (keys :clock (@space clock/toggle 0) diff --git a/tengri b/tengri index b318d498..48aaa393 160000 --- a/tengri +++ b/tengri @@ -1 +1 @@ -Subproject commit b318d498e544fa65bbf3a3ff4dabde166352b045 +Subproject commit 48aaa3933aadd2d795b6652a244fce179d7072bf