wip: move to layered handlers
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-04-28 04:49:28 +03:00
parent 3561867640
commit 5696cbbebb
6 changed files with 45 additions and 68 deletions

View file

@ -5,7 +5,7 @@ use crate::*;
pub struct MidiEditor {
pub mode: PianoHorizontal,
pub size: Measure<TuiOut>,
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 {

View file

@ -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, PoolCommand, TuiIn>(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, PoolCommand, TuiIn>(self, input) {
Ok(if let Some(command) = self.keys.command(self, input) {
let _undo = command.execute(self)?;
Some(true)
} else {

View file

@ -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<PoolMode>,
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")))
}
}
}