mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: refactor pt.5, no translate
This commit is contained in:
parent
8c37c95cc6
commit
5df08409e5
19 changed files with 389 additions and 457 deletions
|
|
@ -1,103 +1,50 @@
|
|||
use crate::*;
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum TransportCommand {
|
||||
FocusNext,
|
||||
FocusPrev,
|
||||
Play,
|
||||
Pause,
|
||||
PlayToggle,
|
||||
PlayFromStart,
|
||||
Increment,
|
||||
Decrement,
|
||||
FineIncrement,
|
||||
FineDecrement,
|
||||
SeekUsec(f64),
|
||||
SeekSample(f64),
|
||||
SeekPulse(f64),
|
||||
SetBpm(f64),
|
||||
SetQuant(f64),
|
||||
SetSync(f64),
|
||||
pub enum TransportViewCommand {
|
||||
Focus(FocusCommand),
|
||||
Transport(TransportCommand),
|
||||
}
|
||||
impl<E: Engine> Command<TransportView<E>> for TransportCommand {
|
||||
fn translate (self, state: &TransportView<E>) -> Self {
|
||||
use TransportCommand::*;
|
||||
use TransportViewFocus::*;
|
||||
match self {
|
||||
Increment => match state.focus {
|
||||
Bpm =>
|
||||
{return SetBpm(state.clock.timebase().bpm.get() + 1.0) },
|
||||
Quant =>
|
||||
{return SetQuant(next_note_length(state.clock.quant.get()as usize)as f64)},
|
||||
Sync =>
|
||||
{return SetSync(next_note_length(state.clock.sync.get()as usize)as f64+1.)},
|
||||
PlayPause =>
|
||||
{/*todo seek*/},
|
||||
Clock =>
|
||||
{/*todo seek*/},
|
||||
},
|
||||
FineIncrement => match state.focus {
|
||||
Bpm =>
|
||||
{return SetBpm(state.clock.timebase().bpm.get() + 0.001)},
|
||||
Quant =>
|
||||
{return Increment},
|
||||
Sync =>
|
||||
{return Increment},
|
||||
PlayPause =>
|
||||
{/*todo seek*/},
|
||||
Clock =>
|
||||
{/*todo seek*/},
|
||||
},
|
||||
Decrement => match state.focus {
|
||||
Bpm =>
|
||||
{return SetBpm(state.clock.timebase().bpm.get() - 1.0)},
|
||||
Quant =>
|
||||
{return SetQuant(prev_note_length(state.clock.quant.get()as usize)as f64)},
|
||||
Sync =>
|
||||
{return SetSync(prev_note_length(state.clock.sync.get()as usize)as f64)},
|
||||
PlayPause =>
|
||||
{/*todo seek*/},
|
||||
Clock =>
|
||||
{/*todo seek*/},
|
||||
},
|
||||
FineDecrement => match state.focus {
|
||||
Bpm =>
|
||||
{return SetBpm(state.clock.timebase().bpm.get() - 0.001)},
|
||||
Quant =>
|
||||
{return Decrement},
|
||||
Sync =>
|
||||
{return Decrement},
|
||||
PlayPause =>
|
||||
{/*todo seek*/},
|
||||
Clock =>
|
||||
{/*todo seek*/},
|
||||
},
|
||||
_ => {}
|
||||
};
|
||||
return self
|
||||
impl Handle<Tui> for TransportView<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
TransportViewCommand::execute_with_state(self, from)
|
||||
}
|
||||
fn execute (self, state: &mut TransportView<E>) -> Perhaps<Self> {
|
||||
use TransportCommand::*;
|
||||
match self.translate(&state) {
|
||||
FocusNext =>
|
||||
{ state.focus.next(); },
|
||||
FocusPrev =>
|
||||
{ state.focus.prev(); },
|
||||
PlayToggle =>
|
||||
{ state.toggle_play()?; },
|
||||
SeekUsec(usec) =>
|
||||
{ state.clock.current.update_from_usec(usec); },
|
||||
SeekSample(sample) =>
|
||||
{ state.clock.current.update_from_sample(sample); },
|
||||
SeekPulse(pulse) =>
|
||||
{ state.clock.current.update_from_pulse(pulse); },
|
||||
SetBpm(bpm) =>
|
||||
{ return Ok(Some(Self::SetBpm(state.clock.timebase().bpm.set(bpm)))) },
|
||||
SetQuant(quant) =>
|
||||
{ return Ok(Some(Self::SetQuant(state.clock.quant.set(quant)))) },
|
||||
SetSync(sync) =>
|
||||
{ return Ok(Some(Self::SetSync(state.clock.sync.set(sync)))) },
|
||||
_ => { unreachable!() }
|
||||
}
|
||||
impl InputToCommand<Tui, TransportView<Tui>> for TransportViewCommand {
|
||||
fn input_to_command (_: &TransportView<Tui>, input: &TuiInput) -> Option<Self> {
|
||||
match input.event() {
|
||||
key!(KeyCode::Char(' ')) => Some(Self::FocusPrev),
|
||||
key!(Shift-KeyCode::Char(' ')) => Some(Self::FocusPrev),
|
||||
key!(KeyCode::Left) => Some(Self::FocusPrev),
|
||||
key!(KeyCode::Right) => Some(Self::FocusNext),
|
||||
key!(KeyCode::Char('.')) => Some(match state.focus {
|
||||
Bpm => SetBpm(state.clock.timebase().bpm.get() + 1.0),
|
||||
Quant => SetQuant(next_note_length(state.clock.quant.get()as usize)as f64),
|
||||
Sync => SetSync(next_note_length(state.clock.sync.get()as usize)as f64+1.),
|
||||
PlayPause => {todo!()},
|
||||
Clock => {todo!()}
|
||||
}),
|
||||
key!(KeyCode::Char(',')) => Some(match state.focus {
|
||||
Bpm => SetBpm(state.clock.timebase().bpm.get() - 1.0),
|
||||
Quant => SetQuant(prev_note_length(state.clock.quant.get()as usize)as f64),
|
||||
Sync => SetSync(prev_note_length(state.clock.sync.get()as usize)as f64+1.),
|
||||
PlayPause => {todo!()},
|
||||
Clock => {todo!()}
|
||||
}),
|
||||
key!(KeyCode::Char('>')) => Some(match state.focus {
|
||||
Bpm => SetBpm(state.clock.timebase().bpm.get() + 0.001),
|
||||
Quant => SetQuant(next_note_length(state.clock.quant.get()as usize)as f64),
|
||||
Sync => SetSync(next_note_length(state.clock.sync.get()as usize)as f64+1.),
|
||||
PlayPause => {todo!()},
|
||||
Clock => {todo!()}
|
||||
}),
|
||||
key!(KeyCode::Char('<')) => Some(match state.focus {
|
||||
Bpm => SetBpm(state.clock.timebase().bpm.get() - 0.001),
|
||||
Quant => SetQuant(prev_note_length(state.clock.quant.get()as usize)as f64),
|
||||
Sync => SetSync(prev_note_length(state.clock.sync.get()as usize)as f64+1.),
|
||||
PlayPause => {todo!()},
|
||||
Clock => {todo!()}
|
||||
}),
|
||||
_ => None
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue