A ripple-closed clip's head no longer overflows on grab
Browse files at this commitaffa0a38a9c3d725d896403d18eaec1158459898Parent: 222336b- fix
- a ripple-closed clip's head no longer overflows on grab
1 changed file +31 -2
- crates/engine/src/project.rs +31 -2
crates/engine/src/project.rsmodified+31 -2
| @@ -1130,8 +1130,13 @@ impl Project { | |||
| 1130 | let (member_lo, member_hi) = match edge { | 1130 | let (member_lo, member_hi) = match edge { |
| 1131 | Edge::Start => ( | 1131 | Edge::Start => ( |
| 1132 | // Back to the source's own first frame, and never over the | 1132 | // Back to the source's own first frame, and never over the |
| 1133 | - // clip in front of it. | 1133 | + // clip in front of it. Saturating because a clip may hold |
| 1134 | - (c.start - c.in_frame).max(i.checked_sub(1).map_or(0, |p| clips[p].end())), | 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())), | ||
| 1135 | c.end() - 1, | 1140 | c.end() - 1, |
| 1136 | ), | 1141 | ), |
| 1137 | Edge::End => ( | 1142 | Edge::End => ( |
| @@ -2303,6 +2308,30 @@ mod tests { | |||
| 2303 | assert_eq!(shape(&p)[0][0], clip(4, 0, 4, 0), "one frame of head left"); | 2308 | assert_eq!(shape(&p)[0][0], clip(4, 0, 4, 0), "one frame of head left"); |
| 2304 | } | 2309 | } |
| 2305 | 2310 | ||
| 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 | + | ||
| 2306 | /// Linked halves trim as one: a link is one span on however many lanes, so | 2335 | /// Linked halves trim as one: a link is one span on however many lanes, so |
| 2307 | /// the sound follows the picture's edge -- and the tightest wall of the two | 2336 | /// the sound follows the picture's edge -- and the tightest wall of the two |
| 2308 | /// is what stops both. | 2337 | /// is what stops both. |