finally adequate performance

This commit is contained in:
i do not exist 2026-09-15 00:41:05 +03:00
parent d495d97516
commit 7eef0cfb62
7 changed files with 36 additions and 31 deletions

View file

@ -38,8 +38,8 @@ pub fn config_load_kind <C: AsRef<Config>, 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 <T: AsMut<Mode>> (mut mode: T, dsl: impl Language) -> Usually<T>
})
}
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<Mode> = config.get_mode(":menu").unwrap();
/// ```
#[derive(Default, Debug)]
pub struct Config {
@ -526,7 +527,7 @@ impl View<Tui, App> {
}
/// 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::<TuiEvent, Arc<str>>::load(&stringify!(
/// (@x (nop))
/// (@y (nop) (nop)));
/// let bind = tek::Bind::<tek::tengri::TuiEvent, std::sync::Arc<str>>::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));
/// ```

View file

@ -89,8 +89,12 @@ fn view_scene_name_theme (scene: &Scene, track_index: usize) -> (Arc<str>, ItemT
}
fn with_clips_size (show: bool, size: &Sizer, content: impl Draw<Tui>) -> impl Draw<Tui> {
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 (

View file

@ -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))
})
}

View file

@ -354,7 +354,7 @@ fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + 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<RwLock<Sample>>>) -> impl Draw<Tui> + 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<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_
//);
})
.render(area, buf);
}
});
}
Ok(Some(xywh))
})

View file

@ -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)