forge
Explore
Log in

Don't you dare go Hollow

78ecdec0f3bc81585c4012e108176dc809caeeb6Ahmet Kaan GümüşParent: ff3520ea650264
crates/app/src/ui/bench_stance.rsmodified+3 -0
@@ -764,6 +764,9 @@ fn lane_row(
764764 }),
765765 )
766766 .drag_over::<SubPick>(|d, _, _, _| d.bg(rgb(DARK_RAISED())))
767+ .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| {
768+ this.place_sub(drag.0, lane, window.mouse_position().x, cx);
769+ }))
767770 .on_drag_move(
768771 cx.listener(move |this, event: &DragMoveEvent<SubPick>, _, cx| {
769772 if !event.bounds.contains(&event.event.position) {
crates/engine/src/playback.rsmodified+10 -8
@@ -2031,14 +2031,15 @@ impl PlaybackSession {
20312031 }
20322032
20332033 /// The empty stretch of `lane` covering `frame`, or `None` when `frame`
2034- /// is inside a clip or past the last one ([`Project::gap_at`]). What a
2035- /// right-click on empty bench space asks before offering to close it.
2034+ /// is inside a clip/caption placement or past the last one
2035+ /// ([`Project::gap_at`]). What a right-click on empty bench space asks
2036+ /// before offering to close it.
20362037 pub fn gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> {
20372038 self.project.gap_at(lane, frame)
20382039 }
20392040
20402041 /// How many bounded gaps that same right-click lane holds. The tail after
2041- /// the last clip is not counted, because nothing would ripple there.
2042+ /// the last placement is not counted, because nothing would ripple there.
20422043 pub fn gap_count(&self, lane: Lane) -> usize {
20432044 self.project.gap_count(lane)
20442045 }
@@ -2459,16 +2460,17 @@ impl PlaybackSession {
24592460 }
24602461
24612462 /// The lanes closing the gap `(start, frames)` on `lane` must ripple
2462- /// together to keep every take crossing it in sync
2463+ /// together to keep every media take crossing it in sync
24632464 /// ([`Project::gap_take_scope`]) -- what a right-click on empty bench
2464- /// space asks before offering to close it.
2465+ /// space asks before offering to close it. Subtitle gaps stay on their own
2466+ /// lane because captions are not A/V take halves.
24652467 pub fn gap_take_scope(&self, lane: Lane, start: u32, frames: u32) -> crate::Result<Vec<Lane>> {
24662468 self.project.gap_take_scope(lane, start, frames)
24672469 }
24682470
2469- /// Closes every bounded gap on one lane, keeping each linked take whole when
2470- /// its other half has the matching empty stretch and reporting the gaps that
2471- /// were not safe to close. One undo step for every gap that closed.
2471+ /// Closes every bounded gap on one lane. Media lanes keep linked takes
2472+ /// whole when the other half has the matching empty stretch and report the
2473+ /// gaps that were not safe to close; subtitle lanes ripple captions only.
24722474 pub fn close_all_gaps_on_lane(&mut self, lane: Lane) -> crate::Result<GapSweep> {
24732475 let report = self.project.close_all_gaps_on_lane(lane)?;
24742476 if report.closed > 0 {
crates/engine/src/project.rsmodified+221 -33
@@ -4198,18 +4198,29 @@ impl Project {
41984198
41994199 /// The empty stretch of `lane` covering `frame`, as `(start, len)` -- what
42004200 /// a right-click on empty bench space names before offering to close it.
4201- /// `None` when `frame` sits inside a clip, or past the last one: the open
4202- /// end of a lane is not a gap, since there is nothing after it to slide
4203- /// back ([`gap`]).
4201+ /// `None` when `frame` sits inside a placement, or past the last one: the
4202+ /// open end of a lane is not a gap, since there is nothing after it to slide
4203+ /// back ([`gap`]). Subtitle lanes are asked of their [`SubClip`] list, not
4204+ /// the media [`Clip`] list they deliberately never hold.
42044205 pub fn gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> {
4205- gap(self.lane(lane), frame)
4206+ let data = self.index(lane).map(|i| &self.lanes[i])?;
4207+ match data.kind {
4208+ LaneKind::Subtitle => gap(&data.subs, frame),
4209+ LaneKind::Video | LaneKind::Audio => gap(&data.clips, frame),
4210+ }
42064211 }
42074212
4208- /// How many bounded holes `lane` holds. The open end after the last clip is
4209- /// not counted, like [`gap_at`](Self::gap_at), because closing it would move
4210- /// nothing.
4213+ /// How many bounded holes `lane` holds. The open end after the last
4214+ /// placement is not counted, like [`gap_at`](Self::gap_at), because closing
4215+ /// it would move nothing.
42114216 pub fn gap_count(&self, lane: Lane) -> usize {
4212- gaps(self.lane(lane)).len()
4217+ let Some(data) = self.index(lane).map(|i| &self.lanes[i]) else {
4218+ return 0;
4219+ };
4220+ match data.kind {
4221+ LaneKind::Subtitle => gaps(&data.subs).len(),
4222+ LaneKind::Video | LaneKind::Audio => gaps(&data.clips).len(),
4223+ }
42134224 }
42144225
42154226 /// The lanes closing the gap `(start, frames)` on `lane` must ripple
@@ -4234,6 +4245,11 @@ impl Project {
42344245 ///
42354246 /// `Ok(vec![lane])` alone for a gap that borders no take, or none whose
42364247 /// partner clip sits on another lane -- the unlinked case, untouched.
4248+ ///
4249+ /// Subtitle lanes have no media take halves to inspect. A caption can be
4250+ /// hand-grouped with clips, but it is not the imported A/V take this method
4251+ /// widens for, so a subtitle gap stays scoped to its own lane; the later
4252+ /// scoped cut still refuses an explicit group split.
42374253 pub fn gap_take_scope(&self, lane: Lane, start: u32, frames: u32) -> crate::Result<Vec<Lane>> {
42384254 let Some(li) = self.index(lane) else {
42394255 return Err("no track to work on".into());
@@ -4281,10 +4297,13 @@ impl Project {
42814297 }
42824298
42834299 /// Close every bounded gap on `lane`, as one undo step, without making the
4284- /// lane's scope global. Each gap uses the same take-safety widening
4300+ /// lane's scope global. Media lanes use the same take-safety widening
42854301 /// [`gap_take_scope`](Self::gap_take_scope) gives a single close: linked
42864302 /// halves ride along only when their matching lane is empty over that exact
4287- /// stretch; mismatches are skipped and reported.
4303+ /// stretch; mismatches are skipped and reported. Subtitle lanes close their
4304+ /// own [`SubClip`] list only: captions may be hand-grouped, but they are not
4305+ /// halves of an imported A/V take, so the media take-widening rule has
4306+ /// nothing to add there.
42884307 ///
42894308 /// The walk is back-to-front. Closing a gap shifts everything after it, so
42904309 /// later holes must be consumed while their measured starts are still true;
@@ -4292,9 +4311,12 @@ impl Project {
42924311 /// only before the first successful close, so an all-skipped sweep is not an
42934312 /// undo step.
42944313 pub fn close_all_gaps_on_lane(&mut self, lane: Lane) -> crate::Result<GapSweep> {
4295- let Some(_) = self.index(lane) else {
4314+ let Some(i) = self.index(lane) else {
42964315 return Err("no track to work on".into());
42974316 };
4317+ if self.lanes[i].kind == LaneKind::Subtitle {
4318+ return Ok(self.close_all_subtitle_gaps_on_lane(i));
4319+ }
42984320 let mut report = GapSweep::default();
42994321 let mut snapshot = false;
43004322 for (start, frames) in gaps(self.lane(lane)).into_iter().rev() {
@@ -4324,6 +4346,35 @@ impl Project {
43244346 Ok(report)
43254347 }
43264348
4349+ /// Subtitle lanes have the same bounded-gap sweep as media lanes, but no
4350+ /// take-scope widening: a caption is not one half of an A/V take. Explicit
4351+ /// hand groups still obey [`scope_holds_takes_whole`](Self::scope_holds_takes_whole),
4352+ /// so a grouped caption is refused rather than pulled away from its group.
4353+ fn close_all_subtitle_gaps_on_lane(&mut self, i: usize) -> GapSweep {
4354+ let mut report = GapSweep::default();
4355+ let mut snapshot = false;
4356+ let on = [i];
4357+ for (start, frames) in gaps(&self.lanes[i].subs).into_iter().rev() {
4358+ match self.scope_holds_takes_whole(&on, start) {
4359+ Ok(()) => {
4360+ if !snapshot {
4361+ self.snapshot();
4362+ snapshot = true;
4363+ }
4364+ ripple(&mut self.lanes, &on, start, frames);
4365+ report.closed += 1;
4366+ }
4367+ Err(e) => report.skipped.push(GapSkip {
4368+ start,
4369+ reason: e.to_string(),
4370+ }),
4371+ }
4372+ }
4373+ report.skipped.reverse();
4374+ debug_assert!(links_are_consistent(&self.lanes).is_ok());
4375+ report
4376+ }
4377+
43274378 /// Cut **every** one of `regions` -- `(start, len)` in timeline frames --
43284379 /// out of the lanes in `scope` and close each hole, as one edit: the
43294380 /// jumpcut a silence scan asks for ([`crate::silence`]).
@@ -5036,38 +5087,67 @@ fn source_frame(c: &Clip, timeline_frame: u32) -> u32 {
50365087 (c.in_frame + c.speed.source_at(timeline_frame - c.start)).min(c.out_frame - 1)
50375088 }
50385089
5039-/// Index of the clip covering `frame`, or `None` for a gap or past the end.
5040-/// Binary search: the sorted-disjoint invariant is what makes it legal.
5041-fn at(clips: &[Clip], frame: u32) -> Option<usize> {
5042- let idx = clips.partition_point(|c| c.start <= frame).checked_sub(1)?;
5043- (frame < clips[idx].end()).then_some(idx)
5090+/// The tiny interface `Clip` and `SubClip` share for gap maths. Keeping the gap
5091+/// finder generic makes the subtitle path use the same bounded-hole rules as
5092+/// media lanes without teaching the media-specific take logic about captions.
5093+trait GapPlacement {
5094+ fn start_frame(&self) -> u32;
5095+ fn end_frame(&self) -> u32;
5096+}
5097+
5098+impl GapPlacement for Clip {
5099+ fn start_frame(&self) -> u32 {
5100+ self.start
5101+ }
5102+
5103+ fn end_frame(&self) -> u32 {
5104+ self.end()
5105+ }
5106+}
5107+
5108+impl GapPlacement for SubClip {
5109+ fn start_frame(&self) -> u32 {
5110+ self.start
5111+ }
5112+
5113+ fn end_frame(&self) -> u32 {
5114+ self.end()
5115+ }
5116+}
5117+
5118+/// Index of the placement covering `frame`, or `None` for a gap or past the
5119+/// end. Binary search: the sorted-disjoint invariant is what makes it legal.
5120+fn at<T: GapPlacement>(items: &[T], frame: u32) -> Option<usize> {
5121+ let idx = items.partition_point(|item| item.start_frame() <= frame).checked_sub(1)?;
5122+ (frame < items[idx].end_frame()).then_some(idx)
50445123 }
50455124
5046-/// The empty stretch of `clips` covering `frame`, as `(start, len)` -- `None`
5047-/// when `frame` is inside a clip, or past the last one. Sorted-disjoint
5048-/// invariant like [`at`]: the first clip whose start is past `frame` is the
5049-/// far wall, and the last one that ends at or before `frame` (or the
5125+/// The empty stretch of `items` covering `frame`, as `(start, len)` -- `None`
5126+/// when `frame` is inside a placement, or past the last one. Sorted-disjoint
5127+/// invariant like [`at`]: the first placement whose start is past `frame` is
5128+/// the far wall, and the last one that ends at or before `frame` (or the
50505129 /// timeline's own head, `0`, when there is none) is the near one.
5051-fn gap(clips: &[Clip], frame: u32) -> Option<(u32, u32)> {
5052- if at(clips, frame).is_some() {
5130+fn gap<T: GapPlacement>(items: &[T], frame: u32) -> Option<(u32, u32)> {
5131+ if at(items, frame).is_some() {
50535132 return None;
50545133 }
5055- let idx = clips.partition_point(|c| c.start <= frame);
5056- let next = clips.get(idx)?;
5057- let start = idx.checked_sub(1).map_or(0, |i| clips[i].end());
5058- Some((start, next.start - start))
5134+ let idx = items.partition_point(|item| item.start_frame() <= frame);
5135+ let next = items.get(idx)?;
5136+ let start = idx.checked_sub(1).map_or(0, |i| items[i].end_frame());
5137+ Some((start, next.start_frame() - start))
50595138 }
50605139
5061-/// Every bounded hole in `clips`, left to right. The tail after the last clip is
5062-/// deliberately absent: there is no later placement for a ripple to bring back.
5063-fn gaps(clips: &[Clip]) -> Vec<(u32, u32)> {
5140+/// Every bounded hole in `items`, left to right. The tail after the last
5141+/// placement is deliberately absent: there is no later placement for a ripple
5142+/// to bring back.
5143+fn gaps<T: GapPlacement>(items: &[T]) -> Vec<(u32, u32)> {
50645144 let mut out = Vec::new();
50655145 let mut next = 0;
5066- for c in clips {
5067- if c.start > next {
5068- out.push((next, c.start - next));
5146+ for item in items {
5147+ if item.start_frame() > next {
5148+ out.push((next, item.start_frame() - next));
50695149 }
5070- next = c.end();
5150+ next = item.end_frame();
50715151 }
50725152 out
50735153 }
@@ -5504,6 +5584,33 @@ mod tests {
55045584 }
55055585 }
55065586
5587+ /// A caption placement for pure timeline tests: the track window is the
5588+ /// same duration as the placement, so assertions can stay in frames.
5589+ fn caption(start: u32, frames: u32) -> SubClip {
5590+ SubClip {
5591+ start,
5592+ frames,
5593+ track: 0,
5594+ in_us: 0,
5595+ out_us: i64::from(frames) * 1_000_000,
5596+ link: None,
5597+ }
5598+ }
5599+
5600+ /// A subtitle palette row for tests that place captions on lanes.
5601+ fn subtitle_track() -> SubtitleTrack {
5602+ SubtitleTrack {
5603+ path: FILE.into(),
5604+ track: None,
5605+ language: "eng".into(),
5606+ name: String::new(),
5607+ label: "eng".into(),
5608+ cues: Vec::new(),
5609+ bitmap: false,
5610+ refused: None,
5611+ }
5612+ }
5613+
55075614 /// A recognisable equalizer setting: one peak band, `n` telling two of them
55085615 /// apart -- which is what makes the table's dedup and its prune visible.
55095616 fn band_at(n: u32) -> EqParams {
@@ -7956,6 +8063,87 @@ mod tests {
79568063 assert_eq!(shape(&p), before);
79578064 }
79588065
8066+ /// Subtitle lanes use the same bounded-hole hit test as clip lanes, against
8067+ /// their own caption storage: head gaps and gaps between cues count, an
8068+ /// empty lane and the tail after the last cue do not.
8069+ #[test]
8070+ fn gap_at_finds_the_hole_a_caption_frame_sits_in() {
8071+ let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]);
8072+ let s = p.add_lane(LaneKind::Subtitle);
8073+ assert_eq!(p.gap_at(s, 0), None, "an empty subtitle lane has nothing to close");
8074+
8075+ p.place_sub(s, 5, caption(0, 3)).expect("single cue at [5,8)");
8076+ assert_eq!(p.gap_at(s, 0), Some((0, 5)), "head gap before first cue");
8077+ assert_eq!(p.gap_at(s, 4), Some((0, 5)));
8078+ assert_eq!(p.gap_at(s, 5), None, "inside the cue");
8079+ assert_eq!(p.gap_at(s, 8), None, "tail after a single cue is not a gap");
8080+
8081+ p.place_sub(s, 12, caption(0, 2)).expect("second cue at [12,14)");
8082+ assert_eq!(p.gap_at(s, 8), Some((8, 4)), "gap between cues");
8083+ assert_eq!(p.gap_at(s, 11), Some((8, 4)));
8084+ assert_eq!(p.gap_at(s, 14), None, "tail after the last cue is still open-ended");
8085+ }
8086+
8087+ /// Closing a caption gap ripples the subtitle lane only. It is not a media
8088+ /// take close, so the video and audio lanes keep their frame positions.
8089+ #[test]
8090+ fn closing_a_caption_gap_ripples_no_video_or_audio_clips() {
8091+ let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]);
8092+ let s = p.add_lane(LaneKind::Subtitle);
8093+ p.place_sub(s, 5, caption(0, 3)).expect("single cue at [5,8)");
8094+ let before_clips = shape(&p);
8095+ let before_subs = p.sub_lane(s).to_vec();
8096+
8097+ let (start, len) = p.gap_at(s, 0).expect("gap before the caption");
8098+ assert_eq!((start, len), (0, 5));
8099+ p.cut_regions(&[(start, len)], &[s]).expect("caption lane gap closes");
8100+
8101+ assert_eq!(shape(&p), before_clips, "media lanes did not move");
8102+ assert_eq!(p.sub_lane(s), &[caption(0, 3)], "caption slid left");
8103+ assert!(p.undo(), "one undo restores the caption close");
8104+ assert_eq!(shape(&p), before_clips);
8105+ assert_eq!(p.sub_lane(s), before_subs);
8106+ }
8107+
8108+ /// The subtitle sweep is the clip sweep's bounded-gap arithmetic on
8109+ /// [`SubClip`] storage: right-to-left, one undo, no tail close, and no
8110+ /// history entry for empty or already-contiguous lanes.
8111+ #[test]
8112+ fn close_all_gaps_on_subtitle_lane_closes_bounded_gaps_and_undoes_once() {
8113+ let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]);
8114+ let s = p.add_lane(LaneKind::Subtitle);
8115+ let history = p.history.len();
8116+ let report = p.close_all_gaps_on_lane(s).expect("empty subtitle lane exists");
8117+ assert_eq!(report, GapSweep::default(), "empty subtitle lane has no bounded gap");
8118+ assert_eq!(p.history.len(), history, "empty sweep is not an undo step");
8119+
8120+ p.place_sub(s, 2, caption(0, 2)).expect("head gap [0,2)");
8121+ p.place_sub(s, 7, caption(0, 2)).expect("middle gap [4,7)");
8122+ p.place_sub(s, 14, caption(0, 1)).expect("middle gap [9,14), tail after 15");
8123+ let before = p.sub_lane(s).to_vec();
8124+
8125+ assert_eq!(p.gap_count(s), 3);
8126+ let report = p.close_all_gaps_on_lane(s).expect("subtitle lane exists");
8127+ assert_eq!(report.closed, 3);
8128+ assert!(report.skipped.is_empty());
8129+ assert_eq!(
8130+ p.sub_lane(s),
8131+ &[caption(0, 2), caption(2, 2), caption(4, 1)],
8132+ "all bounded caption gaps closed without touching windows"
8133+ );
8134+ assert!(p.undo(), "one undo restores every caption gap");
8135+ assert_eq!(p.sub_lane(s), before);
8136+
8137+ let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]);
8138+ let s = p.add_lane(LaneKind::Subtitle);
8139+ p.place_sub(s, 0, caption(0, 3)).expect("contiguous at the head");
8140+ let history = p.history.len();
8141+ let report = p.close_all_gaps_on_lane(s).expect("subtitle lane exists");
8142+ assert_eq!(report, GapSweep::default(), "the open tail is not closed");
8143+ assert_eq!(p.sub_lane(s), &[caption(0, 3)]);
8144+ assert_eq!(p.history.len(), history);
8145+ }
8146+
79598147 #[test]
79608148 fn ripple_delete_spans_partial_clips() {
79618149 let mut p = three();