The inverse admits its hole, the scale law lives once
Browse files at this commit47c08dd67ea60e0f3c529ca262714efc96908e79Parent: b980282- fix
- the inverse admits its hole, the scale law lives once
3 changed files +60 -11
- crates/app/src/tests/editing.rs +25 -0
- crates/engine/src/map.rs +21 -1
- crates/engine/src/project.rs +14 -10
crates/app/src/tests/editing.rsmodified+25 -0
| @@ -479,6 +479,31 @@ fn a_caption_grouped_with_a_clip_pairs_it_for_the_whole_take_question() { | |||
| 479 | ); | 479 | ); |
| 480 | } | 480 | } |
| 481 | 481 | ||
| 482 | +/// An ungrouped clip on a further lane (ord >= 1) is a layer, not a take: it | ||
| 483 | +/// sits over the timeline rather than in it, so deleting it lifts a hole | ||
| 484 | +/// rather than rippling one closed. Pins the `(_, 1..) => false` arm | ||
| 485 | +/// `whole_take` answers before it ever reaches the video/audio arms below. | ||
| 486 | +#[test] | ||
| 487 | +fn an_ungrouped_clip_on_a_further_lane_is_a_layer_not_a_take() { | ||
| 488 | + use engine::project::LaneKind; | ||
| 489 | + | ||
| 490 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 491 | + session.set_gain(0.0); | ||
| 492 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 493 | + assert!(session.move_clip_to(Lane::V1, 0, v2, 0), "V1 -> V2"); | ||
| 494 | + // Its old pairing with A1 came along with the move -- detach it, an | ||
| 495 | + // ungrouped clip is exactly the case this arm is for. | ||
| 496 | + assert!(session.ungroup(v2, 0)); | ||
| 497 | + assert!( | ||
| 498 | + !whole_take(&session, v2, 0), | ||
| 499 | + "an ungrouped clip on ord >= 1 is a layer, not a take" | ||
| 500 | + ); | ||
| 501 | + // ...and its delete lifts, leaving the hole under it open: the take | ||
| 502 | + // beneath (there is none here, but the lane) is untouched. | ||
| 503 | + assert!(session.lift_clip(v2, 0)); | ||
| 504 | + assert!(session.lane_clips(v2).is_empty()); | ||
| 505 | +} | ||
| 506 | + | ||
| 482 | /// A caption anchor names the media half of its group: the video member for | 507 | /// 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 | 508 | /// 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' | 509 | /// the sound. A caption in no group names nothing -- which is what the cards' |
crates/engine/src/map.rsmodified+21 -1
| @@ -119,8 +119,14 @@ impl TimelineMap { | |||
| 119 | if frame < self.knots[0].0.min(self.knots[0].1) { | 119 | if frame < self.knots[0].0.min(self.knots[0].1) { |
| 120 | return Some(frame); | 120 | return Some(frame); |
| 121 | } | 121 | } |
| 122 | + // Between old_lo and new_lo of an unanchored (shift-right / plain | ||
| 123 | + // expansion) piece, `apply` never lands: old frames below old_lo | ||
| 124 | + // stay identity (image 0..old_lo) and the piece's own image starts | ||
| 125 | + // at new_lo > old_lo, leaving [old_lo, new_lo) a true hole. A | ||
| 126 | + // shift-left's anchor knot ties old==new here, so this window is | ||
| 127 | + // empty for it and the branch is never live. | ||
| 122 | if frame < self.knots[0].1 { | 128 | if frame < self.knots[0].1 { |
| 123 | - return Some(lerp((0, 0), self.knots[0], frame)); | 129 | + return None; |
| 124 | } | 130 | } |
| 125 | let mut prev = self.knots[0]; | 131 | let mut prev = self.knots[0]; |
| 126 | for &(o, n) in &self.knots { | 132 | for &(o, n) in &self.knots { |
| @@ -250,6 +256,20 @@ mod tests { | |||
| 250 | assert_piece_laws((100, 200), (100, 100), 500); | 256 | assert_piece_laws((100, 200), (100, 100), 500); |
| 251 | } | 257 | } |
| 252 | 258 | ||
| 259 | + /// The hole a shift-right/expansion piece leaves in its own image: new | ||
| 260 | + /// frames between old_lo and new_lo have no old frame that lands on | ||
| 261 | + /// them, so `invert` must say so instead of fabricating one. | ||
| 262 | + #[test] | ||
| 263 | + fn invert_is_none_inside_a_pieces_own_hole() { | ||
| 264 | + let m = TimelineMap::piece((30, 60), (45, 90)); | ||
| 265 | + for f in 30..45 { | ||
| 266 | + assert_eq!(m.invert(f), None, "new frame {f} has no preimage"); | ||
| 267 | + } | ||
| 268 | + // Just outside the hole, both ends still answer. | ||
| 269 | + assert_eq!(m.invert(29), Some(29)); | ||
| 270 | + assert_eq!(m.invert(45), Some(30)); | ||
| 271 | + } | ||
| 272 | + | ||
| 253 | /// Identity is the base: everything maps to itself, in both directions, | 273 | /// Identity is the base: everything maps to itself, in both directions, |
| 254 | /// and the timeline's length never moved. | 274 | /// and the timeline's length never moved. |
| 255 | #[test] | 275 | #[test] |
crates/engine/src/project.rsmodified+14 -10
| @@ -2252,15 +2252,11 @@ impl Project { | |||
| 2252 | // separately, which is what let the two answers drift apart by a | 2252 | // separately, which is what let the two answers drift apart by a |
| 2253 | // frame. | 2253 | // frame. |
| 2254 | let (held_old, new) = (held.speed.as_f64(), speed.as_f64()); | 2254 | let (held_old, new) = (held.speed.as_f64(), speed.as_f64()); |
| 2255 | - let scale = |f: u32| { | 2255 | + let scale = |f: u32| scaled_caption_frame(held.start, held_old, new, f); |
| 2256 | - (f64::from(held.start) + (f64::from(f) - f64::from(held.start)) * held_old / new) | ||
| 2257 | - .round() | ||
| 2258 | - .clamp(0., f64::from(u32::MAX)) as u32 | ||
| 2259 | - }; | ||
| 2260 | let retimed = |s: SubClip| { | 2256 | let retimed = |s: SubClip| { |
| 2261 | let map = TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end()))); | 2257 | let map = TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end()))); |
| 2262 | let start = map.apply(s.start); | 2258 | let start = map.apply(s.start); |
| 2263 | - let end = map.apply(s.end()).max(start + 1); | 2259 | + let end = map.apply(s.end()).max(start.saturating_add(1)); |
| 2264 | SubClip { start, frames: end - start, ..s } | 2260 | SubClip { start, frames: end - start, ..s } |
| 2265 | }; | 2261 | }; |
| 2266 | for &(l, i) in &members.clips { | 2262 | for &(l, i) in &members.clips { |
| @@ -2363,10 +2359,7 @@ impl Project { | |||
| 2363 | // the held clip's proportion -- the offset the group keeps. | 2359 | // the held clip's proportion -- the offset the group keeps. |
| 2364 | None => { | 2360 | None => { |
| 2365 | let s = self.lanes[l].subs.get(i)?; | 2361 | let s = self.lanes[l].subs.get(i)?; |
| 2366 | - let held_start = f64::from(held.start); | 2362 | + let scale = |f: u32| scaled_caption_frame(held.start, held_old, new, f); |
| 2367 | - let scale = |f: u32| { | ||
| 2368 | - (held_start + (f64::from(f) - held_start) * held_old / new).round() as u32 | ||
| 2369 | - }; | ||
| 2370 | ( | 2363 | ( |
| 2371 | (s.start, s.end()), | 2364 | (s.start, s.end()), |
| 2372 | TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end()))), | 2365 | TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end()))), |
| @@ -4463,6 +4456,17 @@ fn handles(lanes: &[LaneData]) -> Vec<Lane> { | |||
| 4463 | .collect() | 4456 | .collect() |
| 4464 | } | 4457 | } |
| 4465 | 4458 | ||
| 4459 | +/// The one law a caption re-time scales by: frame `f` moves about the held | ||
| 4460 | +/// clip's own start by the held clip's old-to-new rate ratio. [`write_speed`] | ||
| 4461 | +/// commits it, [`Project::speeded_playhead`] previews it -- both build their | ||
| 4462 | +/// [`TimelineMap`] piece from this single answer so the two cannot drift | ||
| 4463 | +/// apart by a frame the way they once did. | ||
| 4464 | +fn scaled_caption_frame(held_start: u32, held_old: f64, new: f64, f: u32) -> u32 { | ||
| 4465 | + (f64::from(held_start) + (f64::from(f) - f64::from(held_start)) * held_old / new) | ||
| 4466 | + .round() | ||
| 4467 | + .clamp(0., f64::from(u32::MAX)) as u32 | ||
| 4468 | +} | ||
| 4469 | + | ||
| 4466 | /// Which source frame a clip plays at `timeline_frame`: its in-point plus the | 4470 | /// Which source frame a clip plays at `timeline_frame`: its in-point plus the |
| 4467 | /// offset *at the clip's own rate*. The one place the two frame spaces meet, so | 4471 | /// offset *at the clip's own rate*. The one place the two frame spaces meet, so |
| 4468 | /// a speed cannot be applied twice or forgotten in one of them. | 4472 | /// a speed cannot be applied twice or forgotten in one of them. |