From ed847d4a47f8acafea73dd3435660197462f0159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 16 Sep 2026 05:23:15 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(audio):=20coalesce=20the=20v?= =?UTF-8?q?isualizer=20wheel=20drag=20like=20the=20colour=20bars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One pointer sample wrote one edit(Dirty::Picture) -> start_picture: a full picture rebuild at the playhead per sample, so a drag queued a reopen per step and the window froze for the sum -- the shape drag_color's own comment already names. The wheel now holds a sample while a rebuild is in flight (stash_or_write, busy = a pending reseek), flushes it on release, and draws its mark from the held sample so the hand leads the picture. --- Cargo.lock | 1 + crates/app/src/main.rs | 8 +++++++ crates/app/src/player/cards.rs | 3 +++ crates/app/src/player/library.rs | 27 ++++++++++++++++++++-- crates/app/src/player/timeline_edit.rs | 15 ++++++++++-- crates/app/src/tests/media.rs | 32 ++++++++++++++++++++++++++ crates/app/src/tests/mod.rs | 2 +- crates/app/src/transport.rs | 16 +++++++++++++ crates/app/src/ui/dock_stance.rs | 7 ++++-- 9 files changed, 104 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e1b145..4574dbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1669,6 +1669,7 @@ version = "0.1.0" dependencies = [ "ec-core", "ec-dsp", + "wide", ] [[package]] diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 819e56b..37cf1b9 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -761,6 +761,13 @@ struct Player { viz_hs_dragging: bool, /// The wheel's box, recorded at prepaint for a drag's window position. viz_wheel: Rc>>, + /// The ink the hand is on, held back because the worker still owes a frame + /// ([`Self::pending_color`]'s own reason, and a wheel sample is heavier + /// than a grade's: it is not a table entry but the painter's own input, so + /// the write is what rebuilds the picture). What the wheel draws while it + /// stands, and never lost -- the frame that lands writes it, and so does + /// the release. + pending_viz: Option<(u8, u8)>, /// Each slider's box, recorded at prepaint: a mouse listener is handed the /// window position only, so this is what a press and a drag are read against /// ([`frac_along`]). One per band, because the press picks the row it landed @@ -1071,6 +1078,7 @@ fn main() { color_dragging: false, viz_hs_dragging: false, viz_wheel: Rc::default(), + pending_viz: None, color_bars: std::array::from_fn(|_| Rc::default()), pending_color: None, transform_open: None, diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 3d02e7f..5745f8c 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -673,6 +673,9 @@ impl Player { if let Some(speed) = self.pending_speed.take() { self.write_speed(speed, true, cx); } + if let Some((hue, sat)) = self.pending_viz.take() { + self.set_viz_hs(hue, sat, cx); + } } /// Opens the silence card on the clip to be scanned: the selected one, or diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 32d0857..c6216e9 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -237,12 +237,28 @@ impl Player { } pub(crate) fn set_viz_hs(&mut self, hue: u8, sat: u8, cx: &mut Context) { + // A write supersedes whatever a drag was holding + // ([`Player::write_color`]'s rule). + self.pending_viz = None; self.set_viz_paint_with(cx, |p| { engine::decode::with_viz_paint_sat(engine::decode::with_viz_paint_hue(p, hue), sat) }); } - pub(crate) fn drag_viz_hs(&mut self, at: gpui::Point, cx: &mut Context) { + /// One pointer sample on the wheel, as the hue and saturation under it. + /// `first` is the press, which is never held: it is the pick the gesture + /// rolls back to, so it has to be taken against the ink the hand picked up. + /// Every sample after it goes through [`stash_or_write`] -- a wheel sample + /// is not a table entry but the painter's input, so the write is what + /// rebuilds the whole picture at the playhead, and a sweep that wrote each + /// one would queue a reopen per pixel, cancel all but one and freeze the + /// window for the sum. + pub(crate) fn drag_viz_hs( + &mut self, + at: gpui::Point, + first: bool, + cx: &mut Context, + ) { let b = self.viz_wheel.get(); let w = f32::from(b.size.width).max(1.); let h = f32::from(b.size.height).max(1.); @@ -254,7 +270,13 @@ impl Player { let ang = dx.atan2(dy).to_degrees(); let hue_deg = (ang + 360.) % 360.; let hue = (hue_deg / 360. * 256.).round() as u16 as u8; - self.set_viz_hs(hue, sat, cx); + let busy = self.seek_since.is_some(); + match stash_or_write(&mut self.pending_viz, (hue, sat), first, busy) { + Some((hue, sat)) => self.set_viz_hs(hue, sat, cx), + // The wheel draws off the held sample, so the mark goes on + // following the hand while the picture catches up. + None => cx.notify(), + } } pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context) { @@ -501,6 +523,7 @@ impl Player { self.color_dragging = false; self.viz_hs_dragging = false; self.pending_color = None; + self.pending_viz = None; self.transform_dragging = false; self.pending_transform = None; self.pending_speed = None; diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 8ecad0b..f7cd0ba 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -2103,11 +2103,18 @@ impl Player { } return; } + // The ink wheel, on the root for the same 4 px reason and gated on the + // worker like the bars above: one sample here is a whole picture + // rebuilt, so what is written is one ink per frame the worker delivers + // rather than one per pixel the pointer crossed. if self.viz_hs_dragging { if event.pressed_button == Some(MouseButton::Left) { - self.drag_viz_hs(event.position, cx); + self.drag_viz_hs(event.position, false, cx); } else { + // The release happened outside the window, so the sample the + // hand let go on is owed like any other ending. self.viz_hs_dragging = false; + self.flush_drag(cx); } return; } @@ -2228,7 +2235,11 @@ impl Player { return; } if std::mem::take(&mut self.viz_hs_dragging) { - self.drag_viz_hs(event.position, cx); + // The release lands exactly where the hand let go, and the flush + // is what makes that true while the worker is still busy: the + // sample above would only be held. + self.drag_viz_hs(event.position, false, cx); + self.flush_drag(cx); return; } if std::mem::take(&mut self.transform_dragging) { diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index f4bb4eb..71c09bc 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -202,6 +202,38 @@ fn a_release_lands_the_value_the_hand_let_go_on() { assert_eq!(stash, None); } +/// The wheel's own version of the same gesture, and the one thing a drag on it +/// may not lose while the worker is behind: the mark follows the hand. A held +/// sample is what the wheel draws -- the clip carries the ink from before it +/// until the holding frame lands -- and the pen's own settings, which are not +/// part of a hue/saturation sample, survive it untouched. +#[test] +fn the_wheel_draws_the_sample_a_drag_is_holding() { + // Nothing held: the clip's own ink, byte for byte -- the default 0 + // included, which materializes to azure where it is read. + assert_eq!(viz_held_paint(0, None), 0); + assert_eq!(viz_held_paint(0x0208_d2fd, None), 0x0208_d2fd); + // Held: that hue and saturation over what the clip already carries. + let held = viz_held_paint(0, Some((253, 210))); + assert_eq!(engine::decode::viz_hue_ui(held), 253); + assert_eq!(engine::decode::viz_sat_ui(held), 210); + // ...in that order, never the other way round: a mark drawn at the wrong + // angle is the whole gesture showing the wrong colour. + let flipped = viz_held_paint(0, Some((210, 253))); + assert_ne!(held, flipped); + assert_eq!(engine::decode::viz_hue_ui(flipped), 210); + assert_eq!(engine::decode::viz_sat_ui(flipped), 253); + // Strands and glow are the clip's, not the sample's: the wheel carries no + // row for either, so a held hue may not move them. + assert_eq!(engine::decode::viz_strands_of(held), 8); + assert_eq!(engine::decode::viz_glow_of(held), 2); + let pen = engine::decode::with_viz_paint_glow(0x0208_d2fd, 9); + assert_eq!( + engine::decode::viz_glow_of(viz_held_paint(pen, Some((253, 210)))), + 9 + ); +} + /// A seek says nothing until it has stood: an ordinary one is a flicker and /// a cold read of a big file is the case worth words. #[test] diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 0d1364f..59379e2 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -31,7 +31,7 @@ use super::{ row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label, rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, timecode, timeline_fixed_h, tip_may_paint, - transport, typed, unseen_paths, unseen_sources, whole_take, window_title, + transport, typed, unseen_paths, unseen_sources, viz_held_paint, whole_take, window_title, }; use super::{ diff --git a/crates/app/src/transport.rs b/crates/app/src/transport.rs index ec974a5..d8da8ed 100644 --- a/crates/app/src/transport.rs +++ b/crates/app/src/transport.rs @@ -204,6 +204,22 @@ pub(crate) fn stash_or_write( } } +/// What the wheel draws: the clip's own ink, or the sample a drag is holding +/// while the worker is still behind ([`stash_or_write`]). The wheel is a +/// picker with no table of its own, so a held sample would otherwise be +/// invisible -- the clip carries the sample *before* it until the holding +/// frame lands -- and the mark would sit still under a moving hand. +/// [`Player::color_params`] holds exactly this rule for the card's sliders. +pub(crate) fn viz_held_paint(paint: u32, held: Option<(u8, u8)>) -> u32 { + match held { + Some((hue, sat)) => engine::decode::with_viz_paint_sat( + engine::decode::with_viz_paint_hue(paint, hue), + sat, + ), + None => paint, + } +} + /// How long an open may stand before the window says so in words. Well past an /// ordinary seek (a warm reopen is under a tenth of this) and well under what a /// cold read of a big film takes, which is the only case worth a line. diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 3590bf2..14d7552 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -1197,7 +1197,10 @@ fn viz_style_verbs(player: &Player, cx: &mut Context) -> impl IntoElemen return div().id("dock-viz-styles"); }; let flags = clip.visualizer; - let paint = clip.viz_paint; + // The ink the wheel draws is the one a drag is holding, when one is: the + // clip still carries the sample before it until the worker lands the + // holding frame (`viz_held_paint`). + let paint = viz_held_paint(clip.viz_paint, player.pending_viz); let pick = |id: &'static str, label_text: &'static str, style: u8, on: bool| { let row = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM); div() @@ -1374,7 +1377,7 @@ fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context) -> imp MouseButton::Left, cx.listener(move |this, event: &MouseDownEvent, _, cx| { this.viz_hs_dragging = true; - this.drag_viz_hs(event.position, cx); + this.drag_viz_hs(event.position, true, cx); }), ) }