mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
extract clip_auto_create; add clip_auto_remove
This commit is contained in:
parent
2c59b1acfd
commit
a9cfaf9767
3 changed files with 51 additions and 27 deletions
|
|
@ -184,34 +184,13 @@ defcom! { |self, app: Tek|
|
||||||
}
|
}
|
||||||
|
|
||||||
Edit(value: Option<bool>) => {
|
Edit(value: Option<bool>) => {
|
||||||
if let Some(value) = value {
|
let editing = app.is_editing();
|
||||||
if app.is_editing() != value {
|
let value = value.unwrap_or_else(||!app.is_editing());
|
||||||
app.editing.store(value, Relaxed);
|
app.editing.store(value, Relaxed);
|
||||||
}
|
if value {
|
||||||
|
app.clip_auto_create();
|
||||||
} else {
|
} else {
|
||||||
app.editing.store(!app.is_editing(), Relaxed);
|
app.clip_auto_remove();
|
||||||
};
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,44 @@ impl Tek {
|
||||||
format!("Sc{:3>}", self.scenes().len() + 1).into()
|
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);
|
has_size!(<TuiOut>|self: Tek|&self.size);
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,13 @@ impl MidiClip {
|
||||||
color: color.unwrap_or_else(ItemPalette::random)
|
color: color.unwrap_or_else(ItemPalette::random)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn count_midi_messages (&self) -> usize {
|
||||||
|
let mut count = 0;
|
||||||
|
for tick in self.notes.iter() {
|
||||||
|
count += tick.len();
|
||||||
|
}
|
||||||
|
count
|
||||||
|
}
|
||||||
pub fn set_length (&mut self, length: usize) {
|
pub fn set_length (&mut self, length: usize) {
|
||||||
self.length = length;
|
self.length = length;
|
||||||
self.notes = vec![Vec::with_capacity(16);length];
|
self.notes = vec![Vec::with_capacity(16);length];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue