diff --git a/Cargo.lock b/Cargo.lock index 5efbb450..d8661d57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1600,7 +1600,7 @@ dependencies = [ [[package]] name = "tengri" -version = "0.11.0" +version = "0.12.0" dependencies = [ "tengri_dsl", "tengri_input", @@ -1610,7 +1610,7 @@ dependencies = [ [[package]] name = "tengri_dsl" -version = "0.11.0" +version = "0.12.0" dependencies = [ "itertools 0.14.0", "konst", @@ -1619,21 +1619,21 @@ dependencies = [ [[package]] name = "tengri_input" -version = "0.11.0" +version = "0.12.0" dependencies = [ "tengri_dsl", ] [[package]] name = "tengri_output" -version = "0.11.0" +version = "0.12.0" dependencies = [ "tengri_dsl", ] [[package]] name = "tengri_tui" -version = "0.11.0" +version = "0.12.0" dependencies = [ "atomic_float", "better-panic", diff --git a/crates/app/src/keys.rs b/crates/app/src/keys.rs index 8628d2e5..c51fedeb 100644 --- a/crates/app/src/keys.rs +++ b/crates/app/src/keys.rs @@ -6,16 +6,6 @@ handle!(TuiIn: |self: Tek, input|if let Some(handler) = self.handler { Ok(None) }); -fn layer (app: &mut Tek, input: &TuiIn, keymap: &str) -> Usually { - if let Some(command) = SourceIter(keymap).command::<_, TekCommand, _>(app, input) { - if let Some(undo) = command.execute(app)? { - app.history.push(undo); - } - return Ok(true) - } - return Ok(false) -} - pub fn handle_arranger (app: &mut Tek, input: &TuiIn) -> Perhaps { Ok((app.is_editing() && app.editor.handle(input)? == Some(true) || layer(app, input, include_str!("../../../config/keys_global.edn"))? || @@ -43,34 +33,12 @@ pub fn handle_sampler (app: &mut Tek, input: &TuiIn) -> Perhaps { layer(app, input, include_str!("../../../config/keys_sampler.edn"))?).then_some(true)) } -// TODO: -//#[derive(Default)] -//struct Handler { - //layers: Vec<(Boxbool>, &'static str)>, - //__: std::marker::PhantomData -//} - -//impl Handler { - //fn layer (mut self, condition: impl Fn(&T)->bool + 'static, keymap: &'static str) -> Self { - //self.layers.push((Box::new(condition), keymap)); - //self - //} - //fn layer_if (mut self, keymap: &'static str) -> Self { - //self.layers.push((Box::new(|_|true), keymap)); - //self - //} - //fn handle <'a, C: Command + TryFromAtom<'a, T>> (&self, state: &mut T, input: &U) -> Perhaps { - //for layer in self.layers.iter() { - //if !(layer.0)(state) { - //continue - //} - //if let Some(command) = SourceIter(layer.1).command::<_, C, _>(state, input) { - //if let Some(undo) = command.execute(state)? { - ////app.history.push(undo); - //} - //return Ok(Some(true)) - //} - //} - //Ok(None) - //} -//} +fn layer (app: &mut Tek, input: &TuiIn, keymap: &str) -> Usually { + if let Some(command) = SourceIter(keymap).command::<_, TekCommand, _>(app, input) { + if let Some(undo) = command.execute(app)? { + app.history.push(undo); + } + return Ok(true) + } + return Ok(false) +} diff --git a/crates/midi/src/clip/clip_editor.rs b/crates/midi/src/clip/clip_editor.rs index 857834c7..6629e106 100644 --- a/crates/midi/src/clip/clip_editor.rs +++ b/crates/midi/src/clip/clip_editor.rs @@ -5,7 +5,7 @@ use crate::*; pub struct MidiEditor { pub mode: PianoHorizontal, pub size: Measure, - pub keys: SourceIter<'static> + pub keys: InputMap<'static, Self, MidiEditCommand, TuiIn> } impl std::fmt::Debug for MidiEditor { @@ -21,7 +21,8 @@ impl Default for MidiEditor { Self { mode: PianoHorizontal::new(None), size: Measure::new(), - keys: SourceIter(include_str!("../../../../config/keys_edit.edn")), + keys: InputMap::new() + .layer(SourceIter(include_str!("../../../../config/keys_edit.edn"))), } } } @@ -206,7 +207,7 @@ atom_command!(MidiEditCommand: |state: MidiEditor| { } handle!(TuiIn: |self: MidiEditor, input|{ - Ok(if let Some(command) = self.keys.command::<_, MidiEditCommand, _>(self, input) { + Ok(if let Some(command) = self.keys.command(self, input) { let _undo = command.execute(self)?; Some(true) } else { diff --git a/crates/midi/src/pool/pool_api.rs b/crates/midi/src/pool/pool_api.rs index ae1c2dd5..cfe39287 100644 --- a/crates/midi/src/pool/pool_api.rs +++ b/crates/midi/src/pool/pool_api.rs @@ -1,12 +1,13 @@ use crate::*; handle!(TuiIn: |self: MidiPool, input|{ - Ok(if let Some(command) = match self.mode() { - Some(PoolMode::Rename(..)) => self.keys_rename, - Some(PoolMode::Length(..)) => self.keys_length, - Some(PoolMode::Import(..)) | Some(PoolMode::Export(..)) => self.keys_file, - _ => self.keys - }.command::(self, input) { + //Ok(if let Some(command) = match self.mode() { + //Some(PoolMode::Rename(..)) => self.keys_rename, + //Some(PoolMode::Length(..)) => self.keys_length, + //Some(PoolMode::Import(..)) | Some(PoolMode::Export(..)) => self.keys_file, + //_ => self.keys + //}.command::(self, input) { + Ok(if let Some(command) = self.keys.command(self, input) { let _undo = command.execute(self)?; Some(true) } else { diff --git a/crates/midi/src/pool/pool_model.rs b/crates/midi/src/pool/pool_model.rs index 8f4c8ee7..5aec75c0 100644 --- a/crates/midi/src/pool/pool_model.rs +++ b/crates/midi/src/pool/pool_model.rs @@ -1,6 +1,6 @@ use crate::*; -#[derive(Debug)] +//#[derive(Debug)] pub struct MidiPool { pub visible: bool, /// Collection of clips @@ -10,23 +10,30 @@ pub struct MidiPool { /// Mode switch pub mode: Option, - pub keys: SourceIter<'static>, - pub keys_rename: SourceIter<'static>, - pub keys_length: SourceIter<'static>, - pub keys_file: SourceIter<'static>, + pub keys: InputMap<'static, Self, PoolCommand, TuiIn>, + //pub keys: SourceIter<'static>, + //pub keys_rename: SourceIter<'static>, + //pub keys_length: SourceIter<'static>, + //pub keys_file: SourceIter<'static>, } impl Default for MidiPool { fn default () -> Self { + use PoolMode::*; Self { visible: true, - clips: Arc::from(RwLock::from(vec![])), - clip: 0.into(), - mode: None, - keys: SourceIter(include_str!("../../../../config/keys_pool.edn")), - keys_file: SourceIter(include_str!("../../../../config/keys_pool_file.edn")), - keys_rename: SourceIter(include_str!("../../../../config/keys_clip_rename.edn")), - keys_length: SourceIter(include_str!("../../../../config/keys_clip_length.edn")), + clips: Arc::from(RwLock::from(vec![])), + clip: 0.into(), + mode: None, + keys: InputMap::new() + .layer( + SourceIter(include_str!("../../../../config/keys_edit.edn"))) + .layer_if(|pool: &Self|matches!(pool.mode, Some(Import(..))|Some(Export(..))), + SourceIter(include_str!("../../../../config/keys_pool_file.edn"))) + .layer_if(|pool: &Self|matches!(pool.mode, Some(Rename(..))), + SourceIter(include_str!("../../../../config/keys_clip_rename.edn"))) + .layer_if(|pool: &Self|matches!(pool.mode, Some(Length(..))), + SourceIter(include_str!("../../../../config/keys_clip_length.edn"))) } } } diff --git a/deps/tengri b/deps/tengri index 95149b79..35ad3712 160000 --- a/deps/tengri +++ b/deps/tengri @@ -1 +1 @@ -Subproject commit 95149b79c4b0d013dcba1eda80e1d14a01087fea +Subproject commit 35ad37120554611197c1e30bbed657f310d332c3