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 {
18 Loading,18 Loading,
19 /// The file has no audio track. An answer, not a miss.19 /// The file has no audio track. An answer, not a miss.
20 Silent,20 Silent,
21- /// The decode failed. Drawn as its own mark rather than as [`Self::Silent`]:21+ /// The decode failed, at the moment it did. Drawn as its own mark rather
22- /// "this file's sound could not be read" and "this file has no sound" look22+ /// than as [`Self::Silent`]: "this file's sound could not be read" and
23- /// the same on a lane, and the first is a bug report waiting to happen.23+ /// "this file has no sound" look the same on a lane, and the first is a
24- Failed,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),
25 Peaks(Arc<Vec<(f32, f32)>>),30 Peaks(Arc<Vec<(f32, f32)>>),
26 }31 }
27 32
crates/app/src/player/actions.rsmodified+127 -6
@@ -685,20 +685,141 @@ impl Player {
685 }685 }
686 686
687 pub(crate) fn undo(&mut self, cx: &mut Context<Self>) {687 pub(crate) fn undo(&mut self, cx: &mut Context<Self>) {
688- if self.session.as_mut().is_some_and(PlaybackSession::undo) {688+ self.step_history(PlaybackSession::undo);
689- self.reset_after_reseek();
690- }
691 self.selected.clear();689 self.selected.clear();
692 cx.notify();690 cx.notify();
693 }691 }
694 692
695 pub(crate) fn redo(&mut self, cx: &mut Context<Self>) {693 pub(crate) fn redo(&mut self, cx: &mut Context<Self>) {
696- if self.session.as_mut().is_some_and(PlaybackSession::redo) {694+ self.step_history(PlaybackSession::redo);
697- self.reset_after_reseek();
698- }
699 self.selected.clear();695 self.selected.clear();
700 cx.notify();696 cx.notify();
701 }697 }
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+ })
702 }823 }
703 824
704 /// The half-open range a mark and a mark make, in either order: a person's two825 /// 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 @@
2 //! two of them decide.2 //! two of them decide.
3 3
4 use crate::*;4 use crate::*;
5+use std::time::Instant;
5 6
6 impl Player {7 impl Player {
7 /// What [`timeline_math::lane_refuses`] asks to decide a video lane's8 /// What [`timeline_math::lane_refuses`] asks to decide a video lane's
@@ -231,7 +232,7 @@ impl Player {
231 }232 }
232 starting.push(path);233 starting.push(path);
233 }234 }
234- for key in unseen_sources(session.sources(), &self.waves) {235+ for key in unseen_sources(session.sources(), &self.waves, Instant::now()) {
235 self.waves.insert(key.clone(), Wave::Loading);236 self.waves.insert(key.clone(), Wave::Loading);
236 let decoded = cx.background_executor().spawn({237 let decoded = cx.background_executor().spawn({
237 let (path, stream) = key.clone();238 let (path, stream) = key.clone();
@@ -254,7 +255,11 @@ impl Player {
254 // A file whose sound we could not read is not a255 // A file whose sound we could not read is not a
255 // silent one, and a lane that drew it as silent is256 // silent one, and a lane that drew it as silent is
256 // how a broken decode passes for a design choice.257 // 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()),
258 },263 },
259 );264 );
260 cx.notify();265 cx.notify();
crates/app/src/player/library.rsmodified+13 -7
@@ -1711,11 +1711,13 @@ impl Player {
1711 /// would name a *different* track -- and the pick is what an export writes1711 /// would name a *different* track -- and the pick is what an export writes
1712 /// into the file.1712 /// into the file.
1713 ///1713 ///
1714- /// Not an undo step: subtitles are not on the history's snapshots, so the1714+ /// One undo step, and the palette comes back with the reindex
1715- /// way back is putting the file's subtitles on again -- which is a door of1715+ /// ([`engine::Project::remove_subtitles`]), so `^z` is a way back that
1716- /// its own ([`Player::pick_and_add_subtitles`]) and reads the subtitles1716+ /// works -- [`Player::step_history`] moves the pick back with it and drops
1717- /// alone, never the media. The notice says that rather than promising a1717+ /// the plate the old index drew. The second way back, for a caller that
1718- /// ctrl+z that would do nothing.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.
1719 pub(crate) fn remove_subtitle_track(&mut self, track: usize, cx: &mut Context<Self>) {1721 pub(crate) fn remove_subtitle_track(&mut self, track: usize, cx: &mut Context<Self>) {
1720 // The one availability oracle, for the same reason the × on a row and1722 // The one availability oracle, for the same reason the × on a row and
1721 // the stroke are one call: an empty list is not a failure, it is an1723 // the stroke are one call: an empty list is not a failure, it is an
@@ -1749,8 +1751,12 @@ impl Player {
1749 .as_ref()1751 .as_ref()
1750 .map_or(0, |session| session.subtitles().len());1752 .map_or(0, |session| session.subtitles().len());
1751 self.sub_track = sub_pick_after_removal(self.sub_track, track, left);1753 self.sub_track = sub_pick_after_removal(self.sub_track, track, left);
1752- // The drawn cue is keyed by that index ([`Player::sub_picture`])1754+ // The cue over the picture goes with the pick: its tile is
1753- // and the index now stands for another track.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`]).
1754 //1760 //
1755 // corner-cut: its atlas tile is not released -- `close_session`'s1761 // corner-cut: its atlas tile is not released -- `close_session`'s
1756 // note, for its reason and with its upgrade path.1762 // 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
333 match subs {333 match subs {
334 Ok(tracks) => match session.add_subtitle_tracks(tracks) {334 Ok(tracks) => match session.add_subtitle_tracks(tracks) {
335 0 => None,335 0 => None,
336- n => Some(format!(336+ n => Some(format!(" · {n} subtitle track(s)")),
337- " · {n} subtitle track(s)"
338- )),
339 },337 },
340 Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")),338 Err(e) => Some(format!(" — SUBTITLES UNREAD: {e}")),
341 }339 }
@@ -625,11 +623,15 @@ pub(crate) fn subtitle_rows(tracks: &[engine::subtitle::SubtitleTrack]) -> Vec<S
625 /// last. Zero on an emptied list, which is the index the section is not drawn at623 /// last. Zero on an emptied list, which is the index the section is not drawn at
626 /// all.624 /// all.
627 ///625 ///
628-/// Its own function because the pick is what the overlay draws: left where it626+/// Its own function because the pick is read as "which row" everywhere it is
629-/// was it would name a different track, and the plate over the picture would627+/// echoed -- the dock highlights the picked row by comparing it
630-/// change language on its own the moment a row above it went. What an export628+/// (`dock_stance`'s `track == player.sub_track`), and the section heading and
631-/// writes is *not* this pick and cannot be desynced by a removal -- it is worked629+/// its notices name it -- so left where it was it would highlight one track and
632-/// out from the cues on the timeline each time ([`Player::export_subs`]).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`]).
633 pub(crate) fn sub_pick_after_removal(picked: usize, removed: usize, left: usize) -> usize {635 pub(crate) fn sub_pick_after_removal(picked: usize, removed: usize, left: usize) -> usize {
634 let picked = match removed < picked {636 let picked = match removed < picked {
635 true => picked - 1,637 true => picked - 1,
@@ -638,6 +640,65 @@ pub(crate) fn sub_pick_after_removal(picked: usize, removed: usize, left: usize)
638 picked.min(left.saturating_sub(1))640 picked.min(left.saturating_sub(1))
639 }641 }
640 642
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+
641 pub(crate) fn sub_pick_name(702 pub(crate) fn sub_pick_name(
642 tracks: &[engine::subtitle::SubtitleTrack],703 tracks: &[engine::subtitle::SubtitleTrack],
643 track: usize,704 track: usize,
@@ -705,17 +766,33 @@ pub(crate) fn cues_at(cues: &[engine::subtitle::Cue], at: f64) -> Vec<&engine::s
705 .collect()766 .collect()
706 }767 }
707 768
708-/// The sources a repaint has not asked about yet. A key that is already there769+/// How long a failed waveform decode is left alone before the next repaint asks
709-/// means "asked", whatever state it is in, which is what stops a decode already770+/// again: long enough that sixty repaints a second do not become sixty decodes,
710-/// running from being started again by the next of sixty repaints a second.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.
711 pub(crate) fn unseen_sources(783 pub(crate) fn unseen_sources(
712 sources: &[Source],784 sources: &[Source],
713 waves: &HashMap<(PathBuf, usize), Wave>,785 waves: &HashMap<(PathBuf, usize), Wave>,
786+ now: std::time::Instant,
714 ) -> Vec<(PathBuf, usize)> {787 ) -> Vec<(PathBuf, usize)> {
715 sources788 sources
716 .iter()789 .iter()
717 .map(|s| (s.path.clone(), s.audio_stream))790 .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+ })
719 .collect()796 .collect()
720 }797 }
721 798
crates/app/src/tests/cards.rsmodified+146 -24
@@ -914,7 +914,10 @@ fn the_budget_is_the_one_number_the_engine_gets() {
914 // put on screen.914 // put on screen.
915 assert_eq!(auto_bps(1920, 1080, 30.), 6_220_800);915 assert_eq!(auto_bps(1920, 1080, 30.), 6_220_800);
916 assert_eq!(auto_bps(160, 120, 15.), BPS_MIN, "a tiny picture floors");916 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+ );
918 for bps in [auto_bps(1920, 1080, 30.), auto_bps(320, 240, 24.)] {921 for bps in [auto_bps(1920, 1080, 30.), auto_bps(320, 240, 24.)] {
919 assert!((BPS_MIN..=BPS_MAX).contains(&bps));922 assert!((BPS_MIN..=BPS_MAX).contains(&bps));
920 }923 }
@@ -1067,11 +1070,25 @@ fn a_chord_the_export_moment_answers_never_reaches_the_room() {
1067 let (typing, closed) = rest1070 let (typing, closed) = rest
1068 .split_once("return true;")1071 .split_once("return true;")
1069 .expect("the typing branch returns before the chords below it");1072 .expect("the typing branch returns before the chords below it");
1070- assert!(typing.contains("self.budget_edit = None"), "esc leaves the field");1073+ assert!(
1071- assert!(closed.contains("self.close_card()"), "then esc closes the moment");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+ );
1072 // Its chords, all of them consumed here rather than by the keymap.1081 // Its chords, all of them consumed here rather than by the keymap.
1073 for chord in [1082 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\"",
1075 "\",\"",1092 "\",\"",
1076 ] {1093 ] {
1077 assert!(closed.contains(chord), "{chord} is not the moment's own");1094 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() {
1086 fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {1103 fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
1087 let cards = src_text("ui/cards.rs");1104 let cards = src_text("ui/cards.rs");
1088 let start = cards.find("fn export_card(").expect("the moment");1105 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)];
1090 // A segment is the setter it names, not a readout of it.1111 // A segment is the setter it names, not a readout of it.
1091 for (id, chord, setter) in [1112 for (id, chord, setter) in [
1092 ("moment-picture", "\"c\"", "cycle_export_picture"),1113 ("moment-picture", "\"c\"", "cycle_export_picture"),
@@ -1098,7 +1119,10 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
1098 assert!(body.contains(setter), "the {id} segment changes nothing");1119 assert!(body.contains(setter), "the {id} segment changes nothing");
1099 }1120 }
1100 // The door, wearing the room's own chord rather than a hand-typed one.1121 // 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+ );
1102 assert!(1126 assert!(
1103 body.contains("self.keymap.chord(ActionId::Settings)"),1127 body.contains("self.keymap.chord(ActionId::Settings)"),
1104 "the door's chord is not read from the keymap"1128 "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() {
1113 .map(|at| &cards[at..at + 1900])1137 .map(|at| &cards[at..at + 1900])
1114 .expect("the segment atom");1138 .expect("the segment atom");
1115 assert!(seg.contains("INK3()") && seg.contains("INK4()"));1139 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+ );
1117 // The readouts worth seeing: the project's picture size and rate, and1144 // The readouts worth seeing: the project's picture size and rate, and
1118 // a sound rate that is on the line whether or not it is pressable.1145 // a sound rate that is on the line whether or not it is pressable.
1119 assert!(1146 assert!(
@@ -1126,13 +1153,18 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
1126 );1153 );
1127 // The picture segment is a child, not a `has_video` maybe: hidden on the1154 // The picture segment is a child, not a `has_video` maybe: hidden on the
1128 // sound-only formats it left `c` pressing nothing and no way back.1155 // 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");
1130 assert!(1159 assert!(
1131 !body[at - 240..at].contains("has_video"),1160 !body[at - 240..at].contains("has_video"),
1132 "the picture segment is gated on has_video again -- the dead end"1161 "the picture segment is gated on has_video again -- the dead end"
1133 );1162 );
1134 // Wrapped, never cut: the readouts made row 3 longer than 1280 wide.1163 // 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+ );
1136 }1168 }
1137 1169
1138 /// The dead end the user hit: the cycle walked into the sound-only formats1170 /// 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() {
1140 /// and can't turn it back to video"). One cycle, and it wraps.1172 /// and can't turn it back to video"). One cycle, and it wraps.
1141 #[test]1173 #[test]
1142 fn the_picture_cycle_wraps_out_of_the_sound_only_formats() {1174 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};
1144 // Nothing refused: every stop is the next one, and the last wraps to the1176 // Nothing refused: every stop is the next one, and the last wraps to the
1145 // first -- OGG, the tail of the list, back to MP4.1177 // first -- OGG, the tail of the list, back to MP4.
1146 let mut at = PICTURE_CYCLE[0];1178 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+ {
1148 at = next_picture(at, |_| false);1184 at = next_picture(at, |_| false);
1149 assert_eq!(at, want, "the cycle stopped walking");1185 assert_eq!(at, want, "the cycle stopped walking");
1150 }1186 }
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+ );
1152 assert_eq!(next_picture(Format::Ogg, |_| false), Format::Mp4);1191 assert_eq!(next_picture(Format::Ogg, |_| false), Format::Mp4);
1153 // A timeline with no picture refuses every video format, and the cycle1192 // A timeline with no picture refuses every video format, and the cycle
1154 // still moves: the sound-only stops are what is left of it.1193 // 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() {
1278 assert!(settings.contains(chord), "the EXPORT rows lost {chord}");1317 assert!(settings.contains(chord), "the EXPORT rows lost {chord}");
1279 assert!(moment.contains(chord), "row 3 lost {chord}");1318 assert!(moment.contains(chord), "row 3 lost {chord}");
1280 assert!(handler.contains(chord), "the moment answers no {chord}");1319 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+ );
1282 }1324 }
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+ );
1283 // `e` stays the Export press: the encoder seat took `g` rather than a1340 // `e` stays the Export press: the encoder seat took `g` rather than a
1284 // shifted letter, which no ghost wears.1341 // shifted letter, which no ghost wears.
1285 assert!(handler.contains("\"e\" | \"enter\" => self.start_export"));1342 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+ );
1287 }1347 }
1288 1348
1289 /// The Sound row: what it offers, and that the pick travels to the engine1349 /// 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() {
1401 edit.typed('z');1461 edit.typed('z');
1402 assert_eq!(edit.commit(), None);1462 assert_eq!(edit.commit(), None);
1403 let why = edit.refusal.clone().expect("a refusal, not a silence");1463 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+ );
1405 assert_eq!(edit.text, "zz", "the refusal keeps the text it refused");1468 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+ );
1407 // ...and the next stroke clears it: that reason described the text that is1473 // ...and the next stroke clears it: that reason described the text that is
1408 // no longer there.1474 // no longer there.
1409 edit.typed('0');1475 edit.typed('0');
@@ -1780,11 +1846,9 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() {
1780 assert!(native_detail.ends_with(" source"), "{native_detail}");1846 assert!(native_detail.ends_with(" source"), "{native_detail}");
1781 // A project at a size nobody listed still gets the whole list, with1847 // A project at a size nobody listed still gets the whole list, with
1782 // nothing marked rather than a wrong row marked.1848 // nothing marked rather than a wrong row marked.
1783- assert!(1849+ assert!(resolution_choices((1000, 1000), native)
1784- resolution_choices((1000, 1000), native)1850+ .iter()
1785- .iter()1851+ .all(|(.., picked)| !picked));
1786- .all(|(.., picked)| !picked)
1787- );
1788 // Picking a row means that row, and stepping means the next one: the1852 // Picking a row means that row, and stepping means the next one: the
1789 // list and the stroke read the same ladder.1853 // list and the stroke read the same ladder.
1790 assert_eq!(next_resolution(ladder[1], native), ladder[2]);1854 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() {
1883 assert!(tall <= 360., "the list is taller than the floor");1947 assert!(tall <= 360., "the list is taller than the floor");
1884 assert_eq!(1948 assert_eq!(
1885 menu_at(point(px(600.), px(340.)), size(px(640.), px(360.)), tall),1949 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+ ),
1887 "the list would hang off the smallest window"1954 "the list would hang off the smallest window"
1888 );1955 );
1889 }1956 }
@@ -2238,8 +2305,8 @@ fn maximizing_a_card_grows_its_box_without_moving_where_a_value_sits_in_it() {
2238 /// inside the dock, or hands it the dock's width again, fails this.2305 /// inside the dock, or hands it the dock's width again, fails this.
2239 #[test]2306 #[test]
2240 fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() {2307 fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() {
2308+ use crate::layout::{split_size, Split};
2241 use crate::SPLIT_W;2309 use crate::SPLIT_W;
2242- use crate::layout::{Split, split_size};
2243 2310
2244 // `layout::SPLIT_W` is the one divider between `stance-centre` and the2311 // `layout::SPLIT_W` is the one divider between `stance-centre` and the
2245 // dock; the 56px rail that used to eat the centre's left edge is gone2312 // 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() {
2286 /// assumption.2353 /// assumption.
2287 #[test]2354 #[test]
2288 fn a_maximized_card_can_never_rise_above_the_picture_no_matter_the_bench_height() {2355 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};
2290 let viewport_h = 1080.;2357 let viewport_h = 1080.;
2291 for bench_h in [140., 200., 400.] {2358 for bench_h in [140., 200., 400.] {
2292 assert_eq!(2359 assert_eq!(
@@ -2531,3 +2598,58 @@ fn picker_row_tails_are_state_words_and_settings_values_carry_no_ellipsis() {
2531 );2598 );
2532 }2599 }
2533 }2600 }
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() {
109 // ...and it places, on the audio lane, through the door `insert_source`109 // ...and it places, on the audio lane, through the door `insert_source`
110 // uses: a second copy of the song at the playhead.110 // uses: a second copy of the song at the playhead.
111 session.seek(1.0);111 session.seek(1.0);
112- assert!(112+ assert!(session
113- session113+ .place_stream_at(1.0, &path, 0, Some(Lane::A1))
114- .place_stream_at(1.0, &path, 0, Some(Lane::A1))114+ .expect("its own file is on this timeline"));
115- .expect("its own file is on this timeline")
116- );
117 assert_eq!(session.lane_clips(Lane::A1).len(), 2);115 assert_eq!(session.lane_clips(Lane::A1).len(), 2);
118 assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture");116 assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture");
119 117
@@ -345,13 +343,11 @@ fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() {
345 );343 );
346 // ...and the same reading with a clip under it is the clip menu, untouched:344 // ...and the same reading with a clip under it is the clip menu, untouched:
347 // the flag is off wherever a `Clip` was clicked.345 // the flag is off wherever a `Clip` was clicked.
348- assert!(346+ assert!(menu_items(Ctx {
349- menu_items(Ctx {347+ timeline: true,
350- timeline: true,348+ ..Ctx::default()
351- ..Ctx::default()349+ })
352- })350+ .contains(&ActionId::Cut));
353- .contains(&ActionId::Cut)
354- );
355 }351 }
356 352
357 /// A timeline with a subtitle palette and an empty subtitle lane: what a353 /// 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() {
939 }935 }
940 assert!(!whole(ActionId::Delete, live).yes());936 assert!(!whole(ActionId::Delete, live).yes());
941 assert!(!whole(ActionId::Paste, live).yes());937 assert!(!whole(ActionId::Paste, live).yes());
942- assert!(938+ assert!(whole(
943- whole(939+ ActionId::Paste,
944- ActionId::Paste,940+ Ctx {
945- Ctx {941+ clipboard: true,
946- clipboard: true,942+ ..live
947- ..live943+ }
948- }944+ )
949- )945+ .yes());
950- .yes()
951- );
952 assert!(!whole(ActionId::CancelExport, live).yes());946 assert!(!whole(ActionId::CancelExport, live).yes());
953 let busy = Ctx {947 let busy = Ctx {
954 exporting: true,948 exporting: true,
@@ -988,7 +982,10 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
988 assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.));982 assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.));
989 assert_eq!(983 assert_eq!(
990 menu_at(point(px(700.), px(380.)), viewport, 150.),984 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+ )
992 );989 );
993 // A window smaller than the menu loses its bottom, never its top: the990 // A window smaller than the menu loses its bottom, never its top: the
994 // top-left margin wins over the bottom-right one, because the items are991 // 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() {
1165 assert!(row_enable(RowItem::RemoveWithClips, placed).yes());1162 assert!(row_enable(RowItem::RemoveWithClips, placed).yes());
1166 let unplaced = row_items(live);1163 let unplaced = row_items(live);
1167 assert!(unplaced.contains(&RowItem::Remove) && !unplaced.contains(&RowItem::RemoveWithClips));1164 assert!(unplaced.contains(&RowItem::Remove) && !unplaced.contains(&RowItem::RemoveWithClips));
1168- assert!(1165+ assert!(!row_enable(
1169- !row_enable(1166+ RowItem::RemoveWithClips,
1170- RowItem::RemoveWithClips,1167+ RowCtx {
1171- RowCtx {1168+ exporting: true,
1172- exporting: true,1169+ ..placed
1173- ..placed1170+ }
1174- }1171+ )
1175- )1172+ .yes());
1176- .yes()
1177- );
1178 assert!(!row_enable(RowItem::Add, RowCtx::default()).yes());1173 assert!(!row_enable(RowItem::Add, RowCtx::default()).yes());
1179 // Every refusal is short enough to sit in the hint column beside its1174 // Every refusal is short enough to sit in the hint column beside its
1180 // label, the clip menu's rule.1175 // 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
1282 }1277 }
1283 // §9: no junk drawer. A label that fits the plate whole beside its1278 // §9: no junk drawer. A label that fits the plate whole beside its
1284 // chord, and never a sentence.1279 // 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+ );
1286 }1285 }
1287 // The two removes must not read as the same verb now that the column1286 // The two removes must not read as the same verb now that the column
1288 // beside them is empty.1287 // beside them is empty.
@@ -1604,11 +1603,9 @@ fn adding_a_row_drops_the_whole_source_in_at_the_playhead() {
1604 let frames = session.file_frames(&second);1603 let frames = session.file_frames(&second);
1605 // Through the engine door `insert_source` uses, with the row's own1604 // Through the engine door `insert_source` uses, with the row's own
1606 // stream: the button, the drop and this are one call.1605 // stream: the button, the drop and this are one call.
1607- assert!(1606+ assert!(session
1608- session1607+ .place_stream_at(2.0, &second, 0, None)
1609- .place_stream_at(2.0, &second, 0, None)1608+ .expect("av2 is already on the timeline"));
1610- .expect("av2 is already on the timeline")
1611- );
1612 // The whole of source 1 went in and nothing was painted over: the1609 // The whole of source 1 went in and nothing was painted over: the
1613 // timeline is longer by exactly that file.1610 // timeline is longer by exactly that file.
1614 assert_eq!(session.timeline_duration(), 9.0);1611 assert_eq!(session.timeline_duration(), 9.0);
@@ -1635,11 +1632,9 @@ fn adding_a_row_drops_the_whole_source_in_at_the_playhead() {
1635 let path = session.sources()[0].path.clone();1632 let path = session.sources()[0].path.clone();
1636 let frames = session.file_frames(&path);1633 let frames = session.file_frames(&path);
1637 let end = session.timeline_duration();1634 let end = session.timeline_duration();
1638- assert!(1635+ assert!(session
1639- session1636+ .place_stream_at(end, &path, 1, None)
1640- .place_stream_at(end, &path, 1, None)1637+ .expect("the French track shares the timeline's parameters"));
1641- .expect("the French track shares the timeline's parameters")
1642- );
1643 assert_eq!(session.sources()[1].audio_stream, 1);1638 assert_eq!(session.sources()[1].audio_stream, 1);
1644 assert_eq!(session.timeline_duration(), end * 2.0);1639 assert_eq!(session.timeline_duration(), end * 2.0);
1645 // Both rows are the same file, so both rows are that file's length --1640 // 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() {
1689 1684
1690 // ...and what the release does with it: the frame back through the same1685 // ...and what the release does with it: the frame back through the same
1691 // rate every box is drawn at, into the door the Add button uses too.1686 // rate every box is drawn at, into the door the Add button uses too.
1692- assert!(1687+ assert!(session
1693- session1688+ .place_stream_at(f64::from(at) / fps, &second, 0, None)
1694- .place_stream_at(f64::from(at) / fps, &second, 0, None)1689+ .expect("av2 is already on this timeline"));
1695- .expect("av2 is already on this timeline")
1696- );
1697 let head = |lane| {1690 let head = |lane| {
1698 session1691 session
1699 .lane_clips(lane)1692 .lane_clips(lane)
@@ -1727,11 +1720,9 @@ fn removing_a_row_is_refused_while_it_plays_and_takes_the_row_away() {
1727 session.import(&asset("test_av2.mp4")).expect("av2 matches");1720 session.import(&asset("test_av2.mp4")).expect("av2 matches");
1728 let second = session.sources()[1].path.clone();1721 let second = session.sources()[1].path.clone();
1729 let end = session.timeline_duration();1722 let end = session.timeline_duration();
1730- assert!(1723+ assert!(session
1731- session1724+ .place_stream_at(end, &second, 0, None)
1732- .place_stream_at(end, &second, 0, None)1725+ .expect("a file just imported is on this timeline"));
1733- .expect("a file just imported is on this timeline")
1734- );
1735 let streams = HashMap::new();1726 let streams = HashMap::new();
1736 let rows = |session: &PlaybackSession| {1727 let rows = |session: &PlaybackSession| {
1737 library_rows(session.sources(), &streams, &HashMap::new(), None, |_| 0).len()1728 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() {
1943 assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the tail is back");1934 assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the tail is back");
1944 }1935 }
1945 1936
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+
1946 /// The oracle side of trim-to-playhead (debt #42): needs a subject cut *and*2142 /// The oracle side of trim-to-playhead (debt #42): needs a subject cut *and*
1947 /// the playhead actually resting on it, unlike the nudge pair above it which2143 /// the playhead actually resting on it, unlike the nudge pair above it which
1948 /// only needs a cut -- the "spot" a keyless drag would snap to has to be on2144 /// 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() {
2058 // A library row let go over that row: the same door the Add button2254 // A library row let go over that row: the same door the Add button
2059 // uses, told which lane it was let go over.2255 // uses, told which lane it was let go over.
2060 let path = session.sources()[0].path.clone();2256 let path = session.sources()[0].path.clone();
2061- assert!(2257+ assert!(session
2062- session2258+ .place_stream_at(1.0, &path, 0, Some(v2))
2063- .place_stream_at(1.0, &path, 0, Some(v2))2259+ .expect("its own file is on this timeline"));
2064- .expect("its own file is on this timeline")
2065- );
2066 assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2");2260 assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2");
2067 assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead");2261 assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead");
2068 // ...with the sound it came with, on the row of its own the drop added:2262 // ...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() {
2149 2343
2150 // clip0 on V1 at the fixture's own start; clip1 on V1 ten seconds in,2344 // clip0 on V1 at the fixture's own start; clip1 on V1 ten seconds in,
2151 // appended to the open bed and rippling nothing.2345 // appended to the open bed and rippling nothing.
2152- assert!(2346+ assert!(session
2153- session2347+ .place_stream_at(10.0, &second, 0, None)
2154- .place_stream_at(10.0, &second, 0, None)2348+ .expect("av2 is on this timeline"));
2155- .expect("av2 is on this timeline")
2156- );
2157 let clip0 = session.lane_clips(Lane::V1)[0];2349 let clip0 = session.lane_clips(Lane::V1)[0];
2158 let clip1 = session.lane_clips(Lane::V1)[1];2350 let clip1 = session.lane_clips(Lane::V1)[1];
2159 assert_eq!((clip0.start, clip1.start), (0, 300));2351 assert_eq!((clip0.start, clip1.start), (0, 300));
2160 2352
2161 // clipC on a second video row, well past both of the above.2353 // clipC on a second video row, well past both of the above.
2162 let v2 = session.add_lane(LaneKind::Video);2354 let v2 = session.add_lane(LaneKind::Video);
2163- assert!(2355+ assert!(session
2164- session2356+ .place_stream_at(20.0, &path, 0, Some(v2))
2165- .place_stream_at(20.0, &path, 0, Some(v2))2357+ .expect("test_av.mp4 is on this timeline"));
2166- .expect("test_av.mp4 is on this timeline")
2167- );
2168 let clip_c = session.lane_clips(v2)[0];2358 let clip_c = session.lane_clips(v2)[0];
2169 assert_eq!(clip_c.start, 600);2359 assert_eq!(clip_c.start, 600);
2170 2360
@@ -2217,28 +2407,22 @@ fn a_selection_drag_refuses_as_one_set_when_any_pick_cannot_land() {
2217 session.import(&asset("test_av2.mp4")).expect("av2 matches");2407 session.import(&asset("test_av2.mp4")).expect("av2 matches");
2218 let second = session.sources()[1].path.clone();2408 let second = session.sources()[1].path.clone();
2219 2409
2220- assert!(2410+ assert!(session
2221- session2411+ .place_stream_at(10.0, &second, 0, None)
2222- .place_stream_at(10.0, &second, 0, None)2412+ .expect("av2 is on this timeline"));
2223- .expect("av2 is on this timeline")
2224- );
2225 let clip0 = session.lane_clips(Lane::V1)[0];2413 let clip0 = session.lane_clips(Lane::V1)[0];
2226 let clip1 = session.lane_clips(Lane::V1)[1];2414 let clip1 = session.lane_clips(Lane::V1)[1];
2227 2415
2228 let v2 = session.add_lane(LaneKind::Video);2416 let v2 = session.add_lane(LaneKind::Video);
2229- assert!(2417+ assert!(session
2230- session2418+ .place_stream_at(0.0, &path, 0, Some(v2))
2231- .place_stream_at(0.0, &path, 0, Some(v2))2419+ .expect("test_av.mp4 is on this timeline"));
2232- .expect("test_av.mp4 is on this timeline")
2233- );
2234 let clip_c = session.lane_clips(v2)[0];2420 let clip_c = session.lane_clips(v2)[0];
2235 // A clip clip1 is not picked, blocking the road on V2 the drag is about2421 // A clip clip1 is not picked, blocking the road on V2 the drag is about
2236 // to try: clip1 dragged onto V2 lands its head inside this one.2422 // to try: clip1 dragged onto V2 lands its head inside this one.
2237- assert!(2423+ assert!(session
2238- session2424+ .place_stream_at(10.0, &second, 0, Some(v2))
2239- .place_stream_at(10.0, &second, 0, Some(v2))2425+ .expect("av2 is on this timeline"));
2240- .expect("av2 is on this timeline")
2241- );
2242 let blocker = session.lane_clips(v2)[1];2426 let blocker = session.lane_clips(v2)[1];
2243 assert_eq!(blocker.start, 300);2427 assert_eq!(blocker.start, 300);
2244 2428
@@ -2293,20 +2477,16 @@ fn a_three_pick_copy_paste_preserves_gaps_and_lane_assignment() {
2293 session.import(&asset("test_av2.mp4")).expect("av2 matches");2477 session.import(&asset("test_av2.mp4")).expect("av2 matches");
2294 let second = session.sources()[1].path.clone();2478 let second = session.sources()[1].path.clone();
2295 2479
2296- assert!(2480+ assert!(session
2297- session2481+ .place_stream_at(10.0, &second, 0, None)
2298- .place_stream_at(10.0, &second, 0, None)2482+ .expect("av2 is on this timeline"));
2299- .expect("av2 is on this timeline")
2300- );
2301 let clip0 = session.lane_clips(Lane::V1)[0];2483 let clip0 = session.lane_clips(Lane::V1)[0];
2302 let clip1 = session.lane_clips(Lane::V1)[1];2484 let clip1 = session.lane_clips(Lane::V1)[1];
2303 2485
2304 let v2 = session.add_lane(LaneKind::Video);2486 let v2 = session.add_lane(LaneKind::Video);
2305- assert!(2487+ assert!(session
2306- session2488+ .place_stream_at(20.0, &path, 0, Some(v2))
2307- .place_stream_at(20.0, &path, 0, Some(v2))2489+ .expect("test_av.mp4 is on this timeline"));
2308- .expect("test_av.mp4 is on this timeline")
2309- );
2310 let clip_c = session.lane_clips(v2)[0];2490 let clip_c = session.lane_clips(v2)[0];
2311 2491
2312 // Copied in click order, out of the lanes each was clicked in -- exactly2492 // Copied in click order, out of the lanes each was clicked in -- exactly
@@ -2354,20 +2534,16 @@ fn a_colliding_set_paste_refuses_whole() {
2354 session.import(&asset("test_av2.mp4")).expect("av2 matches");2534 session.import(&asset("test_av2.mp4")).expect("av2 matches");
2355 let second = session.sources()[1].path.clone();2535 let second = session.sources()[1].path.clone();
2356 2536
2357- assert!(2537+ assert!(session
2358- session2538+ .place_stream_at(10.0, &second, 0, None)
2359- .place_stream_at(10.0, &second, 0, None)2539+ .expect("av2 is on this timeline"));
2360- .expect("av2 is on this timeline")
2361- );
2362 let clip0 = session.lane_clips(Lane::V1)[0];2540 let clip0 = session.lane_clips(Lane::V1)[0];
2363 let clip1 = session.lane_clips(Lane::V1)[1];2541 let clip1 = session.lane_clips(Lane::V1)[1];
2364 2542
2365 let v2 = session.add_lane(LaneKind::Video);2543 let v2 = session.add_lane(LaneKind::Video);
2366- assert!(2544+ assert!(session
2367- session2545+ .place_stream_at(20.0, &path, 0, Some(v2))
2368- .place_stream_at(20.0, &path, 0, Some(v2))2546+ .expect("test_av.mp4 is on this timeline"));
2369- .expect("test_av.mp4 is on this timeline")
2370- );
2371 let clip_c = session.lane_clips(v2)[0];2547 let clip_c = session.lane_clips(v2)[0];
2372 2548
2373 let items = [(Lane::V1, clip0), (Lane::V1, clip1), (v2, clip_c)];2549 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() {
2422 let (mut session, sub_lane) = with_subtitle_lane();2598 let (mut session, sub_lane) = with_subtitle_lane();
2423 let v2 = session.add_lane(LaneKind::Video);2599 let v2 = session.add_lane(LaneKind::Video);
2424 let path = session.sources()[0].path.clone();2600 let path = session.sources()[0].path.clone();
2425- assert!(2601+ assert!(session
2426- session2602+ .place_stream_at(0.0, &path, 0, Some(v2))
2427- .place_stream_at(0.0, &path, 0, Some(v2))2603+ .expect("its own file is on this timeline"));
2428- .expect("its own file is on this timeline")
2429- );
2430 session2604 session
2431 .place_sub(sub_lane, 0, one_second(0))2605 .place_sub(sub_lane, 0, one_second(0))
2432 .expect("the caption goes down");2606 .expect("the caption goes down");
@@ -2486,20 +2660,38 @@ fn a_source_is_only_ever_asked_for_its_peaks_once() {
2486 .collect::<Vec<_>>()2660 .collect::<Vec<_>>()
2487 };2661 };
2488 let mut waves: HashMap<(PathBuf, usize), Wave> = HashMap::new();2662 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+ );
2490 // The entry goes in when the decode *starts*, so the sixty repaints a2667 // The entry goes in when the decode *starts*, so the sixty repaints a
2491 // second that happen while it runs must not start it again -- which is2668 // second that happen while it runs must not start it again -- which is
2492 // what this asserts about a key whose value is not an answer yet.2669 // what this asserts about a key whose value is not an answer yet.
2493 waves.insert((a.clone(), 0), Wave::Loading);2670 waves.insert((a.clone(), 0), Wave::Loading);
2494 assert_eq!(2671 assert_eq!(
2495- unseen_sources(&sources, &waves),2672+ unseen_sources(&sources, &waves, std::time::Instant::now()),
2496 keys(&sources[1..]),2673 keys(&sources[1..]),
2497 "the file's other stream is a key of its own"2674 "the file's other stream is a key of its own"
2498 );2675 );
2499 // A file with no audio is an answer like any other: never re-asked.2676 // A file with no audio is an answer like any other: never re-asked.
2500 waves.insert((a, 1), Wave::Silent);2677 waves.insert((a, 1), Wave::Silent);
2501 waves.insert((b.clone(), 0), Wave::Silent);2678 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+ );
2503 // The stream probe is per *file*: the two entries of `a` ask once.2695 // The stream probe is per *file*: the two entries of `a` ask once.
2504 let mut streams: HashMap<PathBuf, Vec<StreamInfo>> = HashMap::new();2696 let mut streams: HashMap<PathBuf, Vec<StreamInfo>> = HashMap::new();
2505 assert_eq!(2697 assert_eq!(
@@ -2802,13 +2994,21 @@ fn every_verb_the_spine_carried_is_a_right_click_row() {
2802 // Every menu is a list of actions the keyboard already reaches, so every2994 // Every menu is a list of actions the keyboard already reaches, so every
2803 // row can wear its chord (DESIGN §4): a row built here out of an id the2995 // row can wear its chord (DESIGN §4): a row built here out of an id the
2804 // registry never files would print an empty column.2996 // 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+ {
2806 assert!(3002 assert!(
2807 ActionId::ALL.contains(&action),3003 ActionId::ALL.contains(&action),
2808 "{action:?} is a menu row and not a registered action"3004 "{action:?} is a menu row and not a registered action"
2809 );3005 );
2810 }3006 }
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+ ] {
2812 let first = list.iter().position(|&a| destructive(a));3012 let first = list.iter().position(|&a| destructive(a));
2813 if let Some(first) = first {3013 if let Some(first) = first {
2814 assert!(3014 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() {
351 /// strip's row at the zoom boundary without the strip to show for it.351 /// strip's row at the zoom boundary without the strip to show for it.
352 #[test]352 #[test]
353 fn the_scroll_strip_row_comes_and_goes_with_the_zoom() {353 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};
355 use gpui::{px, size};355 use gpui::{px, size};
356 356
357 // The strip's row, and only the strip's row, is what the two faces differ357 // 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() {
398 /// on the track, the time axis's own thumb turned through a right angle.398 /// on the track, the time axis's own thumb turned through a right angle.
399 #[test]399 #[test]
400 fn the_lane_thumb_is_the_visible_share_of_the_stack() {400 fn the_lane_thumb_is_the_visible_share_of_the_stack() {
401- use crate::SCROLL_THUMB_MIN;
402 use crate::lanes_thumb;401 use crate::lanes_thumb;
402+ use crate::SCROLL_THUMB_MIN;
403 403
404 // Whole stack on screen: the track fills and there is nothing to scroll.404 // Whole stack on screen: the track fills and there is nothing to scroll.
405 assert_eq!(lanes_thumb(200., 104., 200., 0.), (0., 200.));405 assert_eq!(lanes_thumb(200., 104., 200., 0.), (0., 200.));
@@ -1301,7 +1301,7 @@ fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() {
1301 /// arrival order, at the end.1301 /// arrival order, at the end.
1302 #[test]1302 #[test]
1303 fn a_file_subtitle_group_follows_its_own_row() {1303 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};
1305 let film = PathBuf::from("/films/a.mkv");1305 let film = PathBuf::from("/films/a.mkv");
1306 let other = PathBuf::from("/rec/b.mp4");1306 let other = PathBuf::from("/rec/b.mp4");
1307 let loose = PathBuf::from("/subs/late.srt");1307 let loose = PathBuf::from("/subs/late.srt");
@@ -1320,7 +1320,12 @@ fn a_file_subtitle_group_follows_its_own_row() {
1320 &[film.clone(), other.clone(), film.clone()],1320 &[film.clone(), other.clone(), film.clone()],
1321 &[film.clone()]1321 &[film.clone()]
1322 ),1322 ),
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+ ],
1324 );1329 );
1325 // Nobody's `.srt`: still a top-level row, still last.1330 // Nobody's `.srt`: still a top-level row, still last.
1326 assert_eq!(1331 assert_eq!(
@@ -1366,7 +1371,9 @@ fn same_named_files_are_told_apart_on_the_metadata_line() {
1366 .collect();1371 .collect();
1367 let rows = library_rows(&three, &HashMap::new(), &HashMap::new(), None, |_| 90);1372 let rows = library_rows(&three, &HashMap::new(), &HashMap::new(), None, |_| 90);
1368 assert_eq!(1373 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<_>>(),
1370 ["a", "b", ""],1377 ["a", "b", ""],
1371 "twins say which folder they came out of"1378 "twins say which folder they came out of"
1372 );1379 );
@@ -1379,7 +1386,9 @@ fn same_named_files_are_told_apart_on_the_metadata_line() {
1379 .collect();1386 .collect();
1380 let rows = library_rows(&twins, &HashMap::new(), &HashMap::new(), None, |_| 90);1387 let rows = library_rows(&twins, &HashMap::new(), &HashMap::new(), None, |_| 90);
1381 assert_eq!(1388 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<_>>(),
1383 ["#1", "#2"],1392 ["#1", "#2"],
1384 "one folder, one stem: arrival order tells them apart"1393 "one folder, one stem: arrival order tells them apart"
1385 );1394 );
@@ -1483,6 +1492,45 @@ fn removing_a_subtitle_row_carries_the_pick_with_it() {
1483 assert_eq!(sub_pick_after_removal(0, 0, 0), 0);1492 assert_eq!(sub_pick_after_removal(0, 0, 0), 0);
1484 }1493 }
1485 1494
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+
1486 /// The same claim from the click's end, on the order imports actually1534 /// The same claim from the click's end, on the order imports actually
1487 /// arrive in: two films opened one after the other and an `.srt` dropped1535 /// arrive in: two films opened one after the other and an `.srt` dropped
1488 /// last interleave in the flat list, and the display reorders them. What a1536 /// 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() {
1707 // `overlays.rs` routes those rows through the same `act_lane` door the1755 // `overlays.rs` routes those rows through the same `act_lane` door the
1708 // head's buttons used.1756 // head's buttons used.
1709 let bench = src_text("ui/bench_stance.rs");1757 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+ ] {
1711 assert!(!bench.contains(gone), "the lane head still wears {gone}");1763 assert!(!bench.contains(gone), "the lane head still wears {gone}");
1712 }1764 }
1713 for door in ["\"bench-show-sub-lane\"", "this.show_sub_lane(lane, cx)"] {1765 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() {
1746 fn a_dragged_divider_stops_before_either_panel_disappears() {1798 fn a_dragged_divider_stops_before_either_panel_disappears() {
1747 use crate::ui::theme::INSPECTOR_MIN_W;1799 use crate::ui::theme::INSPECTOR_MIN_W;
1748 use crate::{1800 use crate::{
1749- SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w,1801+ inspector_w, library_w, split_drag_size, split_size, timeline_fixed_h, timeline_h, Split,
1750- split_drag_size, split_size, timeline_fixed_h, timeline_h,1802+ SIDE_MAX_FRAC, SPLIT_W, TIMELINE_MAX_SHARE, TOOLBAR_H,
1751 };1803 };
1752 use gpui::{point, px, size};1804 use gpui::{point, px, size};
1753 1805
@@ -1867,7 +1919,7 @@ fn a_dragged_divider_stops_before_either_panel_disappears() {
1867 fn the_darkroom_seams_stop_before_either_side_disappears() {1919 fn the_darkroom_seams_stop_before_either_side_disappears() {
1868 use crate::ui::theme::INSPECTOR_MIN_W;1920 use crate::ui::theme::INSPECTOR_MIN_W;
1869 use crate::{1921 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,
1871 };1923 };
1872 use gpui::{point, px, size};1924 use gpui::{point, px, size};
1873 1925
@@ -1926,9 +1978,9 @@ fn the_darkroom_seams_stop_before_either_side_disappears() {
1926 /// ~2px at the old `BENCH_MIN_H = 80.`).1978 /// ~2px at the old `BENCH_MIN_H = 80.`).
1927 #[test]1979 #[test]
1928 fn both_default_lanes_fit_the_bench_at_its_floor() {1980 fn both_default_lanes_fit_the_bench_at_its_floor() {
1929- use crate::BENCH_MIN_H;1981+ use crate::ui::bench_stance::{row_h, LANE_MIN_H, ROW_GAP, RULER_H};
1930- use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H, row_h};
1931 use crate::ui::stance::BENCH_CHROME_H;1982 use crate::ui::stance::BENCH_CHROME_H;
1983+ use crate::BENCH_MIN_H;
1932 1984
1933 let box_h = BENCH_MIN_H - BENCH_CHROME_H;1985 let box_h = BENCH_MIN_H - BENCH_CHROME_H;
1934 let avail = box_h - RULER_H - ROW_GAP;1986 let avail = box_h - RULER_H - ROW_GAP;
@@ -1968,9 +2020,9 @@ fn both_default_lanes_fit_the_bench_at_its_floor() {
1968 /// painted bounds back, so it stays geometry-only, same as its neighbours.2020 /// painted bounds back, so it stays geometry-only, same as its neighbours.
1969 #[test]2021 #[test]
1970 fn the_whole_bench_stack_fits_its_own_floor_with_the_ledger_seam_clear() {2022 fn the_whole_bench_stack_fits_its_own_floor_with_the_ledger_seam_clear() {
1971- use crate::BENCH_MIN_H;
1972 use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H};2023 use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H};
1973 use crate::ui::stance::BENCH_CHROME_H;2024 use crate::ui::stance::BENCH_CHROME_H;
2025+ use crate::BENCH_MIN_H;
1974 2026
1975 const BENCH_BORDER_T: f32 = 1.;2027 const BENCH_BORDER_T: f32 = 1.;
1976 const BENCH_PY_TOP: f32 = 4.;2028 const BENCH_PY_TOP: f32 = 4.;
@@ -2040,9 +2092,9 @@ fn a_lane_row_fits_what_its_own_head_draws() {
2040 #[test]2092 #[test]
2041 fn a_saved_seam_survives_a_reload() {2093 fn a_saved_seam_survives_a_reload() {
2042 use crate::{2094 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,
2044 };2096 };
2045- use gpui::{Pixels, Size, px, size};2097+ use gpui::{px, size, Pixels, Size};
2046 2098
2047 let dir = engine::scratch::Scratch::dir("edith-stance-splits");2099 let dir = engine::scratch::Scratch::dir("edith-stance-splits");
2048 let path = dir.join("stance-splits");2100 let path = dir.join("stance-splits");
@@ -2085,7 +2137,7 @@ fn a_saved_seam_survives_a_reload() {
2085 /// drag that never started (`None`) owes nothing.2137 /// drag that never started (`None`) owes nothing.
2086 #[test]2138 #[test]
2087 fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() {2139 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};
2089 2141
2090 assert!(split_drag_owes_save(Some(Split::Dock)));2142 assert!(split_drag_owes_save(Some(Split::Dock)));
2091 assert!(split_drag_owes_save(Some(Split::Bench)));2143 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() {
2099 /// `load_stance_splits`'s doc comment promises.2151 /// `load_stance_splits`'s doc comment promises.
2100 #[test]2152 #[test]
2101 fn a_missing_stance_splits_file_leaves_every_region_at_its_default() {2153 fn a_missing_stance_splits_file_leaves_every_region_at_its_default() {
2102- use crate::{Split, load_stance_splits_from};2154+ use crate::{load_stance_splits_from, Split};
2103- use gpui::{Pixels, Size, px, size};2155+ use gpui::{px, size, Pixels, Size};
2104 2156
2105 let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing");2157 let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing");
2106 let window: Size<Pixels> = size(px(1280.), px(720.));2158 let window: Size<Pixels> = size(px(1280.), px(720.));
@@ -2182,13 +2234,7 @@ fn the_stance_renders_its_five_regions_in_the_documented_order() {
2182 // Open paren only, no close: DESIGN §12 steps 3 and 4 hand most of the2234 // Open paren only, no close: DESIGN §12 steps 3 and 4 hand most of the
2183 // regions player/window state to read, so their call sites carry2235 // regions player/window state to read, so their call sites carry
2184 // arguments now. Order is what this asserts, not arity.2236 // arguments now. Order is what this asserts, not arity.
2185- let calls = [2237+ let calls = ["screen(", "time_band(", "bench(", "ledger(", "dock("];
2186- "screen(",
2187- "time_band(",
2188- "bench(",
2189- "ledger(",
2190- "dock(",
2191- ];
2192 let composed: Vec<usize> = calls2238 let composed: Vec<usize> = calls
2193 .iter()2239 .iter()
2194 .map(|c| {2240 .map(|c| {
@@ -2662,12 +2708,13 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() {
2662 text.lines()2708 text.lines()
2663 .filter(|l| !l.contains("=> format!(\"{full} (global)\")"))2709 .filter(|l| !l.contains("=> format!(\"{full} (global)\")"))
2664 .any(|line| {2710 .any(|line| {
2665- line.match_indices(&format!("ActionId::{name}")).any(|(i, m)| {2711+ line.match_indices(&format!("ActionId::{name}"))
2666- !line[i + m.len()..]2712+ .any(|(i, m)| {
2667- .chars()2713+ !line[i + m.len()..]
2668- .next()2714+ .chars()
2669- .is_some_and(|c| c.is_alphanumeric() || c == '_')2715+ .next()
2670- })2716+ .is_some_and(|c| c.is_alphanumeric() || c == '_')
2717+ })
2671 })2718 })
2672 }2719 }
2673 let darkroom = [2720 let darkroom = [
@@ -2946,7 +2993,7 @@ fn the_bench_answers_a_wheel_notch_anywhere_over_it() {
2946 /// kept beside the first ([`Splits::clear`]).2993 /// kept beside the first ([`Splits::clear`]).
2947 #[test]2994 #[test]
2948 fn a_double_pressed_divider_forgets_the_size_it_was_dragged_to() {2995 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};
2950 use gpui::{px, size};2997 use gpui::{px, size};
2951 2998
2952 let window = size(px(1280.), px(720.));2999 let window = size(px(1280.), px(720.));
@@ -3007,7 +3054,8 @@ fn the_seam_paints_nothing_until_a_pointer_finds_it() {
3007 // gets after it no longer needs it (a `bench=207` -- a press with no3054 // gets after it no longer needs it (a `bench=207` -- a press with no
3008 // drag in it -- beside a dragged `dock=277`).3055 // drag in it -- beside a dragged `dock=277`).
3009 assert!(3056 assert!(
3010- body.find(".group(group.clone())").expect("the band's group")3057+ body.find(".group(group.clone())")
3058+ .expect("the band's group")
3011 < body.find("border_t_1()").expect("the hairline"),3059 < body.find("border_t_1()").expect("the hairline"),
3012 "the hairline is painted outside the band: {body}"3060 "the hairline is painted outside the band: {body}"
3013 );3061 );
@@ -3030,13 +3078,12 @@ fn the_bench_seam_reaches_no_further_than_every_other_seam() {
3030 );3078 );
3031 }3079 }
3032 3080
3033-
3034 /// The clamp table, driven: the seam refuses exactly two things, and neither3081 /// The clamp table, driven: the seam refuses exactly two things, and neither
3035 /// is anywhere near where a hand drags. Measured live at 2560x1440 --3082 /// is anywhere near where a hand drags. Measured live at 2560x1440 --
3036 /// `bench=105` at the floor, `bench=1164` at the ceiling.3083 /// `bench=105` at the floor, `bench=1164` at the ceiling.
3037 #[test]3084 #[test]
3038 fn the_bench_seam_stops_at_its_floor_and_its_ceiling() {3085 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};
3040 use gpui::{px, size};3087 use gpui::{px, size};
3041 3088
3042 let window = size(px(2560.), px(1440.));3089 let window = size(px(2560.), px(1440.));
@@ -3065,8 +3112,11 @@ fn the_bench_seam_stops_at_its_floor_and_its_ceiling() {
3065 fn the_lane_bed_clips_its_clips_at_the_pinned_heads() {3112 fn the_lane_bed_clips_its_clips_at_the_pinned_heads() {
3066 let src = src_text("ui/bench_stance.rs");3113 let src = src_text("ui/bench_stance.rs");
3067 let start = src.find(r#".id(("bench-bed""#).expect("the bed");3114 let start = src.find(r#".id(("bench-bed""#).expect("the bed");
3068- let bed =3115+ let bed = &src[start
3069- &src[start..start + src[start..].find(".bg(rgb(DARK_CANVAS()))").expect("its fill")];3116+ ..start
3117+ + src[start..]
3118+ .find(".bg(rgb(DARK_CANVAS()))")
3119+ .expect("its fill")];
3070 assert!(3120 assert!(
3071 bed.contains(".overflow_hidden()"),3121 bed.contains(".overflow_hidden()"),
3072 "the bed lets its clips paint outside itself, straight over the \3122 "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() {
3130 "the metadata line no longer drops the decoder seat"3180 "the metadata line no longer drops the decoder seat"
3131 );3181 );
3132 let usage = &dock[dock.find("fn usage_line(").expect("the usage line")..start];3182 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+ );
3134 // DESIGN §8: the permanent footer telling the editor how to use a list3187 // DESIGN §8: the permanent footer telling the editor how to use a list
3135 // ("drag · ↵ add · double-click plays") is instructional copy and is gone.3188 // ("drag · ↵ add · double-click plays") is instructional copy and is gone.
3136 assert!(3189 assert!(
@@ -3183,7 +3236,10 @@ fn every_dock_body_mounts_the_ring_it_is_standing_in_for() {
3183 "the dock's key handler stops a stroke outside its tab/escape branches"3236 "the dock's key handler stops a stroke outside its tab/escape branches"
3184 );3237 );
3185 for branch in ["is_focus_cycle_key(key)", "is_focus_exit_key(key)"] {3238 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+ );
3187 }3243 }
3188 }3244 }
3189 3245
@@ -3299,7 +3355,10 @@ fn a_room_ghost_wears_no_chord_that_repeats_its_name() {
3299 fn the_ledger_carries_the_rooms_four_verbs_and_no_rail_remains() {3355 fn the_ledger_carries_the_rooms_four_verbs_and_no_rail_remains() {
3300 let src = src_text("ui/stance.rs");3356 let src = src_text("ui/stance.rs");
3301 for gone in ["stance-spine", "spine_stance", "SPINE_W", "fn spine("] {3357 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+ );
3303 }3362 }
3304 let ledger = &src[src.find("fn ledger(").expect("the ledger strip")3363 let ledger = &src[src.find("fn ledger(").expect("the ledger strip")
3305 ..src.find("/// The dock:").expect("the dock frame")];3364 ..src.find("/// The dock:").expect("the dock frame")];
@@ -3341,8 +3400,8 @@ fn the_ledger_carries_the_rooms_four_verbs_and_no_rail_remains() {
3341 /// deletion.3400 /// deletion.
3342 #[test]3401 #[test]
3343 fn select_all_left_the_ruler_for_the_rulers_own_menu() {3402 fn select_all_left_the_ruler_for_the_rulers_own_menu() {
3344- use crate::ActionId;
3345 use crate::menus::BENCH_ITEMS;3403 use crate::menus::BENCH_ITEMS;
3404+ use crate::ActionId;
3346 let bench = src_text("ui/bench_stance.rs");3405 let bench = src_text("ui/bench_stance.rs");
3347 for gone in ["bench-select-all", "select_all_band", "SELECT_ALL_PAD"] {3406 for gone in ["bench-select-all", "select_all_band", "SELECT_ALL_PAD"] {
3348 assert!(!bench.contains(gone), "the ruler still carries {gone}");3407 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() {
3431 // a path with no name at all still reads as something.3490 // a path with no name at all still reads as something.
3432 use crate::files::{file_name, stem};3491 use crate::files::{file_name, stem};
3433 use std::path::Path;3492 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+ );
3435 assert_eq!(stem(Path::new("/x/untitled")), "untitled");3497 assert_eq!(stem(Path::new("/x/untitled")), "untitled");
3436 assert_eq!(stem(Path::new("/x/a.b.edith")), "a.b");3498 assert_eq!(stem(Path::new("/x/a.b.edith")), "a.b");
3437 assert_eq!(stem(Path::new("/")), file_name(Path::new("/")));3499 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() {
3461 );3523 );
3462 }3524 }
3463 3525
3464-
3465 /// The band overflowed its own column at 1280x720 (`$EDITH_HITMAP`:3526 /// The band overflowed its own column at 1280x720 (`$EDITH_HITMAP`:
3466 /// `action.Export x=1113 w=80` with the column ending at x=995, the contact3527 /// `action.Export x=1113 w=80` with the column ending at x=995, the contact
3467 /// strip measured `w=0`), so the Export chip was invisible under the dock and3528 /// 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() {
3471 #[test]3532 #[test]
3472 fn the_time_band_never_paints_outside_its_own_column() {3533 fn the_time_band_never_paints_outside_its_own_column() {
3473 let src = src_text("ui/timeband_stance.rs");3534 let src = src_text("ui/timeband_stance.rs");
3474- let start = src.find(r#".id("stance-time-band-row")"#).expect("the band row");3535+ let start = src
3475- let row = &src[start..start + src[start..].find(".child(hero_timecode(").expect("the timecode")];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")];
3476 assert!(3543 assert!(
3477 row.contains(".overflow_hidden()"),3544 row.contains(".overflow_hidden()"),
3478 "the band row lets its children paint (and be clicked) under the dock: {row}"3545 "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() {
3518 fn every_ghost_in_the_time_band_carries_a_full_hit_area() {3585 fn every_ghost_in_the_time_band_carries_a_full_hit_area() {
3519 let src = src_text("ui/timeband_stance.rs");3586 let src = src_text("ui/timeband_stance.rs");
3520 let start = src.find("fn ghost(").expect("the band's ghost");3587 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")];
3522 for needle in [".min_w(px(HIT_MIN))", ".min_h(px(HIT_MIN))"] {3593 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+ );
3524 }3598 }
3525 assert!(HIT_MIN >= 24.);3599 assert!(HIT_MIN >= 24.);
3526 }3600 }
@@ -3532,8 +3606,15 @@ fn every_ghost_in_the_time_band_carries_a_full_hit_area() {
3532 #[test]3606 #[test]
3533 fn the_band_writes_no_monitoring_level() {3607 fn the_band_writes_no_monitoring_level() {
3534 let src = src_text("ui/timeband_stance.rs");3608 let src = src_text("ui/timeband_stance.rs");
3535- for gone in ["player.volume.percent()", "fn volume_readout(", "fn volume_slider("] {3609+ for gone in [
3536- assert!(!src.contains(gone), "the monitoring cluster is back in the band: {gone}");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+ );
3537 }3618 }
3538 }3619 }
3539 3620
@@ -3552,7 +3633,11 @@ fn transport_verbs_differ_by_shape_not_only_by_chord() {
3552 let mut seen = shapes.to_vec();3633 let mut seen = shapes.to_vec();
3553 seen.sort();3634 seen.sort();
3554 seen.dedup();3635 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+ );
3556 }3641 }
3557 3642
3558 /// DESIGN §6: "the cut readout is the odometer". Keyed off the selection it3643 /// 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() {
3745 .find("fn export_section(")3830 .find("fn export_section(")
3746 .expect("the export section");3831 .expect("the export section");
3747 let body = &source[start..];3832 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");
3749 let body = &body[..end];3836 let body = &body[..end];
3750 let rows = [3837 let rows = [
3751 "settings-export-picture",3838 "settings-export-picture",
@@ -3760,10 +3847,16 @@ fn the_export_section_is_four_rows_and_no_fifth() {
3760 // unrated one's readout, never both at once -- so the count is by label,3847 // unrated one's readout, never both at once -- so the count is by label,
3761 // not by id.3848 // not by id.
3762 for label in ["\"Picture\"", "\"Sound\"", "\"Encoder\"", "\"Range\""] {3849 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+ );
3764 }3854 }
3765 let ids = body.match_indices("\"settings-export-").count();3855 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+ );
3767 assert!(3860 assert!(
3768 source.contains("what a delivery is written as"),3861 source.contains("what a delivery is written as"),
3769 "the section lost its head"3862 "the section lost its head"
@@ -3780,7 +3873,7 @@ fn the_export_section_is_four_rows_and_no_fifth() {
3780 /// cannot write, because [`Player::set_format`] would only refuse it back.3873 /// cannot write, because [`Player::set_format`] would only refuse it back.
3781 #[test]3874 #[test]
3782 fn the_picture_row_cycles_codec_and_container_together_and_skips_a_refusal() {3875 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};
3784 assert_eq!(3877 assert_eq!(
3785 PICTURE_CYCLE,3878 PICTURE_CYCLE,
3786 [3879 [
@@ -4017,7 +4110,6 @@ fn no_region_root_wears_a_focus_ring() {
4017 }4110 }
4018 }4111 }
4019 4112
4020-
4021 /// The user could not find the three columns (2026-09-10: "I couldn't realize4113 /// The user could not find the three columns (2026-09-10: "I couldn't realize
4022 /// them when I look at"), because their heads were 12px `ink3` -- the room's4114 /// them when I look at"), because their heads were 12px `ink3` -- the room's
4023 /// quietest type -- with a prose tail running on after each one. The page's4115 /// 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() {
4187 #[test]4279 #[test]
4188 fn the_picture_row_tail_is_the_current_format_alone() {4280 fn the_picture_row_tail_is_the_current_format_alone() {
4189 let source = src_text("ui/settings_stance.rs");4281 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");
4191 let body = &source[start..];4285 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")];
4193 assert!(4289 assert!(
4194 !body.contains("PICTURE_CYCLE"),4290 !body.contains("PICTURE_CYCLE"),
4195 "the Picture row walks the whole cycle to build its tail again"4291 "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::{
6 auto_proxies_pref_path, load_auto_proxies_pref, save_auto_proxies_pref,6 auto_proxies_pref_path, load_auto_proxies_pref, save_auto_proxies_pref,
7 };7 };
8 use crate::subs::{8 use crate::subs::{
9- SUB_SIZE_RANGE, audio_import_tail, load_subtitle_style, save_subtitle_style, sub_line_h_for,9+ audio_import_tail, load_subtitle_style, save_subtitle_style, sub_line_h_for,
10- subtitle_style_path,10+ subtitle_style_path, SUB_SIZE_RANGE,
11 };11 };
12 use crate::ui::preview::{bgra_to_rgba, screenshot_path};12 use crate::ui::preview::{bgra_to_rgba, screenshot_path};
13 13
@@ -32,8 +32,8 @@ fn an_audio_import_names_its_rate_channels_and_length() {
32 /// stuck read and never as a frozen window.32 /// stuck read and never as a frozen window.
33 #[test]33 #[test]
34 fn an_import_line_says_a_stage_has_stopped_moving_and_only_then() {34 fn an_import_line_says_a_stage_has_stopped_moving_and_only_then() {
35- use std::sync::Arc;
36 use std::sync::atomic::{AtomicU8, Ordering::Relaxed};35 use std::sync::atomic::{AtomicU8, Ordering::Relaxed};
36+ use std::sync::Arc;
37 let stage = Arc::new(AtomicU8::new(ImportStage::Header as u8));37 let stage = Arc::new(AtomicU8::new(ImportStage::Header as u8));
38 let started = Instant::now() - Duration::from_secs(9);38 let started = Instant::now() - Duration::from_secs(9);
39 let mut import = Import {39 let mut import = Import {
@@ -303,7 +303,10 @@ fn a_strand_slot_on_a_single_strand_clip_is_the_clip_s_own_colour() {
303 // The clip's own slot is never redirected -- it is what the fallback303 // The clip's own slot is never redirected -- it is what the fallback
304 // lands on.304 // lands on.
305 assert_eq!(VizSlot::Main.picked(one), VizSlot::Main);305 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+ );
307 }310 }
308 311
309 /// A seek says nothing until it has stood: an ordinary one is a flicker and312 /// 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() {
326 /// fifty-one seconds on a 25 GB film.329 /// fifty-one seconds on a 25 GB film.
327 #[test]330 #[test]
328 fn a_silence_card_is_up_while_its_scan_runs_and_says_where_it_has_got_to() {331 fn a_silence_card_is_up_while_its_scan_runs_and_says_where_it_has_got_to() {
329- use std::sync::Arc;
330 use std::sync::atomic::Ordering::Relaxed;332 use std::sync::atomic::Ordering::Relaxed;
333+ use std::sync::Arc;
331 let progress = Arc::new(engine::silence::Progress::default());334 let progress = Arc::new(engine::silence::Progress::default());
332 // Two hours and eight minutes, as the header claims it.335 // Two hours and eight minutes, as the header claims it.
333 progress.total.store(7680, Relaxed);336 progress.total.store(7680, Relaxed);
@@ -757,11 +760,9 @@ fn every_codec_row_is_offered_or_says_why_not() {
757 detail.contains("ec-vorbis"),760 detail.contains("ec-vorbis"),
758 "the row names the encoder like every other live one: {detail}"761 "the row names the encoder like every other live one: {detail}"
759 );762 );
760- assert!(763+ assert!(FORMATS
761- FORMATS764+ .into_iter()
762- .into_iter()765+ .any(|(row, _, _, detail)| row.contains(&Format::Hevc) && detail.contains("intra")));
763- .any(|(row, _, _, detail)| row.contains(&Format::Hevc) && detail.contains("intra"))
764- );
765 // The destination follows the format and keeps the stem, mp4 included.766 // The destination follows the format and keeps the stem, mp4 included.
766 assert_eq!(767 assert_eq!(
767 retarget(std::path::Path::new("/a/take.export.mp4"), Format::Wav),768 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;
10 mod view;10 mod view;
11 11
12 use super::{12 use super::{
13- ACCENT_PRIMARY, AUDIO_KBPS, BG_RAISED, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W,13+ active_lane, auto_bps, band_label, bitrate_detail, clipboard_after_remove, color_snap,
14- ColorEdit, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT,14+ containers, destructive, enable, enable_lane, envelope, eq_card_w, eq_freq, eq_freq_label,
15- EQ_FREQ_HIGH,15+ eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, export_path, export_settings,
16- EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW,16+ format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, frame_rate_ladder,
17- EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, Enable,17+ histogram, inserted_band, is_project, keymap, keys_rows, keys_rows_matching, lane_items,
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,18+ lanes_h, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play,
19- KEYS_ROW_H, KEYS_W, KeyRow, LABEL_H, LANE_H, LANES_MAX, LATE_RESYNC, LIBRARY_MAX_W,19+ notice_tone, panel_h, parse_budget, project_path, proxies_to_start, push_notice, px_below,
20- BENCH_ITEMS, LIBRARY_MIN_W, Lane, MB_FLOOR, MENU_ITEMS, MENU_PAD,20+ range_word, rate_label, retarget, row_enable, row_items, scrub_due, secs_label, should_resync,
21- MENU_ROW_H, MENU_W, NO_FILE, NOTICES_MAX, NumberEdit, OVERLAID, PANEL_H, RESYNC_GAP,21+ silence_rate, size_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at,
22- ROW_ITEMS, RULER_HIT_H, RowCtx, RowItem, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS,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,
23 SPEED_PRESETS, SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_PLAN_CHARS,34 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,35+ TIMELINE_SHARE, VOLUME_W, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, ZOOM_MIN_FRAMES,
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,
37 };36 };
38 37
39 use super::{38 use super::{
40- ActionId, Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, IMPORT_STALL, Import, ImportStage,39+ arrival, audio_rate_choices, av1_hw_warning, clip_width, clock, encoder_choices, encoder_label,
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,
44 eta_secs, file_name, file_uri, fit_choices, frames_of_us, full_scan_key, import_line, landing,40 eta_secs, file_name, file_uri, fit_choices, frames_of_us, full_scan_key, import_line, landing,
45 lane_refuses, launch_queue, library_rows, live_idx, next_fit, next_resolution, note_progress,41 lane_refuses, launch_queue, library_rows, live_idx, next_fit, next_resolution, note_progress,
46 pending_fps_choices, pending_resolution_choices, px_along, read_ahead, repeats,42 pending_fps_choices, pending_resolution_choices, px_along, read_ahead, repeats,
47 resolution_choices, resolution_ladder, sample_rate_choices, scan_plan, seek_line,43 resolution_choices, resolution_ladder, sample_rate_choices, scan_plan, seek_line,
48 silence_cached, silence_line, slice_whole_levels, source_secs, stash_or_write, tone_choices,44 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,
50 };49 };
51 50
52 use super::{51 use super::{
53- SUB_BOTTOM, SUB_CUE_MIN_W, SUB_LINE_H, SUB_TEXT, Subs, carries_subtitles, cue_box, cues_at,52+ carries_subtitles, cue_box, cues_at, file_tint, is_subtitle, lang_human, sub_bottom,
54- file_tint, is_subtitle, lang_human, sub_bottom, sub_pick_name, subtitle_detail,53+ sub_pick_name, subtitle_detail, subtitle_notice, subtitle_rows, subtitle_tail,
55- subtitle_notice, subtitle_rows, subtitle_tail, subtitle_toggle_notice, walk_subtitles,54+ subtitle_toggle_notice, walk_subtitles, Subs, SUB_BOTTOM, SUB_CUE_MIN_W, SUB_LINE_H, SUB_TEXT,
56 };55 };
57 56
58 use engine::PlaybackSession;57 use engine::PlaybackSession;
59 58
60 use engine::scale::FitPolicy;59 use engine::scale::FitPolicy;
61 60
62-use gpui::{Bounds, Pixels, point, px, size};61+use gpui::{point, px, size, Bounds, Pixels};
63 62
64 use std::collections::HashMap;63 use std::collections::HashMap;
65 64
crates/app/src/tests/view.rsmodified+2 -2
@@ -891,7 +891,7 @@ fn the_zoom_button_says_how_much_is_on_the_bed() {
891 /// lives.891 /// lives.
892 #[test]892 #[test]
893 fn tab_cycles_dock_bench_inspector_and_wraps() {893 fn tab_cycles_dock_bench_inspector_and_wraps() {
894- use crate::ui::stance::{Surface, next_surface};894+ use crate::ui::stance::{next_surface, Surface};
895 895
896 assert_eq!(next_surface(Surface::Dock, false), Surface::Bench);896 assert_eq!(next_surface(Surface::Dock, false), Surface::Bench);
897 assert_eq!(next_surface(Surface::Bench, false), Surface::Inspector);897 assert_eq!(next_surface(Surface::Bench, false), Surface::Inspector);
@@ -912,7 +912,7 @@ fn tab_cycles_dock_bench_inspector_and_wraps() {
912 /// surface being entered is always the one mounted.912 /// surface being entered is always the one mounted.
913 #[test]913 #[test]
914 fn surface_wants_src_active_mounts_the_tab_before_focus_lands_on_it() {914 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};
916 916
917 assert_eq!(surface_wants_src_active(Surface::Dock), Some(true));917 assert_eq!(surface_wants_src_active(Surface::Dock), Some(true));
918 assert_eq!(surface_wants_src_active(Surface::Inspector), Some(false));918 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
684 .as_ref()684 .as_ref()
685 .and_then(|session| format_refusal(session, format))685 .and_then(|session| format_refusal(session, format))
686 .map(|why| (short_reason(&why).into(), INK4()));686 .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+ };
688 let (codec, rated) = sound_codec(format);692 let (codec, rated) = sound_codec(format);
689 let seat = player.encoder_seat();693 let seat = player.encoder_seat();
690 let av1_gpu = seat == EncoderSeat::Hardware && matches!(format, Format::Av1 | Format::Av1Mp4);694 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
745 )749 )
746 .into_any_element()750 .into_any_element()
747 }))751 }))
748- .child(row_chord(752+ // The encoder writes the *picture*, and the engine opens no seat for a
749- "settings-export-encoder",753+ // song: with WAV/FLAC/MP3/Ogg picked the row would be a button that
750- "Encoder",754+ // does nothing when pressed. The export moment mounts no row there
751- encoder_word(seat),755+ // either (`Format::has_video`), so this is that same rule rather than a
752- "which encoder writes the picture: the GPU where this machine has a seat, or the CPU",756+ // third treatment.
753- "g",757+ .children(format.has_video().then(|| {
754- av1_gpu.then(|| (AV1_GPU_NOTICE.into(), NOTICE_LOOK())),758+ row_chord(
755- player,759+ "settings-export-encoder",
756- cx.listener(|this, _: &ClickEvent, _, cx| {760+ "Encoder",
757- this.cycle_encoder(cx);761+ encoder_word(seat),
758- }),762+ "which encoder writes the picture: the GPU where this machine has a seat, or the CPU",
759- ))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+ }))
760 // Read-only: the range is set on the timeline with the marks771 // Read-only: the range is set on the timeline with the marks
761 // themselves ([`keymap::ActionId::SetIn`]/`SetOut`), which is where a772 // themselves ([`keymap::ActionId::SetIn`]/`SetOut`), which is where a
762 // person can see what they are marking.773 // person can see what they are marking.
crates/engine/src/edith.rsmodified+99 -22
@@ -387,8 +387,24 @@ pub fn save(
387 let result = std::fs::File::create(&part)387 let result = std::fs::File::create(&part)
388 .and_then(|mut f| {388 .and_then(|mut f| {
389 f.write_all(&emit(389 f.write_all(&emit(
390- &dir, sources, lanes, gains, subs, subtitles, eq, color, transform, resolution,390+ &dir,
391- fps, tone, proxy, auto_proxy, encoder, limiter, sample_rate, playhead,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,
392 ))?;408 ))?;
393 f.sync_all()409 f.sync_all()
394 })410 })
@@ -810,10 +826,9 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
810 }826 }
811 b"samplerate" if v17 => {827 b"samplerate" if v17 => {
812 if doc.sample_rate.is_some() || !doc.sources.is_empty() {828 if doc.sample_rate.is_some() || !doc.sources.is_empty() {
813- return Err(format!(829+ return Err(
814- "line {n}: samplerate belongs once, before the sources"830+ format!("line {n}: samplerate belongs once, before the sources").into(),
815- )831+ );
816- .into());
817 }832 }
818 let f = fields(rest, 1, "samplerate", n)?;833 let f = fields(rest, 1, "samplerate", n)?;
819 let rate = number(f[0], n)?;834 let rate = number(f[0], n)?;
@@ -838,9 +853,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
838 }853 }
839 b"proxy" if v12 => {854 b"proxy" if v12 => {
840 if !doc.sources.is_empty() {855 if !doc.sources.is_empty() {
841- return Err(856+ return Err(format!("line {n}: proxy belongs once, before the sources").into());
842- format!("line {n}: proxy belongs once, before the sources").into()
843- );
844 }857 }
845 let f = fields(rest, 1, "proxy", n)?;858 let f = fields(rest, 1, "proxy", n)?;
846 doc.proxy = match f[0] {859 doc.proxy = match f[0] {
@@ -877,7 +890,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
877 b"encoder" if v14 => {890 b"encoder" if v14 => {
878 if !doc.sources.is_empty() {891 if !doc.sources.is_empty() {
879 return Err(892 return Err(
880- format!("line {n}: encoder belongs once, before the sources").into()893+ format!("line {n}: encoder belongs once, before the sources").into(),
881 );894 );
882 }895 }
883 let f = fields(rest, 1, "encoder", n)?;896 let f = fields(rest, 1, "encoder", n)?;
@@ -1215,7 +1228,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
1215 fade_in: number(f.get(9).copied().unwrap_or(b"0"), n)?.min(frames),1228 fade_in: number(f.get(9).copied().unwrap_or(b"0"), n)?.min(frames),
1216 fade_out: number(f.get(10).copied().unwrap_or(b"0"), n)?.min(frames),1229 fade_out: number(f.get(10).copied().unwrap_or(b"0"), n)?.min(frames),
1217 transition_out: number(f.get(11).copied().unwrap_or(b"0"), n)?.min(frames),1230 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)?,
1219 viz_paint: number64(f.get(14).copied().unwrap_or(b"0"), n)?,1232 viz_paint: number64(f.get(14).copied().unwrap_or(b"0"), n)?,
1220 start: number(f[0], n)?,1233 start: number(f[0], n)?,
1221 in_frame,1234 in_frame,
@@ -1472,6 +1485,15 @@ fn float(field: &[u8], line: usize) -> crate::Result<f32> {
1472 }1485 }
1473 }1486 }
1474 1487
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+
1475 fn number(field: &[u8], line: usize) -> crate::Result<u32> {1497 fn number(field: &[u8], line: usize) -> crate::Result<u32> {
1476 match std::str::from_utf8(field).ok().and_then(|s| s.parse().ok()) {1498 match std::str::from_utf8(field).ok().and_then(|s| s.parse().ok()) {
1477 Some(n) => Ok(n),1499 Some(n) => Ok(n),
@@ -1695,7 +1717,11 @@ mod tests {
1695 (LaneKind::Audio, vec![clip(0, 0, 30, 0, Some(7))]),1717 (LaneKind::Audio, vec![clip(0, 0, 30, 0, Some(7))]),
1696 (LaneKind::Subtitle, Vec::new()),1718 (LaneKind::Subtitle, Vec::new()),
1697 ];1719 ];
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+ ];
1699 let bytes = super::emit(1725 let bytes = super::emit(
1700 &dir,1726 &dir,
1701 &doc().1,1727 &doc().1,
@@ -1917,7 +1943,10 @@ mod tests {
1917 for seat in [EncoderSeat::Hardware, EncoderSeat::Software] {1943 for seat in [EncoderSeat::Hardware, EncoderSeat::Software] {
1918 let written = bytes(seat);1944 let written = bytes(seat);
1919 let text = String::from_utf8_lossy(&written).to_string();1945 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+ );
1921 assert_eq!(parse(&written, &dir).expect("v14 parses").encoder, seat);1950 assert_eq!(parse(&written, &dir).expect("v14 parses").encoder, seat);
1922 }1951 }
1923 1952
@@ -2622,7 +2651,10 @@ mod tests {
2622 "the fades are the clip line's last two fields"2651 "the fades are the clip line's last two fields"
2623 );2652 );
2624 let back = parse(&bytes, &dir).expect("parse");2653 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+ );
2626 }2658 }
2627 2659
2628 /// The whole of the v19 bump, the fade test's twin: a clip's dissolve into2660 /// The whole of the v19 bump, the fade test's twin: a clip's dissolve into
@@ -3248,13 +3280,11 @@ mod tests {
3248 assert!(err.starts_with("line 4: clip at "), "{err}");3280 assert!(err.starts_with("line 4: clip at "), "{err}");
3249 }3281 }
3250 // The lanes are independent, so a video line never crowds an audio one.3282 // The lanes are independent, so a video line never crowds an audio one.
3251- assert!(3283+ assert!(parse(
3252- parse(3284+ b"edith 2\nsource a.mp4\nvideo 0 0 30 0 -\naudio 0 0 30 0 -\n",
3253- b"edith 2\nsource a.mp4\nvideo 0 0 30 0 -\naudio 0 0 30 0 -\n",3285+ &dir
3254- &dir3286+ )
3255- )3287+ .is_ok());
3256- .is_ok()
3257- );
3258 // ...and a lane may be empty as long as the other one is not.3288 // ...and a lane may be empty as long as the other one is not.
3259 let only_audio = parse(b"edith 2\nsource a.mp4\naudio 0 0 30 0 -\n", &dir).expect("parse");3289 let only_audio = parse(b"edith 2\nsource a.mp4\naudio 0 0 30 0 -\n", &dir).expect("parse");
3260 assert!(only_audio.lanes[0].1.is_empty(), "V1 is there and empty");3290 assert!(only_audio.lanes[0].1.is_empty(), "V1 is there and empty");
@@ -3457,7 +3487,10 @@ mod tests {
3457 parse(b"edith 1\nsource a.mp4\n", &dir).expect("v1").lanes,3487 parse(b"edith 1\nsource a.mp4\n", &dir).expect("v1").lanes,
3458 two(Vec::new(), Vec::new())3488 two(Vec::new(), Vec::new())
3459 );3489 );
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());
3461 }3494 }
3462 3495
3463 /// Every truncation of a good file either parses or refuses; none panics.3496 /// Every truncation of a good file either parses or refuses; none panics.
@@ -3479,4 +3512,48 @@ mod tests {
3479 "line 2: truncated % escape in the path"3512 "line 2: truncated % escape in the path"
3480 );3513 );
3481 }3514 }
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+ }
3482 }3559 }
crates/engine/src/playback.rsmodified+211 -24
@@ -26,7 +26,7 @@ use crate::colorspace::{ColorDescription, ContentLight};
26 use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker};26 use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker};
27 use crate::demux::{Codec, Demuxer, NoVideoTrack, Rotation, VideoMeta};27 use crate::demux::{Codec, Demuxer, NoVideoTrack, Rotation, VideoMeta};
28 use crate::eq::EqParams;28 use crate::eq::EqParams;
29-use crate::project::{29+use crate::project::{ProjectSettings,
30 Clip, Edge, GapSweep, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip,30 Clip, Edge, GapSweep, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip,
31 };31 };
32 use crate::scale::{Composer, FitPolicy};32 use crate::scale::{Composer, FitPolicy};
@@ -1188,7 +1188,18 @@ impl PlaybackSession {
1188 // it, and [`Project::with_subs`] refuses one naming a row that is1188 // it, and [`Project::with_subs`] refuses one naming a row that is
1189 // not there.1189 // not there.
1190 .with_subtitles(subtitles)1190 .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);
1192 let span = project.composite_span_at(0);1203 let span = project.composite_span_at(0);
1193 // Last, because it is the one thing here that cannot be taken back: the1204 // Last, because it is the one thing here that cannot be taken back: the
1194 // feeder thread outlives the `Audio` value (it holds its own clones) and1205 // feeder thread outlives the `Audio` value (it holds its own clones) and
@@ -1469,12 +1480,15 @@ impl PlaybackSession {
1469 /// unlike [`remove_source`](Self::remove_source) this does not reseek. Rows1480 /// unlike [`remove_source`](Self::remove_source) this does not reseek. Rows
1470 /// past `idx` move down by one: a caller holding a picked row (the export's1481 /// past `idx` move down by one: a caller holding a picked row (the export's
1471 /// subtitle pick) has to fix it up or drop it; the placements on the lanes1482 /// 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 the1483+ /// are walked down with it and need no fixing.
1473- /// reason [`Project::remove_subtitles`] gives -- the way back is1484+ ///
1474- /// [`import_subtitles`](Self::import_subtitles), which reads a file's1485+ /// One undo step, and the reindex with it ([`Project::remove_subtitles`]'s
1475- /// subtitles and touches nothing else on the timeline -- and it *empties*1486+ /// own entry): every step in the history names its tracks by index into the
1476- /// the undo history, because the steps in it name the tracks by the indexes1487+ /// palette, so an entry carries the palette it was taken beside its lanes --
1477- /// this call just changed.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`]).
1478 pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> {1492 pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> {
1479 self.project.remove_subtitles(idx)1493 self.project.remove_subtitles(idx)
1480 }1494 }
@@ -2820,11 +2834,17 @@ impl PlaybackSession {
2820 /// Says nothing about *which* films have one: a source with no stand-in2834 /// Says nothing about *which* films have one: a source with no stand-in
2821 /// keeps playing its own pictures either way, and one made while this is on2835 /// keeps playing its own pictures either way, and one made while this is on
2822 /// is picked up at the next seek.2836 /// 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.
2823 pub fn set_proxies(&mut self, on: bool) {2841 pub fn set_proxies(&mut self, on: bool) {
2824 if self.proxies == on {2842 if self.proxies == on {
2825 return;2843 return;
2826 }2844 }
2845+ let from = self.settings_value();
2827 self.proxies = on;2846 self.proxies = on;
2847+ self.step_settings(from);
2828 let now = self.now();2848 let now = self.now();
2829 self.seek(now);2849 self.seek(now);
2830 }2850 }
@@ -2839,9 +2859,15 @@ impl PlaybackSession {
2839 }2859 }
2840 2860
2841 /// Pick the seat. Nothing to reseek and nothing to re-probe here: this2861 /// 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.
2843 pub fn set_encoder_seat(&mut self, seat: crate::export::EncoderSeat) {2864 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();
2844 self.encoder_seat = seat;2869 self.encoder_seat = seat;
2870+ self.step_settings(from);
2845 }2871 }
2846 2872
2847 /// The rate this project's mix was picked to run at2873 /// The rate this project's mix was picked to run at
@@ -2853,9 +2879,15 @@ impl PlaybackSession {
2853 2879
2854 /// Pick the mix's own rate, overriding the derived one. Nothing to reseek2880 /// Pick the mix's own rate, overriding the derived one. Nothing to reseek
2855 /// here: it takes effect at the next audio rebuild (a seek, an edit, a2881 /// 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.
2857 pub fn set_sample_rate(&mut self, rate: Option<u32>) {2884 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();
2858 self.sample_rate = rate;2889 self.sample_rate = rate;
2890+ self.step_settings(from);
2859 }2891 }
2860 2892
2861 /// Whether an imported film that wants a stand-in gets one made for it2893 /// Whether an imported film that wants a stand-in gets one made for it
@@ -2867,8 +2899,15 @@ impl PlaybackSession {
2867 /// Make the stand-ins on import, or make none until asked. Nothing to2899 /// Make the stand-ins on import, or make none until asked. Nothing to
2868 /// reseek: this decides what is *started*, never what is decoded -- a proxy2900 /// reseek: this decides what is *started*, never what is decoded -- a proxy
2869 /// already in the cache is still cut on while [`Self::proxies`] is on.2901 /// 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.
2870 pub fn set_auto_proxies(&mut self, on: bool) {2904 pub fn set_auto_proxies(&mut self, on: bool) {
2905+ if self.auto_proxies == on {
2906+ return;
2907+ }
2908+ let from = self.settings_value();
2871 self.auto_proxies = on;2909 self.auto_proxies = on;
2910+ self.step_settings(from);
2872 }2911 }
2873 2912
2874 /// Which source `path` is, canonicalising only if it has to: a source's own2913 /// Which source `path` is, canonicalising only if it has to: a source's own
@@ -2999,10 +3038,9 @@ impl PlaybackSession {
2999 /// that is not a picture -- zero either way, or past 8K, which is where the3038 /// that is not a picture -- zero either way, or past 8K, which is where the
3000 /// per-frame buffers stop being a sane thing to allocate from a keystroke.3039 /// per-frame buffers stop being a sane thing to allocate from a keystroke.
3001 ///3040 ///
3002- /// corner-cut: not an undo step. The project resolution is not in the lane3041+ /// One undo step: the resolution is the project's own, so it rides in the
3003- /// snapshots [`Project::undo`] restores, so cycling it back is one more3042+ /// entry beside the lanes and a `z` takes the canvas back to the size it
3004- /// keypress rather than a `z`. Upgrade path is snapshotting it beside the3043+ /// was ([`Project::push_settings_step`]).
3005- /// lanes, which every existing snapshot site would then have to carry.
3006 pub fn set_resolution(&mut self, width: u32, height: u32) -> bool {3044 pub fn set_resolution(&mut self, width: u32, height: u32) -> bool {
3007 if !crate::is_resolution(width, height) {3045 if !crate::is_resolution(width, height) {
3008 return false;3046 return false;
@@ -3010,8 +3048,10 @@ impl PlaybackSession {
3010 if (width, height) == (self.meta.width, self.meta.height) {3048 if (width, height) == (self.meta.width, self.meta.height) {
3011 return false;3049 return false;
3012 }3050 }
3051+ let from = self.settings_value();
3013 self.meta.width = width;3052 self.meta.width = width;
3014 self.meta.height = height;3053 self.meta.height = height;
3054+ self.step_settings(from);
3015 self.invalidate(Dirty::Picture);3055 self.invalidate(Dirty::Picture);
3016 true3056 true
3017 }3057 }
@@ -3073,12 +3113,15 @@ impl PlaybackSession {
3073 /// ([`crate::mux::frame_timing`], the same wall a file of an unnameable rate3113 /// ([`crate::mux::frame_timing`], the same wall a file of an unnameable rate
3074 /// is refused at).3114 /// is refused at).
3075 ///3115 ///
3076- /// corner-cut: not an undo step, exactly as the project resolution is not --3116+ /// One undo step, and the entry it takes is the whole of the change: the
3077- /// and this one *moves the frame numbers*, so the way back is picking the3117+ /// lanes as they were in the *old* rate's numbering, with that rate beside
3078- /// old rate (or the media's, [`native_frame_rate`](Self::native_frame_rate))3118+ /// them, so a `z` restores the two together ([`Project::retime`]). The
3079- /// rather than a `z`, and it lands within a frame of where it started rather3119+ /// step is taken before the retime rather than after, since this is the one
3080- /// than on it (see [`Project::retime`]). Upgrade path is the same one: the3120+ /// settings door that moves the lanes the step holds. Picking the old rate
3081- /// project's settings snapshotted beside the lanes.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`]).
3082 pub fn set_frame_rate(&mut self, fps: f64) -> bool {3125 pub fn set_frame_rate(&mut self, fps: f64) -> bool {
3083 if !fps.is_finite() || fps <= 0.0 || fps == self.meta.frame_rate {3126 if !fps.is_finite() || fps <= 0.0 || fps == self.meta.frame_rate {
3084 return false;3127 return false;
@@ -3090,6 +3133,8 @@ impl PlaybackSession {
3090 let Ok(k) = Rate::from_fps(self.meta.frame_rate, fps) else {3133 let Ok(k) = Rate::from_fps(self.meta.frame_rate, fps) else {
3091 return false;3134 return false;
3092 };3135 };
3136+ let from = self.settings_value();
3137+ self.project.push_settings_step(from.clone(), from);
3093 // Lengths first: the retime holds every clip inside its source's *new*3138 // Lengths first: the retime holds every clip inside its source's *new*
3094 // length, so a clip that played to the last frame of its file still3139 // length, so a clip that played to the last frame of its file still
3095 // does rather than naming one past the end.3140 // does rather than naming one past the end.
@@ -3103,6 +3148,9 @@ impl PlaybackSession {
3103 }3148 }
3104 self.meta.frame_rate = fps;3149 self.meta.frame_rate = fps;
3105 self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1);3150 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());
3106 let now = self.now();3154 let now = self.now();
3107 self.seek(now);3155 self.seek(now);
3108 true3156 true
@@ -3511,15 +3559,19 @@ impl PlaybackSession {
3511 self.edit(Dirty::Both, |p| p.delete_in(lane, idx))3559 self.edit(Dirty::Both, |p| p.delete_in(lane, idx))
3512 }3560 }
3513 3561
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.
3515 pub fn undo(&mut self) -> bool {3567 pub fn undo(&mut self) -> bool {
3516- self.edit(Dirty::Both, Project::undo)3568+ self.restored_step(Project::undo)
3517 }3569 }
3518 3570
3519 /// Redoes the last edit [`undo`](Self::undo) took back, and reseeks like3571 /// 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.
3521 pub fn redo(&mut self) -> bool {3573 pub fn redo(&mut self) -> bool {
3522- self.edit(Dirty::Both, Project::redo)3574+ self.restored_step(Project::redo)
3523 }3575 }
3524 3576
3525 /// Takes `path` into the **library**: it becomes a source of this session,3577 /// Takes `path` into the **library**: it becomes a source of this session,
@@ -3686,6 +3738,94 @@ impl PlaybackSession {
3686 /// policy rebuilds the picture where it stands, with the sound running3738 /// policy rebuilds the picture where it stands, with the sound running
3687 /// through it untouched -- no flush, no re-open, no hole -- and an3739 /// through it untouched -- no flush, no re-open, no hole -- and an
3688 /// equalizer the other way round.3740 /// 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+
3689 fn edit(&mut self, dirty: Dirty, f: impl FnOnce(&mut Project) -> bool) -> bool {3829 fn edit(&mut self, dirty: Dirty, f: impl FnOnce(&mut Project) -> bool) -> bool {
3690 if !f(&mut self.project) {3830 if !f(&mut self.project) {
3691 return false;3831 return false;
@@ -5179,6 +5319,53 @@ mod tests {
5179 assert_eq!(next.index, first.index, "paused: same timeline position before and after");5319 assert_eq!(next.index, first.index, "paused: same timeline position before and after");
5180 }5320 }
5181 5321
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+
5182 /// The session's live look samples leave its history exactly where the5369 /// The session's live look samples leave its history exactly where the
5183 /// press left it -- the colour-wheel drag's twin for the packed look, and5370 /// press left it -- the colour-wheel drag's twin for the packed look, and
5184 /// what lets the app drive one from a pointer: `z` after a drag lands5371 /// 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(
116 pub(crate) usize,116 pub(crate) usize,
117 pub(crate) Vec<(LaneKind, Vec<Clip>)>,117 pub(crate) Vec<(LaneKind, Vec<Clip>)>,
118 pub(crate) Vec<Vec<SubClip>>,118 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,
119 );124 );
120 125
121 impl Speed {126 impl Speed {
@@ -881,11 +886,75 @@ pub type Parts = (
881 886
882 /// How many undo steps a project keeps. One gesture is one step, so 100 is past887 /// How many undo steps a project keeps. One gesture is one step, so 100 is past
883 /// any chain a person walks back by hand, and the oldest step is dropped rather888 /// 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, so889+/// than the history growing without end: a snapshot is the whole lane list plus
885-/// on a 1394-clip jumpcut timeline this is a bounded ~10 MB instead of a leak890+/// the palette and the project's own settings, so on a 1394-clip jumpcut
886-/// that grows for as long as the session lasts.891+/// timeline this is a bounded ~10 MB instead of a leak that grows for as long
892+/// as the session lasts.
887 const HISTORY_CAP: usize = 100;893 const HISTORY_CAP: usize = 100;
888 894
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+
889 /// One gap a close-all sweep left open, with the frame it still starts on and958 /// One gap a close-all sweep left open, with the frame it still starts on and
890 /// the same refusal a single [`Project::gap_take_scope`] close would have said.959 /// the same refusal a single [`Project::gap_take_scope`] close would have said.
891 #[derive(Clone, Debug, PartialEq, Eq)]960 #[derive(Clone, Debug, PartialEq, Eq)]
@@ -917,32 +986,31 @@ pub struct Project {
917 /// The same, for [`Clip::transform`].986 /// The same, for [`Clip::transform`].
918 transform: Vec<TransformParams>,987 transform: Vec<TransformParams>,
919 /// Snapshots pushed *before* each successful edit; `undo` pops one. The988 /// Snapshots pushed *before* each successful edit; `undo` pops one. The
920- /// whole lane list, so adding a lane undoes as well. Bounded by989+ /// whole lane list, the subtitle palette and the project's own settings,
921- /// [`HISTORY_CAP`]: at the cap the oldest step goes.990+ /// so adding a lane undoes as well and so does picking a resolution. Bounded
922- history: Vec<Vec<LaneData>>,991+ /// by [`HISTORY_CAP`]: at the cap the oldest step goes.
923- /// Lane lists `undo` has stepped past; `redo` pops one. Cleared by992+ history: Vec<Snapshot>,
993+ /// Snapshots `undo` has stepped past; `redo` pops one. Cleared by
924 /// [`Project::snapshot`], since a fresh edit invalidates whatever branch994 /// [`Project::snapshot`], since a fresh edit invalidates whatever branch
925 /// the undone steps came from. Not saved to `.edith`, matching `history`.995 /// the undone steps came from. Not saved to `.edith`, matching `history`.
926- redo: Vec<Vec<LaneData>>,996+ redo: Vec<Snapshot>,
927 /// Never rolled back by an undo: an id retired by an undone split must not997 /// Never rolled back by an undo: an id retired by an undone split must not
928 /// come back and group two clips that were never together.998 /// come back and group two clips that were never together.
929 next_link: u32,999 next_link: u32,
930 /// The subtitle tracks this timeline shows, in the order they were added.1000 /// 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 reason1001+ /// Saved as a *reference* to the file the cues came out of
932- /// the limiter is not: which subtitles a project carries is a setting on1002+ /// ([`crate::subtitle`]). In the history snapshots since the widened
933- /// it, and it is saved as a *reference* to the file the cues came out of1003+ /// [`Snapshot`]: a placement names a track by index into this list, so a
934- /// ([`crate::subtitle`]).1004+ /// removal that reindexes the placements can only undo together with the
1005+ /// palette it removed the row from.
935 subtitles: Vec<SubtitleTrack>,1006 subtitles: Vec<SubtitleTrack>,
936- /// The master limiter every lane's sound is summed *through*1007+ /// The project's own settings ([`ProjectSettings`]) -- the canvas, the
937- /// ([`Project::limiter`]). Off by default, and not in the lane list, which1008+ /// rate, the proxies switches, the encoder seat, the mix rate, the
938- /// is what the history snapshots hold: it is a setting on the mix, like the1009+ /// rendition and the limiter. In every snapshot, so each of them undoes
939- /// project's resolution is a setting on the picture, and neither is an undo1010+ /// like a lane edit: they are the header of the project's own `.edith`
940- /// step.1011+ /// file, not this machine's, and a pick a ctrl+z could not take back
941- limiter: Limiter,1012+ /// would be the one setting with no way out.
942- /// Which HDR-to-SDR rendition every clip on an HDR curve is shown and1013+ settings: ProjectSettings,
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,
946 }1014 }
947 1015
948 impl Project {1016 impl Project {
@@ -980,8 +1048,7 @@ impl Project {
980 redo: Vec::new(),1048 redo: Vec::new(),
981 next_link: 1,1049 next_link: 1,
982 subtitles: Vec::new(),1050 subtitles: Vec::new(),
983- limiter: Limiter::default(),1051+ settings: ProjectSettings::placeholder(),
984- tone: crate::tonemap::Preset::default(),
985 }1052 }
986 }1053 }
987 1054
@@ -1124,8 +1191,7 @@ impl Project {
1124 redo: Vec::new(),1191 redo: Vec::new(),
1125 next_link,1192 next_link,
1126 subtitles: Vec::new(),1193 subtitles: Vec::new(),
1127- limiter: Limiter::default(),1194+ settings: ProjectSettings::placeholder(),
1128- tone: crate::tonemap::Preset::default(),
1129 })1195 })
1130 }1196 }
1131 1197
@@ -1400,7 +1466,8 @@ impl Project {
1400 /// different file. [`PlaybackSession::remove_source`] hands back the index1466 /// different file. [`PlaybackSession::remove_source`] hands back the index
1401 /// that went for exactly that.1467 /// that went for exactly that.
1402 ///1468 ///
1403- /// corner-cut: this retires the undo stack. `history` holds lanes alone, so a1469+ /// 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
1404 /// snapshot older than the removal can name the very source being removed1471 /// snapshot older than the removal can name the very source being removed
1405 /// (delete a file's clips, then remove the file) and restoring it would1472 /// (delete a file's clips, then remove the file) and restoring it would
1406 /// point a clip at an entry that is gone. The upgrade path is snapshotting1473 /// point a clip at an entry that is gone. The upgrade path is snapshotting
@@ -1679,14 +1746,44 @@ impl Project {
1679 data.gain_db = db.clamp(MIN_GAIN_DB, MAX_GAIN_DB);1746 data.gain_db = db.clamp(MIN_GAIN_DB, MAX_GAIN_DB);
1680 }1747 }
1681 }1748 }
1682- self.limiter = limiter.with_ceiling(limiter.ceiling_db);1749+ self.settings.limiter = limiter.with_ceiling(limiter.ceiling_db);
1683 self1750 self
1684 }1751 }
1685 1752
1686 /// The HDR rendition a *load* puts back -- the same door1753 /// The HDR rendition a *load* puts back -- the same door
1687 /// [`with_mix`](Project::with_mix) is, and no undo step for the same reason.1754 /// [`with_mix`](Project::with_mix) is, and no undo step for the same reason.
1688 pub fn with_tone(mut self, preset: crate::tonemap::Preset) -> Self {1755 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;
1690 self1787 self
1691 }1788 }
1692 1789
@@ -1694,21 +1791,18 @@ impl Project {
1694 /// project setting, not a clip's: one picture, one look1791 /// project setting, not a clip's: one picture, one look
1695 /// ([`crate::tonemap::Preset`]).1792 /// ([`crate::tonemap::Preset`]).
1696 pub fn tone(&self) -> crate::tonemap::Preset {1793 pub fn tone(&self) -> crate::tonemap::Preset {
1697- self.tone1794+ self.settings.tone
1698 }1795 }
1699 1796
1700 /// Sets it. `false` for the one already in force, which is what keeps a1797 /// 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.1798+ /// re-pick of the current rendition from costing a reseek. One undo step
1702- ///1799+ /// like every other project-setting pick.
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.
1707 pub fn set_tone(&mut self, preset: crate::tonemap::Preset) -> bool {1800 pub fn set_tone(&mut self, preset: crate::tonemap::Preset) -> bool {
1708- if self.tone == preset {1801+ if self.settings.tone == preset {
1709 return false;1802 return false;
1710 }1803 }
1711- self.tone = preset;1804+ self.snapshot();
1805+ self.settings.tone = preset;
1712 true1806 true
1713 }1807 }
1714 1808
@@ -1763,16 +1857,14 @@ impl Project {
1763 /// [`remove_source`](Project::remove_source) refuses the same way for the1857 /// [`remove_source`](Project::remove_source) refuses the same way for the
1764 /// same silent corruption.1858 /// same silent corruption.
1765 ///1859 ///
1766- /// corner-cut: not an undo step, for the reason the limiter is not -- the1860+ /// One undo step, and the reindex with it: every placement names a track
1767- /// history snapshots hold the lane list and subtitles are not on it1861+ /// by index into the palette ([`crate::subtitle`]), so a removal that
1768- /// ([`Project::subtitles`]). The inverse is putting the file's tracks back1862+ /// renumbers them can only come back together with the palette it took
1769- /// on -- [`crate::PlaybackSession::import_subtitles`], the panel's own1863+ /// the row from -- which is what the history entry holds, beside the
1770- /// door, which reads the subtitles of a file and nothing else -- and not a1864+ /// lanes it also carries ([`Snapshot`]). The inverse, for a caller that
1771- /// ctrl+z; the upgrade path is the same one the limiter has: a history1865+ /// wants the file's tracks back, is [`crate::PlaybackSession::import_subtitles`]
1772- /// entry holding the project's own settings beside the lanes. The history1866+ /// -- the panel's own door, which reads the subtitles of a file and
1773- /// is *cleared* rather than kept, as a source removal clears it: the1867+ /// nothing else.
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.
1776 pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> {1868 pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> {
1777 if idx >= self.subtitles.len() {1869 if idx >= self.subtitles.len() {
1778 return Err(format!("there is no subtitle track {idx} to remove").into());1870 return Err(format!("there is no subtitle track {idx} to remove").into());
@@ -1796,13 +1888,13 @@ impl Project {
1796 )1888 )
1797 .into());1889 .into());
1798 }1890 }
1891+ self.snapshot();
1799 self.subtitles.remove(idx);1892 self.subtitles.remove(idx);
1800 for s in self.lanes.iter_mut().flat_map(|l| &mut l.subs) {1893 for s in self.lanes.iter_mut().flat_map(|l| &mut l.subs) {
1801 if s.track > idx {1894 if s.track > idx {
1802 s.track -= 1;1895 s.track -= 1;
1803 }1896 }
1804 }1897 }
1805- self.history.clear();
1806 Ok(())1898 Ok(())
1807 }1899 }
1808 1900
@@ -2252,25 +2344,34 @@ impl Project {
2252 /// The master limiter the mix is summed through. A project setting, not a2344 /// The master limiter the mix is summed through. A project setting, not a
2253 /// clip's and not a lane's: there is one mix.2345 /// clip's and not a lane's: there is one mix.
2254 pub fn limiter(&self) -> Limiter {2346 pub fn limiter(&self) -> Limiter {
2255- self.limiter2347+ self.settings.limiter
2256 }2348 }
2257 2349
2258 /// Sets it, with the ceiling clamped to what [`Limiter`] allows. `false`2350 /// Sets it, with the ceiling clamped to what [`Limiter`] allows. `false`
2259- /// for a setting already in force.2351+ /// for a setting already in force. One undo step like every other
2260- ///2352+ /// project-setting pick.
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.
2265 pub fn set_limiter(&mut self, limiter: Limiter) -> bool {2353 pub fn set_limiter(&mut self, limiter: Limiter) -> bool {
2266 let limiter = limiter.with_ceiling(limiter.ceiling_db);2354 let limiter = limiter.with_ceiling(limiter.ceiling_db);
2267- if self.limiter == limiter {2355+ if self.settings.limiter == limiter {
2268 return false;2356 return false;
2269 }2357 }
2270- self.limiter = limiter;2358+ self.snapshot();
2359+ self.settings.limiter = limiter;
2271 true2360 true
2272 }2361 }
2273 2362
2363+
2364+
2365+
2366+
2367+
2368+
2369+
2370+
2371+
2372+
2373+
2374+
2274 /// What the clip at `idx` of `lane` plays through, or `None` for one that2375 /// What the clip at `idx` of `lane` plays through, or `None` for one that
2275 /// plays flat (and for an index that is not there) -- what a feeder and an2376 /// plays flat (and for an index that is not there) -- what a feeder and an
2276 /// export ask before they build an [`crate::eq::EqState`].2377 /// export ask before they build an [`crate::eq::EqState`].
@@ -4948,6 +5049,36 @@ impl Project {
4948 self.redo.len()5049 self.redo.len()
4949 }5050 }
4950 5051
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+
4951 /// Every part of the project that an edit can change, as comparable5082 /// Every part of the project that an edit can change, as comparable
4952 /// values: what the sweep's undo round-trip asks "byte identical?" of.5083 /// values: what the sweep's undo round-trip asks "byte identical?" of.
4953 #[cfg(test)]5084 #[cfg(test)]
@@ -4956,31 +5087,45 @@ impl Project {
4956 self.sources.len(),5087 self.sources.len(),
4957 self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(),5088 self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(),
4958 self.lanes.iter().map(|l| l.subs.clone()).collect(),5089 self.lanes.iter().map(|l| l.subs.clone()).collect(),
5090+ self.subtitles.clone(),
5091+ self.settings.clone(),
4959 )5092 )
4960 }5093 }
4961 5094
4962- /// Restore every lane from before the last successful edit -- the clips and5095+ /// Restore everything from before the last successful edit -- the lanes,
4963- /// the lane list both. `false` when there is nothing left to undo. Pushes5096+ /// the subtitle palette and the project's own settings. `false` when there
4964- /// the lanes just left onto the redo stack, so [`Project::redo`] can walk5097+ /// is nothing left to undo. Pushes what was just left onto the redo stack,
4965- /// forward again.5098+ /// so [`Project::redo`] can walk forward again.
4966 pub fn undo(&mut self) -> bool {5099 pub fn undo(&mut self) -> bool {
4967 match self.history.pop() {5100 match self.history.pop() {
4968 Some(prev) => {5101 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;
4970 true5109 true
4971 }5110 }
4972 None => false,5111 None => false,
4973 }5112 }
4974 }5113 }
4975 5114
4976- /// Restore every lane from before the last [`Project::undo`] -- the5115+ /// Restore everything from before the last [`Project::undo`] -- the
4977 /// mirror of `undo`, walking the redo stack it fills. `false` when there5116 /// mirror of `undo`, walking the redo stack it fills. `false` when there
4978 /// is nothing left to redo, which is also true after any fresh edit: a5117 /// is nothing left to redo, which is also true after any fresh edit: a
4979 /// new [`Project::snapshot`] clears the branch `undo` left behind.5118 /// new [`Project::snapshot`] clears the branch `undo` left behind.
4980 pub fn redo(&mut self) -> bool {5119 pub fn redo(&mut self) -> bool {
4981 match self.redo.pop() {5120 match self.redo.pop() {
4982 Some(next) => {5121 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;
4984 true5129 true
4985 }5130 }
4986 None => false,5131 None => false,
@@ -5002,8 +5147,7 @@ impl Project {
5002 redo: Vec::new(),5147 redo: Vec::new(),
5003 next_link: self.next_link,5148 next_link: self.next_link,
5004 subtitles: self.subtitles.clone(),5149 subtitles: self.subtitles.clone(),
5005- limiter: self.limiter,5150+ settings: self.settings.clone(),
5006- tone: self.tone,
5007 }5151 }
5008 }5152 }
5009 5153
@@ -5216,7 +5360,11 @@ impl Project {
5216 if self.history.len() == HISTORY_CAP {5360 if self.history.len() == HISTORY_CAP {
5217 self.history.remove(0);5361 self.history.remove(0);
5218 }5362 }
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+ });
5220 self.redo.clear();5368 self.redo.clear();
5221 }5369 }
5222 5370
@@ -10405,4 +10553,42 @@ mod tests {
10405 .expect("valid parts");10553 .expect("valid parts");
10406 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);10554 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);
10407 }10555 }
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+
10408 }10594 }
crates/engine/src/subtitle.rsmodified+5 -1
@@ -140,7 +140,11 @@ fn segments(set: &[u8]) -> Option<Vec<(u8, &[u8])>> {
140 }140 }
141 141
142 /// A subtitle track: where it came from and what it says.142 /// 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)]
144 pub struct SubtitleTrack {148 pub struct SubtitleTrack {
145 /// The file it was read out of: a standalone subtitle file, or the media149 /// The file it was read out of: a standalone subtitle file, or the media
146 /// file whose track number is below.150 /// file whose track number is below.