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 {
History(isize),
Clock(ClockCommand),
Phrases(PhrasesCommand),
Phrases(PoolCommand),
Editor(PhraseCommand),
Enqueue(Option<Arc<RwLock<Phrase>>>),
}
@ -103,7 +103,7 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
// Shift-U: redo
key_pat!(Char('U')) => History( 1),
// 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
key_pat!(Char('q')) => Enqueue(Some(state.phrases.phrase().clone())),
// 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.
_ => if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) {
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)
} else {
return None
@ -132,18 +132,18 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
});
command!(|self: SequencerCommand, state: SequencerTui|match self {
Self::Phrases(cmd) => {
let mut default = |cmd: PhrasesCommand|cmd
let mut default = |cmd: PoolCommand|cmd
.execute(&mut state.phrases)
.map(|x|x.map(Phrases));
match cmd {
// autoselect: automatically load selected phrase in editor
PhrasesCommand::Select(_) => {
PoolCommand::Select(_) => {
let undo = default(cmd)?;
state.editor.set_phrase(Some(state.phrases.phrase()));
undo
},
// update color in all places simultaneously
PhrasesCommand::Phrase(SetColor(index, _)) => {
PoolCommand::Phrase(SetColor(index, _)) => {
let undo = default(cmd)?;
state.editor.set_phrase(Some(state.phrases.phrase()));
undo

View file

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

View file

@ -35,7 +35,7 @@ pub enum PoolMode {
}
#[derive(Clone, PartialEq, Debug)]
pub enum PhrasesCommand {
pub enum PoolCommand {
Show(bool),
/// Update the contents of the phrase pool
Phrase(Pool),
@ -51,8 +51,8 @@ pub enum PhrasesCommand {
Export(Browse),
}
command!(|self:PhrasesCommand, state: PoolModel|{
use PhrasesCommand::*;
command!(|self:PoolCommand, state: PoolModel|{
use PoolCommand::*;
match self {
Show(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::Length(..)) => Self::Length(Length::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)?
});
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 PhrasesCommand as Cmd;
use PoolCommand as Cmd;
let index = state.phrase_index();
let count = state.phrases().len();
Some(match input.event() {