forge
Explore
Log in

Don't you dare go Hollow

Coalesce the visualizer wheel drag like the colour bars

Browse files at this commit

ed847d4a47f8acafea73dd3435660197462f0159Ahmet Kaan GümüşParent: f93a86c
  • fix
    • coalesce the visualizer wheel drag like the colour bars
Show full message
🐛 fix(audio): coalesce the visualizer wheel drag like the colour bars

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.lockmodified+1 -0
@@ -1669,6 +1669,7 @@ version = "0.1.0"
1669 dependencies = [1669 dependencies = [
1670 "ec-core",1670 "ec-core",
1671 "ec-dsp",1671 "ec-dsp",
1672+ "wide",
1672 ]1673 ]
1673 1674
1674 [[package]]1675 [[package]]
crates/app/src/main.rsmodified+8 -0
@@ -761,6 +761,13 @@ struct Player {
761 viz_hs_dragging: bool,761 viz_hs_dragging: bool,
762 /// The wheel's box, recorded at prepaint for a drag's window position.762 /// The wheel's box, recorded at prepaint for a drag's window position.
763 viz_wheel: Rc<Cell<Bounds<Pixels>>>,763 viz_wheel: Rc<Cell<Bounds<Pixels>>>,
764+ /// The ink the hand is on, held back because the worker still owes a frame
765+ /// ([`Self::pending_color`]'s own reason, and a wheel sample is heavier
766+ /// than a grade's: it is not a table entry but the painter's own input, so
767+ /// the write is what rebuilds the picture). What the wheel draws while it
768+ /// stands, and never lost -- the frame that lands writes it, and so does
769+ /// the release.
770+ pending_viz: Option<(u8, u8)>,
764 /// Each slider's box, recorded at prepaint: a mouse listener is handed the771 /// Each slider's box, recorded at prepaint: a mouse listener is handed the
765 /// window position only, so this is what a press and a drag are read against772 /// window position only, so this is what a press and a drag are read against
766 /// ([`frac_along`]). One per band, because the press picks the row it landed773 /// ([`frac_along`]). One per band, because the press picks the row it landed
@@ -1071,6 +1078,7 @@ fn main() {
1071 color_dragging: false,1078 color_dragging: false,
1072 viz_hs_dragging: false,1079 viz_hs_dragging: false,
1073 viz_wheel: Rc::default(),1080 viz_wheel: Rc::default(),
1081+ pending_viz: None,
1074 color_bars: std::array::from_fn(|_| Rc::default()),1082 color_bars: std::array::from_fn(|_| Rc::default()),
1075 pending_color: None,1083 pending_color: None,
1076 transform_open: None,1084 transform_open: None,
crates/app/src/player/cards.rsmodified+3 -0
@@ -673,6 +673,9 @@ impl Player {
673 if let Some(speed) = self.pending_speed.take() {673 if let Some(speed) = self.pending_speed.take() {
674 self.write_speed(speed, true, cx);674 self.write_speed(speed, true, cx);
675 }675 }
676+ if let Some((hue, sat)) = self.pending_viz.take() {
677+ self.set_viz_hs(hue, sat, cx);
678+ }
676 }679 }
677 680
678 /// Opens the silence card on the clip to be scanned: the selected one, or681 /// Opens the silence card on the clip to be scanned: the selected one, or
crates/app/src/player/library.rsmodified+25 -2
@@ -237,12 +237,28 @@ impl Player {
237 }237 }
238 238
239 pub(crate) fn set_viz_hs(&mut self, hue: u8, sat: u8, cx: &mut Context<Self>) {239 pub(crate) fn set_viz_hs(&mut self, hue: u8, sat: u8, cx: &mut Context<Self>) {
240+ // A write supersedes whatever a drag was holding
241+ // ([`Player::write_color`]'s rule).
242+ self.pending_viz = None;
240 self.set_viz_paint_with(cx, |p| {243 self.set_viz_paint_with(cx, |p| {
241 engine::decode::with_viz_paint_sat(engine::decode::with_viz_paint_hue(p, hue), sat)244 engine::decode::with_viz_paint_sat(engine::decode::with_viz_paint_hue(p, hue), sat)
242 });245 });
243 }246 }
244 247
245- pub(crate) fn drag_viz_hs(&mut self, at: gpui::Point<Pixels>, cx: &mut Context<Self>) {248+ /// One pointer sample on the wheel, as the hue and saturation under it.
249+ /// `first` is the press, which is never held: it is the pick the gesture
250+ /// rolls back to, so it has to be taken against the ink the hand picked up.
251+ /// Every sample after it goes through [`stash_or_write`] -- a wheel sample
252+ /// is not a table entry but the painter's input, so the write is what
253+ /// rebuilds the whole picture at the playhead, and a sweep that wrote each
254+ /// one would queue a reopen per pixel, cancel all but one and freeze the
255+ /// window for the sum.
256+ pub(crate) fn drag_viz_hs(
257+ &mut self,
258+ at: gpui::Point<Pixels>,
259+ first: bool,
260+ cx: &mut Context<Self>,
261+ ) {
246 let b = self.viz_wheel.get();262 let b = self.viz_wheel.get();
247 let w = f32::from(b.size.width).max(1.);263 let w = f32::from(b.size.width).max(1.);
248 let h = f32::from(b.size.height).max(1.);264 let h = f32::from(b.size.height).max(1.);
@@ -254,7 +270,13 @@ impl Player {
254 let ang = dx.atan2(dy).to_degrees();270 let ang = dx.atan2(dy).to_degrees();
255 let hue_deg = (ang + 360.) % 360.;271 let hue_deg = (ang + 360.) % 360.;
256 let hue = (hue_deg / 360. * 256.).round() as u16 as u8;272 let hue = (hue_deg / 360. * 256.).round() as u16 as u8;
257- self.set_viz_hs(hue, sat, cx);273+ let busy = self.seek_since.is_some();
274+ match stash_or_write(&mut self.pending_viz, (hue, sat), first, busy) {
275+ Some((hue, sat)) => self.set_viz_hs(hue, sat, cx),
276+ // The wheel draws off the held sample, so the mark goes on
277+ // following the hand while the picture catches up.
278+ None => cx.notify(),
279+ }
258 }280 }
259 281
260 pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context<Self>) {282 pub(crate) fn set_viz_strands(&mut self, n: u8, cx: &mut Context<Self>) {
@@ -501,6 +523,7 @@ impl Player {
501 self.color_dragging = false;523 self.color_dragging = false;
502 self.viz_hs_dragging = false;524 self.viz_hs_dragging = false;
503 self.pending_color = None;525 self.pending_color = None;
526+ self.pending_viz = None;
504 self.transform_dragging = false;527 self.transform_dragging = false;
505 self.pending_transform = None;528 self.pending_transform = None;
506 self.pending_speed = None;529 self.pending_speed = None;
crates/app/src/player/timeline_edit.rsmodified+13 -2
@@ -2103,11 +2103,18 @@ impl Player {
2103 }2103 }
2104 return;2104 return;
2105 }2105 }
2106+ // The ink wheel, on the root for the same 4 px reason and gated on the
2107+ // worker like the bars above: one sample here is a whole picture
2108+ // rebuilt, so what is written is one ink per frame the worker delivers
2109+ // rather than one per pixel the pointer crossed.
2106 if self.viz_hs_dragging {2110 if self.viz_hs_dragging {
2107 if event.pressed_button == Some(MouseButton::Left) {2111 if event.pressed_button == Some(MouseButton::Left) {
2108- self.drag_viz_hs(event.position, cx);2112+ self.drag_viz_hs(event.position, false, cx);
2109 } else {2113 } else {
2114+ // The release happened outside the window, so the sample the
2115+ // hand let go on is owed like any other ending.
2110 self.viz_hs_dragging = false;2116 self.viz_hs_dragging = false;
2117+ self.flush_drag(cx);
2111 }2118 }
2112 return;2119 return;
2113 }2120 }
@@ -2228,7 +2235,11 @@ impl Player {
2228 return;2235 return;
2229 }2236 }
2230 if std::mem::take(&mut self.viz_hs_dragging) {2237 if std::mem::take(&mut self.viz_hs_dragging) {
2231- self.drag_viz_hs(event.position, cx);2238+ // The release lands exactly where the hand let go, and the flush
2239+ // is what makes that true while the worker is still busy: the
2240+ // sample above would only be held.
2241+ self.drag_viz_hs(event.position, false, cx);
2242+ self.flush_drag(cx);
2232 return;2243 return;
2233 }2244 }
2234 if std::mem::take(&mut self.transform_dragging) {2245 if std::mem::take(&mut self.transform_dragging) {
crates/app/src/tests/media.rsmodified+32 -0
@@ -202,6 +202,38 @@ fn a_release_lands_the_value_the_hand_let_go_on() {
202 assert_eq!(stash, None);202 assert_eq!(stash, None);
203 }203 }
204 204
205+/// The wheel's own version of the same gesture, and the one thing a drag on it
206+/// may not lose while the worker is behind: the mark follows the hand. A held
207+/// sample is what the wheel draws -- the clip carries the ink from before it
208+/// until the holding frame lands -- and the pen's own settings, which are not
209+/// part of a hue/saturation sample, survive it untouched.
210+#[test]
211+fn the_wheel_draws_the_sample_a_drag_is_holding() {
212+ // Nothing held: the clip's own ink, byte for byte -- the default 0
213+ // included, which materializes to azure where it is read.
214+ assert_eq!(viz_held_paint(0, None), 0);
215+ assert_eq!(viz_held_paint(0x0208_d2fd, None), 0x0208_d2fd);
216+ // Held: that hue and saturation over what the clip already carries.
217+ let held = viz_held_paint(0, Some((253, 210)));
218+ assert_eq!(engine::decode::viz_hue_ui(held), 253);
219+ assert_eq!(engine::decode::viz_sat_ui(held), 210);
220+ // ...in that order, never the other way round: a mark drawn at the wrong
221+ // angle is the whole gesture showing the wrong colour.
222+ let flipped = viz_held_paint(0, Some((210, 253)));
223+ assert_ne!(held, flipped);
224+ assert_eq!(engine::decode::viz_hue_ui(flipped), 210);
225+ assert_eq!(engine::decode::viz_sat_ui(flipped), 253);
226+ // Strands and glow are the clip's, not the sample's: the wheel carries no
227+ // row for either, so a held hue may not move them.
228+ assert_eq!(engine::decode::viz_strands_of(held), 8);
229+ assert_eq!(engine::decode::viz_glow_of(held), 2);
230+ let pen = engine::decode::with_viz_paint_glow(0x0208_d2fd, 9);
231+ assert_eq!(
232+ engine::decode::viz_glow_of(viz_held_paint(pen, Some((253, 210)))),
233+ 9
234+ );
235+}
236+
205 /// A seek says nothing until it has stood: an ordinary one is a flicker and237 /// A seek says nothing until it has stood: an ordinary one is a flicker and
206 /// a cold read of a big file is the case worth words.238 /// a cold read of a big file is the case worth words.
207 #[test]239 #[test]
crates/app/src/tests/mod.rsmodified+1 -1
@@ -31,7 +31,7 @@ use super::{
31 row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label,31 row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label,
32 rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal,32 rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal,
33 subtitle_plan, timecode, timeline_fixed_h, tip_may_paint,33 subtitle_plan, timecode, timeline_fixed_h, tip_may_paint,
34- transport, typed, unseen_paths, unseen_sources, whole_take, window_title,34+ transport, typed, unseen_paths, unseen_sources, viz_held_paint, whole_take, window_title,
35 };35 };
36 36
37 use super::{37 use super::{
crates/app/src/transport.rsmodified+16 -0
@@ -204,6 +204,22 @@ pub(crate) fn stash_or_write<T: Copy>(
204 }204 }
205 }205 }
206 206
207+/// What the wheel draws: the clip's own ink, or the sample a drag is holding
208+/// while the worker is still behind ([`stash_or_write`]). The wheel is a
209+/// picker with no table of its own, so a held sample would otherwise be
210+/// invisible -- the clip carries the sample *before* it until the holding
211+/// frame lands -- and the mark would sit still under a moving hand.
212+/// [`Player::color_params`] holds exactly this rule for the card's sliders.
213+pub(crate) fn viz_held_paint(paint: u32, held: Option<(u8, u8)>) -> u32 {
214+ match held {
215+ Some((hue, sat)) => engine::decode::with_viz_paint_sat(
216+ engine::decode::with_viz_paint_hue(paint, hue),
217+ sat,
218+ ),
219+ None => paint,
220+ }
221+}
222+
207 /// How long an open may stand before the window says so in words. Well past an223 /// How long an open may stand before the window says so in words. Well past an
208 /// ordinary seek (a warm reopen is under a tenth of this) and well under what a224 /// ordinary seek (a warm reopen is under a tenth of this) and well under what a
209 /// cold read of a big film takes, which is the only case worth a line.225 /// cold read of a big film takes, which is the only case worth a line.
crates/app/src/ui/dock_stance.rsmodified+5 -2
@@ -1197,7 +1197,10 @@ fn viz_style_verbs(player: &Player, cx: &mut Context<Player>) -> impl IntoElemen
1197 return div().id("dock-viz-styles");1197 return div().id("dock-viz-styles");
1198 };1198 };
1199 let flags = clip.visualizer;1199 let flags = clip.visualizer;
1200- let paint = clip.viz_paint;1200+ // The ink the wheel draws is the one a drag is holding, when one is: the
1201+ // clip still carries the sample before it until the worker lands the
1202+ // holding frame (`viz_held_paint`).
1203+ let paint = viz_held_paint(clip.viz_paint, player.pending_viz);
1201 let pick = |id: &'static str, label_text: &'static str, style: u8, on: bool| {1204 let pick = |id: &'static str, label_text: &'static str, style: u8, on: bool| {
1202 let row = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM);1205 let row = label(type_scale::LABEL_ROW_PX, FontWeight::MEDIUM);
1203 div()1206 div()
@@ -1374,7 +1377,7 @@ fn viz_color_wheel(player: &Player, paint: u32, cx: &mut Context<Player>) -> imp
1374 MouseButton::Left,1377 MouseButton::Left,
1375 cx.listener(move |this, event: &MouseDownEvent, _, cx| {1378 cx.listener(move |this, event: &MouseDownEvent, _, cx| {
1376 this.viz_hs_dragging = true;1379 this.viz_hs_dragging = true;
1377- this.drag_viz_hs(event.position, cx);1380+ this.drag_viz_hs(event.position, true, cx);
1378 }),1381 }),
1379 )1382 )
1380 }1383 }