mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +01:00
60 lines
2.4 KiB
Rust
60 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> {
|
|
match from.event() {
|
|
key!(KeyCode::Char(',')) => { self.clock.set_bpm(self.clock.bpm() - 1.0); },
|
|
key!(KeyCode::Char('.')) => { self.clock.set_bpm(self.clock.bpm() + 1.0); },
|
|
key!(KeyCode::Char('<')) => { self.clock.set_bpm(self.clock.bpm() - 0.001); },
|
|
key!(KeyCode::Char('>')) => { self.clock.set_bpm(self.clock.bpm() + 0.001); },
|
|
_ => return Ok(None)
|
|
}
|
|
Ok(Some(true))
|
|
}
|
|
fn handle_quant (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
match from.event() {
|
|
key!(KeyCode::Char(',')) => {
|
|
self.clock.set_quant(prev_note_length(self.clock.quant()));
|
|
},
|
|
key!(KeyCode::Char('.')) => {
|
|
self.clock.set_quant(next_note_length(self.clock.quant()));
|
|
},
|
|
_ => return Ok(None)
|
|
}
|
|
return Ok(Some(true))
|
|
}
|
|
fn handle_sync (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
match from.event() {
|
|
key!(KeyCode::Char(',')) => {
|
|
self.clock.set_quant(prev_note_length(self.clock.sync()));
|
|
},
|
|
key!(KeyCode::Char('.')) => {
|
|
self.clock.set_quant(next_note_length(self.clock.sync()));
|
|
},
|
|
_ => return Ok(None)
|
|
}
|
|
return Ok(Some(true))
|
|
}
|
|
}
|