forge
Explore
Log in

Don't you dare go Hollow

The drag lands where the hand aims — clamp, one threshold, refused shadow

Browse files at this commit

80b1d8238ecf4206a33b5f9ed14a4db2065f390eAhmet Kaan GümüşParent: a35a1ff
  • feat
    • the drag lands where the hand aims — clamp, one threshold, refused shadow
Show full message
✨ feat(bench): the drag lands where the hand aims — clamp, one threshold, refused shadow
crates/app/src/player/timeline_edit.rsmodified+41 -9
@@ -887,12 +887,35 @@ impl Player {
887 self.set_ghost(Vec::new(), cx);887 self.set_ghost(Vec::new(), cx);
888 return;888 return;
889 };889 };
890+ // What the release would refuse: a lane of the other kind, and a head
891+ // let go on top of a take already there ([`Project::move_selection`]
892+ // changes nothing rather than overwrite one). Drawn as refused so a
893+ // drop that will not happen is seen before the hand lets go, never as a
894+ // silent no-op. The neighbours are the destination lane's clips less
895+ // whatever travels with this one -- itself and its link group.
896+ let neighbours: Vec<(u32, u32)> = self
897+ .session
898+ .as_ref()
899+ .map(|session| {
900+ session
901+ .lane_clips(to)
902+ .iter()
903+ .enumerate()
904+ .filter(|&(i, clip)| {
905+ (to, i) != (drag.lane, idx)
906+ && !(clip.link.is_some() && clip.link == drag.clip.link)
907+ })
908+ .map(|(_, clip)| (clip.start, clip.end()))
909+ .collect()
910+ })
911+ .unwrap_or_default();
890 let anchor = Ghost {912 let anchor = Ghost {
891 lane: to,913 lane: to,
892 start,914 start,
893 frames: drag.clip.frames(),915 frames: drag.clip.frames(),
894 tint: self.clip_tint(drag.clip.source),916 tint: self.clip_tint(drag.clip.source),
895- refused: drag.lane.kind != to.kind,917+ refused: drag.lane.kind != to.kind
918+ || collides(start, drag.clip.frames(), &neighbours),
896 };919 };
897 let mut ghosts = vec![anchor];920 let mut ghosts = vec![anchor];
898 if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 {921 if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 {
@@ -1046,13 +1069,13 @@ impl Player {
1046 .flatten()1069 .flatten()
1047 });1070 });
1048 let skip = skip.and_then(|(lane, idx)| Some((lanes.iter().position(|&l| l == lane)?, idx)));1071 let skip = skip.and_then(|(lane, idx)| Some((lanes.iter().position(|&l| l == lane)?, idx)));
1049- snap_marks(&clips, skip, skip_link, frame_at(session.now(), self.fps))1072+ snap_marks(
1050- }1073+ &clips,
1051-1074+ skip,
1052- /// Where a gesture at `raw` lands and the mark that pulled it there, with1075+ skip_link,
1053- /// the switch honoured: snapping off, nothing moves and no line is drawn.1076+ frame_at(session.now(), self.fps),
1054- pub(crate) fn snap_to(&self, raw: u32, len: u32, marks: &[u32]) -> (u32, Option<u32>) {1077+ self.range,
1055- snap_cue(self.snap_live(), raw, len, self.snap_frames(), marks)1078+ )
1056 }1079 }
1057 1080
1058 /// Every timeline frame that is a *source* sync point: each clip's own1081 /// Every timeline frame that is a *source* sync point: each clip's own
@@ -1459,7 +1482,16 @@ impl Player {
1459 // The edge is pulled onto the same marks a whole clip is, by itself:1482 // The edge is pulled onto the same marks a whole clip is, by itself:
1460 // there is no other end travelling with it, so it snaps at length zero.1483 // there is no other end travelling with it, so it snaps at length zero.
1461 let marks = self.snap_targets(Some((trim.lane, trim.idx)));1484 let marks = self.snap_targets(Some((trim.lane, trim.idx)));
1462- let (at, cue) = self.snap_to(self.frame_under(x), 0, &marks);1485+ // The same 10 px of aim a drop is given ([`DROP_SNAP_PX`]): one
1486+ // threshold for every gesture on this bed, so an edge and a whole clip
1487+ // grip a cut at the same distance from it.
1488+ let (at, cue) = snap_cue(
1489+ self.snap_live(),
1490+ self.frame_under(x),
1491+ 0,
1492+ self.drop_snap_frames(),
1493+ &marks,
1494+ );
1463 let Some((lo, hi)) = self.session.as_ref().and_then(|session| {1495 let Some((lo, hi)) = self.session.as_ref().and_then(|session| {
1464 match trim.lane.kind == LaneKind::Subtitle {1496 match trim.lane.kind == LaneKind::Subtitle {
1465 // The walls a caption's edge has -- its neighbour, its own1497 // The walls a caption's edge has -- its neighbour, its own
crates/app/src/tests/editing.rsmodified+1 -1
@@ -1670,7 +1670,7 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() {
1670 // bed: ten seconds in, five seconds past the end of the timeline, and1670 // bed: ten seconds in, five seconds past the end of the timeline, and
1671 // no mark anywhere near enough to pull it back.1671 // no mark anywhere near enough to pull it back.
1672 let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)];1672 let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)];
1673- let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps));1673+ let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps), None);
1674 let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps);1674 let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps);
1675 let (at, cue) = landing(under, 0, 0, true, scale.snap_frames(fps), &marks);1675 let (at, cue) = landing(under, 0, 0, true, scale.snap_frames(fps), &marks);
1676 assert_eq!((at, cue), (300, None), "the pointer is on frame 300");1676 assert_eq!((at, cue), (300, None), "the pointer is on frame 300");
crates/app/src/tests/view.rsmodified+3 -3
@@ -175,7 +175,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() {
175 let lanes: [&[Clip]; 2] = [&video, &audio];175 let lanes: [&[Clip]; 2] = [&video, &audio];
176 176
177 // Nothing in the hand: both lanes' edges, the playhead, and 0.177 // Nothing in the hand: both lanes' edges, the playhead, and 0.
178- let mut all = snap_marks(&lanes, None, None, 300);178+ let mut all = snap_marks(&lanes, None, None, 300, None);
179 all.sort_unstable();179 all.sort_unstable();
180 assert_eq!(all, [0, 100, 100, 160, 160, 300, 400, 430]);180 assert_eq!(all, [0, 100, 100, 160, 160, 300, 400, 430]);
181 181
@@ -184,12 +184,12 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() {
184 // other lane -- both boxes travel with the drag. The lone audio clip is184 // other lane -- both boxes travel with the drag. The lone audio clip is
185 // still a target, which is the whole point: a take being carried on V1185 // still a target, which is the whole point: a take being carried on V1
186 // lands flush with a sound on A1.186 // lands flush with a sound on A1.
187- let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300);187+ let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300, None);
188 carried.sort_unstable();188 carried.sort_unstable();
189 assert_eq!(carried, [0, 300, 400, 430]);189 assert_eq!(carried, [0, 300, 400, 430]);
190 190
191 // An index that names no clip skips nothing and still answers.191 // An index that names no clip skips nothing and still answers.
192- assert_eq!(snap_marks(&[], Some((3, 9)), None, 0), [0, 0]);192+ assert_eq!(snap_marks(&[], Some((3, 9)), None, 0, None), [0, 0]);
193 }193 }
194 194
195 /// The line the bed draws, and the switch that turns the whole thing off.195 /// The line the bed draws, and the switch that turns the whole thing off.
crates/app/src/timeline_math.rsmodified+99 -2
@@ -583,6 +583,7 @@ pub(crate) fn snap_marks(
583 skip: Option<(usize, usize)>,583 skip: Option<(usize, usize)>,
584 skip_link: Option<u32>,584 skip_link: Option<u32>,
585 playhead: u32,585 playhead: u32,
586+ range: Option<(u32, u32)>,
586 ) -> Vec<u32> {587 ) -> Vec<u32> {
587 let mut marks: Vec<u32> = lanes588 let mut marks: Vec<u32> = lanes
588 .iter()589 .iter()
@@ -599,6 +600,13 @@ pub(crate) fn snap_marks(
599 .collect();600 .collect();
600 marks.push(playhead);601 marks.push(playhead);
601 marks.push(0);602 marks.push(0);
603+ // The in and out points ([`Player::range`]): a hand that has marked a
604+ // stretch is working to it, and a clip meets its brackets as readily as it
605+ // meets a cut.
606+ if let Some((in_, out)) = range {
607+ marks.push(in_);
608+ marks.push(out);
609+ }
602 marks610 marks
603 }611 }
604 612
@@ -653,6 +661,34 @@ pub(crate) fn landing(
653 snap_cue(on, under.saturating_sub(grab), len, tol, marks)661 snap_cue(on, under.saturating_sub(grab), len, tol, marks)
654 }662 }
655 663
664+/// Whether a clip `len` frames long landing at `start` would sit on top of one
665+/// of `others` -- `(start, end)` of every clip already on the lane it is being
666+/// let go over, less the ones travelling with it. The engine refuses such a
667+/// drop ([`Project::move_selection`]'s `move_room`), so the shadow is drawn as
668+/// refused rather than promising a landing the release will not make: a drag
669+/// that ends in nothing at all is what an editor reads as a broken timeline.
670+///
671+/// Touching is not overlapping -- a clip laid exactly against the take in front
672+/// of it is the whole point of the magnet.
673+pub(crate) fn collides(start: u32, len: u32, others: &[(u32, u32)]) -> bool {
674+ let end = start.saturating_add(len);
675+ others
676+ .iter()
677+ .any(|&(other_start, other_end)| start < other_end && other_start < end)
678+}
679+
680+/// The lane a release lands on when the pointer is off the rows themselves:
681+/// the row under it while its kind can hold what is in the hand, and otherwise
682+/// the last one that could -- a picture clip carried down across A1 on its way
683+/// to the empty bench below is still aiming at V1. [`Player::drag_lane`]'s
684+/// whole rule.
685+pub(crate) fn held_lane(prev: Option<Lane>, over: Lane, from: Lane) -> Option<Lane> {
686+ match over.kind == from.kind {
687+ true => Some(over),
688+ false => prev,
689+ }
690+}
691+
656 /// Why this file may not go on that lane, in the words the refusal is told in --692 /// Why this file may not go on that lane, in the words the refusal is told in --
657 /// `None` when it may. A file with no picture belongs on an audio lane and693 /// `None` when it may. A file with no picture belongs on an audio lane and
658 /// nowhere else, and a still is silent, so an audio lane is the one place it694 /// nowhere else, and a still is silent, so an audio lane is the one place it
@@ -706,7 +742,7 @@ mod drop_landing_tests {
706 /// missing mark.742 /// missing mark.
707 #[test]743 #[test]
708 fn a_pull_near_the_head_of_an_empty_timeline_snaps_to_frame_0() {744 fn a_pull_near_the_head_of_an_empty_timeline_snaps_to_frame_0() {
709- let marks = snap_marks(&[&[]], None, None, 0);745+ let marks = snap_marks(&[&[]], None, None, 0, None);
710 assert!(marks.contains(&0), "an empty timeline still offers frame 0");746 assert!(marks.contains(&0), "an empty timeline still offers frame 0");
711 assert_eq!(snapped(4, 0, 10, &marks), 0);747 assert_eq!(snapped(4, 0, 10, &marks), 0);
712 // Outside the tolerance, the raw ask stands: this is a magnet, not a748 // Outside the tolerance, the raw ask stands: this is a magnet, not a
@@ -728,7 +764,7 @@ mod drop_landing_tests {
728 /// where the timeline is parked.764 /// where the timeline is parked.
729 #[test]765 #[test]
730 fn a_pull_near_the_playhead_snaps_onto_it() {766 fn a_pull_near_the_playhead_snaps_onto_it() {
731- let marks = snap_marks(&[&[]], None, None, 500);767+ let marks = snap_marks(&[&[]], None, None, 500, None);
732 assert!(marks.contains(&500));768 assert!(marks.contains(&500));
733 assert_eq!(snapped(493, 0, 10, &marks), 500);769 assert_eq!(snapped(493, 0, 10, &marks), 500);
734 }770 }
@@ -807,4 +843,65 @@ mod drop_landing_tests {
807 // The switch off stays off however the modifier is held.843 // The switch off stays off however the modifier is held.
808 assert!(!snap_live(false, false));844 assert!(!snap_live(false, false));
809 }845 }
846+
847+ /// Every target an NLE offers is on the list: frame 0, the playhead, both
848+ /// edges of every clip on *every* lane, and the in/out brackets.
849+ #[test]
850+ fn the_targets_are_zero_the_playhead_the_edges_and_the_marks() {
851+ let clip = |start: u32, frames: u32| Clip {
852+ fade_in: 0,
853+ fade_out: 0,
854+ transition_out: 0,
855+ start,
856+ in_frame: 0,
857+ out_frame: frames,
858+ source: 0,
859+ link: None,
860+ eq: None,
861+ color: None,
862+ transform: None,
863+ fit: Default::default(),
864+ speed: Default::default(),
865+ };
866+ let v1 = [clip(100, 50), clip(400, 50)];
867+ let a1 = [clip(700, 20)];
868+ let marks = snap_marks(&[&v1, &a1], None, None, 900, Some((250, 600)));
869+ for want in [0, 900, 100, 150, 400, 450, 700, 720, 250, 600] {
870+ assert!(marks.contains(&want), "{want} is not a snap target");
871+ }
872+ // And each of them actually pulls a drag onto itself.
873+ for target in [0, 250, 600, 900] {
874+ assert_eq!(snapped(target + 4, 0, 10, &marks), target);
875+ }
876+ }
877+
878+ /// A release on the empty bench below the last row, or left of the heads,
879+ /// lands on the lane the last live sample was over -- and a lane of the
880+ /// wrong kind crossed on the way down never steals it.
881+ #[test]
882+ fn the_last_lane_that_could_hold_it_keeps_the_drag() {
883+ let v1 = Lane::V1;
884+ let v2 = Lane::new(LaneKind::Video, 1);
885+ let a1 = Lane::A1;
886+ // The head column is part of the row, so the row over it is the answer.
887+ assert_eq!(held_lane(None, v1, v1), Some(v1));
888+ assert_eq!(held_lane(Some(v1), v2, v1), Some(v2));
889+ assert_eq!(held_lane(Some(v2), a1, v1), Some(v2), "audio cannot hold it");
890+ // Nothing promised yet and nothing that can hold it: no landing.
891+ assert_eq!(held_lane(None, a1, v1), None);
892+ }
893+
894+ /// The refused state the shadow draws: a head let go on top of a take
895+ /// already on the lane, which the engine changes nothing for. Laid exactly
896+ /// against one -- what the magnet is for -- is not a collision.
897+ #[test]
898+ fn a_landing_on_top_of_a_take_previews_as_refused() {
899+ let others = [(100, 200), (400, 500)];
900+ assert!(collides(150, 50, &others), "inside the first take");
901+ assert!(collides(90, 50, &others), "its head laps the first take");
902+ assert!(collides(50, 400, &others), "long enough to swallow both");
903+ assert!(!collides(50, 50, &others), "tail meets the head exactly");
904+ assert!(!collides(200, 200, &others), "the gap holds it exactly");
905+ assert!(!collides(500, 10, &others), "past the last take");
906+ }
810 }907 }
crates/app/src/ui/bench_stance.rsmodified+1 -3
@@ -932,9 +932,7 @@ fn lane_row(
932 // clip dragged down across A1 on its way to the empty bench932 // clip dragged down across A1 on its way to the empty bench
933 // below is still aiming at V1, and the catch-all release must933 // below is still aiming at V1, and the catch-all release must
934 // not hand it the audio lane that refused it on the way past.934 // not hand it the audio lane that refused it on the way past.
935- if drag.lane.kind == lane.kind {935+ this.drag_lane = held_lane(this.drag_lane, lane, drag.lane);
936- this.drag_lane = Some(lane);
937- }
938 this.drag_alt = event.event.modifiers.alt;936 this.drag_alt = event.event.modifiers.alt;
939 this.preview_ghost(&drag, lane, event.event.position.x, cx);937 this.preview_ghost(&drag, lane, event.event.position.x, cx);
940 }),938 }),