From 911c47fc7c08755aa1c44ef090ace66769033baa Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 27 Dec 2024 13:48:18 +0100 Subject: [PATCH] remove some shorthands --- crates/tek/src/tui/pool.rs | 45 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/crates/tek/src/tui/pool.rs b/crates/tek/src/tui/pool.rs index c932a27c..5aa85a5d 100644 --- a/crates/tek/src/tui/pool.rs +++ b/crates/tek/src/tui/pool.rs @@ -1,13 +1,8 @@ use super::*; -use crate::PhrasePoolCommand as Pool; mod phrase_length; pub(crate) use phrase_length::*; mod phrase_rename; pub(crate) use phrase_rename::*; -use PhraseRenameCommand as Rename; -use PhraseLengthCommand as Length; -use FileBrowserCommand as Browse; - #[derive(Debug)] pub struct PoolModel { pub(crate) visible: bool, @@ -40,17 +35,17 @@ pub enum PoolMode { pub enum PoolCommand { Show(bool), /// Update the contents of the phrase pool - Phrase(Pool), + Phrase(PhrasePoolCommand), /// Select a phrase from the phrase pool Select(usize), /// Rename a phrase - Rename(Rename), + Rename(PhraseRenameCommand), /// Change the length of a phrase - Length(Length), + Length(PhraseLengthCommand), /// Import from file - Import(Browse), + Import(FileBrowserCommand), /// Export to file - Export(Browse), + Export(FileBrowserCommand), } command!(|self:PoolCommand, state: PoolModel|{ @@ -107,10 +102,10 @@ command!(|self:PoolCommand, state: PoolModel|{ }); input_to_command!(PoolCommand:|state: PoolModel,input|match state.phrases_mode() { - Some(PoolMode::Rename(..)) => Self::Rename(Rename::input_to_command(state, input)?), - Some(PoolMode::Length(..)) => Self::Length(Length::input_to_command(state, input)?), - Some(PoolMode::Import(..)) => Self::Import(Browse::input_to_command(state, input)?), - Some(PoolMode::Export(..)) => Self::Export(Browse::input_to_command(state, input)?), + Some(PoolMode::Rename(..)) => Self::Rename(PhraseRenameCommand::input_to_command(state, input)?), + Some(PoolMode::Length(..)) => Self::Length(PhraseLengthCommand::input_to_command(state, input)?), + Some(PoolMode::Import(..)) => Self::Import(FileBrowserCommand::input_to_command(state, input)?), + Some(PoolMode::Export(..)) => Self::Export(FileBrowserCommand::input_to_command(state, input)?), _ => to_phrases_command(state, input)? }); @@ -120,11 +115,11 @@ fn to_phrases_command (state: &PoolModel, input: &TuiInput) -> Option Cmd::Rename(Rename::Begin), - key_pat!(Char('t')) => Cmd::Length(Length::Begin), - key_pat!(Char('m')) => Cmd::Import(Browse::Begin), - key_pat!(Char('x')) => Cmd::Export(Browse::Begin), - key_pat!(Char('c')) => Cmd::Phrase(Pool::SetColor(index, ItemColor::random())), + key_pat!(Char('n')) => Cmd::Rename(PhraseRenameCommand::Begin), + key_pat!(Char('t')) => Cmd::Length(PhraseLengthCommand::Begin), + key_pat!(Char('m')) => Cmd::Import(FileBrowserCommand::Begin), + key_pat!(Char('x')) => Cmd::Export(FileBrowserCommand::Begin), + key_pat!(Char('c')) => Cmd::Phrase(PhrasePoolCommand::SetColor(index, ItemColor::random())), key_pat!(Char('[')) | key_pat!(Up) => Cmd::Select( index.overflowing_sub(1).0.min(state.phrases().len() - 1) ), @@ -133,32 +128,32 @@ fn to_phrases_command (state: &PoolModel, input: &TuiInput) -> Option if index > 1 { state.set_phrase_index(state.phrase_index().saturating_sub(1)); - Cmd::Phrase(Pool::Swap(index - 1, index)) + Cmd::Phrase(PhrasePoolCommand::Swap(index - 1, index)) } else { return None }, key_pat!(Char('>')) => if index < count.saturating_sub(1) { state.set_phrase_index(state.phrase_index() + 1); - Cmd::Phrase(Pool::Swap(index + 1, index)) + Cmd::Phrase(PhrasePoolCommand::Swap(index + 1, index)) } else { return None }, key_pat!(Delete) => if index > 0 { state.set_phrase_index(index.min(count.saturating_sub(1))); - Cmd::Phrase(Pool::Delete(index)) + Cmd::Phrase(PhrasePoolCommand::Delete(index)) } else { return None }, - key_pat!(Char('a')) | key_pat!(Shift-Char('A')) => Cmd::Phrase(Pool::Add(count, MidiClip::new( + key_pat!(Char('a')) | key_pat!(Shift-Char('A')) => Cmd::Phrase(PhrasePoolCommand::Add(count, MidiClip::new( String::from("(new)"), true, 4 * PPQ, None, Some(ItemPalette::random()) ))), - key_pat!(Char('i')) => Cmd::Phrase(Pool::Add(index + 1, MidiClip::new( + key_pat!(Char('i')) => Cmd::Phrase(PhrasePoolCommand::Add(index + 1, MidiClip::new( String::from("(new)"), true, 4 * PPQ, None, Some(ItemPalette::random()) ))), key_pat!(Char('d')) | key_pat!(Shift-Char('D')) => { let mut phrase = state.phrases()[index].read().unwrap().duplicate(); phrase.color = ItemPalette::random_near(phrase.color, 0.25); - Cmd::Phrase(Pool::Add(index + 1, phrase)) + Cmd::Phrase(PhrasePoolCommand::Add(index + 1, phrase)) }, _ => return None })