FocusCommand, Command::translate, ret old from TimeUnit::set

This commit is contained in:
🪞👃🪞 2024-11-08 22:53:08 +01:00
parent 2b78339e61
commit fe25da4f53
9 changed files with 249 additions and 261 deletions

View file

@ -13,7 +13,7 @@ impl Content for Sequencer<Tui> {
impl Handle<Tui> for Sequencer<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
if let Some(command) = SequencerCommand::match_input(self, from) {
let _undo = command.run(self)?;
let _undo = command.execute(self)?;
return Ok(Some(true))
}
Ok(None)
@ -21,27 +21,30 @@ impl Handle<Tui> for Sequencer<Tui> {
}
impl MatchInput<Tui, Sequencer<Tui>> for SequencerCommand {
fn match_input (state: &Sequencer<Tui>, input: &TuiInput) -> Option<Self> {
use SequencerCommand::*;
use FocusCommand::*;
match input.event() {
key!(KeyCode::Tab) => Some(Self::FocusNext),
key!(Shift-KeyCode::Tab) => Some(Self::FocusPrev),
key!(KeyCode::BackTab) => Some(Self::FocusPrev),
key!(Shift-KeyCode::BackTab) => Some(Self::FocusPrev),
key!(KeyCode::Up) => Some(Self::FocusUp),
key!(KeyCode::Down) => Some(Self::FocusDown),
key!(KeyCode::Left) => Some(Self::FocusLeft),
key!(KeyCode::Right) => Some(Self::FocusRight),
key!(KeyCode::Char(' ')) => Some(Self::Transport(TransportCommand::PlayToggle)),
key!(KeyCode::Tab) => Some(Focus(Next)),
key!(Shift-KeyCode::Tab) => Some(Focus(Prev)),
key!(KeyCode::BackTab) => Some(Focus(Prev)),
key!(Shift-KeyCode::BackTab) => Some(Focus(Prev)),
key!(KeyCode::Up) => Some(Focus(Up)),
key!(KeyCode::Down) => Some(Focus(Down)),
key!(KeyCode::Left) => Some(Focus(Left)),
key!(KeyCode::Right) => Some(Focus(Right)),
key!(KeyCode::Char(' ')) => Some(Transport(TransportCommand::PlayToggle)),
_ => match state.focused() {
SequencerFocus::Transport => state.transport.as_ref()
.map(|t|TransportCommand::match_input(&*t.read().unwrap(), input)
.map(Self::Transport))
.flatten(),
SequencerFocus::Transport => if let Some(t) = state.transport.as_ref() {
TransportCommand::match_input(&*t.read().unwrap(), input).map(Transport)
} else {
None
},
SequencerFocus::PhrasePool =>
PhrasePoolCommand::match_input(&*state.phrases.read().unwrap(), input)
.map(Self::Phrases),
.map(Phrases),
SequencerFocus::PhraseEditor =>
PhraseEditorCommand::match_input(&state.editor, input)
.map(Self::Editor),
.map(Editor),
}
}
}
@ -84,7 +87,7 @@ impl Content for PhrasePool<Tui> {
impl Handle<Tui> for PhrasePool<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
if let Some(command) = PhrasePoolCommand::match_input(self, from) {
let _undo = command.run(self)?;
let _undo = command.execute(self)?;
return Ok(Some(true))
}
Ok(None)
@ -282,7 +285,7 @@ impl Content for PhraseEditor<Tui> {
);
}
let lower_right = format!(
"{}x{}",
"{{{}x{}}}",
self.width.load(Ordering::Relaxed),
self.height.load(Ordering::Relaxed),
);
@ -436,7 +439,7 @@ pub(crate) fn keys_vert () -> Buffer {
impl Handle<Tui> for PhraseEditor<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
if let Some(command) = PhraseEditorCommand::match_input(self, from) {
let _undo = command.run(self)?;
let _undo = command.execute(self)?;
return Ok(Some(true))
}
Ok(None)