forge
Explore
Log in

Don't you dare go Hollow

The wheel wins over the follow while it plays

Browse files at this commit

9bb0b829c0278d9ed94c430b6776042756c7ec7cAhmet Kaan GümüşParent: 9ba8e0a
  • fix
    • the wheel wins over the follow while it plays
Show full message
🐛 fix(timeline): the wheel wins over the follow while it plays

A notch of the wheel during playback was undone before it was seen. The
follow centres a playhead that has run off the bed, and scrolling away
from a playing head is exactly a playhead running off the bed -- so the
very next frame yanked the view back. Which notch survived depended on
where the head happened to be, so the wheel looked like it worked
sometimes: with a second, longer media making the timeline scrollable at
all, five notches moved the view by nothing at all (measured: the seam
between the two clips stayed at the same pixel), while the same five
notches paused moved it by half a bed.

The arbitration has one decision point now. A hand that moves the view
itself -- a wheel scroll, a zoom about the pointer -- takes it, and the
follow keeps off until the head runs back into what the hand chose to
look at, where the pan ends by itself with nothing to press and no
timer. A seek and a play/pause hand it back outright: those are a person
saying where to look. View::shows is the one question both halves ask,
so the follow and the pan can never disagree about where the edge of the
bed is.

Paused scrolling, the zoom-vs-scroll mapping and the playback path are
untouched.
crates/app/src/main.rsmodified+114 -12
@@ -1179,6 +1179,15 @@ struct Player {
11791179 /// and nowhere else: every frame-to-pixel answer in the panel comes out of
11801180 /// it, so the boxes, the playhead and the pointer cannot disagree.
11811181 scale: Scale,
1182+ /// A hand has moved the view itself -- a wheel scroll, a zoom about the
1183+ /// pointer -- and until the playhead runs back into what it chose to look
1184+ /// at, the view is the hand's and the follow keeps off it. Without this a
1185+ /// notch during playback was undone by the very next frame: the follow
1186+ /// centres a playhead that has left the bed, and a scroll away from it is
1187+ /// exactly a playhead leaving the bed. Given back by [`Render`] the moment
1188+ /// the head is on screen again, and by every transport ask (a seek, a
1189+ /// play/pause) outright -- those are a person saying where to look.
1190+ panned: bool,
11821191 /// Which clip the edit keys act on: the lane it is in and its index there.
11831192 /// The *clicked* half, not the group -- a group is what gets marked on
11841193 /// screen, but Lift has to know which half it was aimed at. Indices move
@@ -1719,6 +1728,9 @@ impl Player {
17191728 // Restarted on every reseek, not only on the first: what it measures is
17201729 // the open now standing, which is what a person is waiting on.
17211730 self.seek_since = Some(Instant::now());
1731+ // A seek is a person saying where to look, so it takes the view back
1732+ // from an earlier scroll: the frame asked for is the one to be shown.
1733+ self.panned = false;
17221734 // An edit moves the indices a drag in flight is holding -- a stroke
17231735 // during one is exactly that -- and an edge committed against a moved
17241736 // index would trim a clip nobody grabbed. Dropping it is the whole fix:
@@ -2131,6 +2143,10 @@ impl Player {
21312143 let at = self.playhead(view.duration);
21322144 let anchor = anchor.unwrap_or_else(|| self.scale.px_at(at).clamp(0., view.bed));
21332145 self.scale = view.zoomed(factor, anchor);
2146+ // The view a hand chose. A zoom about the playhead leaves it on the
2147+ // bed, so this is given back on the very next frame and only a zoom
2148+ // that took the head off screen -- ctrl+wheel away from it -- holds.
2149+ self.panned = true;
21342150 cx.notify();
21352151 }
21362152
@@ -2154,6 +2170,10 @@ impl Player {
21542170 return;
21552171 }
21562172 self.scale = view.scrolled(notches * view.bed * SCROLL_NOTCH_SHARE);
2173+ // The one gesture whose whole purpose is to look away from the
2174+ // playhead: while playing it wins over the follow, which is what every
2175+ // editor does with a scroll during playback.
2176+ self.panned = true;
21572177 cx.notify();
21582178 }
21592179
@@ -5455,6 +5475,9 @@ impl Player {
54555475 cx.notify();
54565476 return;
54575477 }
5478+ // Pressing play is asking to watch, so a view scrolled away while
5479+ // paused comes back to the head with it -- as a seek's does.
5480+ self.panned = false;
54585481 match self.transport() {
54595482 // Nothing open: the button is dimmed and the key says nothing.
54605483 Transport::Stopped => {}
@@ -5859,10 +5882,19 @@ impl Render for Player {
58595882 // is what a moving one does, during playback and through a seek. A view
58605883 // yanked back to a playhead nobody moved is a hand's own scroll undone
58615884 // by the very next frame, which is what made the wheel look dead.
5862- self.scale = match state.is_playing() || self.seek_since.is_some() {
5885+ // ...and a hand that scrolled the view away from the head keeps it
5886+ // ([`Player::panned`]): a follow that centres the head again would undo
5887+ // the notch before it was seen, which is what made the wheel look dead
5888+ // while playing. It is given straight back below, the moment the head
5889+ // is on the bed a person chose to look at -- so the scroll wins now and
5890+ // the follow resumes by itself, with nothing to press.
5891+ self.scale = match (state.is_playing() || self.seek_since.is_some()) && !self.panned {
58635892 true => self.view().following(position),
58645893 false => self.view().settled(),
58655894 };
5895+ if self.panned && self.view().shows(position) {
5896+ self.panned = false;
5897+ }
58665898
58675899 div()
58685900 .track_focus(&self.focus)
@@ -9238,19 +9270,32 @@ impl View {
92389270 return self.scale;
92399271 }
92409272 let scale = self.settled();
9273+ if self.shows(at) {
9274+ return scale;
9275+ }
92419276 let span = f64::from(self.bed) / scale.pps;
9242- if at < scale.start || at > scale.start + span {
9243- View {
9244- scale: Scale {
9245- start: at - span / 2.,
9246- ..scale
9247- },
9248- ..self
9249- }
9250- .settled()
9251- } else {
9252- scale
9277+ View {
9278+ scale: Scale {
9279+ start: at - span / 2.,
9280+ ..scale
9281+ },
9282+ ..self
9283+ }
9284+ .settled()
9285+ }
9286+
9287+ /// Whether the moment `at` is on the bed as it is drawn now. The one
9288+ /// question both halves of the follow ask -- [`View::following`] to decide
9289+ /// whether to chase a head that has run off, and the render to decide when
9290+ /// a hand's own scroll ([`Player::panned`]) has been caught up with and the
9291+ /// follow may have the view back -- so the two can never disagree about
9292+ /// where the edge of the bed is.
9293+ fn shows(self, at: f64) -> bool {
9294+ if self.bed <= 0. {
9295+ return false;
92539296 }
9297+ let scale = self.settled();
9298+ at >= scale.start && at <= scale.start + f64::from(self.bed) / scale.pps
92549299 }
92559300 }
92569301
@@ -12585,6 +12630,60 @@ mod tests {
1258512630 }
1258612631 }
1258712632
12633+ /// The wheel during playback. A scroll away from the playing head used to
12634+ /// be undone by the follow on the very next frame -- with a second, longer
12635+ /// media on the timeline making it scrollable at all, one notch in five
12636+ /// reached the screen and the wheel looked dead. The hand keeps the view
12637+ /// now, and the follow takes it back by itself when the head runs into what
12638+ /// the hand is looking at.
12639+ #[test]
12640+ fn a_scroll_during_playback_wins_until_the_head_catches_up() {
12641+ let duration = 80.;
12642+ let mut scale = test_view(Scale { pps: 40., start: 0. }, duration).settled();
12643+ // The render's arbitration, in the two lines it is there: a panned view
12644+ // is left where the hand put it, and the pan ends where the head is
12645+ // back on the bed.
12646+ let frame = |scale: Scale, panned: &mut bool, at: f64| {
12647+ let scale = match *panned {
12648+ true => test_view(scale, duration).settled(),
12649+ false => test_view(scale, duration).following(at),
12650+ };
12651+ if *panned && test_view(scale, duration).shows(at) {
12652+ *panned = false;
12653+ }
12654+ scale
12655+ };
12656+ // Playing at second one, five notches of the wheel: every one of them
12657+ // moves the view, and none is taken back by the head being off the bed.
12658+ let notch = f64::from(TEST_BED * SCROLL_NOTCH_SHARE);
12659+ let mut panned = false;
12660+ for n in 1..=5 {
12661+ scale = test_view(scale, duration).scrolled(TEST_BED * SCROLL_NOTCH_SHARE);
12662+ panned = true;
12663+ scale = frame(scale, &mut panned, 1.);
12664+ // ...and the pan is only *held* while the head is off the bed: the
12665+ // first notches still show it, so the follow has the view back for
12666+ // free and would not have moved anything anyway.
12667+ assert_eq!(panned, scale.start > 1., "held while the head is off");
12668+ assert!(
12669+ (scale.start - notch * f64::from(n) / 40.).abs() < 1e-6,
12670+ "notch {n} reached the screen: {scale:?}"
12671+ );
12672+ }
12673+ // The head runs into it: the pan is given back with nothing pressed...
12674+ let span = test_view(scale, duration).span();
12675+ let start = frame(scale, &mut panned, scale.start + span / 2.).start;
12676+ assert!(!panned, "the follow has the view back");
12677+ assert_eq!(start, scale.start, "and it did not jump to take it");
12678+ // ...and the next head that runs off the bed pulls the view again.
12679+ let ran_off = frame(scale, &mut panned, start + span + 1.);
12680+ assert!(ran_off.start > start, "the follow follows again: {ran_off:?}");
12681+ // A paused hand is untouched by any of this: with no follow asking,
12682+ // `shows` is the only thing the pan is ever released by.
12683+ assert!(test_view(scale, duration).shows(scale.start));
12684+ assert!(!test_view(scale, duration).shows(scale.start + span + 0.5));
12685+ }
12686+
1258812687 /// The bug this mapping exists for: the first import used to fill the whole
1258912688 /// track whatever it was, because the bed *was* the timeline -- so a 5 s
1259012689 /// clip was 100% of the lane, zooming out did nothing, and adding a second
@@ -16253,6 +16352,9 @@ fn main() {
1625316352 // zooms or asks for the fit: a project opens at a scale, not
1625416353 // at whatever its first import happens to be long.
1625516354 scale: Scale::default(),
16355+ // Nobody has scrolled anything yet, so the follow has the
16356+ // view: the first frame is drawn where the head is.
16357+ panned: false,
1625616358 selected: None,
1625716359 context_menu: None,
1625816360 picker: None,