🐛 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 commitf7fa0fec0eea08cc1923f644fc1c5d4012dfba7fParent: 3530c571 changed file +49 -6
- crates/engine/src/project.rs +49 -6
crates/engine/src/project.rsmodified+49 -6
| @@ -1232,8 +1232,19 @@ fn rekey_trimmed(c: &mut Clip, old: &Clip, edge: Edge, still: bool) { | |||
| 1232 | /// ([`with_cut_key`]), so the motion keeps its exact shape. Empty in, empty out. | 1232 | /// ([`with_cut_key`]), so the motion keeps its exact shape. Empty in, empty out. |
| 1233 | pub fn split_transform_keys<K: Keyed>(keys: &[K], cut: u32) -> (Vec<K>, Vec<K>) { | 1233 | pub fn split_transform_keys<K: Keyed>(keys: &[K], cut: u32) -> (Vec<K>, Vec<K>) { |
| 1234 | let list = with_cut_key(keys, cut); | 1234 | let list = with_cut_key(keys, cut); |
| 1235 | - let left: 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 right: 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 | + } | ||
| 1237 | (left, right) | 1248 | (left, right) |
| 1238 | } | 1249 | } |
| 1239 | 1250 | ||
| @@ -7885,12 +7896,16 @@ impl Project { | |||
| 7885 | let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) }; | 7896 | let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) }; |
| 7886 | tail.transform_keys = tail_keys; | 7897 | tail.transform_keys = tail_keys; |
| 7887 | data.clips[idx].transform_keys = head_keys; | 7898 | data.clips[idx].transform_keys = head_keys; |
| 7888 | - let (head_keys, tail_keys) = | 7899 | + // The opacity and grade keys are source frames cut at the same frame as |
| 7889 | - split_transform_keys(&data.clips[idx].opacity_keys, tail.in_frame); | 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) }; | ||
| 7890 | tail.opacity_keys = tail_keys; | 7905 | tail.opacity_keys = tail_keys; |
| 7891 | data.clips[idx].opacity_keys = head_keys; | 7906 | data.clips[idx].opacity_keys = head_keys; |
| 7892 | - let (head_keys, tail_keys) = | 7907 | + let (below, above) = split_transform_keys(&data.clips[idx].color_keys, cut_at); |
| 7893 | - split_transform_keys(&data.clips[idx].color_keys, tail.in_frame); | 7908 | + let (head_keys, tail_keys) = if reversed { (above, below) } else { (below, above) }; |
| 7894 | tail.color_keys = tail_keys; | 7909 | tail.color_keys = tail_keys; |
| 7895 | data.clips[idx].color_keys = head_keys; | 7910 | data.clips[idx].color_keys = head_keys; |
| 7896 | // Each mask's keys divide the same way as the placement's, per stack position. | 7911 | // Each mask's keys divide the same way as the placement's, per stack position. |
| @@ -12349,6 +12364,34 @@ mod tests { | |||
| 12349 | assert_eq!((t.start, t.in_frame, t.out_frame), (10, 0, 90)); | 12364 | assert_eq!((t.start, t.in_frame, t.out_frame), (10, 0, 90)); |
| 12350 | } | 12365 | } |
| 12351 | 12366 | ||
| 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 | + | ||
| 12352 | /// Toggling is one undo step, mirrors a key anchored to the footage so the | 12395 | /// Toggling is one undo step, mirrors a key anchored to the footage so the |
| 12353 | /// timeline behaviour does not change, and refuses a still. | 12396 | /// timeline behaviour does not change, and refuses a still. |
| 12354 | #[test] | 12397 | #[test] |