mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
81 lines
3.7 KiB
Rust
81 lines
3.7 KiB
Rust
use crate::*;
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
pub enum TransportViewCommand {
|
|
Focus(FocusCommand),
|
|
Transport(TransportCommand),
|
|
}
|
|
|
|
impl Handle<Tui> for TransportView<Tui> {
|
|
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
TransportViewCommand::execute_with_state(self, from)
|
|
}
|
|
}
|
|
|
|
impl InputToCommand<Tui, TransportView<Tui>> for TransportViewCommand {
|
|
fn input_to_command (state: &TransportView<Tui>, input: &TuiInput) -> Option<Self> {
|
|
use TransportViewFocus as Focus;
|
|
use FocusCommand as FocusCmd;
|
|
use TransportCommand as Cmd;
|
|
Some(match input.event() {
|
|
|
|
key!(KeyCode::Left) => Self::Focus(FocusCmd::Prev),
|
|
key!(KeyCode::Right) => Self::Focus(FocusCmd::Next),
|
|
|
|
key!(KeyCode::Char('.')) => Self::Transport(match state.focus {
|
|
Focus::Bpm => Cmd::SetBpm(state.state.clock.timebase().bpm.get() + 1.0),
|
|
Focus::Quant => Cmd::SetQuant(next_note_length(state.state.clock.quant.get()as usize)as f64),
|
|
Focus::Sync => Cmd::SetSync(next_note_length(state.state.clock.sync.get()as usize)as f64+1.),
|
|
Focus::PlayPause => {todo!()},
|
|
Focus::Clock => {todo!()}
|
|
}),
|
|
key!(KeyCode::Char(',')) => Self::Transport(match state.focus {
|
|
Focus::Bpm => Cmd::SetBpm(state.state.clock.timebase().bpm.get() - 1.0),
|
|
Focus::Quant => Cmd::SetQuant(prev_note_length(state.state.clock.quant.get()as usize)as f64),
|
|
Focus::Sync => Cmd::SetSync(prev_note_length(state.state.clock.sync.get()as usize)as f64+1.),
|
|
Focus::PlayPause => {todo!()},
|
|
Focus::Clock => {todo!()}
|
|
}),
|
|
key!(KeyCode::Char('>')) => Self::Transport(match state.focus {
|
|
Focus::Bpm => Cmd::SetBpm(state.state.clock.timebase().bpm.get() + 0.001),
|
|
Focus::Quant => Cmd::SetQuant(next_note_length(state.state.clock.quant.get()as usize)as f64),
|
|
Focus::Sync => Cmd::SetSync(next_note_length(state.state.clock.sync.get()as usize)as f64+1.),
|
|
Focus::PlayPause => {todo!()},
|
|
Focus::Clock => {todo!()}
|
|
}),
|
|
key!(KeyCode::Char('<')) => Self::Transport(match state.focus {
|
|
Focus::Bpm => Cmd::SetBpm(state.state.clock.timebase().bpm.get() - 0.001),
|
|
Focus::Quant => Cmd::SetQuant(prev_note_length(state.state.clock.quant.get()as usize)as f64),
|
|
Focus::Sync => Cmd::SetSync(prev_note_length(state.state.clock.sync.get()as usize)as f64+1.),
|
|
Focus::PlayPause => {todo!()},
|
|
Focus::Clock => {todo!()}
|
|
}),
|
|
|
|
_ => return None
|
|
})
|
|
}
|
|
}
|
|
|
|
impl<E: Engine> Command<TransportView<E>> for TransportViewCommand {
|
|
fn execute (self, state: &mut TransportView<E>) -> Perhaps<Self> {
|
|
Ok(Some(match self {
|
|
Self::Focus(command) => Self::Focus({
|
|
use FocusCommand::*;
|
|
match command {
|
|
Next => { todo!() },
|
|
Prev => { todo!() },
|
|
_ => { todo!() }
|
|
}
|
|
}),
|
|
Self::Transport(command) => Self::Transport({
|
|
use TransportCommand::*;
|
|
match command {
|
|
SetBpm(bpm) => SetBpm(state.state.clock.timebase().bpm.set(bpm)),
|
|
SetQuant(quant) => SetQuant(state.state.clock.quant.set(quant)),
|
|
SetSync(sync) => SetSync(state.state.clock.sync.set(sync)),
|
|
_ => { todo!() }
|
|
}
|
|
}),
|
|
}))
|
|
}
|
|
}
|