separate input handling for sampler

This commit is contained in:
🪞👃🪞 2025-04-25 20:50:32 +03:00
parent b58fbdfd30
commit b376d75396
11 changed files with 114 additions and 36 deletions

View file

@ -0,0 +1,21 @@
(@u undo 1)
(@shift-u redo 1)
(@space clock toggle)
(@shift-space clock toggle 0)
(@t select :track 0)
(@tab edit :clip)
(@c color)
(@q launch)
(@shift-I input add)
(@shift-O output add)
(@shift-S scene add)
(@shift-T track add)
(@up select :scene-prev)
(@w select :scene-prev)
(@down select :scene-next)
(@s select :scene-next)
(@left select :track-prev)
(@a select :track-prev)
(@right select :track-next)
(@d select :track-next)

View file

@ -0,0 +1,8 @@
(@g clip get)
(@p clip put)
(@delete clip del)
(@comma clip prev)
(@period clip next)
(@lt clip swap-prev)
(@gt clip swap-next)
(@l clip loop-toggle)

View file

View file

@ -0,0 +1,7 @@
(@q scene launch :scene)
(@c scene color :scene)
(@comma scene prev)
(@period scene next)
(@lt scene swap-prev)
(@gt scene swap-next)
(@delete scene delete)

View file

@ -0,0 +1,12 @@
(@q track launch :track)
(@c track color :track)
(@comma track prev)
(@period track next)
(@lt track swap-prev)
(@gt track swap-next)
(@delete track delete)
(@r track rec)
(@m track mon)
(@p track play)
(@P track solo)

View file

@ -0,0 +1,11 @@
(@up select :sample-up)
(@w select :sample-up)
(@down select :sample-down)
(@s select :sample-down)
(@left select :sample-left)
(@a select :sample-left)
(@right select :sample-right)
(@d select :sample-right)

View file

@ -543,27 +543,55 @@ impose!([app: Tek] {
});
handle!(TuiIn: |self: Tek, input|Ok({
handle!(TuiIn: |self: Tek, input|if let Some(handler) = self.handler {
handler(self, input)
} else {
Ok(None)
});
pub fn handle_arranger (app: &mut Tek, input: &TuiIn) -> Perhaps<bool> {
// If editing, editor keys take priority
if self.is_editing() {
if self.editor.handle(input)? == Some(true) {
if app.is_editing() {
if app.editor.handle(input)? == Some(true) {
return Ok(Some(true))
}
}
// Handle from root keymap
if let Some(command) = self.keys.command::<_, TekCommand, _>(self, input) {
if let Some(undo) = command.execute(self)? { self.history.push(undo); }
if let Some(command) = SourceIter(include_str!("../edn/arranger_keys.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 self.selected() {
Selection::Clip(_, _) => self.keys_clip,
Selection::Track(_) => self.keys_track,
Selection::Scene(_) => self.keys_scene,
Selection::Mix => self.keys_mix,
}.command::<_, TekCommand, _>(self, input) {
if let Some(undo) = command.execute(self)? { self.history.push(undo); }
if let Some(command) = match app.selected() {
Selection::Clip(_, _) => SourceIter(include_str!("../edn/arranger_keys_clip.edn")),
Selection::Track(_) => SourceIter(include_str!("../edn/arranger_keys_track.edn")),
Selection::Scene(_) => SourceIter(include_str!("../edn/arranger_keys_scene.edn")),
Selection::Mix => SourceIter(include_str!("../edn/arranger_keys_mix.edn")),
}.command::<_, TekCommand, _>(app, input) {
if let Some(undo) = command.execute(app)? {
app.history.push(undo);
}
return Ok(Some(true))
}
None
}));
Ok(None)
}
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!("../edn/sampler_keys.edn"))
.command::<_, SamplerCommand, _>(sampler, input)
{
if let Some(undo) = command.execute(sampler)? {
//app.history.push(undo); // TODO UNDO
}
return Ok(Some(true))
}
Ok(None)
}

View file

@ -59,17 +59,22 @@ use crate::*;
pub keys_mix: SourceIter<'static>,
// Cache of formatted strings
pub view_cache: Arc<RwLock<ViewCache>>,
// Input handler function
pub handler: Option<fn(&mut Self, &TuiIn)->Result<Option<bool>, Box<(dyn std::error::Error + 'static)>>>
}
impl Tek {
pub(crate) fn clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
self.scene()?.clips.get(self.selected().track()?)?.clone()
}
pub(crate) fn toggle_loop (&mut self) {
if let Some(clip) = self.clip() {
clip.write().unwrap().toggle_loop()
}
}
pub(crate) fn activate (&mut self) -> Usually<()> {
let selected = self.selected().clone();
match selected {
@ -95,6 +100,7 @@ impl Tek {
}
Ok(())
}
pub fn tracks_add (
&mut self, count: usize, width: Option<usize>,
midi_from: &[PortConnect], midi_to: &[PortConnect],
@ -111,6 +117,7 @@ impl Tek {
}
Ok(())
}
pub fn track_add (
&mut self, name: Option<&str>, color: Option<ItemPalette>,
midi_froms: &[PortConnect],
@ -141,12 +148,14 @@ impl Tek {
}
Ok((index, &mut self.tracks_mut()[index]))
}
pub fn track_del (&mut self, index: usize) {
self.tracks_mut().remove(index);
for scene in self.scenes_mut().iter_mut() {
scene.clips.remove(index);
}
}
pub fn scenes_add (&mut self, n: usize) -> Usually<()> {
let scene_color_1 = ItemColor::random();
let scene_color_2 = ItemColor::random();
@ -157,6 +166,7 @@ impl Tek {
}
Ok(())
}
pub fn scene_add (&mut self, name: Option<&str>, color: Option<ItemPalette>)
-> Usually<(usize, &mut Scene)>
{
@ -169,9 +179,11 @@ impl Tek {
let index = self.scenes().len() - 1;
Ok((index, &mut self.scenes_mut()[index]))
}
pub fn scene_default_name (&self) -> Arc<str> {
format!("Sc{:3>}", self.scenes().len() + 1).into()
}
}
has_size!(<TuiOut>|self: Tek|&self.size);
@ -385,6 +397,19 @@ impl Track {
}
None
}
pub fn sampler_mut (&mut self, mut nth: usize) -> Option<&mut Sampler> {
for device in self.devices.iter_mut() {
match device {
Device::Sampler(s) => if nth == 0 {
return Some(s);
} else {
nth -= 1;
},
_ => {}
}
}
None
}
}
impl HasTracks for Tek {