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};
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};
@@ -1164,7 +1164,18 @@ impl PlaybackSession {
1164 // it, and [`Project::with_subs`] refuses one naming a row that is1164 // it, and [`Project::with_subs`] refuses one naming a row that is
1165 // not there.1165 // not there.
1166 .with_subtitles(subtitles)1166 .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);
1168 let span = project.composite_span_at(0);1179 let span = project.composite_span_at(0);
1169 // Last, because it is the one thing here that cannot be taken back: the1180 // Last, because it is the one thing here that cannot be taken back: the
1170 // feeder thread outlives the `Audio` value (it holds its own clones) and1181 // feeder thread outlives the `Audio` value (it holds its own clones) and
@@ -2734,11 +2745,17 @@ impl PlaybackSession {
2734 /// Says nothing about *which* films have one: a source with no stand-in2745 /// Says nothing about *which* films have one: a source with no stand-in
2735 /// keeps playing its own pictures either way, and one made while this is on2746 /// keeps playing its own pictures either way, and one made while this is on
2736 /// is picked up at the next seek.2747 /// 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.
2737 pub fn set_proxies(&mut self, on: bool) {2752 pub fn set_proxies(&mut self, on: bool) {
2738 if self.proxies == on {2753 if self.proxies == on {
2739 return;2754 return;
2740 }2755 }
2756+ let from = self.settings_value();
2741 self.proxies = on;2757 self.proxies = on;
2758+ self.step_settings(from);
2742 let now = self.now();2759 let now = self.now();
2743 self.seek(now);2760 self.seek(now);
2744 }2761 }
@@ -2753,9 +2770,15 @@ impl PlaybackSession {
2753 }2770 }
2754 2771
2755 /// Pick the seat. Nothing to reseek and nothing to re-probe here: this2772 /// 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.
2757 pub fn set_encoder_seat(&mut self, seat: crate::export::EncoderSeat) {2775 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();
2758 self.encoder_seat = seat;2780 self.encoder_seat = seat;
2781+ self.step_settings(from);
2759 }2782 }
2760 2783
2761 /// The rate this project's mix was picked to run at2784 /// The rate this project's mix was picked to run at
@@ -2767,9 +2790,15 @@ impl PlaybackSession {
2767 2790
2768 /// Pick the mix's own rate, overriding the derived one. Nothing to reseek2791 /// Pick the mix's own rate, overriding the derived one. Nothing to reseek
2769 /// here: it takes effect at the next audio rebuild (a seek, an edit, a2792 /// 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.
2771 pub fn set_sample_rate(&mut self, rate: Option<u32>) {2795 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();
2772 self.sample_rate = rate;2800 self.sample_rate = rate;
2801+ self.step_settings(from);
2773 }2802 }
2774 2803
2775 /// Whether an imported film that wants a stand-in gets one made for it2804 /// Whether an imported film that wants a stand-in gets one made for it
@@ -2781,8 +2810,15 @@ impl PlaybackSession {
2781 /// Make the stand-ins on import, or make none until asked. Nothing to2810 /// Make the stand-ins on import, or make none until asked. Nothing to
2782 /// reseek: this decides what is *started*, never what is decoded -- a proxy2811 /// reseek: this decides what is *started*, never what is decoded -- a proxy
2783 /// already in the cache is still cut on while [`Self::proxies`] is on.2812 /// 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.
2784 pub fn set_auto_proxies(&mut self, on: bool) {2815 pub fn set_auto_proxies(&mut self, on: bool) {
2816+ if self.auto_proxies == on {
2817+ return;
2818+ }
2819+ let from = self.settings_value();
2785 self.auto_proxies = on;2820 self.auto_proxies = on;
2821+ self.step_settings(from);
2786 }2822 }
2787 2823
2788 /// Which source `path` is, canonicalising only if it has to: a source's own2824 /// Which source `path` is, canonicalising only if it has to: a source's own
@@ -2913,10 +2949,9 @@ impl PlaybackSession {
2913 /// that is not a picture -- zero either way, or past 8K, which is where the2949 /// that is not a picture -- zero either way, or past 8K, which is where the
2914 /// per-frame buffers stop being a sane thing to allocate from a keystroke.2950 /// per-frame buffers stop being a sane thing to allocate from a keystroke.
2915 ///2951 ///
2916- /// corner-cut: not an undo step. The project resolution is not in the lane2952+ /// One undo step: the resolution is the project's own, so it rides in the
2917- /// snapshots [`Project::undo`] restores, so cycling it back is one more2953+ /// entry beside the lanes and a `z` takes the canvas back to the size it
2918- /// keypress rather than a `z`. Upgrade path is snapshotting it beside the2954+ /// was ([`Project::push_settings_step`]).
2919- /// lanes, which every existing snapshot site would then have to carry.
2920 pub fn set_resolution(&mut self, width: u32, height: u32) -> bool {2955 pub fn set_resolution(&mut self, width: u32, height: u32) -> bool {
2921 if !crate::is_resolution(width, height) {2956 if !crate::is_resolution(width, height) {
2922 return false;2957 return false;
@@ -2924,8 +2959,10 @@ impl PlaybackSession {
2924 if (width, height) == (self.meta.width, self.meta.height) {2959 if (width, height) == (self.meta.width, self.meta.height) {
2925 return false;2960 return false;
2926 }2961 }
2962+ let from = self.settings_value();
2927 self.meta.width = width;2963 self.meta.width = width;
2928 self.meta.height = height;2964 self.meta.height = height;
2965+ self.step_settings(from);
2929 self.invalidate(Dirty::Picture);2966 self.invalidate(Dirty::Picture);
2930 true2967 true
2931 }2968 }
@@ -2987,12 +3024,15 @@ impl PlaybackSession {
2987 /// ([`crate::mux::frame_timing`], the same wall a file of an unnameable rate3024 /// ([`crate::mux::frame_timing`], the same wall a file of an unnameable rate
2988 /// is refused at).3025 /// is refused at).
2989 ///3026 ///
2990- /// corner-cut: not an undo step, exactly as the project resolution is not --3027+ /// One undo step, and the entry it takes is the whole of the change: the
2991- /// and this one *moves the frame numbers*, so the way back is picking the3028+ /// lanes as they were in the *old* rate's numbering, with that rate beside
2992- /// old rate (or the media's, [`native_frame_rate`](Self::native_frame_rate))3029+ /// them, so a `z` restores the two together ([`Project::retime`]). The
2993- /// rather than a `z`, and it lands within a frame of where it started rather3030+ /// step is taken before the retime rather than after, since this is the one
2994- /// than on it (see [`Project::retime`]). Upgrade path is the same one: the3031+ /// settings door that moves the lanes the step holds. Picking the old rate
2995- /// project's settings snapshotted beside the lanes.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`]).
2996 pub fn set_frame_rate(&mut self, fps: f64) -> bool {3036 pub fn set_frame_rate(&mut self, fps: f64) -> bool {
2997 if !fps.is_finite() || fps <= 0.0 || fps == self.meta.frame_rate {3037 if !fps.is_finite() || fps <= 0.0 || fps == self.meta.frame_rate {
2998 return false;3038 return false;
@@ -3004,6 +3044,8 @@ impl PlaybackSession {
3004 let Ok(k) = Rate::from_fps(self.meta.frame_rate, fps) else {3044 let Ok(k) = Rate::from_fps(self.meta.frame_rate, fps) else {
3005 return false;3045 return false;
3006 };3046 };
3047+ let from = self.settings_value();
3048+ self.project.push_settings_step(from.clone(), from);
3007 // Lengths first: the retime holds every clip inside its source's *new*3049 // Lengths first: the retime holds every clip inside its source's *new*
3008 // length, so a clip that played to the last frame of its file still3050 // length, so a clip that played to the last frame of its file still
3009 // does rather than naming one past the end.3051 // does rather than naming one past the end.
@@ -3017,6 +3059,9 @@ impl PlaybackSession {
3017 }3059 }
3018 self.meta.frame_rate = fps;3060 self.meta.frame_rate = fps;
3019 self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1);3061 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());
3020 let now = self.now();3065 let now = self.now();
3021 self.seek(now);3066 self.seek(now);
3022 true3067 true
@@ -3425,15 +3470,19 @@ impl PlaybackSession {
3425 self.edit(Dirty::Both, |p| p.delete_in(lane, idx))3470 self.edit(Dirty::Both, |p| p.delete_in(lane, idx))
3426 }3471 }
3427 3472
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.
3429 pub fn undo(&mut self) -> bool {3478 pub fn undo(&mut self) -> bool {
3430- self.edit(Dirty::Both, Project::undo)3479+ self.restored_step(Project::undo)
3431 }3480 }
3432 3481
3433 /// Redoes the last edit [`undo`](Self::undo) took back, and reseeks like3482 /// 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.
3435 pub fn redo(&mut self) -> bool {3484 pub fn redo(&mut self) -> bool {
3436- self.edit(Dirty::Both, Project::redo)3485+ self.restored_step(Project::redo)
3437 }3486 }
3438 3487
3439 /// Takes `path` into the **library**: it becomes a source of this session,3488 /// Takes `path` into the **library**: it becomes a source of this session,
@@ -3600,6 +3649,87 @@ impl PlaybackSession {
3600 /// policy rebuilds the picture where it stands, with the sound running3649 /// policy rebuilds the picture where it stands, with the sound running
3601 /// through it untouched -- no flush, no re-open, no hole -- and an3650 /// through it untouched -- no flush, no re-open, no hole -- and an
3602 /// equalizer the other way round.3651 /// 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+
3603 fn edit(&mut self, dirty: Dirty, f: impl FnOnce(&mut Project) -> bool) -> bool {3733 fn edit(&mut self, dirty: Dirty, f: impl FnOnce(&mut Project) -> bool) -> bool {
3604 if !f(&mut self.project) {3734 if !f(&mut self.project) {
3605 return false;3735 return false;
crates/engine/src/project.rsmodified+242 -68
@@ -116,6 +116,7 @@ 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+ pub(crate) ProjectSettings,
119 );120 );
120 121
121 impl Speed {122 impl Speed {
@@ -881,11 +882,75 @@ pub type Parts = (
881 882
882 /// How many undo steps a project keeps. One gesture is one step, so 100 is past883 /// 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 rather884 /// 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, so885+/// 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 leak886+/// the palette and the project's own settings, so on a 1394-clip jumpcut
886-/// that grows for as long as the session lasts.887+/// timeline this is a bounded ~10 MB instead of a leak that grows for as long
888+/// as the session lasts.
887 const HISTORY_CAP: usize = 100;889 const HISTORY_CAP: usize = 100;
888 890
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+
889 /// One gap a close-all sweep left open, with the frame it still starts on and954 /// 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.955 /// the same refusal a single [`Project::gap_take_scope`] close would have said.
891 #[derive(Clone, Debug, PartialEq, Eq)]956 #[derive(Clone, Debug, PartialEq, Eq)]
@@ -917,32 +982,31 @@ pub struct Project {
917 /// The same, for [`Clip::transform`].982 /// The same, for [`Clip::transform`].
918 transform: Vec<TransformParams>,983 transform: Vec<TransformParams>,
919 /// Snapshots pushed *before* each successful edit; `undo` pops one. The984 /// Snapshots pushed *before* each successful edit; `undo` pops one. The
920- /// whole lane list, so adding a lane undoes as well. Bounded by985+ /// whole lane list, the subtitle palette and the project's own settings,
921- /// [`HISTORY_CAP`]: at the cap the oldest step goes.986+ /// so adding a lane undoes as well and so does picking a resolution. Bounded
922- history: Vec<Vec<LaneData>>,987+ /// by [`HISTORY_CAP`]: at the cap the oldest step goes.
923- /// Lane lists `undo` has stepped past; `redo` pops one. Cleared by988+ history: Vec<Snapshot>,
989+ /// Snapshots `undo` has stepped past; `redo` pops one. Cleared by
924 /// [`Project::snapshot`], since a fresh edit invalidates whatever branch990 /// [`Project::snapshot`], since a fresh edit invalidates whatever branch
925 /// the undone steps came from. Not saved to `.edith`, matching `history`.991 /// the undone steps came from. Not saved to `.edith`, matching `history`.
926- redo: Vec<Vec<LaneData>>,992+ redo: Vec<Snapshot>,
927 /// Never rolled back by an undo: an id retired by an undone split must not993 /// 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.994 /// come back and group two clips that were never together.
929 next_link: u32,995 next_link: u32,
930 /// The subtitle tracks this timeline shows, in the order they were added.996 /// 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 reason997+ /// 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 on998+ /// ([`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 of999+ /// [`Snapshot`]: a placement names a track by index into this list, so a
934- /// ([`crate::subtitle`]).1000+ /// removal that reindexes the placements can only undo together with the
1001+ /// palette it removed the row from.
935 subtitles: Vec<SubtitleTrack>,1002 subtitles: Vec<SubtitleTrack>,
936- /// The master limiter every lane's sound is summed *through*1003+ /// The project's own settings ([`ProjectSettings`]) -- the canvas, the
937- /// ([`Project::limiter`]). Off by default, and not in the lane list, which1004+ /// 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 the1005+ /// 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 undo1006+ /// like a lane edit: they are the header of the project's own `.edith`
940- /// step.1007+ /// file, not this machine's, and a pick a ctrl+z could not take back
941- limiter: Limiter,1008+ /// would be the one setting with no way out.
942- /// Which HDR-to-SDR rendition every clip on an HDR curve is shown and1009+ 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 }1010 }
947 1011
948 impl Project {1012 impl Project {
@@ -980,8 +1044,7 @@ impl Project {
980 redo: Vec::new(),1044 redo: Vec::new(),
981 next_link: 1,1045 next_link: 1,
982 subtitles: Vec::new(),1046 subtitles: Vec::new(),
983- limiter: Limiter::default(),1047+ settings: ProjectSettings::placeholder(),
984- tone: crate::tonemap::Preset::default(),
985 }1048 }
986 }1049 }
987 1050
@@ -1124,8 +1187,7 @@ impl Project {
1124 redo: Vec::new(),1187 redo: Vec::new(),
1125 next_link,1188 next_link,
1126 subtitles: Vec::new(),1189 subtitles: Vec::new(),
1127- limiter: Limiter::default(),1190+ settings: ProjectSettings::placeholder(),
1128- tone: crate::tonemap::Preset::default(),
1129 })1191 })
1130 }1192 }
1131 1193
@@ -1400,7 +1462,8 @@ impl Project {
1400 /// different file. [`PlaybackSession::remove_source`] hands back the index1462 /// different file. [`PlaybackSession::remove_source`] hands back the index
1401 /// that went for exactly that.1463 /// that went for exactly that.
1402 ///1464 ///
1403- /// corner-cut: this retires the undo stack. `history` holds lanes alone, so a1465+ /// 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
1404 /// snapshot older than the removal can name the very source being removed1467 /// 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 would1468 /// (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 snapshotting1469 /// point a clip at an entry that is gone. The upgrade path is snapshotting
@@ -1679,14 +1742,44 @@ impl Project {
1679 data.gain_db = db.clamp(MIN_GAIN_DB, MAX_GAIN_DB);1742 data.gain_db = db.clamp(MIN_GAIN_DB, MAX_GAIN_DB);
1680 }1743 }
1681 }1744 }
1682- self.limiter = limiter.with_ceiling(limiter.ceiling_db);1745+ self.settings.limiter = limiter.with_ceiling(limiter.ceiling_db);
1683 self1746 self
1684 }1747 }
1685 1748
1686 /// The HDR rendition a *load* puts back -- the same door1749 /// 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.1750 /// [`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 {1751 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;
1690 self1783 self
1691 }1784 }
1692 1785
@@ -1694,21 +1787,18 @@ impl Project {
1694 /// project setting, not a clip's: one picture, one look1787 /// project setting, not a clip's: one picture, one look
1695 /// ([`crate::tonemap::Preset`]).1788 /// ([`crate::tonemap::Preset`]).
1696 pub fn tone(&self) -> crate::tonemap::Preset {1789 pub fn tone(&self) -> crate::tonemap::Preset {
1697- self.tone1790+ self.settings.tone
1698 }1791 }
1699 1792
1700 /// Sets it. `false` for the one already in force, which is what keeps a1793 /// 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.1794+ /// re-pick of the current rendition from costing a reseek. One undo step
1702- ///1795+ /// 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 {1796 pub fn set_tone(&mut self, preset: crate::tonemap::Preset) -> bool {
1708- if self.tone == preset {1797+ if self.settings.tone == preset {
1709 return false;1798 return false;
1710 }1799 }
1711- self.tone = preset;1800+ self.snapshot();
1801+ self.settings.tone = preset;
1712 true1802 true
1713 }1803 }
1714 1804
@@ -1763,16 +1853,14 @@ impl Project {
1763 /// [`remove_source`](Project::remove_source) refuses the same way for the1853 /// [`remove_source`](Project::remove_source) refuses the same way for the
1764 /// same silent corruption.1854 /// same silent corruption.
1765 ///1855 ///
1766- /// corner-cut: not an undo step, for the reason the limiter is not -- the1856+ /// 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 it1857+ /// by index into the palette ([`crate::subtitle`]), so a removal that
1768- /// ([`Project::subtitles`]). The inverse is putting the file's tracks back1858+ /// renumbers them can only come back together with the palette it took
1769- /// on -- [`crate::PlaybackSession::import_subtitles`], the panel's own1859+ /// 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 a1860+ /// 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 history1861+ /// wants the file's tracks back, is [`crate::PlaybackSession::import_subtitles`]
1772- /// entry holding the project's own settings beside the lanes. The history1862+ /// -- 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: the1863+ /// 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<()> {1864 pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> {
1777 if idx >= self.subtitles.len() {1865 if idx >= self.subtitles.len() {
1778 return Err(format!("there is no subtitle track {idx} to remove").into());1866 return Err(format!("there is no subtitle track {idx} to remove").into());
@@ -1796,13 +1884,13 @@ impl Project {
1796 )1884 )
1797 .into());1885 .into());
1798 }1886 }
1887+ self.snapshot();
1799 self.subtitles.remove(idx);1888 self.subtitles.remove(idx);
1800 for s in self.lanes.iter_mut().flat_map(|l| &mut l.subs) {1889 for s in self.lanes.iter_mut().flat_map(|l| &mut l.subs) {
1801 if s.track > idx {1890 if s.track > idx {
1802 s.track -= 1;1891 s.track -= 1;
1803 }1892 }
1804 }1893 }
1805- self.history.clear();
1806 Ok(())1894 Ok(())
1807 }1895 }
1808 1896
@@ -2252,25 +2340,34 @@ impl Project {
2252 /// The master limiter the mix is summed through. A project setting, not a2340 /// 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.2341 /// clip's and not a lane's: there is one mix.
2254 pub fn limiter(&self) -> Limiter {2342 pub fn limiter(&self) -> Limiter {
2255- self.limiter2343+ self.settings.limiter
2256 }2344 }
2257 2345
2258 /// Sets it, with the ceiling clamped to what [`Limiter`] allows. `false`2346 /// Sets it, with the ceiling clamped to what [`Limiter`] allows. `false`
2259- /// for a setting already in force.2347+ /// for a setting already in force. One undo step like every other
2260- ///2348+ /// 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 {2349 pub fn set_limiter(&mut self, limiter: Limiter) -> bool {
2266 let limiter = limiter.with_ceiling(limiter.ceiling_db);2350 let limiter = limiter.with_ceiling(limiter.ceiling_db);
2267- if self.limiter == limiter {2351+ if self.settings.limiter == limiter {
2268 return false;2352 return false;
2269 }2353 }
2270- self.limiter = limiter;2354+ self.snapshot();
2355+ self.settings.limiter = limiter;
2271 true2356 true
2272 }2357 }
2273 2358
2359+
2360+
2361+
2362+
2363+
2364+
2365+
2366+
2367+
2368+
2369+
2370+
2274 /// What the clip at `idx` of `lane` plays through, or `None` for one that2371 /// 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 an2372 /// 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`].2373 /// export ask before they build an [`crate::eq::EqState`].
@@ -4948,6 +5045,36 @@ impl Project {
4948 self.redo.len()5045 self.redo.len()
4949 }5046 }
4950 5047
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+
4951 /// Every part of the project that an edit can change, as comparable5078 /// 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.5079 /// values: what the sweep's undo round-trip asks "byte identical?" of.
4953 #[cfg(test)]5080 #[cfg(test)]
@@ -4956,31 +5083,44 @@ impl Project {
4956 self.sources.len(),5083 self.sources.len(),
4957 self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(),5084 self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(),
4958 self.lanes.iter().map(|l| l.subs.clone()).collect(),5085 self.lanes.iter().map(|l| l.subs.clone()).collect(),
5086+ self.settings.clone(),
4959 )5087 )
4960 }5088 }
4961 5089
4962- /// Restore every lane from before the last successful edit -- the clips and5090+ /// Restore everything from before the last successful edit -- the lanes,
4963- /// the lane list both. `false` when there is nothing left to undo. Pushes5091+ /// 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 walk5092+ /// is nothing left to undo. Pushes what was just left onto the redo stack,
4965- /// forward again.5093+ /// so [`Project::redo`] can walk forward again.
4966 pub fn undo(&mut self) -> bool {5094 pub fn undo(&mut self) -> bool {
4967 match self.history.pop() {5095 match self.history.pop() {
4968 Some(prev) => {5096 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;
4970 true5104 true
4971 }5105 }
4972 None => false,5106 None => false,
4973 }5107 }
4974 }5108 }
4975 5109
4976- /// Restore every lane from before the last [`Project::undo`] -- the5110+ /// Restore everything from before the last [`Project::undo`] -- the
4977 /// mirror of `undo`, walking the redo stack it fills. `false` when there5111 /// 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: a5112 /// is nothing left to redo, which is also true after any fresh edit: a
4979 /// new [`Project::snapshot`] clears the branch `undo` left behind.5113 /// new [`Project::snapshot`] clears the branch `undo` left behind.
4980 pub fn redo(&mut self) -> bool {5114 pub fn redo(&mut self) -> bool {
4981 match self.redo.pop() {5115 match self.redo.pop() {
4982 Some(next) => {5116 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;
4984 true5124 true
4985 }5125 }
4986 None => false,5126 None => false,
@@ -5002,8 +5142,7 @@ impl Project {
5002 redo: Vec::new(),5142 redo: Vec::new(),
5003 next_link: self.next_link,5143 next_link: self.next_link,
5004 subtitles: self.subtitles.clone(),5144 subtitles: self.subtitles.clone(),
5005- limiter: self.limiter,5145+ settings: self.settings.clone(),
5006- tone: self.tone,
5007 }5146 }
5008 }5147 }
5009 5148
@@ -5216,7 +5355,11 @@ impl Project {
5216 if self.history.len() == HISTORY_CAP {5355 if self.history.len() == HISTORY_CAP {
5217 self.history.remove(0);5356 self.history.remove(0);
5218 }5357 }
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+ });
5220 self.redo.clear();5363 self.redo.clear();
5221 }5364 }
5222 5365
@@ -10405,4 +10548,35 @@ mod tests {
10405 .expect("valid parts");10548 .expect("valid parts");
10406 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);10549 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);
10407 }10550 }
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+
10408 }10582 }