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 {
10221022 /// what keeps a finished decoder from reading as [`Transport::Ended`] one
10231023 /// tick early. See [`Player::transport`].
10241024 held: Option<Frame>,
1025- /// A seek is waiting for its frame. Keeps the repaint loop alive while
1026- /// paused, which is the only way the new still ever reaches the screen.
1027- pending_seek: bool,
1025+ /// A seek is waiting for its frame, and since when. Keeps the repaint loop
1026+ /// alive while paused, which is the only way the new still ever reaches the
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>,
10281031 /// The ruler's own box, recorded at prepaint: a mouse listener is handed
10291032 /// the window position and nothing else.
10301033 ruler: Rc<Cell<Bounds<Pixels>>>,
@@ -1265,6 +1268,10 @@ struct Player {
12651268 /// The bar is being dragged. On the root like the colour card's, for the
12661269 /// same reason: the pointer leaves a 4 px bar on the first move.
12671270 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>,
12681275 /// The mix card is up: every audio track's own volume and the master
12691276 /// limiter, which are project settings and not any clip's -- so unlike the
12701277 /// four clip cards there is no handle to hold, only whether it is open.
@@ -1316,6 +1323,13 @@ struct Player {
13161323 /// ([`frac_along`]). One per band, because the press picks the row it landed
13171324 /// on and the drag then belongs to that row's range.
13181325 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>,
13191333 /// The frame on screen counted into `HIST_BINS` bins per channel -- the
13201334 /// *graded* frame, because the grade is applied in the decode worker and
13211335 /// what arrives here is already through it. Refilled by every pumped frame,
@@ -1381,7 +1395,7 @@ impl Player {
13811395
13821396 if let Some(frame) = newest {
13831397 self.displayed += 1;
1384- self.pending_seek = false;
1398+ self.seek_since = None;
13851399 self.started.get_or_insert_with(|| {
13861400 eprintln!("first frame displayed (index {})", frame.index);
13871401 Instant::now()
@@ -1404,9 +1418,9 @@ impl Player {
14041418
14051419 if self.transport() == Transport::Ended {
14061420 // A seek whose worker never produced a frame (vanished file) would
1407- // otherwise repaint at vsync forever. Held true for as long as the
1421+ // otherwise repaint at vsync forever. Held clear for as long as the
14081422 // state does, not just on the crossing: nothing else is coming.
1409- self.pending_seek = false;
1423+ self.seek_since = None;
14101424 if was != Transport::Ended {
14111425 // Ended is a *stopped* transport, so the clock stops with it,
14121426 // on the out point the timecode and the playhead have been
@@ -1452,7 +1466,9 @@ impl Player {
14521466 /// edits reseek inside the engine and still owe this.
14531467 fn reset_after_reseek(&mut self) {
14541468 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());
14561472 // An edit moves the indices a drag in flight is holding -- a stroke
14571473 // during one is exactly that -- and an edge committed against a moved
14581474 // index would trim a clip nobody grabbed. Dropping it is the whole fix:
@@ -1912,6 +1928,9 @@ impl Player {
19121928 self.color_open = Some(clip);
19131929 self.color_band = 0;
19141930 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;
19151934 // One card at a time, the rule both the others already follow.
19161935 self.keys_open = false;
19171936 self.export_open = false;
@@ -1923,8 +1942,13 @@ impl Player {
19231942 }
19241943
19251944 /// 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.
19271948 fn color_params(&self) -> ColorParams {
1949+ if let Some(params) = self.pending_color {
1950+ return params;
1951+ }
19281952 self.color_open
19291953 .zip(self.session.as_ref())
19301954 .and_then(|((lane, idx), session)| session.color_of(lane, idx).copied())
@@ -1946,6 +1970,9 @@ impl Player {
19461970 /// (`PlaybackSession::set_color_live`). Either way the engine reseeks, so
19471971 /// the picture -- and the histogram counted off it -- is regraded at once.
19481972 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;
19491976 let Some((lane, idx)) = self.color_open else {
19501977 return;
19511978 };
@@ -1986,9 +2013,11 @@ impl Player {
19862013 /// Values land on the [`COLOR_STEP`] grid the keys use, which also bounds
19872014 /// one drag to forty-odd entries in the project's colour table.
19882015 ///
1989- /// ponytail: one reseek per step crossed, up to ~40 for a bar-wide sweep. If
1990- /// that ever stutters, the throttle is [`scrub_due`]'s, which the ruler drag
1991- /// already uses for the same cost.
2016+ /// Samples crossed while the worker still owes a frame are held rather than
2017+ /// written ([`stash_or_write`]): a reopen costs half a second on a big film,
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.
19922021 fn drag_color(&mut self, x: Pixels, first: bool, cx: &mut Context<Self>) {
19932022 let (_, low, high) = COLOR_BANDS[self.color_band];
19942023 let along = frac_along(x, self.color_bars[self.color_band].get());
@@ -1999,7 +2028,13 @@ impl Player {
19992028 return;
20002029 }
20012030 *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+ }
20032038 }
20042039
20052040 /// Opens the speed card on the clip whose rate is to change: the selected
@@ -2023,6 +2058,8 @@ impl Player {
20232058 Some(clip) => {
20242059 self.speed_open = Some(clip);
20252060 self.speed_dragging = false;
2061+ // The colour card's rule: a held sample is the last clip's.
2062+ self.pending_speed = None;
20262063 // One card at a time, the rule the other four follow.
20272064 self.keys_open = false;
20282065 self.export_open = false;
@@ -2039,6 +2076,9 @@ impl Player {
20392076 /// What the card's clip plays at right now -- real time for one nobody has
20402077 /// touched, which is where the bar starts.
20412078 fn card_speed(&self) -> Speed {
2079+ if let Some(speed) = self.pending_speed {
2080+ return speed;
2081+ }
20422082 self.speed_open
20432083 .zip(self.session.as_ref())
20442084 .map_or(Speed::NORMAL, |((lane, idx), session)| {
@@ -2061,6 +2101,8 @@ impl Player {
20612101 /// 2.00x is one undo press and lands back where the hand picked it up, and
20622102 /// the whole linked group comes back with it.
20632103 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;
20642106 let Some((lane, idx)) = self.speed_open else {
20652107 return;
20662108 };
@@ -2102,7 +2144,31 @@ impl Player {
21022144 // step of it: 1.00x is the one value a hand must be able to hit, and
21032145 // nothing about the bar's geometry guarantees a pixel lands on it.
21042146 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+ }
21062172 }
21072173
21082174 /// Opens the silence card on the clip to be scanned: the selected one, or
@@ -3638,6 +3704,8 @@ impl Player {
36383704 self.eq_dragging = false;
36393705 self.speed_dragging = false;
36403706 self.color_dragging = false;
3707+ self.pending_color = None;
3708+ self.pending_speed = None;
36413709 self.displayed = 0;
36423710 self.dropped = 0;
36433711 self.started = None;
@@ -3652,7 +3720,7 @@ impl Player {
36523720 // transport reads `Stopped` from the session being gone, so there is no
36533721 // end-of-stream state left to clear here.
36543722 self.reset_after_reseek();
3655- self.pending_seek = false;
3723+ self.seek_since = None;
36563724 }
36573725
36583726 /// One item of a library row's menu, done. Every one of them closes the
@@ -4483,6 +4551,11 @@ impl Render for Player {
44834551 session.tick();
44844552 }
44854553 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+ }
44864559 self.poll_export();
44874560 self.poll_import(cx);
44884561 // Every way a source can arrive -- argv, an import, a project load --
@@ -4512,7 +4585,7 @@ impl Render for Player {
45124585 // only reach the screen on a repaint, and a still line is the very
45134586 // thing it exists to disprove.
45144587 if state.is_playing()
4515- || self.pending_seek
4588+ || self.seek_since.is_some()
45164589 || self.export.is_some()
45174590 || self.importing.is_some()
45184591 {
@@ -4961,7 +5034,11 @@ impl Render for Player {
49615034 if event.pressed_button == Some(MouseButton::Left) {
49625035 this.drag_color(event.position.x, false, cx);
49635036 } 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.
49645040 this.color_dragging = false;
5041+ this.flush_drag(cx);
49655042 }
49665043 return;
49675044 }
@@ -4972,6 +5049,7 @@ impl Render for Player {
49725049 this.drag_speed(event.position.x, false, cx);
49735050 } else {
49745051 this.speed_dragging = false;
5052+ this.flush_drag(cx);
49755053 }
49765054 return;
49775055 }
@@ -5017,12 +5095,16 @@ impl Render for Player {
50175095 if std::mem::take(&mut this.color_dragging) {
50185096 // The release lands exactly where the hand let go, and
50195097 // 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.
50215101 this.drag_color(event.position.x, false, cx);
5102+ this.flush_drag(cx);
50225103 return;
50235104 }
50245105 if std::mem::take(&mut this.speed_dragging) {
50255106 this.drag_speed(event.position.x, false, cx);
5107+ this.flush_drag(cx);
50265108 return;
50275109 }
50285110 if std::mem::take(&mut this.volume_dragging) {
@@ -5106,6 +5188,9 @@ impl Render for Player {
51065188 // over the notice's: a notice is about something that has already
51075189 // happened, and this is about something still happening.
51085190 .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())
51095194 .children(self.notice_bar(cx))
51105195 .child(self.panel(position, duration, state, cx))
51115196 // Over the panel it was opened on, and under the cards: it is only
@@ -6465,6 +6550,22 @@ impl Player {
64656550 )
64666551 }
64676552
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+
64686569 /// A notice holds its own bar, full width, until it is answered: any key
64696570 /// retires it (the key handler) and so does a click on it. Its own surface
64706571 /// because the message is the point -- a failure cut to the timecode's slot
@@ -9532,14 +9633,59 @@ impl Player {
95329633 }
95339634
95349635 /// 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 only
9536-/// queue workers that are cancelled before they decode anything.
9636+/// hardware path for the small files it was measured on (215 ms in software), so
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.
95379647 const SCRUB_GAP: Duration = Duration::from_millis(100);
95389648
95399649 fn scrub_due(target: u32, last_target: u32, since: Duration) -> bool {
95409650 target != last_target && since >= SCRUB_GAP
95419651 }
95429652
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+
95439689 /// How a finished export announces itself. Written by `poll_export` and read
95449690 /// by the notice bar, which is what makes that one line clickable.
95459691 const EXPORT_DONE: &str = "EXPORT DONE → ";
@@ -12670,7 +12816,8 @@ mod tests {
1267012816 ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri,
1267112817 fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution,
1267212818 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,
1267412821 repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label,
1267512822 trimmed_clip, unscannable,
1267612823 visible_slice,
@@ -15967,6 +16114,70 @@ mod tests {
1596716114 assert_eq!(import.since, held, "an unchanged stage must not reset it");
1596816115 }
1596916116
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+
1597016181 /// The read-ahead is a *cache warmer* and nothing else: whatever it did or
1597116182 /// failed to do, the import that follows lands exactly the rows, lengths
1597216183 /// and refusals it landed before there was a worker at all.
@@ -17421,7 +17632,7 @@ fn main() {
1742117632 // same repaint a seek's still owes: nothing plays by
1742217633 // itself, so this is what carries the poster frame to the
1742317634 // screen. An empty window has none to wait for.
17424- pending_seek: session.is_some(),
17635+ seek_since: session.is_some().then(Instant::now),
1742517636 session,
1742617637 // Full and unmuted, which is what the session it was just
1742717638 // handed is already set to: nothing to push at startup.
@@ -17486,6 +17697,7 @@ fn main() {
1748617697 speed_open: None,
1748717698 speed_bar: Rc::default(),
1748817699 speed_dragging: false,
17700+ pending_speed: None,
1748917701 mix_open: false,
1749017702 mix_field: 0,
1749117703 silence_open: None,
@@ -17506,6 +17718,7 @@ fn main() {
1750617718 color_band: 0,
1750717719 color_dragging: false,
1750817720 color_bars: std::array::from_fn(|_| Rc::default()),
17721+ pending_color: None,
1750917722 // Empty until the first frame is pumped, which draws as a
1751017723 // flat line rather than as a shape nothing measured.
1751117724 histogram: [[0; HIST_BINS]; 3],
crates/engine/src/playback.rsmodified+1 -1
@@ -2374,7 +2374,7 @@ impl PlaybackSession {
23742374 out: &Path,
23752375 settings: &crate::export::ExportSettings,
23762376 ) -> 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)
23782378 }
23792379
23802380 /// 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 = (
618618 Vec<ColorParams>,
619619 );
620620
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+
621628 /// The edit list plus its undo history.
622629 #[derive(Clone, Debug)]
623630 pub struct Project {
@@ -631,7 +638,8 @@ pub struct Project {
631638 /// The same, for [`Clip::color`].
632639 color: Vec<ColorParams>,
633640 /// 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.
635643 history: Vec<Vec<LaneData>>,
636644 /// Never rolled back by an undo: an id retired by an undone split must not
637645 /// come back and group two clips that were never together.
@@ -2693,6 +2701,24 @@ impl Project {
26932701 }
26942702 }
26952703
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+
26962722 /// Half-open `(source, start, end)` segments in *source* seconds, from
26972723 /// `timeline_frame` to the end of the timeline -- the play list for the
26982724 /// audio worker, read off **`A1`**. A `None` source is a gap: the
@@ -2861,6 +2887,9 @@ impl Project {
28612887 /// Pushes the undo snapshot. Every mutating method calls this once, *after*
28622888 /// it has decided it will succeed -- a refusal must not cost an undo step.
28632889 fn snapshot(&mut self) {
2890+ if self.history.len() == HISTORY_CAP {
2891+ self.history.remove(0);
2892+ }
28642893 self.history.push(self.lanes.clone());
28652894 }
28662895
@@ -4215,6 +4244,24 @@ mod tests {
42154244 assert_eq!(shape(&p)[0], vec![clip(0, 0, 9, 0)]);
42164245 }
42174246
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+
42184265 /// Undo/redo by hand across a split must never merge two takes into one
42194266 /// group by reusing an id.
42204267 #[test]