remove some shorthands

This commit is contained in:
🪞👃🪞 2024-12-27 13:48:18 +01:00
parent 96f360791b
commit 911c47fc7c

View file

@ -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:<Tui>|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<PoolComman
let index = state.phrase_index();
let count = state.phrases().len();
Some(match input.event() {
key_pat!(Char('n')) => 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<PoolComman
),
key_pat!(Char('<')) => 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
})