mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
55 lines
2.4 KiB
Rust
55 lines
2.4 KiB
Rust
use crate::*;
|
|
impl Handle<Tui> for TransportToolbar<Tui> {
|
|
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
match from.event() {
|
|
key!(KeyCode::Left) => { self.focus.prev(); },
|
|
key!(KeyCode::Right) => { self.focus.next(); },
|
|
_ => match self.focus {
|
|
TransportToolbarFocus::PlayPause => return self.handle_play_pause(from),
|
|
TransportToolbarFocus::Bpm => return self.handle_bpm(from),
|
|
TransportToolbarFocus::Quant => return self.handle_quant(from),
|
|
TransportToolbarFocus::Sync => return self.handle_sync(from),
|
|
TransportToolbarFocus::Clock => {/*todo*/},
|
|
}
|
|
}
|
|
Ok(Some(true))
|
|
}
|
|
}
|
|
impl TransportToolbar<Tui> {
|
|
fn handle_play_pause (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
match from.event() {
|
|
key!(KeyCode::Enter) => self.toggle_play().map(|_|())?,
|
|
_ => return Ok(None)
|
|
}
|
|
Ok(Some(true))
|
|
}
|
|
fn handle_bpm (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
let bpm = self.clock.timebase().bpm.get();
|
|
match from.event() {
|
|
key!(KeyCode::Char(',')) => { self.clock.timebase().bpm.set(bpm - 1.0); },
|
|
key!(KeyCode::Char('.')) => { self.clock.timebase().bpm.set(bpm + 1.0); },
|
|
key!(KeyCode::Char('<')) => { self.clock.timebase().bpm.set(bpm - 0.001); },
|
|
key!(KeyCode::Char('>')) => { self.clock.timebase().bpm.set(bpm + 0.001); },
|
|
_ => return Ok(None)
|
|
}
|
|
Ok(Some(true))
|
|
}
|
|
fn handle_quant (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
let quant = self.clock.quant.get() as usize;
|
|
match from.event() {
|
|
key!(KeyCode::Char(',')) => { self.clock.quant.set(prev_note_length(quant) as f64); },
|
|
key!(KeyCode::Char('.')) => { self.clock.quant.set(next_note_length(quant) as f64); },
|
|
_ => return Ok(None)
|
|
}
|
|
return Ok(Some(true))
|
|
}
|
|
fn handle_sync (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
let sync = self.clock.sync.get() as usize;
|
|
match from.event() {
|
|
key!(KeyCode::Char(',')) => { self.clock.quant.set(prev_note_length(sync) as f64); },
|
|
key!(KeyCode::Char('.')) => { self.clock.quant.set(next_note_length(sync) as f64); },
|
|
_ => return Ok(None)
|
|
}
|
|
return Ok(Some(true))
|
|
}
|
|
}
|