transport -> clock

This commit is contained in:
🪞👃🪞 2025-01-02 13:04:57 +01:00
parent 7f57465b3a
commit 7a4fa1692b
15 changed files with 37 additions and 36 deletions

View file

@ -1,7 +1,7 @@
use crate::*;
use ClockCommand::{Play, Pause};
use KeyCode::{Tab, Char};
use SequencerCommand::*;
use SequencerCommand as Cmd;
use PhraseCommand::*;
use PhrasePoolCommand::*;
/// Root view for standalone `tek_sequencer`.
@ -9,7 +9,7 @@ pub struct SequencerTui {
_jack: Arc<RwLock<JackConnection>>,
pub transport: bool,
pub selectors: bool,
pub clock: ClockModel,
pub clock: Clock,
pub phrases: PoolModel,
pub player: MidiPlayer,
pub editor: MidiEditor,
@ -20,7 +20,7 @@ pub struct SequencerTui {
pub perf: PerfModel,
}
from_jack!(|jack|SequencerTui {
let clock = ClockModel::from(jack);
let clock = Clock::from(jack);
let phrase = Arc::new(RwLock::new(MidiClip::new(
"New", true, 4 * clock.timebase.ppq.get() as usize,
None, Some(ItemColor::random().into())
@ -102,28 +102,28 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
// TODO: k: toggle on-screen keyboard
key_pat!(Ctrl-Char('k')) => { todo!("keyboard") },
// Transport: Play/pause
key_pat!(Char(' ')) => Clock(
key_pat!(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(' ')) => Clock(
key_pat!(Shift-Char(' ')) => Cmd::Clock(
if state.clock().is_stopped() { Play(Some(0)) } else { Pause(Some(0)) }
),
// u: undo
key_pat!(Char('u')) => History(-1),
key_pat!(Char('u')) => Cmd::History(-1),
// Shift-U: redo
key_pat!(Char('U')) => History( 1),
key_pat!(Char('U')) => Cmd::History( 1),
// Tab: Toggle visibility of phrase pool column
key_pat!(Tab) => Pool(PoolCommand::Show(!state.phrases.visible)),
key_pat!(Tab) => Cmd::Pool(PoolCommand::Show(!state.phrases.visible)),
// q: Enqueue currently edited phrase
key_pat!(Char('q')) => Enqueue(Some(state.phrases.phrase().clone())),
key_pat!(Char('q')) => Cmd::Enqueue(Some(state.phrases.phrase().clone())),
// 0: Enqueue phrase 0 (stop all)
key_pat!(Char('0')) => Enqueue(Some(state.phrases.phrases()[0].clone())),
key_pat!(Char('0')) => Cmd::Enqueue(Some(state.phrases.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() {
let editing = state.editor.phrase().as_ref().map(|p|p.read().unwrap().clone());
let selected = state.phrases.phrase().clone();
Editor(Show(Some(if Some(selected.read().unwrap().clone()) != editing {
Cmd::Editor(Show(Some(if Some(selected.read().unwrap().clone()) != editing {
selected
} else {
playing.clone()
@ -134,9 +134,9 @@ 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) {
Editor(command)
Cmd::Editor(command)
} else if let Some(command) = PoolCommand::input_to_command(&state.phrases, input) {
Pool(command)
Cmd::Pool(command)
} else {
return None
}
@ -145,7 +145,7 @@ command!(|self: SequencerCommand, state: SequencerTui|match self {
Self::Pool(cmd) => {
let mut default = |cmd: PoolCommand|cmd
.execute(&mut state.phrases)
.map(|x|x.map(Pool));
.map(|x|x.map(Cmd::Pool));
match cmd {
// autoselect: automatically load selected phrase in editor
PoolCommand::Select(_) => {
@ -163,12 +163,12 @@ command!(|self: SequencerCommand, state: SequencerTui|match self {
}
},
Self::Editor(cmd) => {
let default = ||cmd.execute(&mut state.editor).map(|x|x.map(Editor));
let default = ||cmd.execute(&mut state.editor).map(|x|x.map(Cmd::Editor));
match cmd {
_ => default()?
}
},
Self::Clock(cmd) => cmd.execute(state)?.map(Clock),
Self::Clock(cmd) => cmd.execute(state)?.map(Cmd::Clock),
Self::Enqueue(phrase) => {
state.player.enqueue_next(phrase.as_ref());
None