The far stop is the timeline's own length, so a five hour edit has an end
Browse files at this commit69ff17ed864bb4cd0a2cbbec926277bb5662b035Parent: 27097e2- fix
- the far stop is the timeline's own length, so a five hour edit has an end
1 changed file +109 -22
- crates/app/src/main.rs +109 -22
crates/app/src/main.rsmodified+109 -22
| @@ -1720,7 +1720,7 @@ impl Player { | ||
| 1720 | 1720 | /// pixels along the bed to hold still (a ctrl+wheel holds the pointer), and |
| 1721 | 1721 | /// with none it is the playhead -- so the frame being worked on is still the |
| 1722 | 1722 | /// frame on screen after the zoom. Clamped at both ends by [`View`]: out |
| 1723 | - /// stops at [`ZOOM_MAX_SECONDS`] on the bed, in at a handful of frames. | |
| 1723 | + /// stops at the whole timeline on the bed, in at a handful of frames. | |
| 1724 | 1724 | fn zoom(&mut self, factor: f32, anchor: Option<f32>, cx: &mut Context<Self>) { |
| 1725 | 1725 | let view = self.view(); |
| 1726 | 1726 | let at = self.playhead(view.duration); |
| @@ -5995,7 +5995,7 @@ impl Player { | ||
| 5995 | 5995 | None, |
| 5996 | 5996 | "−", |
| 5997 | 5997 | format!( |
| 5998 | - "{} — show more of the timeline; stops at four hours on the bed", | |
| 5998 | + "{} — show more of the timeline; stops with all of it on the bed", | |
| 5999 | 5999 | key(ActionId::ZoomOut) |
| 6000 | 6000 | ), |
| 6001 | 6001 | live, |
| @@ -11173,10 +11173,15 @@ const ZOOM_STEP: f32 = 1.25; | ||
| 11173 | 11173 | /// not an edit surface. |
| 11174 | 11174 | const ZOOM_MIN_FRAMES: f64 = 8.; |
| 11175 | 11175 | |
| 11176 | -/// How much timeline the bed may be widened out to hold. The far stop, and the | |
| 11177 | -/// counterpart of [`ZOOM_MIN_FRAMES`]: both are measured against the bed, never | |
| 11178 | -/// against what is on the timeline, so neither moves when a clip is added. | |
| 11179 | -const ZOOM_MAX_SECONDS: f64 = 4. * 3600.; | |
| 11176 | +/// How thin a second of timeline may be drawn on a bed that is already showing | |
| 11177 | +/// all of it: the far stop for a *short* project, which has no length of its own | |
| 11178 | +/// worth widening to, so a five second import can still be zoomed out of. | |
| 11179 | +const PPS_MIN: f64 = 1.; | |
| 11180 | + | |
| 11181 | +/// How much bed the far stop leaves past the last frame, as a multiple of the | |
| 11182 | +/// timeline's own length -- so a timeline zoomed all the way out ends a sliver | |
| 11183 | +/// short of the window's edge rather than glued to it. | |
| 11184 | +const ZOOM_OUT_MARGIN: f64 = 1.05; | |
| 11180 | 11185 | |
| 11181 | 11186 | /// How wide a second of timeline is drawn before anyone zooms: a five second |
| 11182 | 11187 | /// import is 200 px of a bed several times that, so a short clip reads as |
| @@ -11189,6 +11194,10 @@ const PPS_DEFAULT: f64 = 40.; | ||
| 11189 | 11194 | fn span_label(span: f64) -> String { |
| 11190 | 11195 | match span { |
| 11191 | 11196 | s if !s.is_finite() || s <= 0. => "—".to_string(), |
| 11197 | + // Hours once a timeline is long enough to be measured in them: the far | |
| 11198 | + // stop follows the content now, so "315m" is a span a user can be sat | |
| 11199 | + // at, and no one reads a pill in minutes past sixty. | |
| 11200 | + s if s >= 3600. => format!("{:.1}h", s / 3600.), | |
| 11192 | 11201 | s if s >= 600. => format!("{:.0}m", s / 60.), |
| 11193 | 11202 | s if s >= 60. => format!("{:.1}m", s / 60.), |
| 11194 | 11203 | s if s >= 10. => format!("{s:.0}s"), |
| @@ -11288,22 +11297,36 @@ impl View { | ||
| 11288 | 11297 | } |
| 11289 | 11298 | |
| 11290 | 11299 | /// The two stops, in pixels per second: [`ZOOM_MIN_FRAMES`] across the bed |
| 11291 | - /// is as tight as it goes, [`ZOOM_MAX_SECONDS`] across it as wide. `None` | |
| 11292 | - /// on a bed that was never painted -- there is nothing to measure them | |
| 11293 | - /// against yet, and a stop guessed off a zero width would throw away a zoom | |
| 11294 | - /// the user asked for. | |
| 11300 | + /// is as tight as it goes, and as wide as it goes is the whole timeline on | |
| 11301 | + /// the bed with [`ZOOM_OUT_MARGIN`] to spare -- the far stop is *relative*, | |
| 11302 | + /// so the end of a five hour timeline is reachable for the same reason the | |
| 11303 | + /// end of a five minute one is. A fixed far stop could not say that: a | |
| 11304 | + /// timeline longer than it had an end no zoom could reach, which is the bug | |
| 11305 | + /// this is. Short of [`PPS_MIN`] the timeline's own length is not worth | |
| 11306 | + /// widening to and the pixel takes over, so a short import can still be | |
| 11307 | + /// zoomed out of and the resting scale is nobody's content. | |
| 11308 | + /// | |
| 11309 | + /// `None` on a bed that was never painted -- there is nothing to measure | |
| 11310 | + /// them against yet, and a stop guessed off a zero width would throw away a | |
| 11311 | + /// zoom the user asked for. | |
| 11295 | 11312 | fn stops(self) -> Option<(f64, f64)> { |
| 11296 | 11313 | (self.bed > 0.).then(|| { |
| 11297 | 11314 | let bed = f64::from(self.bed); |
| 11298 | - let min = bed / ZOOM_MAX_SECONDS; | |
| 11315 | + let whole = match self.duration > 0. { | |
| 11316 | + true => bed / (self.duration * ZOOM_OUT_MARGIN), | |
| 11317 | + false => PPS_MIN, | |
| 11318 | + }; | |
| 11319 | + let min = whole.min(PPS_MIN); | |
| 11299 | 11320 | (min, (bed * self.fps / ZOOM_MIN_FRAMES).max(min)) |
| 11300 | 11321 | }) |
| 11301 | 11322 | } |
| 11302 | 11323 | |
| 11303 | 11324 | /// Clamped to the bed it draws on: between the two stops, and never |
| 11304 | 11325 | /// scrolled past either end of the timeline. Unlike the fractional view |
| 11305 | - /// this replaced, the *floor* is not the content -- a five second timeline | |
| 11306 | - /// zooms out as far as an hour long one does. | |
| 11326 | + /// this replaced, the *resting* scale is not the content -- a five second | |
| 11327 | + /// timeline zooms out as far as an hour long one does, and both are drawn | |
| 11328 | + /// at [`PPS_DEFAULT`] until someone zooms. Only the far stop knows the | |
| 11329 | + /// length, and only once the length is worth more than [`PPS_MIN`]. | |
| 11307 | 11330 | fn settled(self) -> Scale { |
| 11308 | 11331 | let pps = match self.scale.pps.is_finite() && self.scale.pps > 0. { |
| 11309 | 11332 | true => self.scale.pps, |
| @@ -12360,9 +12383,9 @@ mod tests { | ||
| 12360 | 12383 | whole_take, window_title, |
| 12361 | 12384 | }; |
| 12362 | 12385 | use super::{ |
| 12363 | - Choice, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, PPS_DEFAULT, Preset, RESOLUTIONS, Repeat, | |
| 12386 | + Choice, ETA_SPAN, Edge, FITS, FRAME_RATES, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat, | |
| 12364 | 12387 | Scale, View, |
| 12365 | - ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri, | |
| 12388 | + ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri, | |
| 12366 | 12389 | fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution, |
| 12367 | 12390 | note_progress, px_along, |
| 12368 | 12391 | repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label, |
| @@ -14048,10 +14071,10 @@ mod tests { | ||
| 14048 | 14071 | } |
| 14049 | 14072 | } |
| 14050 | 14073 | |
| 14051 | - /// Both stops, and the point of the whole mapping: neither is the content's | |
| 14052 | - /// own length any more. Out is [`ZOOM_MAX_SECONDS`] across the bed, in is | |
| 14053 | - /// [`ZOOM_MIN_FRAMES`] across it -- so a short import can be zoomed out of | |
| 14054 | - /// and a long one zoomed into, and neither can scroll off an end. | |
| 14074 | + /// Both stops. In is [`ZOOM_MIN_FRAMES`] across the bed; out, on a timeline | |
| 14075 | + /// far too short to be worth widening to, is a pixel to the second -- so a | |
| 14076 | + /// short import can be zoomed out of, a long one zoomed into, and neither | |
| 14077 | + /// can scroll off an end. | |
| 14055 | 14078 | #[test] |
| 14056 | 14079 | fn zoom_stops_at_a_bedful_of_time_and_at_a_handful_of_frames() { |
| 14057 | 14080 | let (duration, fps) = (20., 30.); |
| @@ -14060,8 +14083,8 @@ mod tests { | ||
| 14060 | 14083 | scale = test_view(scale, duration).zoomed(1. / ZOOM_STEP, 100.); |
| 14061 | 14084 | } |
| 14062 | 14085 | assert!( |
| 14063 | - (test_view(scale, duration).span() - ZOOM_MAX_SECONDS).abs() < 1e-6, | |
| 14064 | - "widest is a bedful of hours, not the 20 s that happen to be on it" | |
| 14086 | + (test_view(scale, duration).span() - f64::from(TEST_BED) / PPS_MIN).abs() < 1e-6, | |
| 14087 | + "widest is a pixel to the second, not the 20 s that happen to be on it" | |
| 14065 | 14088 | ); |
| 14066 | 14089 | for _ in 0..200 { |
| 14067 | 14090 | scale = test_view(scale, duration).zoomed(ZOOM_STEP, 100.); |
| @@ -14115,6 +14138,68 @@ mod tests { | ||
| 14115 | 14138 | assert_eq!(unpainted.following(19.), unpainted.scale); |
| 14116 | 14139 | } |
| 14117 | 14140 | |
| 14141 | + /// The bug a fixed far stop was: two two-and-a-half hour clips are five | |
| 14142 | + /// hours of timeline, longer than any stop measured in hours, so the end of | |
| 14143 | + /// the second one could not be brought on screen by any zoom. The stop is | |
| 14144 | + /// the timeline's own length now, so it can. | |
| 14145 | + #[test] | |
| 14146 | + fn zooming_out_reaches_the_end_of_a_timeline_however_long_it_is() { | |
| 14147 | + let bed = 900.; | |
| 14148 | + let view = |scale: Scale, duration: f64| View { | |
| 14149 | + scale, | |
| 14150 | + bed, | |
| 14151 | + duration, | |
| 14152 | + fps: 30., | |
| 14153 | + }; | |
| 14154 | + // As far out as the keys go, from the scale a fresh project is drawn at. | |
| 14155 | + let out = |duration: f64| { | |
| 14156 | + let mut scale = Scale::default(); | |
| 14157 | + for _ in 0..400 { | |
| 14158 | + scale = view(scale, duration).zoomed(1. / ZOOM_STEP, 0.); | |
| 14159 | + } | |
| 14160 | + scale | |
| 14161 | + }; | |
| 14162 | + let five_hours = 2. * 2.5 * 3600.; | |
| 14163 | + let wide = out(five_hours); | |
| 14164 | + // The whole five hours is on the bed, the last frame drawn inside the | |
| 14165 | + // window rather than against its edge. | |
| 14166 | + assert_eq!(wide.start, 0.); | |
| 14167 | + let end = wide.px_at(five_hours); | |
| 14168 | + assert!(end < bed, "the end of the timeline is off the bed at {end} px"); | |
| 14169 | + assert!(end > bed * 0.9, "and not shrunk into a corner: {end} px"); | |
| 14170 | + assert!( | |
| 14171 | + (view(wide, five_hours).span() - five_hours * ZOOM_OUT_MARGIN).abs() < 1e-6, | |
| 14172 | + "the far stop is the timeline plus its margin" | |
| 14173 | + ); | |
| 14174 | + // Zooming back in still reaches the frame stop on a timeline that long: | |
| 14175 | + // the far stop moving does not drag the near one with it. | |
| 14176 | + let mut scale = wide; | |
| 14177 | + for _ in 0..400 { | |
| 14178 | + scale = view(scale, five_hours).zoomed(ZOOM_STEP, 0.); | |
| 14179 | + } | |
| 14180 | + assert_eq!( | |
| 14181 | + (view(scale, five_hours).span() * 30.).round(), | |
| 14182 | + ZOOM_MIN_FRAMES | |
| 14183 | + ); | |
| 14184 | + // And a ten second project is not zoomed out to four hours of empty | |
| 14185 | + // bed: short of a pixel to the second its own length is not worth | |
| 14186 | + // widening to, and that is 900 s of bed, not 14400. | |
| 14187 | + assert!((view(out(10.), 10.).span() - f64::from(bed) / PPS_MIN).abs() < 1e-6); | |
| 14188 | + // Whatever the length, the resting scale is nobody's content: the width | |
| 14189 | + // invariant, which a far stop measured off the content would break. | |
| 14190 | + assert_eq!(view(Scale::default(), 10.).settled(), Scale::default()); | |
| 14191 | + assert_eq!(view(Scale::default(), five_hours).settled(), Scale::default()); | |
| 14192 | + // Shrinking the timeline pulls a fully zoomed out view in with it -- | |
| 14193 | + // what was showing all of the timeline still shows all of it. | |
| 14194 | + let shrunk = view(wide, 1800.).settled(); | |
| 14195 | + assert!((view(shrunk, 1800.).span() - 1800. * ZOOM_OUT_MARGIN).abs() < 1e-6); | |
| 14196 | + assert!(shrunk.px_at(1800.) < bed); | |
| 14197 | + // Growing it does not: a scale the user zoomed to is still legal, and | |
| 14198 | + // the stop it stopped at is one press further out. | |
| 14199 | + assert_eq!(view(wide, 2. * five_hours).settled().pps, wide.pps); | |
| 14200 | + assert!(view(wide, 2. * five_hours).zoomed(1. / ZOOM_STEP, 0.).pps < wide.pps); | |
| 14201 | + } | |
| 14202 | + | |
| 14118 | 14203 | /// What makes a zoomed timeline follow the playing head: off the bed at |
| 14119 | 14204 | /// either end pulls the view onto it, and on the bed it never moves -- a |
| 14120 | 14205 | /// view that jumped every frame would be unreadable. |
| @@ -14206,7 +14291,9 @@ mod tests { | ||
| 14206 | 14291 | assert_eq!(span_label(4.5), "4.5s"); |
| 14207 | 14292 | assert_eq!(span_label(22.5), "22s"); |
| 14208 | 14293 | assert_eq!(span_label(90.), "1.5m"); |
| 14209 | - assert_eq!(span_label(3600.), "60m"); | |
| 14294 | + assert_eq!(span_label(3600.), "1.0h"); | |
| 14295 | + // The span a five hour timeline is zoomed all the way out to. | |
| 14296 | + assert_eq!(span_label(5. * 3600. * 1.05), "5.2h"); | |
| 14210 | 14297 | // Before the first paint there is no bed and so no answer to give. |
| 14211 | 14298 | assert_eq!(span_label(0.), "—"); |
| 14212 | 14299 | assert_eq!(span_label(f64::NAN), "—"); |