forge
Explore
Log in

Don't you dare go Hollow

Close gap carries a linked take across, not one lane into silence

Browse files at this commit

7f487c10e98d32efa4e4b554b778d2eea5d16efdAhmet Kaan GümüşParent: 65f7190
  • fix
    • close gap carries a linked take across, not one lane into silence
Show full message
fix(timeline): close gap carries a linked take across, not one lane into silence

Close gap was a permanent no-op for any linked A/V take: cut_regions
refused per-lane ripples that would pull a take's picture half away
from its sound half. gap_take_scope now widens the ripple to the
take's other lane whenever the same stretch is empty there too (same
start, same length, so nothing but silence moves and sync holds), and
refuses -- in words the user can act on -- when the gap doesn't match
or the other half is solid, rather than leaving the row to click into
silence.
crates/app/src/player/timeline_edit.rsmodified+26 -10
@@ -1054,26 +1054,42 @@ impl Player {
1054 cx.notify();1054 cx.notify();
1055 }1055 }
1056 1056
1057- /// Closes the gap `(start, frames)` on `lane` alone -- Premiere's "Close1057+ /// Closes the gap `(start, frames)` -- Premiere's "Close Gap", scoped to
1058- /// Gap", scoped per-lane rather than per-track1058+ /// `lane` and, when the gap borders a take, to the take's other lane too
1059- /// ([`engine::PlaybackSession::cut_regions`]): a user after every lane's1059+ /// ([`engine::PlaybackSession::gap_take_scope`]): a lane not sharing the
1060- /// gap at once repeats the click on each, while a neighbour that meant to1060+ /// take never moves, so a neighbour that meant to keep its own silence is
1061- /// keep its own silence never moves because this lane's gap closed.1061+ /// untouched, but the two halves of a linked A/V take close together --
1062+ /// the alternative is a ripple that pulls a take's picture and sound out
1063+ /// of step with each other, which no lane's own gap is worth. A take
1064+ /// whose gap does not match on its other lane is refused in words, not
1065+ /// silence ([`engine::Project::gap_take_scope`]).
1062 pub(crate) fn close_gap(&mut self, lane: Lane, start: u32, frames: u32, cx: &mut Context<Self>) {1066 pub(crate) fn close_gap(&mut self, lane: Lane, start: u32, frames: u32, cx: &mut Context<Self>) {
1063 let Some(session) = self.session.as_mut() else {1067 let Some(session) = self.session.as_mut() else {
1064 return;1068 return;
1065 };1069 };
1066- match session.cut_regions(&[(start, frames)], &[lane]) {1070+ let scope = match session.gap_take_scope(lane, start, frames) {
1071+ Ok(scope) => scope,
1072+ Err(e) => {
1073+ self.notify_user(e.to_string().into());
1074+ cx.notify();
1075+ return;
1076+ }
1077+ };
1078+ match session.cut_regions(&[(start, frames)], &scope) {
1067 Ok(()) => {1079 Ok(()) => {
1068 self.mark_dirty();1080 self.mark_dirty();
1069- // The ripple moves every index after the gap on this lane, the1081+ // The ripple moves every index after the gap on the scoped
1070- // same reason a delete drops the selection.1082+ // lanes, the same reason a delete drops the selection.
1071 self.selected.clear();1083 self.selected.clear();
1072 self.reset_after_reseek();1084 self.reset_after_reseek();
1085+ let where_ = if scope.len() > 1 {
1086+ "its take".to_string()
1087+ } else {
1088+ lane.label().to_string()
1089+ };
1073 self.notify_user(1090 self.notify_user(
1074 format!(1091 format!(
1075- "GAP CLOSED on {} — {} takes it back",1092+ "GAP CLOSED on {where_} — {} takes it back",
1076- lane.label(),
1077 self.keymap.display(ActionId::Undo)1093 self.keymap.display(ActionId::Undo)
1078 )1094 )
1079 .into(),1095 .into(),
crates/engine/src/playback.rsmodified+8 -0
@@ -2450,6 +2450,14 @@ impl PlaybackSession {
2450 .and_then(|s| s.from)2450 .and_then(|s| s.from)
2451 }2451 }
2452 2452
2453+ /// The lanes closing the gap `(start, frames)` on `lane` must ripple
2454+ /// together to keep every take crossing it in sync
2455+ /// ([`Project::gap_take_scope`]) -- what a right-click on empty bench
2456+ /// space asks before offering to close it.
2457+ pub fn gap_take_scope(&self, lane: Lane, start: u32, frames: u32) -> crate::Result<Vec<Lane>> {
2458+ self.project.gap_take_scope(lane, start, frames)
2459+ }
2460+
2453 /// Cuts every one of `regions` -- `(start, len)` in timeline frames -- out2461 /// Cuts every one of `regions` -- `(start, len)` in timeline frames -- out
2454 /// of the lanes in `scope` and closes each hole, as **one** edit2462 /// of the lanes in `scope` and closes each hole, as **one** edit
2455 /// ([`Project::cut_regions`]): the jumpcut a silence scan2463 /// ([`Project::cut_regions`]): the jumpcut a silence scan
crates/engine/src/project.rsmodified+167 -0
@@ -4189,6 +4189,74 @@ impl Project {
4189 gap(self.lane(lane), frame)4189 gap(self.lane(lane), frame)
4190 }4190 }
4191 4191
4192+ /// The lanes closing the gap `(start, frames)` on `lane` must ripple
4193+ /// together to keep sync -- what a right-click on empty bench space asks
4194+ /// before the menu offers to close it, and what widens
4195+ /// [`cut_regions`](Project::cut_regions)'s scope from the one lane a hand
4196+ /// named to the whole take the gap might be half of.
4197+ ///
4198+ /// A clip bordering the gap on `lane` -- the one ending where it starts,
4199+ /// the one starting where it ends -- carries a link when it is one take
4200+ /// with a clip on another lane. That lane joins the scope only when the
4201+ /// *exact same* stretch is empty there too (same start, same length): the
4202+ /// ripple then removes nothing but silence, on every lane it touches, and
4203+ /// both halves stay the length they always were. A link whose partner
4204+ /// lane is not empty there -- a gap of a different length, or none at all
4205+ /// -- is named back to the caller rather than silently widened past
4206+ /// (which would cut real media out of a lane nothing asked to touch) or
4207+ /// silently left out (which is the defect this closes: a per-lane ripple
4208+ /// would leave [`scope_holds_takes_whole`](Project::scope_holds_takes_whole)
4209+ /// to refuse it after the fact, on the very half this could have carried
4210+ /// along).
4211+ ///
4212+ /// `Ok(vec![lane])` alone for a gap that borders no take, or none whose
4213+ /// partner clip sits on another lane -- the unlinked case, untouched.
4214+ pub fn gap_take_scope(&self, lane: Lane, start: u32, frames: u32) -> crate::Result<Vec<Lane>> {
4215+ let Some(li) = self.index(lane) else {
4216+ return Err("no track to work on".into());
4217+ };
4218+ let labels = handles(&self.lanes);
4219+ let end = start + frames;
4220+ let mut scope = vec![lane];
4221+ for c in self.lanes[li]
4222+ .clips
4223+ .iter()
4224+ .filter(|c| c.end() == start || c.start == end)
4225+ {
4226+ let Some(id) = c.link else { continue };
4227+ for (j, data) in self.lanes.iter().enumerate() {
4228+ if j == li {
4229+ continue;
4230+ }
4231+ let Some(half) = data.clips.iter().find(|o| o.link == Some(id)) else {
4232+ continue;
4233+ };
4234+ match gap(&data.clips, start) {
4235+ Some((s, f)) if s == start && f == frames => {
4236+ let other = labels[j];
4237+ if !scope.contains(&other) {
4238+ scope.push(other);
4239+ }
4240+ }
4241+ _ => {
4242+ return Err(format!(
4243+ "the {} clip at frame {} is one take with the {} clip at frame {}: \
4244+ closing this gap alone would pull the take out of sync -- close {}'s \
4245+ gap there too, or detach them first",
4246+ labels[li].label(),
4247+ c.start,
4248+ labels[j].label(),
4249+ half.start,
4250+ labels[j].label()
4251+ )
4252+ .into());
4253+ }
4254+ }
4255+ }
4256+ }
4257+ Ok(scope)
4258+ }
4259+
4192 /// Cut **every** one of `regions` -- `(start, len)` in timeline frames --4260 /// Cut **every** one of `regions` -- `(start, len)` in timeline frames --
4193 /// out of the lanes in `scope` and close each hole, as one edit: the4261 /// out of the lanes in `scope` and close each hole, as one edit: the
4194 /// jumpcut a silence scan asks for ([`crate::silence`]).4262 /// jumpcut a silence scan asks for ([`crate::silence`]).
@@ -7606,6 +7674,105 @@ mod tests {
7606 assert_eq!(shape(&p), before, "back to exactly where it was");7674 assert_eq!(shape(&p), before, "back to exactly where it was");
7607 }7675 }
7608 7676
7677+ /// A clip carrying an explicit link id -- what a
7678+ /// [`from_parts`](Project::from_parts) fixture below needs to build a take
7679+ /// by hand, the same shape `a_link_id_is_never_two_clips_of_one_lane`
7680+ /// already builds inline.
7681+ fn linked(start: u32, in_frame: u32, out_frame: u32, link: u32) -> Clip {
7682+ Clip {
7683+ fade_in: 0,
7684+ fade_out: 0,
7685+ transition_out: 0,
7686+ start,
7687+ in_frame,
7688+ out_frame,
7689+ source: 0,
7690+ link: Some(link),
7691+ eq: None,
7692+ color: None,
7693+ transform: None,
7694+ fit: FitPolicy::default(),
7695+ speed: Speed::NORMAL,
7696+ }
7697+ }
7698+
7699+ /// The ordinary case the defect made a permanent no-op: a gap on `V1`
7700+ /// bordered by a linked take whose `A1` half is empty across the very
7701+ /// same stretch widens the scope to both lanes, so the ripple carries the
7702+ /// take rather than tearing it -- and one undo puts both halves back.
7703+ #[test]
7704+ fn closing_a_gap_carries_a_linked_take_when_the_gap_matches_on_both_lanes() {
7705+ let sources = vec![Source::new(FILE, 0)];
7706+ let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];
7707+ let audio = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];
7708+ let mut p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())
7709+ .expect("valid parts");
7710+ let before = shape(&p);
7711+ assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));
7712+ assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 2)), "the same stretch is empty on A1 too");
7713+
7714+ let scope = p
7715+ .gap_take_scope(Lane::V1, 3, 2)
7716+ .expect("a matching gap on both halves widens the scope");
7717+ assert_eq!(scope.len(), 2, "the take's other lane joins");
7718+ assert!(scope.contains(&Lane::V1) && scope.contains(&Lane::A1));
7719+
7720+ assert!(p.cut_regions(&[(3, 2)], &scope).is_ok());
7721+ assert_eq!(p.lane(Lane::V1)[1].start, 3, "V1's far half slid back");
7722+ assert_eq!(p.lane(Lane::A1)[1].start, 3, "A1's far half rode along, in sync");
7723+ assert!(p.undo(), "one press undoes the whole close");
7724+ assert_eq!(shape(&p), before, "back to exactly where it was");
7725+ }
7726+
7727+ /// The real design question: a take whose gap is not the *same size* on
7728+ /// both lanes cannot ripple by one number without pulling a lane's clip
7729+ /// out from under the other's sync -- refused by name, with the frame
7730+ /// naming which lane is out of step, rather than silently taking real
7731+ /// media off the shorter side.
7732+ #[test]
7733+ fn closing_a_gap_refuses_a_take_whose_gap_lengths_differ() {
7734+ let sources = vec![Source::new(FILE, 0)];
7735+ let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];
7736+ // A1's second half starts at 4, not 5: its gap is [3,4), one frame
7737+ // shorter than V1's [3,5) -- a legal offset-preserving group, and
7738+ // still one take.
7739+ let audio = vec![linked(0, 0, 3, 1), linked(4, 5, 9, 3)];
7740+ let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())
7741+ .expect("valid parts");
7742+ assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));
7743+ assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 1)), "a shorter gap on A1");
7744+
7745+ let err = p
7746+ .gap_take_scope(Lane::V1, 3, 2)
7747+ .expect_err("a mismatched gap cannot ripple by one number")
7748+ .to_string();
7749+ assert!(err.contains("A1"), "{err}");
7750+ assert!(err.contains("out of sync"), "{err}");
7751+ }
7752+
7753+ /// A gap on `V1` whose `A1` half is not a gap at all -- real audio plays
7754+ /// there -- cannot close without cutting that audio out from under
7755+ /// nothing asked to touch it: refused, not widened silently past.
7756+ #[test]
7757+ fn closing_a_gap_refuses_a_take_whose_other_half_is_solid() {
7758+ let sources = vec![Source::new(FILE, 0)];
7759+ let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];
7760+ // A1 plays through the whole span as one continuous clip, sharing
7761+ // V1's first-half link: nothing empty at frame 3 there at all.
7762+ let audio = vec![linked(0, 0, 9, 1)];
7763+ let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())
7764+ .expect("valid parts");
7765+ assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));
7766+ assert_eq!(p.gap_at(Lane::A1, 3), None, "A1 plays through, no gap there");
7767+
7768+ let err = p
7769+ .gap_take_scope(Lane::V1, 3, 2)
7770+ .expect_err("a solid partner cannot ripple with the gap")
7771+ .to_string();
7772+ assert!(err.contains("A1"), "{err}");
7773+ assert!(err.contains("detach"), "{err}");
7774+ }
7775+
7609 #[test]7776 #[test]
7610 fn ripple_delete_spans_partial_clips() {7777 fn ripple_delete_spans_partial_clips() {
7611 let mut p = three();7778 let mut p = three();