From b0e58fad08bd13fbc39abd9270172f59306d8c23 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sun, 8 Nov 2026 16:49:18 +0100 Subject: [PATCH] Footage cache (#3271): no expression on a channel selection by any form of Add Expression prop.setExpression refused only a non-empty text on a property that can't be animated, but a call without text (a toggle) or with enabled: true adds the default expression, and pasting expressions (Copy Expression Only) set them too. Every call that would add, switch on or change an expression on such a property is now refused, switching an old one off or removing it still works, and a pasted expression skips such properties. Tests: both bypass forms are refused (they fail on the old code); an old expression can be switched off and removed but not on again. --- crates/engine/src/cmd/edit.rs | 3 ++- crates/engine/src/cmd/prop.rs | 17 +++++++++++++++- crates/engine/src/tests/aux_footage.rs | 27 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index c2ecb838d..36717cbb1 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -553,7 +553,8 @@ fn paste_links(s: &mut Session, clip: LinkClip) -> Result { let l = super::layer_mut(proj, cid, *lid)?; for (path, e) in &pairs { let path = super::resolve_effect_path(l, path); - if let Some(pr) = l.props.prop_mut(&path) { + // (a property that can't be animated takes no expression) + if let Some(pr) = l.props.prop_mut(&path).filter(|pr| !pr.static_only) { pr.expr = Some(e.clone()); n += 1; } diff --git a/crates/engine/src/cmd/prop.rs b/crates/engine/src/cmd/prop.rs index a76888520..2089ae65c 100644 --- a/crates/engine/src/cmd/prop.rs +++ b/crates/engine/src/cmd/prop.rs @@ -694,6 +694,19 @@ fn apply_expr(pr: &mut Property, text: &Option, enabled: Option, d } } +/// Whether [`apply_expr`] would leave `pr` with an enabled expression it didn't have (a new one, +/// one switched on, or new text). +fn adds_expression(pr: &Property, text: &Option, enabled: Option, def: &str) -> bool { + let mut after = pr.clone(); + apply_expr(&mut after, text, enabled, def); + match (&pr.expr, &after.expr) { + (_, None) => false, + (_, Some(a)) if !a.enabled => false, + (Some(b), Some(a)) => !b.enabled || b.text != a.text, + (None, Some(_)) => true, + } +} + /// `{layer?, path|prop, ...}` for one property, or (Animation > Add Expression) no `path`/`prop` /// for the properties selected in the timeline, all in one undo step. fn set_expr(s: &mut Session, p: &Value) -> Result { @@ -731,7 +744,9 @@ fn set_expr(s: &mut Session, p: &Value) -> Result { let mut changed_types = vec![]; for (((cid, lid, uid), def), time) in targets.iter().zip(&defs).zip(×) { let pr = layer_mut(proj, *cid, *lid)?.props.find_mut(*uid).ok_or_else(|| bad(C, "property vanished"))?; - if pr.static_only && text.as_deref().is_some_and(|t| !t.trim().is_empty()) { + // A property that can't be animated takes no expression (one an older document has + // may still be disabled or removed). + if pr.static_only && adds_expression(pr, &text, enabled, def) { return Err(bad(C, format!("{} can't have an expression", pr.name))); } apply_expr(pr, &text, enabled, def); diff --git a/crates/engine/src/tests/aux_footage.rs b/crates/engine/src/tests/aux_footage.rs index 5149fa8e8..1205520bc 100644 --- a/crates/engine/src/tests/aux_footage.rs +++ b/crates/engine/src/tests/aux_footage.rs @@ -224,6 +224,9 @@ fn channel_selection_is_static_and_says_what_is_read() { assert!(s.execute_checked("prop.toggleKey", json!({"layer": l, "path": red})).is_err(), "no keyframe"); assert!(s.execute_checked("prop.toggleAnimation", json!({"layer": l, "path": red})).is_err(), "no stopwatch"); assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "expression": "'Z'"})).is_err(), "no expression"); + // (the forms that add the default expression: a toggle, and switching one on) + assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red})).is_err(), "no expression by toggle"); + assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "enabled": true})).is_err(), "no expression switched on"); assert!(prop(&s, red).keys.is_empty() && prop(&s, red).expr.is_none()); // The value changes; the channels read are exactly those picked. s.execute_checked("prop.set", json!({"layer": l, "path": red, "value": "Z"})).unwrap(); @@ -269,3 +272,27 @@ fn a_keyed_channel_selection_opens_static() { assert!(said, "the loss is reported"); let _ = std::fs::remove_dir_all(&dir); } + +/// #3271 review: an expression a channel selection has from an older document (set here by +/// hand) can still be switched off and removed. +#[test] +fn a_channel_selections_old_expression_can_be_removed() { + let rec = Arc::new(Recorder::default()); + let mut s = session(&rec); + let item = import(&mut s, "/renders/old-expr.exr"); + let l = add_layer(&mut s, &item); + s.execute_checked("effect.apply", json!({"effect": "EXtractoR", "layers": [l]})).unwrap(); + let cid = s.active_comp_id().unwrap(); + let red = "effects/#1/red"; + { + let p = Arc::make_mut(&mut s.project); + let pr = p.comp_mut(cid).unwrap().layer_mut(effectcraft_project::LayerId(l)).unwrap().props.prop_mut(red).unwrap(); + pr.expr = Some(effectcraft_project::Expression { text: "'Z'".into(), enabled: true }); + } + let expr = |s: &Session| s.active_comp().unwrap().layer(effectcraft_project::LayerId(l)).unwrap().props.prop(red).unwrap().expr.clone(); + s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "enabled": false})).unwrap(); + assert!(expr(&s).is_some_and(|e| !e.enabled), "switched off"); + assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "enabled": true})).is_err(), "not on again"); + s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "expression": ""})).unwrap(); + assert!(expr(&s).is_none(), "removed"); +}