forge
Explore
Log in

Don't you dare go Hollow

A dropped row lands where the hand let it go, not after the last clip

Browse files at this commit

0d1c2c18ee469554f78230b7772d21250bfb75b0Ahmet Kaan GümüşParent: 9ebff59
  • fix
    • a dropped row lands where the hand let it go, not after the last clip
Show full message
🐛 fix(timeline): a dropped row lands where the hand let it go, not after the last clip

A library row dragged onto the open bed past the last clip was appended to
the end of the timeline wherever it was released: the ghost promised one
frame and the release committed another.

`Project::paste` clamped the frame it was asked for to `timeline_frames()`
-- the clipboard's rule ("put it here", never "here with black in front"),
imposed on every caller of the primitive. A drop names a place on the bed
and means it, and `Project::place` (the audio/further-lane half of the same
drop) already honoured one, so V1 was the odd lane out.

The clamp moves to the clipboard's own door, `PlaybackSession::paste_at`,
and the grouped branch of `place_stream_at` goes to `Project::paste`
directly with the frame the pointer named. Nothing else changes: a paste at
the playhead cannot be past the end anyway.

Pinned by `a_row_dropped_on_the_open_bed_lands_under_the_pointer`, which
walks the release's own chain -- `landing` as `place_frame` composes it,
the frame back through the rate as `insert_source` hands it over, and the
one engine door a row goes through -- and lands frame 300 where it used to
land 150.
crates/app/src/main.rsmodified+64 -0
@@ -12625,6 +12625,70 @@ mod tests {
12625 assert_eq!(session.file_frames(&path), frames);12625 assert_eq!(session.file_frames(&path), frames);
12626 }12626 }
12627 12627
12628+ /// The drop a hand actually makes: a library row let go on the *empty* bed
12629+ /// past the last clip, which is most of the bed on any timeline shorter
12630+ /// than the window. The whole chain the release runs, minus gpui's own
12631+ /// pointer read -- [`Player::place_frame`]'s [`landing`], the frame back
12632+ /// through the rate as [`Player::insert_source`] hands it over, and the one
12633+ /// engine door a row goes through -- and the head lands on the frame the
12634+ /// ghost was drawn on, black in front of it. It used to be swallowed by the
12635+ /// clipboard's clamp inside `Project::paste` and appended after the last
12636+ /// clip wherever it was let go, which is the bug this pins.
12637+ #[test]
12638+ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() {
12639+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
12640+ session.set_gain(0.0);
12641+ session.import(&asset("test_av2.mp4")).expect("av2 matches");
12642+ let second = session.sources()[1].path.clone();
12643+ let fps = session.meta().frame_rate;
12644+ assert_eq!(session.timeline_duration(), 5.0);
12645+ // 5 s of timeline on a bed 30 s wide: the open bed past the last clip
12646+ // is five sixths of it.
12647+ let bed: Bounds<Pixels> = Bounds {
12648+ origin: point(px(12.), px(400.)),
12649+ size: size(px(600.), px(LANE_H)),
12650+ };
12651+ let scale = Scale {
12652+ pps: 20.,
12653+ start: 0.,
12654+ };
12655+
12656+ // What `Player::place_frame` answers for a pointer 200 px along the
12657+ // bed: ten seconds in, five seconds past the end of the timeline, and
12658+ // no mark anywhere near enough to pull it back.
12659+ let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)];
12660+ let marks = snap_marks(&clips, None, frame_at(session.now(), fps));
12661+ let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps);
12662+ let (at, cue) = landing(under, 0, 0, true, scale.snap_frames(fps), &marks);
12663+ assert_eq!((at, cue), (300, None), "the pointer is on frame 300");
12664+
12665+ // ...and what the release does with it: the frame back through the same
12666+ // rate every box is drawn at, into the door the Add button uses too.
12667+ assert!(
12668+ session
12669+ .place_stream_at(f64::from(at) / fps, &second, 0, None)
12670+ .expect("av2 is already on this timeline")
12671+ );
12672+ let head = |lane| {
12673+ session
12674+ .lane_clips(lane)
12675+ .last()
12676+ .copied()
12677+ .expect("the dropped clip")
12678+ };
12679+ assert_eq!(
12680+ head(Lane::V1).start,
12681+ at,
12682+ "the drop landed somewhere other than under the pointer"
12683+ );
12684+ assert_eq!(head(Lane::A1).start, at, "...and its sound with it");
12685+ assert!(head(Lane::V1).link.is_some(), "one grouped take");
12686+ assert_eq!(head(Lane::V1).link, head(Lane::A1).link);
12687+ // The bed in front of it stays black: nothing was stretched to reach
12688+ // it, and the 4 s file is the whole of what was added.
12689+ assert_eq!(session.timeline_duration(), 14.0);
12690+ }
12691+
12628 /// Remove from library, through the door the menu item uses12692 /// Remove from library, through the door the menu item uses
12629 /// ([`Player::remove_source`] calls exactly this): refused by name while12693 /// ([`Player::remove_source`] calls exactly this): refused by name while
12630 /// clips play from the file, and once they do not the row leaves the list.12694 /// clips play from the file, and once they do not the row leaves the list.
crates/engine/src/playback.rsmodified+14 -2
@@ -1720,7 +1720,12 @@ impl PlaybackSession {
1720 /// delete this moves every following frame, so the session reseeks; past1720 /// delete this moves every following frame, so the session reseeks; past
1721 /// the end of the timeline the clip is appended. One undo step.1721 /// the end of the timeline the clip is appended. One undo step.
1722 pub fn paste_at(&mut self, timeline_secs: f64, clip: Clip) -> bool {1722 pub fn paste_at(&mut self, timeline_secs: f64, clip: Clip) -> bool {
1723- let at = secs_to_frame(timeline_secs, self.meta.frame_rate);1723+ // The clipboard's own rule, and only the clipboard's: a paste past the
1724+ // end is an append, never a clip with black in front of it. The frame
1725+ // itself is honoured in [`Project::paste`], because a *drop* names a
1726+ // place on the bed and means it.
1727+ let at = secs_to_frame(timeline_secs, self.meta.frame_rate)
1728+ .min(self.project.timeline_frames());
1724 self.edit(Dirty::Both, |p| p.paste(at, clip))1729 self.edit(Dirty::Both, |p| p.paste(at, clip))
1725 }1730 }
1726 1731
@@ -1823,7 +1828,14 @@ impl PlaybackSession {
1823 };1828 };
1824 Ok(match onto {1829 Ok(match onto {
1825 Some(lane) => self.place_at(lane, timeline_secs, clip),1830 Some(lane) => self.place_at(lane, timeline_secs, clip),
1826- None => self.paste_at(timeline_secs, clip),1831+ // The grouped take, at the frame it was let go on -- past the last
1832+ // clip included, where the bed is black and the ghost was drawn.
1833+ // Not [`Self::paste_at`]: that door clamps to the end for the
1834+ // clipboard, and a drop that named a place is not a paste.
1835+ None => {
1836+ let at = secs_to_frame(timeline_secs, self.meta.frame_rate);
1837+ self.edit(Dirty::Both, |p| p.paste(at, clip))
1838+ }
1827 })1839 })
1828 }1840 }
1829 1841
crates/engine/src/project.rsmodified+19 -7
@@ -2253,9 +2253,12 @@ impl Project {
2253 /// Insert `clip` into the first lane of each kind at `timeline_frame` as one2253 /// Insert `clip` into the first lane of each kind at `timeline_frame` as one
2254 /// new group, pushing everything from there on later by its length in2254 /// new group, pushing everything from there on later by its length in
2255 /// *every* lane -- the grouped, rippling paste a clipboard does. Mid-clip2255 /// *every* lane -- the grouped, rippling paste a clipboard does. Mid-clip
2256- /// the clip it lands in is split around it; at or past the end of the2256+ /// the clip it lands in is split around it; past the end of the timeline it
2257- /// timeline it is appended, because a paste means "put it here", not "put it2257+ /// goes down where it was asked for, with black in front of it -- which is
2258- /// here and leave black in front".2258+ /// what a library row let go on the open bed means, and what the ghost under
2259+ /// the pointer promised. A clipboard means "put it here", not "here and
2260+ /// black in front", and clamps to the end at its own door
2261+ /// ([`crate::PlaybackSession::paste_at`]).
2259 /// Use [`place`](Project::place) to paste into one lane, or to make a gap.2262 /// Use [`place`](Project::place) to paste into one lane, or to make a gap.
2260 ///2263 ///
2261 /// `V1` and `A1` and no other lane, because a take is one picture and one2264 /// `V1` and `A1` and no other lane, because a take is one picture and one
@@ -2287,7 +2290,12 @@ impl Project {
2287 // worker tries to demux -- which silences the *whole session*, not just2290 // worker tries to demux -- which silences the *whole session*, not just
2288 // that clip -- and a save the engine's own `open_project` then refuses.2291 // that clip -- and a save the engine's own `open_project` then refuses.
2289 let picture_only = crate::is_image(&source.path);2292 let picture_only = crate::is_image(&source.path);
2290- let at = timeline_frame.min(self.timeline_frames());2293+ // The frame it was asked for and no other: a row let go on the empty
2294+ // bed past the last clip lands *there*, under the ghost that promised
2295+ // it, with black in front. Clamping to the end here made every drop on
2296+ // open bed an append -- the clipboard's rule, applied to a hand that
2297+ // had named a place.
2298+ let at = timeline_frame;
2291 // The room it takes on the timeline, which its speed decides -- not the2299 // The room it takes on the timeline, which its speed decides -- not the
2292 // source range it reads.2300 // source range it reads.
2293 let len = clip.frames();2301 let len = clip.frames();
@@ -3510,13 +3518,17 @@ mod tests {
3510 assert_eq!(p.map_timeline(0), Some((0, 100)));3518 assert_eq!(p.map_timeline(0), Some((0, 100)));
3511 assert_eq!(p.map_timeline(2), Some((1, 0)));3519 assert_eq!(p.map_timeline(2), Some((1, 0)));
3512 3520
3513- // At the end and past it both append -- a paste never leaves black in3521+ // At the end: appended, there being nothing in front to leave black.
3514- // front of itself; `place` is the call that makes a gap.
3515 let mut p = three();3522 let mut p = three();
3516 assert!(p.paste(9, PASTED));3523 assert!(p.paste(9, PASTED));
3517 assert_eq!(p.clip_spans(), vec![(0, 3), (3, 2), (5, 4), (9, 2)]);3524 assert_eq!(p.clip_spans(), vec![(0, 3), (3, 2), (5, 4), (9, 2)]);
3525+ // Past it: down on the frame it was asked for, black in front of it --
3526+ // a row let go on the open bed lands under the ghost that promised it.
3527+ // The clipboard's clamp lives in `PlaybackSession::paste_at`.
3518 assert!(p.paste(1_000, PASTED));3528 assert!(p.paste(1_000, PASTED));
3519- assert_eq!(p.timeline_frames(), 13);3529+ assert_eq!(p.timeline_frames(), 1_002);
3530+ assert_eq!(p.lane(Lane::V1).last().expect("the pasted clip").start, 1_000);
3531+ assert_eq!(p.lane(Lane::A1).last().expect("its other half").start, 1_000);
3520 3532
3521 // An empty clip is the one thing refused, and it pushes no history.3533 // An empty clip is the one thing refused, and it pushes no history.
3522 let mut p = three();3534 let mut p = three();