diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 30482e8..61ea861 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -2018,6 +2018,25 @@ impl Player { return clip; }; match trim.edge { + // A still grows forward from source frame 0 instead, exactly as + // `Project::trim` writes it: with the in-point clamped at 0 the box + // below would slide left rather than stretch, and the release would + // then commit a wider clip than the drag drew. + Edge::Start + if self.session.as_ref().is_some_and(|session| { + session + .sources() + .get(clip.source) + .is_some_and(|s| engine::is_image(&s.path)) + }) => + { + Clip { + in_frame: 0, + out_frame: clip.end().saturating_sub(trim.to).max(1), + start: trim.to, + ..clip + } + } // The in-point follows the head, exactly as `Project::trim` moves // it: what stays on screen plays what it always played. Edge::Start => Clip { diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 9d1b789..6af1d62 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1658,8 +1658,19 @@ impl Project { } self.snapshot(); for (&(l, i), keep) in members.iter().zip(fitted) { + let still = self.is_still(&self.lanes[l].clips[i]); let c = &mut self.lanes[l].clips[i]; match edge { + // A still has no earlier frame to walk an in-point back to -- + // every frame of it is the same picture -- so its head grows + // *forward*: the range it plays is however long the new room + // is, anchored at the source's frame 0. Bounded by `lo`, which + // is where the cap in `source_frames` is applied. + Edge::Start if still => { + c.in_frame = 0; + c.out_frame = keep; + c.start = to; + } Edge::Start => { // Non-negative by `lo`, which is what keeps the in-point on // the source. @@ -1700,9 +1711,24 @@ impl Project { // head than the timeline has room for -- a ripple delete // slides a clip back to frame 0 with its in-point wherever // the cut left it -- and frame 0 is the other wall. - c.start - .saturating_sub(c.speed.room(c.in_frame)) - .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), + // + // A still is measured from its *tail* instead: it has no + // in-point worth the name (every frame the same picture), so + // its head reaches exactly as far as its tail does -- out to + // the length the caller's table gives it, whole. Measured + // from the in-point it would have no head room at all, which + // is a placed picture whose left edge cannot be dragged out. + // No entry in the table means no growth, as it does at the + // other end. + if self.is_still(&c) { + c.end().saturating_sub( + c.speed + .room(source_frames.get(c.source).copied().unwrap_or(c.len())), + ) + } else { + c.start.saturating_sub(c.speed.room(c.in_frame)) + } + .max(i.checked_sub(1).map_or(0, |p| clips[p].end())), // One *frame of clip* always survives, and at a rate below // real time one frame of clip is several frames of timeline // ([`Speed::room`]): an edge dragged closer than that would @@ -1739,6 +1765,16 @@ impl Project { Some((lo, hi.max(lo))) } + /// Whether `clip` plays a still image ([`crate::is_image`]): a file whose + /// every frame is the same picture, so which frame of it a clip's in-point + /// names is not a question -- what [`Project::trim`] lets grow at either + /// end. `false` for a source that is not there. + fn is_still(&self, clip: &Clip) -> bool { + self.sources + .get(clip.source) + .is_some_and(|s| crate::is_image(&s.path)) + } + /// The clips that move as one with the clip at `idx` of `lane` -- itself and /// whatever carries its link on the other lanes -- as `(lane storage index, /// clip index)` pairs. `None` for an index that is not there. @@ -3411,6 +3447,56 @@ mod tests { assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]); } + /// A still is trimmed from its head exactly as it is from its tail: it has + /// no earlier frame to walk an in-point back to, so the wall is the length + /// the caller's table allows it, measured back from the tail. Measured from + /// the in-point -- which a placed picture has at 0 -- its left edge could + /// never be dragged outwards at all. + #[test] + fn a_stills_head_stretches_out_like_its_tail() { + const STILL: &str = "/nonexistent/card.png"; + /// What a still is held to, as `PlaybackSession` fills the table in. + const CAP: &[u32] = &[60]; + + let mut p = Project::single(STILL, 20); + assert!(p.lift(Lane::A1, 0), "a picture is silent"); + assert!(p.lift(Lane::V1, 0), "and this one is not at frame 0"); + assert!(p.place(Lane::V1, 100, clip(0, 0, 20, 0))); + + // A source with no entry in the table may not grow, here as at the tail. + assert_eq!( + p.trim_room(Lane::V1, 0, Edge::Start, &[]), + Some((100, 119)), + "a length nobody told us buys no head room" + ); + assert_eq!( + p.trim_room(Lane::V1, 0, Edge::Start, CAP), + Some((60, 119)), + "back to a whole cap's worth, one frame of clip surviving" + ); + assert!(p.trim(Lane::V1, 0, Edge::Start, 80, CAP)); + assert_eq!( + shape(&p)[0][0], + clip(80, 0, 40, 0), + "twenty frames longer, and still read from the source's first frame" + ); + // Past the cap is clamped, exactly as the tail is -- not refused. + assert!(p.trim(Lane::V1, 0, Edge::Start, 0, CAP)); + assert_eq!(shape(&p)[0][0], clip(60, 0, 60, 0), "a cap's worth, no more"); + // ...and the clip in front is the nearer wall of the two: no head trim + // may open an overlap. + assert!(p.trim(Lane::V1, 0, Edge::Start, 90, CAP)); + assert!(p.place(Lane::V1, 70, clip(0, 0, 15, 0))); + assert_eq!( + p.trim_room(Lane::V1, 1, Edge::Start, CAP), + Some((85, 119)), + "up to the neighbour's last frame and not over it" + ); + assert!(p.trim(Lane::V1, 1, Edge::Start, 0, CAP)); + assert_eq!(shape(&p)[0][1], clip(85, 0, 35, 0), "butted against it"); + assert!(sorted_disjoint(p.lane(Lane::V1)), "no overlap"); + } + /// Linked halves trim as one: a link is one span on however many lanes, so /// the sound follows the picture's edge -- and the tightest wall of the two /// is what stops both. diff --git a/crates/engine/tests/images.rs b/crates/engine/tests/images.rs index aab2847..ba0d666 100644 --- a/crates/engine/tests/images.rs +++ b/crates/engine/tests/images.rs @@ -208,6 +208,25 @@ fn a_still_trims_out_to_its_cap_and_no_further() { // ...and back in, which is the half a five-second title card actually uses. assert!(session.trim_clip(Lane::V1, 0, Edge::End, clip.start + 60)); assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60); + + // The *head* is the same story from the other side: a still has no first + // frame to walk an in-point back to, so its left edge stretches out to the + // same cap. Pulled in first, since a clip at frame 0 has nowhere to go. + assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 20)); + let clip = session.lane_clips(Lane::V1)[0]; + assert_eq!((clip.start, clip.len()), (20, 40)); + assert_eq!( + session.trim_room(Lane::V1, 0, Edge::Start), + Some((0, clip.end() - 1)), + "out to frame 0: the cap is further off than the timeline reaches" + ); + assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 0), "dragged out"); + let clip = session.lane_clips(Lane::V1)[0]; + assert_eq!( + (clip.start, clip.in_frame, clip.len()), + (0, 0, 60), + "longer by what the head took, and still read from the first frame" + ); } /// The *clipboard* door, which is the second way a clip picks its lanes and