diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index eae9b79..8aa934f 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -333,6 +333,14 @@ struct Player { /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement /// no magnet may take away. snap: bool, + /// Whether `alt` was down on the last sample of the gesture in flight: + /// snapping off for *this* drag only, the override every NLE has for the + /// one clip that has to sit a frame off an edge, leaving [`Player::snap`] + /// -- the switch -- exactly as the hand left it. Read by + /// [`Player::snap_live`], written by the bench's own drag samples and by + /// the trim's, and stale between gestures, which costs nothing: every + /// gesture writes it before it asks. + drag_alt: bool, /// Whether the subtitle lanes draw at all -- the mute over the shown lane /// ([`Player::sub_lane`]), not a lane of its own. On by default and off by /// one stroke @@ -398,6 +406,12 @@ struct Player { /// the pointer is not guaranteed to answer what the ghost just showed /// (DESIGN: "drop == shadow, by construction"). `None` between drags. drag_x: Option, + /// The lane the last live sample of the drag in flight was over -- the one + /// a release off the rows themselves (left of the heads, between two rows, + /// below the last track) lands on, so a gesture that has already promised a + /// landing in the shadow cannot end in nothing. `None` before the pointer + /// has been over any lane, where there is no landing to promise. + drag_lane: Option, /// The slot a track header being dragged is about to drop into, or `None` /// while the pointer is over no lane: the line drawn between two headers, /// for the reason [`Player::ghost`] draws a shadow -- where a gesture lands @@ -928,6 +942,7 @@ fn main() { fade_drag: None, grab: 0, snap: true, + drag_alt: false, subs_on: true, sub_track: 0, sub_folded: HashSet::new(), @@ -935,6 +950,7 @@ fn main() { snap_cue: None, ghost: Vec::new(), drag_x: None, + drag_lane: None, lane_drop: None, last_scrub: Instant::now(), last_target: 0, diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index f99b977..000b348 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -751,7 +751,7 @@ impl Player { self.frame_under(x), self.grab, sub.frames, - self.snap, + self.snap_live(), self.drop_snap_frames(), &marks, ) @@ -824,7 +824,7 @@ impl Player { self.frame_under(x), self.grab, clip.frames(), - self.snap, + self.snap_live(), self.drop_snap_frames(), &marks, )) @@ -841,7 +841,7 @@ impl Player { self.frame_under(x), 0, 0, - self.snap, + self.snap_live(), self.drop_snap_frames(), &marks, ) @@ -1052,7 +1052,7 @@ impl Player { /// 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, raw, len, self.snap_frames(), marks) + snap_cue(self.snap_live(), raw, len, self.snap_frames(), marks) } /// Every timeline frame that is a *source* sync point: each clip's own @@ -1148,6 +1148,17 @@ impl Player { /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the bed's /// own width drops out of it, since a pixel is now worth the same stretch of /// timeline wherever the view sits. + /// Whether the magnet is on for the gesture happening *now*: the switch + /// ([`Player::snap`]) unless `alt` is held ([`Player::drag_alt`]), which + /// turns it off for this drag or trim alone -- the temporary override + /// Resolve, Premiere and Final Cut all put on the same key. The switch is + /// not touched, so the stroke that follows the drag finds it where it was. + /// Every landing on this timeline asks it, so the shadow, the line and the + /// drop can never disagree about whether a magnet was on. + pub(crate) fn snap_live(&self) -> bool { + snap_live(self.snap, self.drag_alt) + } + pub(crate) fn snap_frames(&self) -> u32 { self.scale.snap_frames(self.fps) } @@ -2005,7 +2016,10 @@ impl Player { // outside the window, still owing its one edit. if self.trim.is_some() { match event.pressed_button { - Some(MouseButton::Left) => self.trim_to(event.position.x, cx), + Some(MouseButton::Left) => { + self.drag_alt = event.modifiers.alt; + self.trim_to(event.position.x, cx); + } _ => self.commit_trim(cx), } return; @@ -2131,6 +2145,7 @@ impl Player { if self.trim.is_some() { // The release lands exactly, then the gesture is // written once -- one edit, one undo step. + self.drag_alt = event.modifiers.alt; self.trim_to(event.position.x, cx); self.commit_trim(cx); return; diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index c566853..2446389 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -626,6 +626,15 @@ pub(crate) fn snap_cue( (start, mark) } +/// Whether the magnet is on for the gesture in flight: the switch, unless +/// `alt` is held -- the temporary override Resolve, Premiere and Final Cut all +/// put on that key, off for this one drag and leaving the switch where the hand +/// left it. [`Player::snap_live`]'s whole rule, here so it can be read without +/// a window. +pub(crate) fn snap_live(on: bool, alt: bool) -> bool { + on && !alt +} + /// Where a drag lands and the mark that pulled it there: the frame under the /// pointer, less however far into the box the hand grabbed it (so a clip travels /// with the pointer rather than jumping its head under it), snapped by @@ -723,4 +732,79 @@ mod drop_landing_tests { assert!(marks.contains(&500)); assert_eq!(snapped(493, 0, 10, &marks), 500); } + + /// The user's own repro: a clip dragged left through the lane-head column + /// -- window x *left of the bed* -- lands on frame 0 rather than nowhere. + /// Two clamps do it, and both are on the path the bench now takes for a + /// drop over the head ([`Player::frame_under`]): [`px_along`] pins an x + /// before the bed's left edge to 0 px, [`Scale::time_at`] pins the moment + /// to 0 s, and the grab offset comes off with a saturating subtraction, so + /// even a clip held by its tail cannot ask for a negative frame. + #[test] + fn a_drag_out_over_the_lane_head_lands_on_frame_0() { + let bed = Bounds { + origin: point(px(100.), px(0.)), + size: size(px(900.), px(60.)), + }; + let scale = Scale::default(); + // 40 px into the head column, and off the window entirely. + for x in [px(60.), px(-400.)] { + assert_eq!(px_along(x, bed), 0.); + let under = frame_at(scale.time_at(px_along(x, bed)), 25.); + assert_eq!(under, 0); + // Grabbed 30 frames into the box: still frame 0, never a refusal. + assert_eq!(landing(under, 30, 50, true, 10, &[0, 300]), (0, Some(0))); + } + } + + /// Both edges of the clip in the hand are candidates and the nearest one + /// wins: a tail 2 frames short of a neighbour's head beats a head 8 frames + /// from the timeline's start. + #[test] + fn the_nearer_of_the_two_edges_wins() { + let marks = [0, 300, 500]; + // len 292: the tail wants 300 (2 away), the head 0 (8 away). + // The tail already sits exactly on 300, so the head is left alone. + assert_eq!(snapped(8, 292, 10, &marks), 8); + assert_eq!(snapped(6, 292, 10, &marks), 8, "tail meets 300, head stays"); + } + + /// The threshold is a distance on *screen*: the same 10 px of aim at two + /// zooms is a different number of frames, which is what makes the magnet + /// feel identical zoomed in and zoomed out ([`Scale::drop_snap_frames`]). + /// Outside it the drag follows the pointer exactly. + #[test] + fn the_threshold_is_ten_pixels_at_any_zoom() { + let fps = 25.; + for pps in [50., 400.] { + let scale = Scale { pps, start: 0. }; + let tol = scale.drop_snap_frames(fps); + // 10 px worth of frames, and one frame more than that is not near. + let near = (DROP_SNAP_PX / pps * fps) as u32; + assert_eq!(tol, near); + assert_eq!(snapped(500 + tol, 0, tol, &[500]), 500); + assert_eq!( + snapped(500 + tol + 1, 0, tol, &[500]), + 500 + tol + 1, + "past the window the pointer is obeyed exactly" + ); + } + } + + /// `alt` held turns the magnet off for the gesture and nothing else: the + /// same raw ask, no line, and [`Player::snap`] itself untouched. + #[test] + fn alt_turns_the_magnet_off_for_this_drag_only() { + let on = true; + assert!(snap_live(on, false)); + assert!(!snap_live(on, true)); + let marks = [0, 300]; + assert_eq!( + snap_cue(snap_live(on, true), 297, 0, 10, &marks), + (297, None) + ); + assert_eq!(snap_cue(snap_live(on, false), 297, 0, 10, &marks), (300, Some(300))); + // The switch off stays off however the modifier is held. + assert!(!snap_live(false, false)); + } } diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index dd5a256..5d2efeb 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -877,6 +877,111 @@ fn lane_row( this.preview_lane_drop(event.drag(cx).0, lane, cx); }), ) + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { + this.drag_alt = window.modifiers().alt; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + let at = this.place_frame(x).0; + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) + })) + // The landing shadow (`Player::preview_ghost_asset`, the same + // setter `ui/timeline.rs`'s own bed calls) -- guarded on the + // pointer actually being inside this *row's* bounds, since + // `on_drag_move` fires on every painted element of the drag's + // type, not just the one under the pointer. The row and not the + // bed: the head column is 72px of this lane too, and a clip + // dragged out over it is aiming at frame 0 -- the drop it used to + // fall through (nothing under the pointer answered `ClipDrag`) is + // the "I have to be pixel perfect to snap to 0" complaint. + // `Player::frame_under` clamps an x left of the bed to the head of + // the view (`px_along`), so the head column reads as frame 0. + .on_drag_move( + cx.listener(move |this, event: &DragMoveEvent, _, cx| { + if !event.bounds.contains(&event.event.position) { + return; + } + let path = event.drag(cx).0.clone(); + this.drag_x = Some(event.event.position.x); + this.drag_alt = event.event.modifiers.alt; + this.preview_ghost_asset(&path, lane, event.event.position.x, cx); + }), + ) + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { + this.drag_alt = window.modifiers().alt; + let Some(idx) = this.dragged(drag) else { + return; + }; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.move_clip(drag.lane, idx, lane, x, cx) + })) + .on_drag_move( + cx.listener(move |this, event: &DragMoveEvent, _, cx| { + if !event.bounds.contains(&event.event.position) { + return; + } + let drag = *event.drag(cx); + this.drag_x = Some(event.event.position.x); + // The last lane this clip could actually land on: a picture + // 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_alt = event.event.modifiers.alt; + this.preview_ghost(&drag, lane, event.event.position.x, cx); + }), + ) + // A caption already on a lane moves along it, or onto another + // subtitle track, exactly as a clip does (`Player::move_sub`, + // the same call `ui/timeline.rs`'s own bed makes). + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { + this.drag_alt = window.modifiers().alt; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.move_sub(drag, lane, x, cx); + })) + .on_drag_move( + cx.listener(move |this, event: &DragMoveEvent, _, cx| { + if !event.bounds.contains(&event.event.position) { + return; + } + let drag = *event.drag(cx); + this.drag_x = Some(event.event.position.x); + this.drag_alt = event.event.modifiers.alt; + this.preview_ghost_sub(&drag, lane, event.event.position.x, cx); + }), + ) + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { + this.drag_alt = window.modifiers().alt; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.place_sub(drag.0, lane, x, cx); + })) + .on_drag_move( + cx.listener(move |this, event: &DragMoveEvent, _, cx| { + if !event.bounds.contains(&event.event.position) { + return; + } + let track = event.drag(cx).0; + this.drag_x = Some(event.event.position.x); + this.drag_alt = event.event.modifiers.alt; + this.preview_ghost_pick(track, lane, event.event.position.x, cx); + }), + ) .child( // Pinned track head: its drag handle remains the lane label; verbs // stay separate pointer targets so a mix/remove click never starts @@ -1019,15 +1124,6 @@ fn lane_row( .h_full() .bg(rgba(DARK_SEAM())), ) - .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) - .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { - let x = this - .drag_x - .take() - .unwrap_or_else(|| window.mouse_position().x); - let at = this.place_frame(x).0; - this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) - })) // Right-click on empty bed space: the "Close Gap" door. A // clip's own right-click handler (`clip_box`/`sub_box`) never // stops propagation, so this fires on that press too -- @@ -1060,81 +1156,6 @@ fn lane_row( } }), ) - // The landing shadow (`Player::preview_ghost_asset`, the same - // setter `ui/timeline.rs`'s own bed calls) -- guarded on the - // pointer actually being inside this bed's own bounds, since - // `on_drag_move` fires on every painted element of the drag's - // type, not just the one under the pointer. - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let path = event.drag(cx).0.clone(); - this.drag_x = Some(event.event.position.x); - this.preview_ghost_asset(&path, lane, event.event.position.x, cx); - }), - ) - .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) - .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { - let Some(idx) = this.dragged(drag) else { - return; - }; - let x = this - .drag_x - .take() - .unwrap_or_else(|| window.mouse_position().x); - this.move_clip(drag.lane, idx, lane, x, cx) - })) - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let drag = *event.drag(cx); - this.drag_x = Some(event.event.position.x); - this.preview_ghost(&drag, lane, event.event.position.x, cx); - }), - ) - // A caption already on a lane moves along it, or onto another - // subtitle track, exactly as a clip does (`Player::move_sub`, - // the same call `ui/timeline.rs`'s own bed makes). - .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) - .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { - let x = this - .drag_x - .take() - .unwrap_or_else(|| window.mouse_position().x); - this.move_sub(drag, lane, x, cx); - })) - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let drag = *event.drag(cx); - this.drag_x = Some(event.event.position.x); - this.preview_ghost_sub(&drag, lane, event.event.position.x, cx); - }), - ) - .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) - .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { - let x = this - .drag_x - .take() - .unwrap_or_else(|| window.mouse_position().x); - this.place_sub(drag.0, lane, x, cx); - })) - .on_drag_move( - cx.listener(move |this, event: &DragMoveEvent, _, cx| { - if !event.bounds.contains(&event.event.position) { - return; - } - let track = event.drag(cx).0; - this.drag_x = Some(event.event.position.x); - this.preview_ghost_pick(track, lane, event.event.position.x, cx); - }), - ) .tooltip(crate::ui::widgets::tip_hover("Lane bed", "drop media here", None)) .children(hitmap::dynamic( move || { @@ -1273,6 +1294,28 @@ pub(crate) fn render( .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { this.timeline_wheel(event, cx); })) + // The catch-all release: a clip let go of anywhere on the bench that is + // not a lane row -- left of the tracks, in the gap between two rows, on + // the empty bench below the last one -- lands on the lane and the x the + // last live sample of that same drag was over (`Player::drag_lane`, + // `Player::drag_x`), which is exactly what the shadow was drawn at. A + // release that reaches no drop target at all is the one thing a drag + // may never do: a hand that has aimed a clip and let go has made an + // edit, and "nothing happened" is not one of the answers an editor + // accepts. A row's own listener stops propagation when it answers, so + // this only ever runs when none did -- and it would answer with the + // same frame if it did run, since both read the one sample. + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { + let (Some(lane), Some(idx)) = (this.drag_lane, this.dragged(drag)) else { + return; + }; + let x = this + .drag_x + .take() + .unwrap_or_else(|| window.mouse_position().x); + this.drag_alt = window.modifiers().alt; + this.move_clip(drag.lane, idx, lane, x, cx); + })) .child( // Pinned ruler: click/drag to seek (reuses `Player::scrub_to`, // the same call the legacy ruler makes), tick marks with mono