forge
Explore
Log in

Don't you dare go Hollow

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

Browse files at this commit

1609d29ef15938c915565c77e7de5ed80774f533Ahmet Kaan GümüşParent: 74a068ecb80597
crates/app/src/main.rsmodified+233 -20
@@ -1022,9 +1022,12 @@ struct Player {
1022 /// what keeps a finished decoder from reading as [`Transport::Ended`] one1022 /// what keeps a finished decoder from reading as [`Transport::Ended`] one
1023 /// tick early. See [`Player::transport`].1023 /// tick early. See [`Player::transport`].
1024 held: Option<Frame>,1024 held: Option<Frame>,
1025- /// A seek is waiting for its frame. Keeps the repaint loop alive while1025+ /// A seek is waiting for its frame, and since when. Keeps the repaint loop
1026- /// paused, which is the only way the new still ever reaches the screen.1026+ /// alive while paused, which is the only way the new still ever reaches the
1027- pending_seek: bool,1027+ /// screen; the instant is what a drag's samples are gated on
1028+ /// ([`Player::flush_drag`]) and what says so in words when one open stands
1029+ /// too long ([`seek_line`]).
1030+ seek_since: Option<Instant>,
1028 /// The ruler's own box, recorded at prepaint: a mouse listener is handed1031 /// The ruler's own box, recorded at prepaint: a mouse listener is handed
1029 /// the window position and nothing else.1032 /// the window position and nothing else.
1030 ruler: Rc<Cell<Bounds<Pixels>>>,1033 ruler: Rc<Cell<Bounds<Pixels>>>,
@@ -1265,6 +1268,10 @@ struct Player {
1265 /// The bar is being dragged. On the root like the colour card's, for the1268 /// The bar is being dragged. On the root like the colour card's, for the
1266 /// same reason: the pointer leaves a 4 px bar on the first move.1269 /// same reason: the pointer leaves a 4 px bar on the first move.
1267 speed_dragging: bool,1270 speed_dragging: bool,
1271+ /// The rate the hand is on, held back because the worker still owes a frame
1272+ /// ([`Player::flush_drag`]). What the bar draws while it stands, so the
1273+ /// handle stays under the hand even though the picture has not caught up.
1274+ pending_speed: Option<Speed>,
1268 /// The mix card is up: every audio track's own volume and the master1275 /// The mix card is up: every audio track's own volume and the master
1269 /// limiter, which are project settings and not any clip's -- so unlike the1276 /// limiter, which are project settings and not any clip's -- so unlike the
1270 /// four clip cards there is no handle to hold, only whether it is open.1277 /// four clip cards there is no handle to hold, only whether it is open.
@@ -1316,6 +1323,13 @@ struct Player {
1316 /// ([`frac_along`]). One per band, because the press picks the row it landed1323 /// ([`frac_along`]). One per band, because the press picks the row it landed
1317 /// on and the drag then belongs to that row's range.1324 /// on and the drag then belongs to that row's range.
1318 color_bars: [Rc<Cell<Bounds<Pixels>>>; COLOR_BANDS.len()],1325 color_bars: [Rc<Cell<Bounds<Pixels>>>; COLOR_BANDS.len()],
1326+ /// The grade the hand is on, held back because the worker still owes a
1327+ /// frame ([`Player::flush_drag`]): a live write into a busy worker only
1328+ /// cancels the open the picture is already waiting for, so a bar-wide sweep
1329+ /// would pay for forty of them and show one. What the sliders draw while it
1330+ /// stands, and never lost -- the frame that lands writes it, and so does the
1331+ /// release.
1332+ pending_color: Option<ColorParams>,
1319 /// The frame on screen counted into `HIST_BINS` bins per channel -- the1333 /// The frame on screen counted into `HIST_BINS` bins per channel -- the
1320 /// *graded* frame, because the grade is applied in the decode worker and1334 /// *graded* frame, because the grade is applied in the decode worker and
1321 /// what arrives here is already through it. Refilled by every pumped frame,1335 /// what arrives here is already through it. Refilled by every pumped frame,
@@ -1381,7 +1395,7 @@ impl Player {
1381 1395
1382 if let Some(frame) = newest {1396 if let Some(frame) = newest {
1383 self.displayed += 1;1397 self.displayed += 1;
1384- self.pending_seek = false;1398+ self.seek_since = None;
1385 self.started.get_or_insert_with(|| {1399 self.started.get_or_insert_with(|| {
1386 eprintln!("first frame displayed (index {})", frame.index);1400 eprintln!("first frame displayed (index {})", frame.index);
1387 Instant::now()1401 Instant::now()
@@ -1404,9 +1418,9 @@ impl Player {
1404 1418
1405 if self.transport() == Transport::Ended {1419 if self.transport() == Transport::Ended {
1406 // A seek whose worker never produced a frame (vanished file) would1420 // A seek whose worker never produced a frame (vanished file) would
1407- // otherwise repaint at vsync forever. Held true for as long as the1421+ // otherwise repaint at vsync forever. Held clear for as long as the
1408 // state does, not just on the crossing: nothing else is coming.1422 // state does, not just on the crossing: nothing else is coming.
1409- self.pending_seek = false;1423+ self.seek_since = None;
1410 if was != Transport::Ended {1424 if was != Transport::Ended {
1411 // Ended is a *stopped* transport, so the clock stops with it,1425 // Ended is a *stopped* transport, so the clock stops with it,
1412 // on the out point the timecode and the playhead have been1426 // on the out point the timecode and the playhead have been
@@ -1452,7 +1466,9 @@ impl Player {
1452 /// edits reseek inside the engine and still owe this.1466 /// edits reseek inside the engine and still owe this.
1453 fn reset_after_reseek(&mut self) {1467 fn reset_after_reseek(&mut self) {
1454 self.held = None;1468 self.held = None;
1455- self.pending_seek = true;1469+ // Restarted on every reseek, not only on the first: what it measures is
1470+ // the open now standing, which is what a person is waiting on.
1471+ self.seek_since = Some(Instant::now());
1456 // An edit moves the indices a drag in flight is holding -- a stroke1472 // An edit moves the indices a drag in flight is holding -- a stroke
1457 // during one is exactly that -- and an edge committed against a moved1473 // during one is exactly that -- and an edge committed against a moved
1458 // index would trim a clip nobody grabbed. Dropping it is the whole fix:1474 // index would trim a clip nobody grabbed. Dropping it is the whole fix:
@@ -1912,6 +1928,9 @@ impl Player {
1912 self.color_open = Some(clip);1928 self.color_open = Some(clip);
1913 self.color_band = 0;1929 self.color_band = 0;
1914 self.color_dragging = false;1930 self.color_dragging = false;
1931+ // A sample the last card held back belongs to the clip it was
1932+ // dragged on, and this may be another one.
1933+ self.pending_color = None;
1915 // One card at a time, the rule both the others already follow.1934 // One card at a time, the rule both the others already follow.
1916 self.keys_open = false;1935 self.keys_open = false;
1917 self.export_open = false;1936 self.export_open = false;
@@ -1923,8 +1942,13 @@ impl Player {
1923 }1942 }
1924 1943
1925 /// What the card's clip is graded by right now -- the identity for one1944 /// What the card's clip is graded by right now -- the identity for one
1926- /// nobody has graded, which is what the sliders start at.1945+ /// nobody has graded, which is what the sliders start at. A sample a drag is
1946+ /// still holding wins over the clip's own: it is what the hand has asked
1947+ /// for, so it is what the sliders show and what the next sample builds on.
1927 fn color_params(&self) -> ColorParams {1948 fn color_params(&self) -> ColorParams {
1949+ if let Some(params) = self.pending_color {
1950+ return params;
1951+ }
1928 self.color_open1952 self.color_open
1929 .zip(self.session.as_ref())1953 .zip(self.session.as_ref())
1930 .and_then(|((lane, idx), session)| session.color_of(lane, idx).copied())1954 .and_then(|((lane, idx), session)| session.color_of(lane, idx).copied())
@@ -1946,6 +1970,9 @@ impl Player {
1946 /// (`PlaybackSession::set_color_live`). Either way the engine reseeks, so1970 /// (`PlaybackSession::set_color_live`). Either way the engine reseeks, so
1947 /// the picture -- and the histogram counted off it -- is regraded at once.1971 /// the picture -- and the histogram counted off it -- is regraded at once.
1948 fn write_color(&mut self, params: ColorParams, live: bool, cx: &mut Context<Self>) {1972 fn write_color(&mut self, params: ColorParams, live: bool, cx: &mut Context<Self>) {
1973+ // Any write supersedes a held sample, whichever way it arrived -- a key,
1974+ // a reset, or the flush that took this one out of the stash.
1975+ self.pending_color = None;
1949 let Some((lane, idx)) = self.color_open else {1976 let Some((lane, idx)) = self.color_open else {
1950 return;1977 return;
1951 };1978 };
@@ -1986,9 +2013,11 @@ impl Player {
1986 /// Values land on the [`COLOR_STEP`] grid the keys use, which also bounds2013 /// Values land on the [`COLOR_STEP`] grid the keys use, which also bounds
1987 /// one drag to forty-odd entries in the project's colour table.2014 /// one drag to forty-odd entries in the project's colour table.
1988 ///2015 ///
1989- /// ponytail: one reseek per step crossed, up to ~40 for a bar-wide sweep. If2016+ /// Samples crossed while the worker still owes a frame are held rather than
1990- /// that ever stutters, the throttle is [`scrub_due`]'s, which the ruler drag2017+ /// written ([`stash_or_write`]): a reopen costs half a second on a big film,
1991- /// already uses for the same cost.2018+ /// so a bar-wide sweep that wrote every step would queue forty opens, cancel
2019+ /// thirty-nine of them and freeze the window for the sum. What is written is
2020+ /// one grade per frame the worker actually delivers.
1992 fn drag_color(&mut self, x: Pixels, first: bool, cx: &mut Context<Self>) {2021 fn drag_color(&mut self, x: Pixels, first: bool, cx: &mut Context<Self>) {
1993 let (_, low, high) = COLOR_BANDS[self.color_band];2022 let (_, low, high) = COLOR_BANDS[self.color_band];
1994 let along = frac_along(x, self.color_bars[self.color_band].get());2023 let along = frac_along(x, self.color_bars[self.color_band].get());
@@ -1999,7 +2028,13 @@ impl Player {
1999 return;2028 return;
2000 }2029 }
2001 *at = value;2030 *at = value;
2002- self.write_color(params, !first, cx);2031+ let busy = self.seek_since.is_some();
2032+ match stash_or_write(&mut self.pending_color, params, first, busy) {
2033+ Some(params) => self.write_color(params, !first, cx),
2034+ // The sliders draw off the held sample, so the handle goes on
2035+ // following the hand while the picture catches up.
2036+ None => cx.notify(),
2037+ }
2003 }2038 }
2004 2039
2005 /// Opens the speed card on the clip whose rate is to change: the selected2040 /// Opens the speed card on the clip whose rate is to change: the selected
@@ -2023,6 +2058,8 @@ impl Player {
2023 Some(clip) => {2058 Some(clip) => {
2024 self.speed_open = Some(clip);2059 self.speed_open = Some(clip);
2025 self.speed_dragging = false;2060 self.speed_dragging = false;
2061+ // The colour card's rule: a held sample is the last clip's.
2062+ self.pending_speed = None;
2026 // One card at a time, the rule the other four follow.2063 // One card at a time, the rule the other four follow.
2027 self.keys_open = false;2064 self.keys_open = false;
2028 self.export_open = false;2065 self.export_open = false;
@@ -2039,6 +2076,9 @@ impl Player {
2039 /// What the card's clip plays at right now -- real time for one nobody has2076 /// What the card's clip plays at right now -- real time for one nobody has
2040 /// touched, which is where the bar starts.2077 /// touched, which is where the bar starts.
2041 fn card_speed(&self) -> Speed {2078 fn card_speed(&self) -> Speed {
2079+ if let Some(speed) = self.pending_speed {
2080+ return speed;
2081+ }
2042 self.speed_open2082 self.speed_open
2043 .zip(self.session.as_ref())2083 .zip(self.session.as_ref())
2044 .map_or(Speed::NORMAL, |((lane, idx), session)| {2084 .map_or(Speed::NORMAL, |((lane, idx), session)| {
@@ -2061,6 +2101,8 @@ impl Player {
2061 /// 2.00x is one undo press and lands back where the hand picked it up, and2101 /// 2.00x is one undo press and lands back where the hand picked it up, and
2062 /// the whole linked group comes back with it.2102 /// the whole linked group comes back with it.
2063 fn write_speed(&mut self, speed: Speed, live: bool, cx: &mut Context<Self>) {2103 fn write_speed(&mut self, speed: Speed, live: bool, cx: &mut Context<Self>) {
2104+ // The colour card's rule: a write supersedes whatever a drag was holding.
2105+ self.pending_speed = None;
2064 let Some((lane, idx)) = self.speed_open else {2106 let Some((lane, idx)) = self.speed_open else {
2065 return;2107 return;
2066 };2108 };
@@ -2102,7 +2144,31 @@ impl Player {
2102 // step of it: 1.00x is the one value a hand must be able to hit, and2144 // step of it: 1.00x is the one value a hand must be able to hit, and
2103 // nothing about the bar's geometry guarantees a pixel lands on it.2145 // nothing about the bar's geometry guarantees a pixel lands on it.
2104 let stepped = (raw / SPEED_STEP as f32).round() as i32 * SPEED_STEP;2146 let stepped = (raw / SPEED_STEP as f32).round() as i32 * SPEED_STEP;
2105- self.write_speed(speed_at(stepped), !first, cx);2147+ // Held back while the worker is busy, the colour card's way and for a
2148+ // sharper reason: a live rate also restarts the sound, so a sweep that
2149+ // wrote every step would restart it forty times.
2150+ let busy = self.seek_since.is_some();
2151+ match stash_or_write(&mut self.pending_speed, speed_at(stepped), first, busy) {
2152+ Some(speed) => self.write_speed(speed, !first, cx),
2153+ None => cx.notify(),
2154+ }
2155+ }
2156+
2157+ /// Writes what a slider drag held back, now that the worker has delivered.
2158+ /// The gate is the frame that landed and never a timer: a 100 ms tick
2159+ /// ([`SCRUB_GAP`]) says nothing about a reopen that costs half a second, and
2160+ /// a drag gated on one would still queue opens nobody sees.
2161+ ///
2162+ /// Called again by the release, where readiness is beside the point: the
2163+ /// value the hand let go on is owed whatever the worker is doing, and a
2164+ /// gesture may not end on a sample that was dropped.
2165+ fn flush_drag(&mut self, cx: &mut Context<Self>) {
2166+ if let Some(params) = self.pending_color.take() {
2167+ self.write_color(params, true, cx);
2168+ }
2169+ if let Some(speed) = self.pending_speed.take() {
2170+ self.write_speed(speed, true, cx);
2171+ }
2106 }2172 }
2107 2173
2108 /// Opens the silence card on the clip to be scanned: the selected one, or2174 /// Opens the silence card on the clip to be scanned: the selected one, or
@@ -3638,6 +3704,8 @@ impl Player {
3638 self.eq_dragging = false;3704 self.eq_dragging = false;
3639 self.speed_dragging = false;3705 self.speed_dragging = false;
3640 self.color_dragging = false;3706 self.color_dragging = false;
3707+ self.pending_color = None;
3708+ self.pending_speed = None;
3641 self.displayed = 0;3709 self.displayed = 0;
3642 self.dropped = 0;3710 self.dropped = 0;
3643 self.started = None;3711 self.started = None;
@@ -3652,7 +3720,7 @@ impl Player {
3652 // transport reads `Stopped` from the session being gone, so there is no3720 // transport reads `Stopped` from the session being gone, so there is no
3653 // end-of-stream state left to clear here.3721 // end-of-stream state left to clear here.
3654 self.reset_after_reseek();3722 self.reset_after_reseek();
3655- self.pending_seek = false;3723+ self.seek_since = None;
3656 }3724 }
3657 3725
3658 /// One item of a library row's menu, done. Every one of them closes the3726 /// One item of a library row's menu, done. Every one of them closes the
@@ -4483,6 +4551,11 @@ impl Render for Player {
4483 session.tick();4551 session.tick();
4484 }4552 }
4485 self.pump(window);4553 self.pump(window);
4554+ // A cleared seek is a frame delivered, which is the one readiness signal
4555+ // there is: whatever a slider drag held back is written here.
4556+ if self.seek_since.is_none() {
4557+ self.flush_drag(cx);
4558+ }
4486 self.poll_export();4559 self.poll_export();
4487 self.poll_import(cx);4560 self.poll_import(cx);
4488 // Every way a source can arrive -- argv, an import, a project load --4561 // Every way a source can arrive -- argv, an import, a project load --
@@ -4512,7 +4585,7 @@ impl Render for Player {
4512 // only reach the screen on a repaint, and a still line is the very4585 // only reach the screen on a repaint, and a still line is the very
4513 // thing it exists to disprove.4586 // thing it exists to disprove.
4514 if state.is_playing()4587 if state.is_playing()
4515- || self.pending_seek4588+ || self.seek_since.is_some()
4516 || self.export.is_some()4589 || self.export.is_some()
4517 || self.importing.is_some()4590 || self.importing.is_some()
4518 {4591 {
@@ -4961,7 +5034,11 @@ impl Render for Player {
4961 if event.pressed_button == Some(MouseButton::Left) {5034 if event.pressed_button == Some(MouseButton::Left) {
4962 this.drag_color(event.position.x, false, cx);5035 this.drag_color(event.position.x, false, cx);
4963 } else {5036 } else {
5037+ // The release happened outside the window, so this is
5038+ // where the gesture ends -- and it may not end on a
5039+ // sample the worker was too busy to take.
4964 this.color_dragging = false;5040 this.color_dragging = false;
5041+ this.flush_drag(cx);
4965 }5042 }
4966 return;5043 return;
4967 }5044 }
@@ -4972,6 +5049,7 @@ impl Render for Player {
4972 this.drag_speed(event.position.x, false, cx);5049 this.drag_speed(event.position.x, false, cx);
4973 } else {5050 } else {
4974 this.speed_dragging = false;5051 this.speed_dragging = false;
5052+ this.flush_drag(cx);
4975 }5053 }
4976 return;5054 return;
4977 }5055 }
@@ -5017,12 +5095,16 @@ impl Render for Player {
5017 if std::mem::take(&mut this.color_dragging) {5095 if std::mem::take(&mut this.color_dragging) {
5018 // The release lands exactly where the hand let go, and5096 // The release lands exactly where the hand let go, and
5019 // it is a live write like every other sample: the undo5097 // it is a live write like every other sample: the undo
5020- // step the gesture rolls back to was the press's.5098+ // step the gesture rolls back to was the press's. The
5099+ // flush is what makes "exactly" true while the worker is
5100+ // still busy -- the sample above would only be held.
5021 this.drag_color(event.position.x, false, cx);5101 this.drag_color(event.position.x, false, cx);
5102+ this.flush_drag(cx);
5022 return;5103 return;
5023 }5104 }
5024 if std::mem::take(&mut this.speed_dragging) {5105 if std::mem::take(&mut this.speed_dragging) {
5025 this.drag_speed(event.position.x, false, cx);5106 this.drag_speed(event.position.x, false, cx);
5107+ this.flush_drag(cx);
5026 return;5108 return;
5027 }5109 }
5028 if std::mem::take(&mut this.volume_dragging) {5110 if std::mem::take(&mut this.volume_dragging) {
@@ -5106,6 +5188,9 @@ impl Render for Player {
5106 // over the notice's: a notice is about something that has already5188 // over the notice's: a notice is about something that has already
5107 // happened, and this is about something still happening.5189 // happened, and this is about something still happening.
5108 .children(self.import_bar())5190 .children(self.import_bar())
5191+ // The same slot and the same reason: work still going on, said out
5192+ // loud because a still picture is the only other evidence of it.
5193+ .children(self.seek_bar())
5109 .children(self.notice_bar(cx))5194 .children(self.notice_bar(cx))
5110 .child(self.panel(position, duration, state, cx))5195 .child(self.panel(position, duration, state, cx))
5111 // Over the panel it was opened on, and under the cards: it is only5196 // Over the panel it was opened on, and under the cards: it is only
@@ -6465,6 +6550,22 @@ impl Player {
6465 )6550 )
6466 }6551 }
6467 6552
6553+ /// The line a long-standing seek shows, in the import bar's place and by the
6554+ /// import bar's rules: nothing dismisses it, and it leaves by itself the
6555+ /// moment the frame lands. No sweep under it -- an open reports nothing about
6556+ /// where it has got to, and the clock is the honest half of that bar anyway.
6557+ fn seek_bar(&self) -> Option<impl IntoElement> {
6558+ let line = seek_line(self.seek_since.map(|t| t.elapsed()))?;
6559+ Some(
6560+ div()
6561+ .flex_none()
6562+ .px(px(12.))
6563+ .py(px(6.))
6564+ .bg(rgb(SURFACE))
6565+ .child(line),
6566+ )
6567+ }
6568+
6468 /// A notice holds its own bar, full width, until it is answered: any key6569 /// A notice holds its own bar, full width, until it is answered: any key
6469 /// retires it (the key handler) and so does a click on it. Its own surface6570 /// retires it (the key handler) and so does a click on it. Its own surface
6470 /// because the message is the point -- a failure cut to the timecode's slot6571 /// because the message is the point -- a failure cut to the timecode's slot
@@ -9532,14 +9633,59 @@ impl Player {
9532 }9633 }
9533 9634
9534 /// Rate limit for scrub seeks: a video worker reopen costs 72-87 ms on the9635 /// Rate limit for scrub seeks: a video worker reopen costs 72-87 ms on the
9535-/// hardware path (215 ms in software), so one seek per mouse move would only9636+/// hardware path for the small files it was measured on (215 ms in software), so
9536-/// queue workers that are cancelled before they decode anything.9637+/// one seek per mouse move would only queue workers that are cancelled before
9638+/// they decode anything.
9639+///
9640+/// It is a *floor*, not a bound: the reopen is a demux open
9641+/// ([`engine::decode::open_worker`]), and on a 25 GB film that is 550-750 ms --
9642+/// five to seven times this gap, which therefore gates nothing there. Where the
9643+/// cost had to be bounded rather than thinned -- the colour and speed drags --
9644+/// the gate is the frame the worker delivers ([`Player::flush_drag`]) and no
9645+/// timer at all. The ruler keeps this one: a scrub has no value to hold back,
9646+/// only a position that the next mouse move replaces anyway.
9537 const SCRUB_GAP: Duration = Duration::from_millis(100);9647 const SCRUB_GAP: Duration = Duration::from_millis(100);
9538 9648
9539 fn scrub_due(target: u32, last_target: u32, since: Duration) -> bool {9649 fn scrub_due(target: u32, last_target: u32, since: Duration) -> bool {
9540 target != last_target && since >= SCRUB_GAP9650 target != last_target && since >= SCRUB_GAP
9541 }9651 }
9542 9652
9653+/// The gate a live drag sample goes through. With the worker still owing a
9654+/// frame (`busy`), writing now would only cancel the open the picture is already
9655+/// waiting for -- the sample is held in `stash` instead, and the frame that
9656+/// lands writes it ([`Player::flush_drag`]). Returns what to write, if anything.
9657+///
9658+/// The press (`first`) never waits: it is the undo step the whole gesture rolls
9659+/// back to, so it has to be taken against the state the hand picked up.
9660+fn stash_or_write<T: Copy>(stash: &mut Option<T>, value: T, first: bool, busy: bool) -> Option<T> {
9661+ match busy && !first {
9662+ true => {
9663+ *stash = Some(value);
9664+ None
9665+ }
9666+ false => Some(value),
9667+ }
9668+}
9669+
9670+/// How long an open may stand before the window says so in words. Well past an
9671+/// ordinary seek (a warm reopen is under a tenth of this) and well under what a
9672+/// cold read of a big film takes, which is the only case worth a line.
9673+const SEEK_STALL: Duration = Duration::from_secs(2);
9674+
9675+/// What a seek that has stood past [`SEEK_STALL`] says, and nothing at all
9676+/// before that: a line on every click of the ruler would be a flicker, and the
9677+/// picture holding still for a tenth of a second is not something to explain.
9678+/// The import bar's words, for the import bar's reason -- a window that cannot
9679+/// move and a window that has hung look identical, so this one says which.
9680+fn seek_line(standing: Option<Duration>) -> Option<String> {
9681+ let since = standing.filter(|d| *d >= SEEK_STALL)?;
9682+ Some(format!(
9683+ "still opening the picture — a cold read of a big file is seconds of it, and the window \
9684+ is not frozen · {} elapsed",
9685+ clock(since.as_secs_f32())
9686+ ))
9687+}
9688+
9543 /// How a finished export announces itself. Written by `poll_export` and read9689 /// How a finished export announces itself. Written by `poll_export` and read
9544 /// by the notice bar, which is what makes that one line clickable.9690 /// by the notice bar, which is what makes that one line clickable.
9545 const EXPORT_DONE: &str = "EXPORT DONE → ";9691 const EXPORT_DONE: &str = "EXPORT DONE → ";
@@ -12670,7 +12816,8 @@ mod tests {
12670 ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri,12816 ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri,
12671 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,12817 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,
12672 note_progress, px_along,12818 note_progress, px_along,
12673- IMPORT_STALL, Import, ImportStage, import_line, read_ahead,12819+ IMPORT_STALL, Import, ImportStage, SEEK_STALL, import_line, read_ahead, seek_line,
12820+ stash_or_write,
12674 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,12821 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,
12675 trimmed_clip, unscannable,12822 trimmed_clip, unscannable,
12676 visible_slice,12823 visible_slice,
@@ -15967,6 +16114,70 @@ mod tests {
15967 assert_eq!(import.since, held, "an unchanged stage must not reset it");16114 assert_eq!(import.since, held, "an unchanged stage must not reset it");
15968 }16115 }
15969 16116
16117+ /// One gesture over the real gate, with the plumbing around it spelled out:
16118+ /// a write reseeks (the worker owes a frame again), a landed frame clears
16119+ /// that and flushes what is held, and the release flushes whatever the
16120+ /// worker is doing. Forty snapped steps and four frames delivered must cost
16121+ /// five writes -- the press's and one per frame -- and not forty, which is
16122+ /// the 22-30 s freeze this exists to remove.
16123+ #[test]
16124+ fn a_bar_wide_sweep_writes_once_per_frame_delivered() {
16125+ let mut stash: Option<i32> = None;
16126+ let mut written = Vec::new();
16127+ let mut busy = false;
16128+ for step in 0..40 {
16129+ if let Some(value) = stash_or_write(&mut stash, step, step == 0, busy) {
16130+ // What `write_color` does: the write supersedes the stash and
16131+ // reseeks, so the worker owes a frame from here.
16132+ stash = None;
16133+ written.push(value);
16134+ busy = true;
16135+ }
16136+ // A frame lands every tenth sample: `pump` clears the seek and the
16137+ // render flushes what the drag held back.
16138+ if step % 10 == 9 {
16139+ busy = false;
16140+ if let Some(value) = stash.take() {
16141+ written.push(value);
16142+ busy = true;
16143+ }
16144+ }
16145+ }
16146+ // The release, whatever the worker is doing.
16147+ written.extend(stash.take());
16148+ assert_eq!(written, vec![0, 9, 19, 29, 39], "one write per frame landed");
16149+ }
16150+
16151+ /// The one value a gesture may never lose: where the hand let go. The
16152+ /// release samples into a busy worker -- so the sample is held -- and the
16153+ /// flush behind it is what writes it.
16154+ #[test]
16155+ fn a_release_lands_the_value_the_hand_let_go_on() {
16156+ let mut stash = None;
16157+ assert_eq!(stash_or_write(&mut stash, 7, false, true), None);
16158+ assert_eq!(stash_or_write(&mut stash, 11, false, true), None);
16159+ assert_eq!(stash.take(), Some(11), "the release writes the last sample");
16160+ // The press is never held: it is the undo step the gesture rolls back
16161+ // to, and one taken a frame late is a snapshot of the wrong grade.
16162+ assert_eq!(stash_or_write(&mut stash, 3, true, true), Some(3));
16163+ assert_eq!(stash, None);
16164+ // Nothing to hold when the worker is idle: the write goes straight out.
16165+ assert_eq!(stash_or_write(&mut stash, 5, false, false), Some(5));
16166+ assert_eq!(stash, None);
16167+ }
16168+
16169+ /// A seek says nothing until it has stood: an ordinary one is a flicker and
16170+ /// a cold read of a big file is the case worth words.
16171+ #[test]
16172+ fn a_seek_says_so_only_once_it_has_stood() {
16173+ assert_eq!(seek_line(None), None, "no seek, no line");
16174+ assert_eq!(seek_line(Some(Duration::from_millis(300))), None);
16175+ let line = seek_line(Some(SEEK_STALL + Duration::from_secs(7))).expect("past the stall");
16176+ assert!(line.contains("still opening the picture"), "{line}");
16177+ assert!(line.contains("not frozen"), "{line}");
16178+ assert!(line.contains("0:09 elapsed"), "{line}");
16179+ }
16180+
15970 /// The read-ahead is a *cache warmer* and nothing else: whatever it did or16181 /// The read-ahead is a *cache warmer* and nothing else: whatever it did or
15971 /// failed to do, the import that follows lands exactly the rows, lengths16182 /// failed to do, the import that follows lands exactly the rows, lengths
15972 /// and refusals it landed before there was a worker at all.16183 /// and refusals it landed before there was a worker at all.
@@ -17421,7 +17632,7 @@ fn main() {
17421 // same repaint a seek's still owes: nothing plays by17632 // same repaint a seek's still owes: nothing plays by
17422 // itself, so this is what carries the poster frame to the17633 // itself, so this is what carries the poster frame to the
17423 // screen. An empty window has none to wait for.17634 // screen. An empty window has none to wait for.
17424- pending_seek: session.is_some(),17635+ seek_since: session.is_some().then(Instant::now),
17425 session,17636 session,
17426 // Full and unmuted, which is what the session it was just17637 // Full and unmuted, which is what the session it was just
17427 // handed is already set to: nothing to push at startup.17638 // handed is already set to: nothing to push at startup.
@@ -17486,6 +17697,7 @@ fn main() {
17486 speed_open: None,17697 speed_open: None,
17487 speed_bar: Rc::default(),17698 speed_bar: Rc::default(),
17488 speed_dragging: false,17699 speed_dragging: false,
17700+ pending_speed: None,
17489 mix_open: false,17701 mix_open: false,
17490 mix_field: 0,17702 mix_field: 0,
17491 silence_open: None,17703 silence_open: None,
@@ -17506,6 +17718,7 @@ fn main() {
17506 color_band: 0,17718 color_band: 0,
17507 color_dragging: false,17719 color_dragging: false,
17508 color_bars: std::array::from_fn(|_| Rc::default()),17720 color_bars: std::array::from_fn(|_| Rc::default()),
17721+ pending_color: None,
17509 // Empty until the first frame is pumped, which draws as a17722 // Empty until the first frame is pumped, which draws as a
17510 // flat line rather than as a shape nothing measured.17723 // flat line rather than as a shape nothing measured.
17511 histogram: [[0; HIST_BINS]; 3],17724 histogram: [[0; HIST_BINS]; 3],
crates/engine/src/playback.rsmodified+1 -1
@@ -2374,7 +2374,7 @@ impl PlaybackSession {
2374 out: &Path,2374 out: &Path,
2375 settings: &crate::export::ExportSettings,2375 settings: &crate::export::ExportSettings,
2376 ) -> crate::ExportHandle {2376 ) -> crate::ExportHandle {
2377- crate::export::start(self.project.clone(), self.meta, out, settings)2377+ crate::export::start(self.project.export_snapshot(), self.meta, out, settings)
2378 }2378 }
2379 2379
2380 /// Moves the clock forward; the caller runs this once per rendered frame.2380 /// Moves the clock forward; the caller runs this once per rendered frame.
crates/engine/src/project.rsmodified+48 -1
@@ -618,6 +618,13 @@ pub type Parts = (
618 Vec<ColorParams>,618 Vec<ColorParams>,
619 );619 );
620 620
621+/// How many undo steps a project keeps. One gesture is one step, so 100 is past
622+/// any chain a person walks back by hand, and the oldest step is dropped rather
623+/// than the history growing without end: a snapshot is the whole lane list, so
624+/// on a 1394-clip jumpcut timeline this is a bounded ~10 MB instead of a leak
625+/// that grows for as long as the session lasts.
626+const HISTORY_CAP: usize = 100;
627+
621 /// The edit list plus its undo history.628 /// The edit list plus its undo history.
622 #[derive(Clone, Debug)]629 #[derive(Clone, Debug)]
623 pub struct Project {630 pub struct Project {
@@ -631,7 +638,8 @@ pub struct Project {
631 /// The same, for [`Clip::color`].638 /// The same, for [`Clip::color`].
632 color: Vec<ColorParams>,639 color: Vec<ColorParams>,
633 /// Snapshots pushed *before* each successful edit; `undo` pops one. The640 /// Snapshots pushed *before* each successful edit; `undo` pops one. The
634- /// whole lane list, so adding a lane undoes as well.641+ /// whole lane list, so adding a lane undoes as well. Bounded by
642+ /// [`HISTORY_CAP`]: at the cap the oldest step goes.
635 history: Vec<Vec<LaneData>>,643 history: Vec<Vec<LaneData>>,
636 /// Never rolled back by an undo: an id retired by an undone split must not644 /// Never rolled back by an undo: an id retired by an undone split must not
637 /// come back and group two clips that were never together.645 /// come back and group two clips that were never together.
@@ -2693,6 +2701,24 @@ impl Project {
2693 }2701 }
2694 }2702 }
2695 2703
2704+ /// The project an export renders from: everything a render reads, with the
2705+ /// undo history left behind. An export never walks the history back, and
2706+ /// cloning it costs a copy of every lane list in the session -- this is
2707+ /// taken on the UI thread, so it clones the lanes and the sources alone.
2708+ pub fn export_snapshot(&self) -> Self {
2709+ Self {
2710+ sources: self.sources.clone(),
2711+ lanes: self.lanes.clone(),
2712+ eq: self.eq.clone(),
2713+ color: self.color.clone(),
2714+ history: Vec::new(),
2715+ next_link: self.next_link,
2716+ subtitles: self.subtitles.clone(),
2717+ limiter: self.limiter,
2718+ tone: self.tone,
2719+ }
2720+ }
2721+
2696 /// Half-open `(source, start, end)` segments in *source* seconds, from2722 /// Half-open `(source, start, end)` segments in *source* seconds, from
2697 /// `timeline_frame` to the end of the timeline -- the play list for the2723 /// `timeline_frame` to the end of the timeline -- the play list for the
2698 /// audio worker, read off **`A1`**. A `None` source is a gap: the2724 /// audio worker, read off **`A1`**. A `None` source is a gap: the
@@ -2861,6 +2887,9 @@ impl Project {
2861 /// Pushes the undo snapshot. Every mutating method calls this once, *after*2887 /// Pushes the undo snapshot. Every mutating method calls this once, *after*
2862 /// it has decided it will succeed -- a refusal must not cost an undo step.2888 /// it has decided it will succeed -- a refusal must not cost an undo step.
2863 fn snapshot(&mut self) {2889 fn snapshot(&mut self) {
2890+ if self.history.len() == HISTORY_CAP {
2891+ self.history.remove(0);
2892+ }
2864 self.history.push(self.lanes.clone());2893 self.history.push(self.lanes.clone());
2865 }2894 }
2866 2895
@@ -4215,6 +4244,24 @@ mod tests {
4215 assert_eq!(shape(&p)[0], vec![clip(0, 0, 9, 0)]);4244 assert_eq!(shape(&p)[0], vec![clip(0, 0, 9, 0)]);
4216 }4245 }
4217 4246
4247+ /// Past the cap the *oldest* step goes, so a long session undoes exactly
4248+ /// `HISTORY_CAP` gestures and then runs dry -- it does not grow for ever.
4249+ #[test]
4250+ fn history_stops_at_the_cap() {
4251+ let mut p = Project::single(FILE, 400);
4252+ for frame in 1..=150 {
4253+ assert!(p.split(frame), "split {frame} is an edit");
4254+ }
4255+ assert_eq!(p.history.len(), HISTORY_CAP, "and only the last 100 kept");
4256+ for step in 0..HISTORY_CAP {
4257+ assert!(p.undo(), "undo {step} is inside the cap");
4258+ }
4259+ assert!(!p.undo(), "and the 101st has nothing left to take");
4260+ // 100 undos off 150 splits is the timeline after the 50th: the older
4261+ // steps were dropped, not the newer ones.
4262+ assert_eq!(p.clips().len(), 51);
4263+ }
4264+
4218 /// Undo/redo by hand across a split must never merge two takes into one4265 /// Undo/redo by hand across a split must never merge two takes into one
4219 /// group by reusing an id.4266 /// group by reusing an id.
4220 #[test]4267 #[test]