PhraseCommand -> MidiEditCommand

This commit is contained in:
🪞👃🪞 2025-01-02 13:35:35 +01:00
parent 7f55c3bfc8
commit 57158d4d6f
4 changed files with 15 additions and 15 deletions

View file

@ -11,7 +11,7 @@ use ClockCommand::{Play, Pause};
Select(ArrangerSelection),
Zoom(usize),
Phrases(PoolCommand),
Editor(PhraseCommand),
Editor(MidiEditCommand),
StopAll,
Clear,
}
@ -57,7 +57,7 @@ input_to_command!(ArrangerCommand: <Tui>|state: ArrangerTui, input|match input.e
key_pat!(Shift-Char(' ')) =>
Self::Clock(if state.clock().is_stopped() { Play(Some(0)) } else { Pause(Some(0)) }),
key_pat!(Char('e')) =>
Self::Editor(PhraseCommand::Show(Some(state.phrases.phrase().clone()))),
Self::Editor(MidiEditCommand::Show(Some(state.phrases.phrase().clone()))),
key_pat!(Ctrl-Left) =>
Self::Scene(ArrangerSceneCommand::Add),
key_pat!(Ctrl-Char('t')) =>
@ -152,7 +152,7 @@ input_to_command!(ArrangerCommand: <Tui>|state: ArrangerTui, input|match input.e
_ => None
},
}
}.or_else(||if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) {
}.or_else(||if let Some(command) = MidiEditCommand::input_to_command(&state.editor, input) {
Some(Self::Editor(command))
} else if let Some(command) = PoolCommand::input_to_command(&state.phrases, input) {
Some(Self::Phrases(command))

View file

@ -3,7 +3,7 @@ use super::*;
use KeyCode::{Char, Delete, Tab, Up, Down, Left, Right};
use ClockCommand::{Play, Pause};
use GrooveboxCommand as Cmd;
use PhraseCommand::*;
use MidiEditCommand::*;
use PhrasePoolCommand::*;
pub struct Groovebox {
@ -183,7 +183,7 @@ pub enum GrooveboxCommand {
History(isize),
Clock(ClockCommand),
Pool(PoolCommand),
Editor(PhraseCommand),
Editor(MidiEditCommand),
Enqueue(Option<Arc<RwLock<MidiClip>>>),
Sampler(SamplerCommand),
}
@ -230,7 +230,7 @@ input_to_command!(GrooveboxCommand: <Tui>|state: Groovebox, input|match input.ev
// For the rest, use the default keybindings of the components.
// The ones defined above supersede them.
_ => if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) {
_ => if let Some(command) = MidiEditCommand::input_to_command(&state.editor, input) {
Cmd::Editor(command)
} else if let Some(command) = PoolCommand::input_to_command(&state.pool, input) {
Cmd::Pool(command)

View file

@ -1,6 +1,6 @@
use crate::*;
use KeyCode::{Char, Up, Down, Left, Right, Enter};
use PhraseCommand::*;
use MidiEditCommand::*;
pub trait HasEditor {
fn editor (&self) -> &MidiEditor;
@ -15,7 +15,7 @@ pub trait HasEditor {
}
#[derive(Clone, Debug)]
pub enum PhraseCommand {
pub enum MidiEditCommand {
// TODO: 1-9 seek markers that by default start every 8th of the phrase
AppendNote,
PutNote,
@ -29,12 +29,12 @@ pub enum PhraseCommand {
Show(Option<Arc<RwLock<MidiClip>>>),
}
event_map_input_to_command!(Tui: MidiEditor: PhraseCommand: MidiEditor::KEYS);
event_map_input_to_command!(Tui: MidiEditor: MidiEditCommand: MidiEditor::KEYS);
pub(crate) type KeyMapping<const N: usize, E, T, U> = [(E, &'static dyn Fn(&T)->U);N];
impl MidiEditor {
const KEYS: KeyMapping<31, Event, Self, PhraseCommand> = [
const KEYS: KeyMapping<31, Event, Self, MidiEditCommand> = [
(kexp!(Ctrl-Alt-Up), &|s: &Self|SetNoteScroll(s.note_point() + 3)),
(kexp!(Ctrl-Alt-Down), &|s: &Self|SetNoteScroll(s.note_point().saturating_sub(3))),
(kexp!(Ctrl-Alt-Left), &|s: &Self|SetTimeScroll(s.time_point().saturating_sub(s.time_zoom().get()))),
@ -74,9 +74,9 @@ impl MidiEditor {
}
}
impl Command<MidiEditor> for PhraseCommand {
impl Command<MidiEditor> for MidiEditCommand {
fn execute (self, state: &mut MidiEditor) -> Perhaps<Self> {
use PhraseCommand::*;
use MidiEditCommand::*;
match self {
Show(phrase) => { state.set_phrase(phrase.as_ref()); },
PutNote => { state.put_note(false); },

View file

@ -2,7 +2,7 @@ use crate::*;
use ClockCommand::{Play, Pause};
use KeyCode::{Tab, Char};
use SequencerCommand as Cmd;
use PhraseCommand::*;
use MidiEditCommand::*;
use PhrasePoolCommand::*;
/// Root view for standalone `tek_sequencer`.
pub struct SequencerTui {
@ -95,7 +95,7 @@ handle!(<Tui>|self:SequencerTui,input|SequencerCommand::execute_with_state(self,
History(isize),
Clock(ClockCommand),
Pool(PoolCommand),
Editor(PhraseCommand),
Editor(MidiEditCommand),
Enqueue(Option<Arc<RwLock<MidiClip>>>),
}
input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input.event() {
@ -133,7 +133,7 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
},
// For the rest, use the default keybindings of the components.
// The ones defined above supersede them.
_ => if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) {
_ => if let Some(command) = MidiEditCommand::input_to_command(&state.editor, input) {
Cmd::Editor(command)
} else if let Some(command) = PoolCommand::input_to_command(&state.phrases, input) {
Cmd::Pool(command)