diff --git a/crates/engine/src/analysis/frames_key/legacy.rs b/crates/engine/src/analysis/frames_key/legacy.rs index 882c82d80..4b1b090a5 100644 --- a/crates/engine/src/analysis/frames_key/legacy.rs +++ b/crates/engine/src/analysis/frames_key/legacy.rs @@ -2,7 +2,7 @@ //! keyed with them. They hash derived `Debug` text, so `tests::analysis_signature` pins keys //! those releases saved: if a type change alters this text, write that part out here. -use effectcraft_project::{Footage, ItemId, ItemKind, Layer, LayerSource, Project, Uid}; +use effectcraft_project::{Footage, GroupKind, ItemId, ItemKind, Layer, LayerSource, ParamUi, Project, PropGroup, Uid}; use super::fnv; @@ -41,12 +41,39 @@ pub(crate) fn input_key_of(mut s: String, layer: &Layer, uid: Uid) -> String { if g.uid == uid { break; } - s.push_str(&format!("{g:?}")); + s.push_str(&effect_text(g)); } } format!("{:016x}", fnv(&s)) } +/// The slider ranges 0.22–0.24 gave effect parameters whose range has changed since, as +/// (effect, parameter path, [min, max, slider min, slider max], decimals). Those releases hashed +/// each effect's UI hints into the Roto Brush Input Key, and opening a project replaces an +/// instance's hints with the current ones, so [`effect_text`] puts these back. A range change +/// above a Roto Brush would otherwise drop the analysis such a key kept: add a row with it. +#[rustfmt::skip] +const SLIDERS_0_24: &[(&str, &str, [f64; 4], u8)] = &[ + ("ec.blur.gaussian", "blurriness", [0.0, 3000.0, 0.0, 50.0], 1), +]; + +/// An effect instance as 0.22–0.24 wrote it into a Roto Brush Input Key: its derived `Debug`, +/// with the [`SLIDERS_0_24`] ranges in place of today's. +pub(crate) fn effect_text(g: &PropGroup) -> String { + let GroupKind::Effect { effect } = &g.kind else { return format!("{g:?}") }; + let mut rows = SLIDERS_0_24.iter().filter(|r| r.0 == effect).peekable(); + if rows.peek().is_none() { + return format!("{g:?}"); + } + let mut g = g.clone(); + for &(_, path, [min, max, slider_min, slider_max], decimals) in rows { + if let Some(p) = g.prop_mut(path).filter(|p| matches!(p.ui, ParamUi::Slider { .. })) { + p.ui = ParamUi::Slider { min, max, slider_min, slider_max, decimals }; + } + } + format!("{g:?}") +} + /// A footage item as 0.23–0.24 wrote it into a signature (without `placed_page` before 0.23), /// with `missing` in place of the item's. pub(crate) fn footage_text(f: &Footage, missing: bool, placed_page: bool) -> String { diff --git a/crates/engine/src/tests/analysis_signature.rs b/crates/engine/src/tests/analysis_signature.rs index 045e279de..a4ab86264 100644 --- a/crates/engine/src/tests/analysis_signature.rs +++ b/crates/engine/src/tests/analysis_signature.rs @@ -5,7 +5,7 @@ use effectcraft_effects::camera_tracker::{TRACKS, TRACKS_KEY}; use effectcraft_effects::roto::{FROZEN, INPUT_KEY}; use effectcraft_effects::warp_stab::{ANALYSIS, ANALYSIS_KEY}; use effectcraft_keyframe::Value; -use effectcraft_project::{ItemId, LayerId, Project}; +use effectcraft_project::{GroupKind, ItemId, LayerId, ParamUi, Project}; use serde_json::json; use crate::Session; @@ -93,6 +93,19 @@ fn analyses_saved_by_0_24_survive_edits_that_keep_their_frames() { assert_eq!(saved(&s), before); } +/// 0.24 hashed each effect's UI hints into the Roto Brush's key, and opening a project takes the +/// current ones: the legacy text puts back Gaussian Blur's 0.24 Blurriness range (#3460). +#[test] +fn legacy_roto_keys_hash_the_0_24_blurriness_range() { + let s = open(ANALYSED_0_24); + let layer = s.project.comp(COMP).unwrap().layer(CLIP).unwrap(); + let is_blur = |kind: &GroupKind| matches!(kind, GroupKind::Effect { effect } if effect == "ec.blur.gaussian"); + let blur = layer.effects().and_then(|fx| fx.groups().find(|g| is_blur(&g.kind))).expect("the fixture has a Gaussian Blur above the Roto Brush"); + let mut as_0_24 = blur.clone(); + as_0_24.get_mut("blurriness").unwrap().ui = ParamUi::Slider { min: 0.0, max: 3000.0, slider_min: 0.0, slider_max: 50.0, decimals: 1 }; + assert_eq!(crate::analysis::frames_key::legacy::effect_text(blur), format!("{as_0_24:?}")); +} + /// The text keys are made from today, written field by field (#3536). It changes only when this /// test is changed with it: a new field of a type it writes doesn't compile until it is decided /// in `analysis::frames_key`, and renaming a field or variant doesn't change it.