forge
Explore
Log in

Don't you dare go Hollow

Merge remote-tracking branch 'origin/main' into worktree-agent-a687c64e216de5a66

Browse files at this commit

07f2cff07122647defc1531d27fb481625a391a6Ahmet Kaan GümüşParent: cd0df099bb0b82
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
@@ -12605,6 +12650,60 @@ mod tests {
1260512650 }
1260612651 }
1260712652
12653+ /// The wheel during playback. A scroll away from the playing head used to
12654+ /// be undone by the follow on the very next frame -- with a second, longer
12655+ /// media on the timeline making it scrollable at all, one notch in five
12656+ /// reached the screen and the wheel looked dead. The hand keeps the view
12657+ /// now, and the follow takes it back by itself when the head runs into what
12658+ /// the hand is looking at.
12659+ #[test]
12660+ fn a_scroll_during_playback_wins_until_the_head_catches_up() {
12661+ let duration = 80.;
12662+ let mut scale = test_view(Scale { pps: 40., start: 0. }, duration).settled();
12663+ // The render's arbitration, in the two lines it is there: a panned view
12664+ // is left where the hand put it, and the pan ends where the head is
12665+ // back on the bed.
12666+ let frame = |scale: Scale, panned: &mut bool, at: f64| {
12667+ let scale = match *panned {
12668+ true => test_view(scale, duration).settled(),
12669+ false => test_view(scale, duration).following(at),
12670+ };
12671+ if *panned && test_view(scale, duration).shows(at) {
12672+ *panned = false;
12673+ }
12674+ scale
12675+ };
12676+ // Playing at second one, five notches of the wheel: every one of them
12677+ // moves the view, and none is taken back by the head being off the bed.
12678+ let notch = f64::from(TEST_BED * SCROLL_NOTCH_SHARE);
12679+ let mut panned = false;
12680+ for n in 1..=5 {
12681+ scale = test_view(scale, duration).scrolled(TEST_BED * SCROLL_NOTCH_SHARE);
12682+ panned = true;
12683+ scale = frame(scale, &mut panned, 1.);
12684+ // ...and the pan is only *held* while the head is off the bed: the
12685+ // first notches still show it, so the follow has the view back for
12686+ // free and would not have moved anything anyway.
12687+ assert_eq!(panned, scale.start > 1., "held while the head is off");
12688+ assert!(
12689+ (scale.start - notch * f64::from(n) / 40.).abs() < 1e-6,
12690+ "notch {n} reached the screen: {scale:?}"
12691+ );
12692+ }
12693+ // The head runs into it: the pan is given back with nothing pressed...
12694+ let span = test_view(scale, duration).span();
12695+ let start = frame(scale, &mut panned, scale.start + span / 2.).start;
12696+ assert!(!panned, "the follow has the view back");
12697+ assert_eq!(start, scale.start, "and it did not jump to take it");
12698+ // ...and the next head that runs off the bed pulls the view again.
12699+ let ran_off = frame(scale, &mut panned, start + span + 1.);
12700+ assert!(ran_off.start > start, "the follow follows again: {ran_off:?}");
12701+ // A paused hand is untouched by any of this: with no follow asking,
12702+ // `shows` is the only thing the pan is ever released by.
12703+ assert!(test_view(scale, duration).shows(scale.start));
12704+ assert!(!test_view(scale, duration).shows(scale.start + span + 0.5));
12705+ }
12706+
1260812707 /// The bug this mapping exists for: the first import used to fill the whole
1260912708 /// track whatever it was, because the bed *was* the timeline -- so a 5 s
1261012709 /// clip was 100% of the lane, zooming out did nothing, and adding a second
@@ -16273,6 +16372,9 @@ fn main() {
1627316372 // zooms or asks for the fit: a project opens at a scale, not
1627416373 // at whatever its first import happens to be long.
1627516374 scale: Scale::default(),
16375+ // Nobody has scrolled anything yet, so the follow has the
16376+ // view: the first frame is drawn where the head is.
16377+ panned: false,
1627616378 selected: None,
1627716379 context_menu: None,
1627816380 picker: None,