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 {
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
@@ -12605,6 +12650,60 @@ mod tests {
12605 }12650 }
12606 }12651 }
12607 12652
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+
12608 /// The bug this mapping exists for: the first import used to fill the whole12707 /// The bug this mapping exists for: the first import used to fill the whole
12609 /// track whatever it was, because the bed *was* the timeline -- so a 5 s12708 /// track whatever it was, because the bed *was* the timeline -- so a 5 s
12610 /// clip was 100% of the lane, zooming out did nothing, and adding a second12709 /// clip was 100% of the lane, zooming out did nothing, and adding a second
@@ -16273,6 +16372,9 @@ fn main() {
16273 // zooms or asks for the fit: a project opens at a scale, not16372 // zooms or asks for the fit: a project opens at a scale, not
16274 // at whatever its first import happens to be long.16373 // at whatever its first import happens to be long.
16275 scale: Scale::default(),16374 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,
16276 selected: None,16378 selected: None,
16277 context_menu: None,16379 context_menu: None,
16278 picker: None,16380 picker: None,