forge
Explore
Log in

Don't you dare go Hollow

A ripple-closed clip's head no longer overflows on grab

Browse files at this commit

affa0a38a9c3d725d896403d18eaec1158459898Ahmet Kaan GümüşParent: 222336b
  • fix
    • a ripple-closed clip's head no longer overflows on grab
Show full message
🐛 fix(timeline): a ripple-closed clip's head no longer overflows on grab

`trim_room` read a clip's head room as `start - in_frame`, which assumes a
clip never carries more source in front of it than the timeline has room for.
A ripple delete leaves exactly that: cut at 5, delete the first piece, and
the survivor slides back to frame 0 still holding in-point 5. Grabbing its
left edge then subtracted with overflow -- a panic in debug on every pointer
sample of the drag, and a wrapped `lo` in release, which is a clamp that
means nothing.

Saturating, because frame 0 is the other wall that room was always bounded
by: a head can be pulled back to the start of the timeline and no further,
whatever the file still has behind it.
crates/engine/src/project.rsmodified+31 -2
@@ -1130,8 +1130,13 @@ impl Project {
11301130 let (member_lo, member_hi) = match edge {
11311131 Edge::Start => (
11321132 // Back to the source's own first frame, and never over the
1133- // clip in front of it.
1134- (c.start - c.in_frame).max(i.checked_sub(1).map_or(0, |p| clips[p].end())),
1133+ // clip in front of it. Saturating because a clip may hold
1134+ // *more* head than the timeline has room for -- a ripple
1135+ // delete slides a clip back to frame 0 with its in-point
1136+ // wherever the cut left it -- and frame 0 is the other wall.
1137+ c.start
1138+ .saturating_sub(c.in_frame)
1139+ .max(i.checked_sub(1).map_or(0, |p| clips[p].end())),
11351140 c.end() - 1,
11361141 ),
11371142 Edge::End => (
@@ -2303,6 +2308,30 @@ mod tests {
23032308 assert_eq!(shape(&p)[0][0], clip(4, 0, 4, 0), "one frame of head left");
23042309 }
23052310
2311+ /// A clip whose in-point is *past* its own start -- what a ripple delete
2312+ /// leaves, the piece in front of it gone and this one slid back to frame 0
2313+ /// carrying the in-point the cut gave it. Its head has more source behind it
2314+ /// than the timeline has room for, and the timeline's own first frame is the
2315+ /// wall: asking is not an overflow, and the answer is 0.
2316+ #[test]
2317+ fn a_ripple_closed_clip_can_still_be_head_trimmed() {
2318+ let mut p = Project::single(FILE, 9);
2319+ assert!(p.split(5));
2320+ assert!(p.delete_in(Lane::V1, 0), "the first piece goes");
2321+ assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)], "start 0, in-point 5");
2322+
2323+ assert_eq!(
2324+ p.trim_room(Lane::V1, 0, Edge::Start, SRC),
2325+ Some((0, 3)),
2326+ "back to frame 0 at most, and one frame of clip always survives"
2327+ );
2328+ assert!(!p.trim(Lane::V1, 0, Edge::Start, 0, SRC), "already there");
2329+ assert!(p.trim(Lane::V1, 0, Edge::Start, 2, SRC));
2330+ assert_eq!(shape(&p)[0], vec![clip(2, 7, 9, 0)], "the in-point followed");
2331+ assert!(p.trim(Lane::V1, 0, Edge::Start, 0, SRC), "and back out");
2332+ assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]);
2333+ }
2334+
23062335 /// Linked halves trim as one: a link is one span on however many lanes, so
23072336 /// the sound follows the picture's edge -- and the tightest wall of the two
23082337 /// is what stops both.