Take management: move takes onto the clip instance

Take management should be per clip instance — deleting a take from one
half of a comped split shouldn't pull it out from under the other half.
That's cleanest if the takes themselves live on the instance rather than
the clip, so they do now.

AudioClipType::TakeFolder is gone entirely. A clip is plain Sampled/Midi
content again, and an instance with a non-empty `takes` list simply
OVERRIDES it with whichever take is active. Splitting already clones the
instance, so each half gets its own take list for free — no index
remapping across instances, no copy-on-write, no shared-state surprise —
and comping still works, because the halves can still each select a
different take. It collapsed machinery too: resolve() moved from the clip
to the instance, and owns_audio_pool_index went back to a one-liner.

Management (DeleteTakeAction, DeleteUnusedTakesAction, RenameTakeAction):
- Right-click a clip with more than one take: `Delete "<active take>"`
  and "Delete Unused Takes". Deletion is named after the take that's
  PLAYING rather than being a generic entry, so you pick the victim by
  selecting it — one clear act instead of hunting a small trash icon in a
  list (which is where this started, and it was fiddly).
- Double-click a take in the dropdown to rename it in place.
- What happens to the selection on delete is the subtle part, and there's
  a test per case: deleting a take BELOW the active one shifts the
  selection down so you keep hearing the same take; deleting the ACTIVE
  take lands on whatever slid into its place (not silently back to take
  1); deleting the LAST take steps back one. The only take can't be
  deleted at all — the menu item isn't offered.
- Deleted takes' audio stays in the pool: undo has to put it back, and
  the other half of a split may still be playing it.

