devices can be focused again

This commit is contained in:
🪞👃🪞 2024-07-09 14:53:05 +03:00
parent b673e4c68d
commit 07084656b8
5 changed files with 61 additions and 26 deletions

View file

@ -10,25 +10,40 @@ handle!{
return Ok(true)
};
}
let handle_focused = |state: &mut Self|handle_keymap(
state, e, match state.section {
AppSection::Arranger => self::arranger::KEYMAP_ARRANGER,
AppSection::Sequencer => self::sequencer::KEYMAP_SEQUENCER,
AppSection::Chain => self::chain::KEYMAP_CHAIN,
}
);
Ok(if self.entered {
handle_focused(self)?
handle_focused(self, e)?
|| handle_keymap(self, e, KEYMAP)?
|| handle_keymap(self, e, KEYMAP_FOCUS)?
} else {
handle_keymap(self, e, KEYMAP)?
|| handle_keymap(self, e, KEYMAP_FOCUS)?
|| handle_focused(self)?
|| handle_focused(self, e)?
})
}
}
fn handle_focused (state: &mut App, e: &AppEvent) -> Usually<bool> {
match state.section {
AppSection::Arranger =>
handle_keymap(state, e, crate::control::arranger::KEYMAP_ARRANGER),
AppSection::Sequencer =>
handle_keymap(state, e, crate::control::sequencer::KEYMAP_SEQUENCER),
AppSection::Chain => Ok(if state.entered {
handle_device(state, e)? || handle_keymap(state, e, crate::control::chain::KEYMAP_CHAIN)?
} else {
handle_keymap(state, e, crate::control::chain::KEYMAP_CHAIN)? || handle_device(state, e)?
})
}
}
fn handle_device (state: &mut App, e: &AppEvent) -> Usually<bool> {
state.track_mut()
.and_then(|(_, track)|track.device_mut())
.map(|mut device|device.handle(e))
.transpose()
.map(|x|x.unwrap_or(false))
}
const KEYMAP_FOCUS: &'static [KeyBinding<App>] = keymap!(App {
[Tab, NONE, "focus_next", "focus next area", focus_next],
[Tab, SHIFT, "focus_prev", "focus previous area", focus_prev],

View file

@ -60,7 +60,7 @@ pub trait Device: Render + Handle + Process + Send + Sync {
impl<T: Render + Handle + Process + Send + Sync> Device for T {}
// Reexport macros:
pub use crate::{submod, pubmod, render, handle, process, phrase, keymap, key, ports};
pub use crate::{submod, pubmod, render, handle, process, phrase, keymap, ports};
// Reexport JACK proto-lib:
pub use crate::jack::*;

View file

@ -71,14 +71,7 @@ pub fn handle_keymap <T> (
Ok(false)
}
/// Define a key binding.
#[macro_export] macro_rules! key {
($k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: expr) => {
(KeyCode::$k $(($char))?, KeyModifiers::$m, $n, $d, &$f)
};
}
/// Define a keymap.
/// Define a keymap
#[macro_export] macro_rules! keymap {
($T:ty { $([$k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: expr]),* $(,)? }) => {
&[

View file

@ -60,18 +60,24 @@ impl Track {
reset: true,
})
}
pub fn get_device (&self, i: usize) -> Option<RwLockReadGuard<Box<dyn Device>>> {
self.devices.get(i).map(|d|d.state.read().unwrap())
}
pub fn get_device_mut (&self, i: usize) -> Option<RwLockWriteGuard<Box<dyn Device>>> {
self.devices.get(i).map(|d|d.state.write().unwrap())
}
pub fn device (&self) -> Option<RwLockReadGuard<Box<dyn Device>>> {
self.get_device(self.device)
}
pub fn device_mut (&self) -> Option<RwLockWriteGuard<Box<dyn Device>>> {
self.get_device_mut(self.device)
}
pub fn first_device (&self) -> Option<RwLockReadGuard<Box<dyn Device>>> {
self.get_device(0)
}
pub fn last_device (&self) -> Option<RwLockReadGuard<Box<dyn Device>>> {
self.get_device(self.devices.len().saturating_sub(1))
}
pub fn get_device (&self, i: usize) -> Option<RwLockReadGuard<Box<dyn Device>>> {
self.devices.get(i).map(|d|d.state.read().unwrap())
}
pub fn add_device (&mut self, device: JackDevice) -> Usually<&mut JackDevice> {
self.devices.push(device);
let index = self.devices.len() - 1;