diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 5fa1fa7..be2e8e2 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -12625,6 +12625,70 @@ mod tests { assert_eq!(session.file_frames(&path), frames); } + /// The drop a hand actually makes: a library row let go on the *empty* bed + /// past the last clip, which is most of the bed on any timeline shorter + /// than the window. The whole chain the release runs, minus gpui's own + /// pointer read -- [`Player::place_frame`]'s [`landing`], the frame back + /// through the rate as [`Player::insert_source`] hands it over, and the one + /// engine door a row goes through -- and the head lands on the frame the + /// ghost was drawn on, black in front of it. It used to be swallowed by the + /// clipboard's clamp inside `Project::paste` and appended after the last + /// clip wherever it was let go, which is the bug this pins. + #[test] + fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); + session.set_gain(0.0); + session.import(&asset("test_av2.mp4")).expect("av2 matches"); + let second = session.sources()[1].path.clone(); + let fps = session.meta().frame_rate; + assert_eq!(session.timeline_duration(), 5.0); + // 5 s of timeline on a bed 30 s wide: the open bed past the last clip + // is five sixths of it. + let bed: Bounds = Bounds { + origin: point(px(12.), px(400.)), + size: size(px(600.), px(LANE_H)), + }; + let scale = Scale { + pps: 20., + start: 0., + }; + + // What `Player::place_frame` answers for a pointer 200 px along the + // bed: ten seconds in, five seconds past the end of the timeline, and + // no mark anywhere near enough to pull it back. + let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)]; + let marks = snap_marks(&clips, None, frame_at(session.now(), fps)); + let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps); + let (at, cue) = landing(under, 0, 0, true, scale.snap_frames(fps), &marks); + assert_eq!((at, cue), (300, None), "the pointer is on frame 300"); + + // ...and what the release does with it: the frame back through the same + // rate every box is drawn at, into the door the Add button uses too. + assert!( + session + .place_stream_at(f64::from(at) / fps, &second, 0, None) + .expect("av2 is already on this timeline") + ); + let head = |lane| { + session + .lane_clips(lane) + .last() + .copied() + .expect("the dropped clip") + }; + assert_eq!( + head(Lane::V1).start, + at, + "the drop landed somewhere other than under the pointer" + ); + assert_eq!(head(Lane::A1).start, at, "...and its sound with it"); + assert!(head(Lane::V1).link.is_some(), "one grouped take"); + assert_eq!(head(Lane::V1).link, head(Lane::A1).link); + // The bed in front of it stays black: nothing was stretched to reach + // it, and the 4 s file is the whole of what was added. + assert_eq!(session.timeline_duration(), 14.0); + } + /// Remove from library, through the door the menu item uses /// ([`Player::remove_source`] calls exactly this): refused by name while /// clips play from the file, and once they do not the row leaves the list. diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 002f3d2..645dd62 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -1720,7 +1720,12 @@ impl PlaybackSession { /// delete this moves every following frame, so the session reseeks; past /// the end of the timeline the clip is appended. One undo step. pub fn paste_at(&mut self, timeline_secs: f64, clip: Clip) -> bool { - let at = secs_to_frame(timeline_secs, self.meta.frame_rate); + // The clipboard's own rule, and only the clipboard's: a paste past the + // end is an append, never a clip with black in front of it. The frame + // itself is honoured in [`Project::paste`], because a *drop* names a + // place on the bed and means it. + let at = secs_to_frame(timeline_secs, self.meta.frame_rate) + .min(self.project.timeline_frames()); self.edit(Dirty::Both, |p| p.paste(at, clip)) } @@ -1823,7 +1828,14 @@ impl PlaybackSession { }; Ok(match onto { Some(lane) => self.place_at(lane, timeline_secs, clip), - None => self.paste_at(timeline_secs, clip), + // The grouped take, at the frame it was let go on -- past the last + // clip included, where the bed is black and the ghost was drawn. + // Not [`Self::paste_at`]: that door clamps to the end for the + // clipboard, and a drop that named a place is not a paste. + None => { + let at = secs_to_frame(timeline_secs, self.meta.frame_rate); + self.edit(Dirty::Both, |p| p.paste(at, clip)) + } }) } diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 48e45d4..381f66c 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -2253,9 +2253,12 @@ impl Project { /// Insert `clip` into the first lane of each kind at `timeline_frame` as one /// new group, pushing everything from there on later by its length in /// *every* lane -- the grouped, rippling paste a clipboard does. Mid-clip - /// the clip it lands in is split around it; at or past the end of the - /// timeline it is appended, because a paste means "put it here", not "put it - /// here and leave black in front". + /// the clip it lands in is split around it; past the end of the timeline it + /// goes down where it was asked for, with black in front of it -- which is + /// what a library row let go on the open bed means, and what the ghost under + /// the pointer promised. A clipboard means "put it here", not "here and + /// black in front", and clamps to the end at its own door + /// ([`crate::PlaybackSession::paste_at`]). /// Use [`place`](Project::place) to paste into one lane, or to make a gap. /// /// `V1` and `A1` and no other lane, because a take is one picture and one @@ -2287,7 +2290,12 @@ impl Project { // worker tries to demux -- which silences the *whole session*, not just // that clip -- and a save the engine's own `open_project` then refuses. let picture_only = crate::is_image(&source.path); - let at = timeline_frame.min(self.timeline_frames()); + // The frame it was asked for and no other: a row let go on the empty + // bed past the last clip lands *there*, under the ghost that promised + // it, with black in front. Clamping to the end here made every drop on + // open bed an append -- the clipboard's rule, applied to a hand that + // had named a place. + let at = timeline_frame; // The room it takes on the timeline, which its speed decides -- not the // source range it reads. let len = clip.frames(); @@ -3510,13 +3518,17 @@ mod tests { assert_eq!(p.map_timeline(0), Some((0, 100))); assert_eq!(p.map_timeline(2), Some((1, 0))); - // At the end and past it both append -- a paste never leaves black in - // front of itself; `place` is the call that makes a gap. + // At the end: appended, there being nothing in front to leave black. let mut p = three(); assert!(p.paste(9, PASTED)); assert_eq!(p.clip_spans(), vec![(0, 3), (3, 2), (5, 4), (9, 2)]); + // Past it: down on the frame it was asked for, black in front of it -- + // a row let go on the open bed lands under the ghost that promised it. + // The clipboard's clamp lives in `PlaybackSession::paste_at`. assert!(p.paste(1_000, PASTED)); - assert_eq!(p.timeline_frames(), 13); + assert_eq!(p.timeline_frames(), 1_002); + assert_eq!(p.lane(Lane::V1).last().expect("the pasted clip").start, 1_000); + assert_eq!(p.lane(Lane::A1).last().expect("its other half").start, 1_000); // An empty clip is the one thing refused, and it pushes no history. let mut p = three();