forge
Explore
Log in

Don't you dare go Hollow

🐛 A reversed clip's split cuts its opacity and grade keys where it plays them; a split never pushes a half past the key cap

Browse files at this commit

f7fa0fec0eea08cc1923f644fc1c5d4012dfba7fAhmet Kaan GümüşParent: 3530c57
crates/engine/src/project.rsmodified+49 -6
@@ -1232,8 +1232,19 @@ fn rekey_trimmed(c: &mut Clip, old: &Clip, edge: Edge, still: bool) {
12321232 /// ([`with_cut_key`]), so the motion keeps its exact shape. Empty in, empty out.
12331233 pub fn split_transform_keys<K: Keyed>(keys: &[K], cut: u32) -> (Vec<K>, Vec<K>) {
12341234 let list = with_cut_key(keys, cut);
1235- let left: Vec<K> = list.iter().copied().filter(|k| k.at() <= cut).collect();
1236- let right: Vec<K> = list.iter().copied().filter(|k| k.at() >= cut).collect();
1235+ let mut left: Vec<K> = list.iter().copied().filter(|k| k.at() <= cut).collect();
1236+ let mut right: Vec<K> = list.iter().copied().filter(|k| k.at() >= cut).collect();
1237+ // A half that holds every key already holds the cut's value there, so the key the
1238+ // cut added to it changes nothing; it is left out, which keeps a half of a full
1239+ // animation inside the key cap the file and the setters hold it to.
1240+ let added = !keys.iter().any(|k| k.at() == cut);
1241+ if added && !keys.is_empty() {
1242+ if keys.iter().all(|k| k.at() < cut) {
1243+ left.pop();
1244+ } else if keys.iter().all(|k| k.at() > cut) {
1245+ right.remove(0);
1246+ }
1247+ }
12371248 (left, right)
12381249 }
12391250
@@ -7885,12 +7896,16 @@ impl Project {
78857896 let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) };
78867897 tail.transform_keys = tail_keys;
78877898 data.clips[idx].transform_keys = head_keys;
7888- let (head_keys, tail_keys) =
7889- split_transform_keys(&data.clips[idx].opacity_keys, tail.in_frame);
7899+ // The opacity and grade keys are source frames cut at the same frame as
7900+ // the placement, so a reversed clip divides them the same way round. The
7901+ // volume envelope stays whole on both halves, so a half trimmed back out
7902+ // still has its points.
7903+ let (below, above) = split_transform_keys(&data.clips[idx].opacity_keys, cut_at);
7904+ let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) };
78907905 tail.opacity_keys = tail_keys;
78917906 data.clips[idx].opacity_keys = head_keys;
7892- let (head_keys, tail_keys) =
7893- split_transform_keys(&data.clips[idx].color_keys, tail.in_frame);
7907+ let (below, above) = split_transform_keys(&data.clips[idx].color_keys, cut_at);
7908+ let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) };
78947909 tail.color_keys = tail_keys;
78957910 data.clips[idx].color_keys = head_keys;
78967911 // Each mask's keys divide the same way as the placement's, per stack position.
@@ -12349,6 +12364,34 @@ mod tests {
1234912364 assert_eq!((t.start, t.in_frame, t.out_frame), (10, 0, 90));
1235012365 }
1235112366
12367+ /// A reversed clip's opacity keys are cut at the source frame the cut lands
12368+ /// on, not at the window's low edge, so each half shows what the unsplit clip
12369+ /// showed at its own timeline frames.
12370+ #[test]
12371+ fn a_reversed_cut_splits_opacity_keys_where_the_clip_plays_them() {
12372+ let mut p = Project::single(FILE, 100);
12373+ let v = p.add_lane(LaneKind::Video);
12374+ let mut c = clip(0, 0, 100, 0);
12375+ c.reversed = true;
12376+ assert!(p.place(v, 0, c));
12377+ assert!(p.set_opacity_keys(
12378+ v,
12379+ 0,
12380+ vec![
12381+ OpacityKey { at: 0, opacity: 0.0, ease: KeyEase::EaseIn },
12382+ OpacityKey { at: 99, opacity: 1.0, ease: KeyEase::Linear },
12383+ ],
12384+ ));
12385+ let frames = [0u32, 10, 29, 30, 45, 99];
12386+ let whole: Vec<f32> = frames.iter().map(|&f| p.opacity_at(v, 0, f)).collect();
12387+ assert!(p.split(30));
12388+ for (&f, want) in frames.iter().zip(whole) {
12389+ let idx = usize::from(f >= 30);
12390+ let got = p.opacity_at(v, idx, f);
12391+ assert!((got - want).abs() < 0.01, "frame {f}: {got} against {want}");
12392+ }
12393+ }
12394+
1235212395 /// Toggling is one undo step, mirrors a key anchored to the footage so the
1235312396 /// timeline behaviour does not change, and refuses a still.
1235412397 #[test]