Fixes:
- A recording that stopped before the loop came round wasn't joining an
  existing take list — it landed as a separate overlapping clip. Trigger-
  on-wrap is right for the FIRST recording, but once takes exist there,
  a further run is plainly another take however short. The engine can't
  know that (it's document state), so the editor passes `force_takes`
  with the start-recording command and the run is cut and padded to the
  region even with zero wraps. This forced cycle_loop_len and `wrapped`
  apart on the MIDI side: the region length has to be known from the
  start, but the clip should only pin to full-region length AFTER a pass
  completes, or the bar jumps to full width the moment you hit record.
- Recording a second take left BOTH sounding. append_cycle_takes tore
  down the recording's backend clip by looking it up in
  clip_instance_to_backend_map — but on the audio path the recording
  instance isn't in that map yet; it's only added during promotion, which
  the append path skips. The event already carries the engine's clip id,
  so it's handed over explicitly now.
- The take badge is hidden when there's only one take — no choice to make.
This commit is contained in:
Skyler Lehmkuhl
2026-07-14 12:58:33 -04:00
parent c62164c365
commit 6924fc0ffe
19 changed files with 905 additions and 337 deletions
@@ -1112,6 +1112,11 @@ struct PendingTakeAppend {
/// The throwaway clip + instance the recording itself was captured into.
recording_instance_id: Uuid,
recording_clip_id: Uuid,
/// The recording's backend clip, which has to be torn down or it keeps playing alongside the
/// take folder we're appending to. Carried explicitly rather than looked up in
/// `clip_instance_to_backend_map`, because on the audio path the recording instance isn't in
/// that map yet — it's only added after promotion, which the append path skips.
recording_backend_id: Option<lightningbeam_core::action::BackendClipInstanceId>,
loop_start: Beats,
loop_len: Beats,
takes: Vec<lightningbeam_core::clip::AudioTake>,
@@ -2069,11 +2074,12 @@ impl EditorApp {
layer_id: uuid::Uuid,
recording_instance_id: uuid::Uuid,
recording_clip_id: uuid::Uuid,
recording_backend_id: Option<lightningbeam_core::action::BackendClipInstanceId>,
loop_start: Beats,
loop_len: Beats,
takes: Vec<lightningbeam_core::clip::AudioTake>,
) -> bool {
let Some((target_instance_id, target_clip_id)) = self.action_executor.document().take_folder_at(
let Some(target_instance_id) = self.action_executor.document().take_folder_at(
&layer_id,
loop_start,
loop_len,
@@ -2082,9 +2088,12 @@ impl EditorApp {
return false;
};
// Drop the recording's backend clip; the target instance's own clip gets repointed at the
// new active take by the action's backend sync.
let backend_id = self.clip_instance_to_backend_map.remove(&recording_instance_id);
// Tear down the recording's own backend clip. Without this it keeps playing on top of the
// take folder we're appending to — two takes sounding at once. The target instance's clip is
// separately repointed at the new active take by the action's backend sync below.
let backend_id = recording_backend_id
.or_else(|| self.clip_instance_to_backend_map.remove(&recording_instance_id));
self.clip_instance_to_backend_map.remove(&recording_instance_id);
let track_id = self.layer_to_track_map.get(&layer_id).copied();
if let (Some(backend_id), Some(track_id), Some(controller_arc)) =
(backend_id, track_id, self.audio_controller.as_ref())
@@ -2112,7 +2121,6 @@ impl EditorApp {
let action = lightningbeam_core::actions::AppendTakesAction::new(
layer_id,
target_instance_id,
target_clip_id,
takes,
);
@@ -6692,6 +6700,13 @@ impl eframe::App for EditorApp {
layer_id,
recording_instance_id: instance_id,
recording_clip_id: clip_id,
// The engine's recording clip. It isn't in
// clip_instance_to_backend_map yet (that only happens on
// promotion, which we're skipping), so hand it over
// directly or it'll keep sounding alongside the folder.
recording_backend_id: Some(
lightningbeam_core::action::BackendClipInstanceId::Audio(backend_clip_id),
),
loop_start,
loop_len: loop_len_beats,
takes: new_takes,
@@ -6701,22 +6716,18 @@ impl eframe::App for EditorApp {
continue;
}
// Promote the in-progress recording clip to a take folder.
// Finalize the recording clip, and hang the takes off the INSTANCE.
{
let doc = self.action_executor.document_mut();
if let Some(clip) = doc.audio_clips.get_mut(&clip_id) {
clip.clip_type = lightningbeam_core::clip::AudioClipType::TakeFolder {
takes: takes.iter().enumerate().map(|(i, &(pool_index, _))| {
lightningbeam_core::clip::AudioTake {
name: format!("Take {}", i + 1),
content: lightningbeam_core::clip::TakeContent::Audio { audio_pool_index: pool_index },
}
}).collect(),
recorded_loop_beats: loop_len_beats,
};
// Audio takes are seconds-domain, and every take is
// exactly one cycle region long.
clip.set_content_duration(ClipDuration::Seconds(loop_len_seconds));
// The clip's own content is take 1; the instance's take
// list overrides it with whichever take is active. Every
// take is exactly one cycle region long, so the clip's
// duration is the region.
clip.finalize_recording(
takes[0].0,
loop_len_seconds.seconds_to_f64(),
);
clip.name = format!("Cycle recording ({} takes)", takes.len());
}
@@ -6735,7 +6746,14 @@ impl eframe::App for EditorApp {
inst.trim_start = daw_backend::ContentTime::ZERO;
inst.trim_end =
Some(daw_backend::ContentTime(loop_len_seconds.seconds_to_f64()));
inst.takes = takes.iter().enumerate().map(|(i, &(pool_index, _))| {
lightningbeam_core::clip::AudioTake {
name: format!("Take {}", i + 1),
content: lightningbeam_core::clip::TakeContent::Audio { audio_pool_index: pool_index },
}
}).collect();
inst.active_take = Some(last_take);
inst.recorded_loop_beats = Some(loop_len_beats);
}
}
}
@@ -7029,6 +7047,9 @@ impl eframe::App for EditorApp {
layer_id,
recording_instance_id: rec_inst,
recording_clip_id: doc_clip_id,
// The MIDI path maps its recording instance during
// MidiRecordingProgress, so the map has it.
recording_backend_id: None,
loop_start,
loop_len: loop_len_beats,
takes: new_takes,
@@ -7046,17 +7067,10 @@ impl eframe::App for EditorApp {
{
let doc = self.action_executor.document_mut();
if let Some(clip) = doc.audio_clips.get_mut(&doc_clip_id) {
clip.clip_type = lightningbeam_core::clip::AudioClipType::TakeFolder {
takes: clip_ids.iter().enumerate().map(|(i, &mid)| {
lightningbeam_core::clip::AudioTake {
name: format!("Take {}", i + 1),
content: lightningbeam_core::clip::TakeContent::Midi { midi_clip_id: mid },
}
}).collect(),
recorded_loop_beats: loop_len_beats,
};
// MIDI takes are beats-domain, and every take spans exactly
// one cycle region.
// The clip's own content stays take 1 (the clip the
// recording started on); the instance's take list
// overrides it with whichever take is active. MIDI takes
// are beats-domain and each spans one cycle region.
clip.set_content_duration(ClipDuration::Beats(loop_len_beats));
clip.name = format!("Cycle recording ({} takes)", clip_ids.len());
}
@@ -7071,7 +7085,14 @@ impl eframe::App for EditorApp {
inst.timeline_duration = None;
inst.trim_start = daw_backend::ContentTime::ZERO;
inst.trim_end = Some(daw_backend::ContentTime(loop_len_beats.beats_to_f64()));
inst.takes = clip_ids.iter().enumerate().map(|(i, &mid)| {
lightningbeam_core::clip::AudioTake {
name: format!("Take {}", i + 1),
content: lightningbeam_core::clip::TakeContent::Midi { midi_clip_id: mid },
}
}).collect();
inst.active_take = Some(last_take);
inst.recorded_loop_beats = Some(loop_len_beats);
}
}
}
@@ -7263,6 +7284,7 @@ impl eframe::App for EditorApp {
req.layer_id,
req.recording_instance_id,
req.recording_clip_id,
req.recording_backend_id,
req.loop_start,
req.loop_len,
req.takes,
@@ -43,6 +43,7 @@ pub const CHEVRONS_UP: &str = "\u{e074}";
pub const PLAY: &str = "\u{e13c}";
pub const PAUSE: &str = "\u{e12e}";
pub const REPEAT: &str = "\u{e146}"; // cycle / loop region toggle
pub const TRASH: &str = "\u{e18d}"; // delete a take
pub const SETTINGS: &str = "\u{e154}";
pub const SEARCH: &str = "\u{e151}";
pub const PLUS: &str = "\u{e13d}";
@@ -7,17 +7,7 @@
//! - Image Assets (static images)
use eframe::egui;
use lightningbeam_core::clip::{AudioClip, ResolvedContent, VectorClip};
/// Library label for an audio clip: a take folder advertises how many takes it holds, anything else
/// just names its kind. The library lists *clips*, not placements, so there's no active take here —
/// a folder is previewed by its first take.
fn take_label(clip: &AudioClip, kind: &str) -> String {
match clip.takes() {
Some(takes) => format!("{} ({} takes)", kind, takes.len()),
None => kind.to_string(),
}
}
use lightningbeam_core::clip::{ResolvedContent, VectorClip};
use lightningbeam_core::document::Document;
use lightningbeam_core::layer::AnyLayer;
use std::collections::{HashMap, HashSet};
@@ -928,9 +918,9 @@ impl AssetLibraryPane {
continue;
}
let (extra_info, drag_clip_type) = match &clip.resolve(None) {
ResolvedContent::Audio { .. } => (take_label(clip, "Sampled"), DragClipType::AudioSampled),
ResolvedContent::Midi { .. } => (take_label(clip, "MIDI"), DragClipType::AudioMidi),
let (extra_info, drag_clip_type) = match &clip.resolve() {
ResolvedContent::Audio { .. } => ("Sampled".to_string(), DragClipType::AudioSampled),
ResolvedContent::Midi { .. } => ("MIDI".to_string(), DragClipType::AudioMidi),
ResolvedContent::Recording => {
// Skip recording-in-progress clips (and empty take folders) from asset library
continue;
@@ -1128,12 +1118,12 @@ impl AssetLibraryPane {
for (id, clip) in &document.audio_clips {
if !linked_audio_ids.contains(id) && clip.folder_id == current_folder {
let (extra_info, drag_clip_type) = match &clip.resolve(None) {
let (extra_info, drag_clip_type) = match &clip.resolve() {
ResolvedContent::Audio { .. } => {
(take_label(clip, "Sampled"), DragClipType::AudioSampled)
("Sampled".to_string(), DragClipType::AudioSampled)
}
ResolvedContent::Midi { .. } => {
(take_label(clip, "MIDI"), DragClipType::AudioMidi)
("MIDI".to_string(), DragClipType::AudioMidi)
}
ResolvedContent::Recording => {
// Skip recording-in-progress clips (and empty take folders)
@@ -1775,7 +1765,7 @@ impl AssetLibraryPane {
let prefetched_waveform: Option<Vec<(f32, f32)>> =
if asset_category == AssetCategory::Audio && !self.thumbnail_cache.has(&asset_id) {
if let Some(clip) = document.audio_clips.get(&asset_id) {
if let Some(audio_pool_index) = clip.resolved_audio_pool_index(None).as_ref() {
if let Some(audio_pool_index) = clip.audio_pool_index().as_ref() {
shared.raw_audio_cache.get(audio_pool_index)
.map(|raw| peaks_from_raw_audio(raw, THUMBNAIL_SIZE as usize))
} else {
@@ -1800,7 +1790,7 @@ impl AssetLibraryPane {
AssetCategory::Audio => {
if let Some(clip) = document.audio_clips.get(&asset_id) {
let bg_color = egui::Color32::from_rgba_unmultiplied(40, 40, 40, 200);
match &clip.resolve(None) {
match &clip.resolve() {
ResolvedContent::Audio { .. } => {
let wave_color = egui::Color32::from_rgb(100, 200, 100);
if let Some(ref peaks) = prefetched_waveform {
@@ -2354,7 +2344,7 @@ impl AssetLibraryPane {
AssetCategory::Audio => {
if let Some(clip) = document.audio_clips.get(&asset_id) {
let bg_color = egui::Color32::from_rgba_unmultiplied(40, 40, 40, 200);
match &clip.resolve(None) {
match &clip.resolve() {
ResolvedContent::Audio { audio_pool_index } => {
let wave_color = egui::Color32::from_rgb(100, 200, 100);
let waveform: Option<Vec<(f32, f32)>> = shared.raw_audio_cache.get(audio_pool_index)
@@ -2491,7 +2481,7 @@ impl AssetLibraryPane {
AssetCategory::Audio => {
if let Some(clip) = document.audio_clips.get(&asset_id) {
let bg_color = egui::Color32::from_rgba_unmultiplied(40, 40, 40, 200);
match &clip.resolve(None) {
match &clip.resolve() {
ResolvedContent::Audio { audio_pool_index } => {
let wave_color = egui::Color32::from_rgb(100, 200, 100);
let waveform: Option<Vec<(f32, f32)>> = shared.raw_audio_cache.get(audio_pool_index)
@@ -2812,7 +2802,7 @@ impl AssetLibraryPane {
let prefetched_waveform: Option<Vec<(f32, f32)>> =
if asset_category == AssetCategory::Audio && !self.thumbnail_cache.has(&asset_id) {
if let Some(clip) = document.audio_clips.get(&asset_id) {
if let Some(audio_pool_index) = clip.resolved_audio_pool_index(None).as_ref() {
if let Some(audio_pool_index) = clip.audio_pool_index().as_ref() {
let waveform: Option<Vec<(f32, f32)>> = shared.raw_audio_cache.get(audio_pool_index)
.map(|raw| peaks_from_raw_audio(raw, THUMBNAIL_SIZE as usize));
if waveform.is_some() {
@@ -2852,7 +2842,7 @@ impl AssetLibraryPane {
// Check if it's sampled or MIDI
if let Some(clip) = document.audio_clips.get(&asset_id) {
let bg_color = egui::Color32::from_rgba_unmultiplied(40, 40, 40, 200);
match &clip.resolve(None) {
match &clip.resolve() {
ResolvedContent::Audio { .. } => {
let wave_color = egui::Color32::from_rgb(100, 200, 100);
if let Some(ref peaks) = prefetched_waveform {
@@ -3197,7 +3187,7 @@ impl PaneRenderer for AssetLibraryPane {
println!("🎨 [ASSET_LIB] Checking for thumbnails to invalidate (pools: {:?})", shared.audio_pools_with_new_waveforms);
let mut invalidated_any = false;
for (asset_id, clip) in &document_arc.audio_clips {
if let Some(audio_pool_index) = clip.resolved_audio_pool_index(None).as_ref() {
if let Some(audio_pool_index) = clip.audio_pool_index().as_ref() {
if shared.audio_pools_with_new_waveforms.contains(audio_pool_index) {
println!("❌ [ASSET_LIB] Invalidating thumbnail for asset {} (pool {})", asset_id, audio_pool_index);
self.thumbnail_cache.invalidate(asset_id);
@@ -1807,16 +1807,10 @@ impl InfopanelPane {
ui.label("Name:");
ui.label(&clip.name);
});
let take_count = clip.takes().map(|t| t.len()).unwrap_or(0);
let take_folder_label;
let type_name = match &clip.clip_type {
lightningbeam_core::clip::AudioClipType::Sampled { .. } => "Audio (Sampled)",
lightningbeam_core::clip::AudioClipType::Midi { .. } => "Audio (MIDI)",
lightningbeam_core::clip::AudioClipType::Recording => "Audio (Recording)",
lightningbeam_core::clip::AudioClipType::TakeFolder { .. } => {
take_folder_label = format!("Audio ({} takes)", take_count);
&take_folder_label
}
};
ui.horizontal(|ui| {
ui.label("Type:");
@@ -467,7 +467,7 @@ impl PianoRollPane {
if let Some(clip) = document.audio_clips.get(&instance.clip_id) {
// Resolve through the instance's active take, so a MIDI take folder edits
// whichever take it's actually playing.
if let Some(midi_clip_id) = clip.resolved_midi_clip_id(instance.active_take) {
if let Some(midi_clip_id) = instance.resolved_midi_clip_id(clip) {
let duration = instance.effective_duration(clip.content_duration(), document.tempo_map());
// A MIDI clip's content time IS beats, which is what the piano roll's
// x-axis uses.
@@ -298,6 +298,9 @@ pub struct TimelinePane {
take_badge_hits: Vec<(egui::Rect, uuid::Uuid, uuid::Uuid, usize, usize)>,
/// The take-folder instance whose take menu is open, if any.
open_take_menu: Option<(uuid::Uuid, uuid::Uuid)>,
/// The (instance, take index) being renamed inline in the take menu.
renaming_take: Option<(uuid::Uuid, usize)>,
take_rename_buffer: String,
/// Seconds between the cycle region's start and where the current recording actually began.
/// Zero unless the user punched in mid-region. Used to line the live waveform preview up with
/// the region on each pass.
@@ -741,6 +744,8 @@ impl TimelinePane {
keyframe_diamond_hits: Vec::new(),
take_badge_hits: Vec::new(),
open_take_menu: None,
renaming_take: None,
take_rename_buffer: String::new(),
cycle_record_lead_secs: 0.0,
duration: 10.0, // Default 10 seconds
is_scrubbing: false,
@@ -1148,6 +1153,28 @@ impl TimelinePane {
// The backend records in the beats domain; start_time is the seconds playhead.
let start_beats = shared.action_executor.document().tempo_map().seconds_to_beats(Seconds(start_time));
// Does this layer already hold takes over the cycle region? If so this recording is another
// take, however short it runs — without this, stopping before the loop came round would land
// it as a separate overlapping clip instead of joining the take list. The engine can't work
// this out for itself: whether takes exist is document state.
let force_takes: std::collections::HashMap<uuid::Uuid, bool> = {
let doc = shared.action_executor.document();
let region = match (doc.cycle_enabled, doc.cycle_region) {
(true, Some((ls, le))) if le > ls => Some((ls, le - ls)),
_ => None,
};
candidates
.iter()
.map(|&(layer_id, _, _)| {
let forced = region.is_some_and(|(loop_start, loop_len)| {
doc.take_folder_at(&layer_id, loop_start, loop_len, &uuid::Uuid::nil())
.is_some()
});
(layer_id, forced)
})
.collect()
};
// Step 4: Dispatch recording for each candidate
for &(layer_id, ref cat, _) in &candidates {
match cat {
@@ -1171,7 +1198,7 @@ impl TimelinePane {
}
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
controller.start_recording(track_id, start_beats);
controller.start_recording(track_id, start_beats, force_takes.get(&layer_id).copied().unwrap_or(false));
println!("🎤 Started audio recording on track {:?} at {:.2}s", track_id, start_time);
}
shared.recording_layer_ids.push(layer_id);
@@ -1184,7 +1211,7 @@ impl TimelinePane {
if let Some(controller_arc) = shared.audio_controller {
let mut controller = controller_arc.lock().unwrap();
let clip_id = controller.create_midi_clip(track_id, start_beats, Beats::ZERO);
controller.start_midi_recording(track_id, clip_id, start_beats);
controller.start_midi_recording(track_id, clip_id, start_beats, force_takes.get(&layer_id).copied().unwrap_or(false));
shared.recording_clips.insert(layer_id, clip_id);
println!("🎹 Started MIDI recording on track {:?} at {:.2}s, clip_id={}",
track_id, start_time, clip_id);
@@ -1695,9 +1722,7 @@ impl TimelinePane {
return;
};
// The instance's *stored* selection, which is what rollback must restore — not `active`,
// which is that value clamped for display.
let old_take = document
let Some(instance) = document
.get_layer(&layer_id)
.and_then(|l| match l {
lightningbeam_core::layer::AnyLayer::Audio(al) => {
@@ -1705,7 +1730,14 @@ impl TimelinePane {
}
_ => None,
})
.and_then(|ci| ci.active_take);
else {
self.open_take_menu = None;
return;
};
// The instance's *stored* selection, which is what rollback must restore — not `active`,
// which is that value clamped for display.
let old_take = instance.active_take;
let take_names: Vec<String> = instance.takes.iter().map(|t| t.name.clone()).collect();
let mut close = false;
let area = egui::Area::new(ui.id().with(("take_menu", instance_id)))
@@ -1715,22 +1747,53 @@ impl TimelinePane {
egui::Frame::popup(ui.style()).show(ui, |ui| {
for i in 0..count {
let is_active = i == active;
if ui
.selectable_label(is_active, format!("Take {}", i + 1))
.clicked()
{
if !is_active {
pending_actions.push(Box::new(
lightningbeam_core::actions::SetActiveTakeAction::new(
layer_id,
instance_id,
i,
old_take,
),
));
let renaming = self.renaming_take == Some((instance_id, i));
ui.horizontal(|ui| {
if renaming {
let edit = ui.add(
egui::TextEdit::singleline(&mut self.take_rename_buffer)
.desired_width(110.0),
);
edit.request_focus();
// Commit on Enter or on clicking away; Escape abandons.
let enter = ui.input(|i| i.key_pressed(egui::Key::Enter));
let escape = ui.input(|i| i.key_pressed(egui::Key::Escape));
if enter || edit.lost_focus() && !escape {
let name = self.take_rename_buffer.trim().to_string();
if !name.is_empty() && name != take_names[i] {
pending_actions.push(Box::new(
lightningbeam_core::actions::RenameTakeAction::new(
layer_id, instance_id, i, name,
),
));
}
self.renaming_take = None;
} else if escape {
self.renaming_take = None;
}
return;
}
close = true;
}
let label = ui.selectable_label(is_active, &take_names[i]);
if label.clicked() {
if !is_active {
pending_actions.push(Box::new(
lightningbeam_core::actions::SetActiveTakeAction::new(
layer_id, instance_id, i, old_take,
),
));
}
close = true;
}
// Double-click a take to rename it in place. Deleting lives on the clip's
// right-click menu, not here — a trash icon per row is a small target
// sitting right next to the one you actually meant to click.
if label.double_clicked() {
self.renaming_take = Some((instance_id, i));
self.take_rename_buffer = take_names[i].clone();
}
});
}
});
});
@@ -1743,6 +1806,7 @@ impl TimelinePane {
}
if close {
self.open_take_menu = None;
self.renaming_take = None;
}
}
@@ -3971,7 +4035,7 @@ impl TimelinePane {
if let Some(clip) = document.get_audio_clip(&clip_instance.clip_id) {
// Resolve through the instance's active take, so a take folder draws
// whichever take it actually plays.
match &clip.resolve(clip_instance.active_take) {
match &clip_instance.resolve(clip) {
// MIDI: Draw piano roll (with loop iterations)
lightningbeam_core::clip::ResolvedContent::Midi { midi_clip_id } => {
if let Some(events) = midi_event_cache.get(midi_clip_id) {
@@ -4357,12 +4421,10 @@ impl TimelinePane {
// only. Records a hit rect so the click that opens the take menu can be
// dispatched after rendering (the usual two-phase pattern), rather than
// mutating the document mid-paint.
if let Some(take_count) = document
.get_audio_clip(&clip_instance.clip_id)
.and_then(|c| c.takes().map(|t| t.len()))
.filter(|n| *n > 0)
{
let active = clip_instance.active_take.unwrap_or(0).min(take_count - 1);
// Only worth showing when there's actually a choice to make.
if clip_instance.takes.len() > 1 {
let take_count = clip_instance.takes.len();
let active = clip_instance.active_take_index();
let label = format!("Take {}/{}", active + 1, take_count);
let text_color = theme.text_color(
&["#timeline", ".take-badge"],
@@ -6596,6 +6658,22 @@ impl PaneRenderer for TimelinePane {
enabled
};
// Take management for the clip that was right-clicked. Only offered when there's more
// than one take — with a single take there's nothing to choose between, and "delete the
// only take" would leave the instance with nothing to play.
let take_target: Option<(uuid::Uuid, uuid::Uuid, usize, String)> = ctx_clip_id.and_then(|instance_id| {
let context_layers = document.context_layers(shared.editing_clip_id.as_ref());
for (layer, instances) in all_layer_clip_instances(&context_layers) {
if let Some(ci) = instances.iter().find(|ci| ci.id == instance_id) {
if ci.takes.len() > 1 {
let active = ci.active_take_index();
return Some((layer.id(), instance_id, active, ci.takes[active].name.clone()));
}
}
}
None
});
let area_id = ui.id().with("clip_context_menu");
let mut item_clicked = false;
let area_response = egui::Area::new(area_id)
@@ -6661,6 +6739,34 @@ impl PaneRenderer for TimelinePane {
shared.pending_menu_actions.push(crate::menu::MenuAction::Delete);
item_clicked = true;
}
// Take management, on the clip that was right-clicked. Takes live on the
// INSTANCE, so on a comped split this prunes the half you clicked and leaves
// the other half's alternatives alone.
if let Some((take_layer_id, take_instance_id, active_index, active_name)) = &take_target {
ui.separator();
// Deletes the take that's PLAYING — the one the badge is showing — so
// it's named rather than just "Delete Take".
if menu_item(ui, &format!("Delete \"{}\"", active_name), true) {
shared.pending_actions.push(Box::new(
lightningbeam_core::actions::DeleteTakeAction::new(
*take_layer_id,
*take_instance_id,
*active_index,
),
));
item_clicked = true;
}
if menu_item(ui, "Delete Unused Takes", true) {
shared.pending_actions.push(Box::new(
lightningbeam_core::actions::DeleteUnusedTakesAction::new(
*take_layer_id,
*take_instance_id,
),
));
item_clicked = true;
}
}
});
});