forge
Explore
Log in

Don't you dare go Hollow

The settings and the subtitle palette ride in the history entry

Browse files at this commit

2d2933c691612bda34abd1dd4d70a6a123a14832Ahmet Kaan GümüşParent: 19dcc3e
  • fix
    • the settings and the subtitle palette ride in the history entry
Show full message
🐛 fix(project,playback): the settings and the subtitle palette ride in the history entry

The entry held the lane list alone, so a resolution, a rate, an encoder seat, a mix rate or a proxy switch could not be taken back by ctrl+z, and removing a subtitle column had to retire the whole stack rather than reindex under it. The entry carries a ProjectSettings value and the palette now; the session hands its own copy over at every door and takes the restored one up after an undo, where a rate step conforms the per-source lengths back within a frame the way the way out already did. The column removal takes a step of its own instead of clearing the stack.
crates/engine/src/playback.rsmodified+148 -18
@@ -26,7 +26,7 @@ use crate::colorspace::{ColorDescription, ContentLight};
2626 use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker};
2727 use crate::demux::{Codec, Demuxer, NoVideoTrack, Rotation, VideoMeta};
2828 use crate::eq::EqParams;
29-use crate::project::{
29+use crate::project::{ProjectSettings,
3030 Clip, Edge, GapSweep, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip,
3131 };
3232 use crate::scale::{Composer, FitPolicy};
@@ -1164,7 +1164,18 @@ impl PlaybackSession {
11641164 // it, and [`Project::with_subs`] refuses one naming a row that is
11651165 // not there.
11661166 .with_subtitles(subtitles)
1167- .with_subs(doc.subs)?;
1167+ .with_subs(doc.subs)?
1168+ // The header a load puts back: the canvas and rate above, which a
1169+ // save's own `resolution`/`fps` lines may have moved off the
1170+ // scaffold's, and the switches the literal below carries -- handed
1171+ // in here because they are the project's own and a door that moved
1172+ // one after this would snapshot whatever copy it holds, which until
1173+ // this line is the placeholder's. No undo step for
1174+ // [`Project::with_mix`]'s reason: a project that arrived one `z`
1175+ // from a state it was never in is a project whose first undo is a
1176+ // surprise.
1177+ .with_canvas(meta.width, meta.height, meta.frame_rate)
1178+ .with_switches(doc.proxy, doc.auto_proxy, doc.encoder, doc.sample_rate);
11681179 let span = project.composite_span_at(0);
11691180 // Last, because it is the one thing here that cannot be taken back: the
11701181 // feeder thread outlives the `Audio` value (it holds its own clones) and
@@ -2734,11 +2745,17 @@ impl PlaybackSession {
27342745 /// Says nothing about *which* films have one: a source with no stand-in
27352746 /// keeps playing its own pictures either way, and one made while this is on
27362747 /// is picked up at the next seek.
2748+ ///
2749+ /// One undo step ([`Project::push_settings_step`]), and the seek below is
2750+ /// what makes the undo of it land on the picture: it reopens the span
2751+ /// through [`picture_path`](Self::picture_path), which reads this switch.
27372752 pub fn set_proxies(&mut self, on: bool) {
27382753 if self.proxies == on {
27392754 return;
27402755 }
2756+ let from = self.settings_value();
27412757 self.proxies = on;
2758+ self.step_settings(from);
27422759 let now = self.now();
27432760 self.seek(now);
27442761 }
@@ -2753,9 +2770,15 @@ impl PlaybackSession {
27532770 }
27542771
27552772 /// Pick the seat. Nothing to reseek and nothing to re-probe here: this
2756- /// decides what an *export* opens, never what plays.
2773+ /// decides what an *export* opens, never what plays. One undo step, like
2774+ /// every other pick on the project.
27572775 pub fn set_encoder_seat(&mut self, seat: crate::export::EncoderSeat) {
2776+ if self.encoder_seat == seat {
2777+ return;
2778+ }
2779+ let from = self.settings_value();
27582780 self.encoder_seat = seat;
2781+ self.step_settings(from);
27592782 }
27602783
27612784 /// The rate this project's mix was picked to run at
@@ -2767,9 +2790,15 @@ impl PlaybackSession {
27672790
27682791 /// Pick the mix's own rate, overriding the derived one. Nothing to reseek
27692792 /// here: it takes effect at the next audio rebuild (a seek, an edit, a
2770- /// reopen), not on the device already playing.
2793+ /// reopen), not on the device already playing. One undo step, like every
2794+ /// other pick on the project.
27712795 pub fn set_sample_rate(&mut self, rate: Option<u32>) {
2796+ if self.sample_rate == rate {
2797+ return;
2798+ }
2799+ let from = self.settings_value();
27722800 self.sample_rate = rate;
2801+ self.step_settings(from);
27732802 }
27742803
27752804 /// Whether an imported film that wants a stand-in gets one made for it
@@ -2781,8 +2810,15 @@ impl PlaybackSession {
27812810 /// Make the stand-ins on import, or make none until asked. Nothing to
27822811 /// reseek: this decides what is *started*, never what is decoded -- a proxy
27832812 /// already in the cache is still cut on while [`Self::proxies`] is on.
2813+ ///
2814+ /// One undo step, like every other switch on the project.
27842815 pub fn set_auto_proxies(&mut self, on: bool) {
2816+ if self.auto_proxies == on {
2817+ return;
2818+ }
2819+ let from = self.settings_value();
27852820 self.auto_proxies = on;
2821+ self.step_settings(from);
27862822 }
27872823
27882824 /// Which source `path` is, canonicalising only if it has to: a source's own
@@ -2913,10 +2949,9 @@ impl PlaybackSession {
29132949 /// that is not a picture -- zero either way, or past 8K, which is where the
29142950 /// per-frame buffers stop being a sane thing to allocate from a keystroke.
29152951 ///
2916- /// corner-cut: not an undo step. The project resolution is not in the lane
2917- /// snapshots [`Project::undo`] restores, so cycling it back is one more
2918- /// keypress rather than a `z`. Upgrade path is snapshotting it beside the
2919- /// lanes, which every existing snapshot site would then have to carry.
2952+ /// One undo step: the resolution is the project's own, so it rides in the
2953+ /// entry beside the lanes and a `z` takes the canvas back to the size it
2954+ /// was ([`Project::push_settings_step`]).
29202955 pub fn set_resolution(&mut self, width: u32, height: u32) -> bool {
29212956 if !crate::is_resolution(width, height) {
29222957 return false;
@@ -2924,8 +2959,10 @@ impl PlaybackSession {
29242959 if (width, height) == (self.meta.width, self.meta.height) {
29252960 return false;
29262961 }
2962+ let from = self.settings_value();
29272963 self.meta.width = width;
29282964 self.meta.height = height;
2965+ self.step_settings(from);
29292966 self.invalidate(Dirty::Picture);
29302967 true
29312968 }
@@ -2987,12 +3024,15 @@ impl PlaybackSession {
29873024 /// ([`crate::mux::frame_timing`], the same wall a file of an unnameable rate
29883025 /// is refused at).
29893026 ///
2990- /// corner-cut: not an undo step, exactly as the project resolution is not --
2991- /// and this one *moves the frame numbers*, so the way back is picking the
2992- /// old rate (or the media's, [`native_frame_rate`](Self::native_frame_rate))
2993- /// rather than a `z`, and it lands within a frame of where it started rather
2994- /// than on it (see [`Project::retime`]). Upgrade path is the same one: the
2995- /// project's settings snapshotted beside the lanes.
3027+ /// One undo step, and the entry it takes is the whole of the change: the
3028+ /// lanes as they were in the *old* rate's numbering, with that rate beside
3029+ /// them, so a `z` restores the two together ([`Project::retime`]). The
3030+ /// step is taken before the retime rather than after, since this is the one
3031+ /// settings door that moves the lanes the step holds. Picking the old rate
3032+ /// back is still within a frame of where it started rather than on it: the
3033+ /// *lanes* come home exactly out of the entry, and the per-source lengths
3034+ /// are the half that goes through the map twice
3035+ /// ([`PlaybackSession::adopt_settings`]).
29963036 pub fn set_frame_rate(&mut self, fps: f64) -> bool {
29973037 if !fps.is_finite() || fps <= 0.0 || fps == self.meta.frame_rate {
29983038 return false;
@@ -3004,6 +3044,8 @@ impl PlaybackSession {
30043044 let Ok(k) = Rate::from_fps(self.meta.frame_rate, fps) else {
30053045 return false;
30063046 };
3047+ let from = self.settings_value();
3048+ self.project.push_settings_step(from.clone(), from);
30073049 // Lengths first: the retime holds every clip inside its source's *new*
30083050 // length, so a clip that played to the last frame of its file still
30093051 // does rather than naming one past the end.
@@ -3017,6 +3059,9 @@ impl PlaybackSession {
30173059 }
30183060 self.meta.frame_rate = fps;
30193061 self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1);
3062+ // The copy the project keeps, now that the change has landed: what the
3063+ // next lane edit's entry carries.
3064+ self.project.mirror_settings(self.settings_value());
30203065 let now = self.now();
30213066 self.seek(now);
30223067 true
@@ -3425,15 +3470,19 @@ impl PlaybackSession {
34253470 self.edit(Dirty::Both, |p| p.delete_in(lane, idx))
34263471 }
34273472
3428- /// Undoes the last successful edit, and reseeks like a delete.
3473+ /// Undoes the last successful edit, and reseeks like a delete. A step on
3474+ /// the project's own settings comes back the same way: the canvas, the
3475+ /// rate and the switches are put back on the session here
3476+ /// ([`Self::adopt_settings`]), so a `z` after a resolution pick, an
3477+ /// encoder pick or a proxy switch lands exactly as one after a cut does.
34293478 pub fn undo(&mut self) -> bool {
3430- self.edit(Dirty::Both, Project::undo)
3479+ self.restored_step(Project::undo)
34313480 }
34323481
34333482 /// Redoes the last edit [`undo`](Self::undo) took back, and reseeks like
3434- /// a delete.
3483+ /// a delete -- settings included, exactly as `undo` takes them back.
34353484 pub fn redo(&mut self) -> bool {
3436- self.edit(Dirty::Both, Project::redo)
3485+ self.restored_step(Project::redo)
34373486 }
34383487
34393488 /// Takes `path` into the **library**: it becomes a source of this session,
@@ -3600,6 +3649,87 @@ impl PlaybackSession {
36003649 /// policy rebuilds the picture where it stands, with the sound running
36013650 /// through it untouched -- no flush, no re-open, no hole -- and an
36023651 /// equalizer the other way round.
3652+ /// The project's own settings as this session has them now
3653+ /// ([`ProjectSettings`]): the canvas and the rate are `meta`'s, the
3654+ /// switches are this session's own fields, and the rendition and the
3655+ /// limiter are the project's -- two halves of one header, which is what
3656+ /// every history entry carries beside the lanes ([`Project::snapshot`]).
3657+ fn settings_value(&self) -> ProjectSettings {
3658+ ProjectSettings {
3659+ resolution: (self.meta.width, self.meta.height),
3660+ frame_rate: self.meta.frame_rate,
3661+ encoder_seat: self.encoder_seat,
3662+ sample_rate: self.sample_rate,
3663+ proxies: self.proxies,
3664+ auto_proxies: self.auto_proxies,
3665+ tone: self.project.tone(),
3666+ limiter: self.project.limiter(),
3667+ }
3668+ }
3669+
3670+ /// One undo step for a change to the project's own settings, taken after
3671+ /// the change: `from` is the state the door found, and what the project
3672+ /// does with the two values is [`Project::push_settings_step`]'s.
3673+ fn step_settings(&mut self, from: ProjectSettings) {
3674+ let now = self.settings_value();
3675+ self.project.push_settings_step(from, now);
3676+ }
3677+
3678+ /// Puts the project's settings back on this session -- what a step that
3679+ /// restored them leaves for the player to take up. The canvas, the rate and
3680+ /// the switches live here, and the rendition and the limiter are the
3681+ /// project's own, already back in place by the time this runs. Every lane
3682+ /// edit's entry comes through here too and moves nothing, which is the
3683+ /// common case; the *rate* is the one that needs more than the fields,
3684+ /// because every source's frame count is held against it and the conform
3685+ /// that scaled them is not in the entry.
3686+ fn adopt_settings(&mut self) {
3687+ let s = self.project.settings_now();
3688+ // A project nobody has handed a canvas to: a fresh [`Project`] carries
3689+ // the placeholder ([`ProjectSettings::placeholder`]) and no session is
3690+ // on one -- the entries pushed before the first settings door hold lane
3691+ // edits and that placeholder, and adopting it would zero the canvas.
3692+ if s.frame_rate <= 0.0 {
3693+ return;
3694+ }
3695+ let was = self.meta.frame_rate;
3696+ self.meta.width = s.resolution.0;
3697+ self.meta.height = s.resolution.1;
3698+ self.meta.frame_rate = s.frame_rate;
3699+ self.encoder_seat = s.encoder_seat;
3700+ self.sample_rate = s.sample_rate;
3701+ self.proxies = s.proxies;
3702+ self.auto_proxies = s.auto_proxies;
3703+ if s.frame_rate != was {
3704+ // Within a frame, like the way out ([`Self::set_frame_rate`]'s own
3705+ // caveat): the lane frame numbers came home exactly, out of the
3706+ // entry, and only the per-source lengths are re-derived through the
3707+ // map back.
3708+ let Ok(k) = Rate::from_fps(was, s.frame_rate) else {
3709+ return;
3710+ };
3711+ for count in &mut self.counts {
3712+ *count = k.timeline_at(*count).max(1);
3713+ }
3714+ for rate in &mut self.rates {
3715+ *rate = rate.then(k);
3716+ }
3717+ self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1);
3718+ }
3719+ }
3720+
3721+ /// [`Self::undo`] and [`Self::redo`] themselves: the project's own step,
3722+ /// and then whatever it restored for the session to take up
3723+ /// ([`Self::adopt_settings`]). Reseeks both halves, so a canvas that moved
3724+ /// is repainted and a proxy switch that flipped reopens the file.
3725+ fn restored_step(&mut self, f: impl FnOnce(&mut Project) -> bool) -> bool {
3726+ if !self.edit(Dirty::Both, f) {
3727+ return false;
3728+ }
3729+ self.adopt_settings();
3730+ true
3731+ }
3732+
36033733 fn edit(&mut self, dirty: Dirty, f: impl FnOnce(&mut Project) -> bool) -> bool {
36043734 if !f(&mut self.project) {
36053735 return false;
crates/engine/src/project.rsmodified+242 -68
@@ -116,6 +116,7 @@ pub(crate) struct SweepParts(
116116 pub(crate) usize,
117117 pub(crate) Vec<(LaneKind, Vec<Clip>)>,
118118 pub(crate) Vec<Vec<SubClip>>,
119+ pub(crate) ProjectSettings,
119120 );
120121
121122 impl Speed {
@@ -881,11 +882,75 @@ pub type Parts = (
881882
882883 /// How many undo steps a project keeps. One gesture is one step, so 100 is past
883884 /// any chain a person walks back by hand, and the oldest step is dropped rather
884-/// than the history growing without end: a snapshot is the whole lane list, so
885-/// on a 1394-clip jumpcut timeline this is a bounded ~10 MB instead of a leak
886-/// that grows for as long as the session lasts.
885+/// than the history growing without end: a snapshot is the whole lane list plus
886+/// the palette and the project's own settings, so on a 1394-clip jumpcut
887+/// timeline this is a bounded ~10 MB instead of a leak that grows for as long
888+/// as the session lasts.
887889 const HISTORY_CAP: usize = 100;
888890
891+/// The project's own settings, as one value: the header a `.edith` file carries
892+/// beside the edit list, and what every undo step restores beside the lanes.
893+/// None of it is the media's own -- the scaffolding file's picture and rate
894+/// ([`PlaybackSession::native`]) stay on the session and are never rolled back.
895+#[derive(Clone, Debug, PartialEq)]
896+pub(crate) struct ProjectSettings {
897+ /// The canvas every clip is composed onto: the project resolution, which a
898+ /// clip of another size is placed onto rather than refused for.
899+ pub(crate) resolution: (u32, u32),
900+ /// The rate the timeline is cut at, which every clip and source is
901+ /// conformed to ([`Project::retime`]).
902+ pub(crate) frame_rate: f64,
903+ /// Which encoder an export of this project opens its picture on
904+ /// ([`crate::export::EncoderSeat`]).
905+ pub(crate) encoder_seat: crate::export::EncoderSeat,
906+ /// The rate the mix was picked to run at, or `None` for the one the first
907+ /// audio source derives.
908+ pub(crate) sample_rate: Option<u32>,
909+ /// Whether the picture is decoded from the stand-ins ([`crate::proxy`]).
910+ pub(crate) proxies: bool,
911+ /// Whether a source that wants a stand-in gets one made for it as it
912+ /// arrives ([`crate::proxy::wanted`]).
913+ pub(crate) auto_proxies: bool,
914+ /// Which HDR-to-SDR rendition the picture is watched and exported in.
915+ pub(crate) tone: crate::tonemap::Preset,
916+ /// The master limiter every lane's sound is summed through.
917+ pub(crate) limiter: Limiter,
918+}
919+
920+impl ProjectSettings {
921+ /// What a project built by hand carries before its constructor names the
922+ /// canvas: the defaults every fresh open has -- nobody has picked stand-ins
923+ /// (the films themselves are cut), an encoder or a mix rate, and the
924+ /// rendition and limiter are the reference ones. Every door that builds a
925+ /// session chains [`Project::with_canvas`] straight after, so the zero
926+ /// canvas here is never a project anybody plays from.
927+ fn placeholder() -> Self {
928+ Self {
929+ resolution: (0, 0),
930+ frame_rate: 0.0,
931+ encoder_seat: crate::export::EncoderSeat::default(),
932+ sample_rate: None,
933+ proxies: false,
934+ auto_proxies: true,
935+ tone: crate::tonemap::Preset::default(),
936+ limiter: Limiter::default(),
937+ }
938+ }
939+}
940+
941+/// One undo step: the lanes, the subtitle palette and the project's own
942+/// settings exactly as they were before the edit that pushed it. Whole values
943+/// rather than the lane list alone, so an undo (or a redo) restores all three
944+/// together and no half of one edit can come back without the others -- which
945+/// is what lets a subtitle removal reindex every placement and still undo: the
946+/// restored palette names the very tracks the restored placements index.
947+#[derive(Clone, Debug)]
948+struct Snapshot {
949+ lanes: Vec<LaneData>,
950+ subtitles: Vec<SubtitleTrack>,
951+ settings: ProjectSettings,
952+}
953+
889954 /// One gap a close-all sweep left open, with the frame it still starts on and
890955 /// the same refusal a single [`Project::gap_take_scope`] close would have said.
891956 #[derive(Clone, Debug, PartialEq, Eq)]
@@ -917,32 +982,31 @@ pub struct Project {
917982 /// The same, for [`Clip::transform`].
918983 transform: Vec<TransformParams>,
919984 /// Snapshots pushed *before* each successful edit; `undo` pops one. The
920- /// whole lane list, so adding a lane undoes as well. Bounded by
921- /// [`HISTORY_CAP`]: at the cap the oldest step goes.
922- history: Vec<Vec<LaneData>>,
923- /// Lane lists `undo` has stepped past; `redo` pops one. Cleared by
985+ /// whole lane list, the subtitle palette and the project's own settings,
986+ /// so adding a lane undoes as well and so does picking a resolution. Bounded
987+ /// by [`HISTORY_CAP`]: at the cap the oldest step goes.
988+ history: Vec<Snapshot>,
989+ /// Snapshots `undo` has stepped past; `redo` pops one. Cleared by
924990 /// [`Project::snapshot`], since a fresh edit invalidates whatever branch
925991 /// the undone steps came from. Not saved to `.edith`, matching `history`.
926- redo: Vec<Vec<LaneData>>,
992+ redo: Vec<Snapshot>,
927993 /// Never rolled back by an undo: an id retired by an undone split must not
928994 /// come back and group two clips that were never together.
929995 next_link: u32,
930996 /// The subtitle tracks this timeline shows, in the order they were added.
931- /// Not in the lane list and not in the history snapshots, for the reason
932- /// the limiter is not: which subtitles a project carries is a setting on
933- /// it, and it is saved as a *reference* to the file the cues came out of
934- /// ([`crate::subtitle`]).
997+ /// Saved as a *reference* to the file the cues came out of
998+ /// ([`crate::subtitle`]). In the history snapshots since the widened
999+ /// [`Snapshot`]: a placement names a track by index into this list, so a
1000+ /// removal that reindexes the placements can only undo together with the
1001+ /// palette it removed the row from.
9351002 subtitles: Vec<SubtitleTrack>,
936- /// The master limiter every lane's sound is summed *through*
937- /// ([`Project::limiter`]). Off by default, and not in the lane list, which
938- /// is what the history snapshots hold: it is a setting on the mix, like the
939- /// project's resolution is a setting on the picture, and neither is an undo
940- /// step.
941- limiter: Limiter,
942- /// Which HDR-to-SDR rendition every clip on an HDR curve is shown and
943- /// exported in ([`crate::tonemap::Preset`]). A setting on the picture, like
944- /// the resolution, and not in the lane snapshots for the same reason.
945- tone: crate::tonemap::Preset,
1003+ /// The project's own settings ([`ProjectSettings`]) -- the canvas, the
1004+ /// rate, the proxies switches, the encoder seat, the mix rate, the
1005+ /// rendition and the limiter. In every snapshot, so each of them undoes
1006+ /// like a lane edit: they are the header of the project's own `.edith`
1007+ /// file, not this machine's, and a pick a ctrl+z could not take back
1008+ /// would be the one setting with no way out.
1009+ settings: ProjectSettings,
9461010 }
9471011
9481012 impl Project {
@@ -980,8 +1044,7 @@ impl Project {
9801044 redo: Vec::new(),
9811045 next_link: 1,
9821046 subtitles: Vec::new(),
983- limiter: Limiter::default(),
984- tone: crate::tonemap::Preset::default(),
1047+ settings: ProjectSettings::placeholder(),
9851048 }
9861049 }
9871050
@@ -1124,8 +1187,7 @@ impl Project {
11241187 redo: Vec::new(),
11251188 next_link,
11261189 subtitles: Vec::new(),
1127- limiter: Limiter::default(),
1128- tone: crate::tonemap::Preset::default(),
1190+ settings: ProjectSettings::placeholder(),
11291191 })
11301192 }
11311193
@@ -1400,7 +1462,8 @@ impl Project {
14001462 /// different file. [`PlaybackSession::remove_source`] hands back the index
14011463 /// that went for exactly that.
14021464 ///
1403- /// corner-cut: this retires the undo stack. `history` holds lanes alone, so a
1465+ /// corner-cut: this retires the undo stack. `history` holds the lanes, the
1466+ /// subtitle palette and the project's own settings -- no source list -- so a
14041467 /// snapshot older than the removal can name the very source being removed
14051468 /// (delete a file's clips, then remove the file) and restoring it would
14061469 /// point a clip at an entry that is gone. The upgrade path is snapshotting
@@ -1679,14 +1742,44 @@ impl Project {
16791742 data.gain_db = db.clamp(MIN_GAIN_DB, MAX_GAIN_DB);
16801743 }
16811744 }
1682- self.limiter = limiter.with_ceiling(limiter.ceiling_db);
1745+ self.settings.limiter = limiter.with_ceiling(limiter.ceiling_db);
16831746 self
16841747 }
16851748
16861749 /// The HDR rendition a *load* puts back -- the same door
16871750 /// [`with_mix`](Project::with_mix) is, and no undo step for the same reason.
16881751 pub fn with_tone(mut self, preset: crate::tonemap::Preset) -> Self {
1689- self.tone = preset;
1752+ self.settings.tone = preset;
1753+ self
1754+ }
1755+
1756+ /// The canvas and rate a *load* or a fresh open names -- the project
1757+ /// resolution and the rate every clip is counted in. The same door
1758+ /// [`with_mix`](Project::with_mix) is, and no undo step for the same
1759+ /// reason: a project that arrives one undo away from a state it was never
1760+ /// in is a project whose first ctrl+z is a surprise.
1761+ pub fn with_canvas(mut self, width: u32, height: u32, frame_rate: f64) -> Self {
1762+ self.settings.resolution = (width, height);
1763+ self.settings.frame_rate = frame_rate;
1764+ self
1765+ }
1766+
1767+ /// The saved switches a *load* puts back: whether the picture is cut on
1768+ /// the stand-ins, whether new ones are made on arrival, which encoder an
1769+ /// export opens, and the rate the mix was picked to run at. The load half
1770+ /// of [`set_proxies`](Project::set_proxies) and its siblings, and no undo
1771+ /// step for [`with_mix`](Project::with_mix)'s reason.
1772+ pub fn with_switches(
1773+ mut self,
1774+ proxies: bool,
1775+ auto_proxies: bool,
1776+ encoder_seat: crate::export::EncoderSeat,
1777+ sample_rate: Option<u32>,
1778+ ) -> Self {
1779+ self.settings.proxies = proxies;
1780+ self.settings.auto_proxies = auto_proxies;
1781+ self.settings.encoder_seat = encoder_seat;
1782+ self.settings.sample_rate = sample_rate;
16901783 self
16911784 }
16921785
@@ -1694,21 +1787,18 @@ impl Project {
16941787 /// project setting, not a clip's: one picture, one look
16951788 /// ([`crate::tonemap::Preset`]).
16961789 pub fn tone(&self) -> crate::tonemap::Preset {
1697- self.tone
1790+ self.settings.tone
16981791 }
16991792
17001793 /// Sets it. `false` for the one already in force, which is what keeps a
1701- /// re-pick of the current rendition from costing a reseek.
1702- ///
1703- /// corner-cut: not an undo step, for the reason the limiter and the project
1704- /// resolution are not -- it is not in the lane list the history snapshots.
1705- /// Upgrade path is the same one: a history entry holding the project's own
1706- /// settings beside the lanes.
1794+ /// re-pick of the current rendition from costing a reseek. One undo step
1795+ /// like every other project-setting pick.
17071796 pub fn set_tone(&mut self, preset: crate::tonemap::Preset) -> bool {
1708- if self.tone == preset {
1797+ if self.settings.tone == preset {
17091798 return false;
17101799 }
1711- self.tone = preset;
1800+ self.snapshot();
1801+ self.settings.tone = preset;
17121802 true
17131803 }
17141804
@@ -1763,16 +1853,14 @@ impl Project {
17631853 /// [`remove_source`](Project::remove_source) refuses the same way for the
17641854 /// same silent corruption.
17651855 ///
1766- /// corner-cut: not an undo step, for the reason the limiter is not -- the
1767- /// history snapshots hold the lane list and subtitles are not on it
1768- /// ([`Project::subtitles`]). The inverse is putting the file's tracks back
1769- /// on -- [`crate::PlaybackSession::import_subtitles`], the panel's own
1770- /// door, which reads the subtitles of a file and nothing else -- and not a
1771- /// ctrl+z; the upgrade path is the same one the limiter has: a history
1772- /// entry holding the project's own settings beside the lanes. The history
1773- /// is *cleared* rather than kept, as a source removal clears it: the
1774- /// snapshots hold the indexes as they were before the reindex, so an undo
1775- /// into one would put every placement past `idx` on the wrong track.
1856+ /// One undo step, and the reindex with it: every placement names a track
1857+ /// by index into the palette ([`crate::subtitle`]), so a removal that
1858+ /// renumbers them can only come back together with the palette it took
1859+ /// the row from -- which is what the history entry holds, beside the
1860+ /// lanes it also carries ([`Snapshot`]). The inverse, for a caller that
1861+ /// wants the file's tracks back, is [`crate::PlaybackSession::import_subtitles`]
1862+ /// -- the panel's own door, which reads the subtitles of a file and
1863+ /// nothing else.
17761864 pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> {
17771865 if idx >= self.subtitles.len() {
17781866 return Err(format!("there is no subtitle track {idx} to remove").into());
@@ -1796,13 +1884,13 @@ impl Project {
17961884 )
17971885 .into());
17981886 }
1887+ self.snapshot();
17991888 self.subtitles.remove(idx);
18001889 for s in self.lanes.iter_mut().flat_map(|l| &mut l.subs) {
18011890 if s.track > idx {
18021891 s.track -= 1;
18031892 }
18041893 }
1805- self.history.clear();
18061894 Ok(())
18071895 }
18081896
@@ -2252,25 +2340,34 @@ impl Project {
22522340 /// The master limiter the mix is summed through. A project setting, not a
22532341 /// clip's and not a lane's: there is one mix.
22542342 pub fn limiter(&self) -> Limiter {
2255- self.limiter
2343+ self.settings.limiter
22562344 }
22572345
22582346 /// Sets it, with the ceiling clamped to what [`Limiter`] allows. `false`
2259- /// for a setting already in force.
2260- ///
2261- /// corner-cut: not an undo step, for the reason the project resolution is not
2262- /// one ([`crate::PlaybackSession::set_resolution`]) -- it is not in the
2263- /// lane list the history snapshots. Upgrade path is a history entry that
2264- /// holds the mix settings beside the lanes.
2347+ /// for a setting already in force. One undo step like every other
2348+ /// project-setting pick.
22652349 pub fn set_limiter(&mut self, limiter: Limiter) -> bool {
22662350 let limiter = limiter.with_ceiling(limiter.ceiling_db);
2267- if self.limiter == limiter {
2351+ if self.settings.limiter == limiter {
22682352 return false;
22692353 }
2270- self.limiter = limiter;
2354+ self.snapshot();
2355+ self.settings.limiter = limiter;
22712356 true
22722357 }
22732358
2359+
2360+
2361+
2362+
2363+
2364+
2365+
2366+
2367+
2368+
2369+
2370+
22742371 /// What the clip at `idx` of `lane` plays through, or `None` for one that
22752372 /// plays flat (and for an index that is not there) -- what a feeder and an
22762373 /// export ask before they build an [`crate::eq::EqState`].
@@ -4948,6 +5045,36 @@ impl Project {
49485045 self.redo.len()
49495046 }
49505047
5048+ /// The project's own settings as they stand ([`ProjectSettings`]) -- what an
5049+ /// undo entry holds beside the lanes, and what the session reads back after
5050+ /// one is restored ([`crate::PlaybackSession::undo`]).
5051+ pub(crate) fn settings_now(&self) -> ProjectSettings {
5052+ self.settings.clone()
5053+ }
5054+
5055+ /// One undo step for a change to the project's own settings: `from` is the
5056+ /// state the change is from and `now` the one it leaves behind. The entry
5057+ /// pushed holds `from`, while the copy kept here is `now` -- so the next
5058+ /// lane edit's own entry carries the canvas and the rate really in force
5059+ /// rather than the ones before the pick. The lanes the entry holds are the
5060+ /// ones in place at the call: a settings door leaves them alone and may
5061+ /// take this step after its change, and one that moves them
5062+ /// ([`Project::retime`] on a rate change) takes it before, with `now` equal
5063+ /// to `from`, mirroring the new state afterwards
5064+ /// ([`Project::mirror_settings`]).
5065+ pub(crate) fn push_settings_step(&mut self, from: ProjectSettings, now: ProjectSettings) {
5066+ self.settings = from;
5067+ self.snapshot();
5068+ self.settings = now;
5069+ }
5070+
5071+ /// Keeps `now` as this project's copy of its own settings, without a step:
5072+ /// the second half of a settings door that had to take its step before the
5073+ /// change.
5074+ pub(crate) fn mirror_settings(&mut self, now: ProjectSettings) {
5075+ self.settings = now;
5076+ }
5077+
49515078 /// Every part of the project that an edit can change, as comparable
49525079 /// values: what the sweep's undo round-trip asks "byte identical?" of.
49535080 #[cfg(test)]
@@ -4956,31 +5083,44 @@ impl Project {
49565083 self.sources.len(),
49575084 self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(),
49585085 self.lanes.iter().map(|l| l.subs.clone()).collect(),
5086+ self.settings.clone(),
49595087 )
49605088 }
49615089
4962- /// Restore every lane from before the last successful edit -- the clips and
4963- /// the lane list both. `false` when there is nothing left to undo. Pushes
4964- /// the lanes just left onto the redo stack, so [`Project::redo`] can walk
4965- /// forward again.
5090+ /// Restore everything from before the last successful edit -- the lanes,
5091+ /// the subtitle palette and the project's own settings. `false` when there
5092+ /// is nothing left to undo. Pushes what was just left onto the redo stack,
5093+ /// so [`Project::redo`] can walk forward again.
49665094 pub fn undo(&mut self) -> bool {
49675095 match self.history.pop() {
49685096 Some(prev) => {
4969- self.redo.push(std::mem::replace(&mut self.lanes, prev));
5097+ self.redo.push(Snapshot {
5098+ lanes: std::mem::replace(&mut self.lanes, prev.lanes),
5099+ subtitles: self.subtitles.clone(),
5100+ settings: self.settings.clone(),
5101+ });
5102+ self.subtitles = prev.subtitles;
5103+ self.settings = prev.settings;
49705104 true
49715105 }
49725106 None => false,
49735107 }
49745108 }
49755109
4976- /// Restore every lane from before the last [`Project::undo`] -- the
5110+ /// Restore everything from before the last [`Project::undo`] -- the
49775111 /// mirror of `undo`, walking the redo stack it fills. `false` when there
49785112 /// is nothing left to redo, which is also true after any fresh edit: a
49795113 /// new [`Project::snapshot`] clears the branch `undo` left behind.
49805114 pub fn redo(&mut self) -> bool {
49815115 match self.redo.pop() {
49825116 Some(next) => {
4983- self.history.push(std::mem::replace(&mut self.lanes, next));
5117+ self.history.push(Snapshot {
5118+ lanes: std::mem::replace(&mut self.lanes, next.lanes),
5119+ subtitles: self.subtitles.clone(),
5120+ settings: self.settings.clone(),
5121+ });
5122+ self.subtitles = next.subtitles;
5123+ self.settings = next.settings;
49845124 true
49855125 }
49865126 None => false,
@@ -5002,8 +5142,7 @@ impl Project {
50025142 redo: Vec::new(),
50035143 next_link: self.next_link,
50045144 subtitles: self.subtitles.clone(),
5005- limiter: self.limiter,
5006- tone: self.tone,
5145+ settings: self.settings.clone(),
50075146 }
50085147 }
50095148
@@ -5216,7 +5355,11 @@ impl Project {
52165355 if self.history.len() == HISTORY_CAP {
52175356 self.history.remove(0);
52185357 }
5219- self.history.push(self.lanes.clone());
5358+ self.history.push(Snapshot {
5359+ lanes: self.lanes.clone(),
5360+ subtitles: self.subtitles.clone(),
5361+ settings: self.settings.clone(),
5362+ });
52205363 self.redo.clear();
52215364 }
52225365
@@ -10405,4 +10548,35 @@ mod tests {
1040510548 .expect("valid parts");
1040610549 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);
1040710550 }
10551+
10552+/// D4: removing a subtitle column used to clear the whole undo history,
10553+/// because a placement names its track by index into the palette and the
10554+/// reindex left every later entry naming the wrong one. The entry holds the
10555+/// palette beside the lanes now, so the reindex undoes with it.
10556+#[test]
10557+fn removing_a_subtitle_column_undoes_with_its_reindex() {
10558+ let track = |label: &str| SubtitleTrack {
10559+ path: FILE.into(),
10560+ track: None,
10561+ language: "eng".into(),
10562+ name: String::new(),
10563+ label: label.into(),
10564+ cues: Vec::new(),
10565+ bitmap: false,
10566+ refused: None,
10567+ };
10568+ let mut p = Project::single(FILE, 300)
10569+ .with_subtitles(vec![track("one"), track("two"), track("three")]);
10570+ assert_eq!(p.subtitles().len(), 3);
10571+ let before = p.parts();
10572+ // Column 0 goes, which renumbers the two behind it.
10573+ p.remove_subtitles(0).expect("a column with nothing on it");
10574+ assert_eq!(p.subtitles().len(), 2);
10575+ assert_eq!(p.subtitles()[0].label, "two");
10576+ assert!(p.undo(), "the removal is a step like any other cut");
10577+ assert_eq!(p.parts(), before, "the palette and the lanes, both back");
10578+ assert!(p.redo(), "and forward again");
10579+ assert_eq!(p.subtitles()[0].label, "two");
10580+}
10581+
1040810582 }