forge
Explore
Log in

Don't you dare go Hollow

🔀 merge(T8): image left-edge stretch

Browse files at this commit

411875af918adc72b1af6a1ca595265208671219Ahmet Kaan GümüşParent: 88fbed0bbc3499
crates/app/src/main.rsmodified+19 -0
@@ -2018,6 +2018,25 @@ impl Player {
2018 return clip;2018 return clip;
2019 };2019 };
2020 match trim.edge {2020 match trim.edge {
2021+ // A still grows forward from source frame 0 instead, exactly as
2022+ // `Project::trim` writes it: with the in-point clamped at 0 the box
2023+ // below would slide left rather than stretch, and the release would
2024+ // then commit a wider clip than the drag drew.
2025+ Edge::Start
2026+ if self.session.as_ref().is_some_and(|session| {
2027+ session
2028+ .sources()
2029+ .get(clip.source)
2030+ .is_some_and(|s| engine::is_image(&s.path))
2031+ }) =>
2032+ {
2033+ Clip {
2034+ in_frame: 0,
2035+ out_frame: clip.end().saturating_sub(trim.to).max(1),
2036+ start: trim.to,
2037+ ..clip
2038+ }
2039+ }
2021 // The in-point follows the head, exactly as `Project::trim` moves2040 // The in-point follows the head, exactly as `Project::trim` moves
2022 // it: what stays on screen plays what it always played.2041 // it: what stays on screen plays what it always played.
2023 Edge::Start => Clip {2042 Edge::Start => Clip {
crates/engine/src/project.rsmodified+89 -3
@@ -1658,8 +1658,19 @@ impl Project {
1658 }1658 }
1659 self.snapshot();1659 self.snapshot();
1660 for (&(l, i), keep) in members.iter().zip(fitted) {1660 for (&(l, i), keep) in members.iter().zip(fitted) {
1661+ let still = self.is_still(&self.lanes[l].clips[i]);
1661 let c = &mut self.lanes[l].clips[i];1662 let c = &mut self.lanes[l].clips[i];
1662 match edge {1663 match edge {
1664+ // A still has no earlier frame to walk an in-point back to --
1665+ // every frame of it is the same picture -- so its head grows
1666+ // *forward*: the range it plays is however long the new room
1667+ // is, anchored at the source's frame 0. Bounded by `lo`, which
1668+ // is where the cap in `source_frames` is applied.
1669+ Edge::Start if still => {
1670+ c.in_frame = 0;
1671+ c.out_frame = keep;
1672+ c.start = to;
1673+ }
1663 Edge::Start => {1674 Edge::Start => {
1664 // Non-negative by `lo`, which is what keeps the in-point on1675 // Non-negative by `lo`, which is what keeps the in-point on
1665 // the source.1676 // the source.
@@ -1700,9 +1711,24 @@ impl Project {
1700 // head than the timeline has room for -- a ripple delete1711 // head than the timeline has room for -- a ripple delete
1701 // slides a clip back to frame 0 with its in-point wherever1712 // slides a clip back to frame 0 with its in-point wherever
1702 // the cut left it -- and frame 0 is the other wall.1713 // the cut left it -- and frame 0 is the other wall.
1703- c.start1714+ //
1704- .saturating_sub(c.speed.room(c.in_frame))1715+ // A still is measured from its *tail* instead: it has no
1705- .max(i.checked_sub(1).map_or(0, |p| clips[p].end())),1716+ // in-point worth the name (every frame the same picture), so
1717+ // its head reaches exactly as far as its tail does -- out to
1718+ // the length the caller's table gives it, whole. Measured
1719+ // from the in-point it would have no head room at all, which
1720+ // is a placed picture whose left edge cannot be dragged out.
1721+ // No entry in the table means no growth, as it does at the
1722+ // other end.
1723+ if self.is_still(&c) {
1724+ c.end().saturating_sub(
1725+ c.speed
1726+ .room(source_frames.get(c.source).copied().unwrap_or(c.len())),
1727+ )
1728+ } else {
1729+ c.start.saturating_sub(c.speed.room(c.in_frame))
1730+ }
1731+ .max(i.checked_sub(1).map_or(0, |p| clips[p].end())),
1706 // One *frame of clip* always survives, and at a rate below1732 // One *frame of clip* always survives, and at a rate below
1707 // real time one frame of clip is several frames of timeline1733 // real time one frame of clip is several frames of timeline
1708 // ([`Speed::room`]): an edge dragged closer than that would1734 // ([`Speed::room`]): an edge dragged closer than that would
@@ -1739,6 +1765,16 @@ impl Project {
1739 Some((lo, hi.max(lo)))1765 Some((lo, hi.max(lo)))
1740 }1766 }
1741 1767
1768+ /// Whether `clip` plays a still image ([`crate::is_image`]): a file whose
1769+ /// every frame is the same picture, so which frame of it a clip's in-point
1770+ /// names is not a question -- what [`Project::trim`] lets grow at either
1771+ /// end. `false` for a source that is not there.
1772+ fn is_still(&self, clip: &Clip) -> bool {
1773+ self.sources
1774+ .get(clip.source)
1775+ .is_some_and(|s| crate::is_image(&s.path))
1776+ }
1777+
1742 /// The clips that move as one with the clip at `idx` of `lane` -- itself and1778 /// The clips that move as one with the clip at `idx` of `lane` -- itself and
1743 /// whatever carries its link on the other lanes -- as `(lane storage index,1779 /// whatever carries its link on the other lanes -- as `(lane storage index,
1744 /// clip index)` pairs. `None` for an index that is not there.1780 /// clip index)` pairs. `None` for an index that is not there.
@@ -3411,6 +3447,56 @@ mod tests {
3411 assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]);3447 assert_eq!(shape(&p)[0], vec![clip(0, 5, 9, 0)]);
3412 }3448 }
3413 3449
3450+ /// A still is trimmed from its head exactly as it is from its tail: it has
3451+ /// no earlier frame to walk an in-point back to, so the wall is the length
3452+ /// the caller's table allows it, measured back from the tail. Measured from
3453+ /// the in-point -- which a placed picture has at 0 -- its left edge could
3454+ /// never be dragged outwards at all.
3455+ #[test]
3456+ fn a_stills_head_stretches_out_like_its_tail() {
3457+ const STILL: &str = "/nonexistent/card.png";
3458+ /// What a still is held to, as `PlaybackSession` fills the table in.
3459+ const CAP: &[u32] = &[60];
3460+
3461+ let mut p = Project::single(STILL, 20);
3462+ assert!(p.lift(Lane::A1, 0), "a picture is silent");
3463+ assert!(p.lift(Lane::V1, 0), "and this one is not at frame 0");
3464+ assert!(p.place(Lane::V1, 100, clip(0, 0, 20, 0)));
3465+
3466+ // A source with no entry in the table may not grow, here as at the tail.
3467+ assert_eq!(
3468+ p.trim_room(Lane::V1, 0, Edge::Start, &[]),
3469+ Some((100, 119)),
3470+ "a length nobody told us buys no head room"
3471+ );
3472+ assert_eq!(
3473+ p.trim_room(Lane::V1, 0, Edge::Start, CAP),
3474+ Some((60, 119)),
3475+ "back to a whole cap's worth, one frame of clip surviving"
3476+ );
3477+ assert!(p.trim(Lane::V1, 0, Edge::Start, 80, CAP));
3478+ assert_eq!(
3479+ shape(&p)[0][0],
3480+ clip(80, 0, 40, 0),
3481+ "twenty frames longer, and still read from the source's first frame"
3482+ );
3483+ // Past the cap is clamped, exactly as the tail is -- not refused.
3484+ assert!(p.trim(Lane::V1, 0, Edge::Start, 0, CAP));
3485+ assert_eq!(shape(&p)[0][0], clip(60, 0, 60, 0), "a cap's worth, no more");
3486+ // ...and the clip in front is the nearer wall of the two: no head trim
3487+ // may open an overlap.
3488+ assert!(p.trim(Lane::V1, 0, Edge::Start, 90, CAP));
3489+ assert!(p.place(Lane::V1, 70, clip(0, 0, 15, 0)));
3490+ assert_eq!(
3491+ p.trim_room(Lane::V1, 1, Edge::Start, CAP),
3492+ Some((85, 119)),
3493+ "up to the neighbour's last frame and not over it"
3494+ );
3495+ assert!(p.trim(Lane::V1, 1, Edge::Start, 0, CAP));
3496+ assert_eq!(shape(&p)[0][1], clip(85, 0, 35, 0), "butted against it");
3497+ assert!(sorted_disjoint(p.lane(Lane::V1)), "no overlap");
3498+ }
3499+
3414 /// Linked halves trim as one: a link is one span on however many lanes, so3500 /// Linked halves trim as one: a link is one span on however many lanes, so
3415 /// the sound follows the picture's edge -- and the tightest wall of the two3501 /// the sound follows the picture's edge -- and the tightest wall of the two
3416 /// is what stops both.3502 /// is what stops both.
crates/engine/tests/images.rsmodified+19 -0
@@ -208,6 +208,25 @@ fn a_still_trims_out_to_its_cap_and_no_further() {
208 // ...and back in, which is the half a five-second title card actually uses.208 // ...and back in, which is the half a five-second title card actually uses.
209 assert!(session.trim_clip(Lane::V1, 0, Edge::End, clip.start + 60));209 assert!(session.trim_clip(Lane::V1, 0, Edge::End, clip.start + 60));
210 assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60);210 assert_eq!(session.lane_clips(Lane::V1)[0].len(), 60);
211+
212+ // The *head* is the same story from the other side: a still has no first
213+ // frame to walk an in-point back to, so its left edge stretches out to the
214+ // same cap. Pulled in first, since a clip at frame 0 has nowhere to go.
215+ assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 20));
216+ let clip = session.lane_clips(Lane::V1)[0];
217+ assert_eq!((clip.start, clip.len()), (20, 40));
218+ assert_eq!(
219+ session.trim_room(Lane::V1, 0, Edge::Start),
220+ Some((0, clip.end() - 1)),
221+ "out to frame 0: the cap is further off than the timeline reaches"
222+ );
223+ assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 0), "dragged out");
224+ let clip = session.lane_clips(Lane::V1)[0];
225+ assert_eq!(
226+ (clip.start, clip.in_frame, clip.len()),
227+ (0, 0, 60),
228+ "longer by what the head took, and still read from the first frame"
229+ );
211 }230 }
212 231
213 /// The *clipboard* door, which is the second way a clip picks its lanes and232 /// The *clipboard* door, which is the second way a clip picks its lanes and