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,34 +184,13 @@ defcom! { |self, app: Tek|
}
Edit(value: Option<bool>) => {
if let Some(value) = value {
if app.is_editing() != value {
app.editing.store(value, Relaxed);
}
let editing = app.is_editing();
let value = value.unwrap_or_else(||!app.is_editing());
app.editing.store(value, Relaxed);
if value {
app.clip_auto_create();
} else {
app.editing.store(!app.is_editing(), Relaxed);
};
// autocreate: create new clip from pool when entering empty cell
if let Some(ref pool) = app.pool
&& app.is_editing()
&& let Selection::Clip(t, s) = app.selected
&& let Some(scene) = app.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(
app.tracks[t].color.base.mix(
scene.color.base,
0.5
),
0.2
).into();
if let Some(ref mut editor) = app.editor {
editor.set_clip(Some(&clip));
}
*slot = Some(clip);
app.clip_auto_remove();
}
None
}

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);