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 {
1179 /// and nowhere else: every frame-to-pixel answer in the panel comes out of1179 /// and nowhere else: every frame-to-pixel answer in the panel comes out of
1180 /// it, so the boxes, the playhead and the pointer cannot disagree.1180 /// it, so the boxes, the playhead and the pointer cannot disagree.
1181 scale: Scale,1181 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,
1182 /// Which clip the edit keys act on: the lane it is in and its index there.1191 /// Which clip the edit keys act on: the lane it is in and its index there.
1183 /// The *clicked* half, not the group -- a group is what gets marked on1192 /// The *clicked* half, not the group -- a group is what gets marked on
1184 /// screen, but Lift has to know which half it was aimed at. Indices move1193 /// screen, but Lift has to know which half it was aimed at. Indices move
@@ -1719,6 +1728,9 @@ impl Player {
1719 // Restarted on every reseek, not only on the first: what it measures is1728 // Restarted on every reseek, not only on the first: what it measures is
1720 // the open now standing, which is what a person is waiting on.1729 // the open now standing, which is what a person is waiting on.
1721 self.seek_since = Some(Instant::now());1730 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;
1722 // An edit moves the indices a drag in flight is holding -- a stroke1734 // An edit moves the indices a drag in flight is holding -- a stroke
1723 // during one is exactly that -- and an edge committed against a moved1735 // during one is exactly that -- and an edge committed against a moved
1724 // index would trim a clip nobody grabbed. Dropping it is the whole fix:1736 // index would trim a clip nobody grabbed. Dropping it is the whole fix:
@@ -2131,6 +2143,10 @@ impl Player {
2131 let at = self.playhead(view.duration);2143 let at = self.playhead(view.duration);
2132 let anchor = anchor.unwrap_or_else(|| self.scale.px_at(at).clamp(0., view.bed));2144 let anchor = anchor.unwrap_or_else(|| self.scale.px_at(at).clamp(0., view.bed));
2133 self.scale = view.zoomed(factor, anchor);2145 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;
2134 cx.notify();2150 cx.notify();
2135 }2151 }
2136 2152
@@ -2154,6 +2170,10 @@ impl Player {
2154 return;2170 return;
2155 }2171 }
2156 self.scale = view.scrolled(notches * view.bed * SCROLL_NOTCH_SHARE);2172 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;
2157 cx.notify();2177 cx.notify();
2158 }2178 }
2159 2179
@@ -5455,6 +5475,9 @@ impl Player {
5455 cx.notify();5475 cx.notify();
5456 return;5476 return;
5457 }5477 }
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;
5458 match self.transport() {5481 match self.transport() {
5459 // Nothing open: the button is dimmed and the key says nothing.5482 // Nothing open: the button is dimmed and the key says nothing.
5460 Transport::Stopped => {}5483 Transport::Stopped => {}
@@ -5859,10 +5882,19 @@ impl Render for Player {
5859 // is what a moving one does, during playback and through a seek. A view5882 // is what a moving one does, during playback and through a seek. A view
5860 // yanked back to a playhead nobody moved is a hand's own scroll undone5883 // yanked back to a playhead nobody moved is a hand's own scroll undone
5861 // by the very next frame, which is what made the wheel look dead.5884 // 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 {
5863 true => self.view().following(position),5892 true => self.view().following(position),
5864 false => self.view().settled(),5893 false => self.view().settled(),
5865 };5894 };
5895+ if self.panned && self.view().shows(position) {
5896+ self.panned = false;
5897+ }
5866 5898
5867 div()5899 div()
5868 .track_focus(&self.focus)5900 .track_focus(&self.focus)
@@ -9238,19 +9270,32 @@ impl View {
9238 return self.scale;9270 return self.scale;
9239 }9271 }
9240 let scale = self.settled();9272 let scale = self.settled();
9273+ if self.shows(at) {
9274+ return scale;
9275+ }
9241 let span = f64::from(self.bed) / scale.pps;9276 let span = f64::from(self.bed) / scale.pps;
9242- if at < scale.start || at > scale.start + span {9277+ View {
9243- View {9278+ scale: Scale {
9244- scale: Scale {9279+ start: at - span / 2.,
9245- start: at - span / 2.,9280+ ..scale
9246- ..scale9281+ },
9247- },9282+ ..self
9248- ..self9283+ }
9249- }9284+ .settled()
9250- .settled()9285+ }
9251- } else {9286+
9252- scale9287+ /// 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;
9253 }9296 }
9297+ let scale = self.settled();
9298+ at >= scale.start && at <= scale.start + f64::from(self.bed) / scale.pps
9254 }9299 }
9255 }9300 }
9256 9301
@@ -12585,6 +12630,60 @@ mod tests {
12585 }12630 }
12586 }12631 }
12587 12632
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+
12588 /// The bug this mapping exists for: the first import used to fill the whole12687 /// The bug this mapping exists for: the first import used to fill the whole
12589 /// track whatever it was, because the bed *was* the timeline -- so a 5 s12688 /// track whatever it was, because the bed *was* the timeline -- so a 5 s
12590 /// clip was 100% of the lane, zooming out did nothing, and adding a second12689 /// clip was 100% of the lane, zooming out did nothing, and adding a second
@@ -16253,6 +16352,9 @@ fn main() {
16253 // zooms or asks for the fit: a project opens at a scale, not16352 // zooms or asks for the fit: a project opens at a scale, not
16254 // at whatever its first import happens to be long.16353 // at whatever its first import happens to be long.
16255 scale: Scale::default(),16354 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,
16256 selected: None,16358 selected: None,
16257 context_menu: None,16359 context_menu: None,
16258 picker: None,16360 picker: None,