forge
Explore
Log in

Don't you dare go Hollow

The inverse admits its hole, the scale law lives once

Browse files at this commit

47c08dd67ea60e0f3c529ca262714efc96908e79Ahmet Kaan GümüşParent: b980282
  • fix
    • the inverse admits its hole, the scale law lives once
Show full message
🧹 fix(engine): the inverse admits its hole, the scale law lives once

invert fabricated an answer for the frames a shift-right piece never
produces -- the hole between the identity run and the piece's own image
-- against its own doc. It answers None there now, and a test walks the
hole asserting so.

The caption scale law lived twice, one copy clamped and one not, the
exact duplication that drifted a frame before: scaled_caption_frame is
now the single fn both write_speed and speeded_playhead call. The
successor guard saturates instead of overflowing at the clamp ceiling,
and the ungrouped-layer arm of whole_take is pinned by its own test
again -- a layer is lifted, never rippled.
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() {
479479 );
480480 }
481481
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+
482507 /// A caption anchor names the media half of its group: the video member for
483508 /// the cards that are about the picture, the audio member for the ones about
484509 /// 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 {
119119 if frame < self.knots[0].0.min(self.knots[0].1) {
120120 return Some(frame);
121121 }
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.
122128 if frame < self.knots[0].1 {
123- return Some(lerp((0, 0), self.knots[0], frame));
129+ return None;
124130 }
125131 let mut prev = self.knots[0];
126132 for &(o, n) in &self.knots {
@@ -250,6 +256,20 @@ mod tests {
250256 assert_piece_laws((100, 200), (100, 100), 500);
251257 }
252258
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+
253273 /// Identity is the base: everything maps to itself, in both directions,
254274 /// and the timeline's length never moved.
255275 #[test]
crates/engine/src/project.rsmodified+14 -10
@@ -2252,15 +2252,11 @@ impl Project {
22522252 // separately, which is what let the two answers drift apart by a
22532253 // frame.
22542254 let (held_old, new) = (held.speed.as_f64(), speed.as_f64());
2255- let scale = |f: u32| {
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- };
2255+ let scale = |f: u32| scaled_caption_frame(held.start, held_old, new, f);
22602256 let retimed = |s: SubClip| {
22612257 let map = TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end())));
22622258 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));
22642260 SubClip { start, frames: end - start, ..s }
22652261 };
22662262 for &(l, i) in &members.clips {
@@ -2363,10 +2359,7 @@ impl Project {
23632359 // the held clip's proportion -- the offset the group keeps.
23642360 None => {
23652361 let s = self.lanes[l].subs.get(i)?;
2366- let held_start = f64::from(held.start);
2367- let scale = |f: u32| {
2368- (held_start + (f64::from(f) - held_start) * held_old / new).round() as u32
2369- };
2362+ let scale = |f: u32| scaled_caption_frame(held.start, held_old, new, f);
23702363 (
23712364 (s.start, s.end()),
23722365 TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end()))),
@@ -4463,6 +4456,17 @@ fn handles(lanes: &[LaneData]) -> Vec<Lane> {
44634456 .collect()
44644457 }
44654458
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+
44664470 /// Which source frame a clip plays at `timeline_frame`: its in-point plus the
44674471 /// offset *at the clip's own rate*. The one place the two frame spaces meet, so
44684472 /// a speed cannot be applied twice or forgotten in one of them.