Merge remote-tracking branch 'origin/main' into worktree-agent-a687c64e216de5a66
Browse files at this commit1 changed file +114 -12
- crates/app/src/main.rs +114 -12
crates/app/src/main.rsmodified+114 -12
| @@ -1179,6 +1179,15 @@ struct Player { | ||
| 1179 | 1179 | /// and nowhere else: every frame-to-pixel answer in the panel comes out of |
| 1180 | 1180 | /// it, so the boxes, the playhead and the pointer cannot disagree. |
| 1181 | 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 | 1191 | /// Which clip the edit keys act on: the lane it is in and its index there. |
| 1183 | 1192 | /// The *clicked* half, not the group -- a group is what gets marked on |
| 1184 | 1193 | /// screen, but Lift has to know which half it was aimed at. Indices move |
| @@ -1719,6 +1728,9 @@ impl Player { | ||
| 1719 | 1728 | // Restarted on every reseek, not only on the first: what it measures is |
| 1720 | 1729 | // the open now standing, which is what a person is waiting on. |
| 1721 | 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 | 1734 | // An edit moves the indices a drag in flight is holding -- a stroke |
| 1723 | 1735 | // during one is exactly that -- and an edge committed against a moved |
| 1724 | 1736 | // index would trim a clip nobody grabbed. Dropping it is the whole fix: |
| @@ -2131,6 +2143,10 @@ impl Player { | ||
| 2131 | 2143 | let at = self.playhead(view.duration); |
| 2132 | 2144 | let anchor = anchor.unwrap_or_else(|| self.scale.px_at(at).clamp(0., view.bed)); |
| 2133 | 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 | 2150 | cx.notify(); |
| 2135 | 2151 | } |
| 2136 | 2152 | |
| @@ -2154,6 +2170,10 @@ impl Player { | ||
| 2154 | 2170 | return; |
| 2155 | 2171 | } |
| 2156 | 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 | 2177 | cx.notify(); |
| 2158 | 2178 | } |
| 2159 | 2179 | |
| @@ -5455,6 +5475,9 @@ impl Player { | ||
| 5455 | 5475 | cx.notify(); |
| 5456 | 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 | 5481 | match self.transport() { |
| 5459 | 5482 | // Nothing open: the button is dimmed and the key says nothing. |
| 5460 | 5483 | Transport::Stopped => {} |
| @@ -5859,10 +5882,19 @@ impl Render for Player { | ||
| 5859 | 5882 | // is what a moving one does, during playback and through a seek. A view |
| 5860 | 5883 | // yanked back to a playhead nobody moved is a hand's own scroll undone |
| 5861 | 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 | 5892 | true => self.view().following(position), |
| 5864 | 5893 | false => self.view().settled(), |
| 5865 | 5894 | }; |
| 5895 | + if self.panned && self.view().shows(position) { | |
| 5896 | + self.panned = false; | |
| 5897 | + } | |
| 5866 | 5898 | |
| 5867 | 5899 | div() |
| 5868 | 5900 | .track_focus(&self.focus) |
| @@ -9238,19 +9270,32 @@ impl View { | ||
| 9238 | 9270 | return self.scale; |
| 9239 | 9271 | } |
| 9240 | 9272 | let scale = self.settled(); |
| 9273 | + if self.shows(at) { | |
| 9274 | + return scale; | |
| 9275 | + } | |
| 9241 | 9276 | 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; | |
| 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 | 12707 | /// The bug this mapping exists for: the first import used to fill the whole |
| 12609 | 12708 | /// track whatever it was, because the bed *was* the timeline -- so a 5 s |
| 12610 | 12709 | /// clip was 100% of the lane, zooming out did nothing, and adding a second |
| @@ -16273,6 +16372,9 @@ fn main() { | ||
| 16273 | 16372 | // zooms or asks for the fit: a project opens at a scale, not |
| 16274 | 16373 | // at whatever its first import happens to be long. |
| 16275 | 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 | 16378 | selected: None, |
| 16277 | 16379 | context_menu: None, |
| 16278 | 16380 | picker: None, |