forge
Explore
Log in

Don't you dare go Hollow

The words a project places are in the file it saves

Browse files at this commit

df4020f31843d0e500ac67c0bd008b69cfd81f18Ahmet Kaan GümüşParent: 6f06fea
  • feat
    • the words a project places are in the file it saves
Show full message
✨ feat(engine): the words a project places are in the file it saves

The `.edith` grows a `sub` line -- `sub <lane> <start> <frames> <track>
<in> <out>` -- and a bare `sub <lane>` for a subtitle lane holding
nothing, written in the lane's own place among the video and audio ones
so the display order a load rebuilds is the one that was saved. Both of
a caption's clocks are on the line: the placement in timeline frames
like everything else, the window in the microseconds its cues are timed
in. MAGIC is `edith 15`.

`Project::without_orphan_sources` stops filtering the subtitle lanes out
of its `Parts` and `Project::lane_gains` stops filtering them out of its
gains -- the two are zipped by `edith::emit`, so they were only ever
allowed to filter in step, and now neither does. What is *on* those
lanes travels beside them in the new `Project::lane_subs`, one list per
lane exactly as the gains are, and comes back through
`Project::with_subs`, which is `from_parts` for words: it refuses a
caption on a lane that is not a subtitle lane, an empty span or window,
a track the palette does not have, a span past the last frame there is,
and a lane that overlaps itself. The parser refuses the same file by
line number.

A v14 project is one that named subtitle files and could place none of
them: it loads with its palette whole and no subtitle lane at all, which
is what it always meant, and re-saves as v15 having invented neither.

