Add nested audio tracks
This commit is contained in:
@@ -43,6 +43,9 @@ pub struct BackendContext<'a> {
|
||||
/// Mapping from document clip instance UUIDs to backend clip instance IDs
|
||||
pub clip_instance_to_backend_map: &'a mut HashMap<Uuid, BackendClipInstanceId>,
|
||||
|
||||
/// Mapping from movie clip UUIDs to backend metatrack (group track) TrackIds
|
||||
pub clip_to_metatrack_map: &'a HashMap<Uuid, daw_backend::TrackId>,
|
||||
|
||||
// Future: pub video_controller: Option<&'a mut VideoController>,
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ pub struct AddLayerAction {
|
||||
/// The layer to add
|
||||
layer: AnyLayer,
|
||||
|
||||
/// If Some, add to this VectorClip's layers instead of root
|
||||
target_clip_id: Option<Uuid>,
|
||||
|
||||
/// ID of the created layer (set after execution)
|
||||
created_layer_id: Option<Uuid>,
|
||||
}
|
||||
@@ -26,6 +29,7 @@ impl AddLayerAction {
|
||||
let layer = VectorLayer::new(name);
|
||||
Self {
|
||||
layer: AnyLayer::Vector(layer),
|
||||
target_clip_id: None,
|
||||
created_layer_id: None,
|
||||
}
|
||||
}
|
||||
@@ -38,10 +42,17 @@ impl AddLayerAction {
|
||||
pub fn new(layer: AnyLayer) -> Self {
|
||||
Self {
|
||||
layer,
|
||||
target_clip_id: None,
|
||||
created_layer_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the target clip for this action (add layer inside a movie clip)
|
||||
pub fn with_target_clip(mut self, clip_id: Option<Uuid>) -> Self {
|
||||
self.target_clip_id = clip_id;
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the ID of the created layer (after execution)
|
||||
pub fn created_layer_id(&self) -> Option<Uuid> {
|
||||
self.created_layer_id
|
||||
@@ -50,8 +61,19 @@ impl AddLayerAction {
|
||||
|
||||
impl Action for AddLayerAction {
|
||||
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
// Add layer to the document's root
|
||||
let layer_id = document.root_mut().add_child(self.layer.clone());
|
||||
let layer_id = if let Some(clip_id) = self.target_clip_id {
|
||||
// Add layer inside a vector clip (movie clip)
|
||||
let clip = document.vector_clips.get_mut(&clip_id)
|
||||
.ok_or_else(|| format!("Target clip {} not found", clip_id))?;
|
||||
let id = self.layer.id();
|
||||
clip.layers.add_root(self.layer.clone());
|
||||
// Register in layer_to_clip_map for O(1) lookup
|
||||
document.layer_to_clip_map.insert(id, clip_id);
|
||||
id
|
||||
} else {
|
||||
// Add layer to the document's root
|
||||
document.root_mut().add_child(self.layer.clone())
|
||||
};
|
||||
|
||||
// Store the ID for rollback
|
||||
self.created_layer_id = Some(layer_id);
|
||||
@@ -62,7 +84,15 @@ impl Action for AddLayerAction {
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
// Remove the created layer if it exists
|
||||
if let Some(layer_id) = self.created_layer_id {
|
||||
document.root_mut().remove_child(&layer_id);
|
||||
if let Some(clip_id) = self.target_clip_id {
|
||||
// Remove from vector clip
|
||||
if let Some(clip) = document.vector_clips.get_mut(&clip_id) {
|
||||
clip.layers.roots.retain(|node| node.data.id() != layer_id);
|
||||
}
|
||||
document.layer_to_clip_map.remove(&layer_id);
|
||||
} else {
|
||||
document.root_mut().remove_child(&layer_id);
|
||||
}
|
||||
|
||||
// Clear the stored ID
|
||||
self.created_layer_id = None;
|
||||
|
||||
@@ -190,6 +190,21 @@ impl Action for MoveClipInstancesAction {
|
||||
let layer = document.get_layer(layer_id)
|
||||
.ok_or_else(|| format!("Layer {} not found", layer_id))?;
|
||||
|
||||
// Handle vector layers: update metatrack offset for movie clips with audio
|
||||
if let AnyLayer::Vector(vl) = layer {
|
||||
for (instance_id, _old_start, new_start) in moves {
|
||||
if let Some(instance) = vl.clip_instances.iter().find(|ci| ci.id == *instance_id) {
|
||||
// Check if this clip has a metatrack
|
||||
if let Some(&metatrack_id) = backend.clip_to_metatrack_map.get(&instance.clip_id) {
|
||||
controller.set_offset(metatrack_id, *new_start);
|
||||
controller.set_trim_start(metatrack_id, instance.trim_start);
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only process audio layers
|
||||
if !matches!(layer, AnyLayer::Audio(_)) {
|
||||
continue;
|
||||
@@ -260,6 +275,20 @@ impl Action for MoveClipInstancesAction {
|
||||
let layer = document.get_layer(layer_id)
|
||||
.ok_or_else(|| format!("Layer {} not found", layer_id))?;
|
||||
|
||||
// Handle vector layers: restore metatrack offset for movie clips with audio
|
||||
if let AnyLayer::Vector(vl) = layer {
|
||||
for (instance_id, old_start, _new_start) in moves {
|
||||
if let Some(instance) = vl.clip_instances.iter().find(|ci| ci.id == *instance_id) {
|
||||
if let Some(&metatrack_id) = backend.clip_to_metatrack_map.get(&instance.clip_id) {
|
||||
controller.set_offset(metatrack_id, *old_start);
|
||||
controller.set_trim_start(metatrack_id, instance.trim_start);
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only process audio layers
|
||||
if !matches!(layer, AnyLayer::Audio(_)) {
|
||||
continue;
|
||||
|
||||
@@ -76,8 +76,8 @@ impl SetLayerPropertiesAction {
|
||||
impl Action for SetLayerPropertiesAction {
|
||||
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
for (i, &layer_id) in self.layer_ids.iter().enumerate() {
|
||||
// Find the layer in the document
|
||||
if let Some(layer) = document.root_mut().get_child_mut(&layer_id) {
|
||||
// Find the layer in the document (searches root + inside movie clips)
|
||||
if let Some(layer) = document.get_layer_mut(&layer_id) {
|
||||
// Store old value if not already stored
|
||||
if self.old_values[i].is_none() {
|
||||
self.old_values[i] = Some(match &self.property {
|
||||
@@ -106,8 +106,8 @@ impl Action for SetLayerPropertiesAction {
|
||||
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
for (i, &layer_id) in self.layer_ids.iter().enumerate() {
|
||||
// Find the layer in the document
|
||||
if let Some(layer) = document.root_mut().get_child_mut(&layer_id) {
|
||||
// Find the layer in the document (searches root + inside movie clips)
|
||||
if let Some(layer) = document.get_layer_mut(&layer_id) {
|
||||
// Restore old value if we have one
|
||||
if let Some(old_value) = &self.old_values[i] {
|
||||
match old_value {
|
||||
|
||||
@@ -355,6 +355,21 @@ impl Action for TrimClipInstancesAction {
|
||||
let layer = document.get_layer(layer_id)
|
||||
.ok_or_else(|| format!("Layer {} not found", layer_id))?;
|
||||
|
||||
// Handle vector layers: update metatrack trim for movie clips with audio
|
||||
if let AnyLayer::Vector(vl) = layer {
|
||||
for (instance_id, _trim_type, _old, _new) in trims {
|
||||
if let Some(instance) = vl.clip_instances.iter().find(|ci| ci.id == *instance_id) {
|
||||
if let Some(&metatrack_id) = backend.clip_to_metatrack_map.get(&instance.clip_id) {
|
||||
// Instance already has new values after execute()
|
||||
controller.set_offset(metatrack_id, instance.timeline_start);
|
||||
controller.set_trim_start(metatrack_id, instance.trim_start);
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only process audio layers
|
||||
if !matches!(layer, AnyLayer::Audio(_)) {
|
||||
continue;
|
||||
@@ -430,6 +445,21 @@ impl Action for TrimClipInstancesAction {
|
||||
let layer = document.get_layer(layer_id)
|
||||
.ok_or_else(|| format!("Layer {} not found", layer_id))?;
|
||||
|
||||
// Handle vector layers: restore metatrack trim for movie clips with audio
|
||||
if let AnyLayer::Vector(vl) = layer {
|
||||
for (instance_id, _trim_type, _old, _new) in trims {
|
||||
if let Some(instance) = vl.clip_instances.iter().find(|ci| ci.id == *instance_id) {
|
||||
if let Some(&metatrack_id) = backend.clip_to_metatrack_map.get(&instance.clip_id) {
|
||||
// Instance already has old values after rollback()
|
||||
controller.set_offset(metatrack_id, instance.timeline_start);
|
||||
controller.set_trim_start(metatrack_id, instance.trim_start);
|
||||
controller.set_trim_end(metatrack_id, instance.trim_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only process audio layers
|
||||
if !matches!(layer, AnyLayer::Audio(_)) {
|
||||
continue;
|
||||
|
||||
@@ -90,14 +90,49 @@ impl VectorClip {
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculate the duration of this clip based on its internal keyframe content.
|
||||
/// Returns the time of the last keyframe across all layers, plus one frame.
|
||||
/// Falls back to the stored `duration` field if no keyframes exist.
|
||||
/// Calculate the duration of this clip based on its internal content.
|
||||
///
|
||||
/// Considers:
|
||||
/// - Vector layer keyframes (last keyframe time + one frame)
|
||||
/// - Audio/video/effect layer clip instances (timeline_start + effective duration)
|
||||
///
|
||||
/// The `clip_duration_fn` resolves referenced clip durations for non-vector layers.
|
||||
/// Falls back to the stored `duration` field if no content exists.
|
||||
pub fn content_duration(&self, framerate: f64) -> f64 {
|
||||
self.content_duration_with(framerate, |_| None)
|
||||
}
|
||||
|
||||
/// Like `content_duration`, but with a closure that resolves clip durations
|
||||
/// for audio/video/effect clip instances inside this movie clip.
|
||||
pub fn content_duration_with(&self, framerate: f64, clip_duration_fn: impl Fn(&Uuid) -> Option<f64>) -> f64 {
|
||||
let frame_duration = 1.0 / framerate;
|
||||
let mut last_time: Option<f64> = None;
|
||||
|
||||
for layer_node in self.layers.iter() {
|
||||
// Check clip instances on ALL layer types (vector, audio, video, effect)
|
||||
let clip_instances: &[ClipInstance] = match &layer_node.data {
|
||||
AnyLayer::Vector(vl) => &vl.clip_instances,
|
||||
AnyLayer::Audio(al) => &al.clip_instances,
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
};
|
||||
for ci in clip_instances {
|
||||
let end = if let Some(td) = ci.timeline_duration {
|
||||
ci.timeline_start + td
|
||||
} else if let Some(te) = ci.trim_end {
|
||||
ci.timeline_start + (te - ci.trim_start).max(0.0)
|
||||
} else if let Some(clip_dur) = clip_duration_fn(&ci.clip_id) {
|
||||
ci.timeline_start + (clip_dur - ci.trim_start).max(0.0)
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
last_time = Some(match last_time {
|
||||
Some(t) => t.max(end),
|
||||
None => end,
|
||||
});
|
||||
}
|
||||
|
||||
// Also check vector layer keyframes
|
||||
if let AnyLayer::Vector(vector_layer) = &layer_node.data {
|
||||
if let Some(last_kf) = vector_layer.keyframes.last() {
|
||||
last_time = Some(match last_time {
|
||||
|
||||
@@ -462,6 +462,15 @@ impl Document {
|
||||
self.context_layers_mut(clip_id).into_iter().find(|l| &l.id() == layer_id)
|
||||
}
|
||||
|
||||
/// Get all layers across the entire document (root + inside all vector clips).
|
||||
pub fn all_layers(&self) -> Vec<&AnyLayer> {
|
||||
let mut layers: Vec<&AnyLayer> = self.root.children.iter().collect();
|
||||
for clip in self.vector_clips.values() {
|
||||
layers.extend(clip.layers.root_data());
|
||||
}
|
||||
layers
|
||||
}
|
||||
|
||||
// === CLIP LIBRARY METHODS ===
|
||||
|
||||
/// Add a vector clip to the library
|
||||
@@ -645,7 +654,21 @@ impl Document {
|
||||
if clip.is_group {
|
||||
Some(clip.duration)
|
||||
} else {
|
||||
Some(clip.content_duration(self.framerate))
|
||||
Some(clip.content_duration_with(self.framerate, |id| {
|
||||
// Resolve nested clip durations (audio, video, other vector clips)
|
||||
if let Some(vc) = self.vector_clips.get(id) {
|
||||
// Avoid deep recursion — use stored duration for nested vector clips
|
||||
Some(vc.content_duration(self.framerate))
|
||||
} else if let Some(ac) = self.audio_clips.get(id) {
|
||||
Some(ac.duration)
|
||||
} else if let Some(vc) = self.video_clips.get(id) {
|
||||
Some(vc.duration)
|
||||
} else if self.effect_definitions.contains_key(id) {
|
||||
Some(crate::effect::EFFECT_DURATION)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}))
|
||||
}
|
||||
} else if let Some(clip) = self.video_clips.get(clip_id) {
|
||||
Some(clip.duration)
|
||||
|
||||
@@ -60,6 +60,10 @@ pub struct SerializedAudioBackend {
|
||||
/// Preserves the connection between UI layers and audio engine tracks across save/load
|
||||
#[serde(default)]
|
||||
pub layer_to_track_map: std::collections::HashMap<uuid::Uuid, u32>,
|
||||
|
||||
/// Mapping from movie clip UUIDs to backend metatrack (group track) TrackIds
|
||||
#[serde(default)]
|
||||
pub clip_to_metatrack_map: std::collections::HashMap<uuid::Uuid, u32>,
|
||||
}
|
||||
|
||||
/// Settings for saving a project
|
||||
@@ -96,6 +100,9 @@ pub struct LoadedProject {
|
||||
/// Mapping from UI layer UUIDs to backend TrackIds (empty for old files)
|
||||
pub layer_to_track_map: std::collections::HashMap<uuid::Uuid, u32>,
|
||||
|
||||
/// Mapping from movie clip UUIDs to backend metatrack TrackIds (empty for old files)
|
||||
pub clip_to_metatrack_map: std::collections::HashMap<uuid::Uuid, u32>,
|
||||
|
||||
/// Loaded audio pool entries
|
||||
pub audio_pool_entries: Vec<AudioPoolEntry>,
|
||||
|
||||
@@ -147,6 +154,7 @@ pub fn save_beam(
|
||||
audio_project: &mut AudioProject,
|
||||
audio_pool_entries: Vec<AudioPoolEntry>,
|
||||
layer_to_track_map: &std::collections::HashMap<uuid::Uuid, u32>,
|
||||
clip_to_metatrack_map: &std::collections::HashMap<uuid::Uuid, u32>,
|
||||
_settings: &SaveSettings,
|
||||
) -> Result<(), String> {
|
||||
let fn_start = std::time::Instant::now();
|
||||
@@ -375,6 +383,7 @@ pub fn save_beam(
|
||||
project: audio_project.clone(),
|
||||
audio_pool_entries: modified_entries,
|
||||
layer_to_track_map: layer_to_track_map.clone(),
|
||||
clip_to_metatrack_map: clip_to_metatrack_map.clone(),
|
||||
},
|
||||
};
|
||||
eprintln!("📊 [SAVE_BEAM] Step 5: Build BeamProject structure took {:.2}ms", step5_start.elapsed().as_secs_f64() * 1000.0);
|
||||
@@ -462,6 +471,7 @@ pub fn load_beam(path: &Path) -> Result<LoadedProject, String> {
|
||||
let mut audio_project = beam_project.audio_backend.project;
|
||||
let audio_pool_entries = beam_project.audio_backend.audio_pool_entries;
|
||||
let layer_to_track_map = beam_project.audio_backend.layer_to_track_map;
|
||||
let clip_to_metatrack_map = beam_project.audio_backend.clip_to_metatrack_map;
|
||||
eprintln!("📊 [LOAD_BEAM] Step 5: Extract document and audio state took {:.2}ms", step5_start.elapsed().as_secs_f64() * 1000.0);
|
||||
|
||||
// 6. Rebuild AudioGraphs from presets
|
||||
@@ -607,6 +617,7 @@ pub fn load_beam(path: &Path) -> Result<LoadedProject, String> {
|
||||
document,
|
||||
audio_project,
|
||||
layer_to_track_map,
|
||||
clip_to_metatrack_map,
|
||||
audio_pool_entries: restored_entries,
|
||||
missing_files,
|
||||
})
|
||||
|
||||
@@ -498,7 +498,7 @@ fn render_clip_instance(
|
||||
}
|
||||
0.0
|
||||
} else {
|
||||
let clip_dur = vector_clip.content_duration(document.framerate);
|
||||
let clip_dur = document.get_clip_duration(&vector_clip.id).unwrap_or(vector_clip.duration);
|
||||
let Some(t) = clip_instance.remap_time(time, clip_dur) else {
|
||||
return; // Clip instance not active at this time
|
||||
};
|
||||
|
||||
@@ -384,6 +384,7 @@ enum FileCommand {
|
||||
path: std::path::PathBuf,
|
||||
document: lightningbeam_core::document::Document,
|
||||
layer_to_track_map: std::collections::HashMap<uuid::Uuid, u32>,
|
||||
clip_to_metatrack_map: std::collections::HashMap<uuid::Uuid, u32>,
|
||||
progress_tx: std::sync::mpsc::Sender<FileProgress>,
|
||||
},
|
||||
Load {
|
||||
@@ -458,8 +459,8 @@ impl FileOperationsWorker {
|
||||
fn run(self) {
|
||||
while let Ok(command) = self.command_rx.recv() {
|
||||
match command {
|
||||
FileCommand::Save { path, document, layer_to_track_map, progress_tx } => {
|
||||
self.handle_save(path, document, &layer_to_track_map, progress_tx);
|
||||
FileCommand::Save { path, document, layer_to_track_map, clip_to_metatrack_map, progress_tx } => {
|
||||
self.handle_save(path, document, &layer_to_track_map, &clip_to_metatrack_map, progress_tx);
|
||||
}
|
||||
FileCommand::Load { path, progress_tx } => {
|
||||
self.handle_load(path, progress_tx);
|
||||
@@ -474,6 +475,7 @@ impl FileOperationsWorker {
|
||||
path: std::path::PathBuf,
|
||||
document: lightningbeam_core::document::Document,
|
||||
layer_to_track_map: &std::collections::HashMap<uuid::Uuid, u32>,
|
||||
clip_to_metatrack_map: &std::collections::HashMap<uuid::Uuid, u32>,
|
||||
progress_tx: std::sync::mpsc::Sender<FileProgress>,
|
||||
) {
|
||||
use lightningbeam_core::file_io::{save_beam, SaveSettings};
|
||||
@@ -516,7 +518,7 @@ impl FileOperationsWorker {
|
||||
let step3_start = std::time::Instant::now();
|
||||
|
||||
let settings = SaveSettings::default();
|
||||
match save_beam(&path, &document, &mut audio_project, audio_pool_entries, layer_to_track_map, &settings) {
|
||||
match save_beam(&path, &document, &mut audio_project, audio_pool_entries, layer_to_track_map, clip_to_metatrack_map, &settings) {
|
||||
Ok(()) => {
|
||||
eprintln!("📊 [SAVE] Step 3: save_beam() took {:.2}ms", step3_start.elapsed().as_secs_f64() * 1000.0);
|
||||
eprintln!("📊 [SAVE] ✅ Total save time: {:.2}ms", save_start.elapsed().as_secs_f64() * 1000.0);
|
||||
@@ -704,6 +706,8 @@ struct EditorApp {
|
||||
// Track ID mapping (Document layer UUIDs <-> daw-backend TrackIds)
|
||||
layer_to_track_map: HashMap<Uuid, daw_backend::TrackId>,
|
||||
track_to_layer_map: HashMap<daw_backend::TrackId, Uuid>,
|
||||
// Movie clip ID -> backend metatrack (group track) mapping
|
||||
clip_to_metatrack_map: HashMap<Uuid, daw_backend::TrackId>,
|
||||
/// Generation counter - incremented on project load to force UI components to reload
|
||||
project_generation: u64,
|
||||
// Clip instance ID mapping (Document clip instance UUIDs <-> backend clip instance IDs)
|
||||
@@ -936,6 +940,7 @@ impl EditorApp {
|
||||
)),
|
||||
layer_to_track_map: HashMap::new(),
|
||||
track_to_layer_map: HashMap::new(),
|
||||
clip_to_metatrack_map: HashMap::new(),
|
||||
project_generation: 0,
|
||||
clip_instance_to_backend_map: HashMap::new(),
|
||||
playback_time: 0.0, // Start at beginning
|
||||
@@ -1309,63 +1314,79 @@ impl EditorApp {
|
||||
fn sync_audio_layers_to_backend(&mut self) {
|
||||
use lightningbeam_core::layer::{AnyLayer, AudioLayerType};
|
||||
|
||||
// Iterate through all layers in the document
|
||||
// Collect audio layers from root and inside vector clips
|
||||
// Each entry: (layer_id, layer_name, audio_type, parent_clip_id)
|
||||
let mut audio_layers_to_sync: Vec<(uuid::Uuid, String, AudioLayerType, Option<uuid::Uuid>)> = Vec::new();
|
||||
|
||||
// Root layers
|
||||
for layer in &self.action_executor.document().root.children {
|
||||
// Only process Audio layers
|
||||
if let AnyLayer::Audio(audio_layer) = layer {
|
||||
let layer_id = audio_layer.layer.id;
|
||||
let layer_name = &audio_layer.layer.name;
|
||||
|
||||
// Skip if already mapped (shouldn't happen, but be defensive)
|
||||
if self.layer_to_track_map.contains_key(&layer_id) {
|
||||
continue;
|
||||
if !self.layer_to_track_map.contains_key(&layer_id) {
|
||||
audio_layers_to_sync.push((
|
||||
layer_id,
|
||||
audio_layer.layer.name.clone(),
|
||||
audio_layer.audio_layer_type,
|
||||
None,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle both MIDI and Sampled audio tracks
|
||||
match audio_layer.audio_layer_type {
|
||||
AudioLayerType::Midi => {
|
||||
// Create daw-backend MIDI track
|
||||
if let Some(ref controller_arc) = self.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
match controller.create_midi_track_sync(layer_name.clone()) {
|
||||
Ok(track_id) => {
|
||||
// Store bidirectional mapping
|
||||
self.layer_to_track_map.insert(layer_id, track_id);
|
||||
self.track_to_layer_map.insert(track_id, layer_id);
|
||||
// Layers inside vector clips
|
||||
for (&clip_id, clip) in &self.action_executor.document().vector_clips {
|
||||
for layer in clip.layers.root_data() {
|
||||
if let AnyLayer::Audio(audio_layer) = layer {
|
||||
let layer_id = audio_layer.layer.id;
|
||||
if !self.layer_to_track_map.contains_key(&layer_id) {
|
||||
audio_layers_to_sync.push((
|
||||
layer_id,
|
||||
audio_layer.layer.name.clone(),
|
||||
audio_layer.audio_layer_type,
|
||||
Some(clip_id),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load default instrument
|
||||
if let Err(e) = default_instrument::load_default_instrument(&mut *controller, track_id) {
|
||||
eprintln!("⚠️ Failed to load default instrument for {}: {}", layer_name, e);
|
||||
} else {
|
||||
println!("✅ Synced MIDI layer '{}' to backend (TrackId: {})", layer_name, track_id);
|
||||
}
|
||||
// Now create backend tracks for each
|
||||
for (layer_id, layer_name, audio_type, parent_clip_id) in audio_layers_to_sync {
|
||||
// If inside a clip, ensure a metatrack exists
|
||||
let parent_track = parent_clip_id.and_then(|cid| self.ensure_metatrack_for_clip(cid));
|
||||
|
||||
// TODO: Sync any existing clips on this layer to the backend
|
||||
// This will be implemented when we add clip synchronization
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("⚠️ Failed to create daw-backend track for MIDI layer '{}': {}", layer_name, e);
|
||||
match audio_type {
|
||||
AudioLayerType::Midi => {
|
||||
if let Some(ref controller_arc) = self.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
match controller.create_midi_track_sync(layer_name.clone(), parent_track) {
|
||||
Ok(track_id) => {
|
||||
self.layer_to_track_map.insert(layer_id, track_id);
|
||||
self.track_to_layer_map.insert(track_id, layer_id);
|
||||
|
||||
if let Err(e) = default_instrument::load_default_instrument(&mut *controller, track_id) {
|
||||
eprintln!("⚠️ Failed to load default instrument for {}: {}", layer_name, e);
|
||||
} else {
|
||||
println!("✅ Synced MIDI layer '{}' to backend (TrackId: {}, parent: {:?})", layer_name, track_id, parent_track);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("⚠️ Failed to create daw-backend track for MIDI layer '{}': {}", layer_name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
AudioLayerType::Sampled => {
|
||||
// Create daw-backend Audio track
|
||||
if let Some(ref controller_arc) = self.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
match controller.create_audio_track_sync(layer_name.clone()) {
|
||||
Ok(track_id) => {
|
||||
// Store bidirectional mapping
|
||||
self.layer_to_track_map.insert(layer_id, track_id);
|
||||
self.track_to_layer_map.insert(track_id, layer_id);
|
||||
println!("✅ Synced Audio layer '{}' to backend (TrackId: {})", layer_name, track_id);
|
||||
|
||||
// TODO: Sync any existing clips on this layer to the backend
|
||||
// This will be implemented when we add clip synchronization
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("⚠️ Failed to create daw-backend audio track for '{}': {}", layer_name, e);
|
||||
}
|
||||
}
|
||||
AudioLayerType::Sampled => {
|
||||
if let Some(ref controller_arc) = self.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
match controller.create_audio_track_sync(layer_name.clone(), parent_track) {
|
||||
Ok(track_id) => {
|
||||
self.layer_to_track_map.insert(layer_id, track_id);
|
||||
self.track_to_layer_map.insert(track_id, layer_id);
|
||||
println!("✅ Synced Audio layer '{}' to backend (TrackId: {}, parent: {:?})", layer_name, track_id, parent_track);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("⚠️ Failed to create daw-backend audio track for '{}': {}", layer_name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1374,6 +1395,36 @@ impl EditorApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure a backend metatrack (group track) exists for a movie clip.
|
||||
/// Returns the metatrack's TrackId, creating one if needed.
|
||||
fn ensure_metatrack_for_clip(&mut self, clip_id: Uuid) -> Option<daw_backend::TrackId> {
|
||||
// Return existing metatrack if already mapped
|
||||
if let Some(&track_id) = self.clip_to_metatrack_map.get(&clip_id) {
|
||||
return Some(track_id);
|
||||
}
|
||||
|
||||
// Create a new metatrack in the backend
|
||||
let clip_name = self.action_executor.document().vector_clips
|
||||
.get(&clip_id)
|
||||
.map(|c| c.name.clone())
|
||||
.unwrap_or_else(|| format!("Clip {}", clip_id));
|
||||
|
||||
if let Some(ref controller_arc) = self.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
match controller.create_group_track_sync(format!("[{}]", clip_name), None) {
|
||||
Ok(track_id) => {
|
||||
self.clip_to_metatrack_map.insert(clip_id, track_id);
|
||||
println!("✅ Created metatrack for clip '{}' (TrackId: {})", clip_name, track_id);
|
||||
return Some(track_id);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("⚠️ Failed to create metatrack for clip '{}': {}", clip_name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Split clip instances at the current playhead position
|
||||
///
|
||||
/// Only splits clips on the active layer, plus any clips linked to them
|
||||
@@ -1487,6 +1538,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
|
||||
if let Err(e) = self.action_executor.execute_with_backend(Box::new(action), &mut backend_context) {
|
||||
@@ -1659,6 +1711,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
if let Err(e) = self
|
||||
.action_executor
|
||||
@@ -1780,6 +1833,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
if let Err(e) = self
|
||||
.action_executor
|
||||
@@ -1894,6 +1948,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
if let Err(e) = self.action_executor.execute_with_backend(Box::new(action), &mut backend_context) {
|
||||
eprintln!("Duplicate clip failed: {}", e);
|
||||
@@ -1973,6 +2028,7 @@ impl EditorApp {
|
||||
// TODO: Add ResetProject command to EngineController
|
||||
self.layer_to_track_map.clear();
|
||||
self.track_to_layer_map.clear();
|
||||
self.clip_to_metatrack_map.clear();
|
||||
|
||||
// Clear file path
|
||||
self.current_file_path = None;
|
||||
@@ -2176,6 +2232,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
match self.action_executor.undo_with_backend(&mut backend_context) {
|
||||
Ok(true) => {
|
||||
@@ -2211,6 +2268,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
match self.action_executor.redo_with_backend(&mut backend_context) {
|
||||
Ok(true) => {
|
||||
@@ -2327,58 +2385,71 @@ impl EditorApp {
|
||||
// Layer menu
|
||||
MenuAction::AddLayer => {
|
||||
// Create a new vector layer with a default name
|
||||
let layer_count = self.action_executor.document().root.children.len();
|
||||
let editing_clip_id = self.editing_context.current_clip_id();
|
||||
let context_layers = self.action_executor.document().context_layers(editing_clip_id.as_ref());
|
||||
let layer_count = context_layers.len();
|
||||
let layer_name = format!("Layer {}", layer_count + 1);
|
||||
|
||||
let action = lightningbeam_core::actions::AddLayerAction::new_vector(layer_name);
|
||||
let action = lightningbeam_core::actions::AddLayerAction::new_vector(layer_name)
|
||||
.with_target_clip(editing_clip_id);
|
||||
let _ = self.action_executor.execute(Box::new(action));
|
||||
|
||||
// Select the newly created layer (last child in the document)
|
||||
if let Some(last_layer) = self.action_executor.document().root.children.last() {
|
||||
// Select the newly created layer (last in context)
|
||||
let context_layers = self.action_executor.document().context_layers(editing_clip_id.as_ref());
|
||||
if let Some(last_layer) = context_layers.last() {
|
||||
self.active_layer_id = Some(last_layer.id());
|
||||
}
|
||||
}
|
||||
MenuAction::AddVideoLayer => {
|
||||
println!("Menu: Add Video Layer");
|
||||
// Create a new video layer with a default name
|
||||
let layer_number = self.action_executor.document().root.children.len() + 1;
|
||||
let editing_clip_id = self.editing_context.current_clip_id();
|
||||
let context_layers = self.action_executor.document().context_layers(editing_clip_id.as_ref());
|
||||
let layer_number = context_layers.len() + 1;
|
||||
let layer_name = format!("Video {}", layer_number);
|
||||
let new_layer = lightningbeam_core::layer::AnyLayer::Video(
|
||||
lightningbeam_core::layer::VideoLayer::new(&layer_name)
|
||||
);
|
||||
|
||||
// Add the layer to the document
|
||||
self.action_executor.document_mut().root.add_child(new_layer.clone());
|
||||
let action = lightningbeam_core::actions::AddLayerAction::new(new_layer)
|
||||
.with_target_clip(editing_clip_id);
|
||||
let _ = self.action_executor.execute(Box::new(action));
|
||||
|
||||
// Set it as the active layer
|
||||
if let Some(last_layer) = self.action_executor.document().root.children.last() {
|
||||
let context_layers = self.action_executor.document().context_layers(editing_clip_id.as_ref());
|
||||
if let Some(last_layer) = context_layers.last() {
|
||||
self.active_layer_id = Some(last_layer.id());
|
||||
}
|
||||
}
|
||||
MenuAction::AddAudioTrack => {
|
||||
// Create a new sampled audio layer with a default name
|
||||
let layer_count = self.action_executor.document().root.children.len();
|
||||
let editing_clip_id = self.editing_context.current_clip_id();
|
||||
let context_layers = self.action_executor.document().context_layers(editing_clip_id.as_ref());
|
||||
let layer_count = context_layers.len();
|
||||
let layer_name = format!("Audio Track {}", layer_count + 1);
|
||||
|
||||
// Create audio layer in document
|
||||
let audio_layer = AudioLayer::new_sampled(layer_name.clone());
|
||||
let action = lightningbeam_core::actions::AddLayerAction::new(AnyLayer::Audio(audio_layer));
|
||||
let action = lightningbeam_core::actions::AddLayerAction::new(AnyLayer::Audio(audio_layer))
|
||||
.with_target_clip(editing_clip_id);
|
||||
let _ = self.action_executor.execute(Box::new(action));
|
||||
|
||||
// Get the newly created layer ID
|
||||
if let Some(last_layer) = self.action_executor.document().root.children.last() {
|
||||
let context_layers = self.action_executor.document().context_layers(editing_clip_id.as_ref());
|
||||
if let Some(last_layer) = context_layers.last() {
|
||||
let layer_id = last_layer.id();
|
||||
self.active_layer_id = Some(layer_id);
|
||||
|
||||
// If inside a clip, ensure a metatrack exists for it
|
||||
let parent_track = editing_clip_id.and_then(|cid| self.ensure_metatrack_for_clip(cid));
|
||||
|
||||
// Create corresponding daw-backend audio track
|
||||
if let Some(ref controller_arc) = self.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
match controller.create_audio_track_sync(layer_name.clone()) {
|
||||
match controller.create_audio_track_sync(layer_name.clone(), parent_track) {
|
||||
Ok(track_id) => {
|
||||
// Store bidirectional mapping
|
||||
self.layer_to_track_map.insert(layer_id, track_id);
|
||||
self.track_to_layer_map.insert(track_id, layer_id);
|
||||
println!("✅ Created {} (backend TrackId: {})", layer_name, track_id);
|
||||
println!("✅ Created {} (backend TrackId: {}, parent: {:?})", layer_name, track_id, parent_track);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("⚠️ Failed to create daw-backend audio track for {}: {}", layer_name, e);
|
||||
@@ -2390,23 +2461,30 @@ impl EditorApp {
|
||||
}
|
||||
MenuAction::AddMidiTrack => {
|
||||
// Create a new MIDI audio layer with a default name
|
||||
let layer_count = self.action_executor.document().root.children.len();
|
||||
let editing_clip_id = self.editing_context.current_clip_id();
|
||||
let context_layers = self.action_executor.document().context_layers(editing_clip_id.as_ref());
|
||||
let layer_count = context_layers.len();
|
||||
let layer_name = format!("MIDI Track {}", layer_count + 1);
|
||||
|
||||
// Create MIDI layer in document
|
||||
let midi_layer = AudioLayer::new_midi(layer_name.clone());
|
||||
let action = lightningbeam_core::actions::AddLayerAction::new(AnyLayer::Audio(midi_layer));
|
||||
let action = lightningbeam_core::actions::AddLayerAction::new(AnyLayer::Audio(midi_layer))
|
||||
.with_target_clip(editing_clip_id);
|
||||
let _ = self.action_executor.execute(Box::new(action));
|
||||
|
||||
// Get the newly created layer ID
|
||||
if let Some(last_layer) = self.action_executor.document().root.children.last() {
|
||||
let context_layers = self.action_executor.document().context_layers(editing_clip_id.as_ref());
|
||||
if let Some(last_layer) = context_layers.last() {
|
||||
let layer_id = last_layer.id();
|
||||
self.active_layer_id = Some(layer_id);
|
||||
|
||||
// If inside a clip, ensure a metatrack exists for it
|
||||
let parent_track = editing_clip_id.and_then(|cid| self.ensure_metatrack_for_clip(cid));
|
||||
|
||||
// Create corresponding daw-backend MIDI track
|
||||
if let Some(ref controller_arc) = self.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
match controller.create_midi_track_sync(layer_name.clone()) {
|
||||
match controller.create_midi_track_sync(layer_name.clone(), parent_track) {
|
||||
Ok(track_id) => {
|
||||
// Store bidirectional mapping
|
||||
self.layer_to_track_map.insert(layer_id, track_id);
|
||||
@@ -2627,6 +2705,7 @@ impl EditorApp {
|
||||
path: path.clone(),
|
||||
document,
|
||||
layer_to_track_map: self.layer_to_track_map.clone(),
|
||||
clip_to_metatrack_map: self.clip_to_metatrack_map.clone(),
|
||||
progress_tx,
|
||||
};
|
||||
|
||||
@@ -2776,6 +2855,15 @@ impl EditorApp {
|
||||
eprintln!("📊 [APPLY] Step 5: No saved track mappings (old file format)");
|
||||
}
|
||||
|
||||
// Restore clip-to-metatrack mappings
|
||||
if !loaded_project.clip_to_metatrack_map.is_empty() {
|
||||
for (&clip_id, &track_id) in &loaded_project.clip_to_metatrack_map {
|
||||
self.clip_to_metatrack_map.insert(clip_id, track_id);
|
||||
}
|
||||
eprintln!("📊 [APPLY] Step 5b: Restored {} clip-to-metatrack mappings",
|
||||
loaded_project.clip_to_metatrack_map.len());
|
||||
}
|
||||
|
||||
// Sync any audio layers that don't have a mapping yet (new layers, or old file format)
|
||||
let step6_start = std::time::Instant::now();
|
||||
self.sync_audio_layers_to_backend();
|
||||
@@ -3317,12 +3405,16 @@ impl EditorApp {
|
||||
// Update active layer to the new layer
|
||||
self.active_layer_id = target_layer_id;
|
||||
|
||||
// If inside a clip, ensure a metatrack exists for it
|
||||
let editing_clip_id = self.editing_context.current_clip_id();
|
||||
let parent_track = editing_clip_id.and_then(|cid| self.ensure_metatrack_for_clip(cid));
|
||||
|
||||
// Create a backend audio/MIDI track and add the mapping
|
||||
if let Some(ref controller_arc) = self.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
match asset_info.clip_type {
|
||||
panes::DragClipType::AudioSampled => {
|
||||
match controller.create_audio_track_sync(layer_name.clone()) {
|
||||
match controller.create_audio_track_sync(layer_name.clone(), parent_track) {
|
||||
Ok(track_id) => {
|
||||
self.layer_to_track_map.insert(layer_id, track_id);
|
||||
self.track_to_layer_map.insert(track_id, layer_id);
|
||||
@@ -3331,7 +3423,7 @@ impl EditorApp {
|
||||
}
|
||||
}
|
||||
panes::DragClipType::AudioMidi => {
|
||||
match controller.create_midi_track_sync(layer_name.clone()) {
|
||||
match controller.create_midi_track_sync(layer_name.clone(), parent_track) {
|
||||
Ok(track_id) => {
|
||||
self.layer_to_track_map.insert(layer_id, track_id);
|
||||
self.track_to_layer_map.insert(track_id, layer_id);
|
||||
@@ -3432,6 +3524,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
|
||||
if let Err(e) = self.action_executor.execute_with_backend(Box::new(action), &mut backend_context) {
|
||||
@@ -3477,6 +3570,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
|
||||
if let Err(e) = self.action_executor.execute_with_backend(Box::new(audio_action), &mut backend_context) {
|
||||
@@ -3505,8 +3599,9 @@ impl EditorApp {
|
||||
let document = self.action_executor.document();
|
||||
let mut video_instance_info: Option<(uuid::Uuid, uuid::Uuid, f64)> = None; // (layer_id, instance_id, timeline_start)
|
||||
|
||||
// Search all layers for a video clip instance with matching clip_id
|
||||
for layer in &document.root.children {
|
||||
// Search all layers (root + inside movie clips) for a video clip instance with matching clip_id
|
||||
let all_layers = document.all_layers();
|
||||
for layer in &all_layers {
|
||||
if let AnyLayer::Video(video_layer) = layer {
|
||||
for instance in &video_layer.clip_instances {
|
||||
if instance.clip_id == video_clip_id {
|
||||
@@ -3559,6 +3654,7 @@ impl EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
|
||||
if let Err(e) = self.action_executor.execute_with_backend(Box::new(audio_action), &mut backend_context) {
|
||||
@@ -3923,10 +4019,8 @@ impl eframe::App for EditorApp {
|
||||
let clip_instance = ClipInstance::new(doc_clip_id)
|
||||
.with_timeline_start(self.recording_start_time);
|
||||
|
||||
// Add instance to layer
|
||||
if let Some(layer) = self.action_executor.document_mut().root.children.iter_mut()
|
||||
.find(|l| l.id() == layer_id)
|
||||
{
|
||||
// Add instance to layer (works for root and inside movie clips)
|
||||
if let Some(layer) = self.action_executor.document_mut().get_layer_mut(&layer_id) {
|
||||
if let lightningbeam_core::layer::AnyLayer::Audio(audio_layer) = layer {
|
||||
audio_layer.clip_instances.push(clip_instance);
|
||||
println!("✅ Created recording clip instance on layer {}", layer_id);
|
||||
@@ -3948,8 +4042,7 @@ impl eframe::App for EditorApp {
|
||||
// First, find the clip_id from the layer (read-only borrow)
|
||||
let clip_id = {
|
||||
let document = self.action_executor.document();
|
||||
document.root.children.iter()
|
||||
.find(|l| l.id() == layer_id)
|
||||
document.get_layer(&layer_id)
|
||||
.and_then(|layer| {
|
||||
if let lightningbeam_core::layer::AnyLayer::Audio(audio_layer) = layer {
|
||||
audio_layer.clip_instances.last().map(|i| i.clip_id)
|
||||
@@ -4014,8 +4107,7 @@ impl eframe::App for EditorApp {
|
||||
// First, find the clip instance and clip id
|
||||
let (clip_id, instance_id, timeline_start, trim_start) = {
|
||||
let document = self.action_executor.document();
|
||||
document.root.children.iter()
|
||||
.find(|l| l.id() == layer_id)
|
||||
document.get_layer(&layer_id)
|
||||
.and_then(|layer| {
|
||||
if let lightningbeam_core::layer::AnyLayer::Audio(audio_layer) = layer {
|
||||
audio_layer.clip_instances.last().map(|instance| {
|
||||
@@ -4093,8 +4185,7 @@ impl eframe::App for EditorApp {
|
||||
if let Some(layer_id) = self.recording_layer_id {
|
||||
let doc_clip_id = {
|
||||
let document = self.action_executor.document();
|
||||
document.root.children.iter()
|
||||
.find(|l| l.id() == layer_id)
|
||||
document.get_layer(&layer_id)
|
||||
.and_then(|layer| {
|
||||
if let lightningbeam_core::layer::AnyLayer::Audio(audio_layer) = layer {
|
||||
audio_layer.clip_instances.last().map(|i| i.clip_id)
|
||||
@@ -4153,8 +4244,7 @@ impl eframe::App for EditorApp {
|
||||
if let Some(layer_id) = self.recording_layer_id {
|
||||
let doc_clip_id = {
|
||||
let document = self.action_executor.document();
|
||||
document.root.children.iter()
|
||||
.find(|l| l.id() == layer_id)
|
||||
document.get_layer(&layer_id)
|
||||
.and_then(|layer| {
|
||||
if let lightningbeam_core::layer::AnyLayer::Audio(audio_layer) = layer {
|
||||
audio_layer.clip_instances.last().map(|i| i.clip_id)
|
||||
@@ -4512,6 +4602,7 @@ impl eframe::App for EditorApp {
|
||||
{
|
||||
let time = self.playback_time;
|
||||
let document = self.action_executor.document_mut();
|
||||
// Bake animation transforms for root layers
|
||||
for layer in document.root.children.iter_mut() {
|
||||
if let lightningbeam_core::layer::AnyLayer::Vector(vl) = layer {
|
||||
for ci in &mut vl.clip_instances {
|
||||
@@ -4523,6 +4614,20 @@ impl eframe::App for EditorApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bake animation transforms for layers inside movie clips
|
||||
for clip in document.vector_clips.values_mut() {
|
||||
for layer_node in clip.layers.roots.iter_mut() {
|
||||
if let lightningbeam_core::layer::AnyLayer::Vector(vl) = &mut layer_node.data {
|
||||
for ci in &mut vl.clip_instances {
|
||||
let (t, opacity) = vl.layer.animation_data.eval_clip_instance_transform(
|
||||
ci.id, time, &ci.transform, ci.opacity,
|
||||
);
|
||||
ci.transform = t;
|
||||
ci.opacity = opacity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create render context
|
||||
@@ -4636,6 +4741,7 @@ impl eframe::App for EditorApp {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: &self.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut self.clip_instance_to_backend_map,
|
||||
clip_to_metatrack_map: &self.clip_to_metatrack_map,
|
||||
};
|
||||
|
||||
// Execute action with backend synchronization
|
||||
|
||||
@@ -1310,8 +1310,8 @@ impl AssetLibraryPane {
|
||||
|
||||
/// Check if an asset is currently in use (has clip instances on layers)
|
||||
fn is_asset_in_use(document: &Document, asset_id: Uuid, category: AssetCategory) -> bool {
|
||||
// Check all layers for clip instances referencing this asset
|
||||
for layer in &document.root.children {
|
||||
// Check all layers (root + inside movie clips) for clip instances referencing this asset
|
||||
for layer in document.all_layers() {
|
||||
match layer {
|
||||
lightningbeam_core::layer::AnyLayer::Vector(vl) => {
|
||||
if category == AssetCategory::Vector {
|
||||
|
||||
@@ -636,10 +636,12 @@ impl NodeGraphPane {
|
||||
let mut controller = audio_controller.lock().unwrap();
|
||||
// Node graph actions don't use clip instances, so we use an empty map
|
||||
let mut empty_clip_map = std::collections::HashMap::new();
|
||||
let empty_metatrack_map = std::collections::HashMap::new();
|
||||
let mut backend_context = lightningbeam_core::action::BackendContext {
|
||||
audio_controller: Some(&mut *controller),
|
||||
layer_to_track_map: shared.layer_to_track_map,
|
||||
clip_instance_to_backend_map: &mut empty_clip_map,
|
||||
clip_to_metatrack_map: &empty_metatrack_map,
|
||||
};
|
||||
|
||||
if let Err(e) = shared.action_executor.execute_with_backend(action, &mut backend_context) {
|
||||
|
||||
@@ -110,8 +110,8 @@ fn effective_clip_duration(
|
||||
let end = vl.group_visibility_end(&clip_instance.id, clip_instance.timeline_start, frame_duration);
|
||||
Some((end - clip_instance.timeline_start).max(0.0))
|
||||
} else {
|
||||
// Movie clips: duration based on internal keyframe content
|
||||
Some(vc.content_duration(document.framerate))
|
||||
// Movie clips: duration based on all internal content (keyframes + clip instances)
|
||||
document.get_clip_duration(&clip_instance.clip_id)
|
||||
}
|
||||
}
|
||||
AnyLayer::Audio(_) => document.get_audio_clip(&clip_instance.clip_id).map(|c| c.duration),
|
||||
@@ -315,9 +315,7 @@ impl TimelinePane {
|
||||
let clip_instance = ClipInstance::new(doc_clip_id)
|
||||
.with_timeline_start(start_time);
|
||||
|
||||
if let Some(layer) = shared.action_executor.document_mut().root.children.iter_mut()
|
||||
.find(|l| l.id() == active_layer_id)
|
||||
{
|
||||
if let Some(layer) = shared.action_executor.document_mut().get_layer_mut(&active_layer_id) {
|
||||
if let lightningbeam_core::layer::AnyLayer::Audio(audio_layer) = layer {
|
||||
audio_layer.clip_instances.push(clip_instance);
|
||||
}
|
||||
@@ -3313,8 +3311,15 @@ impl PaneRenderer for TimelinePane {
|
||||
let new_layer = super::create_layer_for_clip_type(dragging.clip_type, &layer_name);
|
||||
let new_layer_id = new_layer.id();
|
||||
|
||||
// Add the layer
|
||||
shared.action_executor.document_mut().root.add_child(new_layer);
|
||||
// Add the layer to the current editing context
|
||||
if let Some(clip_id) = shared.editing_clip_id {
|
||||
if let Some(clip) = shared.action_executor.document_mut().vector_clips.get_mut(&clip_id) {
|
||||
clip.layers.add_root(new_layer);
|
||||
}
|
||||
shared.action_executor.document_mut().layer_to_clip_map.insert(new_layer_id, clip_id);
|
||||
} else {
|
||||
shared.action_executor.document_mut().root.add_child(new_layer);
|
||||
}
|
||||
|
||||
// Now add the clip to the new layer
|
||||
if dragging.clip_type == DragClipType::Effect {
|
||||
|
||||
Reference in New Issue
Block a user