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 {
67 | ActionId::AddSubtitleLane67 | ActionId::AddSubtitleLane
68 | ActionId::RemoveSubtitleLane68 | ActionId::RemoveSubtitleLane
69 | ActionId::ImportSubtitles69 | ActionId::ImportSubtitles
70- | ActionId::Crossfade70+ // `Crossfade` and `Dissolve` are NOT here, and that is the
71- | ActionId::Dissolve71+ // 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.
72 | ActionId::Visualizer86 | ActionId::Visualizer
73 ) {87 ) {
74 self.mark_dirty();88 self.mark_dirty();
@@ -251,10 +265,12 @@ impl Player {
251 }265 }
252 match action {266 match action {
253 ActionId::Mix => self.open_mix(Some(lane), cx),267 ActionId::Mix => self.open_mix(Some(lane), cx),
254- ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => {268+ // The arm rides the door's own answer, like every arm in this
255- self.mark_dirty();269+ // window: `remove_lane` refuses a track that still holds clips or
256- self.remove_lane(lane, cx);270+ // captions, and the last track of its kind, and arming before the
257- }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),
258 _ => unreachable!("only lane-header actions reach act_lane"),274 _ => unreachable!("only lane-header actions reach act_lane"),
259 }275 }
260 }276 }
crates/app/src/player/cards.rsmodified+57 -44
@@ -1,8 +1,8 @@
1 //! The cards the window opens over itself: the pickers, colour, speed,1 //! The cards the window opens over itself: the pickers, colour, speed,
2 //! silence, the mixer and the equalizer.2 //! silence, the mixer and the equalizer.
3 3
4-use crate::*;
5 use crate::ui::settings_stance::SettingsTab;4 use crate::ui::settings_stance::SettingsTab;
5+use crate::*;
6 6
7 impl Player {7 impl Player {
8 /// Cycles the *project's* resolution through [`RESOLUTIONS`], starting from8 /// Cycles the *project's* resolution through [`RESOLUTIONS`], starting from
@@ -279,10 +279,7 @@ impl Player {
279 match caption_media_half(session, (lane, idx), LaneKind::Video) {279 match caption_media_half(session, (lane, idx), LaneKind::Video) {
280 Some(half) => Some(half),280 Some(half) => Some(half),
281 None => {281 None => {
282- self.notify_user(282+ self.notify_user("NOTHING TO GRADE — a caption has no picture".into());
283- "NOTHING TO GRADE — a caption has no picture"
284- .into(),
285- );
286 cx.notify();283 cx.notify();
287 return;284 return;
288 }285 }
@@ -426,10 +423,7 @@ impl Player {
426 match caption_media_half(session, (lane, idx), LaneKind::Video) {423 match caption_media_half(session, (lane, idx), LaneKind::Video) {
427 Some(half) => Some(half),424 Some(half) => Some(half),
428 None => {425 None => {
429- self.notify_user(426+ self.notify_user("NOTHING TO PLACE — a caption has no picture".into());
430- "NOTHING TO PLACE — a caption has no picture"
431- .into(),
432- );
433 cx.notify();427 cx.notify();
434 return;428 return;
435 }429 }
@@ -567,8 +561,7 @@ impl Player {
567 Some(half) => Some(half),561 Some(half) => Some(half),
568 None => {562 None => {
569 self.notify_user(563 self.notify_user(
570- "NOTHING TO RE-TIME — a caption has no speed of its own"564+ "NOTHING TO RE-TIME — a caption has no speed of its own".into(),
571- .into(),
572 );565 );
573 cx.notify();566 cx.notify();
574 return;567 return;
@@ -734,8 +727,7 @@ impl Player {
734 Some(half) => Some(half),727 Some(half) => Some(half),
735 None => {728 None => {
736 self.notify_user(729 self.notify_user(
737- "NOTHING TO SCAN — a caption has no sound of its own"730+ "NOTHING TO SCAN — a caption has no sound of its own".into(),
738- .into(),
739 );731 );
740 cx.notify();732 cx.notify();
741 return;733 return;
@@ -856,14 +848,20 @@ impl Player {
856 if self.session.is_none() {848 if self.session.is_none() {
857 return;849 return;
858 }850 }
859- self.mark_dirty();
860 let Some(session) = self.session.as_mut() else {851 let Some(session) = self.session.as_mut() else {
861 return;852 return;
862 };853 };
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) {
864 Some(&lane) => {862 Some(&lane) => {
865 let at = session.lane_gain_db(lane) + steps as f32 * MIX_DB_STEP;863 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)
867 }865 }
868 None => {866 None => {
869 let limiter = session.limiter();867 let limiter = session.limiter();
@@ -878,8 +876,11 @@ impl Player {
878 ..limiter876 ..limiter
879 },877 },
880 };878 };
881- session.set_limiter(at);879+ session.set_limiter(at)
882 }880 }
881+ };
882+ if took {
883+ self.mark_dirty();
883 }884 }
884 cx.notify();885 cx.notify();
885 }886 }
@@ -1246,17 +1247,15 @@ impl Player {
1246 /// nothing.1247 /// nothing.
1247 pub(crate) fn previewed(&mut self) -> Option<(Vec<(u32, u32)>, Vec<Lane>)> {1248 pub(crate) fn previewed(&mut self) -> Option<(Vec<(u32, u32)>, Vec<Lane>)> {
1248 if self.silence_marks.is_empty() {1249 if self.silence_marks.is_empty() {
1249- self.notify_user(1250+ self.notify_user(if self.silence_keep_only {
1250- if self.silence_keep_only {1251+ "NO SPEECH TO CUT — keep-only-silence needs silence and speech".into()
1251- "NO SPEECH TO CUT — keep-only-silence needs silence and speech".into()1252+ } else {
1252- } else {1253+ format!(
1253- format!(1254+ "NO SILENCE — under {:.0} dBFS lasting {:.2} s",
1254- "NO SILENCE — under {:.0} dBFS lasting {:.2} s",1255+ self.silence.threshold_db, self.silence.min_silence
1255- self.silence.threshold_db, self.silence.min_silence1256+ )
1256- )1257+ .into()
1257- .into()1258+ });
1258- },
1259- );
1260 return None;1259 return None;
1261 }1260 }
1262 Some((self.silence_marks.clone(), self.silence_lanes()))1261 Some((self.silence_marks.clone(), self.silence_lanes()))
@@ -1302,7 +1301,11 @@ impl Player {
1302 // moves indexes (a delete, a paste, an undo).1301 // moves indexes (a delete, a paste, an undo).
1303 self.selected.clear();1302 self.selected.clear();
1304 self.reset_after_reseek();1303 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+ };
1306 self.notify_user(1309 self.notify_user(
1307 format!(1310 format!(
1308 "{count} {what} CUT {reach} — {} shorter · undo {}",1311 "{count} {what} CUT {reach} — {} shorter · undo {}",
@@ -1342,7 +1345,11 @@ impl Player {
1342 // goes with them.1345 // goes with them.
1343 self.selected.clear();1346 self.selected.clear();
1344 self.reset_after_reseek();1347 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+ };
1346 self.notify_user(1353 self.notify_user(
1347 format!(1354 format!(
1348 "{count} {what} AT {rate} {reach} · undo {}",1355 "{count} {what} AT {rate} {reach} · undo {}",
@@ -1494,9 +1501,9 @@ impl Player {
1494 "NOTHING SELECTED · select all {}",1501 "NOTHING SELECTED · select all {}",
1495 self.keymap.display(ActionId::Select)1502 self.keymap.display(ActionId::Select)
1496 )),1503 )),
1497- (Some((lane, _)), _) if lane.kind != LaneKind::Audio => Some(1504+ (Some((lane, _)), _) if lane.kind != LaneKind::Audio => {
1498- "NOT AN AUDIO CLIP — the equalizer works on sound".to_string(),1505+ Some("NOT AN AUDIO CLIP — the equalizer works on sound".to_string())
1499- ),1506+ }
1500 _ => None,1507 _ => None,
1501 };1508 };
1502 if let Some(refusal) = refusal {1509 if let Some(refusal) = refusal {
@@ -1535,12 +1542,23 @@ impl Player {
1535 };1542 };
1536 let params = (!self.eq_params.is_identity()).then(|| self.eq_params.clone());1543 let params = (!self.eq_params.is_identity()).then(|| self.eq_params.clone());
1537 if let Some(session) = &mut self.session {1544 if let Some(session) = &mut self.session {
1538- session.set_eq(lane, idx, params);1545+ // `set_eq` answers "the index was there and the curve is finite"
1539- self.mark_dirty();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+ }
1540 }1561 }
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();
1544 cx.notify();1562 cx.notify();
1545 }1563 }
1546 1564
@@ -1590,12 +1608,7 @@ impl Player {
1590 /// band that was just made. Refused rather than silently ignored at the cap.1608 /// band that was just made. Refused rather than silently ignored at the cap.
1591 pub(crate) fn add_band(&mut self, cx: &mut Context<Self>) {1609 pub(crate) fn add_band(&mut self, cx: &mut Context<Self>) {
1592 if self.eq_params.bands.len() >= EQ_BANDS_MAX {1610 if self.eq_params.bands.len() >= EQ_BANDS_MAX {
1593- self.notify_user(1611+ self.notify_user(format!("EQUALIZER FULL — {EQ_BANDS_MAX} bands").into());
1594- format!(
1595- "EQUALIZER FULL — {EQ_BANDS_MAX} bands"
1596- )
1597- .into(),
1598- );
1599 cx.notify();1612 cx.notify();
1600 return;1613 return;
1601 }1614 }
crates/app/src/player/library.rsmodified+8 -10
@@ -177,9 +177,7 @@ impl Player {
177 self.reset_after_reseek();177 self.reset_after_reseek();
178 }178 }
179 Err(e) => self.notify_user(format!("NO VISUALIZER — {e}").into()),179 Err(e) => self.notify_user(format!("NO VISUALIZER — {e}").into()),
180- Ok(false) => {180+ Ok(false) => self.notify_user("NO VISUALIZER — that clip could not be placed".into()),
181- self.notify_user("NO VISUALIZER — that clip could not be placed".into())
182- }
183 }181 }
184 cx.notify();182 cx.notify();
185 }183 }
@@ -453,10 +451,7 @@ impl Player {
453 {451 {
454 true => {452 true => {
455 self.close_session();453 self.close_session();
456- format!(454+ format!("REMOVED {} — the library is empty", file_name(path))
457- "REMOVED {} — the library is empty",
458- file_name(path)
459- )
460 }455 }
461 // The undo stack goes with it (`Project::remove_source`):456 // The undo stack goes with it (`Project::remove_source`):
462 // said here, because a `z` that does nothing afterwards457 // said here, because a `z` that does nothing afterwards
@@ -1196,9 +1191,7 @@ impl Player {
1196 .count();1191 .count();
1197 let text = match (on, ready, making) {1192 let text = match (on, ready, making) {
1198 (false, ..) => "PROXIES OFF — the films themselves are what play".to_string(),1193 (false, ..) => "PROXIES OFF — the films themselves are what play".to_string(),
1199- (true, 0, 0) => {1194+ (true, 0, 0) => "PROXIES ON — no film here has one".to_string(),
1200- "PROXIES ON — no film here has one".to_string()
1201- }
1202 (true, 0, n) => format!("PROXIES ON — {n} still being made"),1195 (true, 0, n) => format!("PROXIES ON — {n} still being made"),
1203 (true, n, 0) => format!("PROXIES ON — cutting on {n}"),1196 (true, n, 0) => format!("PROXIES ON — cutting on {n}"),
1204 (true, n, m) => format!("PROXIES ON — cutting on {n}, {m} still being made"),1197 (true, n, m) => format!("PROXIES ON — cutting on {n}, {m} still being made"),
@@ -2156,6 +2149,11 @@ impl Player {
2156 .map(|session| session.remove_lane(lane));2149 .map(|session| session.remove_lane(lane));
2157 let text = match removed {2150 let text = match removed {
2158 Some(Ok(())) => {2151 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();
2159 self.selected.clear();2157 self.selected.clear();
2160 self.context_menu = None;2158 self.context_menu = None;
2161 self.eq_open = None;2159 self.eq_open = None;
crates/app/src/player/timeline_edit.rsmodified+83 -19
@@ -1783,12 +1783,25 @@ impl Player {
1783 return;1783 return;
1784 };1784 };
1785 let frames = self.fps.round().max(1.) as u32;1785 let frames = self.fps.round().max(1.) as u32;
1786- if let Some(session) = &mut self.session {1786+ if self.session.is_none() {
1787- if !session.crossfade(lane, idx, frames) {1787+ return;
1788- self.notify_user("NOTHING TO CROSSFADE — no neighbour end to end".into());1788+ }
1789- }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());
1790 }1804 }
1791- cx.notify();
1792 }1805 }
1793 1806
1794 /// Dissolves the join the selection names, into or back out of it: two1807 /// Dissolves the join the selection names, into or back out of it: two
@@ -1809,24 +1822,48 @@ impl Player {
1809 cx.notify();1822 cx.notify();
1810 return;1823 return;
1811 };1824 };
1812- let Some(session) = &mut self.session else {1825+ if self.session.is_none() {
1813 cx.notify();1826 cx.notify();
1814 return;1827 return;
1815- };1828+ }
1816- let removing = session.transition_out_of(lane, idx) > 0;1829+ let removing = self.transition_out_of_selected(lane, idx);
1817 let frames = if removing {1830 let frames = if removing {
1818 01831 0
1819 } else {1832 } else {
1820 self.fps.round().max(1.) as u321833 self.fps.round().max(1.) as u32
1821 };1834 };
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 {
1823 self.notify_user("NOTHING TO DISSOLVE — no neighbour end to end".into());1853 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());
1826 }1854 }
1827 cx.notify();1855 cx.notify();
1828 }1856 }
1829 1857
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+
1830 /// Widens or narrows the transition the anchor already carries, one1867 /// Widens or narrows the transition the anchor already carries, one
1831 /// frame at a step, from the inspector's duration row -- ctrl+f/ctrl+x1868 /// frame at a step, from the inspector's duration row -- ctrl+f/ctrl+x
1832 /// stay the toggle that seeds a fresh one at one second; this is what1869 /// stay the toggle that seeds a fresh one at one second; this is what
@@ -1869,17 +1906,44 @@ impl Player {
1869 if self.exporting().is_some() {1906 if self.exporting().is_some() {
1870 return;1907 return;
1871 }1908 }
1872- let Some(session) = &mut self.session else {1909+ if self.session.is_none() {
1873 return;1910 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,
1874 };1926 };
1875- let ok = match lane.kind {1927+ if ok && self.transition_edges(lane, idx) != before {
1876- LaneKind::Video => session.set_transition_out(lane, idx, frames),
1877- LaneKind::Audio => session.crossfade(lane, idx, frames),
1878- _ => false,
1879- };
1880- if ok {
1881 self.mark_dirty();1928 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,
1883 }1947 }
1884 }1948 }
1885 1949
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() {
1172 /// and can't turn it back to video"). One cycle, and it wraps.1172 /// and can't turn it back to video"). One cycle, and it wraps.
1173 #[test]1173 #[test]
1174 fn the_picture_cycle_wraps_out_of_the_sound_only_formats() {1174 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};
1176 // Nothing refused: every stop is the next one, and the last wraps to the1176 // Nothing refused: every stop is the next one, and the last wraps to the
1177 // first -- OGG, the tail of the list, back to MP4.1177 // first -- OGG, the tail of the list, back to MP4.
1178 let mut at = PICTURE_CYCLE[0];1178 let mut at = PICTURE_CYCLE[0];
@@ -1710,6 +1710,201 @@ fn every_click_door_that_writes_the_project_arms_autosave() {
1710 one for the same step"1710 one for the same step"
1711 );1711 );
1712 }1712 }
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+ );
1713 }1908 }
1714 1909
1715 /// [`crate::ui::dock_stance::transition_of`]: the dock's duration row1910 /// [`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() {
1928 assert!(native_detail.ends_with(" source"), "{native_detail}");2123 assert!(native_detail.ends_with(" source"), "{native_detail}");
1929 // A project at a size nobody listed still gets the whole list, with2124 // A project at a size nobody listed still gets the whole list, with
1930 // nothing marked rather than a wrong row marked.2125 // nothing marked rather than a wrong row marked.
1931- assert!(resolution_choices((1000, 1000), native)2126+ assert!(
1932- .iter()2127+ resolution_choices((1000, 1000), native)
1933- .all(|(.., picked)| !picked));2128+ .iter()
2129+ .all(|(.., picked)| !picked)
2130+ );
1934 // Picking a row means that row, and stepping means the next one: the2131 // Picking a row means that row, and stepping means the next one: the
1935 // list and the stroke read the same ladder.2132 // list and the stroke read the same ladder.
1936 assert_eq!(next_resolution(ladder[1], native), ladder[2]);2133 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() {
2387 /// inside the dock, or hands it the dock's width again, fails this.2584 /// inside the dock, or hands it the dock's width again, fails this.
2388 #[test]2585 #[test]
2389 fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() {2586 fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() {
2390- use crate::layout::{split_size, Split};
2391 use crate::SPLIT_W;2587 use crate::SPLIT_W;
2588+ use crate::layout::{Split, split_size};
2392 2589
2393 // `layout::SPLIT_W` is the one divider between `stance-centre` and the2590 // `layout::SPLIT_W` is the one divider between `stance-centre` and the
2394 // dock; the 56px rail that used to eat the centre's left edge is gone2591 // 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() {
2435 /// assumption.2632 /// assumption.
2436 #[test]2633 #[test]
2437 fn a_maximized_card_can_never_rise_above_the_picture_no_matter_the_bench_height() {2634 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};
2439 let viewport_h = 1080.;2636 let viewport_h = 1080.;
2440 for bench_h in [140., 200., 400.] {2637 for bench_h in [140., 200., 400.] {
2441 assert_eq!(2638 assert_eq!(
crates/engine/src/project.rsmodified+506 -232
@@ -77,11 +77,11 @@ use crate::map::TimelineMap;
77 use std::path::{Path, PathBuf};77 use std::path::{Path, PathBuf};
78 78
79 use crate::color::ColorParams;79 use crate::color::ColorParams;
80-use crate::transform::TransformParams;
81 use crate::eq::EqParams;80 use crate::eq::EqParams;
82 use crate::limiter::{Limiter, db_to_linear};81 use crate::limiter::{Limiter, db_to_linear};
83 use crate::scale::FitPolicy;82 use crate::scale::FitPolicy;
84 use crate::subtitle::{Cue as SubtitleCue, SubtitleTrack};83 use crate::subtitle::{Cue as SubtitleCue, SubtitleTrack};
84+use crate::transform::TransformParams;
85 85
86 /// How far down a lane's own volume goes ([`Project::set_lane_gain_db`]).86 /// How far down a lane's own volume goes ([`Project::set_lane_gain_db`]).
87 /// -60 dB is a thousandth of the amplitude -- a track that is out of the mix87 /// -60 dB is a thousandth of the amplitude -- a track that is out of the mix
@@ -1083,7 +1083,9 @@ impl Project {
1083 return Err(format!("color {bad} holds a value that is not a finite number").into());1083 return Err(format!("color {bad} holds a value that is not a finite number").into());
1084 }1084 }
1085 if let Some(bad) = transform.iter().position(|p| !transform_finite(p)) {1085 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+ );
1087 }1089 }
1088 if lanes.is_empty() {1090 if lanes.is_empty() {
1089 return Err("no lanes at all: that is not a project".into());1091 return Err("no lanes at all: that is not a project".into());
@@ -1148,7 +1150,9 @@ impl Project {
1148 )1150 )
1149 .into());1151 .into());
1150 }1152 }
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+ {
1152 return Err(format!(1156 return Err(format!(
1153 "{name} clip at {} names transform {} of {}",1157 "{name} clip at {} names transform {} of {}",
1154 c.start,1158 c.start,
@@ -1483,13 +1487,13 @@ impl Project {
1483 let used: Vec<String> = handles(&self.lanes)1487 let used: Vec<String> = handles(&self.lanes)
1484 .into_iter()1488 .into_iter()
1485 .zip(&self.lanes)1489 .zip(&self.lanes)
1486- .filter_map(1490+ .filter_map(|(lane, data)| {
1487- |(lane, data)| match data.clips.iter().filter(|c| c.source == idx).count() {1491+ match data.clips.iter().filter(|c| c.source == idx).count() {
1488 0 => None,1492 0 => None,
1489 1 => Some(format!("{} (1 clip)", lane.label())),1493 1 => Some(format!("{} (1 clip)", lane.label())),
1490 n => Some(format!("{} ({n} clips)", lane.label())),1494 n => Some(format!("{} ({n} clips)", lane.label())),
1491- },1495+ }
1492- )1496+ })
1493 .collect();1497 .collect();
1494 if !used.is_empty() {1498 if !used.is_empty() {
1495 return Err(format!("{name} still plays on {}", used.join(", ")).into());1499 return Err(format!("{name} still plays on {}", used.join(", ")).into());
@@ -1982,7 +1986,9 @@ impl Project {
1982 ..sub1986 ..sub
1983 };1987 };
1984 if at.checked_add(sub.frames).is_none() {1988 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+ );
1986 }1992 }
1987 if let Some(other) = self.lanes[i]1993 if let Some(other) = self.lanes[i]
1988 .subs1994 .subs
@@ -2093,10 +2099,12 @@ impl Project {
2093 let at = subs.partition_point(|o| o.start < moved.start);2099 let at = subs.partition_point(|o| o.start < moved.start);
2094 subs.insert(at, moved);2100 subs.insert(at, moved);
2095 debug_assert!(subs_sorted_disjoint(subs));2101 debug_assert!(subs_sorted_disjoint(subs));
2096- debug_assert!(members2102+ debug_assert!(
2097- .clips2103+ members
2098- .iter()2104+ .clips
2099- .all(|&(l, _)| sorted_disjoint(&self.lanes[l].clips)));2105+ .iter()
2106+ .all(|&(l, _)| sorted_disjoint(&self.lanes[l].clips))
2107+ );
2100 return Ok(());2108 return Ok(());
2101 }2109 }
2102 let moved = SubClip { start, ..sub };2110 let moved = SubClip { start, ..sub };
@@ -2209,7 +2217,13 @@ impl Project {
2209 // clip's trim does: one delta, each member clamped to its own room.2217 // clip's trim does: one delta, each member clamped to its own room.
2210 // No source table to grow by, which only tightens how far a member may2218 // No source table to grow by, which only tightens how far a member may
2211 // follow -- never whether it may.2219 // 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+ );
2213 Ok(())2227 Ok(())
2214 }2228 }
2215 2229
@@ -2230,7 +2244,10 @@ impl Project {
2230 // what turns its two walls -- its own start, and its last cue -- into2244 // what turns its two walls -- its own start, and its last cue -- into
2231 // frames. A rate that is not a rate leaves the window where it is.2245 // frames. A rate that is not a rate leaves the window where it is.
2232 let frames_of = |us: i64| match fps.is_finite() && fps > 0.0 {2246 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,
2234 false => 0,2251 false => 0,
2235 };2252 };
2236 Some(match edge {2253 Some(match edge {
@@ -2360,18 +2377,6 @@ impl Project {
2360 true2377 true
2361 }2378 }
2362 2379
2363-
2364-
2365-
2366-
2367-
2368-
2369-
2370-
2371-
2372-
2373-
2374-
2375 /// What the clip at `idx` of `lane` plays through, or `None` for one that2380 /// What the clip at `idx` of `lane` plays through, or `None` for one that
2376 /// plays flat (and for an index that is not there) -- what a feeder and an2381 /// plays flat (and for an index that is not there) -- what a feeder and an
2377 /// export ask before they build an [`crate::eq::EqState`].2382 /// export ask before they build an [`crate::eq::EqState`].
@@ -2489,7 +2494,12 @@ impl Project {
2489 /// [`set_color`](Self::set_color)'s twin for [`Clip::transform`]: one undo2494 /// [`set_color`](Self::set_color)'s twin for [`Clip::transform`]: one undo
2490 /// step, `false` (and no history) for an index that is not there or a2495 /// step, `false` (and no history) for an index that is not there or a
2491 /// value that is not finite, and equal settings share a table entry.2496 /// 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 {
2493 self.write_transform(lane, idx, params, true)2503 self.write_transform(lane, idx, params, true)
2494 }2504 }
2495 2505
@@ -2608,7 +2618,11 @@ impl Project {
2608 let map = TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end())));2618 let map = TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end())));
2609 let start = map.apply(s.start);2619 let start = map.apply(s.start);
2610 let end = map.apply(s.end()).max(start.saturating_add(1));2620 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+ }
2612 };2626 };
2613 for &(l, i) in &members.clips {2627 for &(l, i) in &members.clips {
2614 let clips = &self.lanes[l].clips;2628 let clips = &self.lanes[l].clips;
@@ -2686,8 +2700,7 @@ impl Project {
2686 let held = self.lane(lane).get(idx).copied()?;2700 let held = self.lane(lane).get(idx).copied()?;
2687 let (held_old, new) = (held.speed.as_f64(), speed.as_f64());2701 let (held_old, new) = (held.speed.as_f64(), speed.as_f64());
2688 for &(l, i) in members.clips.iter().chain(&members.subs) {2702 for &(l, i) in members.clips.iter().chain(&members.subs) {
2689- let (span, map) = match self2703+ let (span, map) = match self.lanes[l]
2690- .lanes[l]
2691 .clips2704 .clips
2692 .get(i)2705 .get(i)
2693 .filter(|_| members.clips.contains(&(l, i)))2706 .filter(|_| members.clips.contains(&(l, i)))
@@ -2700,10 +2713,7 @@ impl Project {
2700 (c.start, c.start + c.frames()),2713 (c.start, c.start + c.frames()),
2701 TimelineMap::piece(2714 TimelineMap::piece(
2702 (c.start, c.start + c.frames()),2715 (c.start, c.start + c.frames()),
2703- (2716+ (c.start, c.start + (c.len() as f64 / new).round() as u32),
2704- c.start,
2705- c.start + (c.len() as f64 / new).round() as u32,
2706- ),
2707 ),2717 ),
2708 ),2718 ),
2709 // The caption's span, scaled about the held clip's head by2719 // The caption's span, scaled about the held clip's head by
@@ -3235,7 +3245,10 @@ impl Project {
3235 .iter()3245 .iter()
3236 .enumerate()3246 .enumerate()
3237 .map(|(i, l)| {3247 .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())
3239 })3252 })
3240 .collect();3253 .collect();
3241 // The links the captions carry, read before the room is opened below3254 // The links the captions carry, read before the room is opened below
@@ -3288,8 +3301,10 @@ impl Project {
3288 }3301 }
3289 }3302 }
3290 let fresh: Vec<u32> = (0..distinct.len()).map(|_| self.new_link()).collect();3303 let fresh: Vec<u32> = (0..distinct.len()).map(|_| self.new_link()).collect();
3291- let right_of =3304+ let right_of = |link: Option<u32>| {
3292- |link: Option<u32>| link.and_then(|id| distinct.iter().position(|&d| d == id)).map(|at| fresh[at]);3305+ link.and_then(|id| distinct.iter().position(|&d| d == id))
3306+ .map(|at| fresh[at])
3307+ };
3293 for (l, data) in self.lanes.iter_mut().enumerate() {3308 for (l, data) in self.lanes.iter_mut().enumerate() {
3294 if !cut_subs[l] {3309 if !cut_subs[l] {
3295 continue;3310 continue;
@@ -3299,7 +3314,11 @@ impl Project {
3299 .subs3314 .subs
3300 .iter()3315 .iter()
3301 .position(|s| s.end() == timeline_frame)3316 .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+ })
3303 {3322 {
3304 data.subs[idx].link = sub_orig[l];3323 data.subs[idx].link = sub_orig[l];
3305 data.subs[idx + 1].link = right_of(sub_orig[l]);3324 data.subs[idx + 1].link = right_of(sub_orig[l]);
@@ -3308,7 +3327,9 @@ impl Project {
3308 for (data_i, data) in self.lanes.iter_mut().enumerate() {3327 for (data_i, data) in self.lanes.iter_mut().enumerate() {
3309 // The lanes this call was not scoped to are not cut, whatever their3328 // The lanes this call was not scoped to are not cut, whatever their
3310 // own clips would allow.3329 // 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 {
3312 continue;3333 continue;
3313 };3334 };
3314 let mut tail = data.clips[idx];3335 let mut tail = data.clips[idx];
@@ -3547,9 +3568,7 @@ impl Project {
3547 } else {3568 } else {
3548 "clip"3569 "clip"
3549 };3570 };
3550- return Err(3571+ return Err(format!("there is no {what} {idx} on {}", lane.label()).into());
3551- format!("there is no {what} {idx} on {}", lane.label()).into()
3552- );
3553 }3572 }
3554 }3573 }
3555 let links: Vec<Option<u32>> = picks3574 let links: Vec<Option<u32>> = picks
@@ -3573,8 +3592,16 @@ impl Project {
3573 let labels = handles(&self.lanes);3592 let labels = handles(&self.lanes);
3574 let mut per_lane: std::collections::HashMap<usize, u32> = std::collections::HashMap::new();3593 let mut per_lane: std::collections::HashMap<usize, u32> = std::collections::HashMap::new();
3575 for (li, data) in self.lanes.iter().enumerate() {3594 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()3595+ let n = data
3577- + data.subs.iter().filter(|s| s.link.is_some() && links.contains(&s.link)).count();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();
3578 if n > 0 {3605 if n > 0 {
3579 per_lane.insert(li, n as u32);3606 per_lane.insert(li, n as u32);
3580 }3607 }
@@ -3866,13 +3893,9 @@ impl Project {
3866 clips.insert(at, clip);3893 clips.insert(at, clip);
3867 }3894 }
3868 debug_assert!(sorted_disjoint(&self.lanes[dest].clips));3895 debug_assert!(sorted_disjoint(&self.lanes[dest].clips));
3869- debug_assert!(members3896+ debug_assert!(members.clips.iter().chain(&members.subs).all(|&(l, _)| {
3870- .clips3897+ sorted_disjoint(&self.lanes[l].clips) && subs_sorted_disjoint(&self.lanes[l].subs)
3871- .iter()3898+ }));
3872- .chain(&members.subs)
3873- .all(|&(l, _)| {
3874- sorted_disjoint(&self.lanes[l].clips) && subs_sorted_disjoint(&self.lanes[l].subs)
3875- }));
3876 true3899 true
3877 }3900 }
3878 3901
@@ -4048,7 +4071,13 @@ impl Project {
4048 Edge::End => c.out_frame = c.in_frame + keep,4071 Edge::End => c.out_frame = c.in_frame + keep,
4049 }4072 }
4050 debug_assert!(sorted_disjoint(&self.lanes[held].clips));4073 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+ );
4052 true4081 true
4053 }4082 }
4054 4083
@@ -4144,13 +4173,7 @@ impl Project {
4144 /// [`trim_room`](Project::trim_room) for a clip the caller already holds by4173 /// [`trim_room`](Project::trim_room) for a clip the caller already holds by
4145 /// its lane's storage index: the one wall computation, asked for the clip4174 /// its lane's storage index: the one wall computation, asked for the clip
4146 /// itself and for each member a group trim carries.4175 /// itself and for each member a group trim carries.
4147- fn clip_room(4176+ fn clip_room(&self, l: usize, i: usize, edge: Edge, source_frames: &[u32]) -> (u32, u32) {
4148- &self,
4149- l: usize,
4150- i: usize,
4151- edge: Edge,
4152- source_frames: &[u32],
4153- ) -> (u32, u32) {
4154 let clips = &self.lanes[l].clips;4177 let clips = &self.lanes[l].clips;
4155 let c = clips[i];4178 let c = clips[i];
4156 let (lo, hi) = match edge {4179 let (lo, hi) = match edge {
@@ -4606,13 +4629,11 @@ impl Project {
4606 let mut report = GapSweep::default();4629 let mut report = GapSweep::default();
4607 let mut snapshot = false;4630 let mut snapshot = false;
4608 for (start, frames) in gaps(self.lane(lane)).into_iter().rev() {4631 for (start, frames) in gaps(self.lane(lane)).into_iter().rev() {
4609- match self4632+ match self.gap_take_scope(lane, start, frames).and_then(|scope| {
4610- .gap_take_scope(lane, start, frames)4633+ let on = self.scoped(&scope)?;
4611- .and_then(|scope| {4634+ self.scope_holds_takes_whole(&on, start)?;
4612- let on = self.scoped(&scope)?;4635+ Ok(on)
4613- self.scope_holds_takes_whole(&on, start)?;4636+ }) {
4614- Ok(on)
4615- }) {
4616 Ok(on) => {4637 Ok(on) => {
4617 if !snapshot {4638 if !snapshot {
4618 self.snapshot();4639 self.snapshot();
@@ -5085,7 +5106,10 @@ impl Project {
5085 pub(crate) fn parts(&self) -> SweepParts {5106 pub(crate) fn parts(&self) -> SweepParts {
5086 SweepParts(5107 SweepParts(
5087 self.sources.len(),5108 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(),
5089 self.lanes.iter().map(|l| l.subs.clone()).collect(),5113 self.lanes.iter().map(|l| l.subs.clone()).collect(),
5090 self.subtitles.clone(),5114 self.subtitles.clone(),
5091 self.settings.clone(),5115 self.settings.clone(),
@@ -5373,7 +5397,6 @@ impl Project {
5373 self.next_link = self.next_link.saturating_add(1);5397 self.next_link = self.next_link.saturating_add(1);
5374 id5398 id
5375 }5399 }
5376-
5377 }5400 }
5378 5401
5379 /// The handle of every lane, in storage order -- the one definition of what5402 /// The handle of every lane, in storage order -- the one definition of what
@@ -5451,7 +5474,9 @@ impl GapPlacement for SubClip {
5451 /// Index of the placement covering `frame`, or `None` for a gap or past the5474 /// Index of the placement covering `frame`, or `None` for a gap or past the
5452 /// end. Binary search: the sorted-disjoint invariant is what makes it legal.5475 /// end. Binary search: the sorted-disjoint invariant is what makes it legal.
5453 fn at<T: GapPlacement>(items: &[T], frame: u32) -> Option<usize> {5476 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)?;
5455 (frame < items[idx].end_frame()).then_some(idx)5480 (frame < items[idx].end_frame()).then_some(idx)
5456 }5481 }
5457 5482
@@ -5667,10 +5692,7 @@ fn sub_joinable(subs: &[SubClip], frame: u32) -> Option<usize> {
5667 fn sub_edge_room(subs: &[SubClip], idx: usize, edge: Edge) -> (u32, u32) {5692 fn sub_edge_room(subs: &[SubClip], idx: usize, edge: Edge) -> (u32, u32) {
5668 let s = &subs[idx];5693 let s = &subs[idx];
5669 match edge {5694 match edge {
5670- Edge::Start => (5695+ Edge::Start => (idx.checked_sub(1).map_or(0, |p| subs[p].end()), s.end() - 1),
5671- idx.checked_sub(1).map_or(0, |p| subs[p].end()),
5672- s.end() - 1,
5673- ),
5674 Edge::End => (s.start + 1, subs.get(idx + 1).map_or(u32::MAX, |n| n.start)),5696 Edge::End => (s.start + 1, subs.get(idx + 1).map_or(u32::MAX, |n| n.start)),
5675 }5697 }
5676 }5698 }
@@ -5737,11 +5759,9 @@ fn links_are_consistent(lanes: &[LaneData]) -> crate::Result<()> {
5737 for (i, s) in data.subs.iter().enumerate() {5759 for (i, s) in data.subs.iter().enumerate() {
5738 let Some(id) = s.link else { continue };5760 let Some(id) = s.link else { continue };
5739 if data.subs[..i].iter().any(|prev| prev.link == Some(id)) {5761 if data.subs[..i].iter().any(|prev| prev.link == Some(id)) {
5740- return Err(format!(5762+ return Err(
5741- "link {id} names two captions in the {} lane",5763+ format!("link {id} names two captions in the {} lane", lane.label()).into(),
5742- lane.label()5764+ );
5743- )
5744- .into());
5745 }5765 }
5746 }5766 }
5747 }5767 }
@@ -6090,7 +6110,11 @@ mod tests {
6090 (f.gain_at(5) - midpoint.sin()).abs() < 1e-6,6110 (f.gain_at(5) - midpoint.sin()).abs() < 1e-6,
6091 "equal-power midpoint is sin(pi/4)"6111 "equal-power midpoint is sin(pi/4)"
6092 );6112 );
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+ );
6094 // The fade-out is the same curve, mirrored, counting down from the6118 // The fade-out is the same curve, mirrored, counting down from the
6095 // clip's end: unity at the frame the ramp starts, the same6119 // clip's end: unity at the frame the ramp starts, the same
6096 // equal-power midpoint, and -- since `total` itself is one past the6120 // equal-power midpoint, and -- since `total` itself is one past the
@@ -6114,14 +6138,8 @@ mod tests {
6114 fn crossfade_only_joins_adjacent_audio_clips() {6138 fn crossfade_only_joins_adjacent_audio_clips() {
6115 let mut p = Project::single(FILE, 20);6139 let mut p = Project::single(FILE, 20);
6116 assert!(p.split(10));6140 assert!(p.split(10));
6117- assert!(6141+ assert!(!p.crossfade(Lane::V1, 0, 5), "video is not an audio lane");
6118- !p.crossfade(Lane::V1, 0, 5),6142+ assert!(!p.crossfade(Lane::A1, 1, 5), "there is no clip after idx 1");
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- );
6125 assert!(p.crossfade(Lane::A1, 0, 5), "the two halves are adjacent");6143 assert!(p.crossfade(Lane::A1, 0, 5), "the two halves are adjacent");
6126 let a = p.lane(Lane::A1);6144 let a = p.lane(Lane::A1);
6127 assert_eq!(a[0].fade_out, 5);6145 assert_eq!(a[0].fade_out, 5);
@@ -6148,10 +6166,16 @@ mod tests {
6148 assert!(p.set_fade_out(Lane::V1, 0, 15));6166 assert!(p.set_fade_out(Lane::V1, 0, 15));
6149 assert!(p.split(5));6167 assert!(p.split(5));
6150 let v = p.lane(Lane::V1);6168 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+ );
6152 assert_eq!(v[0].fade_out, 0, "the cut edge it made starts flat");6173 assert_eq!(v[0].fade_out, 0, "the cut edge it made starts flat");
6153 assert_eq!(v[1].fade_in, 0, "the cut edge it made starts flat");6174 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+ );
6155 }6179 }
6156 6180
6157 /// [`Project::set_transition_out`] refuses a non-video lane, a clip with6181 /// [`Project::set_transition_out`] refuses a non-video lane, a clip with
@@ -6187,6 +6211,55 @@ mod tests {
6187 assert!(!p2.set_transition_out(v2, 0, 5), "a gap is not adjacent");6211 assert!(!p2.set_transition_out(v2, 0, 5), "a gap is not adjacent");
6188 }6212 }
6189 6213
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+
6190 /// The rule [`Project::write_split`] follows for [`Clip::transition_out`],6263 /// The rule [`Project::write_split`] follows for [`Clip::transition_out`],
6191 /// same shape as [`a_split_clamps_the_kept_fade_and_zeroes_the_cut_edge`]:6264 /// same shape as [`a_split_clamps_the_kept_fade_and_zeroes_the_cut_edge`]:
6192 /// only the half that kept the clip's original *end* keeps the dissolve,6265 /// only the half that kept the clip's original *end* keeps the dissolve,
@@ -6203,7 +6276,10 @@ mod tests {
6203 p.lane_mut(Lane::V1).unwrap()[0].transition_out = 15;6276 p.lane_mut(Lane::V1).unwrap()[0].transition_out = 15;
6204 assert!(p.split(5));6277 assert!(p.split(5));
6205 let v = p.lane(Lane::V1);6278 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+ );
6207 assert_eq!(6283 assert_eq!(
6208 v[1].transition_out, 15,6284 v[1].transition_out, 15,
6209 "the tail's kept dissolve, unclamped: 15 frames fit in 15"6285 "the tail's kept dissolve, unclamped: 15 frames fit in 15"
@@ -6451,11 +6527,7 @@ mod tests {
6451 p.group_all(&[(Lane::V1, 0), (v2, 0)])6527 p.group_all(&[(Lane::V1, 0), (v2, 0)])
6452 .expect("the clips group");6528 .expect("the clips group");
6453 let minted = p.lane(Lane::V1)[0].link.expect("grouped");6529 let minted = p.lane(Lane::V1)[0].link.expect("grouped");
6454- assert_ne!(6530+ assert_ne!(minted, 1, "the caption's id is not re-issued to clips");
6455- minted,
6456- 1,
6457- "the caption's id is not re-issued to clips"
6458- );
6459 assert_eq!(6531 assert_eq!(
6460 p.sub_lane(Lane::new(LaneKind::Subtitle, 0))[0].link,6532 p.sub_lane(Lane::new(LaneKind::Subtitle, 0))[0].link,
6461 Some(1),6533 Some(1),
@@ -6501,8 +6573,16 @@ mod tests {
6501 .expect("room for it");6573 .expect("room for it");
6502 assert_eq!(p.lane(Lane::V1)[0].frames(), 45);6574 assert_eq!(p.lane(Lane::V1)[0].frames(), 45);
6503 let s = p.sub_lane(s1)[0];6575 let s = p.sub_lane(s1)[0];
6504- assert_eq!((s.start, s.frames), (0, 45), "same words, half the timeline");6576+ assert_eq!(
6505- assert_eq!((s.in_us, s.out_us), (0, 90_000_000), "the window is untouched");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+ );
6506 assert!(links_are_consistent(&p.lanes).is_ok());6586 assert!(links_are_consistent(&p.lanes).is_ok());
6507 assert!(p.undo());6587 assert!(p.undo());
6508 assert_eq!(p.sub_lane(s1)[0].frames, 90, "one undo puts it back");6588 assert_eq!(p.sub_lane(s1)[0].frames, 90, "one undo puts it back");
@@ -6518,8 +6598,16 @@ mod tests {
6518 .expect("room for it");6598 .expect("room for it");
6519 assert_eq!(p.lane(Lane::V1)[0].frames(), 180);6599 assert_eq!(p.lane(Lane::V1)[0].frames(), 180);
6520 let s = p.sub_lane(s1)[0];6600 let s = p.sub_lane(s1)[0];
6521- assert_eq!((s.start, s.frames), (60, 120), "the offset doubles with the clip");6601+ assert_eq!(
6522- assert_eq!(s.end(), p.lane(Lane::V1)[0].end(), "still ends with the clip");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+ );
6523 6611
6524 // A stretch that runs the caption into its neighbour is refused, by6612 // A stretch that runs the caption into its neighbour is refused, by
6525 // lane and frame, and costs no undo step.6613 // lane and frame, and costs no undo step.
@@ -6534,7 +6622,9 @@ mod tests {
6534 .unwrap_err()6622 .unwrap_err()
6535 .to_string();6623 .to_string();
6536 assert!(6624 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+ ),
6538 "{err}"6628 "{err}"
6539 );6629 );
6540 assert_eq!(p.history.len(), history, "a refusal costs no undo step");6630 assert_eq!(p.history.len(), history, "a refusal costs no undo step");
@@ -6669,7 +6759,8 @@ mod tests {
6669 // An odd-length caption straddling the clip's tail edge: its6759 // An odd-length caption straddling the clip's tail edge: its
6670 // own last frame lands past the held clip.6760 // own last frame lands past the held clip.
6671 let c_start = len.saturating_sub(3);6761 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");
6673 p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");6764 p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");
6674 let speed = Speed::from_permille(permille);6765 let speed = Speed::from_permille(permille);
6675 let last = c_start + 7 - 1;6766 let last = c_start + 7 - 1;
@@ -6804,8 +6895,7 @@ mod tests {
6804 refused: None,6895 refused: None,
6805 };6896 };
6806 // A timeline of words alone: 60 frames of caption, no media clips.6897 // A timeline of words alone: 60 frames of caption, no media clips.
6807- let mut p = Project::single(FILE, 60)6898+ let mut p = Project::single(FILE, 60).with_subtitles(vec![track()]);
6808- .with_subtitles(vec![track()]);
6809 for l in [Lane::V1, Lane::A1] {6899 for l in [Lane::V1, Lane::A1] {
6810 while !p.lane(l).is_empty() {6900 while !p.lane(l).is_empty() {
6811 p.lift(l, 0);6901 p.lift(l, 0);
@@ -6871,16 +6961,31 @@ mod tests {
6871 .expect("the region speeds up");6961 .expect("the region speeds up");
6872 // Adjacent one-frame cues: both map to frame 5, and are forced apart.6962 // Adjacent one-frame cues: both map to frame 5, and are forced apart.
6873 let spans = |p: &Project, lane: Lane| -> Vec<(u32, u32)> {6963 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()
6875 };6968 };
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+ );
6877 // The three-frame pair: [5, 8) and [8, 11) map to [3, 5) and [4, 6),6974 // The three-frame pair: [5, 8) and [8, 11) map to [3, 5) and [4, 6),
6878 // and the walk pushes the second to where the first ends.6975 // 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+ );
6880 // The last cue of the region ends exactly where the region now does6981 // The last cue of the region ends exactly where the region now does
6881 // (frame 15), and the caption behind it lands on that same frame:6982 // (frame 15), and the caption behind it lands on that same frame:
6882 // touching, never overlapping.6983 // 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+ );
6884 for &lane in &lanes {6989 for &lane in &lanes {
6885 assert!(subs_sorted_disjoint(&p.lanes[p.index(lane).unwrap()].subs));6990 assert!(subs_sorted_disjoint(&p.lanes[p.index(lane).unwrap()].subs));
6886 }6991 }
@@ -6968,17 +7073,24 @@ mod tests {
6968 // Too few, one lane twice, and an index that is not there: words, no7073 // Too few, one lane twice, and an index that is not there: words, no
6969 // snapshot.7074 // snapshot.
6970 let history = p.history.len();7075 let history = p.history.len();
6971- assert!(p.group_all(&[]).unwrap_err().to_string().contains("two placements or more"));7076+ assert!(
6972- assert!(p7077+ p.group_all(&[])
6973- .group_all(&[(Lane::V1, 0), (Lane::V1, 0)])7078+ .unwrap_err()
6974- .unwrap_err()7079+ .to_string()
6975- .to_string()7080+ .contains("two placements or more")
6976- .contains("V1 is picked twice"));7081+ );
6977- assert!(p7082+ assert!(
6978- .group_all(&[(Lane::V1, 0), (s1, 9)])7083+ p.group_all(&[(Lane::V1, 0), (Lane::V1, 0)])
6979- .unwrap_err()7084+ .unwrap_err()
6980- .to_string()7085+ .to_string()
6981- .contains("no subtitle 9"));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+ );
6982 assert_eq!(p.history.len(), history, "refusals cost no undo step");7094 assert_eq!(p.history.len(), history, "refusals cost no undo step");
6983 7095
6984 // The group: the picture, the layer, and the caption -- and the sound7096 // The group: the picture, the layer, and the caption -- and the sound
@@ -6987,7 +7099,12 @@ mod tests {
6987 .expect("three picks, three lanes");7099 .expect("three picks, three lanes");
6988 let id = p.lane(Lane::V1)[0].link.expect("grouped");7100 let id = p.lane(Lane::V1)[0].link.expect("grouped");
6989 for lane in [Lane::V1, Lane::A1, v2] {7101 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+ );
6991 }7108 }
6992 assert_eq!(p.sub_lane(s1)[0].link, Some(id), "the caption is a member");7109 assert_eq!(p.sub_lane(s1)[0].link, Some(id), "the caption is a member");
6993 assert_eq!(p.sub_lane(s1)[0].frames, 6, "its own span, kept");7110 assert_eq!(p.sub_lane(s1)[0].frames, 6, "its own span, kept");
@@ -7053,7 +7170,11 @@ mod tests {
7053 .to_string();7170 .to_string();
7054 assert!(err.contains("one placement per lane"), "{err}");7171 assert!(err.contains("one placement per lane"), "{err}");
7055 assert_eq!(p.history.len(), history, "the refusal costs no undo step");7172 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+ );
7057 assert_eq!(p.lane(v2)[0].link, v2_link, "the second group untouched");7178 assert_eq!(p.lane(v2)[0].link, v2_link, "the second group untouched");
7058 assert!(links_are_consistent(&p.lanes).is_ok());7179 assert!(links_are_consistent(&p.lanes).is_ok());
7059 }7180 }
@@ -7138,8 +7259,15 @@ mod tests {
7138 // By the picture or by the caption, the same whole-group delete.7259 // By the picture or by the caption, the same whole-group delete.
7139 assert!(p.delete_sub_in(s1, 0));7260 assert!(p.delete_sub_in(s1, 0));
7140 assert!(p.lane(Lane::V1).is_empty(), "the take's span left V1");7261 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");7262+ assert!(
7142- assert_eq!(p.lane(v2)[0].start, 10, "a lane the group does not touch stays");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+ );
7143 assert!(links_are_consistent(&p.lanes).is_ok());7271 assert!(links_are_consistent(&p.lanes).is_ok());
7144 assert!(p.undo(), "one step puts the group back");7272 assert!(p.undo(), "one step puts the group back");
7145 assert_eq!(p.sub_lane(s1)[0].start, 2, "offsets and all");7273 assert_eq!(p.sub_lane(s1)[0].start, 2, "offsets and all");
@@ -7175,8 +7303,10 @@ mod tests {
7175 let group = || {7303 let group = || {
7176 let mut p = Project::single(FILE, 90).with_subtitles(vec![track()]);7304 let mut p = Project::single(FILE, 90).with_subtitles(vec![track()]);
7177 let s1 = p.add_lane(LaneKind::Subtitle);7305 let s1 = p.add_lane(LaneKind::Subtitle);
7178- p.place_sub(s1, 30, caption(30, 30)).expect("the group's caption");7306+ p.place_sub(s1, 30, caption(30, 30))
7179- p.place_sub(s1, 90, caption(90, 30)).expect("the caption behind");7307+ .expect("the group's caption");
7308+ p.place_sub(s1, 90, caption(90, 30))
7309+ .expect("the caption behind");
7180 p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");7310 p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");
7181 (p, s1)7311 (p, s1)
7182 };7312 };
@@ -7192,7 +7322,11 @@ mod tests {
7192 "the caption's lane closed by its own span: the follower slid up"7322 "the caption's lane closed by its own span: the follower slid up"
7193 );7323 );
7194 assert!(p.undo(), "one step");7324 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+ );
7196 7330
7197 // By the sound: the same whole-group delete.7331 // By the sound: the same whole-group delete.
7198 let (mut p, s1) = group();7332 let (mut p, s1) = group();
@@ -7204,7 +7338,11 @@ mod tests {
7204 let (mut p, s1) = group();7338 let (mut p, s1) = group();
7205 assert!(p.delete_sub_in(s1, 0));7339 assert!(p.delete_sub_in(s1, 0));
7206 assert!(p.lane(Lane::V1).is_empty() && p.lane(Lane::A1).is_empty());7340 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+ );
7208 assert!(links_are_consistent(&p.lanes).is_ok());7346 assert!(links_are_consistent(&p.lanes).is_ok());
7209 7347
7210 // A caption lifted ALONE still leaves its gap: the ungrouped law,7348 // A caption lifted ALONE still leaves its gap: the ungrouped law,
@@ -7213,7 +7351,8 @@ mod tests {
7213 assert!(p.ungroup(s1, 0), "the caption stands alone");7351 assert!(p.ungroup(s1, 0), "the caption stands alone");
7214 assert!(p.lift_sub(s1, 0));7352 assert!(p.lift_sub(s1, 0));
7215 assert_eq!(7353 assert_eq!(
7216- p.sub_lane(s1)[0].start, 90,7354+ p.sub_lane(s1)[0].start,
7355+ 90,
7217 "the follower stayed put: a lone caption's lift is a gap"7356 "the follower stayed put: a lone caption's lift is a gap"
7218 );7357 );
7219 }7358 }
@@ -7248,7 +7387,11 @@ mod tests {
7248 // Same lane, further along: everyone moves by the same eight frames.7387 // Same lane, further along: everyone moves by the same eight frames.
7249 p.move_sub(s1, 0, s1, 10).expect("room for all of it");7388 p.move_sub(s1, 0, s1, 10).expect("room for all of it");
7250 assert_eq!(p.sub_lane(s1)[0].start, 10);7389 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+ );
7252 assert!(links_are_consistent(&p.lanes).is_ok());7395 assert!(links_are_consistent(&p.lanes).is_ok());
7253 7396
7254 // ...and an ungrouped caption is the caption it always was.7397 // ...and an ungrouped caption is the caption it always was.
@@ -7257,11 +7400,12 @@ mod tests {
7257 let s1 = q.add_lane(LaneKind::Subtitle);7400 let s1 = q.add_lane(LaneKind::Subtitle);
7258 q.place_sub(s1, 0, caption(0, 4)).expect("placed");7401 q.place_sub(s1, 0, caption(0, 4)).expect("placed");
7259 q.place_sub(s1, 5, caption(5, 4)).expect("placed");7402 q.place_sub(s1, 5, caption(5, 4)).expect("placed");
7260- assert!(q7403+ assert!(
7261- .move_sub(s1, 0, s1, 3)7404+ q.move_sub(s1, 0, s1, 3)
7262- .unwrap_err()7405+ .unwrap_err()
7263- .to_string()7406+ .to_string()
7264- .contains("already covers"));7407+ .contains("already covers")
7408+ );
7265 }7409 }
7266 7410
7267 /// A trim carries a group's caption by the same delta as its clips, clamped7411 /// A trim carries a group's caption by the same delta as its clips, clamped
@@ -7478,8 +7622,14 @@ mod tests {
7478 // The clipboard's clamp lives in `PlaybackSession::paste_at`.7622 // The clipboard's clamp lives in `PlaybackSession::paste_at`.
7479 assert!(p.paste(1_000, PASTED));7623 assert!(p.paste(1_000, PASTED));
7480 assert_eq!(p.timeline_frames(), 1_002);7624 assert_eq!(p.timeline_frames(), 1_002);
7481- assert_eq!(p.lane(Lane::V1).last().expect("the pasted clip").start, 1_000);7625+ assert_eq!(
7482- assert_eq!(p.lane(Lane::A1).last().expect("its other half").start, 1_000);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+ );
7483 7633
7484 // An empty clip is the one thing refused, and it pushes no history.7634 // An empty clip is the one thing refused, and it pushes no history.
7485 let mut p = three();7635 let mut p = three();
@@ -7681,7 +7831,8 @@ mod tests {
7681 assert!(p.lift(Lane::V1, 0));7831 assert!(p.lift(Lane::V1, 0));
7682 let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();7832 let (sources, lanes, eq, color, _transform) = p.without_orphan_sources();
7683 assert_eq!(sources.len(), 1, "source 0 survives an emptied timeline");7833 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");
7685 assert_eq!(back.timeline_frames(), 0);7836 assert_eq!(back.timeline_frames(), 0);
7686 assert_eq!(back.lanes().len(), 2, "and it kept its lanes");7837 assert_eq!(back.lanes().len(), 2, "and it kept its lanes");
7687 }7838 }
@@ -7789,7 +7940,10 @@ mod tests {
7789 assert!(p.lane(v2).is_empty());7940 assert!(p.lane(v2).is_empty());
7790 7941
7791 // Refusals cost nothing: sound placed alone is `place`'s door.7942 // 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+ );
7793 assert!(!p.place_take(v2, 0, clip(0, 7, 7, 0)), "empty clip");7947 assert!(!p.place_take(v2, 0, clip(0, 7, 7, 0)), "empty clip");
7794 assert!(7948 assert!(
7795 !p.place_take(Lane::new(LaneKind::Video, 9), 0, clip(0, 1, 2, 0)),7949 !p.place_take(Lane::new(LaneKind::Video, 9), 0, clip(0, 1, 2, 0)),
@@ -7855,7 +8009,8 @@ mod tests {
7855 (LaneKind::Video, vec![clip(0, 0, 3, 0), clip(10, 3, 6, 0)]),8009 (LaneKind::Video, vec![clip(0, 0, 3, 0), clip(10, 3, 6, 0)]),
7856 (LaneKind::Audio, vec![clip(0, 0, 3, 0)]),8010 (LaneKind::Audio, vec![clip(0, 0, 3, 0)]),
7857 ];8011 ];
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");
7859 let before = shape(&p);8014 let before = shape(&p);
7860 8015
7861 // Into the gap, exactly where it was let go -- nothing else moves.8016 // Into the gap, exactly where it was let go -- nothing else moves.
@@ -8167,7 +8322,10 @@ mod tests {
8167 assert_eq!(p.gap_at(v, 8), None);8322 assert_eq!(p.gap_at(v, 8), None);
8168 assert_eq!(p.gap_at(v, 100), None);8323 assert_eq!(p.gap_at(v, 100), None);
8169 8324
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+ );
8171 // Between the two: the gap [8,12).8329 // Between the two: the gap [8,12).
8172 assert_eq!(p.gap_at(v, 8), Some((8, 4)));8330 assert_eq!(p.gap_at(v, 8), Some((8, 4)));
8173 assert_eq!(p.gap_at(v, 11), Some((8, 4)));8331 assert_eq!(p.gap_at(v, 11), Some((8, 4)));
@@ -8177,7 +8335,11 @@ mod tests {
8177 p.place(v, 8, clip(8, 0, 4, 0)),8335 p.place(v, 8, clip(8, 0, 4, 0)),
8178 "fills [8,12) exactly, meeting both neighbours"8336 "fills [8,12) exactly, meeting both neighbours"
8179 );8337 );
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+ );
8181 assert_eq!(p.gap_at(v, 11), None);8343 assert_eq!(p.gap_at(v, 11), None);
8182 }8344 }
8183 8345
@@ -8200,7 +8362,11 @@ mod tests {
8200 assert_eq!((start, len), (0, 5));8362 assert_eq!((start, len), (0, 5));
8201 assert!(p.cut_regions(&[(start, len)], &[v]).is_ok());8363 assert!(p.cut_regions(&[(start, len)], &[v]).is_ok());
8202 assert_eq!(p.lane(v)[0].start, 0, "the clip slid back to close the gap");8364 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+ );
8204 assert!(p.undo(), "one press undoes the whole close");8370 assert!(p.undo(), "one press undoes the whole close");
8205 assert_eq!(shape(&p), before, "back to exactly where it was");8371 assert_eq!(shape(&p), before, "back to exactly where it was");
8206 }8372 }
@@ -8238,11 +8404,21 @@ mod tests {
8238 let sources = vec![Source::new(FILE, 0)];8404 let sources = vec![Source::new(FILE, 0)];
8239 let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];8405 let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];
8240 let audio = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)];8406 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())8407+ let mut p = Project::from_parts(
8242- .expect("valid parts");8408+ sources,
8409+ two(video, audio),
8410+ Vec::new(),
8411+ Vec::new(),
8412+ Vec::new(),
8413+ )
8414+ .expect("valid parts");
8243 let before = shape(&p);8415 let before = shape(&p);
8244 assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));8416 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+ );
8246 8422
8247 let scope = p8423 let scope = p
8248 .gap_take_scope(Lane::V1, 3, 2)8424 .gap_take_scope(Lane::V1, 3, 2)
@@ -8252,7 +8428,11 @@ mod tests {
8252 8428
8253 assert!(p.cut_regions(&[(3, 2)], &scope).is_ok());8429 assert!(p.cut_regions(&[(3, 2)], &scope).is_ok());
8254 assert_eq!(p.lane(Lane::V1)[1].start, 3, "V1's far half slid back");8430 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+ );
8256 assert!(p.undo(), "one press undoes the whole close");8436 assert!(p.undo(), "one press undoes the whole close");
8257 assert_eq!(shape(&p), before, "back to exactly where it was");8437 assert_eq!(shape(&p), before, "back to exactly where it was");
8258 }8438 }
@@ -8270,8 +8450,14 @@ mod tests {
8270 // shorter than V1's [3,5) -- a legal offset-preserving group, and8450 // shorter than V1's [3,5) -- a legal offset-preserving group, and
8271 // still one take.8451 // still one take.
8272 let audio = vec![linked(0, 0, 3, 1), linked(4, 5, 9, 3)];8452 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())8453+ let p = Project::from_parts(
8274- .expect("valid parts");8454+ sources,
8455+ two(video, audio),
8456+ Vec::new(),
8457+ Vec::new(),
8458+ Vec::new(),
8459+ )
8460+ .expect("valid parts");
8275 assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));8461 assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));
8276 assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 1)), "a shorter gap on A1");8462 assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 1)), "a shorter gap on A1");
8277 8463
@@ -8293,10 +8479,20 @@ mod tests {
8293 // A1 plays through the whole span as one continuous clip, sharing8479 // A1 plays through the whole span as one continuous clip, sharing
8294 // V1's first-half link: nothing empty at frame 3 there at all.8480 // V1's first-half link: nothing empty at frame 3 there at all.
8295 let audio = vec![linked(0, 0, 9, 1)];8481 let audio = vec![linked(0, 0, 9, 1)];
8296- let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())8482+ let p = Project::from_parts(
8297- .expect("valid parts");8483+ sources,
8484+ two(video, audio),
8485+ Vec::new(),
8486+ Vec::new(),
8487+ Vec::new(),
8488+ )
8489+ .expect("valid parts");
8298 assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2)));8490 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+ );
8300 8496
8301 let err = p8497 let err = p
8302 .gap_take_scope(Lane::V1, 3, 2)8498 .gap_take_scope(Lane::V1, 3, 2)
@@ -8306,7 +8502,6 @@ mod tests {
8306 assert!(err.contains("detach"), "{err}");8502 assert!(err.contains("detach"), "{err}");
8307 }8503 }
8308 8504
8309-
8310 /// The sweep is the single-gap close repeated on one lane, but measured once8505 /// The sweep is the single-gap close repeated on one lane, but measured once
8311 /// and applied from the right. The differing gap lengths here expose a8506 /// and applied from the right. The differing gap lengths here expose a
8312 /// front-to-back bug: the last clip would be cut against a stale frame after8507 /// front-to-back bug: the last clip would be cut against a stale frame after
@@ -8342,14 +8537,20 @@ mod tests {
8342 let v = p.add_lane(LaneKind::Video);8537 let v = p.add_lane(LaneKind::Video);
8343 let history = p.history.len();8538 let history = p.history.len();
8344 let report = p.close_all_gaps_on_lane(v).expect("empty lane exists");8539 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+ );
8346 assert_eq!(p.history.len(), history, "no undo step for a no-op");8545 assert_eq!(p.history.len(), history, "no undo step for a no-op");
8347 8546
8348 let mut p = Project::single(FILE, 9);8547 let mut p = Project::single(FILE, 9);
8349 let v = p.add_lane(LaneKind::Video);8548 let v = p.add_lane(LaneKind::Video);
8350 assert!(p.place(v, 5, clip(5, 0, 3, 0)));8549 assert!(p.place(v, 5, clip(5, 0, 3, 0)));
8351 let before = shape(&p);8550 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");
8353 assert_eq!(report.closed, 1, "the head gap closes");8554 assert_eq!(report.closed, 1, "the head gap closes");
8354 assert_eq!(p.lane(v), &[clip(0, 0, 3, 0)]);8555 assert_eq!(p.lane(v), &[clip(0, 0, 3, 0)]);
8355 assert!(p.undo());8556 assert!(p.undo());
@@ -8366,7 +8567,11 @@ mod tests {
8366 assert!(p.place(v, 0, clip(0, 0, 3, 0)));8567 assert!(p.place(v, 0, clip(0, 0, 3, 0)));
8367 let history = p.history.len();8568 let history = p.history.len();
8368 let report = p.close_all_gaps_on_lane(v).expect("tail-only lane exists");8569 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+ );
8370 assert_eq!(p.lane(v), &[clip(0, 0, 3, 0)]);8575 assert_eq!(p.lane(v), &[clip(0, 0, 3, 0)]);
8371 assert_eq!(p.history.len(), history);8576 assert_eq!(p.history.len(), history);
8372 }8577 }
@@ -8377,19 +8582,16 @@ mod tests {
8377 #[test]8582 #[test]
8378 fn close_all_gaps_on_one_lane_partially_closes_linked_takes_and_reports_skips() {8583 fn close_all_gaps_on_one_lane_partially_closes_linked_takes_and_reports_skips() {
8379 let sources = vec![Source::new(FILE, 0)];8584 let sources = vec![Source::new(FILE, 0)];
8380- let video = vec![8585+ let video = vec![linked(0, 0, 2, 1), linked(4, 4, 6, 2), clip(9, 9, 11, 0)];
8381- linked(0, 0, 2, 1),8586+ let audio = vec![linked(0, 0, 2, 1), linked(4, 4, 6, 2), clip(8, 8, 11, 0)];
8382- linked(4, 4, 6, 2),8587+ let mut p = Project::from_parts(
8383- clip(9, 9, 11, 0),8588+ sources,
8384- ];8589+ two(video, audio),
8385- let audio = vec![8590+ Vec::new(),
8386- linked(0, 0, 2, 1),8591+ Vec::new(),
8387- linked(4, 4, 6, 2),8592+ Vec::new(),
8388- clip(8, 8, 11, 0),8593+ )
8389- ];8594+ .expect("valid parts");
8390- let mut p =
8391- Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new())
8392- .expect("valid parts");
8393 let before = shape(&p);8595 let before = shape(&p);
8394 8596
8395 let report = p.close_all_gaps_on_lane(Lane::V1).expect("V1 exists");8597 let report = p.close_all_gaps_on_lane(Lane::V1).expect("V1 exists");
@@ -8397,12 +8599,27 @@ mod tests {
8397 assert_eq!(report.skipped.len(), 1);8599 assert_eq!(report.skipped.len(), 1);
8398 assert_eq!(report.skipped[0].start, 6);8600 assert_eq!(report.skipped[0].start, 6);
8399 assert!(report.skipped[0].reason.contains("A1"), "{report:?}");8601 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+ );
8401 8606
8402 assert_eq!(p.lane(Lane::V1)[1].start, 2, "the matched take moved");8607 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");8608+ assert_eq!(
8404- assert_eq!(p.lane(Lane::V1)[2].start, 7, "the skipped later gap remains");8609+ p.lane(Lane::A1)[1].start,
8405- assert_eq!(p.lane(Lane::A1)[2].start, 6, "A1's shorter gap remains shorter");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+ );
8406 links_are_consistent(&p.lanes).expect("every linked take that moved stayed whole");8623 links_are_consistent(&p.lanes).expect("every linked take that moved stayed whole");
8407 assert!(p.undo(), "one undo restores every closed gap");8624 assert!(p.undo(), "one undo restores every closed gap");
8408 assert_eq!(shape(&p), before);8625 assert_eq!(shape(&p), before);
@@ -8415,18 +8632,28 @@ mod tests {
8415 fn gap_at_finds_the_hole_a_caption_frame_sits_in() {8632 fn gap_at_finds_the_hole_a_caption_frame_sits_in() {
8416 let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]);8633 let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]);
8417 let s = p.add_lane(LaneKind::Subtitle);8634 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+ );
8419 8640
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)");
8421 assert_eq!(p.gap_at(s, 0), Some((0, 5)), "head gap before first cue");8643 assert_eq!(p.gap_at(s, 0), Some((0, 5)), "head gap before first cue");
8422 assert_eq!(p.gap_at(s, 4), Some((0, 5)));8644 assert_eq!(p.gap_at(s, 4), Some((0, 5)));
8423 assert_eq!(p.gap_at(s, 5), None, "inside the cue");8645 assert_eq!(p.gap_at(s, 5), None, "inside the cue");
8424 assert_eq!(p.gap_at(s, 8), None, "tail after a single cue is not a gap");8646 assert_eq!(p.gap_at(s, 8), None, "tail after a single cue is not a gap");
8425 8647
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)");
8427 assert_eq!(p.gap_at(s, 8), Some((8, 4)), "gap between cues");8650 assert_eq!(p.gap_at(s, 8), Some((8, 4)), "gap between cues");
8428 assert_eq!(p.gap_at(s, 11), Some((8, 4)));8651 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+ );
8430 }8657 }
8431 8658
8432 /// Closing a caption gap ripples the subtitle lane only. It is not a media8659 /// Closing a caption gap ripples the subtitle lane only. It is not a media
@@ -8435,13 +8662,15 @@ mod tests {
8435 fn closing_a_caption_gap_ripples_no_video_or_audio_clips() {8662 fn closing_a_caption_gap_ripples_no_video_or_audio_clips() {
8436 let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]);8663 let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]);
8437 let s = p.add_lane(LaneKind::Subtitle);8664 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)");
8439 let before_clips = shape(&p);8667 let before_clips = shape(&p);
8440 let before_subs = p.sub_lane(s).to_vec();8668 let before_subs = p.sub_lane(s).to_vec();
8441 8669
8442 let (start, len) = p.gap_at(s, 0).expect("gap before the caption");8670 let (start, len) = p.gap_at(s, 0).expect("gap before the caption");
8443 assert_eq!((start, len), (0, 5));8671 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");
8445 8674
8446 assert_eq!(shape(&p), before_clips, "media lanes did not move");8675 assert_eq!(shape(&p), before_clips, "media lanes did not move");
8447 assert_eq!(p.sub_lane(s), &[caption(0, 3)], "caption slid left");8676 assert_eq!(p.sub_lane(s), &[caption(0, 3)], "caption slid left");
@@ -8458,13 +8687,20 @@ mod tests {
8458 let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]);8687 let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]);
8459 let s = p.add_lane(LaneKind::Subtitle);8688 let s = p.add_lane(LaneKind::Subtitle);
8460 let history = p.history.len();8689 let history = p.history.len();
8461- let report = p.close_all_gaps_on_lane(s).expect("empty subtitle lane exists");8690+ let report = p
8462- assert_eq!(report, GapSweep::default(), "empty subtitle lane has no bounded gap");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+ );
8463 assert_eq!(p.history.len(), history, "empty sweep is not an undo step");8698 assert_eq!(p.history.len(), history, "empty sweep is not an undo step");
8464 8699
8465 p.place_sub(s, 2, caption(0, 2)).expect("head gap [0,2)");8700 p.place_sub(s, 2, caption(0, 2)).expect("head gap [0,2)");
8466 p.place_sub(s, 7, caption(0, 2)).expect("middle gap [4,7)");8701 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");
8468 let before = p.sub_lane(s).to_vec();8704 let before = p.sub_lane(s).to_vec();
8469 8705
8470 assert_eq!(p.gap_count(s), 3);8706 assert_eq!(p.gap_count(s), 3);
@@ -8481,7 +8717,8 @@ mod tests {
8481 8717
8482 let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]);8718 let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]);
8483 let s = p.add_lane(LaneKind::Subtitle);8719 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");
8485 let history = p.history.len();8722 let history = p.history.len();
8486 let report = p.close_all_gaps_on_lane(s).expect("subtitle lane exists");8723 let report = p.close_all_gaps_on_lane(s).expect("subtitle lane exists");
8487 assert_eq!(report, GapSweep::default(), "the open tail is not closed");8724 assert_eq!(report, GapSweep::default(), "the open tail is not closed");
@@ -8789,7 +9026,8 @@ mod tests {
8789 [0, 1]9026 [0, 1]
8790 );9027 );
8791 // ...and what comes out is loadable, with the same timeline.9028 // ...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");
8793 assert_eq!(reloaded.timeline_frames(), p.timeline_frames());9031 assert_eq!(reloaded.timeline_frames(), p.timeline_frames());
8794 assert_eq!(reloaded.sources().len(), 2);9032 assert_eq!(reloaded.sources().len(), 2);
8795 }9033 }
@@ -9279,8 +9517,14 @@ mod tests {
9279 fn from_parts_has_no_history_and_checks_the_invariants() {9517 fn from_parts_has_no_history_and_checks_the_invariants() {
9280 let (sources, lanes, eq, color, _transform) = three().without_orphan_sources();9518 let (sources, lanes, eq, color, _transform) = three().without_orphan_sources();
9281 let (video, audio) = (lanes[0].1.clone(), lanes[1].1.clone());9519 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())9520+ let mut p = Project::from_parts(
9283- .expect("valid parts");9521+ sources.clone(),
9522+ lanes.clone(),
9523+ eq.clone(),
9524+ color.clone(),
9525+ Vec::new(),
9526+ )
9527+ .expect("valid parts");
9284 assert_eq!(p.clips(), three().clips());9528 assert_eq!(p.clips(), three().clips());
9285 assert!(!p.undo(), "a loaded project has nothing to undo");9529 assert!(!p.undo(), "a loaded project has nothing to undo");
9286 assert!(p.split(4), "...and is editable from there");9530 assert!(p.split(4), "...and is editable from there");
@@ -9308,7 +9552,16 @@ mod tests {
9308 )9552 )
9309 .is_ok()9553 .is_ok()
9310 );9554 );
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+ );
9312 let bad: [Vec<Clip>; 5] = [9565 let bad: [Vec<Clip>; 5] = [
9313 vec![clip(0, 0, 3, 1)], // source that is not there9566 vec![clip(0, 0, 3, 1)], // source that is not there
9314 vec![clip(0, 3, 3, 0)], // empty clip9567 vec![clip(0, 3, 3, 0)], // empty clip
@@ -9449,7 +9702,8 @@ mod tests {
9449 assert_eq!(loaded.color_of(Lane::V1, 0), Some(&grade_at(1)));9702 assert_eq!(loaded.color_of(Lane::V1, 0), Some(&grade_at(1)));
9450 9703
9451 // Group ids survive a load, and the next split gets a fresh one.9704 // 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");
9453 assert!(p.split(4));9707 assert!(p.split(4));
9454 assert!(p.clips().iter().all(|c| c.link.is_some()));9708 assert!(p.clips().iter().all(|c| c.link.is_some()));
9455 }9709 }
@@ -9487,9 +9741,15 @@ mod tests {
9487 9741
9488 // The door: a doubled id inside one lane, refused by name.9742 // The door: a doubled id inside one lane, refused by name.
9489 let err = |video: Vec<Clip>, audio: Vec<Clip>| {9743 let err = |video: Vec<Clip>, audio: Vec<Clip>| {
9490- Project::from_parts(sources.clone(), two(video, audio), Vec::new(), Vec::new(), Vec::new())9744+ Project::from_parts(
9491- .expect_err("refused")9745+ sources.clone(),
9492- .to_string()9746+ two(video, audio),
9747+ Vec::new(),
9748+ Vec::new(),
9749+ Vec::new(),
9750+ )
9751+ .expect_err("refused")
9752+ .to_string()
9493 };9753 };
9494 assert!(9754 assert!(
9495 err(vec![linked(0, 0, 3, 7), linked(3, 3, 5, 7)], Vec::new())9755 err(vec![linked(0, 0, 3, 7), linked(3, 3, 5, 7)], Vec::new())
@@ -10197,7 +10457,8 @@ mod tests {
10197 lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(),10457 lanes.iter().map(|(k, _)| *k).collect::<Vec<_>>(),
10198 [LaneKind::Video, LaneKind::Video, LaneKind::Audio]10458 [LaneKind::Video, LaneKind::Video, LaneKind::Audio]
10199 );10459 );
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");
10201 assert_eq!(back.lanes(), p.lanes());10462 assert_eq!(back.lanes(), p.lanes());
10202 assert_eq!(shape(&back), shape(&p), "the same lane is still on top");10463 assert_eq!(shape(&back), shape(&p), "the same lane is still on top");
10203 10464
@@ -10215,7 +10476,10 @@ mod tests {
10215 let mut p = Project::single(FILE, 9);10476 let mut p = Project::single(FILE, 9);
10216 let take = p.clips()[0].link.expect("a fresh project is one take");10477 let take = p.clips()[0].link.expect("a fresh project is one take");
10217 let v2 = p.add_lane(LaneKind::Video);10478 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+ );
10219 assert!(p.split(4));10483 assert!(p.split(4));
10220 let side = |p: &Project, i: usize| -> Vec<Option<u32>> {10484 let side = |p: &Project, i: usize| -> Vec<Option<u32>> {
10221 p.lanes().into_iter().map(|l| p.lane(l)[i].link).collect()10485 p.lanes().into_iter().map(|l| p.lane(l)[i].link).collect()
@@ -10345,7 +10609,8 @@ mod tests {
10345 assert_eq!(lanes[2].1, p.lane(v2), "V2's clips are written");10609 assert_eq!(lanes[2].1, p.lane(v2), "V2's clips are written");
10346 assert!(lanes[3].1.is_empty(), "and the empty A2 is still a lane");10610 assert!(lanes[3].1.is_empty(), "and the empty A2 is still a lane");
10347 // ...and all four load again as the same four.10611 // ...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");
10349 assert_eq!(back.lanes(), p.lanes());10614 assert_eq!(back.lanes(), p.lanes());
10350 assert_eq!(back.lane(a2), p.lane(a2));10615 assert_eq!(back.lane(a2), p.lane(a2));
10351 10616
@@ -10438,7 +10703,8 @@ mod tests {
10438 (LaneKind::Video, vec![clip(10, 5, 15, 1)]),10703 (LaneKind::Video, vec![clip(10, 5, 15, 1)]),
10439 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),10704 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),
10440 ];10705 ];
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");
10442 assert_eq!(10708 assert_eq!(
10443 p.composite_spans_from(0),10709 p.composite_spans_from(0),
10444 vec![10710 vec![
@@ -10483,7 +10749,8 @@ mod tests {
10483 (LaneKind::Video, vec![clip(10, 0, 10, 1)]),10749 (LaneKind::Video, vec![clip(10, 0, 10, 1)]),
10484 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),10750 (LaneKind::Audio, vec![clip(0, 0, 30, 0)]),
10485 ];10751 ];
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");
10487 assert_eq!(10754 assert_eq!(
10488 p.composite_spans_from(0),10755 p.composite_spans_from(0),
10489 vec![10756 vec![
@@ -10531,7 +10798,8 @@ mod tests {
10531 (LaneKind::Audio, vec![clip(15, 0, 15, 1)]),10798 (LaneKind::Audio, vec![clip(15, 0, 15, 1)]),
10532 (LaneKind::Audio, Vec::new()),10799 (LaneKind::Audio, Vec::new()),
10533 ];10800 ];
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");
10535 let lists = p.audio_segments_from(0, FPS);10803 let lists = p.audio_segments_from(0, FPS);
10536 assert_eq!(lists.len(), 2, "the empty lane is not mixed in");10804 assert_eq!(lists.len(), 2, "the empty lane is not mixed in");
10537 assert_eq!(lists[0], p.segments_from(0, FPS), "A1 is unchanged");10805 assert_eq!(lists[0], p.segments_from(0, FPS), "A1 is unchanged");
@@ -10554,41 +10822,47 @@ mod tests {
10554 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);10822 assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]);
10555 }10823 }
10556 10824
10557-/// D4: removing a subtitle column used to clear the whole undo history,10825+ /// 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 the10826+ /// 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 the10827+ /// 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.10828+ /// palette beside the lanes now, so the reindex undoes with it.
10561-#[test]10829+ #[test]
10562-fn removing_a_subtitle_column_undoes_with_its_reindex() {10830+ fn removing_a_subtitle_column_undoes_with_its_reindex() {
10563- let track = |label: &str| SubtitleTrack {10831+ let track = |label: &str| SubtitleTrack {
10564- path: FILE.into(),10832+ path: FILE.into(),
10565- track: None,10833+ track: None,
10566- language: "eng".into(),10834+ language: "eng".into(),
10567- name: String::new(),10835+ name: String::new(),
10568- label: label.into(),10836+ label: label.into(),
10569- cues: Vec::new(),10837+ cues: Vec::new(),
10570- bitmap: false,10838+ bitmap: false,
10571- refused: None,10839+ refused: None,
10572- };10840+ };
10573- let mut p = Project::single(FILE, 300)10841+ let mut p = Project::single(FILE, 300).with_subtitles(vec![
10574- .with_subtitles(vec![track("one"), track("two"), track("three")]);10842+ track("one"),
10575- assert_eq!(p.subtitles().len(), 3);10843+ track("two"),
10576- let before = p.parts();10844+ track("three"),
10577- let palette = p.subtitles().to_vec();10845+ ]);
10578- // Column 0 goes, which renumbers the two behind it.10846+ assert_eq!(p.subtitles().len(), 3);
10579- p.remove_subtitles(0).expect("a column with nothing on it");10847+ let before = p.parts();
10580- assert_eq!(p.subtitles().len(), 2);10848+ let palette = p.subtitles().to_vec();
10581- assert_eq!(p.subtitles()[0].label, "two");10849+ // Column 0 goes, which renumbers the two behind it.
10582- assert!(p.undo(), "the removal is a step like any other cut");10850+ p.remove_subtitles(0).expect("a column with nothing on it");
10583- // The palette itself, and not only what `parts` happens to compare: this10851+ assert_eq!(p.subtitles().len(), 2);
10584- // is the assertion that cannot go vacuous if the restore below it ever10852+ assert_eq!(p.subtitles()[0].label, "two");
10585- // leaves a field of it behind.10853+ assert!(p.undo(), "the removal is a step like any other cut");
10586- assert_eq!(p.subtitles(), palette.as_slice(), "the palette itself, back");10854+ // The palette itself, and not only what `parts` happens to compare: this
10587- assert_eq!(p.parts(), before, "the palette and the lanes, both back");10855+ // is the assertion that cannot go vacuous if the restore below it ever
10588- assert!(p.redo(), "and forward again");10856+ // leaves a field of it behind.
10589- assert_eq!(p.subtitles().len(), 2, "the column goes again");10857+ assert_eq!(
10590- assert_eq!(p.subtitles()[0].label, "two");10858+ p.subtitles(),
10591- assert_ne!(p.subtitles(), palette.as_slice(), "and it is not back");10859+ palette.as_slice(),
10592-}10860+ "the palette itself, back"
10593-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+ }
10594 }10868 }
crates/engine/src/proxy.rsmodified+71 -8
@@ -32,8 +32,8 @@
32 //! cancel a file export has ([`Job`]).32 //! cancel a file export has ([`Job`]).
33 33
34 use std::path::{Path, PathBuf};34 use std::path::{Path, PathBuf};
35-use std::sync::atomic::AtomicBool;
36 use std::sync::Arc;35 use std::sync::Arc;
36+use std::sync::atomic::AtomicBool;
37 use std::time::UNIX_EPOCH;37 use std::time::UNIX_EPOCH;
38 38
39 use crate::demux::{Codec, Demuxer, NoVideoTrack, VideoMeta};39 use crate::demux::{Codec, Demuxer, NoVideoTrack, VideoMeta};
@@ -93,8 +93,20 @@ const BITS_PER_PIXEL: f64 = 0.3;
93 /// Whether this is a file worth standing in for: bigger than 1080p, or coded in93 /// Whether this is a file worth standing in for: bigger than 1080p, or coded in
94 /// something this machine decodes slowly even at 1080p. H.264 at or under 1080p94 /// something this machine decodes slowly even at 1080p. H.264 at or under 1080p
95 /// plays natively and a proxy of it would cost time and buy nothing.95 /// 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.
96 pub fn wanted(meta: &VideoMeta) -> bool {106 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)
98 }110 }
99 111
100 /// The picture a proxy of `meta` is coded at: aspect kept, long edge at most112 /// The picture a proxy of `meta` is coded at: aspect kept, long edge at most
@@ -628,7 +640,27 @@ mod tests {
628 Arc::new(AtomicBool::new(false))640 Arc::new(AtomicBool::new(false))
629 }641 }
630 642
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+ };
632 VideoMeta {664 VideoMeta {
633 width,665 width,
634 height,666 height,
@@ -636,11 +668,9 @@ mod tests {
636 frame_count: 240,668 frame_count: 240,
637 codec,669 codec,
638 color: ColorDescription::default(),670 color: ColorDescription::default(),
639- rotation: Rotation::None,671+ rotation,
640- // Square pixels, coded where they are declared: a meta no672+ coded_width,
641- // container wrote, so nothing was read to disagree with it.673+ coded_height,
642- coded_width: width,
643- coded_height: height,
644 pixel_aspect: crate::demux::PixelAspect::SQUARE,674 pixel_aspect: crate::demux::PixelAspect::SQUARE,
645 }675 }
646 }676 }
@@ -657,6 +687,39 @@ mod tests {
657 "1080p H.264 plays natively"687 "1080p H.264 plays natively"
658 );688 );
659 assert!(!wanted(&meta(1280, 720, Codec::H264)), "720p H.264");689 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+ );
660 }723 }
661 724
662 /// Aspect kept, long edge capped, both axes even -- and a small source left725 /// Aspect kept, long edge capped, both axes even -- and a small source left