Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Ripple trim: an L cut's sound stays only when its clip ends at the cut

Peet Guercio480b9e765584
diff --git a/crates/edit/src/lib.rs b/crates/edit/src/lib.rs
index b400afb58..03ca82a9d 100644
--- a/crates/edit/src/lib.rs
+++ b/crates/edit/src/lib.rs
@@ -672,26 +672,19 @@ pub fn ripple_trim_group(seq: &mut Sequence, clips: &[ClipId], edge: Edge, delta
let later = tr.items.iter().filter(|i| !clips.contains(&i.id) && i.start >= *from);
shifting_links.extend(later.filter_map(|i| i.link).filter(|l| !own_links.contains(l)));
}
- // links that tie two or more clips together
- let mut seen: Vec<u64> = Vec::new();
- let mut paired: Vec<u64> = Vec::new();
- for l in work.all_tracks().flat_map(|tr| tr.items.iter().filter_map(|i| i.link)) {
- if seen.contains(&l) {
- paired.push(l);
- } else {
- seen.push(l);
- }
- }
+ // every linked clip: its link, and where it is and ends
+ let linked: Vec<(u64, ClipId, Tick)> = work.all_tracks().flat_map(|tr| tr.items.iter().filter_map(|i| i.link.map(|l| (l, i.id, i.end())))).collect();
for (tid, from, member) in rippling {
let Some(tr) = work.track_mut(tid) else { continue };
let follows = |i: &TrackItem| i.start < from && i.end() > from && i.link.is_some_and(|l| shifting_links.contains(&l));
- // An L cut: the sound of a clip before the cut runs on into the shortened head. Its clip stays
- // put, so the sound stays with it and the L cut still ends where it did. (Unlinked material
- // across the cut, a music bed, still refuses.)
+ // An L cut: the sound of a clip that ends at the cut runs on into the shortened head. That clip
+ // stays put, so its sound stays with it and the L cut still ends where it did. (Unlinked material
+ // across the cut, a music bed, still refuses, and so does a linked clip whose partner reaches past
+ // the cut.)
let stays = |i: &TrackItem| {
- edge == Edge::In
- && i.start < from - Tick(1)
- && i.link.is_some_and(|l| paired.contains(&l) && !shifting_links.contains(&l) && !own_links.contains(&l))
+ let cut = from - Tick(1);
+ let mut partners = linked.iter().filter(|p| Some(p.0) == i.link && p.1 != i.id).peekable();
+ edge == Edge::In && i.start < cut && i.link.is_some_and(|l| !own_links.contains(&l)) && partners.peek().is_some() && partners.all(|p| p.2 <= cut)
};
if !member && shift < Tick::ZERO {
let at = if edge == Edge::In { from - Tick(1) } else { from };
diff --git a/crates/edit/src/tests.rs b/crates/edit/src/tests.rs
index 90af2f31e..8ecf088c6 100644
--- a/crates/edit/src/tests.rs
+++ b/crates/edit/src/tests.rs
@@ -609,4 +609,18 @@ fn shorter_head_into_an_l_cut_keeps_the_earlier_sound_where_it_is() {
// so does a link with no partner left
fx.seq.track_mut(a1).unwrap().items[0].link = Some(9);
assert_eq!(ripple_trim_group(&mut fx.seq, &[b], Edge::In, f(3), &mut Fx::ctx(&mut n)), Err(EditError::SyncLockConflict));
+
+ // a linked cutaway across the cut whose own partner reaches past it too is no L cut: it refuses
+ let mut fx = Fx::new();
+ let (v1, v2, a1) = (fx.v(0), fx.v(1), fx.a(0));
+ fx.put(v1, 0, 10, 0);
+ let b = fx.put(v1, 10, 10, 0);
+ fx.put(v1, 20, 10, 0);
+ let x = fx.put(v2, 5, 20, 0);
+ let xs = fx.put(a1, 5, 20, 0);
+ for c in [x, xs] {
+ fx.seq.find_item_mut(c).unwrap().1.link = Some(7);
+ }
+ let mut n = fx.next;
+ assert_eq!(ripple_trim_group(&mut fx.seq, &[b], Edge::In, f(3), &mut Fx::ctx(&mut n)), Err(EditError::SyncLockConflict));
}