mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
key pattern matching macro
This commit is contained in:
parent
e0c8a427f1
commit
92d747ba2a
7 changed files with 168 additions and 93 deletions
|
|
@ -10,8 +10,8 @@ pub struct Plugin {
|
|||
pub ports: JackPorts,
|
||||
}
|
||||
impl Handle<Tui> for Plugin {
|
||||
fn handle (&mut self, e: &Tui) -> Perhaps<bool> {
|
||||
handle_keymap(self, event, KEYMAP_PLUGIN)
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
handle_keymap(self, &from.event(), KEYMAP_PLUGIN).map(|x|Some(x))
|
||||
}
|
||||
}
|
||||
process!(Plugin = Plugin::process);
|
||||
|
|
|
|||
|
|
@ -60,9 +60,9 @@ impl Render<Tui> for AddSampleModal {
|
|||
impl Handle<Tui> for AddSampleModal {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
if handle_keymap(self, &from.event(), KEYMAP_ADD_SAMPLE)? {
|
||||
return Ok(true)
|
||||
return Ok(Some(true))
|
||||
}
|
||||
Ok(true)
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,12 +49,13 @@ impl<E: Engine> Track<E> {
|
|||
//None => ()
|
||||
//})
|
||||
//}
|
||||
|
||||
}
|
||||
impl Track<Tui> {
|
||||
pub fn from_edn <'a, 'e> (args: &[Edn<'e>]) -> Usually<Track<Tui>> {
|
||||
let mut _gain = 0.0f64;
|
||||
let mut track = Self::new("")?;
|
||||
#[allow(unused_mut)]
|
||||
let mut devices: Vec<JackDevice<E>> = vec![];
|
||||
let mut devices: Vec<JackDevice<Tui>> = vec![];
|
||||
edn!(edn in args {
|
||||
Edn::Map(map) => {
|
||||
if let Some(Edn::Str(n)) = map.get(&Edn::Key(SYM_NAME)) {
|
||||
|
|
@ -95,7 +96,7 @@ impl<E: Engine> Track<E> {
|
|||
}
|
||||
Ok(track)
|
||||
}
|
||||
pub fn add_device (&mut self, device: JackDevice<E>) {
|
||||
pub fn add_device (&mut self, device: JackDevice<Tui>) {
|
||||
self.devices.push(device);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,38 +3,37 @@ use crate::*;
|
|||
impl Handle<Tui> for Track<Tui> {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
TuiEvent::Input(crossterm::event::Event::Key(event)) => {
|
||||
for (code, modifiers, _, _, command) in [
|
||||
key!(Up, NONE, "chain_cursor_up", "move cursor up", || {
|
||||
Ok(true)
|
||||
}),
|
||||
key!(Down, NONE, "chain_cursor_down", "move cursor down", || {
|
||||
Ok(true)
|
||||
}),
|
||||
key!(Left, NONE, "chain_cursor_left", "move cursor left", || {
|
||||
//if let Some(track) = app.arranger.track_mut() {
|
||||
//track.device = track.device.saturating_sub(1);
|
||||
//return Ok(true)
|
||||
//}
|
||||
Ok(false)
|
||||
}),
|
||||
key!(Right, NONE, "chain_cursor_right", "move cursor right", || {
|
||||
//if let Some(track) = app.arranger.track_mut() {
|
||||
//track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
|
||||
//return Ok(true)
|
||||
//}
|
||||
Ok(false)
|
||||
}),
|
||||
key!(Char('`'), NONE, "chain_mode_switch", "switch the display mode", || {
|
||||
//app.chain_mode = !app.chain_mode;
|
||||
Ok(true)
|
||||
}),
|
||||
].iter() {
|
||||
if *code == event.code && modifiers.bits() == event.modifiers.bits() {
|
||||
return command()
|
||||
}
|
||||
}
|
||||
return Ok(None)
|
||||
TuiEvent::Input(key) => match key {
|
||||
//, NONE, "chain_cursor_up", "move cursor up", || {
|
||||
key!(KeyCode::Up) => {
|
||||
Ok(Some(true))
|
||||
},
|
||||
// , NONE, "chain_cursor_down", "move cursor down", || {
|
||||
key!(KeyCode::Down) => {
|
||||
Ok(Some(true))
|
||||
},
|
||||
// Left, NONE, "chain_cursor_left", "move cursor left", || {
|
||||
key!(KeyCode::Left) => {
|
||||
//if let Some(track) = app.arranger.track_mut() {
|
||||
//track.device = track.device.saturating_sub(1);
|
||||
//return Ok(true)
|
||||
//}
|
||||
Ok(Some(true))
|
||||
},
|
||||
// , NONE, "chain_cursor_right", "move cursor right", || {
|
||||
key!(KeyCode::Right) => {
|
||||
//if let Some(track) = app.arranger.track_mut() {
|
||||
//track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
|
||||
//return Ok(true)
|
||||
//}
|
||||
Ok(Some(true))
|
||||
},
|
||||
// , NONE, "chain_mode_switch", "switch the display mode", || {
|
||||
key!(KeyCode::Char('`')) => {
|
||||
//app.chain_mode = !app.chain_mode;
|
||||
Ok(Some(true))
|
||||
},
|
||||
_ => Ok(None)
|
||||
},
|
||||
_ => Ok(None)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue