FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
fix(engine): enable Multi-Camera Enable/Flatten only for clips they work on
Sam Sandweissbe283bc54ce6
diff --git a/crates/engine/src/multicam.rs b/crates/engine/src/multicam.rsindex 23824942b..66e36308f 100644--- a/crates/engine/src/multicam.rs+++ b/crates/engine/src/multicam.rs@@ -163,8 +163,8 @@ fn base_commands() -> Vec<CommandSpec> {create_multicam,true,),- spec("clip.multicamEnable", "Enable", &["Clip", "Multi-Camera"], r#"{"clips":[id]?,"enabled":bool?}"#, has_selection, enable, true),- spec("clip.multicamFlatten", "Flatten", &["Clip", "Multi-Camera"], r#"{"clips":[id]?}"#, has_selection, flatten, true),+ spec("clip.multicamEnable", "Enable", &["Clip", "Multi-Camera"], r#"{"clips":[id]?,"enabled":bool?}"#, has_nested_selection, enable, true),+ spec("clip.multicamFlatten", "Flatten", &["Clip", "Multi-Camera"], r#"{"clips":[id]?}"#, has_multicam_selection, flatten, true),spec("multicam.switchAngle","Switch Multi-Camera Angle",@@ -745,6 +745,24 @@ fn switch_angle(s: &mut Session, p: &Value) -> Result<Value> {Ok(json!({"angle": angle, "changed": n}))}+/// Clip ▸ Multi-Camera ▸ Enable: the selection (with its linked clips) holds a nested sequence+/// clip, as [`enable`] needs; the menu item is greyed out otherwise instead of failing when chosen.+fn has_nested_selection(s: &Session) -> std::result::Result<(), String> {+ has_selection(s)?;+ let q = s.active_sequence().ok_or("no sequence")?;+ let nested = with_links(s, &s.state.selection).iter().any(|c| q.find_item(*c).is_some_and(|(_, i)| s.project.sequence(i.item).is_some()));+ if nested { Ok(()) } else { Err("select nested sequence or multi-camera clips".into()) }+}++/// Clip ▸ Multi-Camera ▸ Flatten: the selection (with its linked clips) holds an enabled+/// multi-camera clip, as [`flatten`] needs.+fn has_multicam_selection(s: &Session) -> std::result::Result<(), String> {+ has_selection(s)?;+ let q = s.active_sequence().ok_or("no sequence")?;+ let multicam = with_links(s, &s.state.selection).iter().any(|c| q.find_item(*c).is_some_and(|(_, i)| i.multicam.is_some_and(|m| m.enabled)));+ if multicam { Ok(()) } else { Err("select multi-camera clips to flatten".into()) }+}+fn enable(s: &mut Session, p: &Value) -> Result<Value> {let q = s.active_sequence().ok_or(EngineError::NoSequence)?.clone();let clips = with_links(s, &clips_p(s, p));diff --git a/crates/engine/src/multicam_tests.rs b/crates/engine/src/multicam_tests.rsindex 486d33730..1a8c3528b 100644--- a/crates/engine/src/multicam_tests.rs+++ b/crates/engine/src/multicam_tests.rs@@ -841,3 +841,30 @@ fn perf_grid_of_four_1080p_angles() {"Multi-Camera grid (4 × 1080p H.264, ¼-scale cells): {grid_ms:.1} ms/frame wall, {grid_cpu:.1} ms/frame CPU; one angle at ½ scale: {one_ms:.1} ms/frame wall (24 fps budget 41.7 ms)");}++/// Clip ▸ Multi-Camera ▸ Enable / Flatten were enabled for any selection and then failed when+/// chosen with plain clips selected. They are enabled when the selection holds what they work on:+/// a nested sequence clip (Enable), an enabled multi-camera clip (Flatten). Naming the clips still+/// works with nothing selected.+#[test]+fn multicam_menu_items_are_enabled_only_for_clips_they_work_on() {+ let mut s = Session::default();+ s.execute("file.openDemoProject", json!({})).unwrap();+ let first = s.active_sequence().unwrap().video_tracks[0].items[0].id;+ s.execute("timeline.select", json!({"clips": [first.0]})).unwrap();+ assert!(!s.is_enabled("clip.multicamEnable"), "a plain clip is not a nest");+ assert!(!s.is_enabled("clip.multicamFlatten"));+ s.execute("clip.nest", json!({"name": "Nest"})).unwrap();+ let nest = s.active_sequence().unwrap().all_tracks().flat_map(|t| &t.items).find(|i| s.project.sequence(i.item).is_some()).map(|i| i.id).unwrap();+ s.execute("timeline.select", json!({"clips": [nest.0]})).unwrap();+ assert!(s.is_enabled("clip.multicamEnable"), "a nested sequence clip can become multi-camera");+ assert!(!s.is_enabled("clip.multicamFlatten"), "not multi-camera yet");+ s.execute("clip.multicamEnable", json!({})).unwrap();+ assert!(s.is_enabled("clip.multicamFlatten"));+ // agents naming the clips do not depend on the selection+ s.execute("edit.deselectAll", json!({})).unwrap();+ assert!(!s.is_enabled("clip.multicamFlatten"));+ s.execute("clip.multicamFlatten", json!({"clips": [nest.0]})).unwrap();+ let q = s.active_sequence().unwrap();+ assert!(q.find_item(nest).is_none(), "flattened into the camera clips");+}