forge
Explore
Log in

Don't you dare go Hollow

The far stop is the timeline's own length, so a five hour edit has an end

Browse files at this commit

69ff17ed864bb4cd0a2cbbec926277bb5662b035Ahmet Kaan GümüşParent: 27097e2
  • fix
    • the far stop is the timeline's own length, so a five hour edit has an end
Show full message
🐛 fix(zoom): the far stop is the timeline's own length, so a five hour edit has an end

Two 2:30:00 clips are five hours of timeline and the stop was four, so the
end of the second one could not be brought on screen by any zoom. The far
stop is the whole timeline on the bed plus a sliver now, and short of a
pixel to the second (PPS_MIN) the length is not worth widening to -- so a
short import still zooms out and the resting scale is still nobody's
content. The zoom pill counts hours once there are hours to count.
crates/app/src/main.rsmodified+109 -22
@@ -1720,7 +1720,7 @@ impl Player {
17201720 /// pixels along the bed to hold still (a ctrl+wheel holds the pointer), and
17211721 /// with none it is the playhead -- so the frame being worked on is still the
17221722 /// 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.
17241724 fn zoom(&mut self, factor: f32, anchor: Option<f32>, cx: &mut Context<Self>) {
17251725 let view = self.view();
17261726 let at = self.playhead(view.duration);
@@ -5995,7 +5995,7 @@ impl Player {
59955995 None,
59965996 "−",
59975997 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",
59995999 key(ActionId::ZoomOut)
60006000 ),
60016001 live,
@@ -11173,10 +11173,15 @@ const ZOOM_STEP: f32 = 1.25;
1117311173 /// not an edit surface.
1117411174 const ZOOM_MIN_FRAMES: f64 = 8.;
1117511175
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;
1118011185
1118111186 /// How wide a second of timeline is drawn before anyone zooms: a five second
1118211187 /// 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.;
1118911194 fn span_label(span: f64) -> String {
1119011195 match span {
1119111196 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.),
1119211201 s if s >= 600. => format!("{:.0}m", s / 60.),
1119311202 s if s >= 60. => format!("{:.1}m", s / 60.),
1119411203 s if s >= 10. => format!("{s:.0}s"),
@@ -11288,22 +11297,36 @@ impl View {
1128811297 }
1128911298
1129011299 /// 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.
1129511312 fn stops(self) -> Option<(f64, f64)> {
1129611313 (self.bed > 0.).then(|| {
1129711314 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);
1129911320 (min, (bed * self.fps / ZOOM_MIN_FRAMES).max(min))
1130011321 })
1130111322 }
1130211323
1130311324 /// Clamped to the bed it draws on: between the two stops, and never
1130411325 /// 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`].
1130711330 fn settled(self) -> Scale {
1130811331 let pps = match self.scale.pps.is_finite() && self.scale.pps > 0. {
1130911332 true => self.scale.pps,
@@ -12360,9 +12383,9 @@ mod tests {
1236012383 whole_take, window_title,
1236112384 };
1236212385 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,
1236412387 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,
1236612389 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,
1236712390 note_progress, px_along,
1236812391 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,
@@ -14048,10 +14071,10 @@ mod tests {
1404814071 }
1404914072 }
1405014073
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.
1405514078 #[test]
1405614079 fn zoom_stops_at_a_bedful_of_time_and_at_a_handful_of_frames() {
1405714080 let (duration, fps) = (20., 30.);
@@ -14060,8 +14083,8 @@ mod tests {
1406014083 scale = test_view(scale, duration).zoomed(1. / ZOOM_STEP, 100.);
1406114084 }
1406214085 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"
1406514088 );
1406614089 for _ in 0..200 {
1406714090 scale = test_view(scale, duration).zoomed(ZOOM_STEP, 100.);
@@ -14115,6 +14138,68 @@ mod tests {
1411514138 assert_eq!(unpainted.following(19.), unpainted.scale);
1411614139 }
1411714140
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+
1411814203 /// What makes a zoomed timeline follow the playing head: off the bed at
1411914204 /// either end pulls the view onto it, and on the bed it never moves -- a
1412014205 /// view that jumped every frame would be unreadable.
@@ -14206,7 +14291,9 @@ mod tests {
1420614291 assert_eq!(span_label(4.5), "4.5s");
1420714292 assert_eq!(span_label(22.5), "22s");
1420814293 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");
1421014297 // Before the first paint there is no bed and so no answer to give.
1421114298 assert_eq!(span_label(0.), "—");
1421214299 assert_eq!(span_label(f64::NAN), "—");