wip: simplify clip traits to implement upsert

This commit is contained in:
i do not exist 2026-09-20 15:33:42 +03:00
parent 8b96ddb411
commit c5d6ce24b2
5 changed files with 178 additions and 184 deletions

View file

@ -19,6 +19,21 @@ use crate::*;
#[cfg(feature = "sampler")] pub samples: Arc<RwLock<Vec<Arc<RwLock<Sample>>>>>,
}
impl HasClips for Pool {
fn clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
self.clips.read().get(self.clip_index()).map(|c|c.clone())
}
fn clip_mut (&self) -> &mut Option<Arc<RwLock<MidiClip>>> {
todo!()
}
fn clips <'a> (&'a self) -> RwLockReadGuard<'a, Clips> {
self.clips.read()
}
fn clips_mut <'a> (&'a self) -> RwLockWriteGuard<'a, Clips> {
self.clips.write()
}
}
/// Displays and edits clip length.
#[derive(Clone, Debug, Default)] pub struct ClipLength {
/// Pulses per beat (quaver)
@ -326,10 +341,6 @@ pub trait PoolController: HasPool
}
has_clip!(|self: Pool|self.clips().get(self.clip_index()).map(|c|c.clone()));
impl_has_clips!(|self: Pool|self.clips);
impl_from!(Pool: |clip:&Arc<RwLock<MidiClip>>|{
let model = Self::default();
model.clips.try_write().unwrap().push(clip.clone());