use keymap! in more places

This commit is contained in:
🪞👃🪞 2025-01-02 21:36:32 +01:00
parent 8dedc8fd5f
commit a82f73d475
6 changed files with 200 additions and 268 deletions

View file

@ -109,29 +109,25 @@ handle!(<Tui>|self:SequencerTui,input|SequencerCommand::execute_with_state(self,
Editor(MidiEditCommand),
Enqueue(Option<Arc<RwLock<MidiClip>>>),
}
input_to_command!(SequencerCommand: |state: SequencerTui, input: Event|match input {
keymap!(KEYS_SEQUENCER = |state: SequencerTui, input: Event| SequencerCommand {
// TODO: k: toggle on-screen keyboard
key_pat!(Ctrl-Char('k')) => { todo!("keyboard") },
ctrl(key(Char('k'))) => { todo!("keyboard") },
// Transport: Play/pause
key_pat!(Char(' ')) => Cmd::Clock(
if state.clock().is_stopped() { Play(None) } else { Pause(None) }
),
key(Char(' ')) => Cmd::Clock(if state.clock().is_stopped() { Play(None) } else { Pause(None) }),
// Transport: Play from start or rewind to start
key_pat!(Shift-Char(' ')) => Cmd::Clock(
if state.clock().is_stopped() { Play(Some(0)) } else { Pause(Some(0)) }
),
shift(key(Char(' '))) => Cmd::Clock(if state.clock().is_stopped() { Play(Some(0)) } else { Pause(Some(0)) }),
// u: undo
key_pat!(Char('u')) => Cmd::History(-1),
key(Char('u')) => Cmd::History(-1),
// Shift-U: redo
key_pat!(Char('U')) => Cmd::History( 1),
key(Char('U')) => Cmd::History( 1),
// Tab: Toggle compact mode
key_pat!(Tab) => Cmd::Compact(!state.compact),
key(Tab) => Cmd::Compact(!state.compact),
// q: Enqueue currently edited phrase
key_pat!(Char('q')) => Cmd::Enqueue(Some(state.pool.phrase().clone())),
key(Char('q')) => Cmd::Enqueue(Some(state.pool.phrase().clone())),
// 0: Enqueue phrase 0 (stop all)
key_pat!(Char('0')) => Cmd::Enqueue(Some(state.phrases()[0].clone())),
key(Char('0')) => Cmd::Enqueue(Some(state.phrases()[0].clone())),
// e: Toggle between editing currently playing or other phrase
key_pat!(Char('e')) => if let Some((_, Some(playing))) = state.player.play_phrase() {
key(Char('e')) => if let Some((_, Some(playing))) = state.player.play_phrase() {
let editing = state.editor.phrase().as_ref().map(|p|p.read().unwrap().clone());
let selected = state.pool.phrase().clone();
Cmd::Editor(Show(Some(if Some(selected.read().unwrap().clone()) != editing {
@ -141,16 +137,13 @@ input_to_command!(SequencerCommand: |state: SequencerTui, input: Event|match inp
})))
} else {
return None
},
// For the rest, use the default keybindings of the components.
// The ones defined above supersede them.
_ => 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)
} else {
return None
}
}, 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)
} else {
return None
});
command!(|self: SequencerCommand, state: SequencerTui|match self {
Self::Enqueue(phrase) => {