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

@ -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 {