Also fixes a version-bump straggler in tests/silence.rs, which asserted
`edith 13` against a `edith 14` writer and was red before this change.
crates/engine/src/edith.rsmodified+179 -38
@@ -1,7 +1,7 @@
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 144+//! edith 15
5 //! playhead 905 //! playhead 90
6 //! resolution 1920 10806 //! resolution 1920 1080
7 //! fps 30.07 //! fps 30.0
@@ -20,6 +20,8 @@
20 //! audio 1 0 0 120 0 0 0 - fit 100020 //! audio 1 0 0 120 0 0 0 - fit 1000
21 //! video 2 120 0 120 1 - - - fill 200021 //! video 2 120 0 120 1 - - - fill 2000
22 //! audio 222 //! audio 2
23+//! sub 1 0 60 0 500000 1500000
24+//! sub 2
23 //! gain audio 1 -3.025 //! gain audio 1 -3.0
24 //! ```26 //! ```
25 //!27 //!
@@ -127,7 +129,24 @@
127 //! is the only way an empty lane could still be there on the way back. A lane129 //! is the only way an empty lane could still be there on the way back. A lane
128 //! number may not skip one of its kind.130 //! number may not skip one of its kind.
129 //!131 //!
130-//! **Version 13** was this without the `encoder` line: an export of such a132+//! A subtitle lane is a lane like the other two and is written in its place
133+//! among them, `sub` for its kind: `sub <lane> <start> <frames> <track>
134+//! <in> <out>` ([`crate::project::SubClip`]) -- where the caption sits on the
135+//! timeline and how many frames it covers, then which `subtitle` line's words
136+//! it shows (by position, the first one is track 0) and the half-open window of
137+//! that track it shows, in *microseconds*, which is the clock the cues
138+//! themselves are timed in. Two clocks on one line because a subtitle has two:
139+//! a placement is in timeline frames like everything else, and a window is in
140+//! the file's own time whatever the timeline runs at. A lane holding nothing
141+//! has the bare `sub <lane>` line for the reason a video one does, and the
142+//! track a caption names has to be one the file declared -- a `sub` line naming
143+//! track 3 of a two-track palette is refused here, as a clip naming a source
144+//! that is not there is.
145+//!
146+//! **Version 14** was this without the `sub` lines: such a project holds no
147+//! subtitle lane at all -- its `subtitle` lines are the palette, and where the
148+//! words of it were shown was nowhere in the file.
149+//! **Version 13** was that without the `encoder` line: an export of such a
131 //! project takes the hardware seat where there is one and the software encoder150 //! project takes the hardware seat where there is one and the software encoder
132 //! everywhere else, which is the only choice those projects had.151 //! everywhere else, which is the only choice those projects had.
133 //! **Version 12** was that without the `autoproxy` line: such a project makes a152 //! **Version 12** was that without the `autoproxy` line: such a project makes a
@@ -158,7 +177,8 @@
158 //! what a v1 timeline meant, and an older file simply equalizes and grades177 //! what a v1 timeline meant, and an older file simply equalizes and grades
159 //! nothing, and an older one plays everything at real time, and an older one178 //! nothing, and an older one plays everything at real time, and an older one
160 //! mixes flat, and an older one shows no subtitles, and an older one is shown179 //! mixes flat, and an older one shows no subtitles, and an older one is shown
161-//! in the reference rendition -- and saving any of them writes v14. An older180+//! in the reference rendition, and an older one places none of the words it
181+//! names -- and saving any of them writes v15. An older
162 //! reader refuses a newer file by name.182 //! reader refuses a newer file by name.
163 //!183 //!
164 //! Text because an edit list is a few integers and a path, and a path is184 //! Text because an edit list is a few integers and a path, and a path is
@@ -188,13 +208,14 @@ use std::path::{Path, PathBuf};
188 use crate::color::ColorParams;208 use crate::color::ColorParams;
189 use crate::eq::{Band, BandKind, EqParams};209 use crate::eq::{Band, BandKind, EqParams};
190 use crate::limiter::Limiter;210 use crate::limiter::Limiter;
191-use crate::project::{Clip, Lane, LaneKind, Source, Speed};211+use crate::project::{Clip, Lane, LaneKind, Source, Speed, SubClip};
192 use crate::scale::FitPolicy;212 use crate::scale::FitPolicy;
193 use crate::subtitle::SubtitleTrack;213 use crate::subtitle::SubtitleTrack;
194 214
195 /// What [`save`] writes. Read support goes back to `edith 1`; see the module215 /// What [`save`] writes. Read support goes back to `edith 1`; see the module
196 /// docs for what those dialects looked like.216 /// docs for what those dialects looked like.
197-const MAGIC: &[u8] = b"edith 14";217+const MAGIC: &[u8] = b"edith 15";
218+const MAGIC_V14: &[u8] = b"edith 14";
198 const MAGIC_V13: &[u8] = b"edith 13";219 const MAGIC_V13: &[u8] = b"edith 13";
199 const MAGIC_V12: &[u8] = b"edith 12";220 const MAGIC_V12: &[u8] = b"edith 12";
200 const MAGIC_V11: &[u8] = b"edith 11";221 const MAGIC_V11: &[u8] = b"edith 11";
@@ -220,6 +241,11 @@ pub struct Document {
220 /// [`crate::Project::from_parts`] takes them in. Exactly two -- `V1` then241 /// [`crate::Project::from_parts`] takes them in. Exactly two -- `V1` then
221 /// `A1` -- for every dialect before v4.242 /// `A1` -- for every dialect before v4.
222 pub lanes: Vec<(LaneKind, Vec<Clip>)>,243 pub lanes: Vec<(LaneKind, Vec<Clip>)>,
244+ /// What is placed on each lane, in the order `lanes` is in and as long as
245+ /// it -- the `sub` lines. Empty for every video and audio lane, which hold
246+ /// no [`SubClip`], and for every lane of every dialect before v15, which
247+ /// placed no words anywhere ([`crate::Project::with_subs`] takes it back).
248+ pub subs: Vec<Vec<SubClip>>,
223 /// The equalizer table [`Clip::eq`] indexes into, in file order. Empty for249 /// The equalizer table [`Clip::eq`] indexes into, in file order. Empty for
224 /// every dialect before v5.250 /// every dialect before v5.
225 pub eq: Vec<EqParams>,251 pub eq: Vec<EqParams>,
@@ -273,13 +299,15 @@ pub struct Document {
273 /// Writes the project to `path`, atomically. `sources`, `eq` and `color` should299 /// Writes the project to `path`, atomically. `sources`, `eq` and `color` should
274 /// already be orphan-free ([`crate::Project::without_orphan_sources`]);300 /// already be orphan-free ([`crate::Project::without_orphan_sources`]);
275 /// `gains` is one dB per lane in the same order the lanes are in301 /// `gains` is one dB per lane in the same order the lanes are in
276-/// ([`crate::Project::lane_gains`]).302+/// ([`crate::Project::lane_gains`]) and `subs` is one list of placements per
303+/// lane in that same order ([`crate::Project::lane_subs`]).
277 #[allow(clippy::too_many_arguments)]304 #[allow(clippy::too_many_arguments)]
278 pub fn save(305 pub fn save(
279 path: &Path,306 path: &Path,
280 sources: &[Source],307 sources: &[Source],
281 lanes: &[(LaneKind, Vec<Clip>)],308 lanes: &[(LaneKind, Vec<Clip>)],
282 gains: &[f32],309 gains: &[f32],
310+ subs: &[Vec<SubClip>],
283 subtitles: &[SubtitleTrack],311 subtitles: &[SubtitleTrack],
284 eq: &[EqParams],312 eq: &[EqParams],
285 color: &[ColorParams],313 color: &[ColorParams],
@@ -303,8 +331,8 @@ pub fn save(
303 let result = std::fs::File::create(&part)331 let result = std::fs::File::create(&part)
304 .and_then(|mut f| {332 .and_then(|mut f| {
305 f.write_all(&emit(333 f.write_all(&emit(
306- &dir, sources, lanes, gains, subtitles, eq, color, resolution, fps, tone, proxy,334+ &dir, sources, lanes, gains, subs, subtitles, eq, color, resolution, fps, tone,
307- auto_proxy, encoder, limiter, playhead,335+ proxy, auto_proxy, encoder, limiter, playhead,
308 ))?;336 ))?;
309 f.sync_all()337 f.sync_all()
310 })338 })
@@ -341,6 +369,7 @@ fn emit(
341 sources: &[Source],369 sources: &[Source],
342 lanes: &[(LaneKind, Vec<Clip>)],370 lanes: &[(LaneKind, Vec<Clip>)],
343 gains: &[f32],371 gains: &[f32],
372+ subs: &[Vec<SubClip>],
344 subtitles: &[SubtitleTrack],373 subtitles: &[SubtitleTrack],
345 eq: &[EqParams],374 eq: &[EqParams],
346 color: &[ColorParams],375 color: &[ColorParams],
@@ -448,8 +477,8 @@ fn emit(
448 // Lane by lane rather than interleaved by time: a lane reads as a list, the477 // Lane by lane rather than interleaved by time: a lane reads as a list, the
449 // parser gets its sortedness check for free from the order it is in, and478 // parser gets its sortedness check for free from the order it is in, and
450 // the lanes come back out in the order they are displayed in.479 // the lanes come back out in the order they are displayed in.
451- let (mut video, mut audio) = (0, 0);480+ let (mut video, mut audio, mut subtitle) = (0, 0, 0);
452- for (kind, clips) in lanes {481+ for (at, (kind, clips)) in lanes.iter().enumerate() {
453 let (keyword, ord) = match kind {482 let (keyword, ord) = match kind {
454 LaneKind::Video => {483 LaneKind::Video => {
455 video += 1;484 video += 1;
@@ -459,13 +488,31 @@ fn emit(
459 audio += 1;488 audio += 1;
460 ("audio", audio)489 ("audio", audio)
461 }490 }
462- // Unreachable by construction: `Project::without_orphan_sources`491+ LaneKind::Subtitle => {
463- // leaves the subtitle lanes out of the [`Parts`] it hands a save,492+ subtitle += 1;
464- // because this format has no line to write a `SubClip` on yet and a493+ ("sub", subtitle)
465- // reader that met the keyword would refuse the file. Skipped rather494+ }
466- // than emitted, and the corner-cut is named at the filter.
467- LaneKind::Subtitle => continue,
468 };495 };
496+ // A subtitle lane holds no `Clip` at all ([`LaneKind::Subtitle`]): what
497+ // is on it is in `subs`, one list per lane and in step with this one,
498+ // and it is written here so the lane comes back in its place among the
499+ // others.
500+ if *kind == LaneKind::Subtitle {
501+ let placed = subs.get(at).map_or(&[][..], Vec::as_slice);
502+ if placed.is_empty() {
503+ out.extend_from_slice(format!("{keyword} {ord}\n").as_bytes());
504+ }
505+ for s in placed {
506+ out.extend_from_slice(
507+ format!(
508+ "{keyword} {ord} {} {} {} {} {}\n",
509+ s.start, s.frames, s.track, s.in_us, s.out_us
510+ )
511+ .as_bytes(),
512+ );
513+ }
514+ continue;
515+ }
469 // A lane is declared by its clips; one holding nothing has to say so on516 // A lane is declared by its clips; one holding nothing has to say so on
470 // a line of its own, or the lane itself would not survive the round trip.517 // a line of its own, or the lane itself would not survive the round trip.
471 if clips.is_empty() {518 if clips.is_empty() {
@@ -503,8 +550,10 @@ fn emit(
503 audio += 1;550 audio += 1;
504 ("audio", audio)551 ("audio", audio)
505 }552 }
506- // Never here, for the reason above -- and a subtitle lane has no553+ // In the list -- the two are zipped, so it has to be -- and never
507- // volume to write anyway (`Project::set_lane_gain_db` refuses one).554+ // written: a subtitle lane has no volume at all
555+ // (`Project::set_lane_gain_db` refuses one), so its entry is the
556+ // `0.0` no lane writes a line for.
508 LaneKind::Subtitle => continue,557 LaneKind::Subtitle => continue,
509 };558 };
510 if db != 0.0 {559 if db != 0.0 {
@@ -524,8 +573,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
524 // The dialects that wrote a source line without its stream field. Reading573 // The dialects that wrote a source line without its stream field. Reading
525 // one is the whole of what "an old project still opens" means here.574 // one is the whole of what "an old project still opens" means here.
526 let streamless = v1 || first == MAGIC_V2;575 let streamless = v1 || first == MAGIC_V2;
527- // The one that says which encoder an export takes...576+ // The one that places the words it names...
528- let v14 = first == MAGIC;577+ let v15 = first == MAGIC;
578+ // ...the ones that say which encoder an export takes...
579+ let v14 = v15 || first == MAGIC_V14;
529 // ...the ones that say whether the stand-ins are made by themselves...580 // ...the ones that say whether the stand-ins are made by themselves...
530 let v13 = v14 || first == MAGIC_V13;581 let v13 = v14 || first == MAGIC_V13;
531 // ...the ones that say whether it is cut on stand-ins...582 // ...the ones that say whether it is cut on stand-ins...
@@ -564,6 +615,11 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
564 } else {615 } else {
565 vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())]616 vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())]
566 },617 },
618+ // Resized to the lanes as they arrive, and once more at the end, so a
619+ // caller may zip the two exactly as it zips the gains. Nothing before
620+ // v15 places a word anywhere: those projects have the palette and no
621+ // subtitle lane to put any of it on.
622+ subs: Vec::new(),
567 // Nothing before v5 equalizes anything, and nothing before v6 grades.623 // Nothing before v5 equalizes anything, and nothing before v6 grades.
568 eq: Vec::new(),624 eq: Vec::new(),
569 color: Vec::new(),625 color: Vec::new(),
@@ -877,6 +933,66 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
877 doc.lanes[0].1.push(clip);933 doc.lanes[0].1.push(clip);
878 doc.lanes[1].1.push(clip);934 doc.lanes[1].1.push(clip);
879 }935 }
936+ // A lane line like the two below it, in its place among them, and
937+ // read into `subs` rather than into the clips: the lane holds
938+ // words, and no media path may ever meet one
939+ // ([`crate::project::LaneKind::Subtitle`]).
940+ b"sub" if v15 => {
941+ let at = rest.iter().position(|&b| b == b' ');
942+ let ord = number(&rest[..at.unwrap_or(rest.len())], n)?;
943+ let rest = &rest[at.map_or(rest.len(), |at| at + 1)..];
944+ let at = lane_of(&mut doc.lanes, LaneKind::Subtitle, ord, n)?;
945+ doc.subs.resize(doc.lanes.len(), Vec::new());
946+ // The bare line is the empty lane's whole existence, exactly as
947+ // it is for a video one.
948+ if rest.is_empty() {
949+ continue;
950+ }
951+ let f = fields(rest, 5, "sub", n)?;
952+ let sub = SubClip {
953+ start: number(f[0], n)?,
954+ frames: number(f[1], n)?,
955+ track: number(f[2], n)? as usize,
956+ in_us: micros(f[3], n)?,
957+ out_us: micros(f[4], n)?,
958+ };
959+ // The never-empty invariant at both clocks, which is what
960+ // [`crate::Project::place_sub`] refuses on the live timeline.
961+ if sub.frames == 0 || sub.out_us <= sub.in_us || sub.in_us < 0 {
962+ return Err(format!(
963+ "line {n}: caption at {} is empty: {} frames of [{}, {})",
964+ sub.start, sub.frames, sub.in_us, sub.out_us
965+ )
966+ .into());
967+ }
968+ // The palette bound, which is a clip's source bound for words:
969+ // the `subtitle` lines are written before these and a caption
970+ // names one of them by position.
971+ if sub.track >= doc.subtitles.len() {
972+ return Err(format!(
973+ "line {n}: caption names subtitle track {} of {}",
974+ sub.track,
975+ doc.subtitles.len()
976+ )
977+ .into());
978+ }
979+ if sub.start.checked_add(sub.frames).is_none() {
980+ return Err(format!(
981+ "line {n}: caption at {} runs past the last frame there is",
982+ sub.start
983+ )
984+ .into());
985+ }
986+ let lane = &mut doc.subs[at];
987+ if lane.last().is_some_and(|prev| prev.end() > sub.start) {
988+ return Err(format!(
989+ "line {n}: caption at {} overlaps the one before it, or comes before it",
990+ sub.start
991+ )
992+ .into());
993+ }
994+ lane.push(sub);
995+ }
880 b"video" | b"audio" if !v1 => {996 b"video" | b"audio" if !v1 => {
881 let kind = match keyword {997 let kind = match keyword {
882 b"video" => LaneKind::Video,998 b"video" => LaneKind::Video,
@@ -945,8 +1061,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
945 }1061 }
946 }1062 }
947 }1063 }
948- // One per lane whatever the file said, so a caller may zip the two.1064+ // One per lane whatever the file said, so a caller may zip the two -- and
1065+ // the same for the placements, whose lanes are the very same list.
949 doc.gains.resize(doc.lanes.len(), 0.0);1066 doc.gains.resize(doc.lanes.len(), 0.0);
1067+ doc.subs.resize(doc.lanes.len(), Vec::new());
950 // A file whose lanes are all empty *is* a project -- the emptied timeline,1068 // A file whose lanes are all empty *is* a project -- the emptied timeline,
951 // saved. What it may not be is laneless; [`crate::Project::from_parts`]1069 // saved. What it may not be is laneless; [`crate::Project::from_parts`]
952 // refuses that one, by the name it has there.1070 // refuses that one, by the name it has there.
@@ -1163,6 +1281,21 @@ fn number(field: &[u8], line: usize) -> crate::Result<u32> {
1163 }1281 }
1164 }1282 }
1165 1283
1284+/// A `sub` line's window field: microseconds, which is the clock a cue is timed
1285+/// in ([`crate::subtitle::Cue`]) and the one thing in this format counted in
1286+/// something other than frames. Signed as the cues are, and the negative half
1287+/// is refused by the never-empty check at the line, not here.
1288+fn micros(field: &[u8], line: usize) -> crate::Result<i64> {
1289+ match std::str::from_utf8(field).ok().and_then(|s| s.parse().ok()) {
1290+ Some(n) => Ok(n),
1291+ None => Err(format!(
1292+ "line {line}: {:?} is not a number",
1293+ String::from_utf8_lossy(field)
1294+ )
1295+ .into()),
1296+ }
1297+}
1298+
1166 /// The two bytes a line-based format cannot hold, and the escape byte itself.1299 /// The two bytes a line-based format cannot hold, and the escape byte itself.
1167 fn escape(path: &Path, out: &mut Vec<u8>) {1300 fn escape(path: &Path, out: &mut Vec<u8>) {
1168 for &b in path.as_os_str().as_bytes() {1301 for &b in path.as_os_str().as_bytes() {
@@ -1223,6 +1356,7 @@ mod tests {
1223 lanes,1356 lanes,
1224 &[],1357 &[],
1225 &[],1358 &[],
1359+ &[],
1226 eq,1360 eq,
1227 color,1361 color,
1228 resolution,1362 resolution,
@@ -1268,6 +1402,7 @@ mod tests {
1268 &sources,1402 &sources,
1269 &lanes,1403 &lanes,
1270 &[],1404 &[],
1405+ &[],
1271 &tracks,1406 &tracks,
1272 &[],1407 &[],
1273 &[],1408 &[],
@@ -1305,7 +1440,7 @@ mod tests {
1305 video 1 0 0 30 0 - - - fit 1000\n";1440 video 1 0 0 30 0 - - - fit 1000\n";
1306 let old = parse(v9, &dir).expect("v9 still loads");1441 let old = parse(v9, &dir).expect("v9 still loads");
1307 assert_eq!(old.subtitles, Vec::new());1442 assert_eq!(old.subtitles, Vec::new());
1308- assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 14\n"));1443+ assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 15\n"));
1309 // ...and the line itself is not a v9 line: a dialect may not be mixed.1444 // ...and the line itself is not a v9 line: a dialect may not be mixed.
1310 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)1445 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)
1311 .unwrap_err()1446 .unwrap_err()
@@ -1337,6 +1472,7 @@ mod tests {
1337 &[],1472 &[],
1338 &[],1473 &[],
1339 &[],1474 &[],
1475+ &[],
1340 (1280, 720),1476 (1280, 720),
1341 None,1477 None,
1342 crate::tonemap::Preset::default(),1478 crate::tonemap::Preset::default(),
@@ -1399,6 +1535,7 @@ mod tests {
1399 &[],1535 &[],
1400 &[],1536 &[],
1401 &[],1537 &[],
1538+ &[],
1402 (1280, 720),1539 (1280, 720),
1403 None,1540 None,
1404 crate::tonemap::Preset::default(),1541 crate::tonemap::Preset::default(),
@@ -1463,6 +1600,7 @@ mod tests {
1463 &[],1600 &[],
1464 &[],1601 &[],
1465 &[],1602 &[],
1603+ &[],
1466 (1280, 720),1604 (1280, 720),
1467 None,1605 None,
1468 crate::tonemap::Preset::default(),1606 crate::tonemap::Preset::default(),
@@ -1510,7 +1648,7 @@ mod tests {
1510 assert_eq!(mixed, "line 3: unknown keyword \"encoder\"");1648 assert_eq!(mixed, "line 3: unknown keyword \"encoder\"");
1511 // Anything but the three names is a corrupt line, by name.1649 // Anything but the three names is a corrupt line, by name.
1512 for line in ["encoder\n", "encoder gpu\n", "encoder Hardware\n"] {1650 for line in ["encoder\n", "encoder gpu\n", "encoder Hardware\n"] {
1513- let file = format!("edith 14\nsource 0 a.mp4\n{line}");1651+ let file = format!("edith 15\nsource 0 a.mp4\n{line}");
1514 assert!(1652 assert!(
1515 parse(file.as_bytes(), &dir).is_err(),1653 parse(file.as_bytes(), &dir).is_err(),
1516 "{line:?} is not an encoder line"1654 "{line:?} is not an encoder line"
@@ -1534,6 +1672,7 @@ mod tests {
1534 &[],1672 &[],
1535 &[],1673 &[],
1536 &[],1674 &[],
1675+ &[],
1537 (1280, 720),1676 (1280, 720),
1538 None,1677 None,
1539 preset,1678 preset,
@@ -1634,7 +1773,7 @@ mod tests {
1634 let bytes = flat(&dir, &sources, &lanes, 12);1773 let bytes = flat(&dir, &sources, &lanes, 12);
1635 assert_eq!(1774 assert_eq!(
1636 String::from_utf8_lossy(&bytes),1775 String::from_utf8_lossy(&bytes),
1637- "edith 14\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\1776+ "edith 15\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
1638 source 2 /elsewhere/b.mp4\n\1777 source 2 /elsewhere/b.mp4\n\
1639 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\1778 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
1640 audio 1 0 0 30 0 0 - - fit 1000\n",1779 audio 1 0 0 30 0 0 - - fit 1000\n",
@@ -1671,7 +1810,7 @@ mod tests {
1671 let bytes = flat(&dir, &sources, &lanes, 7);1810 let bytes = flat(&dir, &sources, &lanes, 7);
1672 assert_eq!(1811 assert_eq!(
1673 String::from_utf8_lossy(&bytes),1812 String::from_utf8_lossy(&bytes),
1674- "edith 14\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\1813+ "edith 15\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
1675 video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\1814 video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\
1676 video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n",1815 video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n",
1677 "an empty lane is a line of its own; everything else is its clips"1816 "an empty lane is a line of its own; everything else is its clips"
@@ -1779,7 +1918,7 @@ mod tests {
1779 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);1918 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);
1780 assert_eq!(1919 assert_eq!(
1781 String::from_utf8_lossy(&bytes),1920 String::from_utf8_lossy(&bytes),
1782- "edith 14\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\1921+ "edith 15\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
1783 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\1922 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
1784 eq 16777215.0:-0.1:3.918315e-39:hs\n\1923 eq 16777215.0:-0.1:3.918315e-39:hs\n\
1785 eq\n\1924 eq\n\
@@ -1883,7 +2022,7 @@ mod tests {
1883 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);2022 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);
1884 assert_eq!(2023 assert_eq!(
1885 String::from_utf8_lossy(&bytes),2024 String::from_utf8_lossy(&bytes),
1886- "edith 14\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2025+ "edith 15\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
1887 color 0.1:1.2:0.9:-0.3\n\2026 color 0.1:1.2:0.9:-0.3\n\
1888 color -1e-7:16777215.0:3.918315e-39:-0.0\n\2027 color -1e-7:16777215.0:3.918315e-39:-0.0\n\
1889 color 0.0:1.0:1.0:0.0\n\2028 color 0.0:1.0:1.0:0.0\n\
@@ -1948,7 +2087,7 @@ mod tests {
1948 (1280, 720),2087 (1280, 720),
1949 old.playhead2088 old.playhead
1950 )),2089 )),
1951- "edith 14\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2090+ "edith 15\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
1952 eq 80.0:-3.0:0.707:ls\n\2091 eq 80.0:-3.0:0.707:ls\n\
1953 video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"2092 video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"
1954 );2093 );
@@ -1986,7 +2125,7 @@ mod tests {
1986 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);2125 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
1987 assert_eq!(2126 assert_eq!(
1988 String::from_utf8_lossy(&bytes),2127 String::from_utf8_lossy(&bytes),
1989- "edith 14\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\2128+ "edith 15\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
1990 video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\2129 video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\
1991 audio 1 0 0 30 0 - - - fit 2000\n",2130 audio 1 0 0 30 0 - - - fit 2000\n",
1992 "the rate is the clip line's last field, in thousandths"2131 "the rate is the clip line's last field, in thousandths"
@@ -2015,7 +2154,7 @@ mod tests {
2015 (1280, 720),2154 (1280, 720),
2016 old.playhead2155 old.playhead
2017 )),2156 )),
2018- "edith 14\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2157+ "edith 15\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2019 video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"2158 video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"
2020 );2159 );
2021 // A rate outside what the editor can set is a corrupt line, by name.2160 // A rate outside what the editor can set is a corrupt line, by name.
@@ -2053,6 +2192,7 @@ mod tests {
2053 &[],2192 &[],
2054 &[],2193 &[],
2055 &[],2194 &[],
2195+ &[],
2056 (1280, 720),2196 (1280, 720),
2057 Some(23.976023976023978),2197 Some(23.976023976023978),
2058 crate::tonemap::Preset::default(),2198 crate::tonemap::Preset::default(),
@@ -2064,7 +2204,7 @@ mod tests {
2064 );2204 );
2065 assert_eq!(2205 assert_eq!(
2066 String::from_utf8_lossy(&bytes),2206 String::from_utf8_lossy(&bytes),
2067- "edith 14\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\2207+ "edith 15\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\
2068 limiter -1.5 on\nsource 0 a.mp4\n\2208 limiter -1.5 on\nsource 0 a.mp4\n\
2069 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\2209 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\
2070 audio 2 0 0 30 0 - - - fit 1000\n\2210 audio 2 0 0 30 0 - - - fit 1000\n\
@@ -2096,7 +2236,7 @@ mod tests {
2096 (1280, 720),2236 (1280, 720),
2097 old.playhead2237 old.playhead
2098 )),2238 )),
2099- "edith 14\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\2239+ "edith 15\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2100 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"2240 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"
2101 );2241 );
2102 2242
@@ -2260,7 +2400,7 @@ mod tests {
2260 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");2400 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");
2261 assert_eq!(2401 assert_eq!(
2262 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),2402 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),
2263- "edith 14\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\2403+ "edith 15\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2264 source 2 /elsewhere/b.mp4\n\2404 source 2 /elsewhere/b.mp4\n\
2265 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\2405 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
2266 audio 1 0 0 30 0 0 - - fit 1000\n"2406 audio 1 0 0 30 0 0 - - fit 1000\n"
@@ -2313,7 +2453,7 @@ mod tests {
2313 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);2453 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
2314 assert_eq!(2454 assert_eq!(
2315 String::from_utf8_lossy(&v5),2455 String::from_utf8_lossy(&v5),
2316- "edith 14\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\2456+ "edith 15\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2317 source 0 /elsewhere/b.mp4\n\2457 source 0 /elsewhere/b.mp4\n\
2318 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\2458 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
2319 audio 1 0 0 30 0 0 - - fit 1000\n",2459 audio 1 0 0 30 0 0 - - fit 1000\n",
@@ -2345,7 +2485,7 @@ mod tests {
2345 // Saved again it is the current version, which round-trips to the2485 // Saved again it is the current version, which round-trips to the
2346 // same document.2486 // same document.
2347 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);2487 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
2348- assert!(v5.starts_with(b"edith 14\n"));2488+ assert!(v5.starts_with(b"edith 15\n"));
2349 let again = parse(&v5, &dir).expect("v5 parses");2489 let again = parse(&v5, &dir).expect("v5 parses");
2350 assert_eq!(again.lanes, back.lanes);2490 assert_eq!(again.lanes, back.lanes);
2351 // A dialect may not be mixed: lane lines under v1, `clip` under v2.2491 // A dialect may not be mixed: lane lines under v1, `clip` under v2.
@@ -2440,6 +2580,7 @@ mod tests {
2440 &[],2580 &[],
2441 &[],2581 &[],
2442 &[],2582 &[],
2583+ &[],
2443 (1280, 720),2584 (1280, 720),
2444 None,2585 None,
2445 crate::tonemap::Preset::default(),2586 crate::tonemap::Preset::default(),
@@ -2453,7 +2594,7 @@ mod tests {
2453 let bytes = std::fs::read(&path).expect("read back");2594 let bytes = std::fs::read(&path).expect("read back");
2454 assert_eq!(2595 assert_eq!(
2455 String::from_utf8_lossy(&bytes),2596 String::from_utf8_lossy(&bytes),
2456- "edith 14\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\2597+ "edith 15\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
2457 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"2598 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"
2458 );2599 );
2459 // Loading rejoins the *given* directory, so the file is reached by the2600 // Loading rejoins the *given* directory, so the file is reached by the
@@ -2498,10 +2639,10 @@ mod tests {
2498 #[test]2639 #[test]
2499 fn a_wrong_first_line_is_refused_by_name() {2640 fn a_wrong_first_line_is_refused_by_name() {
2500 let dir = PathBuf::from("/proj");2641 let dir = PathBuf::from("/proj");
2501- let err = parse(b"edith 15\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)2642+ let err = parse(b"edith 16\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)
2502 .unwrap_err()2643 .unwrap_err()
2503 .to_string();2644 .to_string();
2504- assert_eq!(err, "line 1: unsupported version 15");2645+ assert_eq!(err, "line 1: unsupported version 16");
2505 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {2646 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {
2506 assert_eq!(2647 assert_eq!(
2507 parse(junk, &dir).unwrap_err().to_string(),2648 parse(junk, &dir).unwrap_err().to_string(),
crates/engine/src/playback.rsmodified+8 -1
@@ -969,7 +969,11 @@ impl PlaybackSession {
969 let project = Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color)?969 let project = Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color)?
970 .with_mix(&doc.gains, doc.limiter)970 .with_mix(&doc.gains, doc.limiter)
971 .with_tone(doc.tone)971 .with_tone(doc.tone)
972- .with_subtitles(subtitles);972+ // The palette before what is placed on it: a caption names a row of
973+ // it, and [`Project::with_subs`] refuses one naming a row that is
974+ // not there.
975+ .with_subtitles(subtitles)
976+ .with_subs(doc.subs)?;
973 let span = project.composite_span_at(0);977 let span = project.composite_span_at(0);
974 // Last, because it is the one thing here that cannot be taken back: the978 // Last, because it is the one thing here that cannot be taken back: the
975 // feeder thread outlives the `Audio` value (it holds its own clones) and979 // feeder thread outlives the `Audio` value (it holds its own clones) and
@@ -1260,6 +1264,9 @@ impl PlaybackSession {
1260 // project's, not this machine's (the monitoring volume is not1264 // project's, not this machine's (the monitoring volume is not
1261 // written and never will be).1265 // written and never will be).
1262 &self.project.lane_gains(),1266 &self.project.lane_gains(),
1267+ // ...and what is placed on each lane, in the same order again: the
1268+ // captions, which are the only thing a subtitle lane holds.
1269+ &self.project.lane_subs(),
1263 // The subtitle tracks with them, by reference: which file the cues1270 // The subtitle tracks with them, by reference: which file the cues
1264 // are in, never the cues (see [`crate::edith`]).1271 // are in, never the cues (see [`crate::edith`]).
1265 self.project.subtitles(),1272 self.project.subtitles(),
crates/engine/src/project.rsmodified+83 -22
@@ -1295,20 +1295,11 @@ impl Project {
1295 }1295 }
1296 (1296 (
1297 sources,1297 sources,
1298- lanes1298+ // Every lane, subtitle ones included: they hold no [`Clip`], so what
1299- .into_iter()1299+ // comes out for one is an empty list, and its *place* in the display
1300- // corner-cut: the subtitle lanes are left out, because [`Parts`]1300+ // order is what a save writes it for. What is on it travels beside
1301- // is `(LaneKind, Vec<Clip>)` and a subtitle lane's contents are1301+ // this, in [`lane_subs`](Project::lane_subs), as the gains do.
1302- // [`SubClip`]s -- a `.edith` has no line to write one on yet, so1302+ lanes.into_iter().map(|l| (l.kind, l.clips)).collect(),
1303- // a save that emitted the lane would write a track with nothing
1304- // in it and a *reader* that has never seen the keyword would
1305- // refuse the file. Upgrade path is the format slice that owns
1306- // it: a `sub` line per placement (lane ord, start, frames,
1307- // track, window) beside the `video`/`audio` ones, and this
1308- // filter goes.
1309- .filter(|l| l.kind != LaneKind::Subtitle)
1310- .map(|l| (l.kind, l.clips))
1311- .collect(),
1312 eq,1303 eq,
1313 color,1304 color,
1314 )1305 )
@@ -1352,15 +1343,85 @@ impl Project {
1352 /// Every lane's volume in dB, in display order -- what a save writes,1343 /// Every lane's volume in dB, in display order -- what a save writes,
1353 /// beside the lanes [`Project::without_orphan_sources`] hands back.1344 /// beside the lanes [`Project::without_orphan_sources`] hands back.
1354 ///1345 ///
1355- /// The *same* lanes as that call, subtitle ones left out: a save zips the1346+ /// The *same* lanes as that call, subtitle ones included at the `0.0` they
1356- /// two lists, so a lane that is in one and not the other would hand every1347+ /// are pinned to ([`set_lane_gain_db`](Project::set_lane_gain_db) refuses
1357- /// track below it the volume of the track above.1348+ /// one): a save zips the two lists, so a lane that is in one and not the
1349+ /// other would hand every track below it the volume of the track above.
1358 pub fn lane_gains(&self) -> Vec<f32> {1350 pub fn lane_gains(&self) -> Vec<f32> {
1359- self.lanes1351+ self.lanes.iter().map(|l| l.gain_db).collect()
1360- .iter()1352+ }
1361- .filter(|l| l.kind != LaneKind::Subtitle)1353+
1362- .map(|l| l.gain_db)1354+ /// What is placed on every lane, in display order and in step with
1363- .collect()1355+ /// [`without_orphan_sources`](Project::without_orphan_sources) exactly as
1356+ /// [`lane_gains`](Project::lane_gains) is -- what a save writes as its `sub`
1357+ /// lines. Empty for every video and audio lane, which hold no [`SubClip`].
1358+ ///
1359+ /// Nothing is renumbered on the way out: a [`SubClip`] names a *palette*
1360+ /// row ([`Project::subtitles`]) and the palette is saved whole, so unlike a
1361+ /// clip's source there is no orphan to prune and no index to move.
1362+ pub fn lane_subs(&self) -> Vec<Vec<SubClip>> {
1363+ self.lanes.iter().map(|l| l.subs.clone()).collect()
1364+ }
1365+
1366+ /// The placements a *load* puts back, one list per lane in display order --
1367+ /// the door [`with_mix`](Project::with_mix) is, and no undo step for the
1368+ /// same reason. Called *after*
1369+ /// [`with_subtitles`](Project::with_subtitles), whose palette a placement
1370+ /// names.
1371+ ///
1372+ /// The subtitle half of [`from_parts`](Project::from_parts) and checked
1373+ /// like it, by name and in release, because it is the same untrusted file:
1374+ /// a placement on a lane that is not a subtitle lane, an empty span or an
1375+ /// empty window, a track the palette does not have, a span running past the
1376+ /// last frame there is, and a lane that is out of order or overlaps itself
1377+ /// ([`place_sub`] refuses every one of those on the live timeline).
1378+ ///
1379+ /// [`place_sub`]: Project::place_sub
1380+ pub fn with_subs(mut self, subs: Vec<Vec<SubClip>>) -> crate::Result<Self> {
1381+ let names = handles(&self.lanes);
1382+ let palette = self.subtitles.len();
1383+ for ((data, lane), list) in self.lanes.iter_mut().zip(names).zip(subs) {
1384+ let name = lane.label();
1385+ if list.is_empty() {
1386+ continue;
1387+ }
1388+ if data.kind != LaneKind::Subtitle {
1389+ return Err(format!(
1390+ "{name} is not a subtitle track and holds {} caption(s): words go on a \
1391+ subtitle track",
1392+ list.len()
1393+ )
1394+ .into());
1395+ }
1396+ for s in &list {
1397+ if s.frames == 0 || s.out_us <= s.in_us || s.in_us < 0 {
1398+ return Err(format!(
1399+ "{name} caption at {} is empty: {} frames of [{}, {})",
1400+ s.start, s.frames, s.in_us, s.out_us
1401+ )
1402+ .into());
1403+ }
1404+ if s.track >= palette {
1405+ return Err(format!(
1406+ "{name} caption at {} names subtitle track {} of {palette}",
1407+ s.start, s.track
1408+ )
1409+ .into());
1410+ }
1411+ if s.start.checked_add(s.frames).is_none() {
1412+ return Err(format!(
1413+ "{name} caption at {} runs past the last frame there is",
1414+ s.start
1415+ )
1416+ .into());
1417+ }
1418+ }
1419+ if !subs_sorted_disjoint(&list) {
1420+ return Err(format!("the {name} lane is out of order or overlaps itself").into());
1421+ }
1422+ data.subs = list;
1423+ }
1424+ Ok(self)
1364 }1425 }
1365 1426
1366 /// The mix settings a *load* puts back: lane volumes in display order (a1427 /// The mix settings a *load* puts back: lane volumes in display order (a
crates/engine/tests/export.rsmodified+1 -1
@@ -985,7 +985,7 @@ fn a_proxy_is_picture_only_every_frame_a_starting_point_and_cached() {
985 session.set_proxies(true);985 session.set_proxies(true);
986 session.save_project(&project).expect("save");986 session.save_project(&project).expect("save");
987 let text = std::fs::read_to_string(&project).expect("read the project back");987 let text = std::fs::read_to_string(&project).expect("read the project back");
988- assert!(text.starts_with("edith 14\n"), "{text}");988+ assert!(text.starts_with("edith 15\n"), "{text}");
989 assert!(text.contains("\nproxy on\n"), "{text}");989 assert!(text.contains("\nproxy on\n"), "{text}");
990 let reopened = PlaybackSession::open_project(&project).expect("load");990 let reopened = PlaybackSession::open_project(&project).expect("load");
991 assert!(reopened.proxies(), "the switch came back on");991 assert!(reopened.proxies(), "the switch came back on");
crates/engine/tests/lanes.rsmodified+3 -2
@@ -463,8 +463,9 @@ fn a_subtitle_lane_is_a_peer_and_every_media_path_refuses_it() {
463 assert_eq!(project.audio_gains().len(), 1);463 assert_eq!(project.audio_gains().len(), 1);
464 assert_eq!(464 assert_eq!(
465 project.lane_gains().len(),465 project.lane_gains().len(),
466- 2,466+ 3,
467- "a save's gain list holds the two media lanes, in step with its lane list"467+ "a save's gain list holds one entry per lane, in step with its lane list -- \
468+ this one's at the 0.0 a subtitle lane is pinned to"
468 );469 );
469 470
470 // The clip-shaped calls: the lane holds no `Clip`, so each refuses by the471 // The clip-shaped calls: the lane holds no `Clip`, so each refuses by the
crates/engine/tests/saveload.rsmodified+6 -6
@@ -291,7 +291,7 @@ fn a_version_1_project_loads_fully_grouped_and_saves_as_version_7() {
291 let v2 = dir.join("new.edith");291 let v2 = dir.join("new.edith");
292 loaded.save_project(&v2).expect("save");292 loaded.save_project(&v2).expect("save");
293 let text = std::fs::read_to_string(&v2).expect("read back");293 let text = std::fs::read_to_string(&v2).expect("read back");
294- assert!(text.starts_with("edith 14\n"), "{text}");294+ assert!(text.starts_with("edith 15\n"), "{text}");
295 assert!(295 assert!(
296 text.contains("\nresolution 1280 720\n"),296 text.contains("\nresolution 1280 720\n"),
297 "a project with no resolution of its own is saved at source 0's: {text}"297 "a project with no resolution of its own is saved at source 0's: {text}"
@@ -379,7 +379,7 @@ fn a_version_4_project_holds_more_than_two_lanes() {
379 loaded.save_project(&again).expect("save");379 loaded.save_project(&again).expect("save");
380 assert_eq!(380 assert_eq!(
381 std::fs::read_to_string(&again).expect("read back"),381 std::fs::read_to_string(&again).expect("read back"),
382- "edith 14\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\382+ "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
383 video 1 0 0 30 0 3 - - fit 1000\naudio 1\n\383 video 1 0 0 30 0 3 - - fit 1000\naudio 1\n\
384 video 2 40 0 20 0 - - - fit 1000\naudio 2 0 0 30 0 3 - - fit 1000\n",384 video 2 40 0 20 0 - - - fit 1000\naudio 2 0 0 30 0 3 - - fit 1000\n",
385 "a four-lane project is written as it was read, three versions on"385 "a four-lane project is written as it was read, three versions on"
@@ -409,7 +409,7 @@ fn a_version_5_project_carries_per_clip_equalizers() {
409 loaded.save_project(&again).expect("save");409 loaded.save_project(&again).expect("save");
410 assert_eq!(410 assert_eq!(
411 std::fs::read_to_string(&again).expect("read back"),411 std::fs::read_to_string(&again).expect("read back"),
412- "edith 14\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\412+ "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
413 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\413 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
414 eq 12000.0:6.25:0.5:hs\n\414 eq 12000.0:6.25:0.5:hs\n\
415 video 1 0 0 30 0 - 0 - fit 1000\nvideo 1 30 30 60 0 - 1 - fit 1000\n\415 video 1 0 0 30 0 - 0 - fit 1000\nvideo 1 30 30 60 0 - 1 - fit 1000\n\
@@ -444,7 +444,7 @@ fn a_version_6_project_carries_per_clip_colours() {
444 loaded.save_project(&again).expect("save");444 loaded.save_project(&again).expect("save");
445 assert_eq!(445 assert_eq!(
446 std::fs::read_to_string(&again).expect("read back"),446 std::fs::read_to_string(&again).expect("read back"),
447- "edith 14\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\447+ "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
448 eq 80.0:-3.0:0.707:ls\n\448 eq 80.0:-3.0:0.707:ls\n\
449 color 0.1:1.2:0.9:-0.3\n\449 color 0.1:1.2:0.9:-0.3\n\
450 color -0.25:1.0:0.0:0.5\n\450 color -0.25:1.0:0.0:0.5\n\
@@ -494,7 +494,7 @@ fn a_version_7_project_carries_a_resolution_and_fit_policies() {
494 loaded.save_project(&again).expect("save");494 loaded.save_project(&again).expect("save");
495 assert_eq!(495 assert_eq!(
496 std::fs::read_to_string(&again).expect("read back"),496 std::fs::read_to_string(&again).expect("read back"),
497- "edith 14\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\497+ "edith 15\nplayhead 0\nresolution 960 720\nfps 30.0\nsource 0 test_av.mp4\n\
498 video 1 0 0 30 0 - - - fill 1000\nvideo 1 30 30 60 0 - - - center 1000\n\498 video 1 0 0 30 0 - - - fill 1000\nvideo 1 30 30 60 0 - - - center 1000\n\
499 audio 1 0 0 60 0 - - - fit 1000\n",499 audio 1 0 0 60 0 - - - fit 1000\n",
500 "a v7 project is written back as the v8 it now is: the same clips, each \500 "a v7 project is written back as the v8 it now is: the same clips, each \
@@ -752,7 +752,7 @@ fn malformed_files_are_numbered_errors_and_never_panics() {
752 752
753 for (text, want) in [753 for (text, want) in [
754 (754 (
755- "edith 15\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n",755+ "edith 16\nsource 0 test_av.mp4\nvideo 1 0 0 30 0 - - - fit\n",
756 "line 1",756 "line 1",
757 ),757 ),
758 // An eq index the table does not hold, and a band shape there is none.758 // An eq index the table does not hold, and a band shape there is none.
crates/engine/tests/silence.rsmodified+2 -1
@@ -370,6 +370,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() {
370 &sources,370 &sources,
371 &lanes,371 &lanes,
372 &p.lane_gains(),372 &p.lane_gains(),
373+ &p.lane_subs(),
373 p.subtitles(),374 p.subtitles(),
374 &eq,375 &eq,
375 &color,376 &color,
@@ -385,7 +386,7 @@ fn scanning_a_clip_and_cutting_what_it_finds() {
385 .expect("save");386 .expect("save");
386 let text = std::fs::read_to_string(&file).expect("read it back");387 let text = std::fs::read_to_string(&file).expect("read it back");
387 assert!(388 assert!(
388- text.starts_with("edith 13"),389+ text.starts_with("edith 15"),
389 "{:?}",390 "{:?}",
390 &text[..16.min(text.len())]391 &text[..16.min(text.len())]
391 );392 );
crates/engine/tests/subtitles.rsmodified+175 -1
@@ -260,7 +260,7 @@ fn a_project_keeps_its_subtitles_across_a_save() {
260 let project = dir.join("cut.edith");260 let project = dir.join("cut.edith");
261 session.save_project(&project).expect("save");261 session.save_project(&project).expect("save");
262 let text = std::fs::read_to_string(&project).expect("read the project back");262 let text = std::fs::read_to_string(&project).expect("read the project back");
263- assert!(text.starts_with("edith 14\n"), "{text}");263+ assert!(text.starts_with("edith 15\n"), "{text}");
264 assert!(264 assert!(
265 text.contains("\nsubtitle - test_subs.srt\n"),265 text.contains("\nsubtitle - test_subs.srt\n"),
266 "the reference is written relative, and no cue is: {text}"266 "the reference is written relative, and no cue is: {text}"
@@ -1211,3 +1211,177 @@ fn pgs_erase() -> Vec<u8> {
1211 set.extend(pgs_segment(0x80, &[]));1211 set.extend(pgs_segment(0x80, &[]));
1212 set1212 set
1213 }1213 }
1214+
1215+/// The v15 lines: a subtitle lane is written in its place among the others, a
1216+/// caption on it is one `sub` line -- both clocks and the palette row it names
1217+/// -- and an empty one is the bare line a video lane's is. The whole of it
1218+/// comes back the placement it was, and a re-save is the same bytes, which is
1219+/// what "the file is the timeline" means for words as much as for pictures.
1220+#[test]
1221+fn subtitle_lanes_and_their_captions_survive_a_save() {
1222+ let dir = scratch("lanes_save");
1223+ let media = dir.join("test_av.mp4");
1224+ std::fs::copy(asset("test_av.mp4"), &media).expect("copy the media fixture");
1225+ let subs = dir.join("test_subs.srt");
1226+ std::fs::copy(data("test_subs.srt"), &subs).expect("copy the subtitle fixture");
1227+
1228+ let mut session = engine::PlaybackSession::open(&media).expect("open the fixture");
1229+ session.set_gain(0.0); // silent like the rest of the suites
1230+ assert_eq!(session.import_subtitles(&subs).expect("the .srt imports"), 1);
1231+
1232+ let s1 = session.add_lane(LaneKind::Subtitle);
1233+ let s2 = session.add_lane(LaneKind::Subtitle);
1234+ let caption = SubClip {
1235+ start: 0,
1236+ frames: 45,
1237+ track: 0,
1238+ in_us: 500_000,
1239+ out_us: 1_500_000,
1240+ };
1241+ session.place_sub(s1, 10, caption).expect("a caption goes down");
1242+
1243+ let project = dir.join("cut.edith");
1244+ session.save_project(&project).expect("save");
1245+ let text = std::fs::read_to_string(&project).expect("read the project back");
1246+ assert!(text.starts_with("edith 15\n"), "{text}");
1247+ assert!(
1248+ text.contains("\nsub 1 10 45 0 500000 1500000\n"),
1249+ "the placement is one line: where it sits, how long, whose words, and \
1250+ the window of them in microseconds: {text}"
1251+ );
1252+ assert!(
1253+ text.contains("\nsub 2\n"),
1254+ "and an empty subtitle lane says so on a line of its own: {text}"
1255+ );
1256+
1257+ let back = engine::PlaybackSession::open_project(&project).expect("open the project");
1258+ assert_eq!(
1259+ back.subtitle_lanes(),
1260+ [s1, s2],
1261+ "both lanes come back, in the order they were laid out"
1262+ );
1263+ assert_eq!(
1264+ back.sub_lane(s1),
1265+ [SubClip { start: 10, ..caption }],
1266+ "and the caption is the very placement it was"
1267+ );
1268+ assert!(back.sub_lane(s2).is_empty(), "the empty one is still empty");
1269+ assert_eq!(back.subtitles()[0].cues, expected(), "palette intact");
1270+
1271+ // ...and saving what was loaded writes the file it was loaded from.
1272+ let again = dir.join("cut2.edith");
1273+ back.save_project(&again).expect("save again");
1274+ assert_eq!(
1275+ std::fs::read_to_string(&again).expect("read"),
1276+ text,
1277+ "a load and a re-save is the same file"
1278+ );
1279+}
1280+
1281+/// The dialect before the lanes: a v14 project names its subtitle files and
1282+/// places none of them -- there was no line to place one on -- so it loads with
1283+/// its palette whole and no subtitle lane at all, and re-saves as v15 with the
1284+/// same one `subtitle` line and nothing on any lane.
1285+#[test]
1286+fn a_version_14_project_keeps_its_palette_and_places_nothing() {
1287+ let dir = scratch("v14");
1288+ let media = dir.join("test_av.mp4");
1289+ std::fs::copy(asset("test_av.mp4"), &media).expect("copy the media fixture");
1290+ let srt = dir.join("test_subs.srt");
1291+ std::fs::copy(data("test_subs.srt"), &srt).expect("copy the subtitle fixture");
1292+ let path = dir.join("old.edith");
1293+ std::fs::write(
1294+ &path,
1295+ "edith 14\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
1296+ subtitle - test_subs.srt\nvideo 1 0 0 30 0 0 - - fit 1000\n\
1297+ audio 1 0 0 30 0 0 - - fit 1000\n",
1298+ )
1299+ .expect("write a v14 file");
1300+
1301+ let loaded = engine::PlaybackSession::open_project(&path).expect("a v14 file still opens");
1302+ assert_eq!(loaded.subtitles().len(), 1, "the palette row is there");
1303+ assert_eq!(loaded.subtitles()[0].cues, expected(), "cues and all");
1304+ assert!(
1305+ loaded.subtitle_lanes().is_empty(),
1306+ "and nothing of it is placed: that dialect had nowhere to place it"
1307+ );
1308+
1309+ let now = dir.join("new.edith");
1310+ loaded.save_project(&now).expect("save");
1311+ let text = std::fs::read_to_string(&now).expect("read back");
1312+ assert!(text.starts_with("edith 15\n"), "{text}");
1313+ assert!(
1314+ text.contains("\nsubtitle - test_subs.srt\n"),
1315+ "the row survives the migration: {text}"
1316+ );
1317+ assert!(
1318+ !text.contains("\nsub "),
1319+ "and no lane and no placement were invented for it: {text}"
1320+ );
1321+}
1322+
1323+/// The palette bound, which is a clip's source bound for words: a caption names
1324+/// a `subtitle` line by position, so one naming a row that is not there is
1325+/// refused -- at the parser, which names the line, and at
1326+/// [`engine::Project::with_subs`], which names the lane. Neither is a file this
1327+/// editor wrote; both are files it may be handed.
1328+#[test]
1329+fn a_caption_naming_a_track_the_palette_does_not_have_is_refused() {
1330+ let dir = scratch("badtrack");
1331+ let media = dir.join("test_av.mp4");
1332+ std::fs::copy(asset("test_av.mp4"), &media).expect("copy the media fixture");
1333+ std::fs::copy(data("test_subs.srt"), dir.join("test_subs.srt")).expect("copy the subtitles");
1334+ let path = dir.join("bad.edith");
1335+ std::fs::write(
1336+ &path,
1337+ "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
1338+ subtitle - test_subs.srt\nvideo 1 0 0 30 0 0 - - fit 1000\n\
1339+ audio 1 0 0 30 0 0 - - fit 1000\nsub 1 0 45 3 0 1000000\n",
1340+ )
1341+ .expect("write it");
1342+ let err = engine::PlaybackSession::open_project(&path)
1343+ .err()
1344+ .expect("a caption may not name a row that is not there")
1345+ .to_string();
1346+ assert_eq!(err, "line 9: caption names subtitle track 3 of 1");
1347+
1348+ // An empty placement is refused by the same door, at either clock.
1349+ let empty = dir.join("empty.edith");
1350+ std::fs::write(
1351+ &empty,
1352+ "edith 15\nplayhead 0\nresolution 1280 720\nfps 30.0\nsource 0 test_av.mp4\n\
1353+ subtitle - test_subs.srt\nvideo 1 0 0 30 0 0 - - fit 1000\n\
1354+ audio 1 0 0 30 0 0 - - fit 1000\nsub 1 0 45 0 1000000 1000000\n",
1355+ )
1356+ .expect("write it");
1357+ let err = engine::PlaybackSession::open_project(&empty)
1358+ .err()
1359+ .expect("a window of nothing is not a caption")
1360+ .to_string();
1361+ assert_eq!(
1362+ err,
1363+ "line 9: caption at 0 is empty: 45 frames of [1000000, 1000000)"
1364+ );
1365+
1366+ // ...and the load's own door says the same thing about the same file, by
1367+ // the lane rather than by the line: `from_parts` for words.
1368+ let (project, _lane) = with_subtitle_lane();
1369+ let beyond = SubClip { track: 3, ..whole(0) };
1370+ let refused = project
1371+ .clone()
1372+ .with_subs(vec![Vec::new(), Vec::new(), vec![beyond]])
1373+ .expect_err("the palette holds one row")
1374+ .to_string();
1375+ assert_eq!(refused, "S1 caption at 0 names subtitle track 3 of 1");
1376+
1377+ // A caption on a lane that is not a subtitle lane is refused there too --
1378+ // the media lanes hold pictures and sound, and never words.
1379+ let wrong = project
1380+ .with_subs(vec![vec![whole(0)], Vec::new(), Vec::new()])
1381+ .expect_err("V1 is not a subtitle track")
1382+ .to_string();
1383+ assert!(
1384+ wrong.starts_with("V1 is not a subtitle track and holds 1 caption(s)"),
1385+ "{wrong}"
1386+ );
1387+}