From 2d2933c691612bda34abd1dd4d70a6a123a14832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 24 Sep 2026 13:40:40 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(project,playback):=20the=20s?= =?UTF-8?q?ettings=20and=20the=20subtitle=20palette=20ride=20in=20the=20hi?= =?UTF-8?q?story=20entry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.rs | 166 ++++++++++++++++-- crates/engine/src/project.rs | 310 ++++++++++++++++++++++++++-------- 2 files changed, 390 insertions(+), 86 deletions(-) diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index be6c899..eaabd46 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -26,7 +26,7 @@ use crate::colorspace::{ColorDescription, ContentLight}; use crate::decode::{Backend, BackendCell, DecodeSession, Frame, Worker}; use crate::demux::{Codec, Demuxer, NoVideoTrack, Rotation, VideoMeta}; use crate::eq::EqParams; -use crate::project::{ +use crate::project::{ProjectSettings, Clip, Edge, GapSweep, Lane, LaneKind, Project, Rate, Source, Span, Speed, SubClip, }; use crate::scale::{Composer, FitPolicy}; @@ -1164,7 +1164,18 @@ impl PlaybackSession { // it, and [`Project::with_subs`] refuses one naming a row that is // not there. .with_subtitles(subtitles) - .with_subs(doc.subs)?; + .with_subs(doc.subs)? + // The header a load puts back: the canvas and rate above, which a + // save's own `resolution`/`fps` lines may have moved off the + // scaffold's, and the switches the literal below carries -- handed + // in here because they are the project's own and a door that moved + // one after this would snapshot whatever copy it holds, which until + // this line is the placeholder's. No undo step for + // [`Project::with_mix`]'s reason: a project that arrived one `z` + // from a state it was never in is a project whose first undo is a + // surprise. + .with_canvas(meta.width, meta.height, meta.frame_rate) + .with_switches(doc.proxy, doc.auto_proxy, doc.encoder, doc.sample_rate); let span = project.composite_span_at(0); // Last, because it is the one thing here that cannot be taken back: the // feeder thread outlives the `Audio` value (it holds its own clones) and @@ -2734,11 +2745,17 @@ impl PlaybackSession { /// Says nothing about *which* films have one: a source with no stand-in /// keeps playing its own pictures either way, and one made while this is on /// is picked up at the next seek. + /// + /// One undo step ([`Project::push_settings_step`]), and the seek below is + /// what makes the undo of it land on the picture: it reopens the span + /// through [`picture_path`](Self::picture_path), which reads this switch. pub fn set_proxies(&mut self, on: bool) { if self.proxies == on { return; } + let from = self.settings_value(); self.proxies = on; + self.step_settings(from); let now = self.now(); self.seek(now); } @@ -2753,9 +2770,15 @@ impl PlaybackSession { } /// Pick the seat. Nothing to reseek and nothing to re-probe here: this - /// decides what an *export* opens, never what plays. + /// decides what an *export* opens, never what plays. One undo step, like + /// every other pick on the project. pub fn set_encoder_seat(&mut self, seat: crate::export::EncoderSeat) { + if self.encoder_seat == seat { + return; + } + let from = self.settings_value(); self.encoder_seat = seat; + self.step_settings(from); } /// The rate this project's mix was picked to run at @@ -2767,9 +2790,15 @@ impl PlaybackSession { /// Pick the mix's own rate, overriding the derived one. Nothing to reseek /// here: it takes effect at the next audio rebuild (a seek, an edit, a - /// reopen), not on the device already playing. + /// reopen), not on the device already playing. One undo step, like every + /// other pick on the project. pub fn set_sample_rate(&mut self, rate: Option) { + if self.sample_rate == rate { + return; + } + let from = self.settings_value(); self.sample_rate = rate; + self.step_settings(from); } /// Whether an imported film that wants a stand-in gets one made for it @@ -2781,8 +2810,15 @@ impl PlaybackSession { /// Make the stand-ins on import, or make none until asked. Nothing to /// reseek: this decides what is *started*, never what is decoded -- a proxy /// already in the cache is still cut on while [`Self::proxies`] is on. + /// + /// One undo step, like every other switch on the project. pub fn set_auto_proxies(&mut self, on: bool) { + if self.auto_proxies == on { + return; + } + let from = self.settings_value(); self.auto_proxies = on; + self.step_settings(from); } /// Which source `path` is, canonicalising only if it has to: a source's own @@ -2913,10 +2949,9 @@ impl PlaybackSession { /// that is not a picture -- zero either way, or past 8K, which is where the /// per-frame buffers stop being a sane thing to allocate from a keystroke. /// - /// corner-cut: not an undo step. The project resolution is not in the lane - /// snapshots [`Project::undo`] restores, so cycling it back is one more - /// keypress rather than a `z`. Upgrade path is snapshotting it beside the - /// lanes, which every existing snapshot site would then have to carry. + /// One undo step: the resolution is the project's own, so it rides in the + /// entry beside the lanes and a `z` takes the canvas back to the size it + /// was ([`Project::push_settings_step`]). pub fn set_resolution(&mut self, width: u32, height: u32) -> bool { if !crate::is_resolution(width, height) { return false; @@ -2924,8 +2959,10 @@ impl PlaybackSession { if (width, height) == (self.meta.width, self.meta.height) { return false; } + let from = self.settings_value(); self.meta.width = width; self.meta.height = height; + self.step_settings(from); self.invalidate(Dirty::Picture); true } @@ -2987,12 +3024,15 @@ impl PlaybackSession { /// ([`crate::mux::frame_timing`], the same wall a file of an unnameable rate /// is refused at). /// - /// corner-cut: not an undo step, exactly as the project resolution is not -- - /// and this one *moves the frame numbers*, so the way back is picking the - /// old rate (or the media's, [`native_frame_rate`](Self::native_frame_rate)) - /// rather than a `z`, and it lands within a frame of where it started rather - /// than on it (see [`Project::retime`]). Upgrade path is the same one: the - /// project's settings snapshotted beside the lanes. + /// One undo step, and the entry it takes is the whole of the change: the + /// lanes as they were in the *old* rate's numbering, with that rate beside + /// them, so a `z` restores the two together ([`Project::retime`]). The + /// step is taken before the retime rather than after, since this is the one + /// settings door that moves the lanes the step holds. Picking the old rate + /// back is still within a frame of where it started rather than on it: the + /// *lanes* come home exactly out of the entry, and the per-source lengths + /// are the half that goes through the map twice + /// ([`PlaybackSession::adopt_settings`]). pub fn set_frame_rate(&mut self, fps: f64) -> bool { if !fps.is_finite() || fps <= 0.0 || fps == self.meta.frame_rate { return false; @@ -3004,6 +3044,8 @@ impl PlaybackSession { let Ok(k) = Rate::from_fps(self.meta.frame_rate, fps) else { return false; }; + let from = self.settings_value(); + self.project.push_settings_step(from.clone(), from); // Lengths first: the retime holds every clip inside its source's *new* // length, so a clip that played to the last frame of its file still // does rather than naming one past the end. @@ -3017,6 +3059,9 @@ impl PlaybackSession { } self.meta.frame_rate = fps; self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1); + // The copy the project keeps, now that the change has landed: what the + // next lane edit's entry carries. + self.project.mirror_settings(self.settings_value()); let now = self.now(); self.seek(now); true @@ -3425,15 +3470,19 @@ impl PlaybackSession { self.edit(Dirty::Both, |p| p.delete_in(lane, idx)) } - /// Undoes the last successful edit, and reseeks like a delete. + /// Undoes the last successful edit, and reseeks like a delete. A step on + /// the project's own settings comes back the same way: the canvas, the + /// rate and the switches are put back on the session here + /// ([`Self::adopt_settings`]), so a `z` after a resolution pick, an + /// encoder pick or a proxy switch lands exactly as one after a cut does. pub fn undo(&mut self) -> bool { - self.edit(Dirty::Both, Project::undo) + self.restored_step(Project::undo) } /// Redoes the last edit [`undo`](Self::undo) took back, and reseeks like - /// a delete. + /// a delete -- settings included, exactly as `undo` takes them back. pub fn redo(&mut self) -> bool { - self.edit(Dirty::Both, Project::redo) + self.restored_step(Project::redo) } /// Takes `path` into the **library**: it becomes a source of this session, @@ -3600,6 +3649,87 @@ impl PlaybackSession { /// policy rebuilds the picture where it stands, with the sound running /// through it untouched -- no flush, no re-open, no hole -- and an /// equalizer the other way round. + /// The project's own settings as this session has them now + /// ([`ProjectSettings`]): the canvas and the rate are `meta`'s, the + /// switches are this session's own fields, and the rendition and the + /// limiter are the project's -- two halves of one header, which is what + /// every history entry carries beside the lanes ([`Project::snapshot`]). + fn settings_value(&self) -> ProjectSettings { + ProjectSettings { + resolution: (self.meta.width, self.meta.height), + frame_rate: self.meta.frame_rate, + encoder_seat: self.encoder_seat, + sample_rate: self.sample_rate, + proxies: self.proxies, + auto_proxies: self.auto_proxies, + tone: self.project.tone(), + limiter: self.project.limiter(), + } + } + + /// One undo step for a change to the project's own settings, taken after + /// the change: `from` is the state the door found, and what the project + /// does with the two values is [`Project::push_settings_step`]'s. + fn step_settings(&mut self, from: ProjectSettings) { + let now = self.settings_value(); + self.project.push_settings_step(from, now); + } + + /// Puts the project's settings back on this session -- what a step that + /// restored them leaves for the player to take up. The canvas, the rate and + /// the switches live here, and the rendition and the limiter are the + /// project's own, already back in place by the time this runs. Every lane + /// edit's entry comes through here too and moves nothing, which is the + /// common case; the *rate* is the one that needs more than the fields, + /// because every source's frame count is held against it and the conform + /// that scaled them is not in the entry. + fn adopt_settings(&mut self) { + let s = self.project.settings_now(); + // A project nobody has handed a canvas to: a fresh [`Project`] carries + // the placeholder ([`ProjectSettings::placeholder`]) and no session is + // on one -- the entries pushed before the first settings door hold lane + // edits and that placeholder, and adopting it would zero the canvas. + if s.frame_rate <= 0.0 { + return; + } + let was = self.meta.frame_rate; + self.meta.width = s.resolution.0; + self.meta.height = s.resolution.1; + self.meta.frame_rate = s.frame_rate; + self.encoder_seat = s.encoder_seat; + self.sample_rate = s.sample_rate; + self.proxies = s.proxies; + self.auto_proxies = s.auto_proxies; + if s.frame_rate != was { + // Within a frame, like the way out ([`Self::set_frame_rate`]'s own + // caveat): the lane frame numbers came home exactly, out of the + // entry, and only the per-source lengths are re-derived through the + // map back. + let Ok(k) = Rate::from_fps(was, s.frame_rate) else { + return; + }; + for count in &mut self.counts { + *count = k.timeline_at(*count).max(1); + } + for rate in &mut self.rates { + *rate = rate.then(k); + } + self.meta.frame_count = k.timeline_at(self.meta.frame_count).max(1); + } + } + + /// [`Self::undo`] and [`Self::redo`] themselves: the project's own step, + /// and then whatever it restored for the session to take up + /// ([`Self::adopt_settings`]). Reseeks both halves, so a canvas that moved + /// is repainted and a proxy switch that flipped reopens the file. + fn restored_step(&mut self, f: impl FnOnce(&mut Project) -> bool) -> bool { + if !self.edit(Dirty::Both, f) { + return false; + } + self.adopt_settings(); + true + } + fn edit(&mut self, dirty: Dirty, f: impl FnOnce(&mut Project) -> bool) -> bool { if !f(&mut self.project) { return false; diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 66d8f51..c8b2c4d 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -116,6 +116,7 @@ pub(crate) struct SweepParts( pub(crate) usize, pub(crate) Vec<(LaneKind, Vec)>, pub(crate) Vec>, + pub(crate) ProjectSettings, ); impl Speed { @@ -881,11 +882,75 @@ pub type Parts = ( /// How many undo steps a project keeps. One gesture is one step, so 100 is past /// any chain a person walks back by hand, and the oldest step is dropped rather -/// than the history growing without end: a snapshot is the whole lane list, so -/// on a 1394-clip jumpcut timeline this is a bounded ~10 MB instead of a leak -/// that grows for as long as the session lasts. +/// than the history growing without end: a snapshot is the whole lane list plus +/// the palette and the project's own settings, so on a 1394-clip jumpcut +/// timeline this is a bounded ~10 MB instead of a leak that grows for as long +/// as the session lasts. const HISTORY_CAP: usize = 100; +/// The project's own settings, as one value: the header a `.edith` file carries +/// beside the edit list, and what every undo step restores beside the lanes. +/// None of it is the media's own -- the scaffolding file's picture and rate +/// ([`PlaybackSession::native`]) stay on the session and are never rolled back. +#[derive(Clone, Debug, PartialEq)] +pub(crate) struct ProjectSettings { + /// The canvas every clip is composed onto: the project resolution, which a + /// clip of another size is placed onto rather than refused for. + pub(crate) resolution: (u32, u32), + /// The rate the timeline is cut at, which every clip and source is + /// conformed to ([`Project::retime`]). + pub(crate) frame_rate: f64, + /// Which encoder an export of this project opens its picture on + /// ([`crate::export::EncoderSeat`]). + pub(crate) encoder_seat: crate::export::EncoderSeat, + /// The rate the mix was picked to run at, or `None` for the one the first + /// audio source derives. + pub(crate) sample_rate: Option, + /// Whether the picture is decoded from the stand-ins ([`crate::proxy`]). + pub(crate) proxies: bool, + /// Whether a source that wants a stand-in gets one made for it as it + /// arrives ([`crate::proxy::wanted`]). + pub(crate) auto_proxies: bool, + /// Which HDR-to-SDR rendition the picture is watched and exported in. + pub(crate) tone: crate::tonemap::Preset, + /// The master limiter every lane's sound is summed through. + pub(crate) limiter: Limiter, +} + +impl ProjectSettings { + /// What a project built by hand carries before its constructor names the + /// canvas: the defaults every fresh open has -- nobody has picked stand-ins + /// (the films themselves are cut), an encoder or a mix rate, and the + /// rendition and limiter are the reference ones. Every door that builds a + /// session chains [`Project::with_canvas`] straight after, so the zero + /// canvas here is never a project anybody plays from. + fn placeholder() -> Self { + Self { + resolution: (0, 0), + frame_rate: 0.0, + encoder_seat: crate::export::EncoderSeat::default(), + sample_rate: None, + proxies: false, + auto_proxies: true, + tone: crate::tonemap::Preset::default(), + limiter: Limiter::default(), + } + } +} + +/// One undo step: the lanes, the subtitle palette and the project's own +/// settings exactly as they were before the edit that pushed it. Whole values +/// rather than the lane list alone, so an undo (or a redo) restores all three +/// together and no half of one edit can come back without the others -- which +/// is what lets a subtitle removal reindex every placement and still undo: the +/// restored palette names the very tracks the restored placements index. +#[derive(Clone, Debug)] +struct Snapshot { + lanes: Vec, + subtitles: Vec, + settings: ProjectSettings, +} + /// One gap a close-all sweep left open, with the frame it still starts on and /// the same refusal a single [`Project::gap_take_scope`] close would have said. #[derive(Clone, Debug, PartialEq, Eq)] @@ -917,32 +982,31 @@ pub struct Project { /// The same, for [`Clip::transform`]. transform: Vec, /// Snapshots pushed *before* each successful edit; `undo` pops one. The - /// whole lane list, so adding a lane undoes as well. Bounded by - /// [`HISTORY_CAP`]: at the cap the oldest step goes. - history: Vec>, - /// Lane lists `undo` has stepped past; `redo` pops one. Cleared by + /// whole lane list, the subtitle palette and the project's own settings, + /// so adding a lane undoes as well and so does picking a resolution. Bounded + /// by [`HISTORY_CAP`]: at the cap the oldest step goes. + history: Vec, + /// Snapshots `undo` has stepped past; `redo` pops one. Cleared by /// [`Project::snapshot`], since a fresh edit invalidates whatever branch /// the undone steps came from. Not saved to `.edith`, matching `history`. - redo: Vec>, + redo: Vec, /// Never rolled back by an undo: an id retired by an undone split must not /// come back and group two clips that were never together. next_link: u32, /// The subtitle tracks this timeline shows, in the order they were added. - /// Not in the lane list and not in the history snapshots, for the reason - /// the limiter is not: which subtitles a project carries is a setting on - /// it, and it is saved as a *reference* to the file the cues came out of - /// ([`crate::subtitle`]). + /// Saved as a *reference* to the file the cues came out of + /// ([`crate::subtitle`]). In the history snapshots since the widened + /// [`Snapshot`]: a placement names a track by index into this list, so a + /// removal that reindexes the placements can only undo together with the + /// palette it removed the row from. subtitles: Vec, - /// The master limiter every lane's sound is summed *through* - /// ([`Project::limiter`]). Off by default, and not in the lane list, which - /// is what the history snapshots hold: it is a setting on the mix, like the - /// project's resolution is a setting on the picture, and neither is an undo - /// step. - limiter: Limiter, - /// Which HDR-to-SDR rendition every clip on an HDR curve is shown and - /// exported in ([`crate::tonemap::Preset`]). A setting on the picture, like - /// the resolution, and not in the lane snapshots for the same reason. - tone: crate::tonemap::Preset, + /// The project's own settings ([`ProjectSettings`]) -- the canvas, the + /// rate, the proxies switches, the encoder seat, the mix rate, the + /// rendition and the limiter. In every snapshot, so each of them undoes + /// like a lane edit: they are the header of the project's own `.edith` + /// file, not this machine's, and a pick a ctrl+z could not take back + /// would be the one setting with no way out. + settings: ProjectSettings, } impl Project { @@ -980,8 +1044,7 @@ impl Project { redo: Vec::new(), next_link: 1, subtitles: Vec::new(), - limiter: Limiter::default(), - tone: crate::tonemap::Preset::default(), + settings: ProjectSettings::placeholder(), } } @@ -1124,8 +1187,7 @@ impl Project { redo: Vec::new(), next_link, subtitles: Vec::new(), - limiter: Limiter::default(), - tone: crate::tonemap::Preset::default(), + settings: ProjectSettings::placeholder(), }) } @@ -1400,7 +1462,8 @@ impl Project { /// different file. [`PlaybackSession::remove_source`] hands back the index /// that went for exactly that. /// - /// corner-cut: this retires the undo stack. `history` holds lanes alone, so a + /// corner-cut: this retires the undo stack. `history` holds the lanes, the + /// subtitle palette and the project's own settings -- no source list -- so a /// snapshot older than the removal can name the very source being removed /// (delete a file's clips, then remove the file) and restoring it would /// point a clip at an entry that is gone. The upgrade path is snapshotting @@ -1679,14 +1742,44 @@ impl Project { data.gain_db = db.clamp(MIN_GAIN_DB, MAX_GAIN_DB); } } - self.limiter = limiter.with_ceiling(limiter.ceiling_db); + self.settings.limiter = limiter.with_ceiling(limiter.ceiling_db); self } /// The HDR rendition a *load* puts back -- the same door /// [`with_mix`](Project::with_mix) is, and no undo step for the same reason. pub fn with_tone(mut self, preset: crate::tonemap::Preset) -> Self { - self.tone = preset; + self.settings.tone = preset; + self + } + + /// The canvas and rate a *load* or a fresh open names -- the project + /// resolution and the rate every clip is counted in. The same door + /// [`with_mix`](Project::with_mix) is, and no undo step for the same + /// reason: a project that arrives one undo away from a state it was never + /// in is a project whose first ctrl+z is a surprise. + pub fn with_canvas(mut self, width: u32, height: u32, frame_rate: f64) -> Self { + self.settings.resolution = (width, height); + self.settings.frame_rate = frame_rate; + self + } + + /// The saved switches a *load* puts back: whether the picture is cut on + /// the stand-ins, whether new ones are made on arrival, which encoder an + /// export opens, and the rate the mix was picked to run at. The load half + /// of [`set_proxies`](Project::set_proxies) and its siblings, and no undo + /// step for [`with_mix`](Project::with_mix)'s reason. + pub fn with_switches( + mut self, + proxies: bool, + auto_proxies: bool, + encoder_seat: crate::export::EncoderSeat, + sample_rate: Option, + ) -> Self { + self.settings.proxies = proxies; + self.settings.auto_proxies = auto_proxies; + self.settings.encoder_seat = encoder_seat; + self.settings.sample_rate = sample_rate; self } @@ -1694,21 +1787,18 @@ impl Project { /// project setting, not a clip's: one picture, one look /// ([`crate::tonemap::Preset`]). pub fn tone(&self) -> crate::tonemap::Preset { - self.tone + self.settings.tone } /// Sets it. `false` for the one already in force, which is what keeps a - /// re-pick of the current rendition from costing a reseek. - /// - /// corner-cut: not an undo step, for the reason the limiter and the project - /// resolution are not -- it is not in the lane list the history snapshots. - /// Upgrade path is the same one: a history entry holding the project's own - /// settings beside the lanes. + /// re-pick of the current rendition from costing a reseek. One undo step + /// like every other project-setting pick. pub fn set_tone(&mut self, preset: crate::tonemap::Preset) -> bool { - if self.tone == preset { + if self.settings.tone == preset { return false; } - self.tone = preset; + self.snapshot(); + self.settings.tone = preset; true } @@ -1763,16 +1853,14 @@ impl Project { /// [`remove_source`](Project::remove_source) refuses the same way for the /// same silent corruption. /// - /// corner-cut: not an undo step, for the reason the limiter is not -- the - /// history snapshots hold the lane list and subtitles are not on it - /// ([`Project::subtitles`]). The inverse is putting the file's tracks back - /// on -- [`crate::PlaybackSession::import_subtitles`], the panel's own - /// door, which reads the subtitles of a file and nothing else -- and not a - /// ctrl+z; the upgrade path is the same one the limiter has: a history - /// entry holding the project's own settings beside the lanes. The history - /// is *cleared* rather than kept, as a source removal clears it: the - /// snapshots hold the indexes as they were before the reindex, so an undo - /// into one would put every placement past `idx` on the wrong track. + /// One undo step, and the reindex with it: every placement names a track + /// by index into the palette ([`crate::subtitle`]), so a removal that + /// renumbers them can only come back together with the palette it took + /// the row from -- which is what the history entry holds, beside the + /// lanes it also carries ([`Snapshot`]). The inverse, for a caller that + /// wants the file's tracks back, is [`crate::PlaybackSession::import_subtitles`] + /// -- the panel's own door, which reads the subtitles of a file and + /// nothing else. pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> { if idx >= self.subtitles.len() { return Err(format!("there is no subtitle track {idx} to remove").into()); @@ -1796,13 +1884,13 @@ impl Project { ) .into()); } + self.snapshot(); self.subtitles.remove(idx); for s in self.lanes.iter_mut().flat_map(|l| &mut l.subs) { if s.track > idx { s.track -= 1; } } - self.history.clear(); Ok(()) } @@ -2252,25 +2340,34 @@ impl Project { /// The master limiter the mix is summed through. A project setting, not a /// clip's and not a lane's: there is one mix. pub fn limiter(&self) -> Limiter { - self.limiter + self.settings.limiter } /// Sets it, with the ceiling clamped to what [`Limiter`] allows. `false` - /// for a setting already in force. - /// - /// corner-cut: not an undo step, for the reason the project resolution is not - /// one ([`crate::PlaybackSession::set_resolution`]) -- it is not in the - /// lane list the history snapshots. Upgrade path is a history entry that - /// holds the mix settings beside the lanes. + /// for a setting already in force. One undo step like every other + /// project-setting pick. pub fn set_limiter(&mut self, limiter: Limiter) -> bool { let limiter = limiter.with_ceiling(limiter.ceiling_db); - if self.limiter == limiter { + if self.settings.limiter == limiter { return false; } - self.limiter = limiter; + self.snapshot(); + self.settings.limiter = limiter; true } + + + + + + + + + + + + /// What the clip at `idx` of `lane` plays through, or `None` for one that /// plays flat (and for an index that is not there) -- what a feeder and an /// export ask before they build an [`crate::eq::EqState`]. @@ -4948,6 +5045,36 @@ impl Project { self.redo.len() } + /// The project's own settings as they stand ([`ProjectSettings`]) -- what an + /// undo entry holds beside the lanes, and what the session reads back after + /// one is restored ([`crate::PlaybackSession::undo`]). + pub(crate) fn settings_now(&self) -> ProjectSettings { + self.settings.clone() + } + + /// One undo step for a change to the project's own settings: `from` is the + /// state the change is from and `now` the one it leaves behind. The entry + /// pushed holds `from`, while the copy kept here is `now` -- so the next + /// lane edit's own entry carries the canvas and the rate really in force + /// rather than the ones before the pick. The lanes the entry holds are the + /// ones in place at the call: a settings door leaves them alone and may + /// take this step after its change, and one that moves them + /// ([`Project::retime`] on a rate change) takes it before, with `now` equal + /// to `from`, mirroring the new state afterwards + /// ([`Project::mirror_settings`]). + pub(crate) fn push_settings_step(&mut self, from: ProjectSettings, now: ProjectSettings) { + self.settings = from; + self.snapshot(); + self.settings = now; + } + + /// Keeps `now` as this project's copy of its own settings, without a step: + /// the second half of a settings door that had to take its step before the + /// change. + pub(crate) fn mirror_settings(&mut self, now: ProjectSettings) { + self.settings = now; + } + /// Every part of the project that an edit can change, as comparable /// values: what the sweep's undo round-trip asks "byte identical?" of. #[cfg(test)] @@ -4956,31 +5083,44 @@ impl Project { self.sources.len(), self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(), self.lanes.iter().map(|l| l.subs.clone()).collect(), + self.settings.clone(), ) } - /// Restore every lane from before the last successful edit -- the clips and - /// the lane list both. `false` when there is nothing left to undo. Pushes - /// the lanes just left onto the redo stack, so [`Project::redo`] can walk - /// forward again. + /// Restore everything from before the last successful edit -- the lanes, + /// the subtitle palette and the project's own settings. `false` when there + /// is nothing left to undo. Pushes what was just left onto the redo stack, + /// so [`Project::redo`] can walk forward again. pub fn undo(&mut self) -> bool { match self.history.pop() { Some(prev) => { - self.redo.push(std::mem::replace(&mut self.lanes, prev)); + self.redo.push(Snapshot { + lanes: std::mem::replace(&mut self.lanes, prev.lanes), + subtitles: self.subtitles.clone(), + settings: self.settings.clone(), + }); + self.subtitles = prev.subtitles; + self.settings = prev.settings; true } None => false, } } - /// Restore every lane from before the last [`Project::undo`] -- the + /// Restore everything from before the last [`Project::undo`] -- the /// mirror of `undo`, walking the redo stack it fills. `false` when there /// is nothing left to redo, which is also true after any fresh edit: a /// new [`Project::snapshot`] clears the branch `undo` left behind. pub fn redo(&mut self) -> bool { match self.redo.pop() { Some(next) => { - self.history.push(std::mem::replace(&mut self.lanes, next)); + self.history.push(Snapshot { + lanes: std::mem::replace(&mut self.lanes, next.lanes), + subtitles: self.subtitles.clone(), + settings: self.settings.clone(), + }); + self.subtitles = next.subtitles; + self.settings = next.settings; true } None => false, @@ -5002,8 +5142,7 @@ impl Project { redo: Vec::new(), next_link: self.next_link, subtitles: self.subtitles.clone(), - limiter: self.limiter, - tone: self.tone, + settings: self.settings.clone(), } } @@ -5216,7 +5355,11 @@ impl Project { if self.history.len() == HISTORY_CAP { self.history.remove(0); } - self.history.push(self.lanes.clone()); + self.history.push(Snapshot { + lanes: self.lanes.clone(), + subtitles: self.subtitles.clone(), + settings: self.settings.clone(), + }); self.redo.clear(); } @@ -10405,4 +10548,35 @@ mod tests { .expect("valid parts"); assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]); } + +/// D4: removing a subtitle column used to clear the whole undo history, +/// because a placement names its track by index into the palette and the +/// reindex left every later entry naming the wrong one. The entry holds the +/// palette beside the lanes now, so the reindex undoes with it. +#[test] +fn removing_a_subtitle_column_undoes_with_its_reindex() { + let track = |label: &str| SubtitleTrack { + path: FILE.into(), + track: None, + language: "eng".into(), + name: String::new(), + label: label.into(), + cues: Vec::new(), + bitmap: false, + refused: None, + }; + let mut p = Project::single(FILE, 300) + .with_subtitles(vec![track("one"), track("two"), track("three")]); + assert_eq!(p.subtitles().len(), 3); + let before = p.parts(); + // Column 0 goes, which renumbers the two behind it. + p.remove_subtitles(0).expect("a column with nothing on it"); + assert_eq!(p.subtitles().len(), 2); + assert_eq!(p.subtitles()[0].label, "two"); + assert!(p.undo(), "the removal is a step like any other cut"); + assert_eq!(p.parts(), before, "the palette and the lanes, both back"); + assert!(p.redo(), "and forward again"); + assert_eq!(p.subtitles()[0].label, "two"); +} + }