PhrasesCommand -> PoolCommand

This commit is contained in:
🪞👃🪞 2024-12-25 05:58:45 +01:00
parent 084af3ef01
commit 4ab9463164
3 changed files with 20 additions and 20 deletions

View file

@ -83,7 +83,7 @@ handle!(<Tui>|self:SequencerTui,input|SequencerCommand::execute_with_state(self,
#[derive(Clone, Debug)] pub enum SequencerCommand { #[derive(Clone, Debug)] pub enum SequencerCommand {
History(isize), History(isize),
Clock(ClockCommand), Clock(ClockCommand),
Phrases(PhrasesCommand), Phrases(PoolCommand),
Editor(PhraseCommand), Editor(PhraseCommand),
Enqueue(Option<Arc<RwLock<Phrase>>>), Enqueue(Option<Arc<RwLock<Phrase>>>),
} }
@ -103,7 +103,7 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
// Shift-U: redo // Shift-U: redo
key_pat!(Char('U')) => History( 1), key_pat!(Char('U')) => History( 1),
// Tab: Toggle visibility of phrase pool column // Tab: Toggle visibility of phrase pool column
key_pat!(Tab) => Phrases(PhrasesCommand::Show(!state.phrases.visible)), key_pat!(Tab) => Phrases(PoolCommand::Show(!state.phrases.visible)),
// q: Enqueue currently edited phrase // q: Enqueue currently edited phrase
key_pat!(Char('q')) => Enqueue(Some(state.phrases.phrase().clone())), key_pat!(Char('q')) => Enqueue(Some(state.phrases.phrase().clone())),
// 0: Enqueue phrase 0 (stop all) // 0: Enqueue phrase 0 (stop all)
@ -124,7 +124,7 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
// The ones defined above supersede them. // The ones defined above supersede them.
_ => if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) { _ => if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) {
Editor(command) Editor(command)
} else if let Some(command) = PhrasesCommand::input_to_command(&state.phrases, input) { } else if let Some(command) = PoolCommand::input_to_command(&state.phrases, input) {
Phrases(command) Phrases(command)
} else { } else {
return None return None
@ -132,18 +132,18 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
}); });
command!(|self: SequencerCommand, state: SequencerTui|match self { command!(|self: SequencerCommand, state: SequencerTui|match self {
Self::Phrases(cmd) => { Self::Phrases(cmd) => {
let mut default = |cmd: PhrasesCommand|cmd let mut default = |cmd: PoolCommand|cmd
.execute(&mut state.phrases) .execute(&mut state.phrases)
.map(|x|x.map(Phrases)); .map(|x|x.map(Phrases));
match cmd { match cmd {
// autoselect: automatically load selected phrase in editor // autoselect: automatically load selected phrase in editor
PhrasesCommand::Select(_) => { PoolCommand::Select(_) => {
let undo = default(cmd)?; let undo = default(cmd)?;
state.editor.set_phrase(Some(state.phrases.phrase())); state.editor.set_phrase(Some(state.phrases.phrase()));
undo undo
}, },
// update color in all places simultaneously // update color in all places simultaneously
PhrasesCommand::Phrase(SetColor(index, _)) => { PoolCommand::Phrase(SetColor(index, _)) => {
let undo = default(cmd)?; let undo = default(cmd)?;
state.editor.set_phrase(Some(state.phrases.phrase())); state.editor.set_phrase(Some(state.phrases.phrase()));
undo undo

View file

@ -11,7 +11,7 @@ use KeyCode::{Char, Delete, Tab, Up, Down, Left, Right};
Clip(ArrangerClipCommand), Clip(ArrangerClipCommand),
Select(ArrangerSelection), Select(ArrangerSelection),
Zoom(usize), Zoom(usize),
Phrases(PhrasesCommand), Phrases(PoolCommand),
Editor(PhraseCommand), Editor(PhraseCommand),
StopAll, StopAll,
Clear, Clear,
@ -65,7 +65,7 @@ input_to_command!(ArrangerCommand: <Tui>|state: ArrangerTui, input|match input.e
Self::Track(ArrangerTrackCommand::Add), Self::Track(ArrangerTrackCommand::Add),
// Tab: Toggle visibility of phrase pool column // Tab: Toggle visibility of phrase pool column
key_pat!(Tab) => key_pat!(Tab) =>
Self::Phrases(PhrasesCommand::Show(!state.phrases.visible)), Self::Phrases(PoolCommand::Show(!state.phrases.visible)),
_ => { _ => {
use ArrangerCommand as Cmd; use ArrangerCommand as Cmd;
use ArrangerSelection as Selected; use ArrangerSelection as Selected;
@ -76,7 +76,7 @@ input_to_command!(ArrangerCommand: <Tui>|state: ArrangerTui, input|match input.e
let s_len = state.scenes.len(); let s_len = state.scenes.len();
match state.selected() { match state.selected() {
Selected::Clip(t, s) => match input.event() { Selected::Clip(t, s) => match input.event() {
key_pat!(Char('g')) => Some(Cmd::Phrases(PhrasesCommand::Select(0))), key_pat!(Char('g')) => Some(Cmd::Phrases(PoolCommand::Select(0))),
key_pat!(Char('q')) => Some(Cmd::Clip(Clip::Enqueue(t, s))), key_pat!(Char('q')) => Some(Cmd::Clip(Clip::Enqueue(t, s))),
key_pat!(Char(',')) => Some(Cmd::Clip(Clip::Put(t, s, None))), key_pat!(Char(',')) => Some(Cmd::Clip(Clip::Put(t, s, None))),
key_pat!(Char('.')) => Some(Cmd::Clip(Clip::Put(t, s, None))), key_pat!(Char('.')) => Some(Cmd::Clip(Clip::Put(t, s, None))),
@ -155,7 +155,7 @@ input_to_command!(ArrangerCommand: <Tui>|state: ArrangerTui, input|match input.e
} }
}.or_else(||if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) { }.or_else(||if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) {
Some(Self::Editor(command)) Some(Self::Editor(command))
} else if let Some(command) = PhrasesCommand::input_to_command(&state.phrases, input) { } else if let Some(command) = PoolCommand::input_to_command(&state.phrases, input) {
Some(Self::Phrases(command)) Some(Self::Phrases(command))
} else { } else {
None None
@ -171,7 +171,7 @@ fn to_arrangement_command (state: &ArrangerTui, input: &TuiInput) -> Option<Arra
let s_len = state.scenes.len(); let s_len = state.scenes.len();
match state.selected() { match state.selected() {
Selected::Clip(t, s) => match input.event() { Selected::Clip(t, s) => match input.event() {
key_pat!(Char('g')) => Some(Cmd::Phrases(PhrasesCommand::Select(0))), key_pat!(Char('g')) => Some(Cmd::Phrases(PoolCommand::Select(0))),
key_pat!(Char('q')) => Some(Cmd::Clip(Clip::Enqueue(t, s))), key_pat!(Char('q')) => Some(Cmd::Clip(Clip::Enqueue(t, s))),
key_pat!(Char(',')) => Some(Cmd::Clip(Clip::Put(t, s, None))), key_pat!(Char(',')) => Some(Cmd::Clip(Clip::Put(t, s, None))),
key_pat!(Char('.')) => Some(Cmd::Clip(Clip::Put(t, s, None))), key_pat!(Char('.')) => Some(Cmd::Clip(Clip::Put(t, s, None))),
@ -266,18 +266,18 @@ command!(|self: ArrangerCommand, state: ArrangerTui|match self {
Some(Self::Color(old)) Some(Self::Color(old))
}, },
Self::Phrases(cmd) => { Self::Phrases(cmd) => {
let mut default = |cmd: PhrasesCommand|{ let mut default = |cmd: PoolCommand|{
cmd.execute(&mut state.phrases).map(|x|x.map(Self::Phrases)) cmd.execute(&mut state.phrases).map(|x|x.map(Self::Phrases))
}; };
match cmd { match cmd {
// autoselect: automatically load selected phrase in editor // autoselect: automatically load selected phrase in editor
PhrasesCommand::Select(_) => { PoolCommand::Select(_) => {
let undo = default(cmd)?; let undo = default(cmd)?;
state.editor.set_phrase(Some(state.phrases.phrase())); state.editor.set_phrase(Some(state.phrases.phrase()));
undo undo
}, },
// reload phrase in editor to update color // reload phrase in editor to update color
PhrasesCommand::Phrase(PhrasePoolCommand::SetColor(index, _)) => { PoolCommand::Phrase(PhrasePoolCommand::SetColor(index, _)) => {
let undo = default(cmd)?; let undo = default(cmd)?;
state.editor.set_phrase(Some(state.phrases.phrase())); state.editor.set_phrase(Some(state.phrases.phrase()));
undo undo

View file

@ -35,7 +35,7 @@ pub enum PoolMode {
} }
#[derive(Clone, PartialEq, Debug)] #[derive(Clone, PartialEq, Debug)]
pub enum PhrasesCommand { pub enum PoolCommand {
Show(bool), Show(bool),
/// Update the contents of the phrase pool /// Update the contents of the phrase pool
Phrase(Pool), Phrase(Pool),
@ -51,8 +51,8 @@ pub enum PhrasesCommand {
Export(Browse), Export(Browse),
} }
command!(|self:PhrasesCommand, state: PoolModel|{ command!(|self:PoolCommand, state: PoolModel|{
use PhrasesCommand::*; use PoolCommand::*;
match self { match self {
Show(visible) => { Show(visible) => {
state.visible = visible; state.visible = visible;
@ -104,7 +104,7 @@ command!(|self:PhrasesCommand, state: PoolModel|{
} }
}); });
input_to_command!(PhrasesCommand:<Tui>|state: PoolModel,input|match state.phrases_mode() { 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::Rename(..)) => Self::Rename(Rename::input_to_command(state, input)?),
Some(PoolMode::Length(..)) => Self::Length(Length::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::Import(..)) => Self::Import(Browse::input_to_command(state, input)?),
@ -112,9 +112,9 @@ input_to_command!(PhrasesCommand:<Tui>|state: PoolModel,input|match state.phrase
_ => to_phrases_command(state, input)? _ => to_phrases_command(state, input)?
}); });
fn to_phrases_command (state: &PoolModel, input: &TuiInput) -> Option<PhrasesCommand> { fn to_phrases_command (state: &PoolModel, input: &TuiInput) -> Option<PoolCommand> {
use KeyCode::{Up, Down, Delete, Char}; use KeyCode::{Up, Down, Delete, Char};
use PhrasesCommand as Cmd; use PoolCommand as Cmd;
let index = state.phrase_index(); let index = state.phrase_index();
let count = state.phrases().len(); let count = state.phrases().len();
Some(match input.event() { Some(match input.event() {