forge
Explore
Log in

Don't you dare go Hollow

An arriving clip never touches the captions

Browse files at this commit

a3dc07cdf1d57ae63034f5b93cfadb0a5501fe74Ahmet Kaan GümüşParent: 71b7468
  • fix
    • an arriving clip never touches the captions
Show full message
🐛 fix(timeline): an arriving clip never touches the captions

The rippling paste -- the door a video arriving on the timeline goes
through, and the clipboard's own -- opened room on the subtitle lanes
too, splitting a caption the landing fell inside and sliding the rest
behind the new clips. On a timeline of words alone, adding a video cut
the caption in half and pushed its tail to the video's end, which no
hand asked for.

A paste inserts media; the words keep their own clock. A caption that
should travel with a clip is what a group is for, and a group moves as
one. The razor still cuts captions with the picture, and a cut region
still removes the words over it -- those are cuts, and this was an
add.
crates/engine/src/project.rsmodified+66 -13
@@ -3568,9 +3568,11 @@ impl Project {
3568 /// source with no picture ([`crate::is_audio`]) reaches `A1` only -- on a3568 /// source with no picture ([`crate::is_audio`]) reaches `A1` only -- on a
3569 /// video lane it is a clip that decodes to nothing, and a save carrying one3569 /// video lane it is a clip that decodes to nothing, and a save carrying one
3570 /// does not open again -- and a still image ([`crate::is_image`]) reaches3570 /// does not open again -- and a still image ([`crate::is_image`]) reaches
3571- /// `V1` only, for the mirror of that reason. The room is still opened3571+ /// `V1` only, for the mirror of that reason. The room is still opened on
3572- /// everywhere, or the lanes it was not inserted into would slide out of step3572+ /// every media lane, or the lanes it was not inserted into would slide out
3573- /// with the ones it was.3573+ /// of step with the ones it was -- and the subtitle lanes are left alone:
3574+ /// the words keep their own clock, and a caption that should travel with a
3575+ /// clip is what a group is for.
3574 ///3576 ///
3575 /// Exactly one history snapshot, so one [`Project::undo`] takes it back.3577 /// Exactly one history snapshot, so one [`Project::undo`] takes it back.
3576 /// Changes the timeline->source mapping: the caller must reseek. Refused for3578 /// Changes the timeline->source mapping: the caller must reseek. Refused for
@@ -3611,11 +3613,6 @@ impl Project {
3611 .iter()3613 .iter()
3612 .flat_map(|l| &l.clips)3614 .flat_map(|l| &l.clips)
3613 .any(|c| c.end() > at && c.end().checked_add(len).is_none())3615 .any(|c| c.end() > at && c.end().checked_add(len).is_none())
3614- || self
3615- .lanes
3616- .iter()
3617- .flat_map(|l| &l.subs)
3618- .any(|s| s.end() > at && s.end().checked_add(len).is_none())
3619 {3616 {
3620 return false;3617 return false;
3621 }3618 }
@@ -3653,16 +3650,21 @@ impl Project {
3653 .collect();3650 .collect();
3654 for (i, data) in self.lanes.iter_mut().enumerate() {3651 for (i, data) in self.lanes.iter_mut().enumerate() {
3655 open_room(&mut data.clips, at, len);3652 open_room(&mut data.clips, at, len);
3656- // The room is opened on the subtitle lanes too, and for the reason3653+ // The subtitle lanes are NOT touched: a paste inserts media, and
3657- // it is opened on the lanes the paste does not land on: a caption3654+ // the words keep their own clock. Opening room here used to split
3658- // that stayed put while the picture under it moved on is two things3655+ // a caption the paste landed inside and slide the rest behind it
3659- // that no longer say the same thing.3656+ // -- "a caption that stayed put while the picture moved on no
3660- sub_open_room(&mut data.subs, at, len);3657+ // longer says the same thing" -- but a caption pinned to nothing
3658+ // (and a video arriving on a timeline of words alone) has no
3659+ // picture to follow, and the split did to the words what no hand
3660+ // asked for. A caption that should travel with a clip is what a
3661+ // group is for, and a group moves as one.
3661 if takes.contains(&i) {3662 if takes.contains(&i) {
3662 let idx = data.clips.partition_point(|c| c.start < at);3663 let idx = data.clips.partition_point(|c| c.start < at);
3663 data.clips.insert(idx, clip);3664 data.clips.insert(idx, clip);
3664 }3665 }
3665 debug_assert!(sorted_disjoint(&data.clips));3666 debug_assert!(sorted_disjoint(&data.clips));
3667+ debug_assert!(subs_sorted_disjoint(&data.subs));
3666 }3668 }
3667 true3669 true
3668 }3670 }
@@ -5179,6 +5181,57 @@ mod tests {
5179 );5181 );
5180 }5182 }
5181 5183
5184+ /// A video arriving on a timeline of words mutates none of them: the
5185+ /// import's rippling insert used to open room on the subtitle lanes too,
5186+ /// splitting a caption it landed inside and sliding the rest behind the
5187+ /// video -- the hand asked for an add, and got a cut it never made. The
5188+ /// words keep their own clock; co-travel is what a group is for.
5189+ #[test]
5190+ fn an_arriving_clip_never_touches_the_captions() {
5191+ let caption = |start: u32, frames: u32| SubClip {
5192+ start,
5193+ frames,
5194+ track: 0,
5195+ in_us: i64::from(start) * 1_000_000 / 30,
5196+ out_us: i64::from(start + frames) * 1_000_000 / 30,
5197+ link: None,
5198+ };
5199+ let track = || SubtitleTrack {
5200+ path: FILE.into(),
5201+ track: None,
5202+ language: "eng".into(),
5203+ name: String::new(),
5204+ label: "eng".into(),
5205+ cues: Vec::new(),
5206+ bitmap: false,
5207+ refused: None,
5208+ };
5209+ // A timeline of words alone: 60 frames of caption, no media clips.
5210+ let mut p = Project::single(FILE, 60)
5211+ .with_subtitles(vec![track()]);
5212+ for l in [Lane::V1, Lane::A1] {
5213+ while !p.lane(l).is_empty() {
5214+ p.lift(l, 0);
5215+ }
5216+ }
5217+ let s1 = p.add_lane(LaneKind::Subtitle);
5218+ p.place_sub(s1, 0, caption(0, 60)).expect("placed");
5219+ let before = p.sub_lane(s1).to_vec();
5220+
5221+ // The video lands BEFORE the caption's span: nothing moves.
5222+ let vid = clip(0, 0, 30, 0);
5223+ assert!(p.paste(0, vid), "the video goes down at the head");
5224+ assert_eq!(p.sub_lane(s1), &before[..], "the caption keeps its clock");
5225+
5226+ // ...and OVERLAPPING it, dead centre: no split, no shift, byte for
5227+ // byte the placement the hand made.
5228+ assert!(p.paste(15, vid), "a second video lands inside the caption");
5229+ assert_eq!(p.sub_lane(s1), &before[..], "still one caption, unmoved");
5230+ assert_eq!(p.sub_lane(s1).len(), 1, "and uncut");
5231+ assert_eq!(p.lane(Lane::V1).len(), 3, "the videos landed");
5232+ assert!(links_are_consistent(&p.lanes).is_ok());
5233+ }
5234+
5182 /// The region's caption pieces re-time by mapped boundaries forced apart:5235 /// The region's caption pieces re-time by mapped boundaries forced apart:
5183 /// rounding start and length independently can land two cues on one frame,5236 /// rounding start and length independently can land two cues on one frame,
5184 /// and the artifact is clamped -- one frame each, in order, none past the5237 /// and the artifact is clamped -- one frame each, in order, none past the