extract clip_auto_create; add clip_auto_remove

This commit is contained in:
🪞👃🪞 2025-04-26 13:48:23 +03:00
parent 2c59b1acfd
commit a9cfaf9767
3 changed files with 51 additions and 27 deletions

View file

@ -184,6 +184,44 @@ impl Tek {
format!("Sc{:3>}", self.scenes().len() + 1).into()
}
// Create new clip in pool when entering empty cell
pub fn clip_auto_create (&mut self) {
if let Some(ref pool) = self.pool
&& let Selection::Clip(t, s) = self.selected
&& let Some(scene) = self.scenes.get_mut(s)
&& let Some(slot) = scene.clips.get_mut(t)
&& slot.is_none()
{
let (index, mut clip) = pool.add_new_clip();
// autocolor: new clip colors from scene and track color
clip.write().unwrap().color = ItemColor::random_near(
self.tracks[t].color.base.mix(
scene.color.base,
0.5
),
0.2
).into();
if let Some(ref mut editor) = self.editor {
editor.set_clip(Some(&clip));
}
*slot = Some(clip);
}
}
// Remove clip from arrangement when exiting empty clip editor
pub fn clip_auto_remove (&mut self) {
if let Some(ref pool) = self.pool
&& let Selection::Clip(t, s) = self.selected
&& let Some(scene) = self.scenes.get_mut(s)
&& let Some(slot) = scene.clips.get_mut(t)
&& let Some(clip) = slot
{
if clip.read().unwrap().count_midi_messages() == 0 {
*slot = None;
}
}
}
}
has_size!(<TuiOut>|self: Tek|&self.size);