From f7fa0fec0eea08cc1923f644fc1c5d4012dfba7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 6 Nov 2026 18:19:01 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20A=20reversed=20clip's=20split=20?= =?UTF-8?q?cuts=20its=20opacity=20and=20grade=20keys=20where=20it=20plays?= =?UTF-8?q?=20them;=20a=20split=20never=20pushes=20a=20half=20past=20the?= =?UTF-8?q?=20key=20cap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/engine/src/project.rs | 55 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 9173dd2..d2a7fab 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1232,8 +1232,19 @@ fn rekey_trimmed(c: &mut Clip, old: &Clip, edge: Edge, still: bool) { /// ([`with_cut_key`]), so the motion keeps its exact shape. Empty in, empty out. pub fn split_transform_keys(keys: &[K], cut: u32) -> (Vec, Vec) { let list = with_cut_key(keys, cut); - let left: Vec = list.iter().copied().filter(|k| k.at() <= cut).collect(); - let right: Vec = list.iter().copied().filter(|k| k.at() >= cut).collect(); + let mut left: Vec = list.iter().copied().filter(|k| k.at() <= cut).collect(); + let mut right: Vec = list.iter().copied().filter(|k| k.at() >= cut).collect(); + // A half that holds every key already holds the cut's value there, so the key the + // cut added to it changes nothing; it is left out, which keeps a half of a full + // animation inside the key cap the file and the setters hold it to. + let added = !keys.iter().any(|k| k.at() == cut); + if added && !keys.is_empty() { + if keys.iter().all(|k| k.at() < cut) { + left.pop(); + } else if keys.iter().all(|k| k.at() > cut) { + right.remove(0); + } + } (left, right) } @@ -7885,12 +7896,16 @@ impl Project { let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) }; tail.transform_keys = tail_keys; data.clips[idx].transform_keys = head_keys; - let (head_keys, tail_keys) = - split_transform_keys(&data.clips[idx].opacity_keys, tail.in_frame); + // The opacity and grade keys are source frames cut at the same frame as + // the placement, so a reversed clip divides them the same way round. The + // volume envelope stays whole on both halves, so a half trimmed back out + // still has its points. + let (below, above) = split_transform_keys(&data.clips[idx].opacity_keys, cut_at); + let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) }; tail.opacity_keys = tail_keys; data.clips[idx].opacity_keys = head_keys; - let (head_keys, tail_keys) = - split_transform_keys(&data.clips[idx].color_keys, tail.in_frame); + let (below, above) = split_transform_keys(&data.clips[idx].color_keys, cut_at); + let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) }; tail.color_keys = tail_keys; data.clips[idx].color_keys = head_keys; // Each mask's keys divide the same way as the placement's, per stack position. @@ -12349,6 +12364,34 @@ mod tests { assert_eq!((t.start, t.in_frame, t.out_frame), (10, 0, 90)); } + /// A reversed clip's opacity keys are cut at the source frame the cut lands + /// on, not at the window's low edge, so each half shows what the unsplit clip + /// showed at its own timeline frames. + #[test] + fn a_reversed_cut_splits_opacity_keys_where_the_clip_plays_them() { + let mut p = Project::single(FILE, 100); + let v = p.add_lane(LaneKind::Video); + let mut c = clip(0, 0, 100, 0); + c.reversed = true; + assert!(p.place(v, 0, c)); + assert!(p.set_opacity_keys( + v, + 0, + vec![ + OpacityKey { at: 0, opacity: 0.0, ease: KeyEase::EaseIn }, + OpacityKey { at: 99, opacity: 1.0, ease: KeyEase::Linear }, + ], + )); + let frames = [0u32, 10, 29, 30, 45, 99]; + let whole: Vec = frames.iter().map(|&f| p.opacity_at(v, 0, f)).collect(); + assert!(p.split(30)); + for (&f, want) in frames.iter().zip(whole) { + let idx = usize::from(f >= 30); + let got = p.opacity_at(v, idx, f); + assert!((got - want).abs() < 0.01, "frame {f}: {got} against {want}"); + } + } + /// Toggling is one undo step, mirrors a key anchored to the footage so the /// timeline behaviour does not change, and refuses a still. #[test]