forge
Explore
Log in

Don't you dare go Hollow

Merge the app lane into main

Browse files at this commit

4d39c188af4770000b19f0285074dc7b95f2085fAhmet Kaan GümüşParent: c76e6c507d3b8b
  • fix
    • merge the app lane into main
Show full message
🐛 fix(player,project): merge the app lane into main

The settings and the subtitle palette ride in the history entry, a failed
waveform decode is asked again, and a visualizer byte past a byte is
refused rather than truncated. Lane: lane-bughunt-app.

16 changed files +1495 -398

crates/app/src/importing.rsmodified+9 -4
@@ -18,10 +18,15 @@ pub(crate) enum Wave {
1818 Loading,
1919 /// The file has no audio track. An answer, not a miss.
2020 Silent,
21- /// The decode failed. Drawn as its own mark rather than as [`Self::Silent`]:
22- /// "this file's sound could not be read" and "this file has no sound" look
23- /// the same on a lane, and the first is a bug report waiting to happen.
24- Failed,
21+ /// The decode failed, at the moment it did. Drawn as its own mark rather
22+ /// than as [`Self::Silent`]: "this file's sound could not be read" and
23+ /// "this file has no sound" look the same on a lane, and the first is a
24+ /// bug report waiting to happen. It is *not* an answer, though: a failure
25+ /// may have had a reason that has since gone away (a file still being
26+ /// copied when it arrived), so [`crate::subs::unseen_sources`] asks again
27+ /// once the stamp is older than its cooldown -- which is what the stamp is
28+ /// for.
29+ Failed(std::time::Instant),
2530 Peaks(Arc<Vec<(f32, f32)>>),
2631 }
2732
crates/app/src/player/actions.rsmodified+127 -6
@@ -685,20 +685,141 @@ impl Player {
685685 }
686686
687687 pub(crate) fn undo(&mut self, cx: &mut Context<Self>) {
688- if self.session.as_mut().is_some_and(PlaybackSession::undo) {
689- self.reset_after_reseek();
690- }
688+ self.step_history(PlaybackSession::undo);
691689 self.selected.clear();
692690 cx.notify();
693691 }
694692
695693 pub(crate) fn redo(&mut self, cx: &mut Context<Self>) {
696- if self.session.as_mut().is_some_and(PlaybackSession::redo) {
697- self.reset_after_reseek();
698- }
694+ self.step_history(PlaybackSession::redo);
699695 self.selected.clear();
700696 cx.notify();
701697 }
698+
699+ /// One step of the session's own history through the door both `^z` and
700+ /// `^y` go through, and the window-side state it moves taken back up
701+ /// afterwards ([`history_step`]).
702+ ///
703+ /// The plate the pick drew goes with the pick
704+ /// ([`Player::remove_subtitle_track`]'s own drop, for its own reason) and
705+ /// the frame owed to the screen is cleared
706+ /// ([`Player::reset_after_reseek`]): an undo reseeks inside the engine, and
707+ /// a picture left where it was is the frame before the step.
708+ fn step_history(&mut self, step: fn(&mut PlaybackSession) -> bool) {
709+ let mut caches = SessionCaches {
710+ fps: self.fps,
711+ proxies_on: self.proxies_on,
712+ auto_proxies_on: self.auto_proxies_on,
713+ };
714+ let before = HistoryBefore::of(
715+ self.session.as_ref().map_or(&[][..], |s| s.subtitles()),
716+ self.sub_track,
717+ );
718+ let Some(outcome) = self
719+ .session
720+ .as_mut()
721+ .and_then(|session| history_step(&before, &mut caches, session, step))
722+ else {
723+ return;
724+ };
725+ self.fps = caches.fps;
726+ self.proxies_on = caches.proxies_on;
727+ self.auto_proxies_on = caches.auto_proxies_on;
728+ self.sub_track = outcome.sub_track;
729+ if outcome.drop_sub_image {
730+ // corner-cut: its atlas tile is not released -- `close_session`'s
731+ // note, for its reason and with its upgrade path.
732+ self.sub_image = None;
733+ }
734+ self.reset_after_reseek();
735+ }
736+}
737+
738+/// The three session settings a window keeps its own copy of, as a value so
739+/// that [`history_step`] can re-read them in place: the rate every
740+/// frame↔second conversion in the window counts in (`Player::timeline_at`,
741+/// `Scale::snap_frames`) and the two switches a project carries and the
742+/// Settings rows *show* (`settings_stance`).
743+#[derive(Clone, Copy, Debug, PartialEq)]
744+pub(crate) struct SessionCaches {
745+ pub(crate) fps: f64,
746+ pub(crate) proxies_on: bool,
747+ pub(crate) auto_proxies_on: bool,
748+}
749+
750+/// The window-side state of the palette as a history step finds it: the pick,
751+/// how many rows there are, and which row the pick names.
752+#[derive(Clone, Debug, PartialEq)]
753+pub(crate) struct HistoryBefore {
754+ pub(crate) sub_track: usize,
755+ pub(crate) sub_rows: usize,
756+ pub(crate) sub_row: Option<SubPickKey>,
757+}
758+
759+impl HistoryBefore {
760+ /// `tracks` as they stand and the index picked there -- an empty palette
761+ /// for a window with no session, which is the state a step cannot happen in
762+ /// anyway.
763+ pub(crate) fn of(tracks: &[engine::subtitle::SubtitleTrack], sub_track: usize) -> Self {
764+ Self {
765+ sub_track,
766+ sub_rows: tracks.len(),
767+ sub_row: SubPickKey::of(tracks, sub_track),
768+ }
769+ }
770+}
771+
772+/// What a history step leaves this window to take up beside the session's own
773+/// lanes.
774+#[derive(Clone, Copy, Debug, PartialEq)]
775+pub(crate) struct HistoryOutcome {
776+ pub(crate) sub_track: usize,
777+ /// The plate over the picture (`Player::sub_image`) has to go. Its tile is
778+ /// keyed by *where* a cue sits ([`Player::sub_picture`]'s `(lane,
779+ /// start_us)`) and carries no track, so a step that moves captions, takes
780+ /// one off, or renumbers the track a placement names
781+ /// ([`engine::Project::remove_subtitles`] walks `SubClip::track` down)
782+ /// cannot be asked of that cache -- the tile at a key can be served for a
783+ /// cue it was not drawn from. Conservative on purpose: at most one plate is
784+ /// redrawn by the next repaint.
785+ pub(crate) drop_sub_image: bool,
786+}
787+
788+/// One step of the session's own history ([`PlaybackSession::undo`],
789+/// [`PlaybackSession::redo`]) with everything this window caches re-read after
790+/// it. `None` when the step did not happen -- nothing to undo, nothing to redo
791+/// -- and then nothing here moves either.
792+///
793+/// A free function over the session and the caches rather than a [`Player`]
794+/// method: this test binary has no `TestAppContext` to build a `Player` in, so
795+/// what `^z` does to the session *and* to the caches beside it is pinned here,
796+/// and [`Player::step_history`] is this call plus the repaint.
797+///
798+/// The rate and the two switches are read off the *session*, exactly as the
799+/// doors that own them do ([`Player::apply_frame_rate`], the `.edith` load): a
800+/// history entry carries the project's settings beside its lanes
801+/// (`Project::snapshot`), so a step puts them back -- and a window that kept
802+/// its old copies counts a cut at the rate just undone, keeps reporting a
803+/// switch the session no longer has, and pushes that switch at the next session
804+/// it makes.
805+pub(crate) fn history_step(
806+ before: &HistoryBefore,
807+ caches: &mut SessionCaches,
808+ session: &mut PlaybackSession,
809+ step: fn(&mut PlaybackSession) -> bool,
810+) -> Option<HistoryOutcome> {
811+ if !step(session) {
812+ return None;
813+ }
814+ caches.fps = session.meta().frame_rate;
815+ caches.proxies_on = session.proxies();
816+ caches.auto_proxies_on = session.auto_proxies();
817+ let tracks = session.subtitles();
818+ let sub_track = sub_pick_after_restore(before.sub_track, before.sub_row.as_ref(), tracks);
819+ Some(HistoryOutcome {
820+ sub_track,
821+ drop_sub_image: tracks.len() != before.sub_rows || sub_track != before.sub_track,
822+ })
702823 }
703824
704825 /// The half-open range a mark and a mark make, in either order: a person's two
crates/app/src/player/export.rsmodified+7 -2
@@ -2,6 +2,7 @@
22 //! two of them decide.
33
44 use crate::*;
5+use std::time::Instant;
56
67 impl Player {
78 /// What [`timeline_math::lane_refuses`] asks to decide a video lane's
@@ -231,7 +232,7 @@ impl Player {
231232 }
232233 starting.push(path);
233234 }
234- for key in unseen_sources(session.sources(), &self.waves) {
235+ for key in unseen_sources(session.sources(), &self.waves, Instant::now()) {
235236 self.waves.insert(key.clone(), Wave::Loading);
236237 let decoded = cx.background_executor().spawn({
237238 let (path, stream) = key.clone();
@@ -254,7 +255,11 @@ impl Player {
254255 // A file whose sound we could not read is not a
255256 // silent one, and a lane that drew it as silent is
256257 // how a broken decode passes for a design choice.
257- Err(_) => Wave::Failed,
258+ // Stamped, and not an answer: a repaint past
259+ // [`WAVE_RETRY`] asks again, so a failure whose
260+ // cause went away (a file still being copied when
261+ // it arrived) draws its envelope without a reopen.
262+ Err(_) => Wave::Failed(Instant::now()),
258263 },
259264 );
260265 cx.notify();
crates/app/src/player/library.rsmodified+13 -7
@@ -1711,11 +1711,13 @@ impl Player {
17111711 /// would name a *different* track -- and the pick is what an export writes
17121712 /// into the file.
17131713 ///
1714- /// Not an undo step: subtitles are not on the history's snapshots, so the
1715- /// way back is putting the file's subtitles on again -- which is a door of
1716- /// its own ([`Player::pick_and_add_subtitles`]) and reads the subtitles
1717- /// alone, never the media. The notice says that rather than promising a
1718- /// ctrl+z that would do nothing.
1714+ /// One undo step, and the palette comes back with the reindex
1715+ /// ([`engine::Project::remove_subtitles`]), so `^z` is a way back that
1716+ /// works -- [`Player::step_history`] moves the pick back with it and drops
1717+ /// the plate the old index drew. The second way back, for a caller that
1718+ /// wants the *file's* tracks again, is putting them on
1719+ /// ([`Player::pick_and_add_subtitles`]): a door of its own that reads the
1720+ /// subtitles alone, never the media, which is what the notice names.
17191721 pub(crate) fn remove_subtitle_track(&mut self, track: usize, cx: &mut Context<Self>) {
17201722 // The one availability oracle, for the same reason the × on a row and
17211723 // the stroke are one call: an empty list is not a failure, it is an
@@ -1749,8 +1751,12 @@ impl Player {
17491751 .as_ref()
17501752 .map_or(0, |session| session.subtitles().len());
17511753 self.sub_track = sub_pick_after_removal(self.sub_track, track, left);
1752- // The drawn cue is keyed by that index ([`Player::sub_picture`])
1753- // and the index now stands for another track.
1754+ // The cue over the picture goes with the pick: its tile is
1755+ // keyed by *where* the cue sits ([`Player::sub_picture`]'s
1756+ // `(lane, start_us)`) and never by the track it shows, so the
1757+ // index that moved here is not something that cache can be
1758+ // asked about. Conservative, and the same drop a history step
1759+ // makes for the same reason ([`Player::step_history`]).
17541760 //
17551761 // corner-cut: its atlas tile is not released -- `close_session`'s
17561762 // note, for its reason and with its upgrade path.
crates/app/src/subs.rsmodified+89 -12
@@ -333,9 +333,7 @@ pub(crate) fn subtitle_tail(session: &mut PlaybackSession, subs: Subs) -> Option
333333 match subs {
334334 Ok(tracks) => match session.add_subtitle_tracks(tracks) {
335335 0 => None,
336- n => Some(format!(
337- " · {n} subtitle track(s)"
338- )),
336+ n => Some(format!(" · {n} subtitle track(s)")),
339337 },
340338 Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")),
341339 }
@@ -625,11 +623,15 @@ pub(crate) fn subtitle_rows(tracks: &[engine::subtitle::SubtitleTrack]) -> Vec<S
625623 /// last. Zero on an emptied list, which is the index the section is not drawn at
626624 /// all.
627625 ///
628-/// Its own function because the pick is what the overlay draws: left where it
629-/// was it would name a different track, and the plate over the picture would
630-/// change language on its own the moment a row above it went. What an export
631-/// writes is *not* this pick and cannot be desynced by a removal -- it is worked
632-/// out from the cues on the timeline each time ([`Player::export_subs`]).
626+/// Its own function because the pick is read as "which row" everywhere it is
627+/// echoed -- the dock highlights the picked row by comparing it
628+/// (`dock_stance`'s `track == player.sub_track`), and the section heading and
629+/// its notices name it -- so left where it was it would highlight one track and
630+/// name another the moment a row above it went. The plate over the picture is
631+/// not on that list: it is drawn from the *placements* on the shown lane
632+/// ([`Player::active_sub_lane`], and the session's own `sub_lane_cues`). What an export
633+/// writes is not this pick either -- it is worked out from the cues on the
634+/// timeline each time ([`Player::export_subs`]).
633635 pub(crate) fn sub_pick_after_removal(picked: usize, removed: usize, left: usize) -> usize {
634636 let picked = match removed < picked {
635637 true => picked - 1,
@@ -638,6 +640,65 @@ pub(crate) fn sub_pick_after_removal(picked: usize, removed: usize, left: usize)
638640 picked.min(left.saturating_sub(1))
639641 }
640642
643+/// What a palette row *is*, apart from where it sits: the file it came out of,
644+/// which track of it, and the two words a row shows. Cloned out of the palette
645+/// once per history step -- a path and three short strings, against a palette
646+/// whose cues are the whole film's subtitles. Not [`SubRow`], which is a row as
647+/// the column *draws* it.
648+#[derive(Clone, Debug, PartialEq, Eq)]
649+pub(crate) struct SubPickKey {
650+ path: PathBuf,
651+ track: Option<u64>,
652+ language: String,
653+ label: String,
654+}
655+
656+impl SubPickKey {
657+ /// The row `track` of this palette names, `None` for an index no track
658+ /// answers to -- the same silence [`sub_pick_name`] gives.
659+ pub(crate) fn of(tracks: &[engine::subtitle::SubtitleTrack], track: usize) -> Option<Self> {
660+ let track = tracks.get(track)?;
661+ Some(Self {
662+ path: track.path.clone(),
663+ track: track.track,
664+ language: track.language.clone(),
665+ label: track.label.clone(),
666+ })
667+ }
668+
669+ /// Whether `track` is this row: the four fields a palette would have had to
670+ /// change for a pick left where it was to name a different track.
671+ fn is(&self, track: &engine::subtitle::SubtitleTrack) -> bool {
672+ track.path == self.path
673+ && track.track == self.track
674+ && track.language == self.language
675+ && track.label == self.label
676+ }
677+}
678+
679+/// Where the pick lands once a *restored* palette is back in place: the row
680+/// that was picked, found by what it is rather than by where it sat.
681+///
682+/// A history step moves rows without saying which one moved -- an undo of a
683+/// removal puts a column back above the pick as often as below it -- so an
684+/// index left where it was names a different track, which is the desync
685+/// [`sub_pick_after_removal`] prevents at the door where the row that moved is
686+/// known. That door's arithmetic is this map's one-row-moved case.
687+///
688+/// A row the restored palette does not have (it went again, or the pick named
689+/// nothing) falls back to the old index clamped into the new list -- that same
690+/// door's own fallback, and the zero the section is not drawn at all for an
691+/// emptied palette.
692+pub(crate) fn sub_pick_after_restore(
693+ picked: usize,
694+ before: Option<&SubPickKey>,
695+ after: &[engine::subtitle::SubtitleTrack],
696+) -> usize {
697+ before
698+ .and_then(|was| after.iter().position(|track| was.is(track)))
699+ .unwrap_or_else(|| picked.min(after.len().saturating_sub(1)))
700+}
701+
641702 pub(crate) fn sub_pick_name(
642703 tracks: &[engine::subtitle::SubtitleTrack],
643704 track: usize,
@@ -705,17 +766,33 @@ pub(crate) fn cues_at(cues: &[engine::subtitle::Cue], at: f64) -> Vec<&engine::s
705766 .collect()
706767 }
707768
708-/// The sources a repaint has not asked about yet. A key that is already there
709-/// means "asked", whatever state it is in, which is what stops a decode already
710-/// running from being started again by the next of sixty repaints a second.
769+/// How long a failed waveform decode is left alone before the next repaint asks
770+/// again: long enough that sixty repaints a second do not become sixty decodes,
771+/// short enough that a file which arrived mid-copy has its envelope a moment
772+/// after it lands. The engine memoizes no failure for the same reason
773+/// ([`engine::waveform`]): the reason one failed may have gone away.
774+pub(crate) const WAVE_RETRY: std::time::Duration = std::time::Duration::from_secs(5);
775+
776+/// The sources a repaint has not asked about yet, as of `now`. A key that is
777+/// already there means "asked", whatever state it is in -- which is what stops
778+/// a decode already running from being started again by the next of sixty
779+/// repaints a second -- with one exception: a [`Wave::Failed`] older than
780+/// [`WAVE_RETRY`] is asked again, because a decode that failed once is not an
781+/// answer about the file, only about the moment it was tried. A file with no
782+/// audio (`Wave::Silent`) is an answer like any other and is never re-asked.
711783 pub(crate) fn unseen_sources(
712784 sources: &[Source],
713785 waves: &HashMap<(PathBuf, usize), Wave>,
786+ now: std::time::Instant,
714787 ) -> Vec<(PathBuf, usize)> {
715788 sources
716789 .iter()
717790 .map(|s| (s.path.clone(), s.audio_stream))
718- .filter(|key| !waves.contains_key(key))
791+ .filter(|key| match waves.get(key) {
792+ None => true,
793+ Some(Wave::Failed(at)) => now.duration_since(*at) >= WAVE_RETRY,
794+ Some(_) => false,
795+ })
719796 .collect()
720797 }
721798
crates/app/src/tests/cards.rsmodified+146 -24
@@ -914,7 +914,10 @@ fn the_budget_is_the_one_number_the_engine_gets() {
914914 // put on screen.
915915 assert_eq!(auto_bps(1920, 1080, 30.), 6_220_800);
916916 assert_eq!(auto_bps(160, 120, 15.), BPS_MIN, "a tiny picture floors");
917- assert!(auto_bps(7680, 4320, 60.) <= 20_000_000, "and a huge one caps");
917+ assert!(
918+ auto_bps(7680, 4320, 60.) <= 20_000_000,
919+ "and a huge one caps"
920+ );
918921 for bps in [auto_bps(1920, 1080, 30.), auto_bps(320, 240, 24.)] {
919922 assert!((BPS_MIN..=BPS_MAX).contains(&bps));
920923 }
@@ -1067,11 +1070,25 @@ fn a_chord_the_export_moment_answers_never_reaches_the_room() {
10671070 let (typing, closed) = rest
10681071 .split_once("return true;")
10691072 .expect("the typing branch returns before the chords below it");
1070- assert!(typing.contains("self.budget_edit = None"), "esc leaves the field");
1071- assert!(closed.contains("self.close_card()"), "then esc closes the moment");
1073+ assert!(
1074+ typing.contains("self.budget_edit = None"),
1075+ "esc leaves the field"
1076+ );
1077+ assert!(
1078+ closed.contains("self.close_card()"),
1079+ "then esc closes the moment"
1080+ );
10721081 // Its chords, all of them consumed here rather than by the keymap.
10731082 for chord in [
1074- "\"d\"", "\"n\"", "\"e\"", "\"enter\"", "\"up\"", "\"down\"", "\"c\"", "\"b\"", "\"g\"",
1083+ "\"d\"",
1084+ "\"n\"",
1085+ "\"e\"",
1086+ "\"enter\"",
1087+ "\"up\"",
1088+ "\"down\"",
1089+ "\"c\"",
1090+ "\"b\"",
1091+ "\"g\"",
10751092 "\",\"",
10761093 ] {
10771094 assert!(closed.contains(chord), "{chord} is not the moment's own");
@@ -1086,7 +1103,11 @@ fn a_chord_the_export_moment_answers_never_reaches_the_room() {
10861103 fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
10871104 let cards = src_text("ui/cards.rs");
10881105 let start = cards.find("fn export_card(").expect("the moment");
1089- let body = &cards[start..start + cards[start..].find("\n /// ").unwrap_or(cards.len() - start)];
1106+ let body = &cards[start
1107+ ..start
1108+ + cards[start..]
1109+ .find("\n /// ")
1110+ .unwrap_or(cards.len() - start)];
10901111 // A segment is the setter it names, not a readout of it.
10911112 for (id, chord, setter) in [
10921113 ("moment-picture", "\"c\"", "cycle_export_picture"),
@@ -1098,7 +1119,10 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
10981119 assert!(body.contains(setter), "the {id} segment changes nothing");
10991120 }
11001121 // The door, wearing the room's own chord rather than a hand-typed one.
1101- assert!(body.contains("moment-settings"), "row 3 has no settings door");
1122+ assert!(
1123+ body.contains("moment-settings"),
1124+ "row 3 has no settings door"
1125+ );
11021126 assert!(
11031127 body.contains("self.keymap.chord(ActionId::Settings)"),
11041128 "the door's chord is not read from the keymap"
@@ -1113,7 +1137,10 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
11131137 .map(|at| &cards[at..at + 1900])
11141138 .expect("the segment atom");
11151139 assert!(seg.contains("INK3()") && seg.contains("INK4()"));
1116- assert!(seg.contains("DARK_RAISED()"), "a segment does not answer hover");
1140+ assert!(
1141+ seg.contains("DARK_RAISED()"),
1142+ "a segment does not answer hover"
1143+ );
11171144 // The readouts worth seeing: the project's picture size and rate, and
11181145 // a sound rate that is on the line whether or not it is pressable.
11191146 assert!(
@@ -1126,13 +1153,18 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
11261153 );
11271154 // The picture segment is a child, not a `has_video` maybe: hidden on the
11281155 // sound-only formats it left `c` pressing nothing and no way back.
1129- let at = body.find("\"moment-picture\"").expect("the picture segment");
1156+ let at = body
1157+ .find("\"moment-picture\"")
1158+ .expect("the picture segment");
11301159 assert!(
11311160 !body[at - 240..at].contains("has_video"),
11321161 "the picture segment is gated on has_video again -- the dead end"
11331162 );
11341163 // Wrapped, never cut: the readouts made row 3 longer than 1280 wide.
1135- assert!(body.contains(".flex_wrap()"), "row 3 truncates instead of wrapping");
1164+ assert!(
1165+ body.contains(".flex_wrap()"),
1166+ "row 3 truncates instead of wrapping"
1167+ );
11361168 }
11371169
11381170 /// The dead end the user hit: the cycle walked into the sound-only formats
@@ -1140,15 +1172,22 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
11401172 /// and can't turn it back to video"). One cycle, and it wraps.
11411173 #[test]
11421174 fn the_picture_cycle_wraps_out_of_the_sound_only_formats() {
1143- use crate::ui::settings_stance::{PICTURE_CYCLE, next_picture};
1175+ use crate::ui::settings_stance::{next_picture, PICTURE_CYCLE};
11441176 // Nothing refused: every stop is the next one, and the last wraps to the
11451177 // first -- OGG, the tail of the list, back to MP4.
11461178 let mut at = PICTURE_CYCLE[0];
1147- for &want in PICTURE_CYCLE.iter().skip(1).chain(std::iter::once(&PICTURE_CYCLE[0])) {
1179+ for &want in PICTURE_CYCLE
1180+ .iter()
1181+ .skip(1)
1182+ .chain(std::iter::once(&PICTURE_CYCLE[0]))
1183+ {
11481184 at = next_picture(at, |_| false);
11491185 assert_eq!(at, want, "the cycle stopped walking");
11501186 }
1151- assert_eq!(at, PICTURE_CYCLE[0], "a full walk is a wrap, not a dead end");
1187+ assert_eq!(
1188+ at, PICTURE_CYCLE[0],
1189+ "a full walk is a wrap, not a dead end"
1190+ );
11521191 assert_eq!(next_picture(Format::Ogg, |_| false), Format::Mp4);
11531192 // A timeline with no picture refuses every video format, and the cycle
11541193 // still moves: the sound-only stops are what is left of it.
@@ -1278,12 +1317,33 @@ fn the_moment_and_the_settings_room_wear_the_same_export_chords() {
12781317 assert!(settings.contains(chord), "the EXPORT rows lost {chord}");
12791318 assert!(moment.contains(chord), "row 3 lost {chord}");
12801319 assert!(handler.contains(chord), "the moment answers no {chord}");
1281- assert!(player.contains(chord), "the settings page answers no {chord}");
1320+ assert!(
1321+ player.contains(chord),
1322+ "the settings page answers no {chord}"
1323+ );
12821324 }
1325+ // The Encoder row is the picture's own -- the engine opens no seat for a
1326+ // song -- so the settings room gates it on the format exactly as the
1327+ // moment does, and neither mounts a row for an audio-only format.
1328+ assert_eq!(Format::Mp4.has_video(), true);
1329+ for audio_only in [Format::Wav, Format::Flac, Format::Mp3, Format::Ogg] {
1330+ assert_eq!(audio_only.has_video(), false, "{audio_only:?}");
1331+ }
1332+ let at = settings
1333+ .find("settings-export-encoder")
1334+ .expect("the Encoder row");
1335+ let mount = &settings[at.saturating_sub(260)..at];
1336+ assert!(
1337+ mount.contains("has_video()"),
1338+ "the Encoder row is mounted for a song, where pressing it does nothing"
1339+ );
12831340 // `e` stays the Export press: the encoder seat took `g` rather than a
12841341 // shifted letter, which no ghost wears.
12851342 assert!(handler.contains("\"e\" | \"enter\" => self.start_export"));
1286- assert!(!settings.contains("\n \"e\","), "the Encoder row took `e` back");
1343+ assert!(
1344+ !settings.contains("\n \"e\","),
1345+ "the Encoder row took `e` back"
1346+ );
12871347 }
12881348
12891349 /// The Sound row: what it offers, and that the pick travels to the engine
@@ -1401,9 +1461,15 @@ fn a_typed_colour_is_read_in_every_spelling_and_anything_else_is_refused() {
14011461 edit.typed('z');
14021462 assert_eq!(edit.commit(), None);
14031463 let why = edit.refusal.clone().expect("a refusal, not a silence");
1404- assert!(why.contains("#RRGGBB"), "the refusal says what a colour is: {why}");
1464+ assert!(
1465+ why.contains("#RRGGBB"),
1466+ "the refusal says what a colour is: {why}"
1467+ );
14051468 assert_eq!(edit.text, "zz", "the refusal keeps the text it refused");
1406- assert!(edit.detail().contains("zz▏"), "the caret stays in the buffer");
1469+ assert!(
1470+ edit.detail().contains("zz▏"),
1471+ "the caret stays in the buffer"
1472+ );
14071473 // ...and the next stroke clears it: that reason described the text that is
14081474 // no longer there.
14091475 edit.typed('0');
@@ -1780,11 +1846,9 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() {
17801846 assert!(native_detail.ends_with(" source"), "{native_detail}");
17811847 // A project at a size nobody listed still gets the whole list, with
17821848 // nothing marked rather than a wrong row marked.
1783- assert!(
1784- resolution_choices((1000, 1000), native)
1785- .iter()
1786- .all(|(.., picked)| !picked)
1787- );
1849+ assert!(resolution_choices((1000, 1000), native)
1850+ .iter()
1851+ .all(|(.., picked)| !picked));
17881852 // Picking a row means that row, and stepping means the next one: the
17891853 // list and the stroke read the same ladder.
17901854 assert_eq!(next_resolution(ladder[1], native), ladder[2]);
@@ -1883,7 +1947,10 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() {
18831947 assert!(tall <= 360., "the list is taller than the floor");
18841948 assert_eq!(
18851949 menu_at(point(px(600.), px(340.)), size(px(640.), px(360.)), tall),
1886- (640. - crate::layout::MENU_EDGE - MENU_W, 360. - crate::layout::MENU_EDGE - tall),
1950+ (
1951+ 640. - crate::layout::MENU_EDGE - MENU_W,
1952+ 360. - crate::layout::MENU_EDGE - tall
1953+ ),
18871954 "the list would hang off the smallest window"
18881955 );
18891956 }
@@ -2238,8 +2305,8 @@ fn maximizing_a_card_grows_its_box_without_moving_where_a_value_sits_in_it() {
22382305 /// inside the dock, or hands it the dock's width again, fails this.
22392306 #[test]
22402307 fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() {
2308+ use crate::layout::{split_size, Split};
22412309 use crate::SPLIT_W;
2242- use crate::layout::{Split, split_size};
22432310
22442311 // `layout::SPLIT_W` is the one divider between `stance-centre` and the
22452312 // dock; the 56px rail that used to eat the centre's left edge is gone
@@ -2286,7 +2353,7 @@ fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() {
22862353 /// assumption.
22872354 #[test]
22882355 fn a_maximized_card_can_never_rise_above_the_picture_no_matter_the_bench_height() {
2289- use crate::ui::stance::{LEDGER_H, TIME_BAND_H, below_picture_floor};
2356+ use crate::ui::stance::{below_picture_floor, LEDGER_H, TIME_BAND_H};
22902357 let viewport_h = 1080.;
22912358 for bench_h in [140., 200., 400.] {
22922359 assert_eq!(
@@ -2531,3 +2598,58 @@ fn picker_row_tails_are_state_words_and_settings_values_carry_no_ellipsis() {
25312598 );
25322599 }
25332600 }
2601+
2602+/// D1: the project's own settings are the project's -- the resolution, the
2603+/// rate, the encoder seat, the mix rate and the two proxy switches ride in
2604+/// the same history entry the lanes do, so every one of those picks is a
2605+/// single `ctrl+z`. Before this, pressing `z` after any of them did nothing.
2606+#[test]
2607+fn a_settings_pick_undoes_and_redoes_like_a_cut() {
2608+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
2609+ let (w, h) = session.resolution();
2610+
2611+ assert!(session.set_resolution(w / 2, h / 2));
2612+ assert_eq!(session.resolution(), (w / 2, h / 2));
2613+ assert!(session.undo(), "the resolution pick is one step");
2614+ assert_eq!(session.resolution(), (w, h), "and the canvas comes back");
2615+ assert!(session.redo(), "redo walks the same branch");
2616+ assert_eq!(session.resolution(), (w / 2, h / 2));
2617+ assert!(session.undo(), "back to where the test started");
2618+
2619+ // The encoder seat, which nothing reseeks and nothing shows until an
2620+ // export starts.
2621+ let seat = session.encoder_seat();
2622+ assert_ne!(seat, EncoderSeat::Software);
2623+ session.set_encoder_seat(EncoderSeat::Software);
2624+ assert_eq!(session.encoder_seat(), EncoderSeat::Software);
2625+ assert!(session.undo(), "the encoder pick is one step");
2626+ assert_eq!(session.encoder_seat(), seat, "and the seat comes back");
2627+ assert!(session.redo());
2628+ assert_eq!(session.encoder_seat(), EncoderSeat::Software);
2629+ assert!(session.undo());
2630+
2631+ // The mix rate, and the switches beside it.
2632+ session.set_sample_rate(Some(44_100));
2633+ assert_eq!(session.sample_rate(), Some(44_100));
2634+ assert!(session.undo(), "the mix rate is one step");
2635+ assert_eq!(session.sample_rate(), None, "back to the derived rate");
2636+ let proxies = session.proxies();
2637+ session.set_proxies(!proxies);
2638+ assert_eq!(session.proxies(), !proxies);
2639+ assert!(session.undo(), "the proxy switch is one step");
2640+ assert_eq!(session.proxies(), proxies, "and the switch comes back");
2641+ let auto = session.auto_proxies();
2642+ session.set_auto_proxies(!auto);
2643+ assert_eq!(session.auto_proxies(), !auto);
2644+ assert!(session.undo(), "and so is the auto switch");
2645+ assert_eq!(session.auto_proxies(), auto, "which comes back too");
2646+
2647+ // ...and a lane edit still undoes the way it always did, settings and all
2648+ // in the same stack.
2649+ let clips = session.lane_clips(Lane::V1).len();
2650+ assert_eq!(clips, 1, "one take to start with");
2651+ assert!(session.delete_clip(Lane::V1, 0));
2652+ assert_eq!(session.lane_clips(Lane::V1).len(), 0);
2653+ assert!(session.undo(), "the delete is one step");
2654+ assert_eq!(session.lane_clips(Lane::V1).len(), clips);
2655+}
crates/app/src/tests/editing.rsmodified+314 -114
@@ -109,11 +109,9 @@ fn a_song_opens_the_window_by_itself() {
109109 // ...and it places, on the audio lane, through the door `insert_source`
110110 // uses: a second copy of the song at the playhead.
111111 session.seek(1.0);
112- assert!(
113- session
114- .place_stream_at(1.0, &path, 0, Some(Lane::A1))
115- .expect("its own file is on this timeline")
116- );
112+ assert!(session
113+ .place_stream_at(1.0, &path, 0, Some(Lane::A1))
114+ .expect("its own file is on this timeline"));
117115 assert_eq!(session.lane_clips(Lane::A1).len(), 2);
118116 assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture");
119117
@@ -345,13 +343,11 @@ fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() {
345343 );
346344 // ...and the same reading with a clip under it is the clip menu, untouched:
347345 // the flag is off wherever a `Clip` was clicked.
348- assert!(
349- menu_items(Ctx {
350- timeline: true,
351- ..Ctx::default()
352- })
353- .contains(&ActionId::Cut)
354- );
346+ assert!(menu_items(Ctx {
347+ timeline: true,
348+ ..Ctx::default()
349+ })
350+ .contains(&ActionId::Cut));
355351 }
356352
357353 /// A timeline with a subtitle palette and an empty subtitle lane: what a
@@ -939,16 +935,14 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
939935 }
940936 assert!(!whole(ActionId::Delete, live).yes());
941937 assert!(!whole(ActionId::Paste, live).yes());
942- assert!(
943- whole(
944- ActionId::Paste,
945- Ctx {
946- clipboard: true,
947- ..live
948- }
949- )
950- .yes()
951- );
938+ assert!(whole(
939+ ActionId::Paste,
940+ Ctx {
941+ clipboard: true,
942+ ..live
943+ }
944+ )
945+ .yes());
952946 assert!(!whole(ActionId::CancelExport, live).yes());
953947 let busy = Ctx {
954948 exporting: true,
@@ -988,7 +982,10 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
988982 assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.));
989983 assert_eq!(
990984 menu_at(point(px(700.), px(380.)), viewport, 150.),
991- (800. - crate::layout::MENU_EDGE - MENU_W, 400. - crate::layout::MENU_EDGE - 150.)
985+ (
986+ 800. - crate::layout::MENU_EDGE - MENU_W,
987+ 400. - crate::layout::MENU_EDGE - 150.
988+ )
992989 );
993990 // A window smaller than the menu loses its bottom, never its top: the
994991 // top-left margin wins over the bottom-right one, because the items are
@@ -1165,16 +1162,14 @@ fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() {
11651162 assert!(row_enable(RowItem::RemoveWithClips, placed).yes());
11661163 let unplaced = row_items(live);
11671164 assert!(unplaced.contains(&RowItem::Remove) && !unplaced.contains(&RowItem::RemoveWithClips));
1168- assert!(
1169- !row_enable(
1170- RowItem::RemoveWithClips,
1171- RowCtx {
1172- exporting: true,
1173- ..placed
1174- }
1175- )
1176- .yes()
1177- );
1165+ assert!(!row_enable(
1166+ RowItem::RemoveWithClips,
1167+ RowCtx {
1168+ exporting: true,
1169+ ..placed
1170+ }
1171+ )
1172+ .yes());
11781173 assert!(!row_enable(RowItem::Add, RowCtx::default()).yes());
11791174 // Every refusal is short enough to sit in the hint column beside its
11801175 // label, the clip menu's rule.
@@ -1282,7 +1277,11 @@ fn the_hanging_menus_mount_at_the_room_root_and_their_rows_wear_chords_not_prose
12821277 }
12831278 // §9: no junk drawer. A label that fits the plate whole beside its
12841279 // chord, and never a sentence.
1285- assert!(item.label().split_whitespace().count() <= 4, "{}", item.label());
1280+ assert!(
1281+ item.label().split_whitespace().count() <= 4,
1282+ "{}",
1283+ item.label()
1284+ );
12861285 }
12871286 // The two removes must not read as the same verb now that the column
12881287 // beside them is empty.
@@ -1604,11 +1603,9 @@ fn adding_a_row_drops_the_whole_source_in_at_the_playhead() {
16041603 let frames = session.file_frames(&second);
16051604 // Through the engine door `insert_source` uses, with the row's own
16061605 // stream: the button, the drop and this are one call.
1607- assert!(
1608- session
1609- .place_stream_at(2.0, &second, 0, None)
1610- .expect("av2 is already on the timeline")
1611- );
1606+ assert!(session
1607+ .place_stream_at(2.0, &second, 0, None)
1608+ .expect("av2 is already on the timeline"));
16121609 // The whole of source 1 went in and nothing was painted over: the
16131610 // timeline is longer by exactly that file.
16141611 assert_eq!(session.timeline_duration(), 9.0);
@@ -1635,11 +1632,9 @@ fn adding_a_row_drops_the_whole_source_in_at_the_playhead() {
16351632 let path = session.sources()[0].path.clone();
16361633 let frames = session.file_frames(&path);
16371634 let end = session.timeline_duration();
1638- assert!(
1639- session
1640- .place_stream_at(end, &path, 1, None)
1641- .expect("the French track shares the timeline's parameters")
1642- );
1635+ assert!(session
1636+ .place_stream_at(end, &path, 1, None)
1637+ .expect("the French track shares the timeline's parameters"));
16431638 assert_eq!(session.sources()[1].audio_stream, 1);
16441639 assert_eq!(session.timeline_duration(), end * 2.0);
16451640 // Both rows are the same file, so both rows are that file's length --
@@ -1689,11 +1684,9 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() {
16891684
16901685 // ...and what the release does with it: the frame back through the same
16911686 // rate every box is drawn at, into the door the Add button uses too.
1692- assert!(
1693- session
1694- .place_stream_at(f64::from(at) / fps, &second, 0, None)
1695- .expect("av2 is already on this timeline")
1696- );
1687+ assert!(session
1688+ .place_stream_at(f64::from(at) / fps, &second, 0, None)
1689+ .expect("av2 is already on this timeline"));
16971690 let head = |lane| {
16981691 session
16991692 .lane_clips(lane)
@@ -1727,11 +1720,9 @@ fn removing_a_row_is_refused_while_it_plays_and_takes_the_row_away() {
17271720 session.import(&asset("test_av2.mp4")).expect("av2 matches");
17281721 let second = session.sources()[1].path.clone();
17291722 let end = session.timeline_duration();
1730- assert!(
1731- session
1732- .place_stream_at(end, &second, 0, None)
1733- .expect("a file just imported is on this timeline")
1734- );
1723+ assert!(session
1724+ .place_stream_at(end, &second, 0, None)
1725+ .expect("a file just imported is on this timeline"));
17351726 let streams = HashMap::new();
17361727 let rows = |session: &PlaybackSession| {
17371728 library_rows(session.sources(), &streams, &HashMap::new(), None, |_| 0).len()
@@ -1943,6 +1934,211 @@ fn trim_to_playhead_moves_the_selected_clips_edge_and_undoes_in_one_step() {
19431934 assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the tail is back");
19441935 }
19451936
1937+/// The window's own copy of the rate and the two switches follows the
1938+/// *session* across `^z` and `^y`: a history entry carries the project's
1939+/// settings beside its lanes ([`engine::Project::snapshot`]), so a step puts
1940+/// them back -- and a window that kept its old copies counts every cut, step
1941+/// and fade in the rate it just undid, keeps showing a switch the session no
1942+/// longer has (`settings_stance`), and pushes that switch at the next session
1943+/// it makes.
1944+#[test]
1945+fn the_windows_settings_caches_follow_the_session_across_undo_and_redo() {
1946+ use crate::player::actions::{history_step, HistoryBefore, SessionCaches};
1947+
1948+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
1949+ session.set_gain(0.0);
1950+ let native = session.meta().frame_rate;
1951+ let (proxies, auto) = (!session.proxies(), !session.auto_proxies());
1952+
1953+ // The three picks as the window makes them, with the copies it keeps beside
1954+ // them (`Player::apply_frame_rate`'s own write, both toggle doors').
1955+ assert!(session.set_frame_rate(native * 2.0), "the rate pick");
1956+ session.set_proxies(proxies);
1957+ session.set_auto_proxies(auto);
1958+ let mut caches = SessionCaches {
1959+ fps: session.meta().frame_rate,
1960+ proxies_on: proxies,
1961+ auto_proxies_on: auto,
1962+ };
1963+ assert_ne!(
1964+ caches.fps, native,
1965+ "the test needs a rate that really moved"
1966+ );
1967+
1968+ // Back, one step at a time: after each one the window's copies are the
1969+ // session's, never the pick's.
1970+ for step in 0..3 {
1971+ let before = HistoryBefore::of(session.subtitles(), 0);
1972+ let out = history_step(&before, &mut caches, &mut session, PlaybackSession::undo)
1973+ .expect("a pick behind this one");
1974+ assert_eq!(
1975+ caches.fps,
1976+ session.meta().frame_rate,
1977+ "undo {step}: the rate"
1978+ );
1979+ assert_eq!(
1980+ caches.proxies_on,
1981+ session.proxies(),
1982+ "undo {step}: the switch"
1983+ );
1984+ assert_eq!(
1985+ caches.auto_proxies_on,
1986+ session.auto_proxies(),
1987+ "undo {step}: the auto switch"
1988+ );
1989+ assert!(!out.drop_sub_image, "undo {step}: no palette moved");
1990+ }
1991+ assert_eq!(caches.fps, native, "the rate pick is undone");
1992+ assert_eq!(
1993+ (caches.proxies_on, caches.auto_proxies_on),
1994+ (!proxies, !auto),
1995+ "and both switches are back where they were"
1996+ );
1997+
1998+ // ...and forward again, where the picks come home.
1999+ for step in 0..3 {
2000+ let before = HistoryBefore::of(session.subtitles(), 0);
2001+ history_step(&before, &mut caches, &mut session, PlaybackSession::redo)
2002+ .expect("a pick in front of this one");
2003+ assert_eq!(
2004+ caches.fps,
2005+ session.meta().frame_rate,
2006+ "redo {step}: the rate"
2007+ );
2008+ assert_eq!(
2009+ caches.proxies_on,
2010+ session.proxies(),
2011+ "redo {step}: the switch"
2012+ );
2013+ }
2014+ assert_eq!(caches.fps, native * 2.0, "the pick's own rate is back");
2015+ assert_eq!(caches.proxies_on, proxies, "and its switch");
2016+}
2017+
2018+/// Rows above the picked subtitle move the pick down with them
2019+/// ([`sub_pick_after_removal`]), and a `^z` of that removal has to move it back
2020+/// up: the palette comes home out of the entry, the pick is an *index* into it,
2021+/// and an index left where it was highlights one row and names another. The
2022+/// plate over the picture goes too, not because it is keyed by the pick -- it is
2023+/// keyed by where a cue sits -- but because the step moves the cues under it.
2024+#[test]
2025+fn the_subtitle_pick_follows_its_track_across_an_undo_of_a_removal() {
2026+ use crate::player::actions::{history_step, HistoryBefore, SessionCaches};
2027+
2028+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
2029+ session.set_gain(0.0);
2030+ assert_eq!(
2031+ session.add_subtitle_tracks(vec![
2032+ sub("/subs/one.srt", None, "one.srt"),
2033+ sub("/subs/two.srt", None, "two.srt"),
2034+ sub("/subs/three.srt", None, "three.srt"),
2035+ ]),
2036+ 3,
2037+ "the palette"
2038+ );
2039+ let mut caches = SessionCaches {
2040+ fps: session.meta().frame_rate,
2041+ proxies_on: session.proxies(),
2042+ auto_proxies_on: session.auto_proxies(),
2043+ };
2044+ // The last row picked, which is where a click on it leaves the pick.
2045+ let pick = 2;
2046+ let picked = sub_pick_name(session.subtitles(), pick).expect("a name for the pick");
2047+
2048+ // The row *above* it goes, through the removal door's own fixup.
2049+ session
2050+ .remove_subtitles(0)
2051+ .expect("a row with nothing on it");
2052+ let pick = sub_pick_after_removal(pick, 0, session.subtitles().len());
2053+ assert_eq!(pick, 1, "the pick slid down with the rows");
2054+ assert_eq!(
2055+ sub_pick_name(session.subtitles(), pick).as_deref(),
2056+ Some(picked.as_str()),
2057+ "and still names the same track"
2058+ );
2059+
2060+ let before = HistoryBefore::of(session.subtitles(), pick);
2061+ let out = history_step(&before, &mut caches, &mut session, PlaybackSession::undo)
2062+ .expect("the removal is a step like any other cut");
2063+ assert_eq!(session.subtitles().len(), 3, "the palette is back");
2064+ assert_eq!(
2065+ out.sub_track, 2,
2066+ "the row came back above the pick, so the pick moves up"
2067+ );
2068+ assert_eq!(
2069+ sub_pick_name(session.subtitles(), out.sub_track).as_deref(),
2070+ Some(picked.as_str()),
2071+ "and still names the same track"
2072+ );
2073+ assert_ne!(
2074+ sub_pick_name(session.subtitles(), pick).as_deref(),
2075+ Some(picked.as_str()),
2076+ "which is what the index left where it was would have named"
2077+ );
2078+ assert!(
2079+ out.drop_sub_image,
2080+ "the drawn plate went through the pick that moved"
2081+ );
2082+
2083+ // ...and forward again: the removal, with the fixup it does at its own door.
2084+ let before = HistoryBefore::of(session.subtitles(), out.sub_track);
2085+ let out = history_step(&before, &mut caches, &mut session, PlaybackSession::redo)
2086+ .expect("the removal is in front of this one");
2087+ assert_eq!(
2088+ out.sub_track, 1,
2089+ "the removal slides the pick down with the rows"
2090+ );
2091+ assert_eq!(
2092+ sub_pick_name(session.subtitles(), out.sub_track).as_deref(),
2093+ Some(picked.as_str())
2094+ );
2095+ assert!(out.drop_sub_image, "and the plate goes with it");
2096+}
2097+
2098+/// The app-level write-back of a history step is not reachable from this binary
2099+/// -- `Player` needs a `TestAppContext` this one has none of -- so the wiring is
2100+/// pinned where it can be read: both keyboard doors route through
2101+/// [`Player::step_history`], and its body still keeps the three session caches
2102+/// and the pick, and still drops the plate. What those values *are* is pinned
2103+/// against a real session by the two tests above ([`history_step`] is the free
2104+/// function they drive); this is the copy back into the window's own fields,
2105+/// which no test can call.
2106+#[test]
2107+fn a_history_step_still_takes_its_settings_and_its_pick_back_up() {
2108+ let actions = src_text("player/actions.rs");
2109+ for needle in [
2110+ "self.step_history(PlaybackSession::undo);",
2111+ "self.step_history(PlaybackSession::redo);",
2112+ ] {
2113+ assert!(
2114+ actions.contains(needle),
2115+ "a history door stopped routing through Player::step_history: {needle}"
2116+ );
2117+ }
2118+ let body = fn_body("step_history");
2119+ // The state the step is asked about, and the answer taken back up: every one
2120+ // of these deleted leaves a cache or the pick stale for the next cut, the
2121+ // next frame count, or the next repaint.
2122+ for needle in [
2123+ "let mut caches = SessionCaches {",
2124+ "HistoryBefore::of(",
2125+ "self.fps = caches.fps;",
2126+ "self.proxies_on = caches.proxies_on;",
2127+ "self.auto_proxies_on = caches.auto_proxies_on;",
2128+ "self.sub_track = outcome.sub_track;",
2129+ "if outcome.drop_sub_image {",
2130+ "self.sub_image = None;",
2131+ "self.reset_after_reseek();",
2132+ ] {
2133+ assert!(
2134+ body.contains(needle),
2135+ "Player::step_history no longer carries `{needle}` -- a history step \
2136+ leaves it behind (the app suite cannot see this: it has no \
2137+ TestAppContext to call the door)"
2138+ );
2139+ }
2140+}
2141+
19462142 /// The oracle side of trim-to-playhead (debt #42): needs a subject cut *and*
19472143 /// the playhead actually resting on it, unlike the nudge pair above it which
19482144 /// only needs a cut -- the "spot" a keyless drag would snap to has to be on
@@ -2058,11 +2254,9 @@ fn a_track_can_be_added_dropped_on_edited_and_taken_back() {
20582254 // A library row let go over that row: the same door the Add button
20592255 // uses, told which lane it was let go over.
20602256 let path = session.sources()[0].path.clone();
2061- assert!(
2062- session
2063- .place_stream_at(1.0, &path, 0, Some(v2))
2064- .expect("its own file is on this timeline")
2065- );
2257+ assert!(session
2258+ .place_stream_at(1.0, &path, 0, Some(v2))
2259+ .expect("its own file is on this timeline"));
20662260 assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2");
20672261 assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead");
20682262 // ...with the sound it came with, on the row of its own the drop added:
@@ -2149,22 +2343,18 @@ fn a_selection_drag_moves_every_pick_by_the_same_delta() {
21492343
21502344 // clip0 on V1 at the fixture's own start; clip1 on V1 ten seconds in,
21512345 // appended to the open bed and rippling nothing.
2152- assert!(
2153- session
2154- .place_stream_at(10.0, &second, 0, None)
2155- .expect("av2 is on this timeline")
2156- );
2346+ assert!(session
2347+ .place_stream_at(10.0, &second, 0, None)
2348+ .expect("av2 is on this timeline"));
21572349 let clip0 = session.lane_clips(Lane::V1)[0];
21582350 let clip1 = session.lane_clips(Lane::V1)[1];
21592351 assert_eq!((clip0.start, clip1.start), (0, 300));
21602352
21612353 // clipC on a second video row, well past both of the above.
21622354 let v2 = session.add_lane(LaneKind::Video);
2163- assert!(
2164- session
2165- .place_stream_at(20.0, &path, 0, Some(v2))
2166- .expect("test_av.mp4 is on this timeline")
2167- );
2355+ assert!(session
2356+ .place_stream_at(20.0, &path, 0, Some(v2))
2357+ .expect("test_av.mp4 is on this timeline"));
21682358 let clip_c = session.lane_clips(v2)[0];
21692359 assert_eq!(clip_c.start, 600);
21702360
@@ -2217,28 +2407,22 @@ fn a_selection_drag_refuses_as_one_set_when_any_pick_cannot_land() {
22172407 session.import(&asset("test_av2.mp4")).expect("av2 matches");
22182408 let second = session.sources()[1].path.clone();
22192409
2220- assert!(
2221- session
2222- .place_stream_at(10.0, &second, 0, None)
2223- .expect("av2 is on this timeline")
2224- );
2410+ assert!(session
2411+ .place_stream_at(10.0, &second, 0, None)
2412+ .expect("av2 is on this timeline"));
22252413 let clip0 = session.lane_clips(Lane::V1)[0];
22262414 let clip1 = session.lane_clips(Lane::V1)[1];
22272415
22282416 let v2 = session.add_lane(LaneKind::Video);
2229- assert!(
2230- session
2231- .place_stream_at(0.0, &path, 0, Some(v2))
2232- .expect("test_av.mp4 is on this timeline")
2233- );
2417+ assert!(session
2418+ .place_stream_at(0.0, &path, 0, Some(v2))
2419+ .expect("test_av.mp4 is on this timeline"));
22342420 let clip_c = session.lane_clips(v2)[0];
22352421 // A clip clip1 is not picked, blocking the road on V2 the drag is about
22362422 // to try: clip1 dragged onto V2 lands its head inside this one.
2237- assert!(
2238- session
2239- .place_stream_at(10.0, &second, 0, Some(v2))
2240- .expect("av2 is on this timeline")
2241- );
2423+ assert!(session
2424+ .place_stream_at(10.0, &second, 0, Some(v2))
2425+ .expect("av2 is on this timeline"));
22422426 let blocker = session.lane_clips(v2)[1];
22432427 assert_eq!(blocker.start, 300);
22442428
@@ -2293,20 +2477,16 @@ fn a_three_pick_copy_paste_preserves_gaps_and_lane_assignment() {
22932477 session.import(&asset("test_av2.mp4")).expect("av2 matches");
22942478 let second = session.sources()[1].path.clone();
22952479
2296- assert!(
2297- session
2298- .place_stream_at(10.0, &second, 0, None)
2299- .expect("av2 is on this timeline")
2300- );
2480+ assert!(session
2481+ .place_stream_at(10.0, &second, 0, None)
2482+ .expect("av2 is on this timeline"));
23012483 let clip0 = session.lane_clips(Lane::V1)[0];
23022484 let clip1 = session.lane_clips(Lane::V1)[1];
23032485
23042486 let v2 = session.add_lane(LaneKind::Video);
2305- assert!(
2306- session
2307- .place_stream_at(20.0, &path, 0, Some(v2))
2308- .expect("test_av.mp4 is on this timeline")
2309- );
2487+ assert!(session
2488+ .place_stream_at(20.0, &path, 0, Some(v2))
2489+ .expect("test_av.mp4 is on this timeline"));
23102490 let clip_c = session.lane_clips(v2)[0];
23112491
23122492 // Copied in click order, out of the lanes each was clicked in -- exactly
@@ -2354,20 +2534,16 @@ fn a_colliding_set_paste_refuses_whole() {
23542534 session.import(&asset("test_av2.mp4")).expect("av2 matches");
23552535 let second = session.sources()[1].path.clone();
23562536
2357- assert!(
2358- session
2359- .place_stream_at(10.0, &second, 0, None)
2360- .expect("av2 is on this timeline")
2361- );
2537+ assert!(session
2538+ .place_stream_at(10.0, &second, 0, None)
2539+ .expect("av2 is on this timeline"));
23622540 let clip0 = session.lane_clips(Lane::V1)[0];
23632541 let clip1 = session.lane_clips(Lane::V1)[1];
23642542
23652543 let v2 = session.add_lane(LaneKind::Video);
2366- assert!(
2367- session
2368- .place_stream_at(20.0, &path, 0, Some(v2))
2369- .expect("test_av.mp4 is on this timeline")
2370- );
2544+ assert!(session
2545+ .place_stream_at(20.0, &path, 0, Some(v2))
2546+ .expect("test_av.mp4 is on this timeline"));
23712547 let clip_c = session.lane_clips(v2)[0];
23722548
23732549 let items = [(Lane::V1, clip0), (Lane::V1, clip1), (v2, clip_c)];
@@ -2422,11 +2598,9 @@ fn a_grouped_clip_on_an_added_lane_closes_its_hole_with_its_caption() {
24222598 let (mut session, sub_lane) = with_subtitle_lane();
24232599 let v2 = session.add_lane(LaneKind::Video);
24242600 let path = session.sources()[0].path.clone();
2425- assert!(
2426- session
2427- .place_stream_at(0.0, &path, 0, Some(v2))
2428- .expect("its own file is on this timeline")
2429- );
2601+ assert!(session
2602+ .place_stream_at(0.0, &path, 0, Some(v2))
2603+ .expect("its own file is on this timeline"));
24302604 session
24312605 .place_sub(sub_lane, 0, one_second(0))
24322606 .expect("the caption goes down");
@@ -2486,20 +2660,38 @@ fn a_source_is_only_ever_asked_for_its_peaks_once() {
24862660 .collect::<Vec<_>>()
24872661 };
24882662 let mut waves: HashMap<(PathBuf, usize), Wave> = HashMap::new();
2489- assert_eq!(unseen_sources(&sources, &waves), keys(&sources));
2663+ assert_eq!(
2664+ unseen_sources(&sources, &waves, std::time::Instant::now()),
2665+ keys(&sources)
2666+ );
24902667 // The entry goes in when the decode *starts*, so the sixty repaints a
24912668 // second that happen while it runs must not start it again -- which is
24922669 // what this asserts about a key whose value is not an answer yet.
24932670 waves.insert((a.clone(), 0), Wave::Loading);
24942671 assert_eq!(
2495- unseen_sources(&sources, &waves),
2672+ unseen_sources(&sources, &waves, std::time::Instant::now()),
24962673 keys(&sources[1..]),
24972674 "the file's other stream is a key of its own"
24982675 );
24992676 // A file with no audio is an answer like any other: never re-asked.
25002677 waves.insert((a, 1), Wave::Silent);
25012678 waves.insert((b.clone(), 0), Wave::Silent);
2502- assert!(unseen_sources(&sources, &waves).is_empty());
2679+ assert!(unseen_sources(&sources, &waves, std::time::Instant::now()).is_empty());
2680+ // A decode that *failed* is not an answer: the reason may have gone away
2681+ // (the file was still being copied when it arrived), so it is asked again
2682+ // -- once the stamp is older than the cooldown, so sixty repaints a second
2683+ // do not become sixty decodes.
2684+ let now = std::time::Instant::now();
2685+ waves.insert((b.clone(), 0), Wave::Failed(now));
2686+ assert!(
2687+ unseen_sources(&sources, &waves, now).is_empty(),
2688+ "a failure that just landed is not re-asked at once"
2689+ );
2690+ assert_eq!(
2691+ unseen_sources(&sources, &waves, now + crate::subs::WAVE_RETRY),
2692+ keys(&sources[2..]),
2693+ "and is asked again once the cooldown is out"
2694+ );
25032695 // The stream probe is per *file*: the two entries of `a` ask once.
25042696 let mut streams: HashMap<PathBuf, Vec<StreamInfo>> = HashMap::new();
25052697 assert_eq!(
@@ -2802,13 +2994,21 @@ fn every_verb_the_spine_carried_is_a_right_click_row() {
28022994 // Every menu is a list of actions the keyboard already reaches, so every
28032995 // row can wear its chord (DESIGN §4): a row built here out of an id the
28042996 // registry never files would print an empty column.
2805- for action in MENU_ITEMS.into_iter().chain(BENCH_ITEMS).chain(heads.iter().copied()) {
2997+ for action in MENU_ITEMS
2998+ .into_iter()
2999+ .chain(BENCH_ITEMS)
3000+ .chain(heads.iter().copied())
3001+ {
28063002 assert!(
28073003 ActionId::ALL.contains(&action),
28083004 "{action:?} is a menu row and not a registered action"
28093005 );
28103006 }
2811- for list in [MENU_ITEMS.to_vec(), BENCH_ITEMS.to_vec(), lane_items(Lane::A1)] {
3007+ for list in [
3008+ MENU_ITEMS.to_vec(),
3009+ BENCH_ITEMS.to_vec(),
3010+ lane_items(Lane::A1),
3011+ ] {
28123012 let first = list.iter().position(|&a| destructive(a));
28133013 if let Some(first) = first {
28143014 assert!(
crates/app/src/tests/layout.rsmodified+153 -57
@@ -351,7 +351,7 @@ fn a_lane_row_is_a_fixed_header_and_a_bed_that_can_be_hit() {
351351 /// strip's row at the zoom boundary without the strip to show for it.
352352 #[test]
353353 fn the_scroll_strip_row_comes_and_goes_with_the_zoom() {
354- use crate::{SCROLL_HIT, Split, lanes_h, split_size, timeline_fixed_h, timeline_h};
354+ use crate::{lanes_h, split_size, timeline_fixed_h, timeline_h, Split, SCROLL_HIT};
355355 use gpui::{px, size};
356356
357357 // The strip's row, and only the strip's row, is what the two faces differ
@@ -398,8 +398,8 @@ fn the_scroll_strip_row_comes_and_goes_with_the_zoom() {
398398 /// on the track, the time axis's own thumb turned through a right angle.
399399 #[test]
400400 fn the_lane_thumb_is_the_visible_share_of_the_stack() {
401- use crate::SCROLL_THUMB_MIN;
402401 use crate::lanes_thumb;
402+ use crate::SCROLL_THUMB_MIN;
403403
404404 // Whole stack on screen: the track fills and there is nothing to scroll.
405405 assert_eq!(lanes_thumb(200., 104., 200., 0.), (0., 200.));
@@ -1301,7 +1301,7 @@ fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() {
13011301 /// arrival order, at the end.
13021302 #[test]
13031303 fn a_file_subtitle_group_follows_its_own_row() {
1304- use crate::ui::dock_stance::{Slot, source_list_order};
1304+ use crate::ui::dock_stance::{source_list_order, Slot};
13051305 let film = PathBuf::from("/films/a.mkv");
13061306 let other = PathBuf::from("/rec/b.mp4");
13071307 let loose = PathBuf::from("/subs/late.srt");
@@ -1320,7 +1320,12 @@ fn a_file_subtitle_group_follows_its_own_row() {
13201320 &[film.clone(), other.clone(), film.clone()],
13211321 &[film.clone()]
13221322 ),
1323- [Slot::Media(0), Slot::Media(1), Slot::Media(2), Slot::Subs(0)],
1323+ [
1324+ Slot::Media(0),
1325+ Slot::Media(1),
1326+ Slot::Media(2),
1327+ Slot::Subs(0)
1328+ ],
13241329 );
13251330 // Nobody's `.srt`: still a top-level row, still last.
13261331 assert_eq!(
@@ -1366,7 +1371,9 @@ fn same_named_files_are_told_apart_on_the_metadata_line() {
13661371 .collect();
13671372 let rows = library_rows(&three, &HashMap::new(), &HashMap::new(), None, |_| 90);
13681373 assert_eq!(
1369- rows.iter().map(|row| row.detail.as_str()).collect::<Vec<_>>(),
1374+ rows.iter()
1375+ .map(|row| row.detail.as_str())
1376+ .collect::<Vec<_>>(),
13701377 ["a", "b", ""],
13711378 "twins say which folder they came out of"
13721379 );
@@ -1379,7 +1386,9 @@ fn same_named_files_are_told_apart_on_the_metadata_line() {
13791386 .collect();
13801387 let rows = library_rows(&twins, &HashMap::new(), &HashMap::new(), None, |_| 90);
13811388 assert_eq!(
1382- rows.iter().map(|row| row.detail.as_str()).collect::<Vec<_>>(),
1389+ rows.iter()
1390+ .map(|row| row.detail.as_str())
1391+ .collect::<Vec<_>>(),
13831392 ["#1", "#2"],
13841393 "one folder, one stem: arrival order tells them apart"
13851394 );
@@ -1483,6 +1492,45 @@ fn removing_a_subtitle_row_carries_the_pick_with_it() {
14831492 assert_eq!(sub_pick_after_removal(0, 0, 0), 0);
14841493 }
14851494
1495+/// A `^z` moves rows without saying which one moved, so the pick is followed by
1496+/// what it *names* ([`sub_pick_after_restore`]) rather than by its index: the
1497+/// same three rows as the removal test above, restored instead of taken away,
1498+/// where the index is the wrong answer in the first case and the right one in
1499+/// the second.
1500+#[test]
1501+fn a_restored_palette_carries_the_pick_by_what_it_names() {
1502+ let palette = [
1503+ sub("/films/a.mkv", Some(1), "eng"),
1504+ sub("/films/a.mkv", Some(2), "fre"),
1505+ sub("/films/a.mkv", Some(3), "ger"),
1506+ ];
1507+ // The pick on "ger" at index 1 of the two rows a removal of the first left.
1508+ let short = [palette[1].clone(), palette[2].clone()];
1509+ let picked = SubPickKey::of(&short, 1).expect("a row the pick names");
1510+ assert_eq!(
1511+ sub_pick_after_restore(1, Some(&picked), &palette),
1512+ 2,
1513+ "the row above it came back"
1514+ );
1515+ // The row that came back *below* the pick leaves it where it was.
1516+ let short = [palette[0].clone(), palette[1].clone()];
1517+ let picked = SubPickKey::of(&short, 1).expect("a row the pick names");
1518+ assert_eq!(
1519+ sub_pick_after_restore(1, Some(&picked), &palette),
1520+ 1,
1521+ "a row after it is not its business"
1522+ );
1523+ // The picked row itself gone from the restored palette: the old index
1524+ // clamped into it, which is the removal door's own fallback.
1525+ let picked = SubPickKey::of(&palette, 2).expect("a row the pick names");
1526+ assert_eq!(sub_pick_after_restore(2, Some(&picked), &palette[..2]), 1);
1527+ assert_eq!(
1528+ sub_pick_after_restore(0, None, &[]),
1529+ 0,
1530+ "an emptied palette is a state, not a panic"
1531+ );
1532+}
1533+
14861534 /// The same claim from the click's end, on the order imports actually
14871535 /// arrive in: two films opened one after the other and an `.srt` dropped
14881536 /// last interleave in the flat list, and the display reorders them. What a
@@ -1707,7 +1755,11 @@ fn darkroom_lane_header_verbs_are_targeted_and_visible() {
17071755 // `overlays.rs` routes those rows through the same `act_lane` door the
17081756 // head's buttons used.
17091757 let bench = src_text("ui/bench_stance.rs");
1710- for gone in ["\"bench-mix-lane\"", "\"bench-remove-lane\"", "lane.{}.remove"] {
1758+ for gone in [
1759+ "\"bench-mix-lane\"",
1760+ "\"bench-remove-lane\"",
1761+ "lane.{}.remove",
1762+ ] {
17111763 assert!(!bench.contains(gone), "the lane head still wears {gone}");
17121764 }
17131765 for door in ["\"bench-show-sub-lane\"", "this.show_sub_lane(lane, cx)"] {
@@ -1746,8 +1798,8 @@ fn darkroom_lane_header_verbs_are_targeted_and_visible() {
17461798 fn a_dragged_divider_stops_before_either_panel_disappears() {
17471799 use crate::ui::theme::INSPECTOR_MIN_W;
17481800 use crate::{
1749- SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w,
1750- split_drag_size, split_size, timeline_fixed_h, timeline_h,
1801+ inspector_w, library_w, split_drag_size, split_size, timeline_fixed_h, timeline_h, Split,
1802+ SIDE_MAX_FRAC, SPLIT_W, TIMELINE_MAX_SHARE, TOOLBAR_H,
17511803 };
17521804 use gpui::{point, px, size};
17531805
@@ -1867,7 +1919,7 @@ fn a_dragged_divider_stops_before_either_panel_disappears() {
18671919 fn the_darkroom_seams_stop_before_either_side_disappears() {
18681920 use crate::ui::theme::INSPECTOR_MIN_W;
18691921 use crate::{
1870- BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, split_bounds, split_drag_size, split_size,
1922+ split_bounds, split_drag_size, split_size, Split, BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W,
18711923 };
18721924 use gpui::{point, px, size};
18731925
@@ -1926,9 +1978,9 @@ fn the_darkroom_seams_stop_before_either_side_disappears() {
19261978 /// ~2px at the old `BENCH_MIN_H = 80.`).
19271979 #[test]
19281980 fn both_default_lanes_fit_the_bench_at_its_floor() {
1929- use crate::BENCH_MIN_H;
1930- use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H, row_h};
1981+ use crate::ui::bench_stance::{row_h, LANE_MIN_H, ROW_GAP, RULER_H};
19311982 use crate::ui::stance::BENCH_CHROME_H;
1983+ use crate::BENCH_MIN_H;
19321984
19331985 let box_h = BENCH_MIN_H - BENCH_CHROME_H;
19341986 let avail = box_h - RULER_H - ROW_GAP;
@@ -1968,9 +2020,9 @@ fn both_default_lanes_fit_the_bench_at_its_floor() {
19682020 /// painted bounds back, so it stays geometry-only, same as its neighbours.
19692021 #[test]
19702022 fn the_whole_bench_stack_fits_its_own_floor_with_the_ledger_seam_clear() {
1971- use crate::BENCH_MIN_H;
19722023 use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H};
19732024 use crate::ui::stance::BENCH_CHROME_H;
2025+ use crate::BENCH_MIN_H;
19742026
19752027 const BENCH_BORDER_T: f32 = 1.;
19762028 const BENCH_PY_TOP: f32 = 4.;
@@ -2040,9 +2092,9 @@ fn a_lane_row_fits_what_its_own_head_draws() {
20402092 #[test]
20412093 fn a_saved_seam_survives_a_reload() {
20422094 use crate::{
2043- BENCH_MIN_H, SIDE_MAX_FRAC, Split, Splits, load_stance_splits_from, save_stance_splits_to,
2095+ load_stance_splits_from, save_stance_splits_to, Split, Splits, BENCH_MIN_H, SIDE_MAX_FRAC,
20442096 };
2045- use gpui::{Pixels, Size, px, size};
2097+ use gpui::{px, size, Pixels, Size};
20462098
20472099 let dir = engine::scratch::Scratch::dir("edith-stance-splits");
20482100 let path = dir.join("stance-splits");
@@ -2085,7 +2137,7 @@ fn a_saved_seam_survives_a_reload() {
20852137 /// drag that never started (`None`) owes nothing.
20862138 #[test]
20872139 fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() {
2088- use crate::{Split, player::timeline_edit::split_drag_owes_save};
2140+ use crate::{player::timeline_edit::split_drag_owes_save, Split};
20892141
20902142 assert!(split_drag_owes_save(Some(Split::Dock)));
20912143 assert!(split_drag_owes_save(Some(Split::Bench)));
@@ -2099,8 +2151,8 @@ fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() {
20992151 /// `load_stance_splits`'s doc comment promises.
21002152 #[test]
21012153 fn a_missing_stance_splits_file_leaves_every_region_at_its_default() {
2102- use crate::{Split, load_stance_splits_from};
2103- use gpui::{Pixels, Size, px, size};
2154+ use crate::{load_stance_splits_from, Split};
2155+ use gpui::{px, size, Pixels, Size};
21042156
21052157 let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing");
21062158 let window: Size<Pixels> = size(px(1280.), px(720.));
@@ -2182,13 +2234,7 @@ fn the_stance_renders_its_five_regions_in_the_documented_order() {
21822234 // Open paren only, no close: DESIGN §12 steps 3 and 4 hand most of the
21832235 // regions player/window state to read, so their call sites carry
21842236 // arguments now. Order is what this asserts, not arity.
2185- let calls = [
2186- "screen(",
2187- "time_band(",
2188- "bench(",
2189- "ledger(",
2190- "dock(",
2191- ];
2237+ let calls = ["screen(", "time_band(", "bench(", "ledger(", "dock("];
21922238 let composed: Vec<usize> = calls
21932239 .iter()
21942240 .map(|c| {
@@ -2662,12 +2708,13 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() {
26622708 text.lines()
26632709 .filter(|l| !l.contains("=> format!(\"{full} (global)\")"))
26642710 .any(|line| {
2665- line.match_indices(&format!("ActionId::{name}")).any(|(i, m)| {
2666- !line[i + m.len()..]
2667- .chars()
2668- .next()
2669- .is_some_and(|c| c.is_alphanumeric() || c == '_')
2670- })
2711+ line.match_indices(&format!("ActionId::{name}"))
2712+ .any(|(i, m)| {
2713+ !line[i + m.len()..]
2714+ .chars()
2715+ .next()
2716+ .is_some_and(|c| c.is_alphanumeric() || c == '_')
2717+ })
26712718 })
26722719 }
26732720 let darkroom = [
@@ -2946,7 +2993,7 @@ fn the_bench_answers_a_wheel_notch_anywhere_over_it() {
29462993 /// kept beside the first ([`Splits::clear`]).
29472994 #[test]
29482995 fn a_double_pressed_divider_forgets_the_size_it_was_dragged_to() {
2949- use crate::layout::{Split, Splits, split_size};
2996+ use crate::layout::{split_size, Split, Splits};
29502997 use gpui::{px, size};
29512998
29522999 let window = size(px(1280.), px(720.));
@@ -3007,7 +3054,8 @@ fn the_seam_paints_nothing_until_a_pointer_finds_it() {
30073054 // gets after it no longer needs it (a `bench=207` -- a press with no
30083055 // drag in it -- beside a dragged `dock=277`).
30093056 assert!(
3010- body.find(".group(group.clone())").expect("the band's group")
3057+ body.find(".group(group.clone())")
3058+ .expect("the band's group")
30113059 < body.find("border_t_1()").expect("the hairline"),
30123060 "the hairline is painted outside the band: {body}"
30133061 );
@@ -3030,13 +3078,12 @@ fn the_bench_seam_reaches_no_further_than_every_other_seam() {
30303078 );
30313079 }
30323080
3033-
30343081 /// The clamp table, driven: the seam refuses exactly two things, and neither
30353082 /// is anywhere near where a hand drags. Measured live at 2560x1440 --
30363083 /// `bench=105` at the floor, `bench=1164` at the ceiling.
30373084 #[test]
30383085 fn the_bench_seam_stops_at_its_floor_and_its_ceiling() {
3039- use crate::{BENCH_MIN_H, Split, split_bounds, split_size};
3086+ use crate::{split_bounds, split_size, Split, BENCH_MIN_H};
30403087 use gpui::{px, size};
30413088
30423089 let window = size(px(2560.), px(1440.));
@@ -3065,8 +3112,11 @@ fn the_bench_seam_stops_at_its_floor_and_its_ceiling() {
30653112 fn the_lane_bed_clips_its_clips_at_the_pinned_heads() {
30663113 let src = src_text("ui/bench_stance.rs");
30673114 let start = src.find(r#".id(("bench-bed""#).expect("the bed");
3068- let bed =
3069- &src[start..start + src[start..].find(".bg(rgb(DARK_CANVAS()))").expect("its fill")];
3115+ let bed = &src[start
3116+ ..start
3117+ + src[start..]
3118+ .find(".bg(rgb(DARK_CANVAS()))")
3119+ .expect("its fill")];
30703120 assert!(
30713121 bed.contains(".overflow_hidden()"),
30723122 "the bed lets its clips paint outside itself, straight over the \
@@ -3130,7 +3180,10 @@ fn a_source_row_shows_its_name_before_anything_else() {
31303180 "the metadata line no longer drops the decoder seat"
31313181 );
31323182 let usage = &dock[dock.find("fn usage_line(").expect("the usage line")..start];
3133- assert!(!usage.contains("use{}"), "the metadata line still counts uses");
3183+ assert!(
3184+ !usage.contains("use{}"),
3185+ "the metadata line still counts uses"
3186+ );
31343187 // DESIGN §8: the permanent footer telling the editor how to use a list
31353188 // ("drag · ↵ add · double-click plays") is instructional copy and is gone.
31363189 assert!(
@@ -3183,7 +3236,10 @@ fn every_dock_body_mounts_the_ring_it_is_standing_in_for() {
31833236 "the dock's key handler stops a stroke outside its tab/escape branches"
31843237 );
31853238 for branch in ["is_focus_cycle_key(key)", "is_focus_exit_key(key)"] {
3186- assert!(body.contains(branch), "{branch} left the dock's key handler");
3239+ assert!(
3240+ body.contains(branch),
3241+ "{branch} left the dock's key handler"
3242+ );
31873243 }
31883244 }
31893245
@@ -3299,7 +3355,10 @@ fn a_room_ghost_wears_no_chord_that_repeats_its_name() {
32993355 fn the_ledger_carries_the_rooms_four_verbs_and_no_rail_remains() {
33003356 let src = src_text("ui/stance.rs");
33013357 for gone in ["stance-spine", "spine_stance", "SPINE_W", "fn spine("] {
3302- assert!(!src.contains(gone), "the rail is still in the stance: {gone}");
3358+ assert!(
3359+ !src.contains(gone),
3360+ "the rail is still in the stance: {gone}"
3361+ );
33033362 }
33043363 let ledger = &src[src.find("fn ledger(").expect("the ledger strip")
33053364 ..src.find("/// The dock:").expect("the dock frame")];
@@ -3341,8 +3400,8 @@ fn the_ledger_carries_the_rooms_four_verbs_and_no_rail_remains() {
33413400 /// deletion.
33423401 #[test]
33433402 fn select_all_left_the_ruler_for_the_rulers_own_menu() {
3344- use crate::ActionId;
33453403 use crate::menus::BENCH_ITEMS;
3404+ use crate::ActionId;
33463405 let bench = src_text("ui/bench_stance.rs");
33473406 for gone in ["bench-select-all", "select_all_band", "SELECT_ALL_PAD"] {
33483407 assert!(!bench.contains(gone), "the ruler still carries {gone}");
@@ -3431,7 +3490,10 @@ fn one_name_per_source_one_stem_helper_and_one_save_door() {
34313490 // a path with no name at all still reads as something.
34323491 use crate::files::{file_name, stem};
34333492 use std::path::Path;
3434- assert_eq!(stem(Path::new("/x/he_is_not_the_only_one.mp4")), "he_is_not_the_only_one");
3493+ assert_eq!(
3494+ stem(Path::new("/x/he_is_not_the_only_one.mp4")),
3495+ "he_is_not_the_only_one"
3496+ );
34353497 assert_eq!(stem(Path::new("/x/untitled")), "untitled");
34363498 assert_eq!(stem(Path::new("/x/a.b.edith")), "a.b");
34373499 assert_eq!(stem(Path::new("/")), file_name(Path::new("/")));
@@ -3461,7 +3523,6 @@ fn the_ruler_plate_shows_the_timecode_only_while_a_scrub_is_live() {
34613523 );
34623524 }
34633525
3464-
34653526 /// The band overflowed its own column at 1280x720 (`$EDITH_HITMAP`:
34663527 /// `action.Export x=1113 w=80` with the column ending at x=995, the contact
34673528 /// strip measured `w=0`), so the Export chip was invisible under the dock and
@@ -3471,8 +3532,14 @@ fn the_ruler_plate_shows_the_timecode_only_while_a_scrub_is_live() {
34713532 #[test]
34723533 fn the_time_band_never_paints_outside_its_own_column() {
34733534 let src = src_text("ui/timeband_stance.rs");
3474- let start = src.find(r#".id("stance-time-band-row")"#).expect("the band row");
3475- let row = &src[start..start + src[start..].find(".child(hero_timecode(").expect("the timecode")];
3535+ let start = src
3536+ .find(r#".id("stance-time-band-row")"#)
3537+ .expect("the band row");
3538+ let row = &src[start
3539+ ..start
3540+ + src[start..]
3541+ .find(".child(hero_timecode(")
3542+ .expect("the timecode")];
34763543 assert!(
34773544 row.contains(".overflow_hidden()"),
34783545 "the band row lets its children paint (and be clicked) under the dock: {row}"
@@ -3518,9 +3585,16 @@ fn the_band_sheds_its_chords_and_nothing_else() {
35183585 fn every_ghost_in_the_time_band_carries_a_full_hit_area() {
35193586 let src = src_text("ui/timeband_stance.rs");
35203587 let start = src.find("fn ghost(").expect("the band's ghost");
3521- let ghost = &src[start..start + src[start..].find(".child(glyph.into())").expect("its glyph")];
3588+ let ghost = &src[start
3589+ ..start
3590+ + src[start..]
3591+ .find(".child(glyph.into())")
3592+ .expect("its glyph")];
35223593 for needle in [".min_w(px(HIT_MIN))", ".min_h(px(HIT_MIN))"] {
3523- assert!(ghost.contains(needle), "the band's ghost lost {needle}: {ghost}");
3594+ assert!(
3595+ ghost.contains(needle),
3596+ "the band's ghost lost {needle}: {ghost}"
3597+ );
35243598 }
35253599 assert!(HIT_MIN >= 24.);
35263600 }
@@ -3532,8 +3606,15 @@ fn every_ghost_in_the_time_band_carries_a_full_hit_area() {
35323606 #[test]
35333607 fn the_band_writes_no_monitoring_level() {
35343608 let src = src_text("ui/timeband_stance.rs");
3535- for gone in ["player.volume.percent()", "fn volume_readout(", "fn volume_slider("] {
3536- assert!(!src.contains(gone), "the monitoring cluster is back in the band: {gone}");
3609+ for gone in [
3610+ "player.volume.percent()",
3611+ "fn volume_readout(",
3612+ "fn volume_slider(",
3613+ ] {
3614+ assert!(
3615+ !src.contains(gone),
3616+ "the monitoring cluster is back in the band: {gone}"
3617+ );
35373618 }
35383619 }
35393620
@@ -3552,7 +3633,11 @@ fn transport_verbs_differ_by_shape_not_only_by_chord() {
35523633 let mut seen = shapes.to_vec();
35533634 seen.sort();
35543635 seen.dedup();
3555- assert_eq!(seen.len(), shapes.len(), "two transport verbs share one glyph: {shapes:?}");
3636+ assert_eq!(
3637+ seen.len(),
3638+ shapes.len(),
3639+ "two transport verbs share one glyph: {shapes:?}"
3640+ );
35563641 }
35573642
35583643 /// DESIGN §6: "the cut readout is the odometer". Keyed off the selection it
@@ -3745,7 +3830,9 @@ fn the_export_section_is_four_rows_and_no_fifth() {
37453830 .find("fn export_section(")
37463831 .expect("the export section");
37473832 let body = &source[start..];
3748- let end = body.find("\n/// The page itself").expect("the page's render fn");
3833+ let end = body
3834+ .find("\n/// The page itself")
3835+ .expect("the page's render fn");
37493836 let body = &body[..end];
37503837 let rows = [
37513838 "settings-export-picture",
@@ -3760,10 +3847,16 @@ fn the_export_section_is_four_rows_and_no_fifth() {
37603847 // unrated one's readout, never both at once -- so the count is by label,
37613848 // not by id.
37623849 for label in ["\"Picture\"", "\"Sound\"", "\"Encoder\"", "\"Range\""] {
3763- assert!(body.contains(label), "the EXPORT section has no {label} row");
3850+ assert!(
3851+ body.contains(label),
3852+ "the EXPORT section has no {label} row"
3853+ );
37643854 }
37653855 let ids = body.match_indices("\"settings-export-").count();
3766- assert_eq!(ids, 5, "the EXPORT section grew a row past the four (the two Sound rows are one row's two shapes)");
3856+ assert_eq!(
3857+ ids, 5,
3858+ "the EXPORT section grew a row past the four (the two Sound rows are one row's two shapes)"
3859+ );
37673860 assert!(
37683861 source.contains("what a delivery is written as"),
37693862 "the section lost its head"
@@ -3780,7 +3873,7 @@ fn the_export_section_is_four_rows_and_no_fifth() {
37803873 /// cannot write, because [`Player::set_format`] would only refuse it back.
37813874 #[test]
37823875 fn the_picture_row_cycles_codec_and_container_together_and_skips_a_refusal() {
3783- use crate::ui::settings_stance::{PICTURE_CYCLE, next_picture, picture_label};
3876+ use crate::ui::settings_stance::{next_picture, picture_label, PICTURE_CYCLE};
37843877 assert_eq!(
37853878 PICTURE_CYCLE,
37863879 [
@@ -4017,7 +4110,6 @@ fn no_region_root_wears_a_focus_ring() {
40174110 }
40184111 }
40194112
4020-
40214113 /// The user could not find the three columns (2026-09-10: "I couldn't realize
40224114 /// them when I look at"), because their heads were 12px `ink3` -- the room's
40234115 /// quietest type -- with a prose tail running on after each one. The page's
@@ -4187,9 +4279,13 @@ fn the_settings_page_is_a_centred_modal_with_one_column_of_measure() {
41874279 #[test]
41884280 fn the_picture_row_tail_is_the_current_format_alone() {
41894281 let source = src_text("ui/settings_stance.rs");
4190- let start = source.find("fn export_section(").expect("the export section");
4282+ let start = source
4283+ .find("fn export_section(")
4284+ .expect("the export section");
41914285 let body = &source[start..];
4192- let body = &body[..body.find("\n/// The page itself").expect("the page's render fn")];
4286+ let body = &body[..body
4287+ .find("\n/// The page itself")
4288+ .expect("the page's render fn")];
41934289 assert!(
41944290 !body.contains("PICTURE_CYCLE"),
41954291 "the Picture row walks the whole cycle to build its tail again"
crates/app/src/tests/media.rsmodified+11 -10
@@ -6,8 +6,8 @@ use crate::player::library::{
66 auto_proxies_pref_path, load_auto_proxies_pref, save_auto_proxies_pref,
77 };
88 use crate::subs::{
9- SUB_SIZE_RANGE, audio_import_tail, load_subtitle_style, save_subtitle_style, sub_line_h_for,
10- subtitle_style_path,
9+ audio_import_tail, load_subtitle_style, save_subtitle_style, sub_line_h_for,
10+ subtitle_style_path, SUB_SIZE_RANGE,
1111 };
1212 use crate::ui::preview::{bgra_to_rgba, screenshot_path};
1313
@@ -32,8 +32,8 @@ fn an_audio_import_names_its_rate_channels_and_length() {
3232 /// stuck read and never as a frozen window.
3333 #[test]
3434 fn an_import_line_says_a_stage_has_stopped_moving_and_only_then() {
35- use std::sync::Arc;
3635 use std::sync::atomic::{AtomicU8, Ordering::Relaxed};
36+ use std::sync::Arc;
3737 let stage = Arc::new(AtomicU8::new(ImportStage::Header as u8));
3838 let started = Instant::now() - Duration::from_secs(9);
3939 let mut import = Import {
@@ -303,7 +303,10 @@ fn a_strand_slot_on_a_single_strand_clip_is_the_clip_s_own_colour() {
303303 // The clip's own slot is never redirected -- it is what the fallback
304304 // lands on.
305305 assert_eq!(VizSlot::Main.picked(one), VizSlot::Main);
306- assert_eq!(VizSlot::Strand.picked(with_viz_paint_strands(one, 2)), VizSlot::Strand);
306+ assert_eq!(
307+ VizSlot::Strand.picked(with_viz_paint_strands(one, 2)),
308+ VizSlot::Strand
309+ );
307310 }
308311
309312 /// A seek says nothing until it has stood: an ordinary one is a flicker and
@@ -326,8 +329,8 @@ fn a_seek_says_so_only_once_it_has_stood() {
326329 /// fifty-one seconds on a 25 GB film.
327330 #[test]
328331 fn a_silence_card_is_up_while_its_scan_runs_and_says_where_it_has_got_to() {
329- use std::sync::Arc;
330332 use std::sync::atomic::Ordering::Relaxed;
333+ use std::sync::Arc;
331334 let progress = Arc::new(engine::silence::Progress::default());
332335 // Two hours and eight minutes, as the header claims it.
333336 progress.total.store(7680, Relaxed);
@@ -757,11 +760,9 @@ fn every_codec_row_is_offered_or_says_why_not() {
757760 detail.contains("ec-vorbis"),
758761 "the row names the encoder like every other live one: {detail}"
759762 );
760- assert!(
761- FORMATS
762- .into_iter()
763- .any(|(row, _, _, detail)| row.contains(&Format::Hevc) && detail.contains("intra"))
764- );
763+ assert!(FORMATS
764+ .into_iter()
765+ .any(|(row, _, _, detail)| row.contains(&Format::Hevc) && detail.contains("intra")));
765766 // The destination follows the format and keeps the stem, mp4 included.
766767 assert_eq!(
767768 retarget(std::path::Path::new("/a/take.export.mp4"), Format::Wav),
crates/app/src/tests/mod.rsmodified+31 -32
@@ -10,56 +10,55 @@ mod media;
1010 mod view;
1111
1212 use super::{
13- ACCENT_PRIMARY, AUDIO_KBPS, BG_RAISED, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W,
14- ColorEdit, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT,
15- EQ_FREQ_HIGH,
16- EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW,
17- EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, Enable,
18- BPS_COARSE, BPS_FINE, BPS_MAX, BPS_MIN, EXPORT_MOMENT_H, EncoderSeat, FORMATS, Format, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN,
19- KEYS_ROW_H, KEYS_W, KeyRow, LABEL_H, LANE_H, LANES_MAX, LATE_RESYNC, LIBRARY_MAX_W,
20- BENCH_ITEMS, LIBRARY_MIN_W, Lane, MB_FLOOR, MENU_ITEMS, MENU_PAD,
21- MENU_ROW_H, MENU_W, NO_FILE, NOTICES_MAX, NumberEdit, OVERLAID, PANEL_H, RESYNC_GAP,
22- ROW_ITEMS, RULER_HIT_H, RowCtx, RowItem, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS,
13+ active_lane, auto_bps, band_label, bitrate_detail, clipboard_after_remove, color_snap,
14+ containers, destructive, enable, enable_lane, envelope, eq_card_w, eq_freq, eq_freq_label,
15+ eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, export_path, export_settings,
16+ format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, frame_rate_ladder,
17+ histogram, inserted_band, is_project, keymap, keys_rows, keys_rows_matching, lane_items,
18+ lanes_h, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play,
19+ notice_tone, panel_h, parse_budget, project_path, proxies_to_start, push_notice, px_below,
20+ range_word, rate_label, retarget, row_enable, row_items, scrub_due, secs_label, should_resync,
21+ silence_rate, size_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at,
22+ sub_pick_after_removal, sub_pick_after_restore, subtitle_plan, timecode, timeline_fixed_h,
23+ tip_may_paint, transport, typed, unseen_paths, unseen_sources, viz_held_paint, whole_take,
24+ window_title, Clip, ColorEdit, Ctx, Enable, EncoderSeat, Format, KeyRow, Lane, NumberEdit,
25+ RowCtx, RowItem, Source, Speed, StreamInfo, SubPickKey, Transport, VizSlot, Volume, Wave,
26+ ACCENT_PRIMARY, AUDIO_KBPS, BENCH_ITEMS, BG_RAISED, BPS_COARSE, BPS_FINE, BPS_MAX, BPS_MIN,
27+ COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX,
28+ EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H,
29+ EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE,
30+ EXPORT_DONE, EXPORT_MOMENT_H, FORMATS, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN,
31+ KEYS_ROW_H, KEYS_W, LABEL_H, LANES_MAX, LANE_H, LATE_RESYNC, LIBRARY_MAX_W, LIBRARY_MIN_W,
32+ MB_FLOOR, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_W, NOTICES_MAX, NO_FILE, OVERLAID, PANEL_H,
33+ RESYNC_GAP, ROW_ITEMS, RULER_HIT_H, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS,
2334 SPEED_PRESETS, SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_PLAN_CHARS,
24- Source, Speed, StreamInfo, TIMELINE_SHARE, Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL,
25- WAVE_COLS_MAX, Wave, ZOOM_MIN_FRAMES, active_lane, auto_bps, band_label, bitrate_detail,
26- clipboard_after_remove, color_snap, containers, destructive, enable, enable_lane, envelope, eq_card_w,
27- eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, export_path,
28- export_settings, format_refusal, fps_choices, fps_label, frac_along, frac_down,
29- frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, keys_rows, keys_rows_matching, lanes_h,
30- lane_items, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play,
31- notice_tone, panel_h, parse_budget, project_path, range_word, proxies_to_start, push_notice, px_below, retarget,
32- row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label,
33- rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal,
34- subtitle_plan, timecode, timeline_fixed_h, tip_may_paint,
35- transport, typed, unseen_paths, unseen_sources, viz_held_paint, VizSlot, whole_take,
36- window_title,
35+ TIMELINE_SHARE, VOLUME_W, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, ZOOM_MIN_FRAMES,
3736 };
3837
3938 use super::{
40- ActionId, Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, IMPORT_STALL, Import, ImportStage,
41- Landing, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat, SAMPLE_RATES, SEEK_STALL,
42- Scale, ScanKey, ScanPlan, SilenceScan, SubClip, View, ZOOM_OUT_MARGIN, ZOOM_STEP, arrival,
43- audio_rate_choices, av1_hw_warning, clip_width, clock, encoder_choices, encoder_label,
39+ arrival, audio_rate_choices, av1_hw_warning, clip_width, clock, encoder_choices, encoder_label,
4440 eta_secs, file_name, file_uri, fit_choices, frames_of_us, full_scan_key, import_line, landing,
4541 lane_refuses, launch_queue, library_rows, live_idx, next_fit, next_resolution, note_progress,
4642 pending_fps_choices, pending_resolution_choices, px_along, read_ahead, repeats,
4743 resolution_choices, resolution_ladder, sample_rate_choices, scan_plan, seek_line,
4844 silence_cached, silence_line, slice_whole_levels, source_secs, stash_or_write, tone_choices,
49- tone_label, trimmed_clip, trimmed_sub, trims, unscannable, unusable,
45+ tone_label, trimmed_clip, trimmed_sub, trims, unscannable, unusable, ActionId, Choice, Edge,
46+ Import, ImportStage, Landing, LaneKind, Preset, Repeat, Scale, ScanKey, ScanPlan, SilenceScan,
47+ SubClip, View, EDGE_W, ETA_SPAN, FITS, FRAME_RATES, IMPORT_STALL, PPS_DEFAULT, PPS_MIN,
48+ RESOLUTIONS, SAMPLE_RATES, SEEK_STALL, ZOOM_OUT_MARGIN, ZOOM_STEP,
5049 };
5150
5251 use super::{
53- SUB_BOTTOM, SUB_CUE_MIN_W, SUB_LINE_H, SUB_TEXT, Subs, carries_subtitles, cue_box, cues_at,
54- file_tint, is_subtitle, lang_human, sub_bottom, sub_pick_name, subtitle_detail,
55- subtitle_notice, subtitle_rows, subtitle_tail, subtitle_toggle_notice, walk_subtitles,
52+ carries_subtitles, cue_box, cues_at, file_tint, is_subtitle, lang_human, sub_bottom,
53+ sub_pick_name, subtitle_detail, subtitle_notice, subtitle_rows, subtitle_tail,
54+ subtitle_toggle_notice, walk_subtitles, Subs, SUB_BOTTOM, SUB_CUE_MIN_W, SUB_LINE_H, SUB_TEXT,
5655 };
5756
5857 use engine::PlaybackSession;
5958
6059 use engine::scale::FitPolicy;
6160
62-use gpui::{Bounds, Pixels, point, px, size};
61+use gpui::{point, px, size, Bounds, Pixels};
6362
6463 use std::collections::HashMap;
6564
crates/app/src/tests/view.rsmodified+2 -2
@@ -891,7 +891,7 @@ fn the_zoom_button_says_how_much_is_on_the_bed() {
891891 /// lives.
892892 #[test]
893893 fn tab_cycles_dock_bench_inspector_and_wraps() {
894- use crate::ui::stance::{Surface, next_surface};
894+ use crate::ui::stance::{next_surface, Surface};
895895
896896 assert_eq!(next_surface(Surface::Dock, false), Surface::Bench);
897897 assert_eq!(next_surface(Surface::Bench, false), Surface::Inspector);
@@ -912,7 +912,7 @@ fn tab_cycles_dock_bench_inspector_and_wraps() {
912912 /// surface being entered is always the one mounted.
913913 #[test]
914914 fn surface_wants_src_active_mounts_the_tab_before_focus_lands_on_it() {
915- use crate::ui::stance::{Surface, surface_wants_src_active};
915+ use crate::ui::stance::{surface_wants_src_active, Surface};
916916
917917 assert_eq!(surface_wants_src_active(Surface::Dock), Some(true));
918918 assert_eq!(surface_wants_src_active(Surface::Inspector), Some(false));
crates/app/src/ui/settings_stance.rsmodified+24 -13
@@ -684,7 +684,11 @@ fn export_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElement
684684 .as_ref()
685685 .and_then(|session| format_refusal(session, format))
686686 .map(|why| (short_reason(&why).into(), INK4()));
687- let picture_ink = if refused_now.is_some() { INK4() } else { INK1() };
687+ let picture_ink = if refused_now.is_some() {
688+ INK4()
689+ } else {
690+ INK1()
691+ };
688692 let (codec, rated) = sound_codec(format);
689693 let seat = player.encoder_seat();
690694 let av1_gpu = seat == EncoderSeat::Hardware && matches!(format, Format::Av1 | Format::Av1Mp4);
@@ -745,18 +749,25 @@ fn export_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElement
745749 )
746750 .into_any_element()
747751 }))
748- .child(row_chord(
749- "settings-export-encoder",
750- "Encoder",
751- encoder_word(seat),
752- "which encoder writes the picture: the GPU where this machine has a seat, or the CPU",
753- "g",
754- av1_gpu.then(|| (AV1_GPU_NOTICE.into(), NOTICE_LOOK())),
755- player,
756- cx.listener(|this, _: &ClickEvent, _, cx| {
757- this.cycle_encoder(cx);
758- }),
759- ))
752+ // The encoder writes the *picture*, and the engine opens no seat for a
753+ // song: with WAV/FLAC/MP3/Ogg picked the row would be a button that
754+ // does nothing when pressed. The export moment mounts no row there
755+ // either (`Format::has_video`), so this is that same rule rather than a
756+ // third treatment.
757+ .children(format.has_video().then(|| {
758+ row_chord(
759+ "settings-export-encoder",
760+ "Encoder",
761+ encoder_word(seat),
762+ "which encoder writes the picture: the GPU where this machine has a seat, or the CPU",
763+ "g",
764+ av1_gpu.then(|| (AV1_GPU_NOTICE.into(), NOTICE_LOOK())),
765+ player,
766+ cx.listener(|this, _: &ClickEvent, _, cx| {
767+ this.cycle_encoder(cx);
768+ }),
769+ )
770+ }))
760771 // Read-only: the range is set on the timeline with the marks
761772 // themselves ([`keymap::ActionId::SetIn`]/`SetOut`), which is where a
762773 // person can see what they are marking.
crates/engine/src/edith.rsmodified+99 -22
@@ -387,8 +387,24 @@ pub fn save(
387387 let result = std::fs::File::create(&part)
388388 .and_then(|mut f| {
389389 f.write_all(&emit(
390- &dir, sources, lanes, gains, subs, subtitles, eq, color, transform, resolution,
391- fps, tone, proxy, auto_proxy, encoder, limiter, sample_rate, playhead,
390+ &dir,
391+ sources,
392+ lanes,
393+ gains,
394+ subs,
395+ subtitles,
396+ eq,
397+ color,
398+ transform,
399+ resolution,
400+ fps,
401+ tone,
402+ proxy,
403+ auto_proxy,
404+ encoder,
405+ limiter,
406+ sample_rate,
407+ playhead,
392408 ))?;
393409 f.sync_all()
394410 })
@@ -810,10 +826,9 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
810826 }
811827 b"samplerate" if v17 => {
812828 if doc.sample_rate.is_some() || !doc.sources.is_empty() {
813- return Err(format!(
814- "line {n}: samplerate belongs once, before the sources"
815- )
816- .into());
829+ return Err(
830+ format!("line {n}: samplerate belongs once, before the sources").into(),
831+ );
817832 }
818833 let f = fields(rest, 1, "samplerate", n)?;
819834 let rate = number(f[0], n)?;
@@ -838,9 +853,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
838853 }
839854 b"proxy" if v12 => {
840855 if !doc.sources.is_empty() {
841- return Err(
842- format!("line {n}: proxy belongs once, before the sources").into()
843- );
856+ return Err(format!("line {n}: proxy belongs once, before the sources").into());
844857 }
845858 let f = fields(rest, 1, "proxy", n)?;
846859 doc.proxy = match f[0] {
@@ -877,7 +890,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
877890 b"encoder" if v14 => {
878891 if !doc.sources.is_empty() {
879892 return Err(
880- format!("line {n}: encoder belongs once, before the sources").into()
893+ format!("line {n}: encoder belongs once, before the sources").into(),
881894 );
882895 }
883896 let f = fields(rest, 1, "encoder", n)?;
@@ -1215,7 +1228,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
12151228 fade_in: number(f.get(9).copied().unwrap_or(b"0"), n)?.min(frames),
12161229 fade_out: number(f.get(10).copied().unwrap_or(b"0"), n)?.min(frames),
12171230 transition_out: number(f.get(11).copied().unwrap_or(b"0"), n)?.min(frames),
1218- visualizer: number(f.get(13).copied().unwrap_or(b"0"), n)? as u8,
1231+ visualizer: flags_byte(f.get(13).copied().unwrap_or(b"0"), n)?,
12191232 viz_paint: number64(f.get(14).copied().unwrap_or(b"0"), n)?,
12201233 start: number(f[0], n)?,
12211234 in_frame,
@@ -1472,6 +1485,15 @@ fn float(field: &[u8], line: usize) -> crate::Result<f32> {
14721485 }
14731486 }
14741487
1488+/// A clip's visualizer field: every bit of the byte is a flag
1489+/// ([`crate::decode::VIZ_STYLE_FILL`]'s low bits, the fast bit, the ink
1490+/// nibble), so a line naming one past what a byte holds is a look this
1491+/// program does not have rather than a 300 that quietly loads as a 44.
1492+fn flags_byte(field: &[u8], line: usize) -> crate::Result<u8> {
1493+ let n = number(field, line)?;
1494+ u8::try_from(n).map_err(|_| format!("line {line}: {n} is not a set of visualizer flags").into())
1495+}
1496+
14751497 fn number(field: &[u8], line: usize) -> crate::Result<u32> {
14761498 match std::str::from_utf8(field).ok().and_then(|s| s.parse().ok()) {
14771499 Some(n) => Ok(n),
@@ -1695,7 +1717,11 @@ mod tests {
16951717 (LaneKind::Audio, vec![clip(0, 0, 30, 0, Some(7))]),
16961718 (LaneKind::Subtitle, Vec::new()),
16971719 ];
1698- let subs = vec![vec![], vec![], vec![caption(0, 30, Some(7)), caption(40, 10, None)]];
1720+ let subs = vec![
1721+ vec![],
1722+ vec![],
1723+ vec![caption(0, 30, Some(7)), caption(40, 10, None)],
1724+ ];
16991725 let bytes = super::emit(
17001726 &dir,
17011727 &doc().1,
@@ -1917,7 +1943,10 @@ mod tests {
19171943 for seat in [EncoderSeat::Hardware, EncoderSeat::Software] {
19181944 let written = bytes(seat);
19191945 let text = String::from_utf8_lossy(&written).to_string();
1920- assert!(text.contains(&format!("encoder {}\n", seat.name())), "{text}");
1946+ assert!(
1947+ text.contains(&format!("encoder {}\n", seat.name())),
1948+ "{text}"
1949+ );
19211950 assert_eq!(parse(&written, &dir).expect("v14 parses").encoder, seat);
19221951 }
19231952
@@ -2622,7 +2651,10 @@ mod tests {
26222651 "the fades are the clip line's last two fields"
26232652 );
26242653 let back = parse(&bytes, &dir).expect("parse");
2625- assert_eq!(back.lanes, lanes, "the fades round trip as the very numbers");
2654+ assert_eq!(
2655+ back.lanes, lanes,
2656+ "the fades round trip as the very numbers"
2657+ );
26262658 }
26272659
26282660 /// The whole of the v19 bump, the fade test's twin: a clip's dissolve into
@@ -3248,13 +3280,11 @@ mod tests {
32483280 assert!(err.starts_with("line 4: clip at "), "{err}");
32493281 }
32503282 // The lanes are independent, so a video line never crowds an audio one.
3251- assert!(
3252- parse(
3253- b"edith 2\nsource a.mp4\nvideo 0 0 30 0 -\naudio 0 0 30 0 -\n",
3254- &dir
3255- )
3256- .is_ok()
3257- );
3283+ assert!(parse(
3284+ b"edith 2\nsource a.mp4\nvideo 0 0 30 0 -\naudio 0 0 30 0 -\n",
3285+ &dir
3286+ )
3287+ .is_ok());
32583288 // ...and a lane may be empty as long as the other one is not.
32593289 let only_audio = parse(b"edith 2\nsource a.mp4\naudio 0 0 30 0 -\n", &dir).expect("parse");
32603290 assert!(only_audio.lanes[0].1.is_empty(), "V1 is there and empty");
@@ -3457,7 +3487,10 @@ mod tests {
34573487 parse(b"edith 1\nsource a.mp4\n", &dir).expect("v1").lanes,
34583488 two(Vec::new(), Vec::new())
34593489 );
3460- assert!(parse(b"edith 1\n", &dir).expect("a project of nothing").sources.is_empty());
3490+ assert!(parse(b"edith 1\n", &dir)
3491+ .expect("a project of nothing")
3492+ .sources
3493+ .is_empty());
34613494 }
34623495
34633496 /// Every truncation of a good file either parses or refuses; none panics.
@@ -3479,4 +3512,48 @@ mod tests {
34793512 "line 2: truncated % escape in the path"
34803513 );
34813514 }
3515+
3516+ /// A clip's visualizer field is a whole byte of flags, and a line naming one
3517+ /// past it used to be truncated into a look nobody chose (`300` loaded as
3518+ /// `44`, with the fast bit and the ink nibble both wrong). It is refused by
3519+ /// name now, like the resolution's bound, the sample rate's range, the tone
3520+ /// map and the encoder seat beside it.
3521+ #[test]
3522+ fn a_visualizer_byte_past_a_byte_is_refused_and_the_legal_ones_still_load() {
3523+ // The door the parser reads that field through: the low bits are the
3524+ // style, bit 3 the fast flag and the high nibble the ink, so every value a
3525+ // byte holds is a look and 256 and up is not one.
3526+ assert_eq!(flags_byte(b"0", 1).expect("zero is the plain look"), 0);
3527+ assert_eq!(flags_byte(b"255", 1).expect("the whole byte is flags"), 255);
3528+ let refused = flags_byte(b"300", 9).expect_err("300 is not a byte of flags");
3529+ assert_eq!(
3530+ refused.to_string(),
3531+ "line 9: 300 is not a set of visualizer flags"
3532+ );
3533+ }
3534+
3535+ /// ...and the same field through the parser, on a document of the newest
3536+ /// dialect: the legal byte is what lands in the clip, the illegal one is the
3537+ /// refusal above rather than a truncation.
3538+ #[test]
3539+ fn a_clip_line_whose_visualizer_is_past_a_byte_loses_the_whole_load() {
3540+ let dir = PathBuf::from("/proj");
3541+ let line = |flags: &str| {
3542+ format!(
3543+ "edith 22\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
3544+ video 1 0 0 30 0 - - - fit 1000 0 0 0 - {flags} 0\n"
3545+ )
3546+ };
3547+ let doc = parse(line("12").as_bytes(), &dir).expect("12 is a look");
3548+ // The keyword is the saver's own for this dialect, so a mismatch here would
3549+ // be this test's line and not the field it is about.
3550+ assert_eq!(doc.lanes[0].1[0].visualizer, 12);
3551+ let refused = parse(line("300").as_bytes(), &dir).expect_err("300 is not a look");
3552+ assert!(
3553+ refused
3554+ .to_string()
3555+ .contains("is not a set of visualizer flags"),
3556+ "{refused}"
3557+ );
3558+ }
34823559 }
crates/engine/src/playback.rsmodified+211 -24
@@ -26,7 +26,7 @@ use crate::colorspace::{ColorDescription, ContentLight};
2626 use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker};
2727 use crate::demux::{Codec, Demuxer, NoVideoTrack, Rotation, VideoMeta};
2828 use crate::eq::EqParams;
29-use crate::project::{
29+use crate::project::{ProjectSettings,
3030 Clip, Edge, GapSweep, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip,
3131 };
3232 use crate::scale::{Composer, FitPolicy};
@@ -1188,7 +1188,18 @@ impl PlaybackSession {
11881188 // it, and [`Project::with_subs`] refuses one naming a row that is
11891189 // not there.
11901190 .with_subtitles(subtitles)
1191- .with_subs(doc.subs)?;
1191+ .with_subs(doc.subs)?
1192+ // The header a load puts back: the canvas and rate above, which a
1193+ // save's own `resolution`/`fps` lines may have moved off the
1194+ // scaffold's, and the switches the literal below carries -- handed
1195+ // in here because they are the project's own and a door that moved
1196+ // one after this would snapshot whatever copy it holds, which until
1197+ // this line is the placeholder's. No undo step for
1198+ // [`Project::with_mix`]'s reason: a project that arrived one `z`
1199+ // from a state it was never in is a project whose first undo is a
1200+ // surprise.
1201+ .with_canvas(meta.width, meta.height, meta.frame_rate)
1202+ .with_switches(doc.proxy, doc.auto_proxy, doc.encoder, doc.sample_rate);
11921203 let span = project.composite_span_at(0);
11931204 // Last, because it is the one thing here that cannot be taken back: the
11941205 // feeder thread outlives the `Audio` value (it holds its own clones) and
@@ -1469,12 +1480,15 @@ impl PlaybackSession {
14691480 /// unlike [`remove_source`](Self::remove_source) this does not reseek. Rows
14701481 /// past `idx` move down by one: a caller holding a picked row (the export's
14711482 /// subtitle pick) has to fix it up or drop it; the placements on the lanes
1472- /// are walked down with it and need no fixing. Not an undo step, for the
1473- /// reason [`Project::remove_subtitles`] gives -- the way back is
1474- /// [`import_subtitles`](Self::import_subtitles), which reads a file's
1475- /// subtitles and touches nothing else on the timeline -- and it *empties*
1476- /// the undo history, because the steps in it name the tracks by the indexes
1477- /// this call just changed.
1483+ /// are walked down with it and need no fixing.
1484+ ///
1485+ /// One undo step, and the reindex with it ([`Project::remove_subtitles`]'s
1486+ /// own entry): every step in the history names its tracks by index into the
1487+ /// palette, so an entry carries the palette it was taken beside its lanes --
1488+ /// which is what lets a `z` put this row back, and every placement that
1489+ /// moved down with it. What that entry cannot bring back is the *pick*: it
1490+ /// is the caller's, and a caller holding one fixes it up or drops it
1491+ /// ([`crate::subs::sub_pick_after_restore`]).
14781492 pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> {
14791493 self.project.remove_subtitles(idx)
14801494 }
@@ -2820,11 +2834,17 @@ impl PlaybackSession {
28202834 /// Says nothing about *which* films have one: a source with no stand-in
28212835 /// keeps playing its own pictures either way, and one made while this is on
28222836 /// is picked up at the next seek.
2837+ ///
2838+ /// One undo step ([`Project::push_settings_step`]), and the seek below is
2839+ /// what makes the undo of it land on the picture: it reopens the span
2840+ /// through [`picture_path`](Self::picture_path), which reads this switch.
28232841 pub fn set_proxies(&mut self, on: bool) {
28242842 if self.proxies == on {
28252843 return;
28262844 }
2845+ let from = self.settings_value();
28272846 self.proxies = on;
2847+ self.step_settings(from);
28282848 let now = self.now();
28292849 self.seek(now);
28302850 }
@@ -2839,9 +2859,15 @@ impl PlaybackSession {
28392859 }
28402860
28412861 /// Pick the seat. Nothing to reseek and nothing to re-probe here: this
2842- /// decides what an *export* opens, never what plays.
2862+ /// decides what an *export* opens, never what plays. One undo step, like
2863+ /// every other pick on the project.
28432864 pub fn set_encoder_seat(&mut self, seat: crate::export::EncoderSeat) {
2865+ if self.encoder_seat == seat {
2866+ return;
2867+ }
2868+ let from = self.settings_value();
28442869 self.encoder_seat = seat;
2870+ self.step_settings(from);
28452871 }
28462872
28472873 /// The rate this project's mix was picked to run at
@@ -2853,9 +2879,15 @@ impl PlaybackSession {
28532879
28542880 /// Pick the mix's own rate, overriding the derived one. Nothing to reseek
28552881 /// here: it takes effect at the next audio rebuild (a seek, an edit, a
2856- /// reopen), not on the device already playing.
2882+ /// reopen), not on the device already playing. One undo step, like every
2883+ /// other pick on the project.
28572884 pub fn set_sample_rate(&mut self, rate: Option<u32>) {
2885+ if self.sample_rate == rate {
2886+ return;
2887+ }
2888+ let from = self.settings_value();
28582889 self.sample_rate = rate;
2890+ self.step_settings(from);
28592891 }
28602892
28612893 /// Whether an imported film that wants a stand-in gets one made for it
@@ -2867,8 +2899,15 @@ impl PlaybackSession {
28672899 /// Make the stand-ins on import, or make none until asked. Nothing to
28682900 /// reseek: this decides what is *started*, never what is decoded -- a proxy
28692901 /// already in the cache is still cut on while [`Self::proxies`] is on.
2902+ ///
2903+ /// One undo step, like every other switch on the project.
28702904 pub fn set_auto_proxies(&mut self, on: bool) {
2905+ if self.auto_proxies == on {
2906+ return;
2907+ }
2908+ let from = self.settings_value();
28712909 self.auto_proxies = on;
2910+ self.step_settings(from);
28722911 }
28732912
28742913 /// Which source `path` is, canonicalising only if it has to: a source's own
@@ -2999,10 +3038,9 @@ impl PlaybackSession {
29993038 /// that is not a picture -- zero either way, or past 8K, which is where the
30003039 /// per-frame buffers stop being a sane thing to allocate from a keystroke.
30013040 ///
3002- /// corner-cut: not an undo step. The project resolution is not in the lane
3003- /// snapshots [`Project::undo`] restores, so cycling it back is one more
3004- /// keypress rather than a `z`. Upgrade path is snapshotting it beside the
3005- /// lanes, which every existing snapshot site would then have to carry.
3041+ /// One undo step: the resolution is the project's own, so it rides in the
3042+ /// entry beside the lanes and a `z` takes the canvas back to the size it
3043+ /// was ([`Project::push_settings_step`]).
30063044 pub fn set_resolution(&mut self, width: u32, height: u32) -> bool {
30073045 if !crate::is_resolution(width, height) {
30083046 return false;
@@ -3010,8 +3048,10 @@ impl PlaybackSession {
30103048 if (width, height) == (self.meta.width, self.meta.height) {
30113049 return false;
30123050 }
3051+ let from = self.settings_value();
30133052 self.meta.width = width;
30143053 self.meta.height = height;
3054+ self.step_settings(from);
30153055 self.invalidate(Dirty::Picture);
30163056 true
30173057 }
@@ -3073,12 +3113,15 @@ impl PlaybackSession {
30733113 /// ([`crate::mux::frame_timing`], the same wall a file of an unnameable rate
30743114 /// is refused at).
30753115 ///
3076- /// corner-cut: not an undo step, exactly as the project resolution is not --
3077- /// and this one *moves the frame numbers*, so the way back is picking the
3078- /// old rate (or the media's, [`native_frame_rate`](Self::native_frame_rate))
3079- /// rather than a `z`, and it lands within a frame of where it started rather
3080- /// than on it (see [`Project::retime`]). Upgrade path is the same one: the
3081- /// project's settings snapshotted beside the lanes.
3116+ /// One undo step, and the entry it takes is the whole of the change: the
3117+ /// lanes as they were in the *old* rate's numbering, with that rate beside
3118+ /// them, so a `z` restores the two together ([`Project::retime`]). The
3119+ /// step is taken before the retime rather than after, since this is the one
3120+ /// settings door that moves the lanes the step holds. Picking the old rate
3121+ /// back is still within a frame of where it started rather than on it: the
3122+ /// *lanes* come home exactly out of the entry, and the per-source lengths
3123+ /// are the half that goes through the map twice
3124+ /// ([`PlaybackSession::adopt_settings`]).
30823125 pub fn set_frame_rate(&mut self, fps: f64) -> bool {
30833126 if !fps.is_finite() || fps <= 0.0 || fps == self.meta.frame_rate {
30843127 return false;
@@ -3090,6 +3133,8 @@ impl PlaybackSession {
30903133 let Ok(k) = Rate::from_fps(self.meta.frame_rate, fps) else {
30913134 return false;
30923135 };
3136+ let from = self.settings_value();
3137+ self.project.push_settings_step(from.clone(), from);
30933138 // Lengths first: the retime holds every clip inside its source's *new*
30943139 // length, so a clip that played to the last frame of its file still
30953140 // does rather than naming one past the end.
@@ -3103,6 +3148,9 @@ impl PlaybackSession {
31033148 }
31043149 self.meta.frame_rate = fps;
31053150 self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1);
3151+ // The copy the project keeps, now that the change has landed: what the
3152+ // next lane edit's entry carries.
3153+ self.project.mirror_settings(self.settings_value());
31063154 let now = self.now();
31073155 self.seek(now);
31083156 true
@@ -3511,15 +3559,19 @@ impl PlaybackSession {
35113559 self.edit(Dirty::Both, |p| p.delete_in(lane, idx))
35123560 }
35133561
3514- /// Undoes the last successful edit, and reseeks like a delete.
3562+ /// Undoes the last successful edit, and reseeks like a delete. A step on
3563+ /// the project's own settings comes back the same way: the canvas, the
3564+ /// rate and the switches are put back on the session here
3565+ /// ([`Self::adopt_settings`]), so a `z` after a resolution pick, an
3566+ /// encoder pick or a proxy switch lands exactly as one after a cut does.
35153567 pub fn undo(&mut self) -> bool {
3516- self.edit(Dirty::Both, Project::undo)
3568+ self.restored_step(Project::undo)
35173569 }
35183570
35193571 /// Redoes the last edit [`undo`](Self::undo) took back, and reseeks like
3520- /// a delete.
3572+ /// a delete -- settings included, exactly as `undo` takes them back.
35213573 pub fn redo(&mut self) -> bool {
3522- self.edit(Dirty::Both, Project::redo)
3574+ self.restored_step(Project::redo)
35233575 }
35243576
35253577 /// Takes `path` into the **library**: it becomes a source of this session,
@@ -3686,6 +3738,94 @@ impl PlaybackSession {
36863738 /// policy rebuilds the picture where it stands, with the sound running
36873739 /// through it untouched -- no flush, no re-open, no hole -- and an
36883740 /// equalizer the other way round.
3741+ /// The project's own settings as this session has them now
3742+ /// ([`ProjectSettings`]): the canvas and the rate are `meta`'s, the
3743+ /// switches are this session's own fields, and the rendition and the
3744+ /// limiter are the project's -- two halves of one header, which is what
3745+ /// every history entry carries beside the lanes ([`Project::snapshot`]).
3746+ fn settings_value(&self) -> ProjectSettings {
3747+ ProjectSettings {
3748+ resolution: (self.meta.width, self.meta.height),
3749+ frame_rate: self.meta.frame_rate,
3750+ encoder_seat: self.encoder_seat,
3751+ sample_rate: self.sample_rate,
3752+ proxies: self.proxies,
3753+ auto_proxies: self.auto_proxies,
3754+ tone: self.project.tone(),
3755+ limiter: self.project.limiter(),
3756+ }
3757+ }
3758+
3759+ /// One undo step for a change to the project's own settings, taken after
3760+ /// the change: `from` is the state the door found, and what the project
3761+ /// does with the two values is [`Project::push_settings_step`]'s.
3762+ fn step_settings(&mut self, from: ProjectSettings) {
3763+ let now = self.settings_value();
3764+ self.project.push_settings_step(from, now);
3765+ }
3766+
3767+ /// Puts the project's settings back on this session -- what a step that
3768+ /// restored them leaves for the player to take up. The canvas, the rate and
3769+ /// the switches live here, and the rendition and the limiter are the
3770+ /// project's own, already back in place by the time this runs. Every lane
3771+ /// edit's entry comes through here too and moves nothing, which is the
3772+ /// common case; the *rate* is the one that needs more than the fields,
3773+ /// because every source's frame count is held against it and the conform
3774+ /// that scaled them is not in the entry.
3775+ fn adopt_settings(&mut self) {
3776+ let s = self.project.settings_now();
3777+ // A project nobody has handed a canvas to: a fresh [`Project`] carries
3778+ // the placeholder ([`ProjectSettings::placeholder`]) and no session is
3779+ // on one -- the entries pushed before the first settings door hold lane
3780+ // edits and that placeholder, and adopting it would zero the canvas.
3781+ if s.frame_rate <= 0.0 {
3782+ return;
3783+ }
3784+ let was = self.meta.frame_rate;
3785+ self.meta.width = s.resolution.0;
3786+ self.meta.height = s.resolution.1;
3787+ self.meta.frame_rate = s.frame_rate;
3788+ self.encoder_seat = s.encoder_seat;
3789+ self.sample_rate = s.sample_rate;
3790+ self.proxies = s.proxies;
3791+ self.auto_proxies = s.auto_proxies;
3792+ if s.frame_rate != was {
3793+ // Within a frame, like the way out ([`Self::set_frame_rate`]'s own
3794+ // caveat): the lane frame numbers came home exactly, out of the
3795+ // entry, and only the per-source lengths are re-derived through the
3796+ // map back.
3797+ let Ok(k) = Rate::from_fps(was, s.frame_rate) else {
3798+ return;
3799+ };
3800+ for count in &mut self.counts {
3801+ *count = k.timeline_at(*count).max(1);
3802+ }
3803+ for rate in &mut self.rates {
3804+ *rate = rate.then(k);
3805+ }
3806+ self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1);
3807+ }
3808+ }
3809+
3810+ /// [`Self::undo`] and [`Self::redo`] themselves: the project's own step,
3811+ /// and then whatever it restored for the session to take up
3812+ /// ([`Self::adopt_settings`]). Reseeks both halves, so a canvas that moved
3813+ /// is repainted and a proxy switch that flipped reopens the file.
3814+ fn restored_step(&mut self, f: impl FnOnce(&mut Project) -> bool) -> bool {
3815+ if !f(&mut self.project) {
3816+ return false;
3817+ }
3818+ // Adopted *before* the reseek below, never after it: everything the
3819+ // reseek reads is one of the settings the entry just put back --
3820+ // `landing` the rate and the frame count, `picture_path` the switches,
3821+ // the sound the sample rate -- so a landing computed from the values
3822+ // the step *undid* lands on the wrong frame of the right project (and
3823+ // reopens the file through the switch that just went back).
3824+ self.adopt_settings();
3825+ self.invalidate(Dirty::Both);
3826+ true
3827+ }
3828+
36893829 fn edit(&mut self, dirty: Dirty, f: impl FnOnce(&mut Project) -> bool) -> bool {
36903830 if !f(&mut self.project) {
36913831 return false;
@@ -5179,6 +5319,53 @@ mod tests {
51795319 assert_eq!(next.index, first.index, "paused: same timeline position before and after");
51805320 }
51815321
5322+ /// A rate undo lands the picture where the playhead is, in the rate that
5323+ /// came *back*: the entry a pick takes carries the old numbering beside the
5324+ /// old rate, so an undo restores both and the reseek has to be computed
5325+ /// after the restore. Computed before it, the landing is the pre-undo
5326+ /// rate's reading of the post-undo project -- `now` clamps to the pre-undo
5327+ /// rate's idea of the timeline's end and the worker is handed the last
5328+ /// frame of a five-second timeline for a playhead at three seconds.
5329+ #[test]
5330+ fn a_rate_undo_reseeks_at_the_rate_it_restored() {
5331+ let mut s = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
5332+ s.set_gain(0.0);
5333+ let poll = |s: &mut PlaybackSession| -> crate::decode::Frame {
5334+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(20);
5335+ loop {
5336+ if let Some(f) = s.try_frame() {
5337+ return f;
5338+ }
5339+ assert!(std::time::Instant::now() < deadline, "no frame within 20s");
5340+ std::thread::sleep(std::time::Duration::from_millis(10));
5341+ }
5342+ };
5343+ let native = s.native_frame_rate();
5344+ s.seek(3.0);
5345+ assert_eq!(s.now(), 3.0, "the fixture is five seconds long");
5346+ assert!(s.set_frame_rate(native * 2.0), "the rate pick");
5347+ assert!(s.undo(), "the pick is one step");
5348+ assert_eq!(s.meta().frame_rate, native, "the rate came back");
5349+ assert_eq!(
5350+ s.now(),
5351+ 3.0,
5352+ "the playhead is the seconds it was, read at the rate that came back"
5353+ );
5354+ // The worker's own landing, which is the half the clock alone cannot
5355+ // show: a frame 149 of 150 is exactly the pre-undo rate's clamp.
5356+ assert_eq!(
5357+ s.span.expect("a span for the picture").start,
5358+ secs_to_frame(3.0, native),
5359+ "the picture was asked for the playhead's own frame"
5360+ );
5361+ let frame = poll(&mut s);
5362+ assert_eq!(
5363+ frame.index,
5364+ secs_to_frame(3.0, native),
5365+ "and that is the frame that arrived"
5366+ );
5367+ }
5368+
51825369 /// The session's live look samples leave its history exactly where the
51835370 /// press left it -- the colour-wheel drag's twin for the packed look, and
51845371 /// what lets the app drive one from a pointer: `z` after a drag lands
crates/engine/src/project.rsmodified+254 -68
@@ -116,6 +116,11 @@ pub(crate) struct SweepParts(
116116 pub(crate) usize,
117117 pub(crate) Vec<(LaneKind, Vec<Clip>)>,
118118 pub(crate) Vec<Vec<SubClip>>,
119+ /// The palette, which the history holds beside the lanes and an undo
120+ /// therefore restores ([`Project::undo`]). Left out of this shape, a
121+ /// round-trip check passed with the palette restore deleted outright.
122+ pub(crate) Vec<SubtitleTrack>,
123+ pub(crate) ProjectSettings,
119124 );
120125
121126 impl Speed {
@@ -881,11 +886,75 @@ pub type Parts = (
881886
882887 /// How many undo steps a project keeps. One gesture is one step, so 100 is past
883888 /// any chain a person walks back by hand, and the oldest step is dropped rather
884-/// than the history growing without end: a snapshot is the whole lane list, so
885-/// on a 1394-clip jumpcut timeline this is a bounded ~10 MB instead of a leak
886-/// that grows for as long as the session lasts.
889+/// than the history growing without end: a snapshot is the whole lane list plus
890+/// the palette and the project's own settings, so on a 1394-clip jumpcut
891+/// timeline this is a bounded ~10 MB instead of a leak that grows for as long
892+/// as the session lasts.
887893 const HISTORY_CAP: usize = 100;
888894
895+/// The project's own settings, as one value: the header a `.edith` file carries
896+/// beside the edit list, and what every undo step restores beside the lanes.
897+/// None of it is the media's own -- the scaffolding file's picture and rate
898+/// ([`PlaybackSession::native`]) stay on the session and are never rolled back.
899+#[derive(Clone, Debug, PartialEq)]
900+pub(crate) struct ProjectSettings {
901+ /// The canvas every clip is composed onto: the project resolution, which a
902+ /// clip of another size is placed onto rather than refused for.
903+ pub(crate) resolution: (u32, u32),
904+ /// The rate the timeline is cut at, which every clip and source is
905+ /// conformed to ([`Project::retime`]).
906+ pub(crate) frame_rate: f64,
907+ /// Which encoder an export of this project opens its picture on
908+ /// ([`crate::export::EncoderSeat`]).
909+ pub(crate) encoder_seat: crate::export::EncoderSeat,
910+ /// The rate the mix was picked to run at, or `None` for the one the first
911+ /// audio source derives.
912+ pub(crate) sample_rate: Option<u32>,
913+ /// Whether the picture is decoded from the stand-ins ([`crate::proxy`]).
914+ pub(crate) proxies: bool,
915+ /// Whether a source that wants a stand-in gets one made for it as it
916+ /// arrives ([`crate::proxy::wanted`]).
917+ pub(crate) auto_proxies: bool,
918+ /// Which HDR-to-SDR rendition the picture is watched and exported in.
919+ pub(crate) tone: crate::tonemap::Preset,
920+ /// The master limiter every lane's sound is summed through.
921+ pub(crate) limiter: Limiter,
922+}
923+
924+impl ProjectSettings {
925+ /// What a project built by hand carries before its constructor names the
926+ /// canvas: the defaults every fresh open has -- nobody has picked stand-ins
927+ /// (the films themselves are cut), an encoder or a mix rate, and the
928+ /// rendition and limiter are the reference ones. Every door that builds a
929+ /// session chains [`Project::with_canvas`] straight after, so the zero
930+ /// canvas here is never a project anybody plays from.
931+ fn placeholder() -> Self {
932+ Self {
933+ resolution: (0, 0),
934+ frame_rate: 0.0,
935+ encoder_seat: crate::export::EncoderSeat::default(),
936+ sample_rate: None,
937+ proxies: false,
938+ auto_proxies: true,
939+ tone: crate::tonemap::Preset::default(),
940+ limiter: Limiter::default(),
941+ }
942+ }
943+}
944+
945+/// One undo step: the lanes, the subtitle palette and the project's own
946+/// settings exactly as they were before the edit that pushed it. Whole values
947+/// rather than the lane list alone, so an undo (or a redo) restores all three
948+/// together and no half of one edit can come back without the others -- which
949+/// is what lets a subtitle removal reindex every placement and still undo: the
950+/// restored palette names the very tracks the restored placements index.
951+#[derive(Clone, Debug)]
952+struct Snapshot {
953+ lanes: Vec<LaneData>,
954+ subtitles: Vec<SubtitleTrack>,
955+ settings: ProjectSettings,
956+}
957+
889958 /// One gap a close-all sweep left open, with the frame it still starts on and
890959 /// the same refusal a single [`Project::gap_take_scope`] close would have said.
891960 #[derive(Clone, Debug, PartialEq, Eq)]
@@ -917,32 +986,31 @@ pub struct Project {
917986 /// The same, for [`Clip::transform`].
918987 transform: Vec<TransformParams>,
919988 /// Snapshots pushed *before* each successful edit; `undo` pops one. The
920- /// whole lane list, so adding a lane undoes as well. Bounded by
921- /// [`HISTORY_CAP`]: at the cap the oldest step goes.
922- history: Vec<Vec<LaneData>>,
923- /// Lane lists `undo` has stepped past; `redo` pops one. Cleared by
989+ /// whole lane list, the subtitle palette and the project's own settings,
990+ /// so adding a lane undoes as well and so does picking a resolution. Bounded
991+ /// by [`HISTORY_CAP`]: at the cap the oldest step goes.
992+ history: Vec<Snapshot>,
993+ /// Snapshots `undo` has stepped past; `redo` pops one. Cleared by
924994 /// [`Project::snapshot`], since a fresh edit invalidates whatever branch
925995 /// the undone steps came from. Not saved to `.edith`, matching `history`.
926- redo: Vec<Vec<LaneData>>,
996+ redo: Vec<Snapshot>,
927997 /// Never rolled back by an undo: an id retired by an undone split must not
928998 /// come back and group two clips that were never together.
929999 next_link: u32,
9301000 /// The subtitle tracks this timeline shows, in the order they were added.
931- /// Not in the lane list and not in the history snapshots, for the reason
932- /// the limiter is not: which subtitles a project carries is a setting on
933- /// it, and it is saved as a *reference* to the file the cues came out of
934- /// ([`crate::subtitle`]).
1001+ /// Saved as a *reference* to the file the cues came out of
1002+ /// ([`crate::subtitle`]). In the history snapshots since the widened
1003+ /// [`Snapshot`]: a placement names a track by index into this list, so a
1004+ /// removal that reindexes the placements can only undo together with the
1005+ /// palette it removed the row from.
9351006 subtitles: Vec<SubtitleTrack>,
936- /// The master limiter every lane's sound is summed *through*
937- /// ([`Project::limiter`]). Off by default, and not in the lane list, which
938- /// is what the history snapshots hold: it is a setting on the mix, like the
939- /// project's resolution is a setting on the picture, and neither is an undo
940- /// step.
941- limiter: Limiter,
942- /// Which HDR-to-SDR rendition every clip on an HDR curve is shown and
943- /// exported in ([`crate::tonemap::Preset`]). A setting on the picture, like
944- /// the resolution, and not in the lane snapshots for the same reason.
945- tone: crate::tonemap::Preset,
1007+ /// The project's own settings ([`ProjectSettings`]) -- the canvas, the
1008+ /// rate, the proxies switches, the encoder seat, the mix rate, the
1009+ /// rendition and the limiter. In every snapshot, so each of them undoes
1010+ /// like a lane edit: they are the header of the project's own `.edith`
1011+ /// file, not this machine's, and a pick a ctrl+z could not take back
1012+ /// would be the one setting with no way out.
1013+ settings: ProjectSettings,
9461014 }
9471015
9481016 impl Project {
@@ -980,8 +1048,7 @@ impl Project {
9801048 redo: Vec::new(),
9811049 next_link: 1,
9821050 subtitles: Vec::new(),
983- limiter: Limiter::default(),
984- tone: crate::tonemap::Preset::default(),
1051+ settings: ProjectSettings::placeholder(),
9851052 }
9861053 }
9871054
@@ -1124,8 +1191,7 @@ impl Project {
11241191 redo: Vec::new(),
11251192 next_link,
11261193 subtitles: Vec::new(),
1127- limiter: Limiter::default(),
1128- tone: crate::tonemap::Preset::default(),
1194+ settings: ProjectSettings::placeholder(),
11291195 })
11301196 }
11311197
@@ -1400,7 +1466,8 @@ impl Project {
14001466 /// different file. [`PlaybackSession::remove_source`] hands back the index
14011467 /// that went for exactly that.
14021468 ///
1403- /// corner-cut: this retires the undo stack. `history` holds lanes alone, so a
1469+ /// corner-cut: this retires the undo stack. `history` holds the lanes, the
1470+ /// subtitle palette and the project's own settings -- no source list -- so a
14041471 /// snapshot older than the removal can name the very source being removed
14051472 /// (delete a file's clips, then remove the file) and restoring it would
14061473 /// point a clip at an entry that is gone. The upgrade path is snapshotting
@@ -1679,14 +1746,44 @@ impl Project {
16791746 data.gain_db = db.clamp(MIN_GAIN_DB, MAX_GAIN_DB);
16801747 }
16811748 }
1682- self.limiter = limiter.with_ceiling(limiter.ceiling_db);
1749+ self.settings.limiter = limiter.with_ceiling(limiter.ceiling_db);
16831750 self
16841751 }
16851752
16861753 /// The HDR rendition a *load* puts back -- the same door
16871754 /// [`with_mix`](Project::with_mix) is, and no undo step for the same reason.
16881755 pub fn with_tone(mut self, preset: crate::tonemap::Preset) -> Self {
1689- self.tone = preset;
1756+ self.settings.tone = preset;
1757+ self
1758+ }
1759+
1760+ /// The canvas and rate a *load* or a fresh open names -- the project
1761+ /// resolution and the rate every clip is counted in. The same door
1762+ /// [`with_mix`](Project::with_mix) is, and no undo step for the same
1763+ /// reason: a project that arrives one undo away from a state it was never
1764+ /// in is a project whose first ctrl+z is a surprise.
1765+ pub fn with_canvas(mut self, width: u32, height: u32, frame_rate: f64) -> Self {
1766+ self.settings.resolution = (width, height);
1767+ self.settings.frame_rate = frame_rate;
1768+ self
1769+ }
1770+
1771+ /// The saved switches a *load* puts back: whether the picture is cut on
1772+ /// the stand-ins, whether new ones are made on arrival, which encoder an
1773+ /// export opens, and the rate the mix was picked to run at. The load half
1774+ /// of [`set_proxies`](Project::set_proxies) and its siblings, and no undo
1775+ /// step for [`with_mix`](Project::with_mix)'s reason.
1776+ pub fn with_switches(
1777+ mut self,
1778+ proxies: bool,
1779+ auto_proxies: bool,
1780+ encoder_seat: crate::export::EncoderSeat,
1781+ sample_rate: Option<u32>,
1782+ ) -> Self {
1783+ self.settings.proxies = proxies;
1784+ self.settings.auto_proxies = auto_proxies;
1785+ self.settings.encoder_seat = encoder_seat;
1786+ self.settings.sample_rate = sample_rate;
16901787 self
16911788 }
16921789
@@ -1694,21 +1791,18 @@ impl Project {
16941791 /// project setting, not a clip's: one picture, one look
16951792 /// ([`crate::tonemap::Preset`]).
16961793 pub fn tone(&self) -> crate::tonemap::Preset {
1697- self.tone
1794+ self.settings.tone
16981795 }
16991796
17001797 /// Sets it. `false` for the one already in force, which is what keeps a
1701- /// re-pick of the current rendition from costing a reseek.
1702- ///
1703- /// corner-cut: not an undo step, for the reason the limiter and the project
1704- /// resolution are not -- it is not in the lane list the history snapshots.
1705- /// Upgrade path is the same one: a history entry holding the project's own
1706- /// settings beside the lanes.
1798+ /// re-pick of the current rendition from costing a reseek. One undo step
1799+ /// like every other project-setting pick.
17071800 pub fn set_tone(&mut self, preset: crate::tonemap::Preset) -> bool {
1708- if self.tone == preset {
1801+ if self.settings.tone == preset {
17091802 return false;
17101803 }
1711- self.tone = preset;
1804+ self.snapshot();
1805+ self.settings.tone = preset;
17121806 true
17131807 }
17141808
@@ -1763,16 +1857,14 @@ impl Project {
17631857 /// [`remove_source`](Project::remove_source) refuses the same way for the
17641858 /// same silent corruption.
17651859 ///
1766- /// corner-cut: not an undo step, for the reason the limiter is not -- the
1767- /// history snapshots hold the lane list and subtitles are not on it
1768- /// ([`Project::subtitles`]). The inverse is putting the file's tracks back
1769- /// on -- [`crate::PlaybackSession::import_subtitles`], the panel's own
1770- /// door, which reads the subtitles of a file and nothing else -- and not a
1771- /// ctrl+z; the upgrade path is the same one the limiter has: a history
1772- /// entry holding the project's own settings beside the lanes. The history
1773- /// is *cleared* rather than kept, as a source removal clears it: the
1774- /// snapshots hold the indexes as they were before the reindex, so an undo
1775- /// into one would put every placement past `idx` on the wrong track.
1860+ /// One undo step, and the reindex with it: every placement names a track
1861+ /// by index into the palette ([`crate::subtitle`]), so a removal that
1862+ /// renumbers them can only come back together with the palette it took
1863+ /// the row from -- which is what the history entry holds, beside the
1864+ /// lanes it also carries ([`Snapshot`]). The inverse, for a caller that
1865+ /// wants the file's tracks back, is [`crate::PlaybackSession::import_subtitles`]
1866+ /// -- the panel's own door, which reads the subtitles of a file and
1867+ /// nothing else.
17761868 pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> {
17771869 if idx >= self.subtitles.len() {
17781870 return Err(format!("there is no subtitle track {idx} to remove").into());
@@ -1796,13 +1888,13 @@ impl Project {
17961888 )
17971889 .into());
17981890 }
1891+ self.snapshot();
17991892 self.subtitles.remove(idx);
18001893 for s in self.lanes.iter_mut().flat_map(|l| &mut l.subs) {
18011894 if s.track > idx {
18021895 s.track -= 1;
18031896 }
18041897 }
1805- self.history.clear();
18061898 Ok(())
18071899 }
18081900
@@ -2252,25 +2344,34 @@ impl Project {
22522344 /// The master limiter the mix is summed through. A project setting, not a
22532345 /// clip's and not a lane's: there is one mix.
22542346 pub fn limiter(&self) -> Limiter {
2255- self.limiter
2347+ self.settings.limiter
22562348 }
22572349
22582350 /// Sets it, with the ceiling clamped to what [`Limiter`] allows. `false`
2259- /// for a setting already in force.
2260- ///
2261- /// corner-cut: not an undo step, for the reason the project resolution is not
2262- /// one ([`crate::PlaybackSession::set_resolution`]) -- it is not in the
2263- /// lane list the history snapshots. Upgrade path is a history entry that
2264- /// holds the mix settings beside the lanes.
2351+ /// for a setting already in force. One undo step like every other
2352+ /// project-setting pick.
22652353 pub fn set_limiter(&mut self, limiter: Limiter) -> bool {
22662354 let limiter = limiter.with_ceiling(limiter.ceiling_db);
2267- if self.limiter == limiter {
2355+ if self.settings.limiter == limiter {
22682356 return false;
22692357 }
2270- self.limiter = limiter;
2358+ self.snapshot();
2359+ self.settings.limiter = limiter;
22712360 true
22722361 }
22732362
2363+
2364+
2365+
2366+
2367+
2368+
2369+
2370+
2371+
2372+
2373+
2374+
22742375 /// What the clip at `idx` of `lane` plays through, or `None` for one that
22752376 /// plays flat (and for an index that is not there) -- what a feeder and an
22762377 /// export ask before they build an [`crate::eq::EqState`].
@@ -4948,6 +5049,36 @@ impl Project {
49485049 self.redo.len()
49495050 }
49505051
5052+ /// The project's own settings as they stand ([`ProjectSettings`]) -- what an
5053+ /// undo entry holds beside the lanes, and what the session reads back after
5054+ /// one is restored ([`crate::PlaybackSession::undo`]).
5055+ pub(crate) fn settings_now(&self) -> ProjectSettings {
5056+ self.settings.clone()
5057+ }
5058+
5059+ /// One undo step for a change to the project's own settings: `from` is the
5060+ /// state the change is from and `now` the one it leaves behind. The entry
5061+ /// pushed holds `from`, while the copy kept here is `now` -- so the next
5062+ /// lane edit's own entry carries the canvas and the rate really in force
5063+ /// rather than the ones before the pick. The lanes the entry holds are the
5064+ /// ones in place at the call: a settings door leaves them alone and may
5065+ /// take this step after its change, and one that moves them
5066+ /// ([`Project::retime`] on a rate change) takes it before, with `now` equal
5067+ /// to `from`, mirroring the new state afterwards
5068+ /// ([`Project::mirror_settings`]).
5069+ pub(crate) fn push_settings_step(&mut self, from: ProjectSettings, now: ProjectSettings) {
5070+ self.settings = from;
5071+ self.snapshot();
5072+ self.settings = now;
5073+ }
5074+
5075+ /// Keeps `now` as this project's copy of its own settings, without a step:
5076+ /// the second half of a settings door that had to take its step before the
5077+ /// change.
5078+ pub(crate) fn mirror_settings(&mut self, now: ProjectSettings) {
5079+ self.settings = now;
5080+ }
5081+
49515082 /// Every part of the project that an edit can change, as comparable
49525083 /// values: what the sweep's undo round-trip asks "byte identical?" of.
49535084 #[cfg(test)]
@@ -4956,31 +5087,45 @@ impl Project {
49565087 self.sources.len(),
49575088 self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(),
49585089 self.lanes.iter().map(|l| l.subs.clone()).collect(),
5090+ self.subtitles.clone(),
5091+ self.settings.clone(),
49595092 )
49605093 }
49615094
4962- /// Restore every lane from before the last successful edit -- the clips and
4963- /// the lane list both. `false` when there is nothing left to undo. Pushes
4964- /// the lanes just left onto the redo stack, so [`Project::redo`] can walk
4965- /// forward again.
5095+ /// Restore everything from before the last successful edit -- the lanes,
5096+ /// the subtitle palette and the project's own settings. `false` when there
5097+ /// is nothing left to undo. Pushes what was just left onto the redo stack,
5098+ /// so [`Project::redo`] can walk forward again.
49665099 pub fn undo(&mut self) -> bool {
49675100 match self.history.pop() {
49685101 Some(prev) => {
4969- self.redo.push(std::mem::replace(&mut self.lanes, prev));
5102+ self.redo.push(Snapshot {
5103+ lanes: std::mem::replace(&mut self.lanes, prev.lanes),
5104+ subtitles: self.subtitles.clone(),
5105+ settings: self.settings.clone(),
5106+ });
5107+ self.subtitles = prev.subtitles;
5108+ self.settings = prev.settings;
49705109 true
49715110 }
49725111 None => false,
49735112 }
49745113 }
49755114
4976- /// Restore every lane from before the last [`Project::undo`] -- the
5115+ /// Restore everything from before the last [`Project::undo`] -- the
49775116 /// mirror of `undo`, walking the redo stack it fills. `false` when there
49785117 /// is nothing left to redo, which is also true after any fresh edit: a
49795118 /// new [`Project::snapshot`] clears the branch `undo` left behind.
49805119 pub fn redo(&mut self) -> bool {
49815120 match self.redo.pop() {
49825121 Some(next) => {
4983- self.history.push(std::mem::replace(&mut self.lanes, next));
5122+ self.history.push(Snapshot {
5123+ lanes: std::mem::replace(&mut self.lanes, next.lanes),
5124+ subtitles: self.subtitles.clone(),
5125+ settings: self.settings.clone(),
5126+ });
5127+ self.subtitles = next.subtitles;
5128+ self.settings = next.settings;
49845129 true
49855130 }
49865131 None => false,
@@ -5002,8 +5147,7 @@ impl Project {
50025147 redo: Vec::new(),
50035148 next_link: self.next_link,
50045149 subtitles: self.subtitles.clone(),
5005- limiter: self.limiter,
5006- tone: self.tone,
5150+ settings: self.settings.clone(),
50075151 }
50085152 }
50095153
@@ -5216,7 +5360,11 @@ impl Project {
52165360 if self.history.len() == HISTORY_CAP {
52175361 self.history.remove(0);
52185362 }
5219- self.history.push(self.lanes.clone());
5363+ self.history.push(Snapshot {
5364+ lanes: self.lanes.clone(),
5365+ subtitles: self.subtitles.clone(),
5366+ settings: self.settings.clone(),
5367+ });
52205368 self.redo.clear();
52215369 }
52225370
@@ -10405,4 +10553,42 @@ mod tests {
1040510553 .expect("valid parts");
1040610554 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);
1040710555 }
10556+
10557+/// D4: removing a subtitle column used to clear the whole undo history,
10558+/// because a placement names its track by index into the palette and the
10559+/// reindex left every later entry naming the wrong one. The entry holds the
10560+/// palette beside the lanes now, so the reindex undoes with it.
10561+#[test]
10562+fn removing_a_subtitle_column_undoes_with_its_reindex() {
10563+ let track = |label: &str| SubtitleTrack {
10564+ path: FILE.into(),
10565+ track: None,
10566+ language: "eng".into(),
10567+ name: String::new(),
10568+ label: label.into(),
10569+ cues: Vec::new(),
10570+ bitmap: false,
10571+ refused: None,
10572+ };
10573+ let mut p = Project::single(FILE, 300)
10574+ .with_subtitles(vec![track("one"), track("two"), track("three")]);
10575+ assert_eq!(p.subtitles().len(), 3);
10576+ let before = p.parts();
10577+ let palette = p.subtitles().to_vec();
10578+ // Column 0 goes, which renumbers the two behind it.
10579+ p.remove_subtitles(0).expect("a column with nothing on it");
10580+ assert_eq!(p.subtitles().len(), 2);
10581+ assert_eq!(p.subtitles()[0].label, "two");
10582+ assert!(p.undo(), "the removal is a step like any other cut");
10583+ // The palette itself, and not only what `parts` happens to compare: this
10584+ // is the assertion that cannot go vacuous if the restore below it ever
10585+ // leaves a field of it behind.
10586+ assert_eq!(p.subtitles(), palette.as_slice(), "the palette itself, back");
10587+ assert_eq!(p.parts(), before, "the palette and the lanes, both back");
10588+ assert!(p.redo(), "and forward again");
10589+ assert_eq!(p.subtitles().len(), 2, "the column goes again");
10590+ assert_eq!(p.subtitles()[0].label, "two");
10591+ assert_ne!(p.subtitles(), palette.as_slice(), "and it is not back");
10592+}
10593+
1040810594 }
crates/engine/src/subtitle.rsmodified+5 -1
@@ -140,7 +140,11 @@ fn segments(set: &[u8]) -> Option<Vec<(u8, &[u8])>> {
140140 }
141141
142142 /// A subtitle track: where it came from and what it says.
143-#[derive(Clone, Debug)]
143+///
144+/// `PartialEq` because it is one of the things an edit can change and therefore
145+/// one of the things an undo has to bring back exactly
146+/// ([`crate::Project::parts`], the sweep's round-trip).
147+#[derive(Clone, Debug, PartialEq, Eq)]
144148 pub struct SubtitleTrack {
145149 /// The file it was read out of: a standalone subtitle file, or the media
146150 /// file whose track number is below.