enable transport commands in all contexts

This commit is contained in:
🪞👃🪞 2024-11-25 18:46:26 +01:00
parent 571d475657
commit 8f10117a9c
3 changed files with 43 additions and 27 deletions

View file

@ -145,10 +145,9 @@ fn to_arranger_command (state: &ArrangerTui, input: &TuiInput) -> Option<Arrange
AppFocus::Menu => { todo!() },
AppFocus::Content(focused) => match focused {
ArrangerFocus::Transport(_) => {
use TransportCommand::{Clock, Focus};
match TransportCommand::input_to_command(state, input)? {
Clock(_) => { todo!() },
Focus(command) => Cmd::Focus(command)
TransportCommand::Clock(command) => Cmd::Clock(command),
_ => return None,
}
},
ArrangerFocus::PhraseEditor => {

View file

@ -53,27 +53,23 @@ pub fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option<S
key!(Char('e')) => Editor(
PhraseCommand::Show(state.phrase_to_edit().clone())
),
key!(Char(' ')) => Clock(
if let Some(TransportState::Stopped) = *state.clock.playing.read().unwrap() {
ClockCommand::Play(None)
} else {
ClockCommand::Pause(None)
}
),
key!(Shift-Char(' ')) => Clock(
if let Some(TransportState::Stopped) = *state.clock.playing.read().unwrap() {
ClockCommand::Play(Some(0))
} else {
ClockCommand::Pause(Some(0))
}
),
key!(Char(' ')) => Clock(if state.is_stopped() {
ClockCommand::Play(None)
} else {
ClockCommand::Pause(None)
}),
key!(Shift-Char(' ')) => Clock(if state.is_stopped() {
ClockCommand::Play(Some(0))
} else {
ClockCommand::Pause(Some(0))
}),
_ => match state.focused() {
AppFocus::Menu => { todo!() },
AppFocus::Content(focused) => match focused {
SequencerFocus::Transport(_) => {
match TransportCommand::input_to_command(state, input)? {
TransportCommand::Clock(_) => { todo!() },
TransportCommand::Focus(command) => Focus(command),
TransportCommand::Clock(command) => Clock(command),
_ => return None,
}
},
SequencerFocus::Phrases => Phrases(

View file

@ -18,10 +18,11 @@ impl<T: TransportControl> Command<T> for TransportCommand {
use FocusCommand::{Next, Prev};
use ClockCommand::{SetBpm, SetQuant, SetSync};
Ok(match self {
Focus(cmd) => cmd.execute(state)?.map(Focus),
Clock(SetBpm(bpm)) => Some(Clock(SetBpm(state.bpm().set(bpm)))),
Clock(SetQuant(quant)) => Some(Clock(SetQuant(state.quant().set(quant)))),
Clock(SetSync(sync)) => Some(Clock(SetSync(state.sync().set(sync)))),
Focus(cmd) => cmd.execute(state)?.map(Focus),
Clock(cmd) => cmd.execute(state)?.map(Clock),
//Clock(SetBpm(bpm)) => Some(Clock(SetBpm(state.bpm().set(bpm)))),
//Clock(SetQuant(quant)) => Some(Clock(SetQuant(state.quant().set(quant)))),
//Clock(SetSync(sync)) => Some(Clock(SetSync(state.sync().set(sync)))),
_ => return Ok(None)
})
}
@ -78,8 +79,16 @@ where
Some(match input.event() {
key!(Left) => Focus(FocusCommand::Prev),
key!(Right) => Focus(FocusCommand::Next),
key!(Char(' ')) => todo!("toolbar space"),
key!(Shift-Char(' ')) => todo!("toolbar shift-space"),
key!(Char(' ')) => Clock(if state.is_stopped() {
ClockCommand::Play(None)
} else {
ClockCommand::Pause(None)
}),
key!(Shift-Char(' ')) => Clock(if state.is_stopped() {
ClockCommand::Play(Some(0))
} else {
ClockCommand::Pause(Some(0))
}),
_ => match state.transport_focused().unwrap() {
TransportFocus::Bpm => match input.event() {
key!(Char(',')) => Clock(SetBpm(state.bpm().get() - 1.0)),
@ -110,8 +119,20 @@ where
_ => return None,
},
TransportFocus::PlayPause => match input.event() {
key!(Enter) => todo!("transport play toggle"),
key!(Shift-Enter) => todo!("transport shift-play toggle"),
key!(Enter) => Clock(
if state.is_stopped() {
ClockCommand::Play(None)
} else {
ClockCommand::Pause(None)
}
),
key!(Shift-Enter) => Clock(
if state.is_stopped() {
ClockCommand::Play(Some(0))
} else {
ClockCommand::Pause(Some(0))
}
),
_ => return None,
},
}