From 5357e832450e14ff98d814fdee0492000a296d57 Mon Sep 17 00:00:00 2001 From: i do not exist Date: Fri, 31 Jul 2026 06:59:00 +0300 Subject: [PATCH] tengri flat --- src/device/editor.rs | 2 +- src/tek.edn | 4 ++-- src/tek.rs | 38 ++++++++++++++++++++++++++++++++++++-- tengri | 2 +- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/device/editor.rs b/src/device/editor.rs index bd02db77..7e130b37 100644 --- a/src/device/editor.rs +++ b/src/device/editor.rs @@ -131,7 +131,7 @@ impl MidiEditor { } /// ``` -/// use tek::{*, tengri::{*, lang::*}}; +/// use tek::{*, tengri::*}; /// /// struct Test(Option); /// impl_as_ref_opt!(MidiEditor: |self: Test|self.0.as_ref()); diff --git a/src/tek.edn b/src/tek.edn index 4dda6306..8fe0cd13 100644 --- a/src/tek.edn +++ b/src/tek.edn @@ -13,8 +13,8 @@ :transport) (mode :menu (name Menu) (info Mode selector.) (keys :axis/y :confirm) - (view (bg (g 64) - (bsp/s (max/xy 80 2 :transport) + (view (bg (g 16) + (bsp/s (fill/x (bg (g 32) (max/xy 80 2 :transport))) (bsp/s (max/y 3 (bg (g 80) :ports/out)) (bsp/n (max/y 3 (bg (g 80) :ports/in)) (bg (g 30) (bsp/s (max/y 6 :logo) :dialog/menu)))))))) diff --git a/src/tek.rs b/src/tek.rs index 4d918519..fe3b7f2c 100644 --- a/src/tek.rs +++ b/src/tek.rs @@ -25,7 +25,7 @@ pub(crate) use ::{ }, tengri::{ *, - lang::*, + dizzle::*, midly::{ Smf, TrackEventKind, MidiMessage, Error as MidiError, num::*, @@ -451,9 +451,11 @@ mod app { } } } + fn get_arc_str (&self, src: impl Language) -> Perhaps> { Ok(src.src()?.map(|x|x.into())) } + fn get_u16 (&self, src: impl Language) -> Perhaps { Ok(Some(match src.word()? { Some(":w/sidebar") => self.project.w_sidebar(self.editor().is_some()), @@ -461,6 +463,7 @@ mod app { _ => return try_to_u16(src) })) } + fn get_usize (&self, src: impl Language) -> Perhaps { Ok(Some(match src.word()? { Some(":scene-count") => self.scenes().len(), @@ -471,6 +474,7 @@ mod app { _ => return try_to_usize(src) })) } + fn get_bool (&self, src: impl Language) -> Perhaps { src.word()?.map(|word|Ok(match word { "Y" => true, @@ -491,6 +495,7 @@ mod app { _ => return Err(format!("not bool: {word}").into()) })).transpose() } + fn get_selection (&self, src: impl Language) -> Perhaps { src.word()?.map(|word|Ok(match word { ":select/scene" => self.selection().select_scene(self.tracks().len()), @@ -502,6 +507,7 @@ mod app { _ => return Err(format!("not selection: {word}").into()) })).transpose() } + fn get_color (&self, src: impl Language) -> Perhaps { if let Some(expr) = src.expr()? { match (expr.head()?, expr.tail()?) { @@ -531,6 +537,7 @@ mod app { return Err(format!("not a color: {:?}", src.src()?).into()) } } + fn get_opt_u7 (&self, src: impl Language) -> Perhaps> { src.word()?.map(|word|Ok(match word { ":editor/pitch" => Some(( @@ -539,9 +546,11 @@ mod app { _ => return Err(format!("unknown midi note: {word}").into()) })).transpose() } + fn get_opt_u16 (&self, _src: impl Language) -> Perhaps> { Ok(None) } + fn get_opt_usize (&self, src: impl Language) -> Perhaps> { src.word()?.map(|word|Ok(match word { ":selected/scene" => self.selection().scene(), @@ -549,6 +558,7 @@ mod app { _ => return Err(format!("unknown opt: {word}").into()) })).transpose() } + fn get_clip (&self, src: impl Language) -> Perhaps>>> { src.word()?.map(|word|Ok(match word { ":selected/clip" if let Selection::TrackClip { track, scene } = self.selection() => @@ -556,6 +566,7 @@ mod app { _ => return Err(format!("not a clip: {word}").into()) })).transpose() } + pub fn inc (&mut self, axis: &ControlAxis) -> Perhaps { Ok(match (&self.dialog, axis) { (Dialog::None, _) => todo!(), @@ -564,6 +575,7 @@ mod app { _ => todo!() }) } + pub fn dec (&mut self, axis: &ControlAxis) -> Perhaps { Ok(match (&self.dialog, axis) { (Dialog::None, _) => None, @@ -572,6 +584,7 @@ mod app { _ => todo!() }) } + pub fn confirm (&mut self) -> Perhaps { Ok(match &self.dialog { Dialog::Menu(index, items) => { @@ -582,6 +595,7 @@ mod app { _ => todo!(), }) } + } pub fn swap_value ( @@ -1033,6 +1047,26 @@ pub fn show_version () { //})?)? //} +/// Define an enum containing commands, and implement [Command] trait for over given `State`. +#[macro_export] macro_rules! def_command ( + ($Command:ident: |$state:ident: $State:ty| { + // FIXME: support attrs (docstrings) + $($Variant:ident$({$($arg:ident:$Arg:ty),+ $(,)?})?=>$body:expr),* $(,)? + })=>{ + #[derive(Debug)] pub enum $Command { + // FIXME: support attrs (docstrings) + $($Variant $({ $($arg: $Arg),* })?),* + } + impl ::tengri::dizzle::Act<$State> for $Command { + fn act (&self, $state: &mut $State) -> Perhaps { + match self { + $(Self::$Variant $({ $($arg),* })? => $body,)* + _ => unimplemented!("Act<{}>: {self:?}", stringify!($State)), + } + } + } + }); + pub use self::config::*; mod config { use crate::*; @@ -1456,7 +1490,7 @@ mod draw { fn tek_draw_expr (state: &App, to: &mut Tui, lang: &impl Expression) -> Drawn { Ok(Some(if let Some(area) = eval_view(state, to, lang)? { area - } else if let Some(area) = eval_view_tui(state, to, lang)? { + } else if let Some(area) = Tui::eval_view(state, to, lang)? { area } else { return Err(format!("App::interpret_expr: unexpected: {lang:?}").into()) diff --git a/tengri b/tengri index 5ca32929..fc01fd6a 160000 --- a/tengri +++ b/tengri @@ -1 +1 @@ -Subproject commit 5ca329292f808c137b6e2b7e80892e2a9e855696 +Subproject commit fc01fd6ad3a6ed4ee17d65a65b3e59df522f895a