forge
Explore
Log in

Don't you dare go Hollow

The picture may come off the stand-in, the delivery never does

Browse files at this commit

79c69dde77c0f0c0aaded3b251624b9009873e6fAhmet Kaan GümüşParent: 83e561d
  • feat
    • the picture may come off the stand-in, the delivery never does
Show full message
✨ feat(engine): the picture may come off the stand-in, the delivery never does

One switch for the project, saved with it as the v12 `proxy` line, and
one place that reads it: the span open asks `picture_path`, which hands
back the stand-in where the cache has one and the film itself
everywhere else. The sound is opened elsewhere and is always the film's;
`export` reads the project's own sources and knows nothing of proxies,
so a delivery cannot come off one -- and both sides now say out loud
which file they read (`export source:` / `picture: proxy`), so that is a
grep rather than a belief.

*Which* films have a stand-in is deliberately not saved: a proxy is
found by the film's own path, length and modification time, so the cache
is the single answer and a project file cannot go stale about it. A v11
project loads unchanged and is cut on its films, which is all it could
ever do.
crates/engine/src/edith.rsmodified+131 -22
@@ -1,11 +1,12 @@
1 //! The project file: a line of text per thing, and nothing else.1 //! The project file: a line of text per thing, and nothing else.
2 //!2 //!
3 //! ```text3 //! ```text
4-//! edith 114+//! edith 12
5 //! playhead 905 //! playhead 90
6 //! resolution 1920 10806 //! resolution 1920 1080
7 //! fps 30.07 //! fps 30.0
8 //! tonemap vivid8 //! tonemap vivid
9+//! proxy on
9 //! limiter -1.0 on10 //! limiter -1.0 on
10 //! source 0 test_av.mp411 //! source 0 test_av.mp4
11 //! source 1 /elsewhere/test_av2.mp412 //! source 1 /elsewhere/test_av2.mp4
@@ -44,6 +45,13 @@
44 //! project holding no HDR media, and one whose owner never picked, are the bytes45 //! project holding no HDR media, and one whose owner never picked, are the bytes
45 //! they were.46 //! they were.
46 //!47 //!
48+//! The `proxy` line is whether this project is cut on the stand-ins
49+//! ([`crate::proxy`]) rather than on the films themselves, spelled `on` or
50+//! `off`. Left out when it is off, which is what every dialect before v12 was.
51+//! *Which* sources have a stand-in is not written: a proxy is found by the
52+//! film's own path, length and modification time, so the cache is the only
53+//! answer and a project file cannot go stale about it.
54+//!
47 //! The `limiter` line is the master limiter over the whole mix55 //! The `limiter` line is the master limiter over the whole mix
48 //! ([`crate::limiter`]): its ceiling in dBFS and whether it is in circuit,56 //! ([`crate::limiter`]): its ceiling in dBFS and whether it is in circuit,
49 //! spelled `on` or `off`. Left out when it is the default, which is off.57 //! spelled `on` or `off`. Left out when it is the default, which is off.
@@ -100,7 +108,9 @@
100 //! is the only way an empty lane could still be there on the way back. A lane108 //! is the only way an empty lane could still be there on the way back. A lane
101 //! number may not skip one of its kind.109 //! number may not skip one of its kind.
102 //!110 //!
103-//! **Version 10** was this without the `tonemap` line: such a project is shown111+//! **Version 11** was this without the `proxy` line: such a project is cut on
112+//! its films themselves, which is all any project could do.
113+//! **Version 10** was that without the `tonemap` line: such a project is shown
104 //! in the reference rendition, which is the only one there was.114 //! in the reference rendition, which is the only one there was.
105 //! **Version 9** was that without the `subtitle` lines: such a project shows no115 //! **Version 9** was that without the `subtitle` lines: such a project shows no
106 //! subtitles, which is all any project could do.116 //! subtitles, which is all any project could do.
@@ -159,7 +169,8 @@ use crate::subtitle::SubtitleTrack;
159 169
160 /// What [`save`] writes. Read support goes back to `edith 1`; see the module170 /// What [`save`] writes. Read support goes back to `edith 1`; see the module
161 /// docs for what those dialects looked like.171 /// docs for what those dialects looked like.
162-const MAGIC: &[u8] = b"edith 11";172+const MAGIC: &[u8] = b"edith 12";
173+const MAGIC_V11: &[u8] = b"edith 11";
163 const MAGIC_V10: &[u8] = b"edith 10";174 const MAGIC_V10: &[u8] = b"edith 10";
164 const MAGIC_V9: &[u8] = b"edith 9";175 const MAGIC_V9: &[u8] = b"edith 9";
165 const MAGIC_V8: &[u8] = b"edith 8";176 const MAGIC_V8: &[u8] = b"edith 8";
@@ -214,6 +225,11 @@ pub struct Document {
214 /// for a v11 file that leaves the line out, which both mean the published225 /// for a v11 file that leaves the line out, which both mean the published
215 /// conversion -- the only one those projects had.226 /// conversion -- the only one those projects had.
216 pub tone: crate::tonemap::Preset,227 pub tone: crate::tonemap::Preset,
228+ /// Whether the films are cut on their stand-ins ([`crate::proxy`]). `false`
229+ /// for every dialect before v12 and for a v12 file that leaves the line
230+ /// out, which both mean the films themselves -- the only thing those
231+ /// projects could do.
232+ pub proxy: bool,
217 pub playhead: u32,233 pub playhead: u32,
218 }234 }
219 235
@@ -233,6 +249,7 @@ pub fn save(
233 resolution: (u32, u32),249 resolution: (u32, u32),
234 fps: Option<f64>,250 fps: Option<f64>,
235 tone: crate::tonemap::Preset,251 tone: crate::tonemap::Preset,
252+ proxy: bool,
236 limiter: Limiter,253 limiter: Limiter,
237 playhead: u32,254 playhead: u32,
238 ) -> crate::Result<()> {255 ) -> crate::Result<()> {
@@ -247,7 +264,7 @@ pub fn save(
247 let result = std::fs::File::create(&part)264 let result = std::fs::File::create(&part)
248 .and_then(|mut f| {265 .and_then(|mut f| {
249 f.write_all(&emit(266 f.write_all(&emit(
250- &dir, sources, lanes, gains, subtitles, eq, color, resolution, fps, tone,267+ &dir, sources, lanes, gains, subtitles, eq, color, resolution, fps, tone, proxy,
251 limiter, playhead,268 limiter, playhead,
252 ))?;269 ))?;
253 f.sync_all()270 f.sync_all()
@@ -291,6 +308,7 @@ fn emit(
291 resolution: (u32, u32),308 resolution: (u32, u32),
292 fps: Option<f64>,309 fps: Option<f64>,
293 tone: crate::tonemap::Preset,310 tone: crate::tonemap::Preset,
311+ proxy: bool,
294 limiter: Limiter,312 limiter: Limiter,
295 playhead: u32,313 playhead: u32,
296 ) -> Vec<u8> {314 ) -> Vec<u8> {
@@ -310,6 +328,11 @@ fn emit(
310 if tone != crate::tonemap::Preset::default() {328 if tone != crate::tonemap::Preset::default() {
311 out.extend_from_slice(format!("tonemap {}\n", tone.name()).as_bytes());329 out.extend_from_slice(format!("tonemap {}\n", tone.name()).as_bytes());
312 }330 }
331+ // Beside it and by the same rule: a project cut on the films themselves --
332+ // every project before there were stand-ins -- says nothing here.
333+ if proxy {
334+ out.extend_from_slice(b"proxy on\n");
335+ }
313 // Written only when it is not the default, so a project nobody has limited336 // Written only when it is not the default, so a project nobody has limited
314 // is the same bytes it was in v8 bar the version line.337 // is the same bytes it was in v8 bar the version line.
315 if limiter != Limiter::default() {338 if limiter != Limiter::default() {
@@ -439,8 +462,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
439 // The dialects that wrote a source line without its stream field. Reading462 // The dialects that wrote a source line without its stream field. Reading
440 // one is the whole of what "an old project still opens" means here.463 // one is the whole of what "an old project still opens" means here.
441 let streamless = v1 || first == MAGIC_V2;464 let streamless = v1 || first == MAGIC_V2;
442- // The one that carries an HDR rendition...465+ // The one that says whether it is cut on stand-ins...
443- let v11 = first == MAGIC;466+ let v12 = first == MAGIC;
467+ // ...the ones that carry an HDR rendition...
468+ let v11 = v12 || first == MAGIC_V11;
444 // ...the ones that carry subtitle tracks...469 // ...the ones that carry subtitle tracks...
445 let v10 = v11 || first == MAGIC_V10;470 let v10 = v11 || first == MAGIC_V10;
446 // ...the ones that carry the mix -- lane volumes, the master limiter and471 // ...the ones that carry the mix -- lane volumes, the master limiter and
@@ -487,6 +512,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
487 subtitles: Vec::new(),512 subtitles: Vec::new(),
488 limiter: Limiter::default(),513 limiter: Limiter::default(),
489 tone: crate::tonemap::Preset::default(),514 tone: crate::tonemap::Preset::default(),
515+ proxy: false,
490 fps: None,516 fps: None,
491 playhead: 0,517 playhead: 0,
492 };518 };
@@ -557,6 +583,25 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
557 )583 )
558 })?;584 })?;
559 }585 }
586+ b"proxy" if v12 => {
587+ if !doc.sources.is_empty() {
588+ return Err(
589+ format!("line {n}: proxy belongs once, before the sources").into()
590+ );
591+ }
592+ let f = fields(rest, 1, "proxy", n)?;
593+ doc.proxy = match f[0] {
594+ b"on" => true,
595+ b"off" => false,
596+ other => {
597+ return Err(format!(
598+ "line {n}: proxy is on or off, not {:?}",
599+ String::from_utf8_lossy(other)
600+ )
601+ .into());
602+ }
603+ };
604+ }
560 b"limiter" if v9 => {605 b"limiter" if v9 => {
561 if !doc.sources.is_empty() {606 if !doc.sources.is_empty() {
562 return Err(607 return Err(
@@ -1076,6 +1121,7 @@ mod tests {
1076 resolution,1121 resolution,
1077 None,1122 None,
1078 crate::tonemap::Preset::default(),1123 crate::tonemap::Preset::default(),
1124+ false,
1079 Limiter::default(),1125 Limiter::default(),
1080 playhead,1126 playhead,
1081 )1127 )
@@ -1119,6 +1165,7 @@ mod tests {
1119 (1280, 720),1165 (1280, 720),
1120 None,1166 None,
1121 crate::tonemap::Preset::default(),1167 crate::tonemap::Preset::default(),
1168+ false,
1122 Limiter::default(),1169 Limiter::default(),
1123 0,1170 0,
1124 );1171 );
@@ -1147,7 +1194,7 @@ mod tests {
1147 video 1 0 0 30 0 - - - fit 1000\n";1194 video 1 0 0 30 0 - - - fit 1000\n";
1148 let old = parse(v9, &dir).expect("v9 still loads");1195 let old = parse(v9, &dir).expect("v9 still loads");
1149 assert_eq!(old.subtitles, Vec::new());1196 assert_eq!(old.subtitles, Vec::new());
1150- assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 11\n"));1197+ assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 12\n"));
1151 // ...and the line itself is not a v9 line: a dialect may not be mixed.1198 // ...and the line itself is not a v9 line: a dialect may not be mixed.
1152 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)1199 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)
1153 .unwrap_err()1200 .unwrap_err()
@@ -1163,6 +1210,65 @@ mod tests {
1163 }1210 }
1164 }1211 }
1165 1212
1213+ /// The v12 line: whether the project is cut on the stand-ins, written only
1214+ /// when it is -- and the dialect before it, which had no stand-ins and
1215+ /// whose bytes are therefore unchanged bar the version.
1216+ #[test]
1217+ fn the_proxy_switch_round_trips_and_a_v11_file_is_cut_on_its_films() {
1218+ let dir = PathBuf::from("/proj");
1219+ let (_, sources, lanes) = doc();
1220+ let bytes = |proxy| {
1221+ super::emit(
1222+ &dir,
1223+ &sources,
1224+ &lanes,
1225+ &[],
1226+ &[],
1227+ &[],
1228+ &[],
1229+ (1280, 720),
1230+ None,
1231+ crate::tonemap::Preset::default(),
1232+ proxy,
1233+ Limiter::default(),
1234+ 0,
1235+ )
1236+ };
1237+ let on = bytes(true);
1238+ assert!(
1239+ String::from_utf8_lossy(&on).contains("proxy on\n"),
1240+ "{}",
1241+ String::from_utf8_lossy(&on)
1242+ );
1243+ assert!(parse(&on, &dir).expect("v12 parses").proxy);
1244+ let off = bytes(false);
1245+ assert!(
1246+ !String::from_utf8_lossy(&off).contains("proxy"),
1247+ "off is the line left out"
1248+ );
1249+ assert!(!parse(&off, &dir).expect("v12 parses").proxy);
1250+
1251+ // A v11 project is one cut on the films themselves, and it still loads.
1252+ let v11 = b"edith 11\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
1253+ video 1 0 0 30 0 - - - fit 1000\n";
1254+ let old = parse(v11, &dir).expect("v11 still loads");
1255+ assert!(!old.proxy);
1256+ assert_eq!(old.sources.len(), 1, "the rest of it came back too");
1257+ // ...and the line is not a v11 line: a dialect may not be mixed.
1258+ let mixed = parse(b"edith 11\nsource 0 a.mp4\nproxy on\n", &dir)
1259+ .unwrap_err()
1260+ .to_string();
1261+ assert_eq!(mixed, "line 3: unknown keyword \"proxy\"");
1262+ // Anything but on or off is a corrupt line, by name.
1263+ for line in ["proxy\n", "proxy yes\n", "proxy On\n"] {
1264+ let file = format!("edith 12\nsource 0 a.mp4\n{line}");
1265+ assert!(
1266+ parse(file.as_bytes(), &dir).is_err(),
1267+ "{line:?} is not a proxy line"
1268+ );
1269+ }
1270+ }
1271+
1166 /// The v11 line: the HDR rendition, written by name, read back as the very1272 /// The v11 line: the HDR rendition, written by name, read back as the very
1167 /// preset -- and the dialect before it, which had no way to say one and1273 /// preset -- and the dialect before it, which had no way to say one and
1168 /// meant the published conversion.1274 /// meant the published conversion.
@@ -1182,6 +1288,7 @@ mod tests {
1182 (1280, 720),1288 (1280, 720),
1183 None,1289 None,
1184 preset,1290 preset,
1291+ false,
1185 Limiter::default(),1292 Limiter::default(),
1186 0,1293 0,
1187 );1294 );
@@ -1276,7 +1383,7 @@ mod tests {
1276 let bytes = flat(&dir, &sources, &lanes, 12);1383 let bytes = flat(&dir, &sources, &lanes, 12);
1277 assert_eq!(1384 assert_eq!(
1278 String::from_utf8_lossy(&bytes),1385 String::from_utf8_lossy(&bytes),
1279- "edith 11\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\1386+ "edith 12\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
1280 source 2 /elsewhere/b.mp4\n\1387 source 2 /elsewhere/b.mp4\n\
1281 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\1388 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
1282 audio 1 0 0 30 0 0 - - fit 1000\n",1389 audio 1 0 0 30 0 0 - - fit 1000\n",
@@ -1313,7 +1420,7 @@ mod tests {
1313 let bytes = flat(&dir, &sources, &lanes, 7);1420 let bytes = flat(&dir, &sources, &lanes, 7);
1314 assert_eq!(1421 assert_eq!(
1315 String::from_utf8_lossy(&bytes),1422 String::from_utf8_lossy(&bytes),
1316- "edith 11\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\1423+ "edith 12\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
1317 video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\1424 video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\
1318 video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n",1425 video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n",
1319 "an empty lane is a line of its own; everything else is its clips"1426 "an empty lane is a line of its own; everything else is its clips"
@@ -1421,7 +1528,7 @@ mod tests {
1421 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);1528 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);
1422 assert_eq!(1529 assert_eq!(
1423 String::from_utf8_lossy(&bytes),1530 String::from_utf8_lossy(&bytes),
1424- "edith 11\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\1531+ "edith 12\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
1425 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\1532 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
1426 eq 16777215.0:-0.1:3.918315e-39:hs\n\1533 eq 16777215.0:-0.1:3.918315e-39:hs\n\
1427 eq\n\1534 eq\n\
@@ -1525,7 +1632,7 @@ mod tests {
1525 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);1632 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);
1526 assert_eq!(1633 assert_eq!(
1527 String::from_utf8_lossy(&bytes),1634 String::from_utf8_lossy(&bytes),
1528- "edith 11\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\1635+ "edith 12\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
1529 color 0.1:1.2:0.9:-0.3\n\1636 color 0.1:1.2:0.9:-0.3\n\
1530 color -1e-7:16777215.0:3.918315e-39:-0.0\n\1637 color -1e-7:16777215.0:3.918315e-39:-0.0\n\
1531 color 0.0:1.0:1.0:0.0\n\1638 color 0.0:1.0:1.0:0.0\n\
@@ -1590,7 +1697,7 @@ mod tests {
1590 (1280, 720),1697 (1280, 720),
1591 old.playhead1698 old.playhead
1592 )),1699 )),
1593- "edith 11\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\1700+ "edith 12\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
1594 eq 80.0:-3.0:0.707:ls\n\1701 eq 80.0:-3.0:0.707:ls\n\
1595 video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"1702 video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"
1596 );1703 );
@@ -1628,7 +1735,7 @@ mod tests {
1628 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);1735 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
1629 assert_eq!(1736 assert_eq!(
1630 String::from_utf8_lossy(&bytes),1737 String::from_utf8_lossy(&bytes),
1631- "edith 11\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\1738+ "edith 12\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
1632 video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\1739 video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\
1633 audio 1 0 0 30 0 - - - fit 2000\n",1740 audio 1 0 0 30 0 - - - fit 2000\n",
1634 "the rate is the clip line's last field, in thousandths"1741 "the rate is the clip line's last field, in thousandths"
@@ -1657,7 +1764,7 @@ mod tests {
1657 (1280, 720),1764 (1280, 720),
1658 old.playhead1765 old.playhead
1659 )),1766 )),
1660- "edith 11\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\1767+ "edith 12\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
1661 video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"1768 video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"
1662 );1769 );
1663 // A rate outside what the editor can set is a corrupt line, by name.1770 // A rate outside what the editor can set is a corrupt line, by name.
@@ -1698,12 +1805,13 @@ mod tests {
1698 (1280, 720),1805 (1280, 720),
1699 Some(23.976023976023978),1806 Some(23.976023976023978),
1700 crate::tonemap::Preset::default(),1807 crate::tonemap::Preset::default(),
1808+ false,
1701 limiter,1809 limiter,
1702 0,1810 0,
1703 );1811 );
1704 assert_eq!(1812 assert_eq!(
1705 String::from_utf8_lossy(&bytes),1813 String::from_utf8_lossy(&bytes),
1706- "edith 11\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\1814+ "edith 12\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\
1707 limiter -1.5 on\nsource 0 a.mp4\n\1815 limiter -1.5 on\nsource 0 a.mp4\n\
1708 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\1816 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\
1709 audio 2 0 0 30 0 - - - fit 1000\n\1817 audio 2 0 0 30 0 - - - fit 1000\n\
@@ -1735,7 +1843,7 @@ mod tests {
1735 (1280, 720),1843 (1280, 720),
1736 old.playhead1844 old.playhead
1737 )),1845 )),
1738- "edith 11\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\1846+ "edith 12\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
1739 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"1847 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"
1740 );1848 );
1741 1849
@@ -1899,7 +2007,7 @@ mod tests {
1899 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");2007 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");
1900 assert_eq!(2008 assert_eq!(
1901 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),2009 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),
1902- "edith 11\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\2010+ "edith 12\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
1903 source 2 /elsewhere/b.mp4\n\2011 source 2 /elsewhere/b.mp4\n\
1904 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\2012 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
1905 audio 1 0 0 30 0 0 - - fit 1000\n"2013 audio 1 0 0 30 0 0 - - fit 1000\n"
@@ -1952,7 +2060,7 @@ mod tests {
1952 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);2060 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
1953 assert_eq!(2061 assert_eq!(
1954 String::from_utf8_lossy(&v5),2062 String::from_utf8_lossy(&v5),
1955- "edith 11\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\2063+ "edith 12\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
1956 source 0 /elsewhere/b.mp4\n\2064 source 0 /elsewhere/b.mp4\n\
1957 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\2065 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
1958 audio 1 0 0 30 0 0 - - fit 1000\n",2066 audio 1 0 0 30 0 0 - - fit 1000\n",
@@ -1984,7 +2092,7 @@ mod tests {
1984 // Saved again it is the current version, which round-trips to the2092 // Saved again it is the current version, which round-trips to the
1985 // same document.2093 // same document.
1986 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);2094 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
1987- assert!(v5.starts_with(b"edith 11\n"));2095+ assert!(v5.starts_with(b"edith 12\n"));
1988 let again = parse(&v5, &dir).expect("v5 parses");2096 let again = parse(&v5, &dir).expect("v5 parses");
1989 assert_eq!(again.lanes, back.lanes);2097 assert_eq!(again.lanes, back.lanes);
1990 // A dialect may not be mixed: lane lines under v1, `clip` under v2.2098 // A dialect may not be mixed: lane lines under v1, `clip` under v2.
@@ -2082,6 +2190,7 @@ mod tests {
2082 (1280, 720),2190 (1280, 720),
2083 None,2191 None,
2084 crate::tonemap::Preset::default(),2192 crate::tonemap::Preset::default(),
2193+ false,
2085 Limiter::default(),2194 Limiter::default(),
2086 0,2195 0,
2087 )2196 )
@@ -2089,7 +2198,7 @@ mod tests {
2089 let bytes = std::fs::read(&path).expect("read back");2198 let bytes = std::fs::read(&path).expect("read back");
2090 assert_eq!(2199 assert_eq!(
2091 String::from_utf8_lossy(&bytes),2200 String::from_utf8_lossy(&bytes),
2092- "edith 11\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\2201+ "edith 12\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
2093 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"2202 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"
2094 );2203 );
2095 // Loading rejoins the *given* directory, so the file is reached by the2204 // Loading rejoins the *given* directory, so the file is reached by the
@@ -2134,10 +2243,10 @@ mod tests {
2134 #[test]2243 #[test]
2135 fn a_wrong_first_line_is_refused_by_name() {2244 fn a_wrong_first_line_is_refused_by_name() {
2136 let dir = PathBuf::from("/proj");2245 let dir = PathBuf::from("/proj");
2137- let err = parse(b"edith 12\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)2246+ let err = parse(b"edith 13\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)
2138 .unwrap_err()2247 .unwrap_err()
2139 .to_string();2248 .to_string();
2140- assert_eq!(err, "line 1: unsupported version 12");2249+ assert_eq!(err, "line 1: unsupported version 13");
2141 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {2250 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {
2142 assert_eq!(2251 assert_eq!(
2143 parse(junk, &dir).unwrap_err().to_string(),2252 parse(junk, &dir).unwrap_err().to_string(),
crates/engine/src/export.rsmodified+9 -0
@@ -402,6 +402,15 @@ pub fn start(
402 part.push(".part");402 part.push(".part");
403 let part = PathBuf::from(part);403 let part = PathBuf::from(part);
404 let spawned = thread::Builder::new().name("export".into()).spawn(move || {404 let spawned = thread::Builder::new().name("export".into()).spawn(move || {
405+ // Every file this export will read, named before a byte of one is.
406+ // These are the project's own sources and can be nothing else: a
407+ // stand-in ([`crate::proxy`]) is a substitution playback makes when it
408+ // opens a span, and nothing here knows such a thing exists. Printed so
409+ // that "the delivery came off the film itself" is a grep rather than a
410+ // belief.
411+ for source in project.sources() {
412+ eprintln!("export source: {}", source.path.display());
413+ }
405 // The rename is the last step and the only one that publishes a file414 // The rename is the last step and the only one that publishes a file
406 // under the name the caller asked for; it stays on the same directory,415 // under the name the caller asked for; it stays on the same directory,
407 // so it is atomic.416 // so it is atomic.
crates/engine/src/playback.rsmodified+73 -2
@@ -11,7 +11,7 @@
11 //! Drift policy stays with the caller -- this type answers "what time is it",11 //! Drift policy stays with the caller -- this type answers "what time is it",
12 //! the renderer decides which frame that means.12 //! the renderer decides which frame that means.
13 13
14-use std::path::Path;14+use std::path::{Path, PathBuf};
15 use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize, Ordering};15 use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize, Ordering};
16 use std::sync::mpsc::{Receiver, TryRecvError};16 use std::sync::mpsc::{Receiver, TryRecvError};
17 use std::sync::{Arc, Mutex};17 use std::sync::{Arc, Mutex};
@@ -311,6 +311,16 @@ pub struct PlaybackSession {
311 /// of a restart is never counted as timeline time. See311 /// of a restart is never counted as timeline time. See
312 /// [`Audio::content_at`].312 /// [`Audio::content_at`].
313 priming: bool,313 priming: bool,
314+ /// Whether the picture is decoded from the stand-ins rather than from the
315+ /// films ([`crate::proxy`]). One switch for the whole project, saved with
316+ /// it, and *only* the picture: the sound is always the film's own, and so
317+ /// is everything an export reads.
318+ ///
319+ /// Which sources have a stand-in is not kept here -- it is asked of the
320+ /// cache when a span opens ([`Self::picture_path`]), one `stat` against a
321+ /// file open that already costs milliseconds, so a proxy made (or deleted)
322+ /// mid-session is picked up at the next seek and nothing can go stale.
323+ proxies: bool,
314 }324 }
315 325
316 /// What an edit dirtied -- which half of the pipeline has to be rebuilt for the326 /// What an edit dirtied -- which half of the pipeline has to be rebuilt for the
@@ -423,6 +433,8 @@ impl PlaybackSession {
423 eos: false,433 eos: false,
424 mix: None,434 mix: None,
425 priming: false,435 priming: false,
436+ // A file just opened is a project nobody has picked stand-ins for.
437+ proxies: false,
426 })438 })
427 }439 }
428 440
@@ -533,6 +545,8 @@ impl PlaybackSession {
533 eos: false,545 eos: false,
534 mix: None,546 mix: None,
535 priming: false,547 priming: false,
548+ // A file just opened is a project nobody has picked stand-ins for.
549+ proxies: false,
536 })550 })
537 }551 }
538 552
@@ -607,6 +621,8 @@ impl PlaybackSession {
607 eos: false,621 eos: false,
608 mix: None,622 mix: None,
609 priming: false,623 priming: false,
624+ // A file just opened is a project nobody has picked stand-ins for.
625+ proxies: false,
610 })626 })
611 }627 }
612 628
@@ -898,6 +914,9 @@ impl PlaybackSession {
898 eos: false,914 eos: false,
899 mix: None,915 mix: None,
900 priming: false,916 priming: false,
917+ // What the file says, and `false` for every dialect before v12:
918+ // a project cut on the films themselves opens on them.
919+ proxies: doc.proxy,
901 };920 };
902 // The scaffolding above opened source 0 from its first frame and the921 // The scaffolding above opened source 0 from its first frame and the
903 // whole of its audio; this puts both onto the clip the playhead is922 // whole of its audio; this puts both onto the clip the playhead is
@@ -1149,6 +1168,10 @@ impl PlaybackSession {
1149 // reason: a picked look that vanished on a reload is a look nobody1168 // reason: a picked look that vanished on a reload is a look nobody
1150 // could keep.1169 // could keep.
1151 self.project.tone(),1170 self.project.tone(),
1171+ // ...and whether it is cut on the stand-ins, for the same reason.
1172+ // *Which* files have one is not saved: [`crate::proxy`] finds that
1173+ // out from the film itself, so nothing here can go stale.
1174+ self.proxies,
1152 self.project.limiter(),1175 self.project.limiter(),
1153 playhead,1176 playhead,
1154 )1177 )
@@ -1328,7 +1351,11 @@ impl PlaybackSession {
1328 from: Some((source, in_frame)),1351 from: Some((source, in_frame)),
1329 ..1352 ..
1330 }) => Ok(DecodeSession::open_worker_deferred(1353 }) => Ok(DecodeSession::open_worker_deferred(
1331- &self.project.sources()[source].path,1354+ // The stand-in where there is one and the switch is on, the
1355+ // film itself otherwise -- the one place the picture's file is
1356+ // decided ([`Self::picture_path`]). The sound is opened
1357+ // elsewhere and is always the film's.
1358+ &self.picture_path(source),
1332 // The file's own frames, which is the only place they exist:1359 // The file's own frames, which is the only place they exist:
1333 // a clip counts the timeline's ([`Rate`]).1360 // a clip counts the timeline's ([`Rate`]).
1334 self.span_rate.source_at(in_frame),1361 self.span_rate.source_at(in_frame),
@@ -1743,6 +1770,50 @@ impl PlaybackSession {
1743 .map_or(Rate::REAL_TIME, |i| self.rates[i])1770 .map_or(Rate::REAL_TIME, |i| self.rates[i])
1744 }1771 }
1745 1772
1773+ /// Which file this source's **picture** is decoded from: its stand-in when
1774+ /// the project is cut on stand-ins and one has been made for it, and the
1775+ /// film itself in every other case ([`crate::proxy`]).
1776+ ///
1777+ /// One `stat` per span open, against a decoder open that costs milliseconds
1778+ /// -- so a proxy that appeared (or was deleted) since the last seek is
1779+ /// picked up at this one, and no table of attachments exists to disagree
1780+ /// with the cache.
1781+ ///
1782+ /// The sound never comes through here: [`open_audio`] is given the
1783+ /// project's own source path, so a mix is the film's however this answers.
1784+ pub fn picture_path(&self, source: usize) -> PathBuf {
1785+ let path = &self.project.sources()[source].path;
1786+ let Some(proxy) = self.proxies.then(|| crate::proxy::cached(path)).flatten() else {
1787+ return path.clone();
1788+ };
1789+ // Said out loud, once per span opened, because "the picture came off
1790+ // the stand-in and the delivery did not" is a claim somebody has to be
1791+ // able to check: `export` prints the file *it* reads by the same rule.
1792+ eprintln!("picture: proxy {}", proxy.display());
1793+ proxy
1794+ }
1795+
1796+ /// Whether the picture comes off the stand-ins ([`Self::set_proxies`]).
1797+ pub fn proxies(&self) -> bool {
1798+ self.proxies
1799+ }
1800+
1801+ /// Cut on the stand-ins, or on the films themselves. Reseeks, so the very
1802+ /// next picture comes from the other file -- which is what makes this a
1803+ /// switch a person can flip while watching.
1804+ ///
1805+ /// Says nothing about *which* films have one: a source with no stand-in
1806+ /// keeps playing its own pictures either way, and one made while this is on
1807+ /// is picked up at the next seek.
1808+ pub fn set_proxies(&mut self, on: bool) {
1809+ if self.proxies == on {
1810+ return;
1811+ }
1812+ self.proxies = on;
1813+ let now = self.now();
1814+ self.seek(now);
1815+ }
1816+
1746 /// Which source `path` is, canonicalising only if it has to: a source's own1817 /// Which source `path` is, canonicalising only if it has to: a source's own
1747 /// path is canonical ([`Source::new`]), so a caller handing one back from1818 /// path is canonical ([`Source::new`]), so a caller handing one back from
1748 /// [`sources`](Self::sources) -- which is every library row -- hits on the1819 /// [`sources`](Self::sources) -- which is every library row -- hits on the
crates/engine/tests/export.rsmodified+42 -0
@@ -930,6 +930,48 @@ fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() {
930 let session = PlaybackSession::open(&made).expect("play the proxy");930 let session = PlaybackSession::open(&made).expect("play the proxy");
931 assert_eq!(session.meta().frame_count, source_meta.frame_count);931 assert_eq!(session.meta().frame_count, source_meta.frame_count);
932 932
933+ // ...and a session on the *film* plays it instead once the switch is on,
934+ // while the film is still the only thing the project names -- which is what
935+ // an export reads and why an export can never come off a stand-in.
936+ let mut session = PlaybackSession::open(&source).expect("open the film");
937+ // The film as the project names it: canonical ([`Source::new`]), which the
938+ // proxy key resolves to as well -- the same file under two names is one
939+ // stand-in.
940+ let film = session.sources()[0].path.clone();
941+ assert_eq!(session.picture_path(0), film, "off: the film itself");
942+ session.set_proxies(true);
943+ assert!(session.proxies());
944+ assert_eq!(session.picture_path(0), made, "on: the stand-in");
945+ assert_eq!(
946+ session.sources()[0].path,
947+ film,
948+ "the project still names the film, and that is what an export reads"
949+ );
950+ // A frame really arrives from it: the switch reseeks, so the picture after
951+ // it is the proxy's.
952+ let started = Instant::now();
953+ while session.try_frame().is_none() {
954+ assert!(
955+ started.elapsed() < Duration::from_secs(10),
956+ "no picture after switching to the stand-in"
957+ );
958+ std::thread::sleep(Duration::from_millis(10));
959+ }
960+ session.set_proxies(false);
961+ assert_eq!(session.picture_path(0), film, "and back again");
962+
963+ // The switch survives a save and a load, and a project written before there
964+ // were stand-ins opens on its films.
965+ let project = Scratch::file("ve_proxy_switch", "edith");
966+ session.set_proxies(true);
967+ session.save_project(&project).expect("save");
968+ let text = std::fs::read_to_string(&project).expect("read the project back");
969+ assert!(text.starts_with("edith 12\n"), "{text}");
970+ assert!(text.contains("\nproxy on\n"), "{text}");
971+ let reopened = PlaybackSession::open_project(&project).expect("load");
972+ assert!(reopened.proxies(), "the switch came back on");
973+ assert_eq!(reopened.picture_path(0), made, "and it is substituting");
974+
933 // Asked again, it is the file already there: no second encode.975 // Asked again, it is the file already there: no second encode.
934 let again = engine::proxy::generate(&source).expect("ask again");976 let again = engine::proxy::generate(&source).expect("ask again");
935 assert!(again.is_finished(), "a cached proxy is done on the spot");977 assert!(again.is_finished(), "a cached proxy is done on the spot");
crates/engine/tests/saveload.rsmodified+6 -6
@@ -208,7 +208,7 @@ fn a_version_1_project_loads_fully_grouped_and_saves_as_version_7() {
208 let v2 = dir.join("new.edith");208 let v2 = dir.join("new.edith");
209 loaded.save_project(&v2).expect("save");209 loaded.save_project(&v2).expect("save");
210 let text = std::fs::read_to_string(&v2).expect("read back");210 let text = std::fs::read_to_string(&v2).expect("read back");
211- assert!(text.starts_with("edith 11\n"), "{text}");211+ assert!(text.starts_with("edith 12\n"), "{text}");
212 assert!(212 assert!(
213 text.contains("\nresolution 1280 720\n"),213 text.contains("\nresolution 1280 720\n"),
214 "a project with no resolution of its own is saved at source 0's: {text}"214 "a project with no resolution of its own is saved at source 0's: {text}"
@@ -296,7 +296,7 @@ fn a_version_4_project_holds_more_than_two_lanes() {
296 loaded.save_project(&again).expect("save");296 loaded.save_project(&again).expect("save");
297 assert_eq!(297 assert_eq!(
298 std::fs::read_to_string(&again).expect("read back"),298 std::fs::read_to_string(&again).expect("read back"),
299- "edith 11\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\299+ "edith 12\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
300 video 1 0 0 30 0 3 - - fit 1000\naudio 1\n\300 video 1 0 0 30 0 3 - - fit 1000\naudio 1\n\
301 video 2 40 0 20 0 - - - fit 1000\naudio 2 0 0 30 0 3 - - fit 1000\n",301 video 2 40 0 20 0 - - - fit 1000\naudio 2 0 0 30 0 3 - - fit 1000\n",
302 "a four-lane project is written as it was read, three versions on"302 "a four-lane project is written as it was read, three versions on"
@@ -326,7 +326,7 @@ fn a_version_5_project_carries_per_clip_equalizers() {
326 loaded.save_project(&again).expect("save");326 loaded.save_project(&again).expect("save");
327 assert_eq!(327 assert_eq!(
328 std::fs::read_to_string(&again).expect("read back"),328 std::fs::read_to_string(&again).expect("read back"),
329- "edith 11\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\329+ "edith 12\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
330 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\330 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
331 eq 12000.0:6.25:0.5:hs\n\331 eq 12000.0:6.25:0.5:hs\n\
332 video 1 0 0 30 0 - 0 - fit 1000\nvideo 1 30 30 60 0 - 1 - fit 1000\n\332 video 1 0 0 30 0 - 0 - fit 1000\nvideo 1 30 30 60 0 - 1 - fit 1000\n\
@@ -361,7 +361,7 @@ fn a_version_6_project_carries_per_clip_colours() {
361 loaded.save_project(&again).expect("save");361 loaded.save_project(&again).expect("save");
362 assert_eq!(362 assert_eq!(
363 std::fs::read_to_string(&again).expect("read back"),363 std::fs::read_to_string(&again).expect("read back"),
364- "edith 11\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\364+ "edith 12\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
365 eq 80.0:-3.0:0.707:ls\n\365 eq 80.0:-3.0:0.707:ls\n\
366 color 0.1:1.2:0.9:-0.3\n\366 color 0.1:1.2:0.9:-0.3\n\
367 color -0.25:1.0:0.0:0.5\n\367 color -0.25:1.0:0.0:0.5\n\
@@ -411,7 +411,7 @@ fn a_version_7_project_carries_a_resolution_and_fit_policies() {
411 loaded.save_project(&again).expect("save");411 loaded.save_project(&again).expect("save");
412 assert_eq!(412 assert_eq!(
413 std::fs::read_to_string(&again).expect("read back"),413 std::fs::read_to_string(&again).expect("read back"),
414- "edith 11\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\414+ "edith 12\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\
415 video 1 0 0 30 0 - - - fill 1000\nvideo 1 30 30 60 0 - - - center 1000\n\415 video 1 0 0 30 0 - - - fill 1000\nvideo 1 30 30 60 0 - - - center 1000\n\
416 audio 1 0 0 60 0 - - - fit 1000\n",416 audio 1 0 0 60 0 - - - fit 1000\n",
417 "a v7 project is written back as the v8 it now is: the same clips, each \417 "a v7 project is written back as the v8 it now is: the same clips, each \
@@ -669,7 +669,7 @@ fn malformed_files_are_numbered_errors_and_never_panics() {
669 669
670 for (text, want) in [670 for (text, want) in [
671 (671 (
672- "edith 12\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n",672+ "edith 13\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n",
673 "line 1",673 "line 1",
674 ),674 ),
675 // An eq index the table does not hold, and a band shape there is none.675 // An eq index the table does not hold, and a band shape there is none.
crates/engine/tests/silence.rsmodified+2 -1
@@ -376,13 +376,14 @@ fn scanning_a_clip_and_cutting_what_it_finds() {
376 (1920, 1080),376 (1920, 1080),
377 None,377 None,
378 p.tone(),378 p.tone(),
379+ false,
379 p.limiter(),380 p.limiter(),
380 0,381 0,
381 )382 )
382 .expect("save");383 .expect("save");
383 let text = std::fs::read_to_string(&file).expect("read it back");384 let text = std::fs::read_to_string(&file).expect("read it back");
384 assert!(385 assert!(
385- text.starts_with("edith 11"),386+ text.starts_with("edith 12"),
386 "{:?}",387 "{:?}",
387 &text[..16.min(text.len())]388 &text[..16.min(text.len())]
388 );389 );
crates/engine/tests/subtitles.rsmodified+1 -1
@@ -259,7 +259,7 @@ fn a_project_keeps_its_subtitles_across_a_save() {
259 let project = dir.join("cut.edith");259 let project = dir.join("cut.edith");
260 session.save_project(&project).expect("save");260 session.save_project(&project).expect("save");
261 let text = std::fs::read_to_string(&project).expect("read the project back");261 let text = std::fs::read_to_string(&project).expect("read the project back");
262- assert!(text.starts_with("edith 11\n"), "{text}");262+ assert!(text.starts_with("edith 12\n"), "{text}");
263 assert!(263 assert!(
264 text.contains("\nsubtitle - test_subs.srt\n"),264 text.contains("\nsubtitle - test_subs.srt\n"),
265 "the reference is written relative, and no cue is: {text}"265 "the reference is written relative, and no cue is: {text}"