mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
refactor stacked keymaps
This commit is contained in:
parent
26b7a9390e
commit
dcd0de7710
9 changed files with 31 additions and 70 deletions
|
|
@ -6,74 +6,43 @@ handle!(TuiIn: |self: Tek, input|if let Some(handler) = self.handler {
|
|||
Ok(None)
|
||||
});
|
||||
|
||||
pub fn handle_arranger (app: &mut Tek, input: &TuiIn) -> Perhaps<bool> {
|
||||
// If editing, editor keys take priority
|
||||
if app.is_editing() {
|
||||
if app.editor.handle(input)? == Some(true) {
|
||||
return Ok(Some(true))
|
||||
}
|
||||
}
|
||||
// Handle from root keymap
|
||||
if let Some(command) = SourceIter(include_str!("../../../config/keys_arranger.edn"))
|
||||
.command::<_, TekCommand, _>(app, input)
|
||||
{
|
||||
if let Some(undo) = command.execute(app)? { app.history.push(undo); }
|
||||
return Ok(Some(true))
|
||||
}
|
||||
// Handle from selection-dependent keymaps
|
||||
if let Some(command) = match app.selected() {
|
||||
Selection::Clip(_, _) => SourceIter(include_str!("../../../config/keys_arranger_clip.edn")),
|
||||
Selection::Track(_) => SourceIter(include_str!("../../../config/keys_arranger_track.edn")),
|
||||
Selection::Scene(_) => SourceIter(include_str!("../../../config/keys_arranger_scene.edn")),
|
||||
Selection::Mix => SourceIter(include_str!("../../../config/keys_arranger_mix.edn")),
|
||||
}.command::<_, TekCommand, _>(app, input) {
|
||||
fn layer (app: &mut Tek, input: &TuiIn, keymap: &str) -> Usually<bool> {
|
||||
if let Some(command) = SourceIter(keymap).command::<_, TekCommand, _>(app, input) {
|
||||
if let Some(undo) = command.execute(app)? {
|
||||
app.history.push(undo);
|
||||
}
|
||||
return Ok(Some(true))
|
||||
return Ok(true)
|
||||
}
|
||||
Ok(None)
|
||||
return Ok(false)
|
||||
}
|
||||
|
||||
pub fn handle_arranger (app: &mut Tek, input: &TuiIn) -> Perhaps<bool> {
|
||||
Ok((app.is_editing() && app.editor.handle(input)? == Some(true) ||
|
||||
layer(app, input, include_str!("../../../config/keys_global.edn"))? ||
|
||||
layer(app, input, include_str!("../../../config/keys_arranger.edn"))? ||
|
||||
app.selected.is_clip() && layer(app, input, include_str!("../../../config/keys_clip.edn"))? ||
|
||||
app.selected.is_track() && layer(app, input, include_str!("../../../config/keys_track.edn"))? ||
|
||||
app.selected.is_scene() && layer(app, input, include_str!("../../../config/keys_scene.edn"))? ||
|
||||
app.selected.is_mix() && layer(app, input, include_str!("../../../config/keys_mix.edn"))?
|
||||
).then_some(true))
|
||||
}
|
||||
|
||||
pub fn handle_sequencer (app: &mut Tek, input: &TuiIn) -> Perhaps<bool> {
|
||||
if app.editor.handle(input)? == Some(true) {
|
||||
return Ok(Some(true))
|
||||
}
|
||||
if let Some(command) = SourceIter(include_str!("../../../config/keys_sequencer.edn"))
|
||||
.command::<_, TekCommand, _>(app, input)
|
||||
{
|
||||
if let Some(undo) = command.execute(app)? {
|
||||
app.history.push(undo);
|
||||
}
|
||||
return Ok(Some(true))
|
||||
}
|
||||
Ok(None)
|
||||
Ok((app.editor.handle(input)? == Some(true) ||
|
||||
layer(app, input, include_str!("../../../config/keys_global.edn"))? ||
|
||||
layer(app, input, include_str!("../../../config/keys_sequencer.edn"))?
|
||||
).then_some(true))
|
||||
}
|
||||
|
||||
pub fn handle_groovebox (app: &mut Tek, input: &TuiIn) -> Perhaps<bool> {
|
||||
if app.editor.handle(input)? == Some(true) {
|
||||
return Ok(Some(true))
|
||||
}
|
||||
if let Some(command) = SourceIter(include_str!("../../../config/keys_groovebox.edn"))
|
||||
.command::<_, TekCommand, _>(app, input)
|
||||
{
|
||||
if let Some(undo) = command.execute(app)? {
|
||||
app.history.push(undo);
|
||||
}
|
||||
return Ok(Some(true))
|
||||
}
|
||||
Ok(None)
|
||||
Ok((app.editor.handle(input)? == Some(true) ||
|
||||
layer(app, input, include_str!("../../../config/keys_global.edn"))? ||
|
||||
layer(app, input, include_str!("../../../config/keys_groovebox.edn"))?
|
||||
).then_some(true))
|
||||
}
|
||||
|
||||
pub fn handle_sampler (app: &mut Tek, input: &TuiIn) -> Perhaps<bool> {
|
||||
let sampler = app.tracks[0].sampler_mut(0).expect("no sampler");
|
||||
if let Some(command) = SourceIter(include_str!("../../../config/keys_sampler.edn"))
|
||||
.command::<_, SamplerCommand, _>(sampler, input)
|
||||
{
|
||||
if let Some(undo) = command.execute(sampler)? {
|
||||
//app.history.push(undo); // TODO UNDO
|
||||
}
|
||||
return Ok(Some(true))
|
||||
}
|
||||
Ok(None)
|
||||
Ok((layer(app, input, include_str!("../../../config/keys_global.edn"))? ||
|
||||
layer(app, input, include_str!("../../../config/keys_sampler.edn"))?
|
||||
).then_some(true))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue