forge
Explore
Log in

Don't you dare go Hollow

πŸ”€ merge(falsedirty): the app arms its gates and marks proxy candidacy

Browse files at this commit

b8aec297d78df52fc2faa266cc7303687f64e205Ahmet Kaan GümüşParent: 0c9d76c6f579f0
crates/app/src/player/actions.rsmodified+22 -6
@@ -67,8 +67,22 @@ impl Player {
6767 | ActionId::AddSubtitleLane
6868 | ActionId::RemoveSubtitleLane
6969 | ActionId::ImportSubtitles
70- | ActionId::Crossfade
71- | ActionId::Dissolve
70+ // `Crossfade` and `Dissolve` are NOT here, and that is the
71+ // rule rather than an omission: their doors answer for
72+ // themselves ([`Player::crossfade_selected`],
73+ // [`Player::dissolve_selected`]) and the clip-menu row reaches
74+ // `dissolve_selected` directly, never through this table, so a
75+ // list entry armed the key path and left the menu path armed by
76+ // nothing.
77+ //
78+ // The three `Remove*Lane` entries ARE still here and are still
79+ // wrong in the same way -- `remove_lane` refuses a track that
80+ // holds clips and the last of its kind, and it now carries its
81+ // own arm ([`Player::remove_lane`]) -- but taking them off is
82+ // a wider pass over this list than this change makes, so they
83+ // stay until it does. Until then each of those removals arms
84+ // twice over, which is the lesser fault beside arming once for
85+ // a removal that did not happen.
7286 | ActionId::Visualizer
7387 ) {
7488 self.mark_dirty();
@@ -251,10 +265,12 @@ impl Player {
251265 }
252266 match action {
253267 ActionId::Mix => self.open_mix(Some(lane), cx),
254- ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => {
255- self.mark_dirty();
256- self.remove_lane(lane, cx);
257- }
268+ // The arm rides the door's own answer, like every arm in this
269+ // window: `remove_lane` refuses a track that still holds clips or
270+ // captions, and the last track of its kind, and arming before the
271+ // ask lit the ledger's `unsaved` ghost, wrote a sidecar and put the
272+ // close prompt up over a project whose bytes had not moved.
273+ ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => self.remove_lane(lane, cx),
258274 _ => unreachable!("only lane-header actions reach act_lane"),
259275 }
260276 }
crates/app/src/player/cards.rsmodified+57 -44
@@ -1,8 +1,8 @@
11 //! The cards the window opens over itself: the pickers, colour, speed,
22 //! silence, the mixer and the equalizer.
33
4-use crate::*;
54 use crate::ui::settings_stance::SettingsTab;
5+use crate::*;
66
77 impl Player {
88 /// Cycles the *project's* resolution through [`RESOLUTIONS`], starting from
@@ -279,10 +279,7 @@ impl Player {
279279 match caption_media_half(session, (lane, idx), LaneKind::Video) {
280280 Some(half) => Some(half),
281281 None => {
282- self.notify_user(
283- "NOTHING TO GRADE β€” a caption has no picture"
284- .into(),
285- );
282+ self.notify_user("NOTHING TO GRADE β€” a caption has no picture".into());
286283 cx.notify();
287284 return;
288285 }
@@ -426,10 +423,7 @@ impl Player {
426423 match caption_media_half(session, (lane, idx), LaneKind::Video) {
427424 Some(half) => Some(half),
428425 None => {
429- self.notify_user(
430- "NOTHING TO PLACE β€” a caption has no picture"
431- .into(),
432- );
426+ self.notify_user("NOTHING TO PLACE β€” a caption has no picture".into());
433427 cx.notify();
434428 return;
435429 }
@@ -567,8 +561,7 @@ impl Player {
567561 Some(half) => Some(half),
568562 None => {
569563 self.notify_user(
570- "NOTHING TO RE-TIME β€” a caption has no speed of its own"
571- .into(),
564+ "NOTHING TO RE-TIME β€” a caption has no speed of its own".into(),
572565 );
573566 cx.notify();
574567 return;
@@ -734,8 +727,7 @@ impl Player {
734727 Some(half) => Some(half),
735728 None => {
736729 self.notify_user(
737- "NOTHING TO SCAN β€” a caption has no sound of its own"
738- .into(),
730+ "NOTHING TO SCAN β€” a caption has no sound of its own".into(),
739731 );
740732 cx.notify();
741733 return;
@@ -856,14 +848,20 @@ impl Player {
856848 if self.session.is_none() {
857849 return;
858850 }
859- self.mark_dirty();
860851 let Some(session) = self.session.as_mut() else {
861852 return;
862853 };
863- match lanes.get(self.mix_field) {
854+ // The arm rides the door's answer, not the press: a fader already
855+ // against its wall, a ceiling already at its clamp and a limiter
856+ // switch that did not move are *not* edits, and `set_lane_gain_db` /
857+ // `set_limiter` each answer `false` for exactly those (an unchanged
858+ // value). Arming before the ask lit the ledger's `unsaved` ghost,
859+ // wrote an autosave sidecar and put the close prompt up over a
860+ // project whose bytes had not moved.
861+ let took = match lanes.get(self.mix_field) {
864862 Some(&lane) => {
865863 let at = session.lane_gain_db(lane) + steps as f32 * MIX_DB_STEP;
866- session.set_lane_gain_db(lane, at);
864+ session.set_lane_gain_db(lane, at)
867865 }
868866 None => {
869867 let limiter = session.limiter();
@@ -878,8 +876,11 @@ impl Player {
878876 ..limiter
879877 },
880878 };
881- session.set_limiter(at);
879+ session.set_limiter(at)
882880 }
881+ };
882+ if took {
883+ self.mark_dirty();
883884 }
884885 cx.notify();
885886 }
@@ -1246,17 +1247,15 @@ impl Player {
12461247 /// nothing.
12471248 pub(crate) fn previewed(&mut self) -> Option<(Vec<(u32, u32)>, Vec<Lane>)> {
12481249 if self.silence_marks.is_empty() {
1249- self.notify_user(
1250- if self.silence_keep_only {
1251- "NO SPEECH TO CUT β€” keep-only-silence needs silence and speech".into()
1252- } else {
1253- format!(
1254- "NO SILENCE β€” under {:.0} dBFS lasting {:.2} s",
1255- self.silence.threshold_db, self.silence.min_silence
1256- )
1257- .into()
1258- },
1259- );
1250+ self.notify_user(if self.silence_keep_only {
1251+ "NO SPEECH TO CUT β€” keep-only-silence needs silence and speech".into()
1252+ } else {
1253+ format!(
1254+ "NO SILENCE β€” under {:.0} dBFS lasting {:.2} s",
1255+ self.silence.threshold_db, self.silence.min_silence
1256+ )
1257+ .into()
1258+ });
12601259 return None;
12611260 }
12621261 Some((self.silence_marks.clone(), self.silence_lanes()))
@@ -1302,7 +1301,11 @@ impl Player {
13021301 // moves indexes (a delete, a paste, an undo).
13031302 self.selected.clear();
13041303 self.reset_after_reseek();
1305- let what = if self.silence_keep_only { "SPEECH" } else { "SILENCES" };
1304+ let what = if self.silence_keep_only {
1305+ "SPEECH"
1306+ } else {
1307+ "SILENCES"
1308+ };
13061309 self.notify_user(
13071310 format!(
13081311 "{count} {what} CUT {reach} β€” {} shorter Β· undo {}",
@@ -1342,7 +1345,11 @@ impl Player {
13421345 // goes with them.
13431346 self.selected.clear();
13441347 self.reset_after_reseek();
1345- let what = if self.silence_keep_only { "SPEECH" } else { "SILENCES" };
1348+ let what = if self.silence_keep_only {
1349+ "SPEECH"
1350+ } else {
1351+ "SILENCES"
1352+ };
13461353 self.notify_user(
13471354 format!(
13481355 "{count} {what} AT {rate} {reach} Β· undo {}",
@@ -1494,9 +1501,9 @@ impl Player {
14941501 "NOTHING SELECTED Β· select all {}",
14951502 self.keymap.display(ActionId::Select)
14961503 )),
1497- (Some((lane, _)), _) if lane.kind != LaneKind::Audio => Some(
1498- "NOT AN AUDIO CLIP β€” the equalizer works on sound".to_string(),
1499- ),
1504+ (Some((lane, _)), _) if lane.kind != LaneKind::Audio => {
1505+ Some("NOT AN AUDIO CLIP β€” the equalizer works on sound".to_string())
1506+ }
15001507 _ => None,
15011508 };
15021509 if let Some(refusal) = refusal {
@@ -1535,12 +1542,23 @@ impl Player {
15351542 };
15361543 let params = (!self.eq_params.is_identity()).then(|| self.eq_params.clone());
15371544 if let Some(session) = &mut self.session {
1538- session.set_eq(lane, idx, params);
1539- self.mark_dirty();
1545+ // `set_eq` answers "the index was there and the curve is finite"
1546+ // -- it snapshots and rewrites the very slot it already holds for
1547+ // a curve that is already in force -- so on its own bool a
1548+ // re-commit of the same curve armed autosave, the ledger's
1549+ // `unsaved` ghost and the close prompt over a project whose bytes
1550+ // had not moved. The arm rides the curve having moved, the
1551+ // comparison `apply_fit` reads for `set_fit`
1552+ // ([`Player::apply_fit`]), and then the door's own answer.
1553+ let moved = session.eq_of(lane, idx).cloned() != params;
1554+ if moved && session.set_eq(lane, idx, params) {
1555+ self.mark_dirty();
1556+ // `set_eq` reseeks inside the engine -- that is what makes the
1557+ // change audible at once -- and a reseek is what these flags
1558+ // are about. Nothing was written, so nothing was reseeked.
1559+ self.reset_after_reseek();
1560+ }
15401561 }
1541- // `set_eq` reseeks inside the engine -- that is what makes the change
1542- // audible at once -- and a reseek is what these flags are about.
1543- self.reset_after_reseek();
15441562 cx.notify();
15451563 }
15461564
@@ -1590,12 +1608,7 @@ impl Player {
15901608 /// band that was just made. Refused rather than silently ignored at the cap.
15911609 pub(crate) fn add_band(&mut self, cx: &mut Context<Self>) {
15921610 if self.eq_params.bands.len() >= EQ_BANDS_MAX {
1593- self.notify_user(
1594- format!(
1595- "EQUALIZER FULL β€” {EQ_BANDS_MAX} bands"
1596- )
1597- .into(),
1598- );
1611+ self.notify_user(format!("EQUALIZER FULL β€” {EQ_BANDS_MAX} bands").into());
15991612 cx.notify();
16001613 return;
16011614 }
crates/app/src/player/library.rsmodified+8 -10
@@ -177,9 +177,7 @@ impl Player {
177177 self.reset_after_reseek();
178178 }
179179 Err(e) => self.notify_user(format!("NO VISUALIZER β€” {e}").into()),
180- Ok(false) => {
181- self.notify_user("NO VISUALIZER β€” that clip could not be placed".into())
182- }
180+ Ok(false) => self.notify_user("NO VISUALIZER β€” that clip could not be placed".into()),
183181 }
184182 cx.notify();
185183 }
@@ -453,10 +451,7 @@ impl Player {
453451 {
454452 true => {
455453 self.close_session();
456- format!(
457- "REMOVED {} β€” the library is empty",
458- file_name(path)
459- )
454+ format!("REMOVED {} β€” the library is empty", file_name(path))
460455 }
461456 // The undo stack goes with it (`Project::remove_source`):
462457 // said here, because a `z` that does nothing afterwards
@@ -1196,9 +1191,7 @@ impl Player {
11961191 .count();
11971192 let text = match (on, ready, making) {
11981193 (false, ..) => "PROXIES OFF β€” the films themselves are what play".to_string(),
1199- (true, 0, 0) => {
1200- "PROXIES ON β€” no film here has one".to_string()
1201- }
1194+ (true, 0, 0) => "PROXIES ON β€” no film here has one".to_string(),
12021195 (true, 0, n) => format!("PROXIES ON β€” {n} still being made"),
12031196 (true, n, 0) => format!("PROXIES ON β€” cutting on {n}"),
12041197 (true, n, m) => format!("PROXIES ON β€” cutting on {n}, {m} still being made"),
@@ -2156,6 +2149,11 @@ impl Player {
21562149 .map(|session| session.remove_lane(lane));
21572150 let text = match removed {
21582151 Some(Ok(())) => {
2152+ // The arm lives here, on the one answer that means the track
2153+ // went: `remove_lane` refuses a track still holding clips or
2154+ // captions, and the last of its kind, and both used to arrive
2155+ // with the `unsaved` ghost already lit behind them.
2156+ self.mark_dirty();
21592157 self.selected.clear();
21602158 self.context_menu = None;
21612159 self.eq_open = None;
crates/app/src/player/timeline_edit.rsmodified+83 -19
@@ -1783,12 +1783,25 @@ impl Player {
17831783 return;
17841784 };
17851785 let frames = self.fps.round().max(1.) as u32;
1786- if let Some(session) = &mut self.session {
1787- if !session.crossfade(lane, idx, frames) {
1788- self.notify_user("NOTHING TO CROSSFADE β€” no neighbour end to end".into());
1789- }
1786+ if self.session.is_none() {
1787+ return;
1788+ }
1789+ // The arm rides the write, and rides the join's own edges as well as
1790+ // the door's answer: `Project::crossfade` answers true for any two
1791+ // adjacent clips, so a crossfade already at the room the two clips
1792+ // offer writes the value the join already carried and still says yes.
1793+ // This door carries its own arm rather than leaning on the action
1794+ // table's list, which fires before any door is asked.
1795+ let before = self.transition_edges(lane, idx);
1796+ let took = match &mut self.session {
1797+ Some(session) => session.crossfade(lane, idx, frames),
1798+ None => false,
1799+ };
1800+ if took && self.transition_edges(lane, idx) != before {
1801+ self.mark_dirty();
1802+ } else if !took {
1803+ self.notify_user("NOTHING TO CROSSFADE β€” no neighbour end to end".into());
17901804 }
1791- cx.notify();
17921805 }
17931806
17941807 /// Dissolves the join the selection names, into or back out of it: two
@@ -1809,24 +1822,48 @@ impl Player {
18091822 cx.notify();
18101823 return;
18111824 };
1812- let Some(session) = &mut self.session else {
1825+ if self.session.is_none() {
18131826 cx.notify();
18141827 return;
1815- };
1816- let removing = session.transition_out_of(lane, idx) > 0;
1828+ }
1829+ let removing = self.transition_out_of_selected(lane, idx);
18171830 let frames = if removing {
18181831 0
18191832 } else {
18201833 self.fps.round().max(1.) as u32
18211834 };
1822- if !session.set_transition_out(lane, idx, frames) {
1835+ // The arm rides the write, and the join's own edges as well as the
1836+ // door's answer -- `set_transition_out`'s own rule
1837+ // ([`Player::crossfade_selected`]'s). This door carries its own arm
1838+ // rather than leaning on the action table's list, which fires before
1839+ // any door is asked: the clip-menu row
1840+ // ([`crate::ui::bench_stance`]) reaches this door directly, never
1841+ // through the table at all, and was armed by nothing.
1842+ let before = self.transition_edges(lane, idx);
1843+ let took = match &mut self.session {
1844+ Some(session) => session.set_transition_out(lane, idx, frames),
1845+ None => false,
1846+ };
1847+ if took && self.transition_edges(lane, idx) != before {
1848+ self.mark_dirty();
1849+ if removing {
1850+ self.notify_user("DISSOLVE REMOVED β€” the clips cut again".into());
1851+ }
1852+ } else if !took {
18231853 self.notify_user("NOTHING TO DISSOLVE β€” no neighbour end to end".into());
1824- } else if removing {
1825- self.notify_user("DISSOLVE REMOVED β€” the clips cut again".into());
18261854 }
18271855 cx.notify();
18281856 }
18291857
1858+ /// The dissolve the join at `idx` of `lane` already carries, read before
1859+ /// the session is borrowed mutably: `0` for a lane, index or join that has
1860+ /// none, and `false` if there is no session to ask.
1861+ fn transition_out_of_selected(&self, lane: Lane, idx: usize) -> bool {
1862+ self.session
1863+ .as_ref()
1864+ .is_some_and(|session| session.transition_out_of(lane, idx) > 0)
1865+ }
1866+
18301867 /// Widens or narrows the transition the anchor already carries, one
18311868 /// frame at a step, from the inspector's duration row -- ctrl+f/ctrl+x
18321869 /// stay the toggle that seeds a fresh one at one second; this is what
@@ -1869,17 +1906,44 @@ impl Player {
18691906 if self.exporting().is_some() {
18701907 return;
18711908 }
1872- let Some(session) = &mut self.session else {
1909+ if self.session.is_none() {
18731910 return;
1911+ }
1912+ // The engine's bool answers "the two clips are adjacent" -- both
1913+ // setters snapshot and clamp, and a `frames` already in force (a step
1914+ // past the cap, a number retyped in the field) writes the value the
1915+ // clip already carried and still says true. The arm therefore rides
1916+ // the join's own edges read back, the same before/after comparison
1917+ // `move_sub` and `commit_fade` make.
1918+ let before = self.transition_edges(lane, idx);
1919+ let ok = match &mut self.session {
1920+ Some(session) => match lane.kind {
1921+ LaneKind::Video => session.set_transition_out(lane, idx, frames),
1922+ LaneKind::Audio => session.crossfade(lane, idx, frames),
1923+ _ => false,
1924+ },
1925+ None => false,
18741926 };
1875- let ok = match lane.kind {
1876- LaneKind::Video => session.set_transition_out(lane, idx, frames),
1877- LaneKind::Audio => session.crossfade(lane, idx, frames),
1878- _ => false,
1879- };
1880- if ok {
1927+ if ok && self.transition_edges(lane, idx) != before {
18811928 self.mark_dirty();
1882- cx.notify();
1929+ }
1930+ cx.notify();
1931+ }
1932+
1933+ /// What the join at `idx` of `lane` carries on both sides, for the doors
1934+ /// that only the *pair* can answer for: a crossfade writes `idx`'s
1935+ /// `fade_out` and its neighbour's `fade_in`, so a comparison of the
1936+ /// anchor's own field alone would miss a neighbour-side no-op. `None`
1937+ /// for a lane with no such pair, which is a value no write can equal.
1938+ fn transition_edges(&self, lane: Lane, idx: usize) -> Option<(u32, u32)> {
1939+ let session = self.session.as_ref()?;
1940+ match lane.kind {
1941+ LaneKind::Video => Some((session.transition_out_of(lane, idx), 0)),
1942+ LaneKind::Audio => {
1943+ let clips = session.lane_clips(lane);
1944+ Some((clips.get(idx)?.fade_out, clips.get(idx + 1)?.fade_in))
1945+ }
1946+ _ => None,
18831947 }
18841948 }
18851949
crates/app/src/tests/cards.rsmodified+203 -6
@@ -1172,7 +1172,7 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() {
11721172 /// and can't turn it back to video"). One cycle, and it wraps.
11731173 #[test]
11741174 fn the_picture_cycle_wraps_out_of_the_sound_only_formats() {
1175- use crate::ui::settings_stance::{next_picture, PICTURE_CYCLE};
1175+ use crate::ui::settings_stance::{PICTURE_CYCLE, next_picture};
11761176 // Nothing refused: every stop is the next one, and the last wraps to the
11771177 // first -- OGG, the tail of the list, back to MP4.
11781178 let mut at = PICTURE_CYCLE[0];
@@ -1710,6 +1710,201 @@ fn every_click_door_that_writes_the_project_arms_autosave() {
17101710 one for the same step"
17111711 );
17121712 }
1713+ // The mix card's own doors. Both answer "the value moved" -- a fader
1714+ // already against its wall, a ceiling already at its clamp, a limiter
1715+ // switch whose value is the one in force are each `false` -- so the arm
1716+ // rides the bool, and `nudge_mix` does not arm before the ask the way it
1717+ // did: a held arrow key at the top of the fader lit `unsaved`, wrote a
1718+ // sidecar and put the close prompt up over a project whose bytes had not
1719+ // moved.
1720+ let body = fn_body("nudge_mix");
1721+ for door in ["set_lane_gain_db", "set_limiter"] {
1722+ assert!(
1723+ body.contains(door),
1724+ "nudge_mix no longer goes through {door}"
1725+ );
1726+ }
1727+ let arm = body
1728+ .split_once("if took {")
1729+ .expect("the mix arm no longer rides the door's own answer")
1730+ .1;
1731+ assert!(
1732+ arm.contains("mark_dirty()"),
1733+ "nudge_mix arms outside its gate, so a fader held against its wall \
1734+ would dirty the project"
1735+ );
1736+ let before = body.split_once("if took {").unwrap().0;
1737+ assert!(
1738+ !before.contains("mark_dirty()"),
1739+ "nudge_mix still arms ahead of the door, so a clamped no-op nudge \
1740+ leaves the project looking edited"
1741+ );
1742+ // The equalizer card's commit, the same rule against a door whose bool is
1743+ // the WEAKER of the two shapes: `set_eq` answers "the index was there and
1744+ // the curve is finite" and rewrites the very slot it already holds for a
1745+ // curve already in force, so the arm needs the comparison too -- the same
1746+ // pair of conditions `apply_fit` rides.
1747+ let body = fn_body("commit_eq");
1748+ let arm = body
1749+ .split_once("if moved && session.set_eq(lane, idx, params) {")
1750+ .expect("the EQ commit no longer rides the curve having moved and then the door")
1751+ .1;
1752+ assert!(
1753+ arm.contains("mark_dirty()"),
1754+ "commit_eq arms outside its gate, so re-committing the curve already \
1755+ in force would dirty the project"
1756+ );
1757+ assert!(
1758+ body.contains("session.eq_of(lane, idx).cloned() != params"),
1759+ "commit_eq rides the engine's bool alone, which is true for a \
1760+ re-commit of the curve already in force"
1761+ );
1762+ // ...and the reseek bookkeeping rides with the arm, not instead of it.
1763+ assert!(
1764+ arm.contains("reset_after_reseek()"),
1765+ "commit_eq's reseek flags no longer clear on a write that took"
1766+ );
1767+ let before = body
1768+ .split_once("if moved && session.set_eq(lane, idx, params) {")
1769+ .unwrap()
1770+ .0;
1771+ assert!(
1772+ !before.contains("mark_dirty()"),
1773+ "commit_eq still arms ahead of the door"
1774+ );
1775+}
1776+
1777+/// The transition doors, which are the class's other shape: both engine
1778+/// setters ([`engine::project::Project::set_transition_out`],
1779+/// [`engine::project::Project::crossfade`]) answer `true` for any two
1780+/// adjacent clips, snapshot and clamp included -- so a step past the
1781+/// successor's length, or a number retyped into the field, wrote the value the
1782+/// join already carried and still said yes. [`Player::set_transition_frames`]
1783+/// reads the join's own edges back and rides those, and the crossfade side
1784+/// compares *both* edges: it writes the anchor's `fade_out` and the
1785+/// neighbour's `fade_in`, and a comparison of the anchor alone would miss a
1786+/// neighbour-side no-op.
1787+#[test]
1788+fn a_transition_step_or_a_retyped_number_arms_only_what_moved() {
1789+ let body = fn_body("set_transition_frames");
1790+ for door in ["set_transition_out", "crossfade"] {
1791+ assert!(
1792+ body.contains(door),
1793+ "the duration doors no longer include {door}"
1794+ );
1795+ }
1796+ let gate = "if ok && self.transition_edges(lane, idx) != before {";
1797+ let arm = body
1798+ .split_once(gate)
1799+ .unwrap_or_else(|| panic!("the transition arm no longer rides the join's own edges"))
1800+ .1;
1801+ assert!(
1802+ arm.contains("mark_dirty()"),
1803+ "the transition arm is outside its gate, so a step past the cap or a \
1804+ retyped number would dirty an unchanged project"
1805+ );
1806+ let before = body.split_once(gate).unwrap().0;
1807+ assert!(
1808+ !before.contains("mark_dirty()"),
1809+ "the transition arm is still ahead of the comparison"
1810+ );
1811+ assert!(
1812+ body.contains("let before = self.transition_edges(lane, idx);"),
1813+ "the join's edges are no longer read before the write"
1814+ );
1815+ // The helper both sides call, and the pair it must compare: an anchor-only
1816+ // comparison cannot see the neighbour's `fade_in` not moving.
1817+ let helper = fn_body("transition_edges");
1818+ assert!(
1819+ helper.contains("clips.get(idx)?.fade_out")
1820+ && helper.contains("clips.get(idx + 1)?.fade_in"),
1821+ "the edge reader no longer reads both sides of the join, so a \
1822+ crossfade that only moves the neighbour is invisible"
1823+ );
1824+}
1825+
1826+/// The three doors the action table used to arm on their behalf. The table
1827+/// fires *before* any door is asked, so an entry for a door that can refuse
1828+/// dirties an untouched project -- and the dissolve is the sharpest case,
1829+/// because the clip-menu row reaches [`Player::dissolve_selected`] directly
1830+/// ([`crate::ui::bench_stance`]) and so was armed by nothing at all while the
1831+/// key chord beside it armed on every press, refused or not.
1832+///
1833+/// The engine half of the premise is not a scan but a run: see
1834+/// `engine::project::tests::a_transition_door_says_yes_to_a_write_that_moved_nothing`,
1835+/// which drives `set_transition_out` and `crossfade` and shows they answer
1836+/// `true` for a write that changed nothing. That is why these three need a
1837+/// before/after comparison and not just the door's own answer.
1838+#[test]
1839+fn the_action_table_arms_nothing_a_door_answers_for_itself() {
1840+ // The two transition doors, in the same shape as the duration row's.
1841+ for (name, door) in [
1842+ ("crossfade_selected", "session.crossfade(lane, idx, frames)"),
1843+ (
1844+ "dissolve_selected",
1845+ "session.set_transition_out(lane, idx, frames)",
1846+ ),
1847+ ] {
1848+ let body = fn_body(name);
1849+ assert!(body.contains(door), "{name} no longer goes through {door}");
1850+ let gate = "if took && self.transition_edges(lane, idx) != before {";
1851+ let arm = body
1852+ .split_once(gate)
1853+ .unwrap_or_else(|| panic!("{name} no longer arms on the write that took"))
1854+ .1;
1855+ assert!(
1856+ arm.contains("mark_dirty()"),
1857+ "{name} arms outside its gate, so a crossfade already at the room \
1858+ the two clips offer would dirty an unchanged project"
1859+ );
1860+ let before = body.split_once(gate).unwrap().0;
1861+ assert!(
1862+ !before.contains("mark_dirty()"),
1863+ "{name} still arms ahead of the comparison"
1864+ );
1865+ }
1866+ // ...and the two actions are out of the table's list, or the key path is
1867+ // armed twice over and the menu path not at all.
1868+ let act = fn_body("act");
1869+ let listed = act
1870+ .split_once("if matches!(")
1871+ .unwrap()
1872+ .1
1873+ .split_once(") {")
1874+ .unwrap()
1875+ .0;
1876+ for gone in ["ActionId::Crossfade", "ActionId::Dissolve"] {
1877+ assert!(
1878+ !listed.contains(gone),
1879+ "{gone} is back in the pre-arm list, so the key path arms before \
1880+ the door is asked while the clip-menu row arms by nothing"
1881+ );
1882+ }
1883+ // The track removal, whose two callers are a key and a header button.
1884+ let body = fn_body("remove_lane");
1885+ let arm = body
1886+ .split_once("Some(Ok(())) => {")
1887+ .expect("the track door no longer answers which arm means the track went")
1888+ .1;
1889+ assert!(
1890+ arm.contains("mark_dirty()"),
1891+ "a track that went arms nothing, so the removal is invisible to \
1892+ autosave, the unsaved ghost and the close question"
1893+ );
1894+ // ...and the header door no longer arms on its own before asking, which
1895+ // would be a second arm for the same step.
1896+ let lane_act = fn_body("act_lane");
1897+ assert!(
1898+ !lane_act.contains("mark_dirty"),
1899+ "act_lane arms before remove_lane, so a track still holding clips \
1900+ refuses with the unsaved ghost already lit"
1901+ );
1902+ assert!(
1903+ lane_act.contains(
1904+ "ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => self.remove_lane(lane, cx)"
1905+ ),
1906+ "act_lane no longer routes the header's remove to the one armed door"
1907+ );
17131908 }
17141909
17151910 /// [`crate::ui::dock_stance::transition_of`]: the dock's duration row
@@ -1928,9 +2123,11 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() {
19282123 assert!(native_detail.ends_with(" source"), "{native_detail}");
19292124 // A project at a size nobody listed still gets the whole list, with
19302125 // nothing marked rather than a wrong row marked.
1931- assert!(resolution_choices((1000, 1000), native)
1932- .iter()
1933- .all(|(.., picked)| !picked));
2126+ assert!(
2127+ resolution_choices((1000, 1000), native)
2128+ .iter()
2129+ .all(|(.., picked)| !picked)
2130+ );
19342131 // Picking a row means that row, and stepping means the next one: the
19352132 // list and the stroke read the same ladder.
19362133 assert_eq!(next_resolution(ladder[1], native), ladder[2]);
@@ -2387,8 +2584,8 @@ fn maximizing_a_card_grows_its_box_without_moving_where_a_value_sits_in_it() {
23872584 /// inside the dock, or hands it the dock's width again, fails this.
23882585 #[test]
23892586 fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() {
2390- use crate::layout::{split_size, Split};
23912587 use crate::SPLIT_W;
2588+ use crate::layout::{Split, split_size};
23922589
23932590 // `layout::SPLIT_W` is the one divider between `stance-centre` and the
23942591 // dock; the 56px rail that used to eat the centre's left edge is gone
@@ -2435,7 +2632,7 @@ fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() {
24352632 /// assumption.
24362633 #[test]
24372634 fn a_maximized_card_can_never_rise_above_the_picture_no_matter_the_bench_height() {
2438- use crate::ui::stance::{below_picture_floor, LEDGER_H, TIME_BAND_H};
2635+ use crate::ui::stance::{LEDGER_H, TIME_BAND_H, below_picture_floor};
24392636 let viewport_h = 1080.;
24402637 for bench_h in [140., 200., 400.] {
24412638 assert_eq!(
crates/engine/src/project.rsmodified+506 -232
@@ -77,11 +77,11 @@ use crate::map::TimelineMap;
7777 use std::path::{Path, PathBuf};
7878
7979 use crate::color::ColorParams;
80-use crate::transform::TransformParams;
8180 use crate::eq::EqParams;
8281 use crate::limiter::{Limiter, db_to_linear};
8382 use crate::scale::FitPolicy;
8483 use crate::subtitle::{Cue as SubtitleCue, SubtitleTrack};
84+use crate::transform::TransformParams;
8585
8686 /// How far down a lane's own volume goes ([`Project::set_lane_gain_db`]).
8787 /// -60 dB is a thousandth of the amplitude -- a track that is out of the mix
@@ -1083,7 +1083,9 @@ impl Project {
10831083 return Err(format!("color {bad} holds a value that is not a finite number").into());
10841084 }
10851085 if let Some(bad) = transform.iter().position(|p| !transform_finite(p)) {
1086- return Err(format!("transform {bad} holds a value that is not a finite number").into());
1086+ return Err(
1087+ format!("transform {bad} holds a value that is not a finite number").into(),
1088+ );
10871089 }
10881090 if lanes.is_empty() {
10891091 return Err("no lanes at all: that is not a project".into());
@@ -1148,7 +1150,9 @@ impl Project {
11481150 )
11491151 .into());
11501152 }
1151- if c.transform.is_some_and(|i| usize::from(i) >= transform.len()) {
1153+ if c.transform
1154+ .is_some_and(|i| usize::from(i) >= transform.len())
1155+ {
11521156 return Err(format!(
11531157 "{name} clip at {} names transform {} of {}",
11541158 c.start,
@@ -1483,13 +1487,13 @@ impl Project {
14831487 let used: Vec<String> = handles(&self.lanes)
14841488 .into_iter()
14851489 .zip(&self.lanes)
1486- .filter_map(
1487- |(lane, data)| match data.clips.iter().filter(|c| c.source == idx).count() {
1490+ .filter_map(|(lane, data)| {
1491+ match data.clips.iter().filter(|c| c.source == idx).count() {
14881492 0 => None,
14891493 1 => Some(format!("{} (1 clip)", lane.label())),
14901494 n => Some(format!("{} ({n} clips)", lane.label())),
1491- },
1492- )
1495+ }
1496+ })
14931497 .collect();
14941498 if !used.is_empty() {
14951499 return Err(format!("{name} still plays on {}", used.join(", ")).into());
@@ -1982,7 +1986,9 @@ impl Project {
19821986 ..sub
19831987 };
19841988 if at.checked_add(sub.frames).is_none() {
1985- return Err(format!("a placement at frame {at} runs past the last frame there is").into());
1989+ return Err(
1990+ format!("a placement at frame {at} runs past the last frame there is").into(),
1991+ );
19861992 }
19871993 if let Some(other) = self.lanes[i]
19881994 .subs
@@ -2093,10 +2099,12 @@ impl Project {
20932099 let at = subs.partition_point(|o| o.start < moved.start);
20942100 subs.insert(at, moved);
20952101 debug_assert!(subs_sorted_disjoint(subs));
2096- debug_assert!(members
2097- .clips
2098- .iter()
2099- .all(|&(l, _)| sorted_disjoint(&self.lanes[l].clips)));
2102+ debug_assert!(
2103+ members
2104+ .clips
2105+ .iter()
2106+ .all(|&(l, _)| sorted_disjoint(&self.lanes[l].clips))
2107+ );
21002108 return Ok(());
21012109 }
21022110 let moved = SubClip { start, ..sub };
@@ -2209,7 +2217,13 @@ impl Project {
22092217 // clip's trim does: one delta, each member clamped to its own room.
22102218 // No source table to grow by, which only tightens how far a member may
22112219 // follow -- never whether it may.
2212- self.follow_group(&members, &(i, idx), edge, i64::from(to) - i64::from(at), &[]);
2220+ self.follow_group(
2221+ &members,
2222+ &(i, idx),
2223+ edge,
2224+ i64::from(to) - i64::from(at),
2225+ &[],
2226+ );
22132227 Ok(())
22142228 }
22152229
@@ -2230,7 +2244,10 @@ impl Project {
22302244 // what turns its two walls -- its own start, and its last cue -- into
22312245 // frames. A rate that is not a rate leaves the window where it is.
22322246 let frames_of = |us: i64| match fps.is_finite() && fps > 0.0 {
2233- true => ((us as f64) * fps / 1e6).round().max(0.0).min(f64::from(u32::MAX)) as u32,
2247+ true => ((us as f64) * fps / 1e6)
2248+ .round()
2249+ .max(0.0)
2250+ .min(f64::from(u32::MAX)) as u32,
22342251 false => 0,
22352252 };
22362253 Some(match edge {
@@ -2360,18 +2377,6 @@ impl Project {
23602377 true
23612378 }
23622379
2363-
2364-
2365-
2366-
2367-
2368-
2369-
2370-
2371-
2372-
2373-
2374-
23752380 /// What the clip at `idx` of `lane` plays through, or `None` for one that
23762381 /// plays flat (and for an index that is not there) -- what a feeder and an
23772382 /// export ask before they build an [`crate::eq::EqState`].
@@ -2489,7 +2494,12 @@ impl Project {
24892494 /// [`set_color`](Self::set_color)'s twin for [`Clip::transform`]: one undo
24902495 /// step, `false` (and no history) for an index that is not there or a
24912496 /// value that is not finite, and equal settings share a table entry.
2492- pub fn set_transform(&mut self, lane: Lane, idx: usize, params: Option<TransformParams>) -> bool {
2497+ pub fn set_transform(
2498+ &mut self,
2499+ lane: Lane,
2500+ idx: usize,
2501+ params: Option<TransformParams>,
2502+ ) -> bool {
24932503 self.write_transform(lane, idx, params, true)
24942504 }
24952505
@@ -2608,7 +2618,11 @@ impl Project {
26082618 let map = TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end())));
26092619 let start = map.apply(s.start);
26102620 let end = map.apply(s.end()).max(start.saturating_add(1));
2611- SubClip { start, frames: end - start, ..s }
2621+ SubClip {
2622+ start,
2623+ frames: end - start,
2624+ ..s
2625+ }
26122626 };
26132627 for &(l, i) in &members.clips {
26142628 let clips = &self.lanes[l].clips;
@@ -2686,8 +2700,7 @@ impl Project {
26862700 let held = self.lane(lane).get(idx).copied()?;
26872701 let (held_old, new) = (held.speed.as_f64(), speed.as_f64());
26882702 for &(l, i) in members.clips.iter().chain(&members.subs) {
2689- let (span, map) = match self
2690- .lanes[l]
2703+ let (span, map) = match self.lanes[l]
26912704 .clips
26922705 .get(i)
26932706 .filter(|_| members.clips.contains(&(l, i)))
@@ -2700,10 +2713,7 @@ impl Project {
27002713 (c.start, c.start + c.frames()),
27012714 TimelineMap::piece(
27022715 (c.start, c.start + c.frames()),
2703- (
2704- c.start,
2705- c.start + (c.len() as f64 / new).round() as u32,
2706- ),
2716+ (c.start, c.start + (c.len() as f64 / new).round() as u32),
27072717 ),
27082718 ),
27092719 // The caption's span, scaled about the held clip's head by
@@ -3235,7 +3245,10 @@ impl Project {
32353245 .iter()
32363246 .enumerate()
32373247 .map(|(i, l)| {
3238- on.contains(&i) && l.subs.iter().any(|s| s.start < timeline_frame && timeline_frame < s.end())
3248+ on.contains(&i)
3249+ && l.subs
3250+ .iter()
3251+ .any(|s| s.start < timeline_frame && timeline_frame < s.end())
32393252 })
32403253 .collect();
32413254 // The links the captions carry, read before the room is opened below
@@ -3288,8 +3301,10 @@ impl Project {
32883301 }
32893302 }
32903303 let fresh: Vec<u32> = (0..distinct.len()).map(|_| self.new_link()).collect();
3291- let right_of =
3292- |link: Option<u32>| link.and_then(|id| distinct.iter().position(|&d| d == id)).map(|at| fresh[at]);
3304+ let right_of = |link: Option<u32>| {
3305+ link.and_then(|id| distinct.iter().position(|&d| d == id))
3306+ .map(|at| fresh[at])
3307+ };
32933308 for (l, data) in self.lanes.iter_mut().enumerate() {
32943309 if !cut_subs[l] {
32953310 continue;
@@ -3299,7 +3314,11 @@ impl Project {
32993314 .subs
33003315 .iter()
33013316 .position(|s| s.end() == timeline_frame)
3302- .filter(|&idx| data.subs.get(idx + 1).is_some_and(|n| n.start == timeline_frame))
3317+ .filter(|&idx| {
3318+ data.subs
3319+ .get(idx + 1)
3320+ .is_some_and(|n| n.start == timeline_frame)
3321+ })
33033322 {
33043323 data.subs[idx].link = sub_orig[l];
33053324 data.subs[idx + 1].link = right_of(sub_orig[l]);
@@ -3308,7 +3327,9 @@ impl Project {
33083327 for (data_i, data) in self.lanes.iter_mut().enumerate() {
33093328 // The lanes this call was not scoped to are not cut, whatever their
33103329 // own clips would allow.
3311- let Some(idx) = splittable(&data.clips, timeline_frame).filter(|_| cut[data_i].is_some()) else {
3330+ let Some(idx) =
3331+ splittable(&data.clips, timeline_frame).filter(|_| cut[data_i].is_some())
3332+ else {
33123333 continue;
33133334 };
33143335 let mut tail = data.clips[idx];
@@ -3547,9 +3568,7 @@ impl Project {
35473568 } else {
35483569 "clip"
35493570 };
3550- return Err(
3551- format!("there is no {what} {idx} on {}", lane.label()).into()
3552- );
3571+ return Err(format!("there is no {what} {idx} on {}", lane.label()).into());
35533572 }
35543573 }
35553574 let links: Vec<Option<u32>> = picks
@@ -3573,8 +3592,16 @@ impl Project {
35733592 let labels = handles(&self.lanes);
35743593 let mut per_lane: std::collections::HashMap<usize, u32> = std::collections::HashMap::new();
35753594 for (li, data) in self.lanes.iter().enumerate() {
3576- let n = data.clips.iter().filter(|c| c.link.is_some() && links.contains(&c.link)).count()
3577- + data.subs.iter().filter(|s| s.link.is_some() && links.contains(&s.link)).count();
3595+ let n = data
3596+ .clips
3597+ .iter()
3598+ .filter(|c| c.link.is_some() && links.contains(&c.link))
3599+ .count()
3600+ + data
3601+ .subs
3602+ .iter()
3603+ .filter(|s| s.link.is_some() && links.contains(&s.link))
3604+ .count();
35783605 if n > 0 {
35793606 per_lane.insert(li, n as u32);
35803607 }
@@ -3866,13 +3893,9 @@ impl Project {
38663893 clips.insert(at, clip);
38673894 }
38683895 debug_assert!(sorted_disjoint(&self.lanes[dest].clips));
3869- debug_assert!(members
3870- .clips
3871- .iter()
3872- .chain(&members.subs)
3873- .all(|&(l, _)| {
3874- sorted_disjoint(&self.lanes[l].clips) && subs_sorted_disjoint(&self.lanes[l].subs)
3875- }));
3896+ debug_assert!(members.clips.iter().chain(&members.subs).all(|&(l, _)| {
3897+ sorted_disjoint(&self.lanes[l].clips) && subs_sorted_disjoint(&self.lanes[l].subs)
3898+ }));
38763899 true
38773900 }
38783901
@@ -4048,7 +4071,13 @@ impl Project {
40484071 Edge::End => c.out_frame = c.in_frame + keep,
40494072 }
40504073 debug_assert!(sorted_disjoint(&self.lanes[held].clips));
4051- self.follow_group(&members, &(held, idx), edge, i64::from(to) - i64::from(at), source_frames);
4074+ self.follow_group(
4075+ &members,
4076+ &(held, idx),
4077+ edge,
4078+ i64::from(to) - i64::from(at),
4079+ source_frames,
4080+ );
40524081 true
40534082 }
40544083
@@ -4144,13 +4173,7 @@ impl Project {
41444173 /// [`trim_room`](Project::trim_room) for a clip the caller already holds by
41454174 /// its lane's storage index: the one wall computation, asked for the clip
41464175 /// itself and for each member a group trim carries.
4147- fn clip_room(
4148- &self,
4149- l: usize,
4150- i: usize,
4151- edge: Edge,
4152- source_frames: &[u32],
4153- ) -> (u32, u32) {
4176+ fn clip_room(&self, l: usize, i: usize, edge: Edge, source_frames: &[u32]) -> (u32, u32) {
41544177 let clips = &self.lanes[l].clips;
41554178 let c = clips[i];
41564179 let (lo, hi) = match edge {
@@ -4606,13 +4629,11 @@ impl Project {
46064629 let mut report = GapSweep::default();
46074630 let mut snapshot = false;
46084631 for (start, frames) in gaps(self.lane(lane)).into_iter().rev() {
4609- match self
4610- .gap_take_scope(lane, start, frames)
4611- .and_then(|scope| {
4612- let on = self.scoped(&scope)?;
4613- self.scope_holds_takes_whole(&on, start)?;
4614- Ok(on)
4615- }) {
4632+ match self.gap_take_scope(lane, start, frames).and_then(|scope| {
4633+ let on = self.scoped(&scope)?;
4634+ self.scope_holds_takes_whole(&on, start)?;
4635+ Ok(on)
4636+ }) {
46164637 Ok(on) => {
46174638 if !snapshot {
46184639 self.snapshot();
@@ -5085,7 +5106,10 @@ impl Project {
50855106 pub(crate) fn parts(&self) -> SweepParts {
50865107 SweepParts(
50875108 self.sources.len(),
5088- self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(),
5109+ self.lanes
5110+ .iter()
5111+ .map(|l| (l.kind, l.clips.clone()))
5112+ .collect(),
50895113 self.lanes.iter().map(|l| l.subs.clone()).collect(),
50905114 self.subtitles.clone(),
50915115 self.settings.clone(),
@@ -5373,7 +5397,6 @@ impl Project {
53735397 self.next_link = self.next_link.saturating_add(1);
53745398 id
53755399 }
5376-
53775400 }
53785401
53795402 /// The handle of every lane, in storage order -- the one definition of what
@@ -5451,7 +5474,9 @@ impl GapPlacement for SubClip {
54515474 /// Index of the placement covering `frame`, or `None` for a gap or past the
54525475 /// end. Binary search: the sorted-disjoint invariant is what makes it legal.
54535476 fn at<T: GapPlacement>(items: &[T], frame: u32) -> Option<usize> {
5454- let idx = items.partition_point(|item| item.start_frame() <= frame).checked_sub(1)?;
5477+ let idx = items
5478+ .partition_point(|item| item.start_frame() <= frame)
5479+ .checked_sub(1)?;
54555480 (frame < items[idx].end_frame()).then_some(idx)
54565481 }
54575482
@@ -5667,10 +5692,7 @@ fn sub_joinable(subs: &[SubClip], frame: u32) -> Option<usize> {
56675692 fn sub_edge_room(subs: &[SubClip], idx: usize, edge: Edge) -> (u32, u32) {
56685693 let s = &subs[idx];
56695694 match edge {
5670- Edge::Start => (
5671- idx.checked_sub(1).map_or(0, |p| subs[p].end()),
5672- s.end() - 1,
5673- ),
5695+ Edge::Start => (idx.checked_sub(1).map_or(0, |p| subs[p].end()), s.end() - 1),
56745696 Edge::End => (s.start + 1, subs.get(idx + 1).map_or(u32::MAX, |n| n.start)),
56755697 }
56765698 }
@@ -5737,11 +5759,9 @@ fn links_are_consistent(lanes: &[LaneData]) -> crate::Result<()> {
57375759 for (i, s) in data.subs.iter().enumerate() {
57385760 let Some(id) = s.link else { continue };
57395761 if data.subs[..i].iter().any(|prev| prev.link == Some(id)) {
5740- return Err(format!(
5741- "link {id} names two captions in the {} lane",
5742- lane.label()
5743- )
5744- .into());
5762+ return Err(
5763+ format!("link {id} names two captions in the {} lane", lane.label()).into(),
5764+ );
57455765 }
57465766 }
57475767 }
@@ -6090,7 +6110,11 @@ mod tests {
60906110 (f.gain_at(5) - midpoint.sin()).abs() < 1e-6,
60916111 "equal-power midpoint is sin(pi/4)"
60926112 );
6093- assert_eq!(f.gain_at(20), 1.0, "unchanged in the body, past either ramp");
6113+ assert_eq!(
6114+ f.gain_at(20),
6115+ 1.0,
6116+ "unchanged in the body, past either ramp"
6117+ );
60946118 // The fade-out is the same curve, mirrored, counting down from the
60956119 // clip's end: unity at the frame the ramp starts, the same
60966120 // equal-power midpoint, and -- since `total` itself is one past the
@@ -6114,14 +6138,8 @@ mod tests {
61146138 fn crossfade_only_joins_adjacent_audio_clips() {
61156139 let mut p = Project::single(FILE, 20);
61166140 assert!(p.split(10));
6117- assert!(
6118- !p.crossfade(Lane::V1, 0, 5),
6119- "video is not an audio lane"
6120- );
6121- assert!(
6122- !p.crossfade(Lane::A1, 1, 5),
6123- "there is no clip after idx 1"
6124- );
6141+ assert!(!p.crossfade(Lane::V1, 0, 5), "video is not an audio lane");
6142+ assert!(!p.crossfade(Lane::A1, 1, 5), "there is no clip after idx 1");
61256143 assert!(p.crossfade(Lane::A1, 0, 5), "the two halves are adjacent");
61266144 let a = p.lane(Lane::A1);
61276145 assert_eq!(a[0].fade_out, 5);
@@ -6148,10 +6166,16 @@ mod tests {
61486166 assert!(p.set_fade_out(Lane::V1, 0, 15));
61496167 assert!(p.split(5));
61506168 let v = p.lane(Lane::V1);
6151- assert_eq!(v[0].fade_in, 5, "the left half's kept fade-in, clamped to 5 frames");
6169+ assert_eq!(
6170+ v[0].fade_in, 5,
6171+ "the left half's kept fade-in, clamped to 5 frames"
6172+ );
61526173 assert_eq!(v[0].fade_out, 0, "the cut edge it made starts flat");
61536174 assert_eq!(v[1].fade_in, 0, "the cut edge it made starts flat");
6154- assert_eq!(v[1].fade_out, 15, "the right half's kept fade-out, unclamped: 15 frames fit in 15");
6175+ assert_eq!(
6176+ v[1].fade_out, 15,
6177+ "the right half's kept fade-out, unclamped: 15 frames fit in 15"
6178+ );
61556179 }
61566180
61576181 /// [`Project::set_transition_out`] refuses a non-video lane, a clip with
@@ -6187,6 +6211,55 @@ mod tests {
61876211 assert!(!p2.set_transition_out(v2, 0, 5), "a gap is not adjacent");
61886212 }
61896213
6214+ /// The two transition doors' bool is the WEAK shape, stated here as
6215+ /// behaviour rather than left as something a front-end has to know: both
6216+ /// answer "these two clips are adjacent", and both snapshot and clamp --
6217+ /// so a write that lands the value the join already carries is still
6218+ /// reported as a write, and still spends an undo step. This is the fact
6219+ /// `Player::transition_edges`'s before/after comparison exists to cover,
6220+ /// and the fact a UI test can only reach through a source scan: driving
6221+ /// the front-end needs a window this crate has no harness for, so the
6222+ /// door's own answer is pinned here, where it can be run.
6223+ #[test]
6224+ fn a_transition_door_says_yes_to_a_write_that_moved_nothing() {
6225+ let mut p = Project::single(FILE, 20);
6226+ assert!(p.split(10), "two halves to join");
6227+ assert!(p.set_transition_out(Lane::V1, 0, 5), "the dissolve lands");
6228+ assert!(p.crossfade(Lane::A1, 0, 5), "the crossfade lands");
6229+ let history = p.history.len();
6230+
6231+ // The very same numbers again: nothing moved, and both doors report a
6232+ // write anyway.
6233+ assert!(
6234+ p.set_transition_out(Lane::V1, 0, 5),
6235+ "set_transition_out answers 'the clips are adjacent', not 'the \
6236+ dissolve moved', so a no-op reads as a write"
6237+ );
6238+ assert!(
6239+ p.crossfade(Lane::A1, 0, 5),
6240+ "crossfade answers the same way for the same reason"
6241+ );
6242+ assert_eq!(
6243+ p.history.len(),
6244+ history + 2,
6245+ "and each spent an undo step saying so, which is why the \
6246+ front-end compares the join's own edges before it arms"
6247+ );
6248+
6249+ // What did not move -- the comparison the front-end makes: both edges
6250+ // a crossfade writes, and the dissolve itself.
6251+ let a = p.lane(Lane::A1);
6252+ assert_eq!((a[0].fade_out, a[1].fade_in), (5, 5), "unchanged");
6253+ assert_eq!(p.transition_out_of(Lane::V1, 0), 5, "unchanged");
6254+
6255+ // And a refusal still answers no, so the arm is not simply always on:
6256+ // the last clip has no successor to dissolve into.
6257+ assert!(
6258+ !p.set_transition_out(Lane::V1, 1, 5),
6259+ "no neighbour end to end"
6260+ );
6261+ }
6262+
61906263 /// The rule [`Project::write_split`] follows for [`Clip::transition_out`],
61916264 /// same shape as [`a_split_clamps_the_kept_fade_and_zeroes_the_cut_edge`]:
61926265 /// only the half that kept the clip's original *end* keeps the dissolve,
@@ -6203,7 +6276,10 @@ mod tests {
62036276 p.lane_mut(Lane::V1).unwrap()[0].transition_out = 15;
62046277 assert!(p.split(5));
62056278 let v = p.lane(Lane::V1);
6206- assert_eq!(v[0].transition_out, 0, "the cut edge it made has no successor");
6279+ assert_eq!(
6280+ v[0].transition_out, 0,
6281+ "the cut edge it made has no successor"
6282+ );
62076283 assert_eq!(
62086284 v[1].transition_out, 15,
62096285 "the tail's kept dissolve, unclamped: 15 frames fit in 15"
@@ -6451,11 +6527,7 @@ mod tests {
64516527 p.group_all(&[(Lane::V1, 0), (v2, 0)])
64526528 .expect("the clips group");
64536529 let minted = p.lane(Lane::V1)[0].link.expect("grouped");
6454- assert_ne!(
6455- minted,
6456- 1,
6457- "the caption's id is not re-issued to clips"
6458- );
6530+ assert_ne!(minted, 1, "the caption's id is not re-issued to clips");
64596531 assert_eq!(
64606532 p.sub_lane(Lane::new(LaneKind::Subtitle, 0))[0].link,
64616533 Some(1),
@@ -6501,8 +6573,16 @@ mod tests {
65016573 .expect("room for it");
65026574 assert_eq!(p.lane(Lane::V1)[0].frames(), 45);
65036575 let s = p.sub_lane(s1)[0];
6504- assert_eq!((s.start, s.frames), (0, 45), "same words, half the timeline");
6505- assert_eq!((s.in_us, s.out_us), (0, 90_000_000), "the window is untouched");
6576+ assert_eq!(
6577+ (s.start, s.frames),
6578+ (0, 45),
6579+ "same words, half the timeline"
6580+ );
6581+ assert_eq!(
6582+ (s.in_us, s.out_us),
6583+ (0, 90_000_000),
6584+ "the window is untouched"
6585+ );
65066586 assert!(links_are_consistent(&p.lanes).is_ok());
65076587 assert!(p.undo());
65086588 assert_eq!(p.sub_lane(s1)[0].frames, 90, "one undo puts it back");
@@ -6518,8 +6598,16 @@ mod tests {
65186598 .expect("room for it");
65196599 assert_eq!(p.lane(Lane::V1)[0].frames(), 180);
65206600 let s = p.sub_lane(s1)[0];
6521- assert_eq!((s.start, s.frames), (60, 120), "the offset doubles with the clip");
6522- assert_eq!(s.end(), p.lane(Lane::V1)[0].end(), "still ends with the clip");
6601+ assert_eq!(
6602+ (s.start, s.frames),
6603+ (60, 120),
6604+ "the offset doubles with the clip"
6605+ );
6606+ assert_eq!(
6607+ s.end(),
6608+ p.lane(Lane::V1)[0].end(),
6609+ "still ends with the clip"
6610+ );
65236611
65246612 // A stretch that runs the caption into its neighbour is refused, by
65256613 // lane and frame, and costs no undo step.
@@ -6534,7 +6622,9 @@ mod tests {
65346622 .unwrap_err()
65356623 .to_string();
65366624 assert!(
6537- err.contains("the S1 caption at frame 0 would run to frame 180 and the next starts at 95"),
6625+ err.contains(
6626+ "the S1 caption at frame 0 would run to frame 180 and the next starts at 95"
6627+ ),
65386628 "{err}"
65396629 );
65406630 assert_eq!(p.history.len(), history, "a refusal costs no undo step");
@@ -6669,7 +6759,8 @@ mod tests {
66696759 // An odd-length caption straddling the clip's tail edge: its
66706760 // own last frame lands past the held clip.
66716761 let c_start = len.saturating_sub(3);
6672- p.place_sub(s1, c_start, caption(c_start, 7)).expect("placed");
6762+ p.place_sub(s1, c_start, caption(c_start, 7))
6763+ .expect("placed");
66736764 p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");
66746765 let speed = Speed::from_permille(permille);
66756766 let last = c_start + 7 - 1;
@@ -6804,8 +6895,7 @@ mod tests {
68046895 refused: None,
68056896 };
68066897 // A timeline of words alone: 60 frames of caption, no media clips.
6807- let mut p = Project::single(FILE, 60)
6808- .with_subtitles(vec![track()]);
6898+ let mut p = Project::single(FILE, 60).with_subtitles(vec![track()]);
68096899 for l in [Lane::V1, Lane::A1] {
68106900 while !p.lane(l).is_empty() {
68116901 p.lift(l, 0);
@@ -6871,16 +6961,31 @@ mod tests {
68716961 .expect("the region speeds up");
68726962 // Adjacent one-frame cues: both map to frame 5, and are forced apart.
68736963 let spans = |p: &Project, lane: Lane| -> Vec<(u32, u32)> {
6874- p.sub_lane(lane).iter().map(|s| (s.start, s.frames)).collect()
6964+ p.sub_lane(lane)
6965+ .iter()
6966+ .map(|s| (s.start, s.frames))
6967+ .collect()
68756968 };
6876- assert_eq!(spans(&p, lanes[0]), [(5, 1), (6, 1)], "one frame each, in order");
6969+ assert_eq!(
6970+ spans(&p, lanes[0]),
6971+ [(5, 1), (6, 1)],
6972+ "one frame each, in order"
6973+ );
68776974 // The three-frame pair: [5, 8) and [8, 11) map to [3, 5) and [4, 6),
68786975 // and the walk pushes the second to where the first ends.
6879- assert_eq!(spans(&p, lanes[1]), [(3, 1), (4, 2)], "forced apart, kept in order");
6976+ assert_eq!(
6977+ spans(&p, lanes[1]),
6978+ [(3, 1), (4, 2)],
6979+ "forced apart, kept in order"
6980+ );
68806981 // The last cue of the region ends exactly where the region now does
68816982 // (frame 15), and the caption behind it lands on that same frame:
68826983 // touching, never overlapping.
6883- assert_eq!(spans(&p, lanes[2]), [(14, 1), (15, 15)], "the cue ends with the region");
6984+ assert_eq!(
6985+ spans(&p, lanes[2]),
6986+ [(14, 1), (15, 15)],
6987+ "the cue ends with the region"
6988+ );
68846989 for &lane in &lanes {
68856990 assert!(subs_sorted_disjoint(&p.lanes[p.index(lane).unwrap()].subs));
68866991 }
@@ -6968,17 +7073,24 @@ mod tests {
69687073 // Too few, one lane twice, and an index that is not there: words, no
69697074 // snapshot.
69707075 let history = p.history.len();
6971- assert!(p.group_all(&[]).unwrap_err().to_string().contains("two placements or more"));
6972- assert!(p
6973- .group_all(&[(Lane::V1, 0), (Lane::V1, 0)])
6974- .unwrap_err()
6975- .to_string()
6976- .contains("V1 is picked twice"));
6977- assert!(p
6978- .group_all(&[(Lane::V1, 0), (s1, 9)])
6979- .unwrap_err()
6980- .to_string()
6981- .contains("no subtitle 9"));
7076+ assert!(
7077+ p.group_all(&[])
7078+ .unwrap_err()
7079+ .to_string()
7080+ .contains("two placements or more")
7081+ );
7082+ assert!(
7083+ p.group_all(&[(Lane::V1, 0), (Lane::V1, 0)])
7084+ .unwrap_err()
7085+ .to_string()
7086+ .contains("V1 is picked twice")
7087+ );
7088+ assert!(
7089+ p.group_all(&[(Lane::V1, 0), (s1, 9)])
7090+ .unwrap_err()
7091+ .to_string()
7092+ .contains("no subtitle 9")
7093+ );
69827094 assert_eq!(p.history.len(), history, "refusals cost no undo step");
69837095
69847096 // The group: the picture, the layer, and the caption -- and the sound
@@ -6987,7 +7099,12 @@ mod tests {
69877099 .expect("three picks, three lanes");
69887100 let id = p.lane(Lane::V1)[0].link.expect("grouped");
69897101 for lane in [Lane::V1, Lane::A1, v2] {
6990- assert_eq!(p.lane(lane)[0].link, Some(id), "{} rides along", lane.label());
7102+ assert_eq!(
7103+ p.lane(lane)[0].link,
7104+ Some(id),
7105+ "{} rides along",
7106+ lane.label()
7107+ );
69917108 }
69927109 assert_eq!(p.sub_lane(s1)[0].link, Some(id), "the caption is a member");
69937110 assert_eq!(p.sub_lane(s1)[0].frames, 6, "its own span, kept");
@@ -7053,7 +7170,11 @@ mod tests {
70537170 .to_string();
70547171 assert!(err.contains("one placement per lane"), "{err}");
70557172 assert_eq!(p.history.len(), history, "the refusal costs no undo step");
7056- assert_eq!(p.lane(Lane::V1)[0].link, v1_link, "the first group untouched");
7173+ assert_eq!(
7174+ p.lane(Lane::V1)[0].link,
7175+ v1_link,
7176+ "the first group untouched"
7177+ );
70577178 assert_eq!(p.lane(v2)[0].link, v2_link, "the second group untouched");
70587179 assert!(links_are_consistent(&p.lanes).is_ok());
70597180 }
@@ -7138,8 +7259,15 @@ mod tests {
71387259 // By the picture or by the caption, the same whole-group delete.
71397260 assert!(p.delete_sub_in(s1, 0));
71407261 assert!(p.lane(Lane::V1).is_empty(), "the take's span left V1");
7141- assert!(p.sub_lane(s1).is_empty(), "the caption's span left its lane");
7142- assert_eq!(p.lane(v2)[0].start, 10, "a lane the group does not touch stays");
7262+ assert!(
7263+ p.sub_lane(s1).is_empty(),
7264+ "the caption's span left its lane"
7265+ );
7266+ assert_eq!(
7267+ p.lane(v2)[0].start,
7268+ 10,
7269+ "a lane the group does not touch stays"
7270+ );
71437271 assert!(links_are_consistent(&p.lanes).is_ok());
71447272 assert!(p.undo(), "one step puts the group back");
71457273 assert_eq!(p.sub_lane(s1)[0].start, 2, "offsets and all");
@@ -7175,8 +7303,10 @@ mod tests {
71757303 let group = || {
71767304 let mut p = Project::single(FILE, 90).with_subtitles(vec![track()]);
71777305 let s1 = p.add_lane(LaneKind::Subtitle);
7178- p.place_sub(s1, 30, caption(30, 30)).expect("the group's caption");
7179- p.place_sub(s1, 90, caption(90, 30)).expect("the caption behind");
7306+ p.place_sub(s1, 30, caption(30, 30))
7307+ .expect("the group's caption");
7308+ p.place_sub(s1, 90, caption(90, 30))
7309+ .expect("the caption behind");
71807310 p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");
71817311 (p, s1)
71827312 };
@@ -7192,7 +7322,11 @@ mod tests {
71927322 "the caption's lane closed by its own span: the follower slid up"
71937323 );
71947324 assert!(p.undo(), "one step");
7195- assert_eq!(p.sub_lane(s1).len(), 2, "both captions back, offsets and all");
7325+ assert_eq!(
7326+ p.sub_lane(s1).len(),
7327+ 2,
7328+ "both captions back, offsets and all"
7329+ );
71967330
71977331 // By the sound: the same whole-group delete.
71987332 let (mut p, s1) = group();
@@ -7204,7 +7338,11 @@ mod tests {
72047338 let (mut p, s1) = group();
72057339 assert!(p.delete_sub_in(s1, 0));
72067340 assert!(p.lane(Lane::V1).is_empty() && p.lane(Lane::A1).is_empty());
7207- assert_eq!(p.sub_lane(s1)[0].start, 60, "closed from the caption's own door");
7341+ assert_eq!(
7342+ p.sub_lane(s1)[0].start,
7343+ 60,
7344+ "closed from the caption's own door"
7345+ );
72087346 assert!(links_are_consistent(&p.lanes).is_ok());
72097347
72107348 // A caption lifted ALONE still leaves its gap: the ungrouped law,
@@ -7213,7 +7351,8 @@ mod tests {
72137351 assert!(p.ungroup(s1, 0), "the caption stands alone");
72147352 assert!(p.lift_sub(s1, 0));
72157353 assert_eq!(
7216- p.sub_lane(s1)[0].start, 90,
7354+ p.sub_lane(s1)[0].start,
7355+ 90,
72177356 "the follower stayed put: a lone caption's lift is a gap"
72187357 );
72197358 }
@@ -7248,7 +7387,11 @@ mod tests {
72487387 // Same lane, further along: everyone moves by the same eight frames.
72497388 p.move_sub(s1, 0, s1, 10).expect("room for all of it");
72507389 assert_eq!(p.sub_lane(s1)[0].start, 10);
7251- assert_eq!(p.lane(Lane::V1)[0].start, 8, "the clip follows by the delta");
7390+ assert_eq!(
7391+ p.lane(Lane::V1)[0].start,
7392+ 8,
7393+ "the clip follows by the delta"
7394+ );
72527395 assert!(links_are_consistent(&p.lanes).is_ok());
72537396
72547397 // ...and an ungrouped caption is the caption it always was.
@@ -7257,11 +7400,12 @@ mod tests {
72577400 let s1 = q.add_lane(LaneKind::Subtitle);
72587401 q.place_sub(s1, 0, caption(0, 4)).expect("placed");
72597402 q.place_sub(s1, 5, caption(5, 4)).expect("placed");
7260- assert!(q
7261- .move_sub(s1, 0, s1, 3)
7262- .unwrap_err()
7263- .to_string()
7264- .contains("already covers"));
7403+ assert!(
7404+ q.move_sub(s1, 0, s1, 3)
7405+ .unwrap_err()
7406+ .to_string()
7407+ .contains("already covers")
7408+ );
72657409 }
72667410
72677411 /// A trim carries a group's caption by the same delta as its clips, clamped
@@ -7478,8 +7622,14 @@ mod tests {
74787622 // The clipboard's clamp lives in `PlaybackSession::paste_at`.
74797623 assert!(p.paste(1_000, PASTED));
74807624 assert_eq!(p.timeline_frames(), 1_002);
7481- assert_eq!(p.lane(Lane::V1).last().expect("the pasted clip").start, 1_000);
7482- assert_eq!(p.lane(Lane::A1).last().expect("its other half").start, 1_000);
7625+ assert_eq!(
7626+ p.lane(Lane::V1).last().expect("the pasted clip").start,
7627+ 1_000
7628+ );
7629+ assert_eq!(
7630+ p.lane(Lane::A1).last().expect("its other half").start,
7631+ 1_000
7632+ );
74837633
74847634 // An empty clip is the one thing refused, and it pushes no history.
74857635 let mut p = three();
@@ -7681,7 +7831,8 @@ mod tests {
76817831 assert!(p.lift(Lane::V1, 0));
76827832 let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();
76837833 assert_eq!(sources.len(), 1, "source 0 survives an emptied timeline");
7684- let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("an empty project loads");
7834+ let back = Project::from_parts(sources, lanes, eq, color, Vec::new())
7835+ .expect("an empty project loads");
76857836 assert_eq!(back.timeline_frames(), 0);
76867837 assert_eq!(back.lanes().len(), 2, "and it kept its lanes");
76877838 }
@@ -7789,7 +7940,10 @@ mod tests {
77897940 assert!(p.lane(v2).is_empty());
77907941
77917942 // Refusals cost nothing: sound placed alone is `place`'s door.
7792- assert!(!p.place_take(Lane::A1, 0, clip(0, 100, 102, 0)), "audio lane");
7943+ assert!(
7944+ !p.place_take(Lane::A1, 0, clip(0, 100, 102, 0)),
7945+ "audio lane"
7946+ );
77937947 assert!(!p.place_take(v2, 0, clip(0, 7, 7, 0)), "empty clip");
77947948 assert!(
77957949 !p.place_take(Lane::new(LaneKind::Video, 9), 0, clip(0, 1, 2, 0)),
@@ -7855,7 +8009,8 @@ mod tests {
78558009 (LaneKind::Video, vec![clip(0, 0, 3, 0), clip(10, 3, 6, 0)]),
78568010 (LaneKind::Audio, vec![clip(0, 0, 3, 0)]),
78578011 ];
7858- let mut p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
8012+ let mut p =
8013+ Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
78598014 let before = shape(&p);
78608015
78618016 // Into the gap, exactly where it was let go -- nothing else moves.
@@ -8167,7 +8322,10 @@ mod tests {
81678322 assert_eq!(p.gap_at(v, 8), None);
81688323 assert_eq!(p.gap_at(v, 100), None);
81698324
8170- assert!(p.place(v, 12, clip(12, 0, 2, 0)), "a second clip at [12,14)");
8325+ assert!(
8326+ p.place(v, 12, clip(12, 0, 2, 0)),
8327+ "a second clip at [12,14)"
8328+ );
81718329 // Between the two: the gap [8,12).
81728330 assert_eq!(p.gap_at(v, 8), Some((8, 4)));
81738331 assert_eq!(p.gap_at(v, 11), Some((8, 4)));
@@ -8177,7 +8335,11 @@ mod tests {
81778335 p.place(v, 8, clip(8, 0, 4, 0)),
81788336 "fills [8,12) exactly, meeting both neighbours"
81798337 );
8180- assert_eq!(p.gap_at(v, 8), None, "adjacent clips leave no frame to name a gap");
8338+ assert_eq!(
8339+ p.gap_at(v, 8),
8340+ None,
8341+ "adjacent clips leave no frame to name a gap"
8342+ );
81818343 assert_eq!(p.gap_at(v, 11), None);
81828344 }
81838345
@@ -8200,7 +8362,11 @@ mod tests {
82008362 assert_eq!((start, len), (0, 5));
82018363 assert!(p.cut_regions(&[(start, len)], &[v]).is_ok());
82028364 assert_eq!(p.lane(v)[0].start, 0, "the clip slid back to close the gap");
8203- assert_eq!(p.lane(a)[0].start, 0, "the untouched lane's clip did not move");
8365+ assert_eq!(
8366+ p.lane(a)[0].start,
8367+ 0,
8368+ "the untouched lane's clip did not move"
8369+ );
82048370 assert!(p.undo(), "one press undoes the whole close");
82058371 assert_eq!(shape(&p), before, "back to exactly where it was");
82068372 }
@@ -8238,11 +8404,21 @@ mod tests {
82388404 let sources = vec![Source::new(FILE, 0)];
82398405 let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];
82408406 let audio = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];
8241- let mut p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())
8242- .expect("valid parts");
8407+ let mut p = Project::from_parts(
8408+ sources,
8409+ two(video, audio),
8410+ Vec::new(),
8411+ Vec::new(),
8412+ Vec::new(),
8413+ )
8414+ .expect("valid parts");
82438415 let before = shape(&p);
82448416 assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));
8245- assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 2)), "the same stretch is empty on A1 too");
8417+ assert_eq!(
8418+ p.gap_at(Lane::A1, 3),
8419+ Some((3, 2)),
8420+ "the same stretch is empty on A1 too"
8421+ );
82468422
82478423 let scope = p
82488424 .gap_take_scope(Lane::V1, 3, 2)
@@ -8252,7 +8428,11 @@ mod tests {
82528428
82538429 assert!(p.cut_regions(&[(3, 2)], &scope).is_ok());
82548430 assert_eq!(p.lane(Lane::V1)[1].start, 3, "V1's far half slid back");
8255- assert_eq!(p.lane(Lane::A1)[1].start, 3, "A1's far half rode along, in sync");
8431+ assert_eq!(
8432+ p.lane(Lane::A1)[1].start,
8433+ 3,
8434+ "A1's far half rode along, in sync"
8435+ );
82568436 assert!(p.undo(), "one press undoes the whole close");
82578437 assert_eq!(shape(&p), before, "back to exactly where it was");
82588438 }
@@ -8270,8 +8450,14 @@ mod tests {
82708450 // shorter than V1's [3,5) -- a legal offset-preserving group, and
82718451 // still one take.
82728452 let audio = vec![linked(0, 0, 3, 1), linked(4, 5, 9, 3)];
8273- let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())
8274- .expect("valid parts");
8453+ let p = Project::from_parts(
8454+ sources,
8455+ two(video, audio),
8456+ Vec::new(),
8457+ Vec::new(),
8458+ Vec::new(),
8459+ )
8460+ .expect("valid parts");
82758461 assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));
82768462 assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 1)), "a shorter gap on A1");
82778463
@@ -8293,10 +8479,20 @@ mod tests {
82938479 // A1 plays through the whole span as one continuous clip, sharing
82948480 // V1's first-half link: nothing empty at frame 3 there at all.
82958481 let audio = vec![linked(0, 0, 9, 1)];
8296- let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())
8297- .expect("valid parts");
8482+ let p = Project::from_parts(
8483+ sources,
8484+ two(video, audio),
8485+ Vec::new(),
8486+ Vec::new(),
8487+ Vec::new(),
8488+ )
8489+ .expect("valid parts");
82988490 assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));
8299- assert_eq!(p.gap_at(Lane::A1, 3), None, "A1 plays through, no gap there");
8491+ assert_eq!(
8492+ p.gap_at(Lane::A1, 3),
8493+ None,
8494+ "A1 plays through, no gap there"
8495+ );
83008496
83018497 let err = p
83028498 .gap_take_scope(Lane::V1, 3, 2)
@@ -8306,7 +8502,6 @@ mod tests {
83068502 assert!(err.contains("detach"), "{err}");
83078503 }
83088504
8309-
83108505 /// The sweep is the single-gap close repeated on one lane, but measured once
83118506 /// and applied from the right. The differing gap lengths here expose a
83128507 /// front-to-back bug: the last clip would be cut against a stale frame after
@@ -8342,14 +8537,20 @@ mod tests {
83428537 let v = p.add_lane(LaneKind::Video);
83438538 let history = p.history.len();
83448539 let report = p.close_all_gaps_on_lane(v).expect("empty lane exists");
8345- assert_eq!(report, GapSweep::default(), "an empty lane has no bounded gap");
8540+ assert_eq!(
8541+ report,
8542+ GapSweep::default(),
8543+ "an empty lane has no bounded gap"
8544+ );
83468545 assert_eq!(p.history.len(), history, "no undo step for a no-op");
83478546
83488547 let mut p = Project::single(FILE, 9);
83498548 let v = p.add_lane(LaneKind::Video);
83508549 assert!(p.place(v, 5, clip(5, 0, 3, 0)));
83518550 let before = shape(&p);
8352- let report = p.close_all_gaps_on_lane(v).expect("single clip lane exists");
8551+ let report = p
8552+ .close_all_gaps_on_lane(v)
8553+ .expect("single clip lane exists");
83538554 assert_eq!(report.closed, 1, "the head gap closes");
83548555 assert_eq!(p.lane(v), &[clip(0, 0, 3, 0)]);
83558556 assert!(p.undo());
@@ -8366,7 +8567,11 @@ mod tests {
83668567 assert!(p.place(v, 0, clip(0, 0, 3, 0)));
83678568 let history = p.history.len();
83688569 let report = p.close_all_gaps_on_lane(v).expect("tail-only lane exists");
8369- assert_eq!(report, GapSweep::default(), "the open-ended tail is not closed");
8570+ assert_eq!(
8571+ report,
8572+ GapSweep::default(),
8573+ "the open-ended tail is not closed"
8574+ );
83708575 assert_eq!(p.lane(v), &[clip(0, 0, 3, 0)]);
83718576 assert_eq!(p.history.len(), history);
83728577 }
@@ -8377,19 +8582,16 @@ mod tests {
83778582 #[test]
83788583 fn close_all_gaps_on_one_lane_partially_closes_linked_takes_and_reports_skips() {
83798584 let sources = vec![Source::new(FILE, 0)];
8380- let video = vec![
8381- linked(0, 0, 2, 1),
8382- linked(4, 4, 6, 2),
8383- clip(9, 9, 11, 0),
8384- ];
8385- let audio = vec![
8386- linked(0, 0, 2, 1),
8387- linked(4, 4, 6, 2),
8388- clip(8, 8, 11, 0),
8389- ];
8390- let mut p =
8391- Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())
8392- .expect("valid parts");
8585+ let video = vec![linked(0, 0, 2, 1), linked(4, 4, 6, 2), clip(9, 9, 11, 0)];
8586+ let audio = vec![linked(0, 0, 2, 1), linked(4, 4, 6, 2), clip(8, 8, 11, 0)];
8587+ let mut p = Project::from_parts(
8588+ sources,
8589+ two(video, audio),
8590+ Vec::new(),
8591+ Vec::new(),
8592+ Vec::new(),
8593+ )
8594+ .expect("valid parts");
83938595 let before = shape(&p);
83948596
83958597 let report = p.close_all_gaps_on_lane(Lane::V1).expect("V1 exists");
@@ -8397,12 +8599,27 @@ mod tests {
83978599 assert_eq!(report.skipped.len(), 1);
83988600 assert_eq!(report.skipped[0].start, 6);
83998601 assert!(report.skipped[0].reason.contains("A1"), "{report:?}");
8400- assert!(report.skipped[0].reason.contains("out of sync"), "{report:?}");
8602+ assert!(
8603+ report.skipped[0].reason.contains("out of sync"),
8604+ "{report:?}"
8605+ );
84018606
84028607 assert_eq!(p.lane(Lane::V1)[1].start, 2, "the matched take moved");
8403- assert_eq!(p.lane(Lane::A1)[1].start, 2, "and its other half stayed in sync");
8404- assert_eq!(p.lane(Lane::V1)[2].start, 7, "the skipped later gap remains");
8405- assert_eq!(p.lane(Lane::A1)[2].start, 6, "A1's shorter gap remains shorter");
8608+ assert_eq!(
8609+ p.lane(Lane::A1)[1].start,
8610+ 2,
8611+ "and its other half stayed in sync"
8612+ );
8613+ assert_eq!(
8614+ p.lane(Lane::V1)[2].start,
8615+ 7,
8616+ "the skipped later gap remains"
8617+ );
8618+ assert_eq!(
8619+ p.lane(Lane::A1)[2].start,
8620+ 6,
8621+ "A1's shorter gap remains shorter"
8622+ );
84068623 links_are_consistent(&p.lanes).expect("every linked take that moved stayed whole");
84078624 assert!(p.undo(), "one undo restores every closed gap");
84088625 assert_eq!(shape(&p), before);
@@ -8415,18 +8632,28 @@ mod tests {
84158632 fn gap_at_finds_the_hole_a_caption_frame_sits_in() {
84168633 let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]);
84178634 let s = p.add_lane(LaneKind::Subtitle);
8418- assert_eq!(p.gap_at(s, 0), None, "an empty subtitle lane has nothing to close");
8635+ assert_eq!(
8636+ p.gap_at(s, 0),
8637+ None,
8638+ "an empty subtitle lane has nothing to close"
8639+ );
84198640
8420- p.place_sub(s, 5, caption(0, 3)).expect("single cue at [5,8)");
8641+ p.place_sub(s, 5, caption(0, 3))
8642+ .expect("single cue at [5,8)");
84218643 assert_eq!(p.gap_at(s, 0), Some((0, 5)), "head gap before first cue");
84228644 assert_eq!(p.gap_at(s, 4), Some((0, 5)));
84238645 assert_eq!(p.gap_at(s, 5), None, "inside the cue");
84248646 assert_eq!(p.gap_at(s, 8), None, "tail after a single cue is not a gap");
84258647
8426- p.place_sub(s, 12, caption(0, 2)).expect("second cue at [12,14)");
8648+ p.place_sub(s, 12, caption(0, 2))
8649+ .expect("second cue at [12,14)");
84278650 assert_eq!(p.gap_at(s, 8), Some((8, 4)), "gap between cues");
84288651 assert_eq!(p.gap_at(s, 11), Some((8, 4)));
8429- assert_eq!(p.gap_at(s, 14), None, "tail after the last cue is still open-ended");
8652+ assert_eq!(
8653+ p.gap_at(s, 14),
8654+ None,
8655+ "tail after the last cue is still open-ended"
8656+ );
84308657 }
84318658
84328659 /// Closing a caption gap ripples the subtitle lane only. It is not a media
@@ -8435,13 +8662,15 @@ mod tests {
84358662 fn closing_a_caption_gap_ripples_no_video_or_audio_clips() {
84368663 let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]);
84378664 let s = p.add_lane(LaneKind::Subtitle);
8438- p.place_sub(s, 5, caption(0, 3)).expect("single cue at [5,8)");
8665+ p.place_sub(s, 5, caption(0, 3))
8666+ .expect("single cue at [5,8)");
84398667 let before_clips = shape(&p);
84408668 let before_subs = p.sub_lane(s).to_vec();
84418669
84428670 let (start, len) = p.gap_at(s, 0).expect("gap before the caption");
84438671 assert_eq!((start, len), (0, 5));
8444- p.cut_regions(&[(start, len)], &[s]).expect("caption lane gap closes");
8672+ p.cut_regions(&[(start, len)], &[s])
8673+ .expect("caption lane gap closes");
84458674
84468675 assert_eq!(shape(&p), before_clips, "media lanes did not move");
84478676 assert_eq!(p.sub_lane(s), &[caption(0, 3)], "caption slid left");
@@ -8458,13 +8687,20 @@ mod tests {
84588687 let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]);
84598688 let s = p.add_lane(LaneKind::Subtitle);
84608689 let history = p.history.len();
8461- let report = p.close_all_gaps_on_lane(s).expect("empty subtitle lane exists");
8462- assert_eq!(report, GapSweep::default(), "empty subtitle lane has no bounded gap");
8690+ let report = p
8691+ .close_all_gaps_on_lane(s)
8692+ .expect("empty subtitle lane exists");
8693+ assert_eq!(
8694+ report,
8695+ GapSweep::default(),
8696+ "empty subtitle lane has no bounded gap"
8697+ );
84638698 assert_eq!(p.history.len(), history, "empty sweep is not an undo step");
84648699
84658700 p.place_sub(s, 2, caption(0, 2)).expect("head gap [0,2)");
84668701 p.place_sub(s, 7, caption(0, 2)).expect("middle gap [4,7)");
8467- p.place_sub(s, 14, caption(0, 1)).expect("middle gap [9,14), tail after 15");
8702+ p.place_sub(s, 14, caption(0, 1))
8703+ .expect("middle gap [9,14), tail after 15");
84688704 let before = p.sub_lane(s).to_vec();
84698705
84708706 assert_eq!(p.gap_count(s), 3);
@@ -8481,7 +8717,8 @@ mod tests {
84818717
84828718 let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]);
84838719 let s = p.add_lane(LaneKind::Subtitle);
8484- p.place_sub(s, 0, caption(0, 3)).expect("contiguous at the head");
8720+ p.place_sub(s, 0, caption(0, 3))
8721+ .expect("contiguous at the head");
84858722 let history = p.history.len();
84868723 let report = p.close_all_gaps_on_lane(s).expect("subtitle lane exists");
84878724 assert_eq!(report, GapSweep::default(), "the open tail is not closed");
@@ -8789,7 +9026,8 @@ mod tests {
87899026 [0, 1]
87909027 );
87919028 // ...and what comes out is loadable, with the same timeline.
8792- let reloaded = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("from_parts");
9029+ let reloaded =
9030+ Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("from_parts");
87939031 assert_eq!(reloaded.timeline_frames(), p.timeline_frames());
87949032 assert_eq!(reloaded.sources().len(), 2);
87959033 }
@@ -9279,8 +9517,14 @@ mod tests {
92799517 fn from_parts_has_no_history_and_checks_the_invariants() {
92809518 let (sources, lanes, eq, color, _transform) = three().without_orphan_sources();
92819519 let (video, audio) = (lanes[0].1.clone(), lanes[1].1.clone());
9282- let mut p = Project::from_parts(sources.clone(), lanes.clone(), eq.clone(), color.clone(), Vec::new())
9283- .expect("valid parts");
9520+ let mut p = Project::from_parts(
9521+ sources.clone(),
9522+ lanes.clone(),
9523+ eq.clone(),
9524+ color.clone(),
9525+ Vec::new(),
9526+ )
9527+ .expect("valid parts");
92849528 assert_eq!(p.clips(), three().clips());
92859529 assert!(!p.undo(), "a loaded project has nothing to undo");
92869530 assert!(p.split(4), "...and is editable from there");
@@ -9308,7 +9552,16 @@ mod tests {
93089552 )
93099553 .is_ok()
93109554 );
9311- assert!(Project::from_parts(sources.clone(), Vec::new(), Vec::new(), Vec::new(), Vec::new()).is_err());
9555+ assert!(
9556+ Project::from_parts(
9557+ sources.clone(),
9558+ Vec::new(),
9559+ Vec::new(),
9560+ Vec::new(),
9561+ Vec::new()
9562+ )
9563+ .is_err()
9564+ );
93129565 let bad: [Vec<Clip>; 5] = [
93139566 vec![clip(0, 0, 3, 1)], // source that is not there
93149567 vec![clip(0, 3, 3, 0)], // empty clip
@@ -9449,7 +9702,8 @@ mod tests {
94499702 assert_eq!(loaded.color_of(Lane::V1, 0), Some(&grade_at(1)));
94509703
94519704 // Group ids survive a load, and the next split gets a fresh one.
9452- let mut p = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("valid parts");
9705+ let mut p =
9706+ Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("valid parts");
94539707 assert!(p.split(4));
94549708 assert!(p.clips().iter().all(|c| c.link.is_some()));
94559709 }
@@ -9487,9 +9741,15 @@ mod tests {
94879741
94889742 // The door: a doubled id inside one lane, refused by name.
94899743 let err = |video: Vec<Clip>, audio: Vec<Clip>| {
9490- Project::from_parts(sources.clone(), two(video, audio), Vec::new(), Vec::new(), Vec::new())
9491- .expect_err("refused")
9492- .to_string()
9744+ Project::from_parts(
9745+ sources.clone(),
9746+ two(video, audio),
9747+ Vec::new(),
9748+ Vec::new(),
9749+ Vec::new(),
9750+ )
9751+ .expect_err("refused")
9752+ .to_string()
94939753 };
94949754 assert!(
94959755 err(vec![linked(0, 0, 3, 7), linked(3, 3, 5, 7)], Vec::new())
@@ -10197,7 +10457,8 @@ mod tests {
1019710457 lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(),
1019810458 [LaneKind::Video, LaneKind::Video, LaneKind::Audio]
1019910459 );
10200- let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("three lanes load");
10460+ let back =
10461+ Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("three lanes load");
1020110462 assert_eq!(back.lanes(), p.lanes());
1020210463 assert_eq!(shape(&back), shape(&p), "the same lane is still on top");
1020310464
@@ -10215,7 +10476,10 @@ mod tests {
1021510476 let mut p = Project::single(FILE, 9);
1021610477 let take = p.clips()[0].link.expect("a fresh project is one take");
1021710478 let v2 = p.add_lane(LaneKind::Video);
10218- assert!(p.place(v2, 0, clip(0, 0, 9, 0)), "a placement joins no group");
10479+ assert!(
10480+ p.place(v2, 0, clip(0, 0, 9, 0)),
10481+ "a placement joins no group"
10482+ );
1021910483 assert!(p.split(4));
1022010484 let side = |p: &Project, i: usize| -> Vec<Option<u32>> {
1022110485 p.lanes().into_iter().map(|l| p.lane(l)[i].link).collect()
@@ -10345,7 +10609,8 @@ mod tests {
1034510609 assert_eq!(lanes[2].1, p.lane(v2), "V2's clips are written");
1034610610 assert!(lanes[3].1.is_empty(), "and the empty A2 is still a lane");
1034710611 // ...and all four load again as the same four.
10348- let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("four lanes load");
10612+ let back =
10613+ Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("four lanes load");
1034910614 assert_eq!(back.lanes(), p.lanes());
1035010615 assert_eq!(back.lane(a2), p.lane(a2));
1035110616
@@ -10438,7 +10703,8 @@ mod tests {
1043810703 (LaneKind::Video, vec![clip(10, 5, 15, 1)]),
1043910704 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),
1044010705 ];
10441- let p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
10706+ let p =
10707+ Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
1044210708 assert_eq!(
1044310709 p.composite_spans_from(0),
1044410710 vec![
@@ -10483,7 +10749,8 @@ mod tests {
1048310749 (LaneKind::Video, vec![clip(10, 0, 10, 1)]),
1048410750 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),
1048510751 ];
10486- let p = Project::from_parts(sources, holed, vec![], vec![], Vec::new()).expect("valid parts");
10752+ let p =
10753+ Project::from_parts(sources, holed, vec![], vec![], Vec::new()).expect("valid parts");
1048710754 assert_eq!(
1048810755 p.composite_spans_from(0),
1048910756 vec![
@@ -10531,7 +10798,8 @@ mod tests {
1053110798 (LaneKind::Audio, vec![clip(15, 0, 15, 1)]),
1053210799 (LaneKind::Audio, Vec::new()),
1053310800 ];
10534- let p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
10801+ let p =
10802+ Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts");
1053510803 let lists = p.audio_segments_from(0, FPS);
1053610804 assert_eq!(lists.len(), 2, "the empty lane is not mixed in");
1053710805 assert_eq!(lists[0], p.segments_from(0, FPS), "A1 is unchanged");
@@ -10554,41 +10822,47 @@ mod tests {
1055410822 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);
1055510823 }
1055610824
10557-/// D4: removing a subtitle column used to clear the whole undo history,
10558-/// because a placement names its track by index into the palette and the
10559-/// reindex left every later entry naming the wrong one. The entry holds the
10560-/// palette beside the lanes now, so the reindex undoes with it.
10561-#[test]
10562-fn removing_a_subtitle_column_undoes_with_its_reindex() {
10563- let track = |label: &str| SubtitleTrack {
10564- path: FILE.into(),
10565- track: None,
10566- language: "eng".into(),
10567- name: String::new(),
10568- label: label.into(),
10569- cues: Vec::new(),
10570- bitmap: false,
10571- refused: None,
10572- };
10573- let mut p = Project::single(FILE, 300)
10574- .with_subtitles(vec![track("one"), track("two"), track("three")]);
10575- assert_eq!(p.subtitles().len(), 3);
10576- let before = p.parts();
10577- let palette = p.subtitles().to_vec();
10578- // Column 0 goes, which renumbers the two behind it.
10579- p.remove_subtitles(0).expect("a column with nothing on it");
10580- assert_eq!(p.subtitles().len(), 2);
10581- assert_eq!(p.subtitles()[0].label, "two");
10582- assert!(p.undo(), "the removal is a step like any other cut");
10583- // The palette itself, and not only what `parts` happens to compare: this
10584- // is the assertion that cannot go vacuous if the restore below it ever
10585- // leaves a field of it behind.
10586- assert_eq!(p.subtitles(), palette.as_slice(), "the palette itself, back");
10587- assert_eq!(p.parts(), before, "the palette and the lanes, both back");
10588- assert!(p.redo(), "and forward again");
10589- assert_eq!(p.subtitles().len(), 2, "the column goes again");
10590- assert_eq!(p.subtitles()[0].label, "two");
10591- assert_ne!(p.subtitles(), palette.as_slice(), "and it is not back");
10592-}
10593-
10825+ /// D4: removing a subtitle column used to clear the whole undo history,
10826+ /// because a placement names its track by index into the palette and the
10827+ /// reindex left every later entry naming the wrong one. The entry holds the
10828+ /// palette beside the lanes now, so the reindex undoes with it.
10829+ #[test]
10830+ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10831+ let track = |label: &str| SubtitleTrack {
10832+ path: FILE.into(),
10833+ track: None,
10834+ language: "eng".into(),
10835+ name: String::new(),
10836+ label: label.into(),
10837+ cues: Vec::new(),
10838+ bitmap: false,
10839+ refused: None,
10840+ };
10841+ let mut p = Project::single(FILE, 300).with_subtitles(vec![
10842+ track("one"),
10843+ track("two"),
10844+ track("three"),
10845+ ]);
10846+ assert_eq!(p.subtitles().len(), 3);
10847+ let before = p.parts();
10848+ let palette = p.subtitles().to_vec();
10849+ // Column 0 goes, which renumbers the two behind it.
10850+ p.remove_subtitles(0).expect("a column with nothing on it");
10851+ assert_eq!(p.subtitles().len(), 2);
10852+ assert_eq!(p.subtitles()[0].label, "two");
10853+ assert!(p.undo(), "the removal is a step like any other cut");
10854+ // The palette itself, and not only what `parts` happens to compare: this
10855+ // is the assertion that cannot go vacuous if the restore below it ever
10856+ // leaves a field of it behind.
10857+ assert_eq!(
10858+ p.subtitles(),
10859+ palette.as_slice(),
10860+ "the palette itself, back"
10861+ );
10862+ assert_eq!(p.parts(), before, "the palette and the lanes, both back");
10863+ assert!(p.redo(), "and forward again");
10864+ assert_eq!(p.subtitles().len(), 2, "the column goes again");
10865+ assert_eq!(p.subtitles()[0].label, "two");
10866+ assert_ne!(p.subtitles(), palette.as_slice(), "and it is not back");
10867+ }
1059410868 }
crates/engine/src/proxy.rsmodified+71 -8
@@ -32,8 +32,8 @@
3232 //! cancel a file export has ([`Job`]).
3333
3434 use std::path::{Path, PathBuf};
35-use std::sync::atomic::AtomicBool;
3635 use std::sync::Arc;
36+use std::sync::atomic::AtomicBool;
3737 use std::time::UNIX_EPOCH;
3838
3939 use crate::demux::{Codec, Demuxer, NoVideoTrack, VideoMeta};
@@ -93,8 +93,20 @@ const BITS_PER_PIXEL: f64 = 0.3;
9393 /// Whether this is a file worth standing in for: bigger than 1080p, or coded in
9494 /// something this machine decodes slowly even at 1080p. H.264 at or under 1080p
9595 /// plays natively and a proxy of it would cost time and buy nothing.
96+///
97+/// The size test reads the **coded** pair, not the displayed one
98+/// ([`VideoMeta::coded_width`]): those differ wherever the file carries a
99+/// display matrix or a non-square pixel, and a 1920x1080 H.264 phone clip with
100+/// a 90-degree turn *displays* as 1080x1920 -- so judging the displayed pair
101+/// called a clip that plays natively proxy-worthy and put a whole film through
102+/// a decoder and an encoder to stand in for something already at speed. What a
103+/// decoder is asked to chew through is the stored raster, so the stored raster
104+/// is what this is about; the codec test is not a size question and is
105+/// unchanged.
96106 pub fn wanted(meta: &VideoMeta) -> bool {
97- meta.width > 1920 || meta.height > 1080 || matches!(meta.codec, Codec::Hevc | Codec::Av1)
107+ meta.coded_width > 1920
108+ || meta.coded_height > 1080
109+ || matches!(meta.codec, Codec::Hevc | Codec::Av1)
98110 }
99111
100112 /// The picture a proxy of `meta` is coded at: aspect kept, long edge at most
@@ -628,7 +640,27 @@ mod tests {
628640 Arc::new(AtomicBool::new(false))
629641 }
630642
631- fn meta(width: u32, height: u32, codec: Codec) -> VideoMeta {
643+ /// A meta as no container wrote it: square pixels, no turn, the displayed
644+ /// pair the same pair the samples are stored at.
645+ fn meta(coded_width: u32, coded_height: u32, codec: Codec) -> VideoMeta {
646+ turned_meta(coded_width, coded_height, Rotation::None, codec)
647+ }
648+
649+ /// The same, but with the display pair built the way `demux` builds it for
650+ /// a file carrying a display matrix: the stored pair with its axes swapped
651+ /// where the turn says they are. A phone clip shot 1920x1080 and turned to
652+ /// portrait is the case that matters -- it *displays* 1080x1920, and a
653+ /// predicate that reads the displayed pair calls it a tall 1080p film.
654+ fn turned_meta(
655+ coded_width: u32,
656+ coded_height: u32,
657+ rotation: Rotation,
658+ codec: Codec,
659+ ) -> VideoMeta {
660+ let (width, height) = match rotation.swaps_axes() {
661+ true => (coded_height, coded_width),
662+ false => (coded_width, coded_height),
663+ };
632664 VideoMeta {
633665 width,
634666 height,
@@ -636,11 +668,9 @@ mod tests {
636668 frame_count: 240,
637669 codec,
638670 color: ColorDescription::default(),
639- rotation: Rotation::None,
640- // Square pixels, coded where they are declared: a meta no
641- // container wrote, so nothing was read to disagree with it.
642- coded_width: width,
643- coded_height: height,
671+ rotation,
672+ coded_width,
673+ coded_height,
644674 pixel_aspect: crate::demux::PixelAspect::SQUARE,
645675 }
646676 }
@@ -657,6 +687,39 @@ mod tests {
657687 "1080p H.264 plays natively"
658688 );
659689 assert!(!wanted(&meta(1280, 720, Codec::H264)), "720p H.264");
690+
691+ // A turn must not turn a native file into a proxy job. What a decoder
692+ // is handed is the stored raster -- 1920x1080 of H.264 -- and that is
693+ // what plays at speed; the 1080x1920 the file *displays* is a metadata
694+ // turn, not a bigger picture. Judged on the displayed pair this file
695+ // was handed to a background decoder and an encoder to be stood in for,
696+ // which is a whole film of CPU and cache for a clip already at rate.
697+ let phone = turned_meta(1920, 1080, Rotation::Cw90, Codec::H264);
698+ assert_eq!(
699+ (phone.coded_width, phone.coded_height),
700+ (1920, 1080),
701+ "the samples are stored landscape"
702+ );
703+ assert_eq!(
704+ (phone.width, phone.height),
705+ (1080, 1920),
706+ "and the file only claims to display portrait"
707+ );
708+ assert!(
709+ !wanted(&phone),
710+ "a rotated 1080p H.264 clip plays natively: the turn is not height"
711+ );
712+ // ...while the same turn on a codec this machine decodes slowly is
713+ // still wanted, and so is a genuinely tall stored raster: the two
714+ // tests are about the stored pair, not about `rotation` itself.
715+ assert!(
716+ wanted(&turned_meta(1920, 1080, Rotation::Cw90, Codec::Hevc)),
717+ "1080p HEVC is wanted whatever turn it carries"
718+ );
719+ assert!(
720+ wanted(&turned_meta(1080, 1920, Rotation::None, Codec::H264)),
721+ "a stored 1080x1920 raster is a big one, turn or not"
722+ );
660723 }
661724
662725 /// Aspect kept, long edge capped, both axes even -- and a small source left