From 80b1d8238ecf4206a33b5f9ed14a4db2065f390e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 10 Sep 2026 00:51:47 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(bench):=20the=20drag=20lands?= =?UTF-8?q?=20where=20the=20hand=20aims=20=E2=80=94=20clamp,=20one=20thres?= =?UTF-8?q?hold,=20refused=20shadow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/app/src/player/timeline_edit.rs | 50 +++++++++--- crates/app/src/tests/editing.rs | 2 +- crates/app/src/tests/view.rs | 6 +- crates/app/src/timeline_math.rs | 101 ++++++++++++++++++++++++- crates/app/src/ui/bench_stance.rs | 4 +- 5 files changed, 145 insertions(+), 18 deletions(-) diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 000b348..3131334 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -887,12 +887,35 @@ impl Player { self.set_ghost(Vec::new(), cx); return; }; + // What the release would refuse: a lane of the other kind, and a head + // let go on top of a take already there ([`Project::move_selection`] + // changes nothing rather than overwrite one). Drawn as refused so a + // drop that will not happen is seen before the hand lets go, never as a + // silent no-op. The neighbours are the destination lane's clips less + // whatever travels with this one -- itself and its link group. + let neighbours: Vec<(u32, u32)> = self + .session + .as_ref() + .map(|session| { + session + .lane_clips(to) + .iter() + .enumerate() + .filter(|&(i, clip)| { + (to, i) != (drag.lane, idx) + && !(clip.link.is_some() && clip.link == drag.clip.link) + }) + .map(|(_, clip)| (clip.start, clip.end())) + .collect() + }) + .unwrap_or_default(); let anchor = Ghost { lane: to, start, frames: drag.clip.frames(), tint: self.clip_tint(drag.clip.source), - refused: drag.lane.kind != to.kind, + refused: drag.lane.kind != to.kind + || collides(start, drag.clip.frames(), &neighbours), }; let mut ghosts = vec![anchor]; if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 { @@ -1046,13 +1069,13 @@ impl Player { .flatten() }); let skip = skip.and_then(|(lane, idx)| Some((lanes.iter().position(|&l| l == lane)?, idx))); - snap_marks(&clips, skip, skip_link, frame_at(session.now(), self.fps)) - } - - /// Where a gesture at `raw` lands and the mark that pulled it there, with - /// the switch honoured: snapping off, nothing moves and no line is drawn. - pub(crate) fn snap_to(&self, raw: u32, len: u32, marks: &[u32]) -> (u32, Option) { - snap_cue(self.snap_live(), raw, len, self.snap_frames(), marks) + snap_marks( + &clips, + skip, + skip_link, + frame_at(session.now(), self.fps), + self.range, + ) } /// Every timeline frame that is a *source* sync point: each clip's own @@ -1459,7 +1482,16 @@ impl Player { // The edge is pulled onto the same marks a whole clip is, by itself: // there is no other end travelling with it, so it snaps at length zero. let marks = self.snap_targets(Some((trim.lane, trim.idx))); - let (at, cue) = self.snap_to(self.frame_under(x), 0, &marks); + // The same 10 px of aim a drop is given ([`DROP_SNAP_PX`]): one + // threshold for every gesture on this bed, so an edge and a whole clip + // grip a cut at the same distance from it. + let (at, cue) = snap_cue( + self.snap_live(), + self.frame_under(x), + 0, + self.drop_snap_frames(), + &marks, + ); let Some((lo, hi)) = self.session.as_ref().and_then(|session| { match trim.lane.kind == LaneKind::Subtitle { // The walls a caption's edge has -- its neighbour, its own diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 2e61258..d104c03 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -1670,7 +1670,7 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { // 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, None, frame_at(session.now(), fps)); + let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps), None); 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"); diff --git a/crates/app/src/tests/view.rs b/crates/app/src/tests/view.rs index d6face9..baa14b0 100644 --- a/crates/app/src/tests/view.rs +++ b/crates/app/src/tests/view.rs @@ -175,7 +175,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { let lanes: [&[Clip]; 2] = [&video, &audio]; // Nothing in the hand: both lanes' edges, the playhead, and 0. - let mut all = snap_marks(&lanes, None, None, 300); + let mut all = snap_marks(&lanes, None, None, 300, None); all.sort_unstable(); assert_eq!(all, [0, 100, 100, 160, 160, 300, 400, 430]); @@ -184,12 +184,12 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { // other lane -- both boxes travel with the drag. The lone audio clip is // still a target, which is the whole point: a take being carried on V1 // lands flush with a sound on A1. - let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300); + let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300, None); carried.sort_unstable(); assert_eq!(carried, [0, 300, 400, 430]); // An index that names no clip skips nothing and still answers. - assert_eq!(snap_marks(&[], Some((3, 9)), None, 0), [0, 0]); + assert_eq!(snap_marks(&[], Some((3, 9)), None, 0, None), [0, 0]); } /// The line the bed draws, and the switch that turns the whole thing off. diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 2446389..de6632b 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -583,6 +583,7 @@ pub(crate) fn snap_marks( skip: Option<(usize, usize)>, skip_link: Option, playhead: u32, + range: Option<(u32, u32)>, ) -> Vec { let mut marks: Vec = lanes .iter() @@ -599,6 +600,13 @@ pub(crate) fn snap_marks( .collect(); marks.push(playhead); marks.push(0); + // The in and out points ([`Player::range`]): a hand that has marked a + // stretch is working to it, and a clip meets its brackets as readily as it + // meets a cut. + if let Some((in_, out)) = range { + marks.push(in_); + marks.push(out); + } marks } @@ -653,6 +661,34 @@ pub(crate) fn landing( snap_cue(on, under.saturating_sub(grab), len, tol, marks) } +/// Whether a clip `len` frames long landing at `start` would sit on top of one +/// of `others` -- `(start, end)` of every clip already on the lane it is being +/// let go over, less the ones travelling with it. The engine refuses such a +/// drop ([`Project::move_selection`]'s `move_room`), so the shadow is drawn as +/// refused rather than promising a landing the release will not make: a drag +/// that ends in nothing at all is what an editor reads as a broken timeline. +/// +/// Touching is not overlapping -- a clip laid exactly against the take in front +/// of it is the whole point of the magnet. +pub(crate) fn collides(start: u32, len: u32, others: &[(u32, u32)]) -> bool { + let end = start.saturating_add(len); + others + .iter() + .any(|&(other_start, other_end)| start < other_end && other_start < end) +} + +/// The lane a release lands on when the pointer is off the rows themselves: +/// the row under it while its kind can hold what is in the hand, and otherwise +/// the last one that could -- a picture clip carried down across A1 on its way +/// to the empty bench below is still aiming at V1. [`Player::drag_lane`]'s +/// whole rule. +pub(crate) fn held_lane(prev: Option, over: Lane, from: Lane) -> Option { + match over.kind == from.kind { + true => Some(over), + false => prev, + } +} + /// Why this file may not go on that lane, in the words the refusal is told in -- /// `None` when it may. A file with no picture belongs on an audio lane and /// nowhere else, and a still is silent, so an audio lane is the one place it @@ -706,7 +742,7 @@ mod drop_landing_tests { /// missing mark. #[test] fn a_pull_near_the_head_of_an_empty_timeline_snaps_to_frame_0() { - let marks = snap_marks(&[&[]], None, None, 0); + let marks = snap_marks(&[&[]], None, None, 0, None); assert!(marks.contains(&0), "an empty timeline still offers frame 0"); assert_eq!(snapped(4, 0, 10, &marks), 0); // Outside the tolerance, the raw ask stands: this is a magnet, not a @@ -728,7 +764,7 @@ mod drop_landing_tests { /// where the timeline is parked. #[test] fn a_pull_near_the_playhead_snaps_onto_it() { - let marks = snap_marks(&[&[]], None, None, 500); + let marks = snap_marks(&[&[]], None, None, 500, None); assert!(marks.contains(&500)); assert_eq!(snapped(493, 0, 10, &marks), 500); } @@ -807,4 +843,65 @@ mod drop_landing_tests { // The switch off stays off however the modifier is held. assert!(!snap_live(false, false)); } + + /// Every target an NLE offers is on the list: frame 0, the playhead, both + /// edges of every clip on *every* lane, and the in/out brackets. + #[test] + fn the_targets_are_zero_the_playhead_the_edges_and_the_marks() { + let clip = |start: u32, frames: u32| Clip { + fade_in: 0, + fade_out: 0, + transition_out: 0, + start, + in_frame: 0, + out_frame: frames, + source: 0, + link: None, + eq: None, + color: None, + transform: None, + fit: Default::default(), + speed: Default::default(), + }; + let v1 = [clip(100, 50), clip(400, 50)]; + let a1 = [clip(700, 20)]; + let marks = snap_marks(&[&v1, &a1], None, None, 900, Some((250, 600))); + for want in [0, 900, 100, 150, 400, 450, 700, 720, 250, 600] { + assert!(marks.contains(&want), "{want} is not a snap target"); + } + // And each of them actually pulls a drag onto itself. + for target in [0, 250, 600, 900] { + assert_eq!(snapped(target + 4, 0, 10, &marks), target); + } + } + + /// A release on the empty bench below the last row, or left of the heads, + /// lands on the lane the last live sample was over -- and a lane of the + /// wrong kind crossed on the way down never steals it. + #[test] + fn the_last_lane_that_could_hold_it_keeps_the_drag() { + let v1 = Lane::V1; + let v2 = Lane::new(LaneKind::Video, 1); + let a1 = Lane::A1; + // The head column is part of the row, so the row over it is the answer. + assert_eq!(held_lane(None, v1, v1), Some(v1)); + assert_eq!(held_lane(Some(v1), v2, v1), Some(v2)); + assert_eq!(held_lane(Some(v2), a1, v1), Some(v2), "audio cannot hold it"); + // Nothing promised yet and nothing that can hold it: no landing. + assert_eq!(held_lane(None, a1, v1), None); + } + + /// The refused state the shadow draws: a head let go on top of a take + /// already on the lane, which the engine changes nothing for. Laid exactly + /// against one -- what the magnet is for -- is not a collision. + #[test] + fn a_landing_on_top_of_a_take_previews_as_refused() { + let others = [(100, 200), (400, 500)]; + assert!(collides(150, 50, &others), "inside the first take"); + assert!(collides(90, 50, &others), "its head laps the first take"); + assert!(collides(50, 400, &others), "long enough to swallow both"); + assert!(!collides(50, 50, &others), "tail meets the head exactly"); + assert!(!collides(200, 200, &others), "the gap holds it exactly"); + assert!(!collides(500, 10, &others), "past the last take"); + } } diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index 5d2efeb..8bcc236 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -932,9 +932,7 @@ fn lane_row( // clip dragged down across A1 on its way to the empty bench // below is still aiming at V1, and the catch-all release must // not hand it the audio lane that refused it on the way past. - if drag.lane.kind == lane.kind { - this.drag_lane = Some(lane); - } + this.drag_lane = held_lane(this.drag_lane, lane, drag.lane); this.drag_alt = event.event.modifiers.alt; this.preview_ghost(&drag, lane, event.event.position.x, cx); }),