forge
Explore
Log in

Don't you dare go Hollow

Offset-preserving groups over clips and captions

Browse files at this commit

48cacb671eb3a476c4fd5b1b7137d7b86306e78aAhmet Kaan GümüşParent: 888f39d
  • feat
    • offset-preserving groups over clips and captions
Show full message
✨ feat(engine): offset-preserving groups over clips and captions

The engine half of manual clip grouping: SubClip gains a link id, the
group invariant becomes one-placement-per-lane (span equality dropped),
group_all builds a hand group over clips and captions with mates riding
along, splits keep the left group and share one fresh id on the right
(captions included), deletes ripple each media member's own span on its
own lane and lift caption members, grouped caption drags and group
trims move every member by one delta clamped to each member's own
walls, and the save format grows an optional 6th sub field as v16.

App half (Selection refactor, ctrl+click, ctrl+A, oracle/menu, marks)
follows.
crates/engine/src/edith.rsmodified+54 -25
@@ -143,11 +143,13 @@
143143 //! track 3 of a two-track palette is refused here, as a clip naming a source
144144 //! that is not there is.
145145 //!
146-//! **Version 14** was this without the `sub` lines: such a project holds no
146+//! **Version 15** was this without the caption's group field: such a project
147+//! holds captions no hand ever grouped, which is every caption there could be.
148+//! **Version 14** was that without the `sub` lines: such a project holds no
147149 //! subtitle lane at all -- its `subtitle` lines are the palette, and where the
148150 //! words of it were shown was nowhere in the file.
149-//! **Version 13** was that without the `encoder` line: an export of such a
150-//! project takes the hardware seat where there is one and the software encoder
151+//! **Version 13** was that without the `encoder` line: such a project takes the
152+//! hardware seat where there is one and the software encoder
151153 //! everywhere else, which is the only choice those projects had.
152154 //! **Version 12** was that without the `autoproxy` line: such a project makes a
153155 //! stand-in for every film that wants one the moment it arrives, which is all
@@ -178,7 +180,7 @@
178180 //! nothing, and an older one plays everything at real time, and an older one
179181 //! mixes flat, and an older one shows no subtitles, and an older one is shown
180182 //! 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
183+//! names -- and saving any of them writes v16. An older
182184 //! reader refuses a newer file by name.
183185 //!
184186 //! Text because an edit list is a few integers and a path, and a path is
@@ -214,7 +216,8 @@ use crate::subtitle::SubtitleTrack;
214216
215217 /// What [`save`] writes. Read support goes back to `edith 1`; see the module
216218 /// docs for what those dialects looked like.
217-const MAGIC: &[u8] = b"edith 15";
219+const MAGIC: &[u8] = b"edith 16";
220+const MAGIC_V15: &[u8] = b"edith 15";
218221 const MAGIC_V14: &[u8] = b"edith 14";
219222 const MAGIC_V13: &[u8] = b"edith 13";
220223 const MAGIC_V12: &[u8] = b"edith 12";
@@ -503,9 +506,13 @@ fn emit(
503506 out.extend_from_slice(format!("{keyword} {ord}\n").as_bytes());
504507 }
505508 for s in placed {
509+ // The group field only when the caption is in one, for the
510+ // clip line's reason: a project nobody grouped a caption in is
511+ // the same bytes it was in v15.
512+ let link = s.link.map_or(String::new(), |l| format!(" {l}"));
506513 out.extend_from_slice(
507514 format!(
508- "{keyword} {ord} {} {} {} {} {}\n",
515+ "{keyword} {ord} {} {} {} {} {}{link}\n",
509516 s.start, s.frames, s.track, s.in_us, s.out_us
510517 )
511518 .as_bytes(),
@@ -573,8 +580,10 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
573580 // The dialects that wrote a source line without its stream field. Reading
574581 // one is the whole of what "an old project still opens" means here.
575582 let streamless = v1 || first == MAGIC_V2;
576- // The one that places the words it names...
577- let v15 = first == MAGIC;
583+ // The one whose captions may carry a group id...
584+ let v16 = first == MAGIC;
585+ // ...the one that places the words it names...
586+ let v15 = v16 || first == MAGIC_V15;
578587 // ...the ones that say which encoder an export takes...
579588 let v14 = v15 || first == MAGIC_V14;
580589 // ...the ones that say whether the stand-ins are made by themselves...
@@ -948,13 +957,33 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
948957 if rest.is_empty() {
949958 continue;
950959 }
951- let f = fields(rest, 5, "sub", n)?;
960+ // v16 on may carry a sixth field -- the caption's group id, the
961+ // same spelling a clip's link takes (`-` for none). A v15 line
962+ // stops at five, and a sixth field in one is a file this parser
963+ // never wrote.
964+ let all: Vec<&[u8]> = rest.split(|&b| b == b' ').collect();
965+ let ok = all.len() == 5 || (v16 && all.len() == 6);
966+ if !ok {
967+ return Err(format!(
968+ "line {n}: sub wants {} fields, found {}",
969+ if v16 { "5 or 6" } else { "5" },
970+ all.len()
971+ )
972+ .into());
973+ }
974+ let link = match all.get(5) {
975+ None => None,
976+ Some(f) if *f == b"-" => None,
977+ Some(f) => Some(number(f, n)?),
978+ };
979+ let f = &all;
952980 let sub = SubClip {
953981 start: number(f[0], n)?,
954982 frames: number(f[1], n)?,
955983 track: number(f[2], n)? as usize,
956984 in_us: micros(f[3], n)?,
957985 out_us: micros(f[4], n)?,
986+ link,
958987 };
959988 // The never-empty invariant at both clocks, which is what
960989 // [`crate::Project::place_sub`] refuses on the live timeline.
@@ -1440,7 +1469,7 @@ mod tests {
14401469 video 1 0 0 30 0 - - - fit 1000\n";
14411470 let old = parse(v9, &dir).expect("v9 still loads");
14421471 assert_eq!(old.subtitles, Vec::new());
1443- assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 15\n"));
1472+ assert!(flat(&dir, &old.sources, &old.lanes, old.playhead).starts_with(b"edith 16\n"));
14441473 // ...and the line itself is not a v9 line: a dialect may not be mixed.
14451474 let mixed = parse(b"edith 9\nsource 0 a.mp4\nsubtitle - subs.srt\n", &dir)
14461475 .unwrap_err()
@@ -1773,7 +1802,7 @@ mod tests {
17731802 let bytes = flat(&dir, &sources, &lanes, 12);
17741803 assert_eq!(
17751804 String::from_utf8_lossy(&bytes),
1776- "edith 15\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
1805+ "edith 16\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
17771806 source 2 /elsewhere/b.mp4\n\
17781807 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
17791808 audio 1 0 0 30 0 0 - - fit 1000\n",
@@ -1810,7 +1839,7 @@ mod tests {
18101839 let bytes = flat(&dir, &sources, &lanes, 7);
18111840 assert_eq!(
18121841 String::from_utf8_lossy(&bytes),
1813- "edith 15\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
1842+ "edith 16\nplayhead 7\nresolution 1280 720\nsource 0 a.mp4\n\
18141843 video 1 0 0 30 0 4 - - fit 1000\naudio 1\n\
18151844 video 2 40 0 10 0 - - - fit 1000\naudio 2 0 0 30 0 4 - - fit 1000\n",
18161845 "an empty lane is a line of its own; everything else is its clips"
@@ -1918,7 +1947,7 @@ mod tests {
19181947 let bytes = emit(&dir, &sources, &lanes, &eq, &[], (1280, 720), 0);
19191948 assert_eq!(
19201949 String::from_utf8_lossy(&bytes),
1921- "edith 15\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
1950+ "edith 16\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
19221951 eq 80.0:-3.0:0.707:ls 1000.0:4.5:1.0:pk\n\
19231952 eq 16777215.0:-0.1:3.918315e-39:hs\n\
19241953 eq\n\
@@ -2022,7 +2051,7 @@ mod tests {
20222051 let bytes = emit(&dir, &sources, &lanes, &[], &color, (1280, 720), 0);
20232052 assert_eq!(
20242053 String::from_utf8_lossy(&bytes),
2025- "edith 15\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2054+ "edith 16\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
20262055 color 0.1:1.2:0.9:-0.3\n\
20272056 color -1e-7:16777215.0:3.918315e-39:-0.0\n\
20282057 color 0.0:1.0:1.0:0.0\n\
@@ -2087,7 +2116,7 @@ mod tests {
20872116 (1280, 720),
20882117 old.playhead
20892118 )),
2090- "edith 15\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2119+ "edith 16\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
20912120 eq 80.0:-3.0:0.707:ls\n\
20922121 video 1 0 0 30 0 0 0 - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"
20932122 );
@@ -2125,7 +2154,7 @@ mod tests {
21252154 let bytes = emit(&dir, &sources, &lanes, &[], &[], (1280, 720), 0);
21262155 assert_eq!(
21272156 String::from_utf8_lossy(&bytes),
2128- "edith 15\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
2157+ "edith 16\nplayhead 0\nresolution 1280 720\nsource 0 a.mp4\n\
21292158 video 1 0 0 30 0 - - - fit 2000\nvideo 1 15 30 40 0 - - - fit 250\n\
21302159 audio 1 0 0 30 0 - - - fit 2000\n",
21312160 "the rate is the clip line's last field, in thousandths"
@@ -2154,7 +2183,7 @@ mod tests {
21542183 (1280, 720),
21552184 old.playhead
21562185 )),
2157- "edith 15\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2186+ "edith 16\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
21582187 video 1 0 0 30 0 0 - - fit 1000\naudio 1 0 0 30 0 0 - - fit 1000\n"
21592188 );
21602189 // A rate outside what the editor can set is a corrupt line, by name.
@@ -2204,7 +2233,7 @@ mod tests {
22042233 );
22052234 assert_eq!(
22062235 String::from_utf8_lossy(&bytes),
2207- "edith 15\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\
2236+ "edith 16\nplayhead 0\nresolution 1280 720\nfps 23.976023976023978\n\
22082237 limiter -1.5 on\nsource 0 a.mp4\n\
22092238 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n\
22102239 audio 2 0 0 30 0 - - - fit 1000\n\
@@ -2236,7 +2265,7 @@ mod tests {
22362265 (1280, 720),
22372266 old.playhead
22382267 )),
2239- "edith 15\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
2268+ "edith 16\nplayhead 3\nresolution 1280 720\nsource 0 a.mp4\n\
22402269 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"
22412270 );
22422271
@@ -2400,7 +2429,7 @@ mod tests {
24002429 assert!(old.eq.is_empty(), "nothing before v5 equalizes anything");
24012430 assert_eq!(
24022431 String::from_utf8_lossy(&flat(&dir, &old.sources, &old.lanes, old.playhead)),
2403- "edith 15\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2432+ "edith 16\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
24042433 source 2 /elsewhere/b.mp4\n\
24052434 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
24062435 audio 1 0 0 30 0 0 - - fit 1000\n"
@@ -2453,7 +2482,7 @@ mod tests {
24532482 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
24542483 assert_eq!(
24552484 String::from_utf8_lossy(&v5),
2456- "edith 15\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
2485+ "edith 16\nplayhead 12\nresolution 1280 720\nsource 0 a.mp4\n\
24572486 source 0 /elsewhere/b.mp4\n\
24582487 video 1 0 0 30 0 0 - - fit 1000\nvideo 1 30 10 20 1 1 - - fit 1000\n\
24592488 audio 1 0 0 30 0 0 - - fit 1000\n",
@@ -2485,7 +2514,7 @@ mod tests {
24852514 // Saved again it is the current version, which round-trips to the
24862515 // same document.
24872516 let v5 = flat(&dir, &back.sources, &back.lanes, back.playhead);
2488- assert!(v5.starts_with(b"edith 15\n"));
2517+ assert!(v5.starts_with(b"edith 16\n"));
24892518 let again = parse(&v5, &dir).expect("v5 parses");
24902519 assert_eq!(again.lanes, back.lanes);
24912520 // A dialect may not be mixed: lane lines under v1, `clip` under v2.
@@ -2594,7 +2623,7 @@ mod tests {
25942623 let bytes = std::fs::read(&path).expect("read back");
25952624 assert_eq!(
25962625 String::from_utf8_lossy(&bytes),
2597- "edith 15\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
2626+ "edith 16\nplayhead 0\nresolution 1280 720\nsource 1 a.mp4\n\
25982627 video 1 0 0 30 0 - - - fit 1000\naudio 1 0 0 30 0 - - - fit 1000\n"
25992628 );
26002629 // Loading rejoins the *given* directory, so the file is reached by the
@@ -2639,10 +2668,10 @@ mod tests {
26392668 #[test]
26402669 fn a_wrong_first_line_is_refused_by_name() {
26412670 let dir = PathBuf::from("/proj");
2642- let err = parse(b"edith 16\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)
2671+ let err = parse(b"edith 17\nsource 0 a.mp4\nvideo 0 0 5 0 -\n", &dir)
26432672 .unwrap_err()
26442673 .to_string();
2645- assert_eq!(err, "line 1: unsupported version 16");
2674+ assert_eq!(err, "line 1: unsupported version 17");
26462675 for junk in [&b""[..], b"{}\n", b"source a.mp4\n"] {
26472676 assert_eq!(
26482677 parse(junk, &dir).unwrap_err().to_string(),
crates/engine/src/playback.rsmodified+36 -0
@@ -1825,6 +1825,42 @@ impl PlaybackSession {
18251825 self.project.group(a, a_idx, b, b_idx)
18261826 }
18271827
1828+ /// Puts every placement the picks name into one group
1829+ /// ([`Project::group_all`]) -- the ctrl-click selection's own door, which
1830+ /// may name clips and captions alike. Metadata only like the pair above:
1831+ /// no reseek, one undo step, and the error says why when it refuses.
1832+ pub fn group_all(&mut self, picks: &[(Lane, usize)]) -> crate::Result<()> {
1833+ self.project.group_all(picks)
1834+ }
1835+
1836+ /// [`delete_clip`](Self::delete_clip) for the caption the pick named: a
1837+ /// caption in no group lifts exactly as [`lift_sub`](Self::lift_sub) lifts
1838+ /// it -- no reseek, because nothing that plays has changed -- and a caption
1839+ /// in a group takes the group with it, which ripples the media members and
1840+ /// reseeks like a delete. `false` for a bad index.
1841+ pub fn delete_sub(&mut self, lane: Lane, idx: usize) -> bool {
1842+ // Which of the two, asked before anything moves: the reseek a grouped
1843+ // delete owes is the whole difference between the paths.
1844+ let grouped = self
1845+ .project
1846+ .sub_lane(lane)
1847+ .get(idx)
1848+ .and_then(|s| s.link)
1849+ .is_some_and(|id| {
1850+ self.project
1851+ .lanes()
1852+ .into_iter()
1853+ .any(|l| l != lane && self.project.lane(l).iter().any(|c| c.link == Some(id)))
1854+ });
1855+ match grouped {
1856+ true => self.edit(Dirty::Both, |p| p.delete_sub_in(lane, idx)),
1857+ // A caption in no group -- or one grouped only with other captions,
1858+ // which lift and move nothing that plays -- is the lift it always
1859+ // was.
1860+ false => self.project.delete_sub_in(lane, idx),
1861+ }
1862+ }
1863+
18281864 /// What the clip at `idx` of `lane` is equalized with, or `None` for one
18291865 /// that plays flat -- what a card shows before it lets anyone drag a band.
18301866 pub fn eq_of(&self, lane: Lane, idx: usize) -> Option<&EqParams> {
crates/engine/src/project.rsmodified+1038 -348
@@ -561,6 +561,12 @@ pub struct SubClip {
561561 /// keeps it.
562562 pub in_us: i64,
563563 pub out_us: i64,
564+ /// Group id: `Some` exactly when a hand put this caption in a group with
565+ /// clips on other lanes ([`Project::group_all`]) -- a caption arrives in
566+ /// no group, and what a cut cuts apart loses the one it had
567+ /// ([`sub_open_room`], for [`Clip::link`]'s reason). Sharing an id with a
568+ /// clip is what makes the caption move, trim and delete with it.
569+ pub link: Option<u32>,
564570 }
565571
566572 impl SubClip {
@@ -634,6 +640,25 @@ impl LaneData {
634640 }
635641 }
636642
643+/// The placements one group id names, split by the two lists a lane holds:
644+/// what a drag, a trim and a delete each have to walk, now that a group may
645+/// hold a caption beside its clips ([`Project::group_all`]). A clip and a
646+/// caption of one group never share a lane -- a subtitle lane holds no `Clip`
647+/// -- so the pairs are `(lane storage index, index into that lane's list)`.
648+#[derive(Default)]
649+struct Members {
650+ clips: Vec<(usize, usize)>,
651+ subs: Vec<(usize, usize)>,
652+}
653+
654+impl Members {
655+ /// Whether the group is the one placement and no more: what a lift leaves
656+ /// behind, and what every whole-group question answers "not one" for.
657+ fn alone(&self) -> bool {
658+ self.clips.len() + self.subs.len() < 2
659+ }
660+}
661+
637662 /// Which end of a clip a [`Project::trim`] moves: the one the pointer grabbed.
638663 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
639664 pub enum Edge {
@@ -1639,7 +1664,14 @@ impl Project {
16391664 )
16401665 .into());
16411666 }
1642- let sub = SubClip { start: at, ..sub };
1667+ // The placement belongs to no group, for [`place`]'s reason: a caption
1668+ // dragged out of the palette arrives alone, and grouping it with what
1669+ // is under it is a hand's decision ([`Project::group_all`]).
1670+ let sub = SubClip {
1671+ start: at,
1672+ link: None,
1673+ ..sub
1674+ };
16431675 if at.checked_add(sub.frames).is_none() {
16441676 return Err(format!("a placement at frame {at} runs past the last frame there is").into());
16451677 }
@@ -1667,11 +1699,16 @@ impl Project {
16671699 }
16681700
16691701 /// Move the subtitle at `idx` of `from` onto `to` with its head at `start`
1670- /// -- [`move_clip`](Project::move_clip)'s twin, and refusing an overlap
1671- /// where that one clamps to it, for [`place_sub`](Project::place_sub)'s
1672- /// reason: there is no group to hold a subtitle still and no picture under
1673- /// it that a landing would hide, so "as far as it goes" would silently be a
1674- /// frame nobody named.
1702+ /// -- [`move_clip`](Project::move_clip)'s twin. A caption in no group is
1703+ /// refused an overlap where that one clamps to it, for
1704+ /// [`place_sub`](Project::place_sub)'s reason: there is no group to hold it
1705+ /// still and no picture under it that a landing would hide, so "as far as
1706+ /// it goes" would silently be a frame nobody named.
1707+ ///
1708+ /// A caption *in* a group drags the group: one delta for every member --
1709+ /// its clips and its other captions -- clamped to the room each of them
1710+ /// has, exactly as a clip's drag always has. That is the point of putting
1711+ /// a caption in a group: the words go where the picture goes.
16751712 ///
16761713 /// The window travels untouched: a caption dragged later says the same
16771714 /// words later, exactly as a clip dragged later plays the same pictures
@@ -1679,9 +1716,10 @@ impl Project {
16791716 ///
16801717 /// One undo step on success; nothing changed and no step on a refusal --
16811718 /// an index that is not there, a lane that is not a subtitle lane or is not
1682- /// there, and an overlap. A drop that changes neither lane nor frame is
1683- /// `Ok` and no step: a hand that picked a caption up and put it back has
1684- /// done nothing wrong, and a front-end showing every `Err` would say so.
1719+ /// there, and (for a caption in no group) an overlap. A drop that changes
1720+ /// neither lane nor frame is `Ok` and no step: a hand that picked a caption
1721+ /// up and put it back has done nothing wrong, and a front-end showing every
1722+ /// `Err` would say so.
16851723 pub fn move_sub(&mut self, from: Lane, idx: usize, to: Lane, start: u32) -> crate::Result<()> {
16861724 let Some(sub) = self.sub_lane(from).get(idx).copied() else {
16871725 return Err(format!("there is no subtitle {idx} on {}", from.label()).into());
@@ -1707,6 +1745,51 @@ impl Project {
17071745 format!("a placement at frame {start} runs past the last frame there is").into(),
17081746 );
17091747 }
1748+ // A grouped caption carries its group, clamped to the room the whole
1749+ // group has rather than refused ([`Project::move_room]) -- one drag, one
1750+ // delta, one undo step.
1751+ let members = self.group_of(from, idx).expect("the subtitle was found");
1752+ if !members.alone() {
1753+ if members
1754+ .subs
1755+ .iter()
1756+ .any(|&(l, i)| l == dest && (l, i) != (here, idx))
1757+ {
1758+ return Err(format!(
1759+ "a group is one caption per track: {} already carries this group",
1760+ to.label()
1761+ )
1762+ .into());
1763+ }
1764+ let want = i64::from(start) - i64::from(sub.start);
1765+ let Some((lo, hi)) = self.move_room(&members, Some((here, idx, dest, start))) else {
1766+ return Err(format!(
1767+ "another placement already covers those frames on {}",
1768+ to.label()
1769+ )
1770+ .into());
1771+ };
1772+ let delta = want.clamp(lo, hi);
1773+ self.snapshot();
1774+ for &(l, i) in &members.clips {
1775+ let c = &mut self.lanes[l].clips[i];
1776+ c.start = (i64::from(c.start) + delta) as u32;
1777+ }
1778+ for &(l, i) in &members.subs {
1779+ let s = &mut self.lanes[l].subs[i];
1780+ s.start = (i64::from(s.start) + delta) as u32;
1781+ }
1782+ let moved = self.lanes[here].subs.remove(idx);
1783+ let subs = &mut self.lanes[dest].subs;
1784+ let at = subs.partition_point(|o| o.start < moved.start);
1785+ subs.insert(at, moved);
1786+ debug_assert!(subs_sorted_disjoint(subs));
1787+ debug_assert!(members
1788+ .clips
1789+ .iter()
1790+ .all(|&(l, _)| sorted_disjoint(&self.lanes[l].clips)));
1791+ return Ok(());
1792+ }
17101793 let moved = SubClip { start, ..sub };
17111794 if let Some(other) = self.lanes[dest]
17121795 .subs
@@ -1790,6 +1873,7 @@ impl Project {
17901873 return Ok(());
17911874 }
17921875 self.snapshot();
1876+ let members = self.group_of(lane, idx).expect("the subtitle was found");
17931877 let i = self.index(lane).expect("the subtitle was found on it");
17941878 let s = &mut self.lanes[i].subs[idx];
17951879 match edge {
@@ -1812,6 +1896,11 @@ impl Project {
18121896 }
18131897 debug_assert!(s.frames >= 1 && s.out_us > s.in_us && s.in_us >= 0);
18141898 debug_assert!(subs_sorted_disjoint(&self.lanes[i].subs));
1899+ // A caption in a group drags its group's edge with it, exactly as a
1900+ // clip's trim does: one delta, each member clamped to its own room.
1901+ // No source table to grow by, which only tightens how far a member may
1902+ // follow -- never whether it may.
1903+ self.follow_group(&members, &(i, idx), edge, i64::from(to) - i64::from(at), &[]);
18151904 Ok(())
18161905 }
18171906
@@ -2107,8 +2196,9 @@ impl Project {
21072196 return Err(format!("there is no clip {idx} on {}", lane.label()).into());
21082197 };
21092198 let labels = handles(&self.lanes);
2110- let mut span: Option<(Lane, u32, u32)> = None;
2111- for &(l, i) in &members {
2199+ // Media members only: a caption has no rate to change, and what the
2200+ // id binds it to -- a move, a trim, a delete -- travels by frames.
2201+ for &(l, i) in &members.clips {
21122202 let clips = &self.lanes[l].clips;
21132203 let mut moved = clips[i];
21142204 moved.speed = speed;
@@ -2124,34 +2214,11 @@ impl Project {
21242214 )
21252215 .into());
21262216 }
2127- // A link is **one span on however many lanes**
2128- // ([`links_are_consistent`]), and one rate over two halves does not
2129- // guarantee that: two clips of *different source lengths* can occupy
2130- // the same timeline frames at their old rates (rounding collapses
2131- // neighbouring lengths onto one footprint at 4x), and re-rating them
2132- // pulls those footprints apart. Refused by name rather than written
2133- // -- a group whose halves disagree about their span is a project
2134- // that would not load again.
2135- match span {
2136- None => span = Some((labels[l], moved.start, moved.end())),
2137- Some((first, start, end)) if (start, end) != (moved.start, moved.end()) => {
2138- return Err(format!(
2139- "at {speed} the {} half would cover [{}, {}) and the {} half [{start}, {end}): \
2140- they are one take and a take is one span -- detach them first",
2141- labels[l].label(),
2142- moved.start,
2143- moved.end(),
2144- first.label()
2145- )
2146- .into());
2147- }
2148- Some(_) => {}
2149- }
21502217 }
21512218 if snapshot {
21522219 self.snapshot();
21532220 }
2154- for (l, i) in members {
2221+ for (l, i) in members.clips {
21552222 self.lanes[l].clips[i].speed = speed;
21562223 debug_assert!(sorted_disjoint(&self.lanes[l].clips));
21572224 }
@@ -2507,6 +2574,24 @@ impl Project {
25072574 on.contains(&i) && l.subs.iter().any(|s| s.start < timeline_frame && timeline_frame < s.end())
25082575 })
25092576 .collect();
2577+ // The links the captions carry, read before the room is opened below
2578+ // -- `sub_open_room` takes the id off both halves, exactly as
2579+ // `open_room` does for a clip, and the split hands the halves theirs
2580+ // back afterwards.
2581+ let sub_orig: Vec<Option<u32>> = self
2582+ .lanes
2583+ .iter()
2584+ .zip(&cut_subs)
2585+ .map(|(l, &cut)| {
2586+ cut.then(|| {
2587+ l.subs
2588+ .iter()
2589+ .find(|s| s.start < timeline_frame && timeline_frame < s.end())
2590+ .and_then(|s| s.link)
2591+ })
2592+ .flatten()
2593+ })
2594+ .collect();
25102595 if cut.iter().all(Option::is_none) && !cut_subs.contains(&true) {
25112596 return false;
25122597 }
@@ -2524,22 +2609,42 @@ impl Project {
25242609 sub_open_room(&mut data.subs, timeline_frame, 0);
25252610 debug_assert!(subs_sorted_disjoint(&data.subs));
25262611 }
2527- // Each side is its own question: two clips may start together and end
2528- // apart, and every lane whose halves do line up stays one take.
2529- let starts: Vec<Option<u32>> = cut.iter().map(|c| c.map(|c| c.start)).collect();
2530- let ends: Vec<Option<u32>> = cut.iter().map(|c| c.map(|c| c.end())).collect();
2531- let left = self.group_ids(&starts);
2532- let right = self.group_ids(&ends);
2533- for (((data, left), right), cut) in self
2534- .lanes
2535- .iter_mut()
2536- .zip(left)
2537- .zip(right)
2538- .zip(cut.iter().map(Option::is_some))
2539- {
2612+ // Each side is its own question, and the answer is the group the clip
2613+ // already carried: the left half *keeps* its take's id -- the take the
2614+ // frames before the cut still are -- and the right halves of one take
2615+ // share one fresh id of their own, clips and captions alike. A lane
2616+ // holding no group (a `place`ment, a caption nobody grouped) comes out
2617+ // of the cut holding none, which is what it went in with. The captions'
2618+ // own links were drawn above, before the room opened.
2619+ let orig: Vec<Option<u32>> = cut.iter().map(|c| c.and_then(|c| c.link)).collect();
2620+ let mut distinct: Vec<u32> = Vec::new();
2621+ for id in orig.iter().chain(&sub_orig).flatten() {
2622+ if !distinct.contains(id) {
2623+ distinct.push(*id);
2624+ }
2625+ }
2626+ let fresh: Vec<u32> = (0..distinct.len()).map(|_| self.new_link()).collect();
2627+ let right_of =
2628+ |link: Option<u32>| link.and_then(|id| distinct.iter().position(|&d| d == id)).map(|at| fresh[at]);
2629+ for (l, data) in self.lanes.iter_mut().enumerate() {
2630+ if !cut_subs[l] {
2631+ continue;
2632+ }
2633+ // The pair the razor just made: they touch at the frame it cut.
2634+ if let Some(idx) = data
2635+ .subs
2636+ .iter()
2637+ .position(|s| s.end() == timeline_frame)
2638+ .filter(|&idx| data.subs.get(idx + 1).is_some_and(|n| n.start == timeline_frame))
2639+ {
2640+ data.subs[idx].link = sub_orig[l];
2641+ data.subs[idx + 1].link = right_of(sub_orig[l]);
2642+ }
2643+ }
2644+ for (data_i, data) in self.lanes.iter_mut().enumerate() {
25402645 // The lanes this call was not scoped to are not cut, whatever their
25412646 // own clips would allow.
2542- let Some(idx) = splittable(&data.clips, timeline_frame).filter(|_| cut) else {
2647+ let Some(idx) = splittable(&data.clips, timeline_frame).filter(|_| cut[data_i].is_some()) else {
25432648 continue;
25442649 };
25452650 let mut tail = data.clips[idx];
@@ -2549,9 +2654,9 @@ impl Project {
25492654 // the two would not add up to the one being cut.
25502655 tail.in_frame = split_source(&tail, timeline_frame).expect("splittable said so");
25512656 tail.start = timeline_frame;
2552- tail.link = right;
2657+ tail.link = right_of(orig[data_i]);
25532658 data.clips[idx].out_frame = tail.in_frame;
2554- data.clips[idx].link = left;
2659+ data.clips[idx].link = orig[data_i];
25552660 data.clips.insert(idx + 1, tail);
25562661 }
25572662 true
@@ -2562,9 +2667,9 @@ impl Project {
25622667 /// Only what a split could have produced is rejoined -- the two sides must
25632668 /// touch on the timeline *and* be consecutive frames of the same source --
25642669 /// so the clip list comes back exactly as it was and traversal with it.
2565- /// `false` when no lane has such a pair. The rejoined clips share one id
2566- /// only when they rejoin into the same span, for [`split`](Project::split)'s
2567- /// reason.
2670+ /// `false` when no lane has such a pair. The rejoined placement keeps the
2671+ /// **left** half's id, which is the take the split left on it: rejoining a
2672+ /// cut take puts the take back, id and all.
25682673 pub fn regroup(&mut self, timeline_frame: u32) -> bool {
25692674 // What each lane would end up covering, if it joins here at all.
25702675 let joined: Vec<Option<(u32, u32)>> = self
@@ -2585,8 +2690,7 @@ impl Project {
25852690 return false;
25862691 }
25872692 self.snapshot();
2588- let ids = self.group_ids(&joined);
2589- for ((data, link), sub) in self.lanes.iter_mut().zip(ids).zip(join_subs) {
2693+ for (data, sub) in self.lanes.iter_mut().zip(join_subs) {
25902694 if let Some(idx) = sub {
25912695 data.subs[idx].frames += data.subs[idx + 1].frames;
25922696 data.subs[idx].out_us = data.subs[idx + 1].out_us;
@@ -2597,16 +2701,17 @@ impl Project {
25972701 continue;
25982702 };
25992703 data.clips[idx].out_frame = data.clips[idx + 1].out_frame;
2600- data.clips[idx].link = link;
26012704 data.clips.remove(idx + 1);
26022705 }
26032706 true
26042707 }
26052708
2606- /// Take the clip at `idx` of `lane` out of its group: every clip carrying
2607- /// its id -- on however many lanes -- is handed an id of its own, so from
2608- /// here on each half moves, trims and is deleted alone. The music video
2609- /// whose sound is to be cut against its picture starts here.
2709+ /// Take the placement at `idx` of `lane` out of its group: every clip and
2710+ /// every caption carrying its id -- on however many lanes -- is handed an
2711+ /// id of its own, so from here on each half moves, trims and is deleted
2712+ /// alone. The music video whose sound is to be cut against its picture
2713+ /// starts here, and so does the caption that has to come off the picture it
2714+ /// was pinned to.
26102715 ///
26112716 /// An id of its own rather than none at all: a half no other lane is grouped
26122717 /// with is exactly what a [`lift`](Project::lift) leaves behind and is legal
@@ -2617,30 +2722,36 @@ impl Project {
26172722 /// Metadata only, like a [`split`](Project::split): no mapping changes, so
26182723 /// nothing has to be reseeked. One snapshot, so one [`Project::undo`] puts
26192724 /// the group back. Refused (`false`, nothing changed) for an index that is
2620- /// not there, a clip in no group at all, and one whose group has no other
2621- /// half -- that one is already detached, and a refusal must not cost an undo
2622- /// step.
2725+ /// not there, a placement in no group at all, and one whose group has no
2726+ /// other half -- that one is already detached, and a refusal must not cost
2727+ /// an undo step.
26232728 pub fn ungroup(&mut self, lane: Lane, idx: usize) -> bool {
2624- let Some(id) = self.lane(lane).get(idx).and_then(|c| c.link) else {
2729+ let Some(members) = self.group_of(lane, idx) else {
26252730 return false;
26262731 };
2627- let members = self
2628- .lanes
2629- .iter()
2630- .flat_map(|l| &l.clips)
2631- .filter(|c| c.link == Some(id))
2632- .count();
2633- if members < 2 {
2732+ if members.alone() {
26342733 return false;
26352734 }
2735+ let Some(id) = self
2736+ .lane(lane)
2737+ .get(idx)
2738+ .and_then(|c| c.link)
2739+ .or_else(|| self.sub_lane(lane).get(idx).and_then(|s| s.link))
2740+ else {
2741+ return false;
2742+ };
26362743 self.snapshot();
26372744 // Drawn before the walk: `new_link` takes the whole project, and the
26382745 // walk holds the lanes.
2639- let mut fresh = (0..members).map(|_| self.new_link()).collect::<Vec<_>>();
2746+ let count = members.clips.len() + members.subs.len();
2747+ let mut fresh = (0..count).map(|_| self.new_link()).collect::<Vec<_>>();
26402748 for data in &mut self.lanes {
26412749 for c in data.clips.iter_mut().filter(|c| c.link == Some(id)) {
26422750 c.link = fresh.pop();
26432751 }
2752+ for s in data.subs.iter_mut().filter(|s| s.link == Some(id)) {
2753+ s.link = fresh.pop();
2754+ }
26442755 }
26452756 debug_assert!(links_are_consistent(&self.lanes).is_ok());
26462757 true
@@ -2712,6 +2823,103 @@ impl Project {
27122823 Ok(())
27132824 }
27142825
2826+ /// Put every placement the picks name into one group -- the group a hand
2827+ /// builds with ctrl-click and a menu: the picture, its sound and the
2828+ /// caption over it, on as many lanes as the picks name. What any of them
2829+ /// was already grouped with rides along (one group, not two sharing a
2830+ /// member), and the members keep their own spans: a group is one id over
2831+ /// one placement per lane, and the offsets between them are what the group
2832+ /// preserves -- a drag, a trim and a delete all move the members *by the
2833+ /// same distance*, not to the same frames.
2834+ ///
2835+ /// No two picks may name one lane -- that is the one clip-per-lane rule,
2836+ /// and the refusal says which lane -- and a pick that names nothing is
2837+ /// refused with its own words. At least two picks, or there is nothing to
2838+ /// group.
2839+ ///
2840+ /// Metadata only, one snapshot, so one [`Project::undo`] takes the group
2841+ /// apart again. None of the refusals changes anything or costs an undo
2842+ /// step.
2843+ pub fn group_all(&mut self, picks: &[(Lane, usize)]) -> crate::Result<()> {
2844+ if picks.len() < 2 {
2845+ return Err("a group is two placements or more: pick another one first".into());
2846+ }
2847+ let mut seen: Vec<Lane> = Vec::with_capacity(picks.len());
2848+ for &(lane, idx) in picks {
2849+ if seen.contains(&lane) {
2850+ return Err(format!(
2851+ "a group is one placement per lane: {} is picked twice -- keep one clip per \
2852+ track",
2853+ lane.label()
2854+ )
2855+ .into());
2856+ }
2857+ seen.push(lane);
2858+ let there = if lane.kind == LaneKind::Subtitle {
2859+ idx < self.sub_lane(lane).len()
2860+ } else {
2861+ idx < self.lane(lane).len()
2862+ };
2863+ if !there {
2864+ let what = if lane.kind == LaneKind::Subtitle {
2865+ "subtitle"
2866+ } else {
2867+ "clip"
2868+ };
2869+ return Err(
2870+ format!("there is no {what} {idx} on {}", lane.label()).into()
2871+ );
2872+ }
2873+ }
2874+ let links: Vec<Option<u32>> = picks
2875+ .iter()
2876+ .map(|&(lane, idx)| {
2877+ if lane.kind == LaneKind::Subtitle {
2878+ self.sub_lane(lane)[idx].link
2879+ } else {
2880+ self.lane(lane)[idx].link
2881+ }
2882+ })
2883+ .collect();
2884+ self.snapshot();
2885+ let id = self.new_link();
2886+ // Whatever any pick was grouped with comes along, for [`group`]'s
2887+ // reason -- one id over the lot, not two groups sharing a member.
2888+ for data in &mut self.lanes {
2889+ for c in data.clips.iter_mut() {
2890+ if c.link.is_some() && links.contains(&c.link) {
2891+ c.link = Some(id);
2892+ }
2893+ }
2894+ for s in data.subs.iter_mut() {
2895+ if s.link.is_some() && links.contains(&s.link) {
2896+ s.link = Some(id);
2897+ }
2898+ }
2899+ }
2900+ // And the picks themselves, which a `place` may have left in no group.
2901+ // The lane seats are read before the walk, which holds the lanes.
2902+ let seats: Vec<(usize, bool)> = picks
2903+ .iter()
2904+ .map(|&(lane, _)| {
2905+ (
2906+ self.index(lane).expect("checked above"),
2907+ lane.kind == LaneKind::Subtitle,
2908+ )
2909+ })
2910+ .collect();
2911+ for (&(lane, idx), &(at, sub)) in picks.iter().zip(&seats) {
2912+ let _ = lane;
2913+ if sub {
2914+ self.lanes[at].subs[idx].link = Some(id);
2915+ } else {
2916+ self.lanes[at].clips[idx].link = Some(id);
2917+ }
2918+ }
2919+ debug_assert!(links_are_consistent(&self.lanes).is_ok());
2920+ Ok(())
2921+ }
2922+
27152923 /// Place `clip` in one lane at `timeline_frame`, overwriting whatever it
27162924 /// lands on and leaving every other clip exactly where it is -- the
27172925 /// per-lane paste. Anything already there is trimmed away (and split in two
@@ -2841,40 +3049,23 @@ impl Project {
28413049 // is the one thing a link may never mean. Refused rather than clamped:
28423050 // the partner moves the same distance, so there is no room for it
28433051 // anywhere on that lane.
2844- if dest != held && members.iter().any(|&(l, _)| l == dest) {
3052+ if dest != held
3053+ && members
3054+ .clips
3055+ .iter()
3056+ .chain(&members.subs)
3057+ .any(|&(l, _)| l == dest)
3058+ {
28453059 return false;
28463060 }
28473061 let want = i64::from(start) - i64::from(clip.start);
28483062 // How far the group may travel, in timeline frames and signed: every
2849- // member narrows it to the gap it is landing in, and what is left is
2850- // what the pointer is clamped to.
2851- let (mut lo, mut hi) = (i64::MIN, i64::MAX);
2852- for &(l, i) in &members {
2853- let c = self.lanes[l].clips[i];
2854- let land = if (l, i) == (held, idx) { dest } else { l };
2855- // Which gap this member's walls are read off: its own place on the
2856- // lane it stays on, and the frame the pointer named on the lane it
2857- // is let go over.
2858- let at = if land == l { c.start } else { start };
2859- let (mut wall_lo, mut wall_hi) = (0, u32::MAX);
2860- for (j, other) in self.lanes[land].clips.iter().enumerate() {
2861- if members.contains(&(land, j)) {
2862- continue;
2863- }
2864- if other.start <= at && at < other.end() {
2865- return false;
2866- }
2867- match other.end() <= at {
2868- true => wall_lo = wall_lo.max(other.end()),
2869- false => wall_hi = wall_hi.min(other.start),
2870- }
2871- }
2872- if wall_hi - wall_lo < c.frames() {
2873- return false;
2874- }
2875- lo = lo.max(i64::from(wall_lo) - i64::from(c.start));
2876- hi = hi.min(i64::from(wall_hi - c.frames()) - i64::from(c.start));
2877- }
3063+ // member -- the clips and any caption grouped with them -- narrows it
3064+ // to the gap it is landing in, and what is left is what the pointer is
3065+ // clamped to.
3066+ let Some((lo, hi)) = self.move_room(&members, Some((held, idx, dest, start))) else {
3067+ return false;
3068+ };
28783069 if lo > hi {
28793070 return false;
28803071 }
@@ -2883,11 +3074,15 @@ impl Project {
28833074 return false;
28843075 }
28853076 self.snapshot();
2886- for &(l, i) in &members {
3077+ for &(l, i) in &members.clips {
28873078 let c = &mut self.lanes[l].clips[i];
28883079 // In range by the walls above, which are `u32` frames throughout.
28893080 c.start = (i64::from(c.start) + delta) as u32;
28903081 }
3082+ for &(l, i) in &members.subs {
3083+ let s = &mut self.lanes[l].subs[i];
3084+ s.start = (i64::from(s.start) + delta) as u32;
3085+ }
28913086 if dest != held {
28923087 let clip = self.lanes[held].clips.remove(idx);
28933088 let clips = &mut self.lanes[dest].clips;
@@ -2895,14 +3090,93 @@ impl Project {
28953090 clips.insert(at, clip);
28963091 }
28973092 debug_assert!(sorted_disjoint(&self.lanes[dest].clips));
2898- debug_assert!(
2899- members
2900- .iter()
2901- .all(|&(l, _)| sorted_disjoint(&self.lanes[l].clips))
2902- );
3093+ debug_assert!(members
3094+ .clips
3095+ .iter()
3096+ .chain(&members.subs)
3097+ .all(|&(l, _)| {
3098+ sorted_disjoint(&self.lanes[l].clips) && subs_sorted_disjoint(&self.lanes[l].subs)
3099+ }));
29033100 true
29043101 }
29053102
3103+ /// How far a group drag may travel, `(least, most)` in timeline frames and
3104+ /// signed: every member narrows the range to the gap it is landing in --
3105+ /// the clips against their lanes' clips and the captions against their
3106+ /// lanes' captions -- and what is left is what the pointer is clamped to.
3107+ /// `travelling` names the one member that changes lane, if any: the clip a
3108+ /// hand is carrying onto another track, whose walls are read on the lane it
3109+ /// is let go over at the frame the pointer named. `None` when a member has
3110+ /// no gap to land in at all.
3111+ fn move_room(
3112+ &self,
3113+ members: &Members,
3114+ travelling: Option<(usize, usize, usize, u32)>,
3115+ ) -> Option<(i64, i64)> {
3116+ let (mut lo, mut hi) = (i64::MIN, i64::MAX);
3117+ for &(l, i) in members.clips.iter().chain(&members.subs) {
3118+ let sub = members.subs.contains(&(l, i));
3119+ let (start, frames) = match self.lanes[l]
3120+ .clips
3121+ .get(i)
3122+ .filter(|_| !sub)
3123+ .map(|c| (c.start, c.frames()))
3124+ {
3125+ Some(pair) => pair,
3126+ None => {
3127+ let s = self.lanes[l].subs.get(i)?;
3128+ (s.start, s.frames)
3129+ }
3130+ };
3131+ let land = travelling
3132+ .filter(|&(fl, fi, ..)| (fl, fi) == (l, i))
3133+ .map_or(l, |(_, _, dest, _)| dest);
3134+ // Which gap this member's walls are read off: its own place on the
3135+ // lane it stays on, and the frame the pointer named on the lane it
3136+ // is let go over. A clip's neighbours are the clips of the lane it
3137+ // lands on and a caption's are its captions -- the two lists of one
3138+ // lane never meet.
3139+ let at = match travelling {
3140+ Some((fl, fi, _, asked)) if (fl, fi) == (l, i) && land != l => asked,
3141+ _ => start,
3142+ };
3143+ let (mut wall_lo, mut wall_hi) = (0, u32::MAX);
3144+ let neighbours: Vec<(u32, u32)> = if sub {
3145+ self.lanes[land]
3146+ .subs
3147+ .iter()
3148+ .map(|s| (s.start, s.end()))
3149+ .collect()
3150+ } else {
3151+ self.lanes[land]
3152+ .clips
3153+ .iter()
3154+ .map(|c| (c.start, c.end()))
3155+ .collect()
3156+ };
3157+ for (j, (other_start, other_end)) in neighbours.iter().enumerate() {
3158+ if members.clips.contains(&(land, j)) || members.subs.contains(&(land, j)) {
3159+ continue;
3160+ }
3161+ if *other_start <= at && at < *other_end {
3162+ // A head let go inside another placement, which a clamp
3163+ // has no answer for: the drop is refused.
3164+ return None;
3165+ }
3166+ match other_end <= &at {
3167+ true => wall_lo = wall_lo.max(*other_end),
3168+ false => wall_hi = wall_hi.min(*other_start),
3169+ }
3170+ }
3171+ if wall_hi - wall_lo < frames {
3172+ return None;
3173+ }
3174+ lo = lo.max(i64::from(wall_lo) - i64::from(start));
3175+ hi = hi.min(i64::from(wall_hi - frames) - i64::from(start));
3176+ }
3177+ Some((lo, hi))
3178+ }
3179+
29063180 /// Move one `edge` of the clip at `idx` of `lane` to timeline frame `to` --
29073181 /// the drag on a clip's end that makes it play more or less of its source.
29083182 /// The rest of the lane stays exactly where it is (nothing ripples), so what
@@ -2926,10 +3200,10 @@ impl Project {
29263200 /// `PlaybackSession::trim_clip`, which fills it in). A source with no entry
29273201 /// there may not grow at all.
29283202 ///
2929- /// Linked clips trim *together*, to one clamped edge: a link is one span on
2930- /// however many lanes ([`links_are_consistent`]), so a picture trimmed away
2931- /// from its sound would be a group no save could load. The room is therefore
2932- /// what every member of the group has -- the tightest wall wins.
3203+ /// Linked placements trim *together*, by one delta: every member's same
3204+ /// edge moves the distance the dragged one did, clamped to the room its
3205+ /// own walls leave -- offsets between the members of a hand-built group
3206+ /// survive the trim, exactly as they survive a drag.
29333207 ///
29343208 /// `false`, changing nothing and costing no undo step, for an index that is
29353209 /// not there and for an edge that is already where it was asked to go.
@@ -2956,64 +3230,130 @@ impl Project {
29563230 return false;
29573231 }
29583232 // Worked out before anything moves: at a slow rate a room can be too
2959- // narrow to hold even one source frame ([`Speed::fit`]), and a member
2960- // that cannot fit must refuse the whole gesture rather than be given a
2961- // range wider than its room -- which is the overlap the lane invariant
2962- // exists to forbid. The walls below leave that room, so this is the
2963- // backstop for a project that came in through another door.
3233+ // narrow to hold even one source frame ([`Speed::fit`]), and the
3234+ // dragged clip refusing to fit must refuse the whole gesture rather
3235+ // than be given a range wider than its room -- which is the overlap
3236+ // the lane invariant exists to forbid. The walls below leave that room,
3237+ // so this is the backstop for a project that came in through another
3238+ // door.
3239+ let room = match edge {
3240+ // The frames that stay play what they played, so what survives is
3241+ // measured from the *end*.
3242+ Edge::Start => clip.end() - to,
3243+ Edge::End => to - clip.start,
3244+ };
3245+ let Some(keep) = clip.speed.fit(room) else {
3246+ return false;
3247+ };
29643248 let members = self.group_of(lane, idx).expect("checked above");
2965- let mut fitted = Vec::with_capacity(members.len());
2966- for &(l, i) in &members {
3249+ self.snapshot();
3250+ let still = self.is_still(&clip);
3251+ let held = self.index(lane).expect("checked above");
3252+ let c = &mut self.lanes[held].clips[idx];
3253+ match edge {
3254+ // A still has no earlier frame to walk an in-point back to --
3255+ // every frame of it is the same picture -- so its head grows
3256+ // *forward*: the range it plays is however long the new room is,
3257+ // anchored at the source's frame 0. Bounded by `lo`, which is where
3258+ // the cap in `source_frames` is applied.
3259+ Edge::Start if still => {
3260+ c.in_frame = 0;
3261+ c.out_frame = keep;
3262+ c.start = to;
3263+ }
3264+ Edge::Start => {
3265+ // Non-negative by `lo`, which is what keeps the in-point on the
3266+ // source.
3267+ c.in_frame = c.out_frame - keep.min(c.out_frame);
3268+ c.start = to;
3269+ }
3270+ // Never wider than the room the edge was clamped to: see
3271+ // [`Speed::fit`].
3272+ Edge::End => c.out_frame = c.in_frame + keep,
3273+ }
3274+ debug_assert!(sorted_disjoint(&self.lanes[held].clips));
3275+ self.follow_group(&members, &(held, idx), edge, i64::from(to) - i64::from(at), source_frames);
3276+ true
3277+ }
3278+
3279+ /// The rest of a group after one member's `edge` has moved by `delta`:
3280+ /// every other member's same edge moves the same distance, clamped to the
3281+ /// room its own walls leave -- a clip's against its lane and its source,
3282+ /// a caption's against its own lane, its window following by the
3283+ /// placement's own proportion. The undo step is the caller's: this is the
3284+ // second half of one edit, not an edit of its own.
3285+ fn follow_group(
3286+ &mut self,
3287+ members: &Members,
3288+ dragged: &(usize, usize),
3289+ edge: Edge,
3290+ delta: i64,
3291+ source_frames: &[u32],
3292+ ) {
3293+ for &(l, i) in &members.clips {
3294+ if (l, i) == *dragged {
3295+ continue;
3296+ }
29673297 let c = self.lanes[l].clips[i];
3298+ let at = match edge {
3299+ Edge::Start => c.start,
3300+ Edge::End => c.end(),
3301+ };
3302+ let (lo, hi) = self.clip_room(l, i, edge, source_frames);
3303+ let to = (i64::from(at) + delta).clamp(i64::from(lo), i64::from(hi)) as u32;
3304+ if to == at {
3305+ continue;
3306+ }
29683307 let room = match edge {
2969- // The frames that stay play what they played, so what survives
2970- // is measured from the *end*.
29713308 Edge::Start => c.end() - to,
29723309 Edge::End => to - c.start,
29733310 };
2974- match c.speed.fit(room) {
2975- // Not clamped to the clip's current length: an out-point trim
2976- // *grows* the range, and the source wall in `hi` is what bounds
2977- // that. The in-point's own clamp is at the write below.
2978- Some(keep) => fitted.push(keep),
2979- None => return false,
2980- }
2981- }
2982- self.snapshot();
2983- for (&(l, i), keep) in members.iter().zip(fitted) {
3311+ let Some(keep) = c.speed.fit(room) else {
3312+ continue;
3313+ };
29843314 let still = self.is_still(&self.lanes[l].clips[i]);
29853315 let c = &mut self.lanes[l].clips[i];
29863316 match edge {
2987- // A still has no earlier frame to walk an in-point back to --
2988- // every frame of it is the same picture -- so its head grows
2989- // *forward*: the range it plays is however long the new room
2990- // is, anchored at the source's frame 0. Bounded by `lo`, which
2991- // is where the cap in `source_frames` is applied.
29923317 Edge::Start if still => {
29933318 c.in_frame = 0;
29943319 c.out_frame = keep;
29953320 c.start = to;
29963321 }
29973322 Edge::Start => {
2998- // Non-negative by `lo`, which is what keeps the in-point on
2999- // the source.
30003323 c.in_frame = c.out_frame - keep.min(c.out_frame);
30013324 c.start = to;
30023325 }
3003- // Never wider than the room the edge was clamped to: see
3004- // [`Speed::fit`].
30053326 Edge::End => c.out_frame = c.in_frame + keep,
30063327 }
30073328 debug_assert!(sorted_disjoint(&self.lanes[l].clips));
30083329 }
3009- true
3330+ for &(l, i) in &members.subs {
3331+ if (l, i) == *dragged {
3332+ continue;
3333+ }
3334+ let s = self.lanes[l].subs[i];
3335+ let at = match edge {
3336+ Edge::Start => s.start,
3337+ Edge::End => s.end(),
3338+ };
3339+ let (lo, hi) = sub_edge_room(&self.lanes[l].subs, i, edge);
3340+ let to = (i64::from(at) + delta).clamp(i64::from(lo), i64::from(hi)) as u32;
3341+ if to == at {
3342+ continue;
3343+ }
3344+ write_sub_edge(&mut self.lanes[l].subs[i], edge, to);
3345+ debug_assert!(subs_sorted_disjoint(&self.lanes[l].subs));
3346+ }
30103347 }
30113348
30123349 /// How far that edge may travel, `(first, last)` timeline frame inclusive --
30133350 /// the walls [`trim`](Project::trim) clamps to, without moving anything.
30143351 /// What a front-end drawing the box *during* a drag asks, so the live width
30153352 /// is the width the release will commit and an edge stops under the pointer
3016- /// rather than snapping back. `None` for an index that is not there.
3353+ /// rather than snapping back. The **clip's own** walls: the rest of its
3354+ /// group follows by the same delta within their own ([`follow_group`]), so
3355+ /// what is drawn for the dragged edge is what its own clip will commit.
3356+ /// `None` for an index that is not there.
30173357 pub fn trim_room(
30183358 &self,
30193359 lane: Lane,
@@ -3021,71 +3361,80 @@ impl Project {
30213361 edge: Edge,
30223362 source_frames: &[u32],
30233363 ) -> Option<(u32, u32)> {
3024- let (mut lo, mut hi) = (u32::MIN, u32::MAX);
3025- for (l, i) in self.group_of(lane, idx)? {
3026- let clips = &self.lanes[l].clips;
3027- let c = clips[i];
3028- let (member_lo, member_hi) = match edge {
3029- Edge::Start => (
3030- // Back to the source's own first frame -- as many *timeline*
3031- // frames as that head is worth at the clip's rate, which at
3032- // real time is the head itself -- and never over the clip in
3033- // front of it. Saturating because a clip may hold *more*
3034- // head than the timeline has room for -- a ripple delete
3035- // slides a clip back to frame 0 with its in-point wherever
3036- // the cut left it -- and frame 0 is the other wall.
3037- //
3038- // A still is measured from its *tail* instead: it has no
3039- // in-point worth the name (every frame the same picture), so
3040- // its head reaches exactly as far as its tail does -- out to
3041- // the length the caller's table gives it, whole. Measured
3042- // from the in-point it would have no head room at all, which
3043- // is a placed picture whose left edge cannot be dragged out.
3044- // No entry in the table means no growth, as it does at the
3045- // other end.
3046- if self.is_still(&c) {
3047- c.end().saturating_sub(
3048- c.speed
3049- .room(source_frames.get(c.source).copied().unwrap_or(c.len())),
3050- )
3051- } else {
3052- c.start.saturating_sub(c.speed.room(c.in_frame))
3053- }
3054- .max(i.checked_sub(1).map_or(0, |p| clips[p].end())),
3055- // One *frame of clip* always survives, and at a rate below
3056- // real time one frame of clip is several frames of timeline
3057- // ([`Speed::room`]): an edge dragged closer than that would
3058- // ask for a range no source frame fits in. At real time this
3059- // is `end - 1`, unchanged.
3060- c.end() - c.speed.room(1),
3061- ),
3062- Edge::End => (
3063- // ...and the same wall from the other end: the shortest this
3064- // clip can be is the room one source frame of it takes.
3065- c.start + c.speed.room(1),
3066- // Out to whatever is left of the source -- again in timeline
3067- // frames, at this clip's rate -- and never over the clip
3068- // behind it.
3069- c.start
3070- .saturating_add(
3071- c.speed.room(
3072- source_frames
3073- .get(c.source)
3074- .copied()
3075- .unwrap_or(c.out_frame)
3076- .saturating_sub(c.in_frame),
3077- ),
3078- )
3079- .min(clips.get(i + 1).map_or(u32::MAX, |n| n.start)),
3080- ),
3081- };
3082- lo = lo.max(member_lo);
3083- hi = hi.min(member_hi);
3084- }
3364+ let l = self.index(lane)?;
3365+ (idx < self.lanes[l].clips.len()).then(|| self.clip_room(l, idx, edge, source_frames))
3366+ }
3367+
3368+ /// [`trim_room`](Project::trim_room) for a clip the caller already holds by
3369+ /// its lane's storage index: the one wall computation, asked for the clip
3370+ /// itself and for each member a group trim carries.
3371+ fn clip_room(
3372+ &self,
3373+ l: usize,
3374+ i: usize,
3375+ edge: Edge,
3376+ source_frames: &[u32],
3377+ ) -> (u32, u32) {
3378+ let clips = &self.lanes[l].clips;
3379+ let c = clips[i];
3380+ let (lo, hi) = match edge {
3381+ Edge::Start => (
3382+ // Back to the source's own first frame -- as many *timeline*
3383+ // frames as that head is worth at the clip's rate, which at
3384+ // real time is the head itself -- and never over the clip in
3385+ // front of it. Saturating because a clip may hold *more*
3386+ // head than the timeline has room for -- a ripple delete
3387+ // slides a clip back to frame 0 with its in-point wherever
3388+ // the cut left it -- and frame 0 is the other wall.
3389+ //
3390+ // A still is measured from its *tail* instead: it has no
3391+ // in-point worth the name (every frame the same picture), so
3392+ // its head reaches exactly as far as its tail does -- out to
3393+ // the length the caller's table gives it, whole. Measured
3394+ // from the in-point it would have no head room at all, which
3395+ // is a placed picture whose left edge cannot be dragged out.
3396+ // No entry in the table means no growth, as it does at the
3397+ // other end.
3398+ if self.is_still(&c) {
3399+ c.end().saturating_sub(
3400+ c.speed
3401+ .room(source_frames.get(c.source).copied().unwrap_or(c.len())),
3402+ )
3403+ } else {
3404+ c.start.saturating_sub(c.speed.room(c.in_frame))
3405+ }
3406+ .max(i.checked_sub(1).map_or(0, |p| clips[p].end())),
3407+ // One *frame of clip* always survives, and at a rate below
3408+ // real time one frame of clip is several frames of timeline
3409+ // ([`Speed::room`]): an edge dragged closer than that would
3410+ // ask for a range no source frame fits in. At real time this
3411+ // is `end - 1`, unchanged.
3412+ c.end() - c.speed.room(1),
3413+ ),
3414+ Edge::End => (
3415+ // ...and the same wall from the other end: the shortest this
3416+ // clip can be is the room one source frame of it takes.
3417+ c.start + c.speed.room(1),
3418+ // Out to whatever is left of the source -- again in timeline
3419+ // frames, at this clip's rate -- and never over the clip
3420+ // behind it.
3421+ c.start
3422+ .saturating_add(
3423+ c.speed.room(
3424+ source_frames
3425+ .get(c.source)
3426+ .copied()
3427+ .unwrap_or(c.out_frame)
3428+ .saturating_sub(c.in_frame),
3429+ ),
3430+ )
3431+ .min(clips.get(i + 1).map_or(u32::MAX, |n| n.start)),
3432+ ),
3433+ };
30853434 // `hi.max(lo)`: for a clip the invariants hold for, the range always
30863435 // contains the edge's own place, and a caller's wrong `source_frames`
30873436 // must not become an empty range (or a panicking `clamp`) here.
3088- Some((lo, hi.max(lo)))
3437+ (lo, hi.max(lo))
30893438 }
30903439
30913440 /// Whether `clip` plays a still image ([`crate::is_image`]): a file whose
@@ -3098,22 +3447,38 @@ impl Project {
30983447 .is_some_and(|s| crate::is_image(&s.path))
30993448 }
31003449
3101- /// The clips that move as one with the clip at `idx` of `lane` -- itself and
3102- /// whatever carries its link on the other lanes -- as `(lane storage index,
3103- /// clip index)` pairs. `None` for an index that is not there.
3104- fn group_of(&self, lane: Lane, idx: usize) -> Option<Vec<(usize, usize)>> {
3105- let clip = *self.lane(lane).get(idx)?;
3106- Some(match clip.link {
3107- Some(link) => self
3108- .lanes
3109- .iter()
3110- .enumerate()
3111- .filter_map(|(l, data)| {
3112- Some((l, data.clips.iter().position(|c| c.link == Some(link))?))
3113- })
3114- .collect(),
3115- None => vec![(self.index(lane).expect("the clip was found on it"), idx)],
3116- })
3450+ /// The placements that move as one with the one at `idx` of `lane` --
3451+ /// itself and whatever carries its link, on the media lanes and the
3452+ /// subtitle ones alike. `None` for an index that is not there.
3453+ fn group_of(&self, lane: Lane, idx: usize) -> Option<Members> {
3454+ let sub = lane.kind == LaneKind::Subtitle;
3455+ let link = if sub {
3456+ self.sub_lane(lane).get(idx)?.link
3457+ } else {
3458+ self.lane(lane).get(idx)?.link
3459+ };
3460+ let mut members = Members::default();
3461+ match link {
3462+ Some(link) => {
3463+ for (l, data) in self.lanes.iter().enumerate() {
3464+ if let Some(i) = data.clips.iter().position(|c| c.link == Some(link)) {
3465+ members.clips.push((l, i));
3466+ }
3467+ if let Some(i) = data.subs.iter().position(|s| s.link == Some(link)) {
3468+ members.subs.push((l, i));
3469+ }
3470+ }
3471+ }
3472+ None => {
3473+ let l = self.index(lane).expect("the placement was found on it");
3474+ if sub {
3475+ members.subs.push((l, idx));
3476+ } else {
3477+ members.clips.push((l, idx));
3478+ }
3479+ }
3480+ }
3481+ Some(members)
31173482 }
31183483
31193484 /// Insert `clip` into the first lane of each kind at `timeline_frame` as one
@@ -3322,10 +3687,10 @@ impl Project {
33223687 }
33233688 }
33243689
3325- /// The law a scoped ripple lives under: **a link is one span on however
3326- /// many lanes**, so a batch that moves one half of a take and not the other
3327- /// would leave a group whose halves disagree -- a project no save could
3328- /// load ([`links_are_consistent`]).
3690+ /// The law a scoped ripple lives under: **a group travels as one**, so a
3691+ /// batch that moves one half of a take and not the other would leave the
3692+ /// halves disagreeing about where they stand -- an offset no hand asked
3693+ /// for, and the reason the take's lanes have to be scoped together.
33293694 ///
33303695 /// Refused by name rather than widened silently. Widening would edit a
33313696 /// track the user did not scope, which is exactly the surprise scoping
@@ -3511,17 +3876,66 @@ impl Project {
35113876 self.delete_in(Lane::V1, idx)
35123877 }
35133878
3514- /// [`delete`](Project::delete) for the lane the clip was picked on: the
3515- /// clip's own span is cut out of *every* lane, so a take deletes whole from
3516- /// whichever half of it was clicked. `false` for a bad index, and for a lane
3517- /// that is not there.
3879+ /// [`delete`](Project::delete) for the lane the clip was picked on. A clip
3880+ /// in no group (or a group of one, which is the same thing to a delete) is
3881+ /// what it always was: its own span cut out of *every* lane, so the
3882+ /// timeline closes up under it. A clip in a group takes the group with it,
3883+ /// each member by its **own** span and on its **own** lane -- the members
3884+ /// keep their offsets, so their spans may disagree, and the lanes may end
3885+ /// up out of step with each other, which is inherent to a hand-built group
3886+ /// and one undo away. The caption members lift rather than ripple, for the
3887+ /// reason a caption's own delete always lifted: a subtitle lane never
3888+ /// slides, or the words after the cut would stop matching the ones before
3889+ /// it. One snapshot for the whole group, so one [`Project::undo`] puts it
3890+ /// back. `false` for a bad index, and for a lane that is not there.
3891+ /// Changes the mapping: the caller must reseek.
35183892 pub fn delete_in(&mut self, lane: Lane, idx: usize) -> bool {
3893+ let Some(members) = self.group_of(lane, idx) else {
3894+ return false;
3895+ };
3896+ if !members.alone() {
3897+ return self.delete_members(&members);
3898+ }
35193899 let Some(clip) = self.lane(lane).get(idx).copied() else {
35203900 return false;
35213901 };
35223902 self.ripple_delete(clip.start, clip.frames())
35233903 }
35243904
3905+ /// [`delete_in`](Project::delete_in) for the caption the pick named: a
3906+ /// caption in no group lifts, exactly as its own key always made it
3907+ /// ([`Project::lift_sub`]), and a caption in a group takes the group with
3908+ /// it by [`delete_in`](Project::delete_in)'s rule -- the media members'
3909+ /// spans out of their own lanes, the other captions lifted. `false` for a
3910+ /// bad index.
3911+ pub fn delete_sub_in(&mut self, lane: Lane, idx: usize) -> bool {
3912+ let Some(members) = self.group_of(lane, idx) else {
3913+ return false;
3914+ };
3915+ if !members.alone() {
3916+ return self.delete_members(&members);
3917+ }
3918+ self.lift_sub(lane, idx)
3919+ }
3920+
3921+ /// The one whole-group delete both doors land in: every media member's own
3922+ /// span cut out of its own lane and the hole closed there -- and nothing
3923+ /// else on another lane moves, which is what keeps one member's ripple from
3924+ /// dragging another member's lane out from under it -- and every caption
3925+ /// member lifted. One snapshot, one undo step.
3926+ fn delete_members(&mut self, members: &Members) -> bool {
3927+ self.snapshot();
3928+ for &(l, i) in &members.clips {
3929+ let c = self.lanes[l].clips[i];
3930+ ripple(&mut self.lanes, &[l], c.start, c.frames());
3931+ }
3932+ for &(l, i) in members.subs.iter().rev() {
3933+ self.lanes[l].subs.remove(i);
3934+ }
3935+ debug_assert!(links_are_consistent(&self.lanes).is_ok());
3936+ true
3937+ }
3938+
35253939 /// Restore every lane from before the last successful edit -- the clips and
35263940 /// the lane list both. `false` when there is nothing left to undo.
35273941 pub fn undo(&mut self) -> bool {
@@ -3732,31 +4146,6 @@ impl Project {
37324146 id
37334147 }
37344148
3735- /// One fresh group id per *distinct* key, in lane order, and `None` where a
3736- /// lane has no key -- how [`split`](Project::split) and
3737- /// [`regroup`](Project::regroup) hand out ids across however many lanes.
3738- /// Lanes sharing a key end up sharing an id, which is exactly the rule
3739- /// [`links_are_consistent`] enforces: one id, one span.
3740- fn group_ids<K: PartialEq>(&mut self, keys: &[Option<K>]) -> Vec<Option<u32>> {
3741- // Linear, over a handful of lanes: a hash of a lane list would cost
3742- // more than it saves and would not be deterministic for free.
3743- let mut seen: Vec<(&K, u32)> = Vec::new();
3744- let mut out = Vec::with_capacity(keys.len());
3745- for key in keys {
3746- out.push(
3747- key.as_ref()
3748- .map(|k| match seen.iter().find(|(other, _)| *other == k) {
3749- Some(&(_, id)) => id,
3750- None => {
3751- let id = self.new_link();
3752- seen.push((k, id));
3753- id
3754- }
3755- }),
3756- );
3757- }
3758- out
3759- }
37604149 }
37614150
37624151 /// The handle of every lane, in storage order -- the one definition of what
@@ -3898,6 +4287,10 @@ fn sub_clear(subs: &mut Vec<SubClip>, start: u32, end: u32) {
38984287 out.push(SubClip {
38994288 frames: start - s.start,
39004289 out_us: s.window_at(start),
4290+ // Both pieces lose the group id, for [`clear`]'s reason: one
4291+ // id on two boxes of one lane is the one thing it may never
4292+ // mean.
4293+ link: None,
39014294 ..s
39024295 });
39034296 }
@@ -3906,6 +4299,7 @@ fn sub_clear(subs: &mut Vec<SubClip>, start: u32, end: u32) {
39064299 start: end,
39074300 frames: s.end() - end,
39084301 in_us: s.window_at(end),
4302+ link: None,
39094303 ..s
39104304 });
39114305 }
@@ -3924,6 +4318,7 @@ fn sub_open_room(subs: &mut Vec<SubClip>, at: u32, len: u32) {
39244318 subs[idx] = SubClip {
39254319 frames: at - s.start,
39264320 out_us: cut,
4321+ link: None,
39274322 ..s
39284323 };
39294324 subs.insert(
@@ -3932,6 +4327,7 @@ fn sub_open_room(subs: &mut Vec<SubClip>, at: u32, len: u32) {
39324327 start: at,
39334328 frames: s.end() - at,
39344329 in_us: cut,
4330+ link: None,
39354331 ..s
39364332 },
39374333 );
@@ -3952,15 +4348,56 @@ fn sub_joinable(subs: &[SubClip], frame: u32) -> Option<usize> {
39524348 .then_some(idx)
39534349 }
39544350
4351+/// How far one `edge` of the caption at `idx` may travel against its own lane's
4352+/// walls alone: the frame arithmetic of [`Project::trim_sub_room`] without the
4353+/// rate, which a caption *following* a group's trim does not have to be exact
4354+/// about -- its own walls, its own one surviving frame, and nothing that needs
4355+/// a clock.
4356+fn sub_edge_room(subs: &[SubClip], idx: usize, edge: Edge) -> (u32, u32) {
4357+ let s = &subs[idx];
4358+ match edge {
4359+ Edge::Start => (
4360+ idx.checked_sub(1).map_or(0, |p| subs[p].end()),
4361+ s.end() - 1,
4362+ ),
4363+ Edge::End => (s.start + 1, subs.get(idx + 1).map_or(u32::MAX, |n| n.start)),
4364+ }
4365+}
4366+
4367+/// Move one `edge` of `s` to timeline frame `to`, its window following by the
4368+/// placement's own proportion -- [`SubClip::window_at`]'s arithmetic, run
4369+/// forwards and backwards. The caption a group's trim is carrying has no rate
4370+/// of its own and needs none: what one frame of it is worth in microseconds is
4371+/// the window it already shows over the frames it already takes.
4372+fn write_sub_edge(s: &mut SubClip, edge: Edge, to: u32) {
4373+ let per_frame = s.window_us() / i64::from(s.frames.max(1));
4374+ let by = |from: u32, to: u32| per_frame.saturating_mul(i64::from(to) - i64::from(from));
4375+ match edge {
4376+ Edge::Start => {
4377+ s.in_us = (s.in_us + by(s.start, to)).clamp(0, s.out_us - 1);
4378+ s.frames = s.end() - to;
4379+ s.start = to;
4380+ }
4381+ Edge::End => {
4382+ s.out_us = (s.out_us + by(s.end(), to)).max(s.in_us + 1);
4383+ s.frames = to - s.start;
4384+ }
4385+ }
4386+ debug_assert!(s.frames >= 1 && s.out_us > s.in_us && s.in_us >= 0);
4387+}
4388+
39554389 /// The grouping invariant, checked in release at [`Project::from_parts`] and
3956-/// asserted by the tests after every edit: a link id names **at most one** clip
3957-/// per lane, and every clip carrying it covers the same timeline span -- that is
3958-/// all "these move together" can mean.
4390+/// asserted by the tests after every edit: a link id names **at most one**
4391+/// placement per lane -- a clip on a media lane or a caption on a subtitle
4392+/// one, whichever carries it. That is all "these move together" can mean now
4393+/// that a group is assembled by hand: the members keep their own spans and
4394+/// their own offsets, and what binds them is the id alone.
39594395 ///
3960-/// Deliberately *not* a pairing of two lanes: with N lanes a take may run on
3961-/// `V1`, `V2` and `A1` at once, and the rule that makes an id meaningful is span
3962-/// identity, not which lane (or which `ord`) the partner sits on. Two lanes are
3963-/// the case where it reads as "the picture and its sound".
4396+/// Deliberately *not* a pairing of two lanes, and never a span rule: with N
4397+/// lanes a group may run on `V1`, `A1` and a subtitle lane at once, and two
4398+/// placements of one group may cover different frames -- the offset-preserving
4399+/// group a hand builds with [`Project::group_all`], which a drag moves by one
4400+/// delta rather than by one span.
39644401 ///
39654402 /// A link no other lane carries is legal and is not an error: lifting one half
39664403 /// of a group ([`Project::lift`]) leaves exactly that, and a save of that
@@ -3976,26 +4413,17 @@ fn links_are_consistent(lanes: &[LaneData]) -> crate::Result<()> {
39764413 );
39774414 }
39784415 }
3979- }
3980- // First lane to carry an id fixes the span every other lane must agree on.
3981- let mut seen: Vec<(u32, Lane, u32, u32)> = Vec::new();
3982- for (data, &lane) in lanes.iter().zip(&handles) {
3983- for c in &data.clips {
3984- let Some(id) = c.link else { continue };
3985- match seen.iter().find(|(other, ..)| *other == id) {
3986- Some(&(_, first, start, end)) => {
3987- if (start, end) != (c.start, c.end()) {
3988- return Err(format!(
3989- "link {id} covers [{start}, {end}) in {} and [{}, {}) in {}",
3990- first.label(),
3991- c.start,
3992- c.end(),
3993- lane.label()
3994- )
3995- .into());
3996- }
3997- }
3998- None => seen.push((id, lane, c.start, c.end())),
4416+ // ...and the same for the captions, in their own list on the same lane:
4417+ // a subtitle lane holds no `Clip`, so this is the only list a caption's
4418+ // id could be doubled on.
4419+ for (i, s) in data.subs.iter().enumerate() {
4420+ let Some(id) = s.link else { continue };
4421+ if data.subs[..i].iter().any(|prev| prev.link == Some(id)) {
4422+ return Err(format!(
4423+ "link {id} names two captions in the {} lane",
4424+ lane.label()
4425+ )
4426+ .into());
39994427 }
40004428 }
40014429 }
@@ -4374,6 +4802,258 @@ mod tests {
43744802 assert_eq!(shape(&p), before);
43754803 }
43764804
4805+ /// The caption a hand groups: `group_all` over clips *and* a caption, the
4806+ /// mates riding along, the offsets kept, the refusals in words.
4807+ #[test]
4808+ fn a_hand_built_group_holds_clips_and_a_caption() {
4809+ let caption = |start: u32, frames: u32| SubClip {
4810+ start,
4811+ frames,
4812+ track: 0,
4813+ in_us: 0,
4814+ out_us: i64::from(frames) * 1_000_000,
4815+ link: None,
4816+ };
4817+ let track = || SubtitleTrack {
4818+ path: FILE.into(),
4819+ track: None,
4820+ language: "eng".into(),
4821+ name: String::new(),
4822+ label: "eng".into(),
4823+ cues: Vec::new(),
4824+ bitmap: false,
4825+ refused: None,
4826+ };
4827+ let mut p = Project::single(FILE, 9).with_subtitles(vec![track()]);
4828+ let v2 = p.add_lane(LaneKind::Video);
4829+ let s1 = p.add_lane(LaneKind::Subtitle);
4830+ // A layer at its own offset, and a caption over the head of the take.
4831+ assert!(p.place(v2, 2, clip(2, 0, 7, 0)));
4832+ p.place_sub(s1, 0, caption(0, 6)).expect("placed");
4833+
4834+ // Too few, one lane twice, and an index that is not there: words, no
4835+ // snapshot.
4836+ let history = p.history.len();
4837+ assert!(p.group_all(&[]).unwrap_err().to_string().contains("two placements or more"));
4838+ assert!(p
4839+ .group_all(&[(Lane::V1, 0), (Lane::V1, 0)])
4840+ .unwrap_err()
4841+ .to_string()
4842+ .contains("V1 is picked twice"));
4843+ assert!(p
4844+ .group_all(&[(Lane::V1, 0), (s1, 9)])
4845+ .unwrap_err()
4846+ .to_string()
4847+ .contains("no subtitle 9"));
4848+ assert_eq!(p.history.len(), history, "refusals cost no undo step");
4849+
4850+ // The group: the picture, the layer, and the caption -- and the sound
4851+ // the picture was already grouped with comes along unasked.
4852+ p.group_all(&[(Lane::V1, 0), (v2, 0), (s1, 0)])
4853+ .expect("three picks, three lanes");
4854+ let id = p.lane(Lane::V1)[0].link.expect("grouped");
4855+ for lane in [Lane::V1, Lane::A1, v2] {
4856+ assert_eq!(p.lane(lane)[0].link, Some(id), "{} rides along", lane.label());
4857+ }
4858+ assert_eq!(p.sub_lane(s1)[0].link, Some(id), "the caption is a member");
4859+ assert_eq!(p.sub_lane(s1)[0].frames, 6, "its own span, kept");
4860+ assert_eq!(p.lane(v2)[0].start, 2, "the layer's offset, kept");
4861+ assert!(links_are_consistent(&p.lanes).is_ok());
4862+ assert_eq!(p.history.len(), history + 1, "one snapshot for the group");
4863+
4864+ // ...and one undo takes it apart again.
4865+ assert!(p.undo());
4866+ assert_eq!(p.sub_lane(s1)[0].link, None, "the caption is loose again");
4867+
4868+ // Detach names a caption like it names a clip: every member an id of
4869+ // its own, which is never `None` (see `ungroup`).
4870+ p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("two picks");
4871+ assert!(p.ungroup(s1, 0));
4872+ let (loose_sub, loose_clip) = (p.sub_lane(s1)[0].link, p.lane(Lane::V1)[0].link);
4873+ assert!(loose_sub.is_some() && loose_clip.is_some());
4874+ assert_ne!(loose_sub, loose_clip);
4875+ assert!(links_are_consistent(&p.lanes).is_ok());
4876+ }
4877+
4878+ /// A split hands the caption of a group the same ids it hands the clips:
4879+ /// the left halves keep the group, the right halves share a fresh one.
4880+ #[test]
4881+ fn a_split_cuts_a_grouped_caption_with_its_clips() {
4882+ let caption = |start: u32, frames: u32| SubClip {
4883+ start,
4884+ frames,
4885+ track: 0,
4886+ in_us: 0,
4887+ out_us: i64::from(frames) * 1_000_000,
4888+ link: None,
4889+ };
4890+ let track = || SubtitleTrack {
4891+ path: FILE.into(),
4892+ track: None,
4893+ language: "eng".into(),
4894+ name: String::new(),
4895+ label: "eng".into(),
4896+ cues: Vec::new(),
4897+ bitmap: false,
4898+ refused: None,
4899+ };
4900+ let mut p = Project::single(FILE, 9).with_subtitles(vec![track()]);
4901+ let s1 = p.add_lane(LaneKind::Subtitle);
4902+ p.place_sub(s1, 0, caption(0, 9)).expect("placed");
4903+ p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");
4904+ let take = p.lane(Lane::V1)[0].link.expect("the group id");
4905+
4906+ assert!(p.split(4));
4907+ let (left, right) = (p.sub_lane(s1)[0], p.sub_lane(s1)[1]);
4908+ assert_eq!(left.link, Some(take), "the caption's head keeps the group");
4909+ assert_eq!(left.frames, 4);
4910+ assert_eq!(
4911+ right.link,
4912+ p.lane(Lane::V1)[1].link,
4913+ "the caption's tail shares the clips' fresh id"
4914+ );
4915+ assert_ne!(right.link, Some(take));
4916+ assert!(links_are_consistent(&p.lanes).is_ok());
4917+
4918+ // Regroup at the seam restores the take, caption included.
4919+ assert!(p.regroup(4));
4920+ assert_eq!(p.sub_lane(s1).len(), 1, "the caption rejoined");
4921+ assert_eq!(p.sub_lane(s1)[0].link, Some(take));
4922+ }
4923+
4924+ /// Deleting a member of a hand-built group takes the group: each media
4925+ /// member's own span out of its own lane, the captions lifted -- the lanes
4926+ /// may end up out of step, which is what one undo restores together.
4927+ #[test]
4928+ fn deleting_a_grouped_clip_ripples_each_lane_alone_and_lifts_the_captions() {
4929+ let caption = |start: u32, frames: u32| SubClip {
4930+ start,
4931+ frames,
4932+ track: 0,
4933+ in_us: 0,
4934+ out_us: i64::from(frames) * 1_000_000,
4935+ link: None,
4936+ };
4937+ let track = || SubtitleTrack {
4938+ path: FILE.into(),
4939+ track: None,
4940+ language: "eng".into(),
4941+ name: String::new(),
4942+ label: "eng".into(),
4943+ cues: Vec::new(),
4944+ bitmap: false,
4945+ refused: None,
4946+ };
4947+ let mut p = Project::single(FILE, 9).with_subtitles(vec![track()]);
4948+ let s1 = p.add_lane(LaneKind::Subtitle);
4949+ p.place_sub(s1, 2, caption(2, 4)).expect("placed");
4950+ p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");
4951+ // A neighbour on a lane the group does not touch.
4952+ let v2 = p.add_lane(LaneKind::Video);
4953+ assert!(p.place(v2, 10, clip(10, 0, 3, 0)));
4954+
4955+ // By the picture or by the caption, the same whole-group delete.
4956+ assert!(p.delete_sub_in(s1, 0));
4957+ assert!(p.lane(Lane::V1).is_empty(), "the take's span left V1");
4958+ assert!(p.sub_lane(s1).is_empty(), "the caption lifted");
4959+ assert_eq!(p.lane(v2)[0].start, 10, "a lane the group does not touch stays");
4960+ assert!(links_are_consistent(&p.lanes).is_ok());
4961+ assert!(p.undo(), "one step puts the group back");
4962+ assert_eq!(p.sub_lane(s1)[0].start, 2, "offsets and all");
4963+ }
4964+
4965+ /// Dragging a grouped caption carries its clips, one delta for all of them
4966+ /// -- and a caption in no group refuses an overlap exactly as it always did.
4967+ #[test]
4968+ fn dragging_a_grouped_caption_carries_its_group() {
4969+ let caption = |start: u32, frames: u32| SubClip {
4970+ start,
4971+ frames,
4972+ track: 0,
4973+ in_us: 0,
4974+ out_us: i64::from(frames) * 1_000_000,
4975+ link: None,
4976+ };
4977+ let track = || SubtitleTrack {
4978+ path: FILE.into(),
4979+ track: None,
4980+ language: "eng".into(),
4981+ name: String::new(),
4982+ label: "eng".into(),
4983+ cues: Vec::new(),
4984+ bitmap: false,
4985+ refused: None,
4986+ };
4987+ let mut p = Project::single(FILE, 9).with_subtitles(vec![track()]);
4988+ let s1 = p.add_lane(LaneKind::Subtitle);
4989+ p.place_sub(s1, 2, caption(2, 4)).expect("placed");
4990+ p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");
4991+
4992+ // Same lane, further along: everyone moves by the same eight frames.
4993+ p.move_sub(s1, 0, s1, 10).expect("room for all of it");
4994+ assert_eq!(p.sub_lane(s1)[0].start, 10);
4995+ assert_eq!(p.lane(Lane::V1)[0].start, 8, "the clip follows by the delta");
4996+ assert!(links_are_consistent(&p.lanes).is_ok());
4997+
4998+ // ...and an ungrouped caption is the caption it always was.
4999+ assert!(p.ungroup(s1, 0));
5000+ let mut q = Project::single(FILE, 9).with_subtitles(vec![track()]);
5001+ let s1 = q.add_lane(LaneKind::Subtitle);
5002+ q.place_sub(s1, 0, caption(0, 4)).expect("placed");
5003+ q.place_sub(s1, 5, caption(5, 4)).expect("placed");
5004+ assert!(q
5005+ .move_sub(s1, 0, s1, 3)
5006+ .unwrap_err()
5007+ .to_string()
5008+ .contains("already covers"));
5009+ }
5010+
5011+ /// A trim carries a group's caption by the same delta as its clips, clamped
5012+ /// to the caption's own walls -- the offsets between the members survive.
5013+ #[test]
5014+ fn trimming_a_grouped_clip_carries_the_caption_by_the_same_delta() {
5015+ let caption = |start: u32, frames: u32| SubClip {
5016+ start,
5017+ frames,
5018+ track: 0,
5019+ in_us: 0,
5020+ out_us: i64::from(frames) * 1_000_000,
5021+ link: None,
5022+ };
5023+ let track = || SubtitleTrack {
5024+ path: FILE.into(),
5025+ track: None,
5026+ language: "eng".into(),
5027+ name: String::new(),
5028+ label: "eng".into(),
5029+ cues: Vec::new(),
5030+ bitmap: false,
5031+ refused: None,
5032+ };
5033+ let mut p = Project::single(FILE, 9).with_subtitles(vec![track()]);
5034+ let s1 = p.add_lane(LaneKind::Subtitle);
5035+ // The caption sits two frames into the take and ends one early. The
5036+ // source runs past the clip, or there is no tail to pull out.
5037+ let src = &[20];
5038+ p.place_sub(s1, 2, caption(2, 6)).expect("placed");
5039+ p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped");
5040+
5041+ // The tail goes out by three: the clip to 12, the caption to 11.
5042+ assert!(p.trim(Lane::V1, 0, Edge::End, 12, src));
5043+ assert_eq!(p.lane(Lane::V1)[0].end(), 12);
5044+ assert_eq!(
5045+ (p.sub_lane(s1)[0].start, p.sub_lane(s1)[0].end()),
5046+ (2, 11),
5047+ "the caption follows by the delta"
5048+ );
5049+ assert!(p.sub_lane(s1)[0].out_us > p.sub_lane(s1)[0].in_us);
5050+
5051+ // The head comes in by two: everyone's start moves two along.
5052+ assert!(p.trim(Lane::V1, 0, Edge::Start, 2, src));
5053+ assert_eq!(p.sub_lane(s1)[0].start, 4, "the offset is kept");
5054+ assert!(links_are_consistent(&p.lanes).is_ok());
5055+ }
5056+
43775057 #[test]
43785058 fn split_refused_at_zero_boundary_end_and_in_a_gap() {
43795059 let mut p = three();
@@ -5944,13 +6624,15 @@ mod tests {
59446624 }
59456625
59466626 /// The grouping rules, at the untrusted door and after every edit that can
5947- /// touch a link. A link id is at most one clip per lane and, wherever it is
5948- /// carried, one span -- and no sequence of edits may produce otherwise,
5949- /// because what an edit produces is what a save writes and a load reads.
6627+ /// touch a link. A link id is at most one placement per lane -- a clip or a
6628+ /// caption, whichever carries it -- and no sequence of edits may produce
6629+ /// otherwise, because what an edit produces is what a save writes and a load
6630+ /// reads.
59506631 ///
5951- /// Amended for the lane model: the two errors name their lane `V1`/`A1`
5952- /// rather than "video"/"audio", because with N lanes "the video lane" is no
5953- /// longer a lane. Same causes, same door, same claim.
6632+ /// Amended for the offset-preserving group: the members keep their own
6633+ /// spans, so two placements of one id covering different frames is *legal*
6634+ /// -- it is what a hand-built group is -- and the only refusal left is the
6635+ /// doubled id inside one lane.
59546636 #[test]
59556637 fn a_link_id_is_never_two_clips_of_one_lane() {
59566638 let sources = vec![Source::new(FILE, 0)];
@@ -5966,7 +6648,7 @@ mod tests {
59666648 speed: Speed::NORMAL,
59676649 };
59686650
5969- // The door: named errors, one per cause.
6651+ // The door: a doubled id inside one lane, refused by name.
59706652 let err = |video: Vec<Clip>, audio: Vec<Clip>| {
59716653 Project::from_parts(sources.clone(), two(video, audio), Vec::new(), Vec::new())
59726654 .expect_err("refused")
@@ -5977,11 +6659,34 @@ mod tests {
59776659 .contains("link 7 names two clips in the V1 lane"),
59786660 "a duplicate id inside one lane is refused by name"
59796661 );
5980- assert!(
5981- err(vec![linked(0, 0, 5, 2)], vec![linked(0, 0, 3, 2)])
5982- .contains("link 2 covers [0, 5) in V1 and [0, 3) in A1"),
5983- "a pair that does not cover one span is refused by name"
6662+ // ...and the same doubling on a subtitle lane, in its own words: a
6663+ // caption is the other placement an id may name.
6664+ let caption = |start: u32, frames: u32, link| SubClip {
6665+ start,
6666+ frames,
6667+ track: 0,
6668+ in_us: 0,
6669+ out_us: i64::from(frames) * 1_000_000,
6670+ link: Some(link),
6671+ };
6672+ let subs = LaneData {
6673+ clips: Vec::new(),
6674+ subs: vec![caption(0, 3, 7), caption(4, 3, 7)],
6675+ ..LaneData::new(LaneKind::Subtitle, Vec::new())
6676+ };
6677+ assert_eq!(
6678+ links_are_consistent(&[subs]).unwrap_err().to_string(),
6679+ "link 7 names two captions in the S1 lane"
6680+ );
6681+ // A pair covering *different* frames is legal now: the members of a
6682+ // hand-built group keep their own spans, and what binds them is the id.
6683+ let apart = Project::from_parts(
6684+ sources.clone(),
6685+ two(vec![linked(0, 0, 5, 2)], vec![linked(0, 0, 3, 2)]),
6686+ Vec::new(),
6687+ Vec::new(),
59846688 );
6689+ assert!(apart.is_ok(), "offsets within one group load: {apart:?}");
59856690 // A one-sided link is *not* an error: it is what a lift leaves behind.
59866691 let mut p = Project::single(FILE, 9);
59876692 assert!(p.lift(Lane::A1, 0));
@@ -6646,81 +7351,65 @@ mod tests {
66467351 assert_eq!(shape(&p), vec![before[0].clone(), before[1].clone(), over]);
66477352 }
66487353
6649- /// The grouping rule across more than two lanes: a link id is one *span*,
6650- /// on however many lanes carry it -- not a video/audio pair and not a
6651- /// pairing by `ord`. So a split shares an id with every lane whose half
6652- /// lines up, and gives its own to every lane whose half does not.
7354+ /// The grouping rule across more than two lanes, under the offset model: a
7355+ /// split *keeps* the group on the left halves and hands the right halves of
7356+ /// that group one fresh id of their own -- a clip in no group comes out of
7357+ /// the cut in none. So a take cut apart is two takes, one per side, and a
7358+ /// lane that was never part of it stays out of both.
66537359 #[test]
6654- fn a_group_id_is_one_span_across_every_lane() {
7360+ fn a_split_keeps_the_left_group_and_shares_a_fresh_right_one() {
66557361 let mut p = Project::single(FILE, 9);
7362+ let take = p.clips()[0].link.expect("a fresh project is one take");
66567363 let v2 = p.add_lane(LaneKind::Video);
6657- assert!(p.place(v2, 0, clip(0, 0, 9, 0)), "three lanes, one span");
7364+ assert!(p.place(v2, 0, clip(0, 0, 9, 0)), "a placement joins no group");
66587365 assert!(p.split(4));
66597366 let side = |p: &Project, i: usize| -> Vec<Option<u32>> {
66607367 p.lanes().into_iter().map(|l| p.lane(l)[i].link).collect()
66617368 };
66627369 let (left, right) = (side(&p, 0), side(&p, 1));
6663- assert!(
6664- left[0].is_some() && left.iter().all(|id| *id == left[0]),
6665- "one id for three left halves: {left:?}"
7370+ // The lanes in order are V1, A1, V2: the take's two keep its id on the
7371+ // left, and the placed clip never had one for the cut to keep.
7372+ assert_eq!(
7373+ left,
7374+ vec![Some(take), Some(take), None],
7375+ "the left halves keep the take"
66667376 );
6667- assert!(right.iter().all(|id| *id == right[0]), "{right:?}");
6668- assert_ne!(left[0], right[0], "the halves are no longer one take");
7377+ // ...and the right halves of that take are one fresh group.
7378+ assert_eq!(right[0], right[1]);
7379+ assert_ne!(right[0], Some(take));
7380+ assert_eq!(right[2], None, "an unlinked lane stays unlinked");
66697381 invariants_hold(&p, "split across three lanes");
66707382
6671- // V2 ends early: same start, so the left halves are one take; different
6672- // end, so the right halves cannot be.
7383+ // V2 ends early: the left halves still keep what each clip carried --
7384+ // the take on V1 and A1, nothing on V2 -- and the fresh right id is
7385+ // shared by exactly the take's lanes.
66737386 let mut p = Project::single(FILE, 9);
66747387 let v2 = p.add_lane(LaneKind::Video);
66757388 assert!(p.place(v2, 0, clip(0, 0, 6, 0)));
66767389 assert!(p.split(3));
6677- assert_eq!(p.lane(Lane::V1)[0].link, p.lane(v2)[0].link, "same [0, 3)");
6678- assert_ne!(
6679- p.lane(Lane::V1)[1].link,
6680- p.lane(v2)[1].link,
6681- "[3,9) vs [3,6)"
6682- );
7390+ assert_eq!(p.lane(Lane::V1)[0].link, Some(take));
7391+ assert_eq!(p.lane(v2)[0].link, None, "[0, 3) of a placement");
66837392 assert_eq!(p.lane(Lane::V1)[1].link, p.lane(Lane::A1)[1].link);
7393+ assert_eq!(p.lane(v2)[1].link, None, "[3, 6) of a placement");
66847394 invariants_hold(&p, "split where one lane ends early");
66857395
6686- // The inverse rejoins all three, and groups them the same way.
7396+ // The inverse rejoins each lane into the group its left half kept.
66877397 assert!(p.regroup(3));
66887398 assert_eq!(p.lane(Lane::V1)[0].link, p.lane(Lane::A1)[0].link);
6689- assert_ne!(
7399+ assert_eq!(
66907400 p.lane(Lane::V1)[0].link,
6691- p.lane(v2)[0].link,
6692- "V2 rejoins into a span of its own"
7401+ Some(take),
7402+ "the take's id is back, not a fresh one"
66937403 );
7404+ assert_eq!(p.lane(v2)[0].link, None, "V2 rejoined into no group");
66947405 invariants_hold(&p, "regroup across three lanes");
6695-
6696- // ...and the rule is enforced, not merely produced: two video lanes
6697- // carrying one id over two spans is refused, by lane name.
6698- let linked = |out_frame, link| Clip {
6699- start: 0,
6700- in_frame: 0,
6701- out_frame,
6702- source: 0,
6703- link: Some(link),
6704- eq: None,
6705- color: None,
6706- fit: FitPolicy::default(),
6707- speed: Speed::NORMAL,
6708- };
6709- let lanes = vec![
6710- LaneData::new(LaneKind::Video, vec![linked(3, 4)]),
6711- LaneData::new(LaneKind::Video, vec![linked(5, 4)]),
6712- ];
6713- assert_eq!(
6714- links_are_consistent(&lanes).unwrap_err().to_string(),
6715- "link 4 covers [0, 3) in V1 and [0, 5) in V2"
6716- );
67177406 }
67187407
6719- /// A group is a set of clips over one span, at most one per lane: a picture
6720- /// may be grouped with sound in *any* audio lane -- there is no paired ord,
6721- /// and the lanes in between may be empty -- and the two ways to break that
6722- /// name the lane they broke it on. Lanes built by hand, because the rule is
6723- /// checked at the untrusted door and no edit can produce these.
7408+ /// A group is one placement per lane, on however many lanes carry the id --
7409+ /// not a video/audio pair and not a pairing by `ord` -- and the members may
7410+ /// cover whatever frames they cover: the offset between them is what a
7411+ /// hand-built group keeps. Lanes built by hand, because the rule is checked
7412+ /// at the untrusted door and no edit can produce the one thing it refuses.
67247413 #[test]
67257414 fn a_group_may_span_any_lane() {
67267415 let lane = |kind, clips: Vec<Clip>| LaneData::new(kind, clips);
@@ -6751,13 +7440,14 @@ mod tests {
67517440 // way a lifted half is legal.
67527441 let across = build([take(), Vec::new(), Vec::new(), take()]);
67537442 assert!(links_are_consistent(&across).is_ok(), "V1 grouped with A2");
6754- // Disagreeing about the span is not, and the message names both lanes.
6755- let apart = build([take(), Vec::new(), Vec::new(), vec![one(0, 6, 7)]]);
6756- assert_eq!(
6757- links_are_consistent(&apart).unwrap_err().to_string(),
6758- "link 7 covers [0, 4) in V1 and [0, 6) in A2"
7443+ // ...and so is a group whose members disagree about their spans: the
7444+ // offset between them is the hand's business, not the loader's.
7445+ let apart = build([take(), Vec::new(), Vec::new(), vec![one(2, 6, 7)]]);
7446+ assert!(
7447+ links_are_consistent(&apart).is_ok(),
7448+ "[0, 4) on V1 and [2, 6) on A2 are one group"
67597449 );
6760- // ...and one id twice in one lane is still that lane's error, by name.
7450+ // One id twice in one lane is still that lane's error, by name.
67617451 let twice = build([
67627452 Vec::new(),
67637453 Vec::new(),