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

@ -46,8 +46,9 @@
(:11 (35 100) (36 100))
(:12 (44 100) (40 100))
(:14 (44 100)))
(phrase { :name "Trapping" :beats 4 :steps 48 }
(:00 (42 100) (36 100) (34 100))
(phrase { :name "Trapping" :beats 8 :steps 96 }
(:00 (42 100) (36 100) (34 120))
(:01 (42 100))
(:02 (42 100))
(:06 (42 100) (36 100))
@ -56,14 +57,34 @@
(:08 (42 100))
(:12 (42 100))
(:18 (42 100))
(:24 (42 100) (38 100) (40 50))
(:24 (42 100) (38 50) (40 50))
(:27 (42 100) (36 50))
(:30 (42 100) (34 100))
(:33 (42 100) (36 50))
(:36 (42 90))
(:39 (42 80))
(:42 (42 70) (38 100) (40 50))
(:45 (42 60)))
(:42 (42 70))
(:45 (42 60))
(:48 (42 100) (36 100) (34 100))
(:50 (42 100))
(:52 (42 100))
(:54 (42 100))
(:56 (42 100))
(:58 (42 100))
(:60 (42 100) (35 100))
(:66 (42 100) (34 100))
(:70 (42 100))
(:71 (42 100))
(:72 (42 100) (38 50) (40 50))
(:75 (42 100) (36 50) (34 80))
(:78 (42 100))
(:81 (42 100) (36 50))
(:84 (42 90) (38 40) (40 50) (34 90))
(:87 (42 90) (35 40))
(:90 (42 70)))
(sampler { :name "DrumKit1" :dir "/home/user/Lab/Music/pak" }
(sample { :midi 34 :name "808" :file "808.wav" })
(sample { :midi 35 :name "KC1" :file "kik.wav" })

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;