Tempo ops carry the captions of a group
Browse files at this commitb801cf59a189909e2989bcb28a265f97bc676841Parent: cda6d0e- feat
- tempo ops carry the captions of a group
4 changed files +401 -26
- crates/app/src/export_ui.rs +24 -0
- crates/app/src/player/cards.rs +64 -6
- crates/app/src/tests/editing.rs +30 -0
- crates/engine/src/project.rs +283 -20
crates/app/src/export_ui.rsmodified+24 -0
| @@ -271,6 +271,30 @@ pub(crate) fn audio_half(session: &PlaybackSession, (lane, idx): (Lane, usize)) | ||
| 271 | 271 | .unwrap_or((lane, idx)) |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | +/// The member of a caption's group on a media lane of the wanted kind: what a | |
| 275 | +/// card that is about media opens on when the hand is on the caption pinned to | |
| 276 | +/// it. `None` for a caption in no group with clips -- there are no pictures or | |
| 277 | +/// sound behind the words to be reaching at, and the card that opened anyway | |
| 278 | +/// would be a card of settings nothing plays. | |
| 279 | +pub(crate) fn caption_media_half( | |
| 280 | + session: &PlaybackSession, | |
| 281 | + (lane, idx): (Lane, usize), | |
| 282 | + kind: LaneKind, | |
| 283 | +) -> Option<(Lane, usize)> { | |
| 284 | + let link = session.sub_lane(lane).get(idx).and_then(|s| s.link)?; | |
| 285 | + session | |
| 286 | + .lanes() | |
| 287 | + .into_iter() | |
| 288 | + .filter(|l| l.kind == kind) | |
| 289 | + .find_map(|l| { | |
| 290 | + session | |
| 291 | + .lane_clips(l) | |
| 292 | + .iter() | |
| 293 | + .position(|c| c.link == Some(link)) | |
| 294 | + .map(|i| (l, i)) | |
| 295 | + }) | |
| 296 | +} | |
| 297 | + | |
| 274 | 298 | pub(crate) fn color_key(key: &str) -> Option<ColorKey> { |
| 275 | 299 | Some(match key { |
| 276 | 300 | ESCAPE => ColorKey::Close, |
crates/app/src/player/cards.rsmodified+64 -6
| @@ -309,11 +309,32 @@ impl Player { | ||
| 309 | 309 | cx.notify(); |
| 310 | 310 | return; |
| 311 | 311 | }; |
| 312 | - match self | |
| 312 | + // A caption the hand is on names the clip it was pinned to, and the | |
| 313 | + // card opens on that. A caption in no group has no rate to change and | |
| 314 | + // nothing behind it that does: said out loud, rather than a card that | |
| 315 | + // reads 1.00x and writes nothing. | |
| 316 | + let anchor = match self | |
| 313 | 317 | .selected |
| 314 | 318 | .anchor() |
| 315 | 319 | .or_else(|| session.video_clip_at(session.now())) |
| 316 | 320 | { |
| 321 | + Some((lane, idx)) if lane.kind == LaneKind::Subtitle => { | |
| 322 | + match caption_media_half(session, (lane, idx), LaneKind::Video) { | |
| 323 | + Some(half) => Some(half), | |
| 324 | + None => { | |
| 325 | + self.notify_user( | |
| 326 | + "NOTHING TO RE-TIME — a caption has no speed of its own; group it \ | |
| 327 | + with a clip first (ctrl-click both, then Group)" | |
| 328 | + .into(), | |
| 329 | + ); | |
| 330 | + cx.notify(); | |
| 331 | + return; | |
| 332 | + } | |
| 333 | + } | |
| 334 | + } | |
| 335 | + other => other, | |
| 336 | + }; | |
| 337 | + match anchor { | |
| 317 | 338 | Some(clip) => { |
| 318 | 339 | self.speed_open = Some(clip); |
| 319 | 340 | self.speed_dragging = false; |
| @@ -452,12 +473,32 @@ impl Player { | ||
| 452 | 473 | cx.notify(); |
| 453 | 474 | return; |
| 454 | 475 | }; |
| 455 | - match self | |
| 476 | + // A caption the hand is on names the sound its group plays: the card | |
| 477 | + // scans that half. A caption with no sound behind it -- alone, or | |
| 478 | + // grouped with clips that have none -- is a scan with nothing to hear, | |
| 479 | + // and it says so instead of returning without a word. | |
| 480 | + let anchor = match self | |
| 456 | 481 | .selected |
| 457 | 482 | .anchor() |
| 458 | 483 | .or_else(|| session.video_clip_at(session.now())) |
| 459 | - .map(|clip| audio_half(session, clip)) | |
| 460 | 484 | { |
| 485 | + Some((lane, idx)) if lane.kind == LaneKind::Subtitle => { | |
| 486 | + match caption_media_half(session, (lane, idx), LaneKind::Audio) { | |
| 487 | + Some(half) => Some(half), | |
| 488 | + None => { | |
| 489 | + self.notify_user( | |
| 490 | + "NOTHING TO SCAN — a caption has no sound of its own; group it with \ | |
| 491 | + the take's sound first (ctrl-click both, then Group)" | |
| 492 | + .into(), | |
| 493 | + ); | |
| 494 | + cx.notify(); | |
| 495 | + return; | |
| 496 | + } | |
| 497 | + } | |
| 498 | + } | |
| 499 | + other => other, | |
| 500 | + }; | |
| 501 | + match anchor.map(|clip| audio_half(session, clip)) { | |
| 461 | 502 | Some((lane, idx)) => { |
| 462 | 503 | let found = self.session.as_ref().and_then(|session| { |
| 463 | 504 | let clip = *session.lane_clips(lane).get(idx)?; |
| @@ -783,7 +824,12 @@ impl Player { | ||
| 783 | 824 | .lanes() |
| 784 | 825 | .into_iter() |
| 785 | 826 | .filter(|&l| { |
| 786 | - l == lane || session.lane_clips(l).iter().any(|c| c.link == Some(id)) | |
| 827 | + l == lane | |
| 828 | + || session.lane_clips(l).iter().any(|c| c.link == Some(id)) | |
| 829 | + // The caption pinned to the take travels with it: | |
| 830 | + // the ripple closes its lane too, or the words | |
| 831 | + // would stay put while the clip under them moved. | |
| 832 | + || session.sub_lane(l).iter().any(|s| s.link == Some(id)) | |
| 787 | 833 | }) |
| 788 | 834 | .collect(), |
| 789 | 835 | }, |
| @@ -961,7 +1007,19 @@ impl Player { | ||
| 961 | 1007 | if self.exporting().is_some() { |
| 962 | 1008 | return; |
| 963 | 1009 | } |
| 964 | - let refusal = match (self.selected.anchor(), &self.session) { | |
| 1010 | + // A caption the hand is on names the sound its group plays, and the | |
| 1011 | + // card opens on that; one in no group has no sound to equalize and | |
| 1012 | + // falls to the lane refusal below, in the words it always used. | |
| 1013 | + let anchor = match (self.selected.anchor(), self.session.as_ref()) { | |
| 1014 | + (Some((lane, idx)), Some(session)) | |
| 1015 | + if lane.kind == LaneKind::Subtitle => | |
| 1016 | + { | |
| 1017 | + caption_media_half(session, (lane, idx), LaneKind::Audio) | |
| 1018 | + .or(self.selected.anchor()) | |
| 1019 | + } | |
| 1020 | + _ => self.selected.anchor(), | |
| 1021 | + }; | |
| 1022 | + let refusal = match (anchor, &self.session) { | |
| 965 | 1023 | (_, None) => Some("NO TIMELINE — open a file first".to_string()), |
| 966 | 1024 | (None, _) => Some(format!( |
| 967 | 1025 | "NOTHING SELECTED — click an audio clip or press {}, then ask again", |
| @@ -977,7 +1035,7 @@ impl Player { | ||
| 977 | 1035 | cx.notify(); |
| 978 | 1036 | return; |
| 979 | 1037 | } |
| 980 | - let (lane, idx) = self.selected.anchor().expect("checked above"); | |
| 1038 | + let (lane, idx) = anchor.expect("checked above"); | |
| 981 | 1039 | let session = self.session.as_ref().expect("checked above"); |
| 982 | 1040 | // What the clip already plays through, or the flat default -- so the |
| 983 | 1041 | // card opens on the curve that is in force and a reopen shows the last |
crates/app/src/tests/editing.rsmodified+30 -0
| @@ -479,6 +479,36 @@ fn a_caption_grouped_with_a_clip_pairs_it_for_the_whole_take_question() { | ||
| 479 | 479 | ); |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | +/// A caption anchor names the media half of its group: the video member for | |
| 483 | +/// the cards that are about the picture, the audio member for the ones about | |
| 484 | +/// the sound. A caption in no group names nothing -- which is what the cards' | |
| 485 | +/// new refusals say out loud. | |
| 486 | +#[test] | |
| 487 | +fn a_caption_anchor_names_the_media_half_of_its_group() { | |
| 488 | + use crate::caption_media_half; | |
| 489 | + | |
| 490 | + let (mut session, lane) = with_subtitle_lane(); | |
| 491 | + session | |
| 492 | + .place_sub(lane, 0, one_second(0)) | |
| 493 | + .expect("the caption goes down"); | |
| 494 | + // Ungrouped: no pictures and no sound behind the words. | |
| 495 | + assert_eq!(caption_media_half(&session, (lane, 0), LaneKind::Video), None); | |
| 496 | + assert_eq!(caption_media_half(&session, (lane, 0), LaneKind::Audio), None); | |
| 497 | + // Grouped with the take -- whose sound rides along unasked -- both halves | |
| 498 | + // answer by lane and index. | |
| 499 | + session | |
| 500 | + .group_all(&[(Lane::V1, 0), (lane, 0)]) | |
| 501 | + .expect("a clip and a caption are a group"); | |
| 502 | + assert_eq!( | |
| 503 | + caption_media_half(&session, (lane, 0), LaneKind::Video), | |
| 504 | + Some((Lane::V1, 0)) | |
| 505 | + ); | |
| 506 | + assert_eq!( | |
| 507 | + caption_media_half(&session, (lane, 0), LaneKind::Audio), | |
| 508 | + Some((Lane::A1, 0)) | |
| 509 | + ); | |
| 510 | +} | |
| 511 | + | |
| 482 | 512 | /// The manual group's oracle question: a selection of placements, one per lane. |
| 483 | 513 | /// Two picks on two lanes is a group waiting to happen; a lane picked twice is |
| 484 | 514 | /// the one thing a group may never hold; a single pick is the partner hunt. |
crates/engine/src/project.rsmodified+283 -20
| @@ -2214,8 +2214,25 @@ impl Project { | ||
| 2214 | 2214 | return Err(format!("there is no clip {idx} on {}", lane.label()).into()); |
| 2215 | 2215 | }; |
| 2216 | 2216 | let labels = handles(&self.lanes); |
| 2217 | - // Media members only: a caption has no rate to change, and what the | |
| 2218 | - // id binds it to -- a move, a trim, a delete -- travels by frames. | |
| 2217 | + // The clip the hand is holding is the group's clock: everything else | |
| 2218 | + // in the group, caption members included, re-times by the ratio its new | |
| 2219 | + // rate gives its own frames. The clips take the rate itself; a caption | |
| 2220 | + // has none, so it takes the *ratio* -- its span on the timeline | |
| 2221 | + // compresses or stretches about the held clip's head, while the words | |
| 2222 | + // it reads keep their own timing ([`write_sub_edge`]'s law: the | |
| 2223 | + // timeline moves, the track does not). | |
| 2224 | + let Some(held) = self.lane(lane).get(idx).copied() else { | |
| 2225 | + return Err(format!("there is no clip {idx} on {}", lane.label()).into()); | |
| 2226 | + }; | |
| 2227 | + let (old, new) = (f64::from(held.frames()), f64::from(speed.frames(held.len()))); | |
| 2228 | + let ratio = new / old.max(1.); | |
| 2229 | + let retimed = |s: SubClip| SubClip { | |
| 2230 | + start: ((f64::from(s.start) - f64::from(held.start)) * ratio + f64::from(held.start)) | |
| 2231 | + .round() | |
| 2232 | + .clamp(0., f64::from(u32::MAX)) as u32, | |
| 2233 | + frames: (f64::from(s.frames) * ratio).round().clamp(1., f64::from(u32::MAX)) as u32, | |
| 2234 | + ..s | |
| 2235 | + }; | |
| 2219 | 2236 | for &(l, i) in &members.clips { |
| 2220 | 2237 | let clips = &self.lanes[l].clips; |
| 2221 | 2238 | let mut moved = clips[i]; |
| @@ -2233,6 +2250,29 @@ impl Project { | ||
| 2233 | 2250 | .into()); |
| 2234 | 2251 | } |
| 2235 | 2252 | } |
| 2253 | + // ...and the captions, against their own lanes' captions: a stretch | |
| 2254 | + // that runs one into its neighbour is refused for the clip arm's | |
| 2255 | + // reason -- a lane may not overlap itself -- and by name like it. | |
| 2256 | + let subs: Vec<(usize, usize, SubClip)> = members | |
| 2257 | + .subs | |
| 2258 | + .iter() | |
| 2259 | + .map(|&(l, i)| (l, i, retimed(self.lanes[l].subs[i]))) | |
| 2260 | + .collect(); | |
| 2261 | + for &(l, i, moved) in &subs { | |
| 2262 | + for (j, other) in self.lanes[l].subs.iter().enumerate() { | |
| 2263 | + if j != i && moved.start < other.end() && other.start < moved.end() { | |
| 2264 | + return Err(format!( | |
| 2265 | + "at {speed} the {} caption at frame {} would run to frame {} and the next \ | |
| 2266 | + starts at {}: move it along, or trim this one first", | |
| 2267 | + labels[l].label(), | |
| 2268 | + self.lanes[l].subs[i].start, | |
| 2269 | + moved.end(), | |
| 2270 | + other.start | |
| 2271 | + ) | |
| 2272 | + .into()); | |
| 2273 | + } | |
| 2274 | + } | |
| 2275 | + } | |
| 2236 | 2276 | if snapshot { |
| 2237 | 2277 | self.snapshot(); |
| 2238 | 2278 | } |
| @@ -2240,6 +2280,10 @@ impl Project { | ||
| 2240 | 2280 | self.lanes[l].clips[i].speed = speed; |
| 2241 | 2281 | debug_assert!(sorted_disjoint(&self.lanes[l].clips)); |
| 2242 | 2282 | } |
| 2283 | + for (l, i, moved) in subs { | |
| 2284 | + self.lanes[l].subs[i] = moved; | |
| 2285 | + debug_assert!(subs_sorted_disjoint(&self.lanes[l].subs)); | |
| 2286 | + } | |
| 2243 | 2287 | debug_assert!(links_are_consistent(&self.lanes).is_ok()); |
| 2244 | 2288 | Ok(()) |
| 2245 | 2289 | } |
| @@ -3719,26 +3763,50 @@ impl Project { | ||
| 3719 | 3763 | /// not move, so it is not this rule's business. |
| 3720 | 3764 | fn scope_holds_takes_whole(&self, on: &[usize], from: u32) -> crate::Result<()> { |
| 3721 | 3765 | let labels = handles(&self.lanes); |
| 3766 | + // The halves of a group are on either of a lane's lists, and the | |
| 3767 | + // refusal names whichever sits outside the scope -- a clip like it | |
| 3768 | + // always has, and a caption now that a group may hold one. | |
| 3769 | + let halves = |start: u32, link: Option<u32>, what: &str| -> crate::Result<()> { | |
| 3770 | + let Some(id) = link else { | |
| 3771 | + return Ok(()); | |
| 3772 | + }; | |
| 3773 | + for (j, data) in self.lanes.iter().enumerate() { | |
| 3774 | + if on.contains(&j) { | |
| 3775 | + continue; | |
| 3776 | + } | |
| 3777 | + let clip = data.clips.iter().find(|o| o.link == Some(id)); | |
| 3778 | + let sub = data.subs.iter().find(|s| s.link == Some(id)); | |
| 3779 | + if let Some(half) = clip { | |
| 3780 | + return Err(format!( | |
| 3781 | + "the {what} at frame {start} is one take with the {} clip at frame {}: \ | |
| 3782 | + moving one track of a take would pull it apart -- take the whole take, \ | |
| 3783 | + or detach them first", | |
| 3784 | + labels[j].label(), | |
| 3785 | + half.start | |
| 3786 | + ) | |
| 3787 | + .into()); | |
| 3788 | + } | |
| 3789 | + if let Some(half) = sub { | |
| 3790 | + return Err(format!( | |
| 3791 | + "the {what} at frame {start} is one take with the {} caption at frame {}: \ | |
| 3792 | + moving one track of a take would pull it apart -- take the whole take, \ | |
| 3793 | + or detach them first", | |
| 3794 | + labels[j].label(), | |
| 3795 | + half.start | |
| 3796 | + ) | |
| 3797 | + .into()); | |
| 3798 | + } | |
| 3799 | + } | |
| 3800 | + Ok(()) | |
| 3801 | + }; | |
| 3722 | 3802 | for &i in on { |
| 3723 | 3803 | for c in self.lanes[i].clips.iter().filter(|c| c.end() > from) { |
| 3724 | - let Some(id) = c.link else { continue }; | |
| 3725 | - for (j, data) in self.lanes.iter().enumerate() { | |
| 3726 | - if on.contains(&j) { | |
| 3727 | - continue; | |
| 3728 | - } | |
| 3729 | - if let Some(half) = data.clips.iter().find(|o| o.link == Some(id)) { | |
| 3730 | - return Err(format!( | |
| 3731 | - "the {} clip at frame {} is one take with the {} clip at frame {}: \ | |
| 3732 | - moving one track of a take would pull it apart -- take the whole take, \ | |
| 3733 | - or detach them first", | |
| 3734 | - labels[i].label(), | |
| 3735 | - c.start, | |
| 3736 | - labels[j].label(), | |
| 3737 | - half.start | |
| 3738 | - ) | |
| 3739 | - .into()); | |
| 3740 | - } | |
| 3741 | - } | |
| 3804 | + halves(c.start, c.link, &format!("{} clip", labels[i].label()))?; | |
| 3805 | + } | |
| 3806 | + // A caption before the first cut does not move, so it is not this | |
| 3807 | + // rule's business -- exactly the clip test's own line. | |
| 3808 | + for s in self.lanes[i].subs.iter().filter(|s| s.end() > from) { | |
| 3809 | + halves(s.start, s.link, &format!("{} caption", labels[i].label()))?; | |
| 3742 | 3810 | } |
| 3743 | 3811 | } |
| 3744 | 3812 | Ok(()) |
| @@ -3864,6 +3932,8 @@ impl Project { | ||
| 3864 | 3932 | (None, None) => continue, |
| 3865 | 3933 | (None, Some((_, after))) => after, |
| 3866 | 3934 | }; |
| 3935 | + // The region's new length, on every scoped lane alike. | |
| 3936 | + let after = shrunk; | |
| 3867 | 3937 | let Some(delta) = len.checked_sub(shrunk) else { |
| 3868 | 3938 | self.undo(); |
| 3869 | 3939 | return Err(format!( |
| @@ -3881,6 +3951,21 @@ impl Project { | ||
| 3881 | 3951 | } |
| 3882 | 3952 | } |
| 3883 | 3953 | debug_assert!(sorted_disjoint(&self.lanes[l].clips)); |
| 3954 | + // The captions on a scoped lane travel with the region's time: | |
| 3955 | + // a piece inside it plays in `after` frames instead of `len` | |
| 3956 | + // -- same words on less timeline, its window untouched, for | |
| 3957 | + // [`write_speed`]'s reason -- and everything behind the region | |
| 3958 | + // slides up by what the region gave back. | |
| 3959 | + let share = f64::from(after) / f64::from(len).max(1.); | |
| 3960 | + for s in &mut self.lanes[l].subs { | |
| 3961 | + if s.start >= at + len { | |
| 3962 | + s.start -= delta; | |
| 3963 | + } else if s.start >= at && s.end() <= at + len { | |
| 3964 | + s.start = at + (f64::from(s.start - at) * share).round() as u32; | |
| 3965 | + s.frames = (f64::from(s.frames) * share).round().max(1.) as u32; | |
| 3966 | + } | |
| 3967 | + } | |
| 3968 | + debug_assert!(subs_sorted_disjoint(&self.lanes[l].subs)); | |
| 3884 | 3969 | } |
| 3885 | 3970 | } |
| 3886 | 3971 | debug_assert!(links_are_consistent(&self.lanes).is_ok()); |
| @@ -4873,6 +4958,184 @@ mod tests { | ||
| 4873 | 4958 | assert!(links_are_consistent(&p.lanes).is_ok()); |
| 4874 | 4959 | } |
| 4875 | 4960 | |
| 4961 | + /// A rate re-times the caption members of the group by the ratio it gives | |
| 4962 | + /// the held clip: the span on the timeline compresses about the held clip's | |
| 4963 | + /// head, the words' own window untouched -- and one undo puts it back. | |
| 4964 | + #[test] | |
| 4965 | + fn a_rate_carries_the_group_caption_by_the_held_clips_ratio() { | |
| 4966 | + let caption = |start: u32, frames: u32| SubClip { | |
| 4967 | + start, | |
| 4968 | + frames, | |
| 4969 | + track: 0, | |
| 4970 | + in_us: 0, | |
| 4971 | + out_us: i64::from(frames) * 1_000_000, | |
| 4972 | + link: None, | |
| 4973 | + }; | |
| 4974 | + let track = || SubtitleTrack { | |
| 4975 | + path: FILE.into(), | |
| 4976 | + track: None, | |
| 4977 | + language: "eng".into(), | |
| 4978 | + name: String::new(), | |
| 4979 | + label: "eng".into(), | |
| 4980 | + cues: Vec::new(), | |
| 4981 | + bitmap: false, | |
| 4982 | + refused: None, | |
| 4983 | + }; | |
| 4984 | + let grouped = || { | |
| 4985 | + let mut p = Project::single(FILE, 90).with_subtitles(vec![track()]); | |
| 4986 | + let s1 = p.add_lane(LaneKind::Subtitle); | |
| 4987 | + p.place_sub(s1, 0, caption(0, 90)).expect("placed"); | |
| 4988 | + p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped"); | |
| 4989 | + (p, s1) | |
| 4990 | + }; | |
| 4991 | + | |
| 4992 | + // An aligned take, doubled: the caption plays in half the frames. | |
| 4993 | + let (mut p, s1) = grouped(); | |
| 4994 | + p.set_speed(Lane::V1, 0, Speed::from_permille(2000)) | |
| 4995 | + .expect("room for it"); | |
| 4996 | + assert_eq!(p.lane(Lane::V1)[0].frames(), 45); | |
| 4997 | + let s = p.sub_lane(s1)[0]; | |
| 4998 | + assert_eq!((s.start, s.frames), (0, 45), "same words, half the timeline"); | |
| 4999 | + assert_eq!((s.in_us, s.out_us), (0, 90_000_000), "the window is untouched"); | |
| 5000 | + assert!(links_are_consistent(&p.lanes).is_ok()); | |
| 5001 | + assert!(p.undo()); | |
| 5002 | + assert_eq!(p.sub_lane(s1)[0].frames, 90, "one undo puts it back"); | |
| 5003 | + | |
| 5004 | + // An offset group, slowed to half: the caption's *offset from the held | |
| 5005 | + // clip's head* is what scales -- it sits 30 frames in at 1x, 60 at | |
| 5006 | + // 0.5x, and still ends where the clip does. | |
| 5007 | + let (mut p, s1) = grouped(); | |
| 5008 | + p.lift_sub(s1, 0); | |
| 5009 | + p.place_sub(s1, 30, caption(30, 60)).expect("placed"); | |
| 5010 | + p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped"); | |
| 5011 | + p.set_speed(Lane::V1, 0, Speed::from_permille(500)) | |
| 5012 | + .expect("room for it"); | |
| 5013 | + assert_eq!(p.lane(Lane::V1)[0].frames(), 180); | |
| 5014 | + let s = p.sub_lane(s1)[0]; | |
| 5015 | + assert_eq!((s.start, s.frames), (60, 120), "the offset doubles with the clip"); | |
| 5016 | + assert_eq!(s.end(), p.lane(Lane::V1)[0].end(), "still ends with the clip"); | |
| 5017 | + | |
| 5018 | + // A stretch that runs the caption into its neighbour is refused, by | |
| 5019 | + // lane and frame, and costs no undo step. | |
| 5020 | + let (mut p, s1) = grouped(); | |
| 5021 | + p.lift_sub(s1, 0); | |
| 5022 | + p.place_sub(s1, 0, caption(0, 90)).expect("placed"); | |
| 5023 | + p.place_sub(s1, 95, caption(95, 5)).expect("the neighbour"); | |
| 5024 | + p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped"); | |
| 5025 | + let history = p.history.len(); | |
| 5026 | + let err = p | |
| 5027 | + .set_speed(Lane::V1, 0, Speed::from_permille(500)) | |
| 5028 | + .unwrap_err() | |
| 5029 | + .to_string(); | |
| 5030 | + assert!( | |
| 5031 | + err.contains("the S1 caption at frame 0 would run to frame 180 and the next starts at 95"), | |
| 5032 | + "{err}" | |
| 5033 | + ); | |
| 5034 | + assert_eq!(p.history.len(), history, "a refusal costs no undo step"); | |
| 5035 | + } | |
| 5036 | + | |
| 5037 | + /// The silence scan's speed-up re-times the captions on a scoped lane with | |
| 5038 | + /// everything else: the piece inside the region plays in the region's new | |
| 5039 | + /// frames, and what sits behind the region slides up with the clips. | |
| 5040 | + #[test] | |
| 5041 | + fn speeding_a_region_carries_the_captions_on_the_scoped_lanes() { | |
| 5042 | + let caption = |start: u32, frames: u32| SubClip { | |
| 5043 | + start, | |
| 5044 | + frames, | |
| 5045 | + track: 0, | |
| 5046 | + in_us: 0, | |
| 5047 | + out_us: i64::from(frames) * 1_000_000, | |
| 5048 | + link: None, | |
| 5049 | + }; | |
| 5050 | + let track = || SubtitleTrack { | |
| 5051 | + path: FILE.into(), | |
| 5052 | + track: None, | |
| 5053 | + language: "eng".into(), | |
| 5054 | + name: String::new(), | |
| 5055 | + label: "eng".into(), | |
| 5056 | + cues: Vec::new(), | |
| 5057 | + bitmap: false, | |
| 5058 | + refused: None, | |
| 5059 | + }; | |
| 5060 | + let mut p = Project::single(FILE, 90).with_subtitles(vec![track()]); | |
| 5061 | + let s1 = p.add_lane(LaneKind::Subtitle); | |
| 5062 | + // Words over the region [30, 60) and words behind it. | |
| 5063 | + p.place_sub(s1, 30, caption(30, 30)).expect("placed"); | |
| 5064 | + p.place_sub(s1, 60, caption(60, 30)).expect("placed"); | |
| 5065 | + | |
| 5066 | + // The region [30, 60) plays at 4x: 30 frames become 8, everything | |
| 5067 | + // behind slides up 22. | |
| 5068 | + // The scope is what the card's Take row says, caption lane included. | |
| 5069 | + p.speed_regions( | |
| 5070 | + &[(30, 30)], | |
| 5071 | + Speed::from_permille(4000), | |
| 5072 | + &[Lane::V1, Lane::A1, s1], | |
| 5073 | + ) | |
| 5074 | + .expect("the region speeds up"); | |
| 5075 | + let subs = p.sub_lane(s1); | |
| 5076 | + assert_eq!( | |
| 5077 | + (subs[0].start, subs[0].frames), | |
| 5078 | + (30, 8), | |
| 5079 | + "the piece inside plays in the region's new frames" | |
| 5080 | + ); | |
| 5081 | + assert_eq!( | |
| 5082 | + (subs[1].start, subs[1].frames), | |
| 5083 | + (38, 30), | |
| 5084 | + "the piece behind slides up by what the region gave back" | |
| 5085 | + ); | |
| 5086 | + assert!(subs_sorted_disjoint(&p.lanes[p.index(s1).unwrap()].subs)); | |
| 5087 | + } | |
| 5088 | + | |
| 5089 | + /// The scope law names a caption half too: a scoped cut that would move one | |
| 5090 | + // track of a group whose caption sits outside the scope is refused. | |
| 5091 | + #[test] | |
| 5092 | + fn the_scope_law_refuses_a_caption_half_outside_the_scope() { | |
| 5093 | + let caption = |start: u32, frames: u32| SubClip { | |
| 5094 | + start, | |
| 5095 | + frames, | |
| 5096 | + track: 0, | |
| 5097 | + in_us: 0, | |
| 5098 | + out_us: i64::from(frames) * 1_000_000, | |
| 5099 | + link: None, | |
| 5100 | + }; | |
| 5101 | + let track = || SubtitleTrack { | |
| 5102 | + path: FILE.into(), | |
| 5103 | + track: None, | |
| 5104 | + language: "eng".into(), | |
| 5105 | + name: String::new(), | |
| 5106 | + label: "eng".into(), | |
| 5107 | + cues: Vec::new(), | |
| 5108 | + bitmap: false, | |
| 5109 | + refused: None, | |
| 5110 | + }; | |
| 5111 | + let mut p = Project::single(FILE, 90).with_subtitles(vec![track()]); | |
| 5112 | + let s1 = p.add_lane(LaneKind::Subtitle); | |
| 5113 | + p.place_sub(s1, 0, caption(0, 90)).expect("placed"); | |
| 5114 | + p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped"); | |
| 5115 | + | |
| 5116 | + // The subtitle lane is not in the scope, so the group's caption half | |
| 5117 | + // sits outside it: refused, in the law's own words. | |
| 5118 | + let err = p | |
| 5119 | + .cut_regions(&[(10, 5)], &[Lane::V1, Lane::A1]) | |
| 5120 | + .unwrap_err() | |
| 5121 | + .to_string(); | |
| 5122 | + assert!( | |
| 5123 | + err.contains("is one take with the S1 caption at frame 0"), | |
| 5124 | + "{err}" | |
| 5125 | + ); | |
| 5126 | + | |
| 5127 | + // ...and with the caption's lane in the scope, the cut carries it: | |
| 5128 | + // the words over the hole go, and the words behind slide up. | |
| 5129 | + p.cut_regions(&[(10, 5)], &[Lane::V1, Lane::A1, s1]) | |
| 5130 | + .expect("the whole group is in the scope"); | |
| 5131 | + let subs = p.sub_lane(s1); | |
| 5132 | + assert_eq!( | |
| 5133 | + subs.iter().map(|s| (s.start, s.frames)).collect::<Vec<_>>(), | |
| 5134 | + [(0, 10), (10, 75)], | |
| 5135 | + "the caption is cut and shifted with the clips" | |
| 5136 | + ); | |
| 5137 | + } | |
| 5138 | + | |
| 4876 | 5139 | /// The caption a hand groups: `group_all` over clips *and* a caption, the |
| 4877 | 5140 | /// mates riding along, the offsets kept, the refusals in words. |
| 4878 | 5141 | #[test] |