mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-10-08 18:56:42 +02:00
SlotExt::map_inner(_mut); HasClip::clip_mut
This commit is contained in:
parent
ca774cca41
commit
fdee3fbfc8
7 changed files with 214 additions and 168 deletions
|
|
@ -175,17 +175,17 @@ impl<T: HasTracks
|
|||
Ok(None)
|
||||
}
|
||||
/// Launch multiple clips
|
||||
#[command(Launch = "launch")] fn tracks_launch (&mut self, clips: Option<ClipPool>)
|
||||
#[command(Launch = "launch")] fn tracks_launch (&mut self, clips: ClipPool)
|
||||
-> Perhaps<TracksCmd>
|
||||
{
|
||||
if let Some(clips) = clips {
|
||||
for (clip, track) in clips.0.read().iter().zip(self.tracks_mut()) {
|
||||
track.sequencer.enqueue_next(clip);
|
||||
}
|
||||
} else {
|
||||
if clips.len() == 0 {
|
||||
for track in self.tracks_mut().iter_mut() {
|
||||
track.sequencer.enqueue_next(None);
|
||||
}
|
||||
return Ok(None)
|
||||
}
|
||||
for (clip, track) in clips.0.read().iter().zip(self.tracks_mut()) {
|
||||
track.sequencer.enqueue_next(clip.read().as_ref());
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
|
@ -734,16 +734,13 @@ impl<T> ModeControl for T where T: HasModeStack
|
|||
}
|
||||
|
||||
pub trait HasClip {
|
||||
fn clip (&self) -> RwLockReadGuard<'_, Option<Arc<RwLock<MidiClip>>>>;
|
||||
fn clip_mut (&self) -> RwLockWriteGuard<'_, Option<Arc<RwLock<MidiClip>>>>;
|
||||
}
|
||||
impl<T: AsRef<Slot<MidiClip>>> HasClip for T {
|
||||
fn clip (&self) -> RwLockReadGuard<'_, Option<Arc<RwLock<MidiClip>>>> {
|
||||
self.as_ref().0.read()
|
||||
fn clip (&self) -> Option<ArcRwLockReadGuard<RawRwLock, Option<Arc<RwLock<MidiClip>>>>> {
|
||||
self.clip_slot().map(|slot|slot.read())
|
||||
}
|
||||
fn clip_mut (&self) -> RwLockWriteGuard<'_, Option<Arc<RwLock<MidiClip>>>> {
|
||||
self.as_ref().0.write()
|
||||
fn clip_mut (&self) -> Option<ArcRwLockWriteGuard<RawRwLock, Option<Arc<RwLock<MidiClip>>>>> {
|
||||
self.clip_slot().map(|slot|slot.write())
|
||||
}
|
||||
fn clip_slot (&self) -> Option<Slot<MidiClip>>;
|
||||
}
|
||||
|
||||
impl<T> MidiClipControl for T where T: HasClip
|
||||
|
|
@ -752,20 +749,30 @@ impl<T> MidiClipControl for T where T: HasClip
|
|||
+ Namespace<Option<bool>> + Namespace<Option<ItemTheme>>
|
||||
{
|
||||
/// Create a clip at the current position if it does not already exist.
|
||||
#[command(Upsert = "upsert")] fn clip_upsert (&mut self) -> Perhaps<MidiClipCmd> {
|
||||
if self.clip().is_some() {
|
||||
Ok(None)
|
||||
#[command(Upsert = "upsert")] fn clip_upsert (
|
||||
&mut self
|
||||
) -> Perhaps<MidiClipCmd> {
|
||||
Ok(self.clip_mut().map(|mut clip|if clip.is_none() {
|
||||
*clip = Some(Default::default());
|
||||
None // TODO undo
|
||||
} else {
|
||||
*self.clip_mut() = Some(Default::default());
|
||||
Ok(None)
|
||||
}
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
#[command(SetColor = "color")] fn clip_set_color (&mut self, color: Option<ItemTheme>) -> Perhaps<MidiClipCmd> {
|
||||
Ok(self.clip().as_ref().map(|clip|MidiClipCmd::SetColor { color: Some(clip.write().set_color(color)) }))
|
||||
#[command(SetColor = "color")] fn clip_set_color (
|
||||
&mut self, color: Option<ItemTheme>
|
||||
) -> Perhaps<MidiClipCmd> {
|
||||
Ok(self.clip_slot().map_inner_mut(|clip|MidiClipCmd::SetColor {
|
||||
color: Some(clip.set_color(color))
|
||||
}))
|
||||
}
|
||||
/// Toggle looping for the active clip
|
||||
#[command(SetLoop = "loop")] fn clip_toggle_loop (&mut self, looping: Option<bool>) -> Perhaps<MidiClipCmd> {
|
||||
Ok(self.clip().as_ref().map(|clip|MidiClipCmd::SetLoop { looping: Some(clip.write().toggle_loop(looping)) }))
|
||||
#[command(SetLoop = "loop")] fn clip_toggle_loop (
|
||||
&mut self, looping: Option<bool>
|
||||
) -> Perhaps<MidiClipCmd> {
|
||||
Ok(self.clip_slot().map_inner_mut(|clip|MidiClipCmd::SetLoop {
|
||||
looping: Some(clip.toggle_loop(looping))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue