forge
Explore
Log in

Don't you dare go Hollow

The project holds N lanes, V1..Vn and A1..An

Browse files at this commit

154fd69c54bac3cd704c2af4495e6f169eaf9339Ahmet Kaan GümüşParent: 771cd4a
  • refactor
    • the project holds N lanes, V1..Vn and A1..An
Show full message
♻️ refactor(engine): the project holds N lanes, V1..Vn and A1..An

The edit list was a fixed pair -- `Lane` {Video, Audio}, `lanes: [Vec<Clip>; 2]`
and seven hundred lines of methods walking that pair by hand. Multi-lane UI,
per-lane compositing and per-clip EQ all want lanes to be a list, so make them
one now, while the model is small enough to change in one sitting.

`Lane` becomes a handle -- a `LaneKind` plus a 0-based `ord`, so `Lane::V1` is
the first video lane and `Lane::new(Audio, 1)` is A2 -- and the project stores
`Vec<LaneData>`, a struct that per-lane state (mute, compositing mode, a name)
can grow into. A handle naming a lane that is not there reads as an empty lane
and refuses every mutation, so a front-end that only ever asks for V1/A1 needs
no bounds check of its own. Every method is a walk over the lane list now
instead of two hand-written cases.

The grouping rule generalises rather than pairing lanes off: a link id names at
most one clip per lane and every clip carrying it covers the same span, on
however many lanes. So a split hands out one id per group of lanes whose halves
line up -- one helper, used by split and regroup alike.

Playback, export and the audio worker still read V1 and A1: compositing is its
own slice. So is the file format, which holds one lane keyword per kind, so a
save of more than two lanes is refused by name instead of silently dropping
one; a two-lane project writes exactly the bytes it always did.
crates/app/src/main.rsmodified+20 -19
@@ -10,7 +10,7 @@ use std::sync::Arc;
10 use std::time::{Duration, Instant};10 use std::time::{Duration, Instant};
11 11
12 use engine::export::ExportSettings;12 use engine::export::ExportSettings;
13-use engine::project::Lane;13+use engine::project::{Lane, LaneKind};
14 use engine::{Clip, ExportHandle, Frame, PlaybackSession};14 use engine::{Clip, ExportHandle, Frame, PlaybackSession};
15 use gpui::{15 use gpui::{
16 AnyElement, App, Application, Bounds, ClickEvent, Context, FocusHandle, KeyDownEvent,16 AnyElement, App, Application, Bounds, ClickEvent, Context, FocusHandle, KeyDownEvent,
@@ -424,10 +424,10 @@ impl Player {
424 return;424 return;
425 }425 }
426 let deleted = match (&mut self.session, self.selected.take()) {426 let deleted = match (&mut self.session, self.selected.take()) {
427- (Some(session), Some((Lane::Video, idx))) => session.delete_clip(idx),427+ (Some(session), Some((Lane::V1, idx))) => session.delete_clip(idx),
428- (Some(session), Some((Lane::Audio, idx))) => match video_half(session, idx) {428+ (Some(session), Some((Lane::A1, idx))) => match video_half(session, idx) {
429 Some(video) => session.delete_clip(video),429 Some(video) => session.delete_clip(video),
430- None => session.lift_clip(Lane::Audio, idx),430+ None => session.lift_clip(Lane::A1, idx),
431 },431 },
432 _ => false,432 _ => false,
433 };433 };
@@ -1582,8 +1582,8 @@ impl Player {
1582 ),1582 ),
1583 ),1583 ),
1584 )1584 )
1585- .child(self.lane_row(Lane::Video, "V1", duration, filled, cx))1585+ .child(self.lane_row(Lane::V1, "V1", duration, filled, cx))
1586- .child(self.lane_row(Lane::Audio, "A1", duration, filled, cx))1586+ .child(self.lane_row(Lane::A1, "A1", duration, filled, cx))
1587 }1587 }
1588 1588
1589 /// A notice holds its own bar, full width, until it is answered: any key1589 /// A notice holds its own bar, full width, until it is answered: any key
@@ -1887,9 +1887,10 @@ impl Player {
1887 let (clips, others) = match &self.session {1887 let (clips, others) = match &self.session {
1888 Some(session) => (1888 Some(session) => (
1889 session.lane_clips(lane),1889 session.lane_clips(lane),
1890- session.lane_clips(match lane {1890+ session.lane_clips(if lane.kind == LaneKind::Video {
1891- Lane::Video => Lane::Audio,1891+ Lane::A1
1892- Lane::Audio => Lane::Video,1892+ } else {
1893+ Lane::V1
1893 }),1894 }),
1894 ),1895 ),
1895 None => (&[][..], &[][..]),1896 None => (&[][..], &[][..]),
@@ -1899,7 +1900,7 @@ impl Player {
1899 .as_ref()1900 .as_ref()
1900 .map_or(&[][..], PlaybackSession::sources);1901 .map_or(&[][..], PlaybackSession::sources);
1901 let (sel, sel_link) = (self.selected, self.selected_link());1902 let (sel, sel_link) = (self.selected, self.selected_link());
1902- let audio = lane == Lane::Audio;1903+ let audio = lane.kind == LaneKind::Audio;
1903 let tip: SharedString = format!(1904 let tip: SharedString = format!(
1904 "Select — {} removes the take, {} leaves a gap, {} rejoins a cut",1905 "Select — {} removes the take, {} leaves a gap, {} rejoins a cut",
1905 self.keymap.display(ActionId::Delete),1906 self.keymap.display(ActionId::Delete),
@@ -2169,9 +2170,9 @@ fn unseen_sources(sources: &[PathBuf], waves: &HashMap<PathBuf, Wave>) -> Vec<Pa
2169 /// Both lanes' clips, which is everything the timeline knows about its sources.2170 /// Both lanes' clips, which is everything the timeline knows about its sources.
2170 fn lane_clips(session: &PlaybackSession) -> impl Iterator<Item = &Clip> {2171 fn lane_clips(session: &PlaybackSession) -> impl Iterator<Item = &Clip> {
2171 session2172 session
2172- .lane_clips(Lane::Video)2173+ .lane_clips(Lane::V1)
2173 .iter()2174 .iter()
2174- .chain(session.lane_clips(Lane::Audio))2175+ .chain(session.lane_clips(Lane::A1))
2175 }2176 }
2176 2177
2177 /// How long a source is, as the timeline knows it: the furthest frame any clip2178 /// How long a source is, as the timeline knows it: the furthest frame any clip
@@ -2343,9 +2344,9 @@ fn start_frac(start: f64, total: f64) -> f32 {
2343 /// still holds that half. `None` for a half whose picture was lifted -- which is2344 /// still holds that half. `None` for a half whose picture was lifted -- which is
2344 /// what makes it a thing of its own to delete.2345 /// what makes it a thing of its own to delete.
2345 fn video_half(session: &PlaybackSession, audio: usize) -> Option<usize> {2346 fn video_half(session: &PlaybackSession, audio: usize) -> Option<usize> {
2346- let link = session.lane_clips(Lane::Audio).get(audio)?.link?;2347+ let link = session.lane_clips(Lane::A1).get(audio)?.link?;
2347 session2348 session
2348- .lane_clips(Lane::Video)2349+ .lane_clips(Lane::V1)
2349 .iter()2350 .iter()
2350 .position(|clip| clip.link == Some(link))2351 .position(|clip| clip.link == Some(link))
2351 }2352 }
@@ -2739,8 +2740,8 @@ mod tests {
2739 // timeline is longer by exactly that file.2740 // timeline is longer by exactly that file.
2740 assert_eq!(session.timeline_duration(), 13.0);2741 assert_eq!(session.timeline_duration(), 13.0);
2741 let (video, audio) = (2742 let (video, audio) = (
2742- session.lane_clips(Lane::Video),2743+ session.lane_clips(Lane::V1),
2743- session.lane_clips(Lane::Audio),2744+ session.lane_clips(Lane::A1),
2744 );2745 );
2745 // One take, not a video clip with no sound under it: both lanes hold2746 // One take, not a video clip with no sound under it: both lanes hold
2746 // the same clip at the same place, in the same group.2747 // the same clip at the same place, in the same group.
@@ -3131,13 +3132,13 @@ mod tests {
3131 3132
3132 #[test]3133 #[test]
3133 fn a_click_marks_the_whole_group_and_nothing_else() {3134 fn a_click_marks_the_whole_group_and_nothing_else() {
3134- let (v, a) = ((Lane::Video, 0), (Lane::Audio, 0));3135+ let (v, a) = ((Lane::V1, 0), (Lane::A1, 0));
3135 // Clicking the video half of group 1 marks the audio half with it.3136 // Clicking the video half of group 1 marks the audio half with it.
3136 assert!(marked(v, Some(1), Some(v), Some(1)));3137 assert!(marked(v, Some(1), Some(v), Some(1)));
3137 assert!(marked(a, Some(1), Some(v), Some(1)));3138 assert!(marked(a, Some(1), Some(v), Some(1)));
3138 // Another group's clips stay unmarked, in either lane.3139 // Another group's clips stay unmarked, in either lane.
3139- assert!(!marked((Lane::Video, 1), Some(2), Some(v), Some(1)));3140+ assert!(!marked((Lane::V1, 1), Some(2), Some(v), Some(1)));
3140- assert!(!marked((Lane::Audio, 1), Some(2), Some(v), Some(1)));3141+ assert!(!marked((Lane::A1, 1), Some(2), Some(v), Some(1)));
3141 // A half a lift left behind has no group: it marks itself only, which3142 // A half a lift left behind has no group: it marks itself only, which
3142 // is what makes it separately deletable. Two ungrouped clips must not3143 // is what makes it separately deletable. Two ungrouped clips must not
3143 // mark each other by both being ungrouped.3144 // mark each other by both being ungrouped.
crates/engine/src/export.rsmodified+1 -1
@@ -173,7 +173,7 @@ fn run(
173 // Spans, not clips: a gap in the video lane is part of the timeline and173 // Spans, not clips: a gap in the video lane is part of the timeline and
174 // gets encoded too, as black frames. The picture count is therefore174 // gets encoded too, as black frames. The picture count is therefore
175 // `timeline_frames` however the lane is arranged.175 // `timeline_frames` however the lane is arranged.
176- for span in project.spans_from(Lane::Video, 0) {176+ for span in project.spans_from(Lane::V1, 0) {
177 // Every clip reopens its own source file at its own in point; the177 // Every clip reopens its own source file at its own in point; the
178 // encoder is *not* reopened, so the export is one continuous stream178 // encoder is *not* reopened, so the export is one continuous stream
179 // whose GOP boundaries need not line up with the cuts -- nor with the179 // whose GOP boundaries need not line up with the cuts -- nor with the
crates/engine/src/playback.rsmodified+6 -6
@@ -131,7 +131,7 @@ impl PlaybackSession {
131 // One clip per lane covering the file, so timeline == source until the131 // One clip per lane covering the file, so timeline == source until the
132 // first edit -- and the range opened above is exactly that clip's.132 // first edit -- and the range opened above is exactly that clip's.
133 let project = Project::single(&path, meta.frame_count);133 let project = Project::single(&path, meta.frame_count);
134- let span = project.span_at(Lane::Video, 0).expect("never empty");134+ let span = project.span_at(Lane::V1, 0).expect("never empty");
135 Ok(Self {135 Ok(Self {
136 meta,136 meta,
137 frames: stream.frames,137 frames: stream.frames,
@@ -201,7 +201,7 @@ impl PlaybackSession {
201 201
202 let playhead = doc.playhead;202 let playhead = doc.playhead;
203 let project = Project::from_parts(doc.sources, doc.video, doc.audio)?;203 let project = Project::from_parts(doc.sources, doc.video, doc.audio)?;
204- let span = project.span_at(Lane::Video, 0).expect("never empty");204+ let span = project.span_at(Lane::V1, 0).expect("never empty");
205 // Last, because it is the one thing here that cannot be taken back: the205 // Last, because it is the one thing here that cannot be taken back: the
206 // feeder thread outlives the `Audio` value (it holds its own clones) and206 // feeder thread outlives the `Audio` value (it holds its own clones) and
207 // only a session's `drop` retires it, so a refusal above this line would207 // only a session's `drop` retires it, so a refusal above this line would
@@ -245,7 +245,7 @@ impl PlaybackSession {
245 /// [`crate::edith`]). Sources no clip plays from are left out, and the245 /// [`crate::edith`]). Sources no clip plays from are left out, and the
246 /// playhead is saved with it so a reopened project resumes where it stood.246 /// playhead is saved with it so a reopened project resumes where it stood.
247 pub fn save_project(&self, path: &Path) -> crate::Result<()> {247 pub fn save_project(&self, path: &Path) -> crate::Result<()> {
248- let (sources, video, audio) = self.project.without_orphan_sources();248+ let (sources, video, audio) = self.project.without_orphan_sources()?;
249 let playhead = secs_to_frame(self.now(), self.meta.frame_rate)249 let playhead = secs_to_frame(self.now(), self.meta.frame_rate)
250 .min(self.project.timeline_frames().saturating_sub(1));250 .min(self.project.timeline_frames().saturating_sub(1));
251 crate::edith::save(path, &sources, &video, &audio, playhead)251 crate::edith::save(path, &sources, &video, &audio, playhead)
@@ -309,7 +309,7 @@ impl PlaybackSession {
309 /// clip under the running worker and only the mapping stays true.309 /// clip under the running worker and only the mapping stays true.
310 fn next_clip(&mut self) -> bool {310 fn next_clip(&mut self) -> bool {
311 let next = self.span.end();311 let next = self.span.end();
312- let Some(span) = self.project.span_at(Lane::Video, next) else {312+ let Some(span) = self.project.span_at(Lane::V1, next) else {
313 return false;313 return false;
314 };314 };
315 // We only get here on a disconnect, so the old worker has already315 // We only get here on a disconnect, so the old worker has already
@@ -373,7 +373,7 @@ impl PlaybackSession {
373 /// [`Project::sources`] each clip plays from -- what a lane needs to colour373 /// [`Project::sources`] each clip plays from -- what a lane needs to colour
374 /// an imported clip differently from the file the session was opened with.374 /// an imported clip differently from the file the session was opened with.
375 pub fn clip_spans_by_source(&self) -> Vec<(f64, f64, usize)> {375 pub fn clip_spans_by_source(&self) -> Vec<(f64, f64, usize)> {
376- self.lane_spans_by_source(Lane::Video)376+ self.lane_spans_by_source(Lane::V1)
377 }377 }
378 378
379 /// [`clip_spans_by_source`](Self::clip_spans_by_source) for either lane,379 /// [`clip_spans_by_source`](Self::clip_spans_by_source) for either lane,
@@ -585,7 +585,7 @@ impl PlaybackSession {
585 // `target` is inside the timeline (never empty), so this always spans;585 // `target` is inside the timeline (never empty), so this always spans;
586 // the span runs from there to the end of whatever it landed in -- a586 // the span runs from there to the end of whatever it landed in -- a
587 // clip, or a gap, which starts a black-frame worker instead.587 // clip, or a gap, which starts a black-frame worker instead.
588- if let Some(span) = self.project.span_at(Lane::Video, target) {588+ if let Some(span) = self.project.span_at(Lane::V1, target) {
589 self.start_span(span);589 self.start_span(span);
590 }590 }
591 self.eos = false;591 self.eos = false;
crates/engine/src/project.rsmodified+666 -224
@@ -1,6 +1,8 @@
1-//! Edit list: two lanes of *placed* source ranges. Pure data, no I/O.1+//! Edit list: N ordered lanes of *placed* source ranges. Pure data, no I/O.
2 //!2 //!
3-//! A [`Project`] holds a video lane and an audio lane. Each lane is a list of3+//! A [`Project`] holds video lanes and audio lanes -- `V1..Vn`, `A1..An`, named
4+//! by a [`Lane`] handle of a [`LaneKind`] and a 0-based `ord`. Each lane is a
5+//! list of
4 //! [`Clip`]s, and a clip says three things: which half-open `[in, out)` range of6 //! [`Clip`]s, and a clip says three things: which half-open `[in, out)` range of
5 //! *source* frames it plays, which file it plays it from, and -- the whole model7 //! *source* frames it plays, which file it plays it from, and -- the whole model
6 //! -- where on the timeline it sits ([`Clip::start`]). Clips are placed at an8 //! -- where on the timeline it sits ([`Clip::start`]). Clips are placed at an
@@ -11,8 +13,10 @@
11 //! a hole cannot disagree with its neighbours about how long it is;13 //! a hole cannot disagree with its neighbours about how long it is;
12 //! * **moving and trimming are arithmetic** on `start`/`in_frame`, never a14 //! * **moving and trimming are arithmetic** on `start`/`in_frame`, never a
13 //! splice of the list;15 //! splice of the list;
14-//! * the lanes are independent: deleting audio under a picture is one lane's16+//! * the lanes are independent and are peers: deleting audio under a picture is
15-//! business, and the picture does not shift.17+//! one lane's business, and the picture does not shift. No lane is special
18+//! except by what a *caller* reads -- playback and export take `V1`, the audio
19+//! worker takes `A1`, until a compositing slice teaches them the rest.
16 //!20 //!
17 //! The price is one invariant this module enforces at every mutation and every21 //! The price is one invariant this module enforces at every mutation and every
18 //! constructor: within a lane, clips are **sorted by `start` and never overlap**22 //! constructor: within a lane, clips are **sorted by `start` and never overlap**
@@ -24,14 +28,17 @@
24 //! (sample ids in the demuxer are 1-based; that conversion stays in `decode`).28 //! (sample ids in the demuxer are 1-based; that conversion stays in `decode`).
25 //!29 //!
26 //! Grouping is [`Clip::link`]: clips carrying the same id were split from the30 //! Grouping is [`Clip::link`]: clips carrying the same id were split from the
27-//! same take and move together. [`Project::split`] cuts every lane at a timeline31+//! same take and move together. An id is *not* a pairing of two lanes -- it
28-//! frame and hands the two sides two fresh ids; [`Project::regroup`] is its32+//! names at most one clip per lane and every clip carrying it covers the same
29-//! inverse and rejoins them.33+//! timeline span, on however many lanes ([`links_are_consistent`]).
34+//! [`Project::split`] cuts every lane at a timeline frame and hands each side
35+//! fresh ids, one per group of lanes whose halves line up; [`Project::regroup`]
36+//! is its inverse and rejoins them.
30 //!37 //!
31 //! Editing is metadata only. [`Project::split`] changes no timeline->source38 //! Editing is metadata only. [`Project::split`] changes no timeline->source
32 //! mapping, so a running decoder stays correct across it; everything else does39 //! mapping, so a running decoder stays correct across it; everything else does
33-//! and the caller must reseek. Every successful edit snapshots both lanes, so40+//! and the caller must reseek. Every successful edit snapshots every lane, so
34-//! [`Project::undo`] is an exact restore.41+//! [`Project::undo`] is an exact restore -- of the clips *and* of the lane list.
35 //!42 //!
36 //! A clip names its file by *index* into [`Project::sources`], which is43 //! A clip names its file by *index* into [`Project::sources`], which is
37 //! append-only: an index handed out once stays valid forever, so a clip on the44 //! append-only: an index handed out once stays valid forever, so a clip on the
@@ -71,22 +78,59 @@ impl Clip {
71 }78 }
72 }79 }
73 80
74-/// Which lane an operation acts on. The lanes are peers: no operation reads one81+/// What a lane carries, which is what a *gap* in it means: black frames on a
75-/// to decide what to do to the other, except the grouped ones that say so.82+/// video lane, silence on an audio one.
76 #[derive(Clone, Copy, PartialEq, Eq, Debug)]83 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
77-pub enum Lane {84+pub enum LaneKind {
78 Video,85 Video,
79 Audio,86 Audio,
80 }87 }
81 88
89+/// Which lane an operation acts on: a kind plus a 0-based position among the
90+/// lanes of that kind, so [`Lane::V1`] is the first video lane and
91+/// `Lane::new(LaneKind::Audio, 1)` is `A2`.
92+///
93+/// A handle, not the lane itself. It stays meaningful while lanes are added,
94+/// and one naming a lane that is not there reads as an empty lane and refuses
95+/// every mutation -- a front-end that always asks for `V1`/`A1` needs no
96+/// bounds check of its own.
97+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
98+pub struct Lane {
99+ pub kind: LaneKind,
100+ pub ord: usize,
101+}
102+
82 impl Lane {103 impl Lane {
83- pub const ALL: [Lane; 2] = [Lane::Video, Lane::Audio];104+ /// The first video lane: what a decoder plays and what an export renders.
105+ pub const V1: Lane = Lane::new(LaneKind::Video, 0);
106+ /// The first audio lane: what the audio worker plays.
107+ pub const A1: Lane = Lane::new(LaneKind::Audio, 0);
84 108
85- fn index(self) -> usize {109+ pub const fn new(kind: LaneKind, ord: usize) -> Self {
86- self as usize110+ Self { kind, ord }
111+ }
112+
113+ /// `V1`, `A2`: how a lane is written in a header column and named in an
114+ /// error about it.
115+ pub fn label(self) -> String {
116+ let kind = match self.kind {
117+ LaneKind::Video => 'V',
118+ LaneKind::Audio => 'A',
119+ };
120+ format!("{kind}{}", self.ord + 1)
87 }121 }
88 }122 }
89 123
124+/// One lane: what it is and what it holds. A struct rather than a bare
125+/// `Vec<Clip>` because per-lane state is what the next slices add -- mute, a
126+/// compositing mode, a name -- and it belongs next to the clips it applies to.
127+#[derive(Clone, Debug)]
128+struct LaneData {
129+ kind: LaneKind,
130+ /// Sorted by `start` and disjoint ([`sorted_disjoint`]).
131+ clips: Vec<Clip>,
132+}
133+
90 /// What a lane holds over one stretch of the timeline: either a placed clip or134 /// What a lane holds over one stretch of the timeline: either a placed clip or
91 /// a gap. Returned already trimmed to the position it was asked about, so a135 /// a gap. Returned already trimmed to the position it was asked about, so a
92 /// caller can hand `len` straight to a decoder (or to a black-frame generator).136 /// caller can hand `len` straight to a decoder (or to a black-frame generator).
@@ -113,20 +157,22 @@ impl Span {
113 pub struct Project {157 pub struct Project {
114 /// Append-only: never popped, never reordered. See the module docs.158 /// Append-only: never popped, never reordered. See the module docs.
115 sources: Vec<PathBuf>,159 sources: Vec<PathBuf>,
116- /// Indexed by [`Lane::index`]. Each lane is sorted by `start` and disjoint.160+ /// In display order, which is the order [`Lane::ord`] counts in: the nth
117- lanes: [Vec<Clip>; 2],161+ /// lane of a kind here is that kind's `ord` n. Never empty.
118- /// Snapshots pushed *before* each successful edit; `undo` pops one.162+ lanes: Vec<LaneData>,
119- history: Vec<[Vec<Clip>; 2]>,163+ /// Snapshots pushed *before* each successful edit; `undo` pops one. The
164+ /// whole lane list, so adding a lane undoes as well.
165+ history: Vec<Vec<LaneData>>,
120 /// Never rolled back by an undo: an id retired by an undone split must not166 /// Never rolled back by an undo: an id retired by an undone split must not
121 /// come back and group two clips that were never together.167 /// come back and group two clips that were never together.
122 next_link: u32,168 next_link: u32,
123 }169 }
124 170
125 impl Project {171 impl Project {
126- /// One clip per lane covering the whole of `path`, the two grouped -- the172+ /// `V1` and `A1`, one clip each covering the whole of `path` and the two
127- /// state of a freshly opened video, where the timeline is the source.173+ /// grouped -- the state of a freshly opened video, where the timeline is the
128- /// `frame_count` of 0 would break the never-empty invariant, so it is174+ /// source. `frame_count` of 0 would break the never-empty invariant, so it
129- /// clamped to one frame.175+ /// is clamped to one frame.
130 pub fn single(path: impl AsRef<Path>, frame_count: u32) -> Self {176 pub fn single(path: impl AsRef<Path>, frame_count: u32) -> Self {
131 let clip = Clip {177 let clip = Clip {
132 start: 0,178 start: 0,
@@ -137,14 +183,25 @@ impl Project {
137 };183 };
138 Self {184 Self {
139 sources: vec![canonical(path.as_ref())],185 sources: vec![canonical(path.as_ref())],
140- lanes: [vec![clip], vec![clip]],186+ lanes: vec![
187+ LaneData {
188+ kind: LaneKind::Video,
189+ clips: vec![clip],
190+ },
191+ LaneData {
192+ kind: LaneKind::Audio,
193+ clips: vec![clip],
194+ },
195+ ],
141 history: Vec::new(),196 history: Vec::new(),
142 next_link: 1,197 next_link: 1,
143 }198 }
144 }199 }
145 200
146 /// A project rebuilt from a saved edit list -- the load half of201 /// A project rebuilt from a saved edit list -- the load half of
147- /// [`crate::edith`]. History is *not* saved, so [`Project::undo`] is202+ /// [`crate::edith`], which is a two-lane format, so this door takes `V1` and
203+ /// `A1` and nothing else (see [`Project::without_orphan_sources`], which
204+ /// refuses to *write* more). History is *not* saved, so [`Project::undo`] is
148 /// `false` until the first edit of the new session. This is the one door205 /// `false` until the first edit of the new session. This is the one door
149 /// untrusted parts come in through, so every invariant every other206 /// untrusted parts come in through, so every invariant every other
150 /// constructor keeps is checked here, by name and in release: both lanes207 /// constructor keeps is checked here, by name and in release: both lanes
@@ -159,9 +216,19 @@ impl Project {
159 if video.is_empty() && audio.is_empty() {216 if video.is_empty() && audio.is_empty() {
160 return Err("both lanes are empty: that is not a project".into());217 return Err("both lanes are empty: that is not a project".into());
161 }218 }
162- let lanes = [video, audio];219+ let lanes = vec![
163- for (lane, name) in lanes.iter().zip(["video", "audio"]) {220+ LaneData {
164- for c in lane {221+ kind: LaneKind::Video,
222+ clips: video,
223+ },
224+ LaneData {
225+ kind: LaneKind::Audio,
226+ clips: audio,
227+ },
228+ ];
229+ for (data, lane) in lanes.iter().zip(handles(&lanes)) {
230+ let name = lane.label();
231+ for c in &data.clips {
165 if c.out_frame <= c.in_frame {232 if c.out_frame <= c.in_frame {
166 return Err(format!(233 return Err(format!(
167 "{name} clip at {} plays the empty range [{}, {})",234 "{name} clip at {} plays the empty range [{}, {})",
@@ -186,14 +253,14 @@ impl Project {
186 .into());253 .into());
187 }254 }
188 }255 }
189- if !sorted_disjoint(lane) {256+ if !sorted_disjoint(&data.clips) {
190 return Err(format!("the {name} lane is out of order or overlaps itself").into());257 return Err(format!("the {name} lane is out of order or overlaps itself").into());
191 }258 }
192 }259 }
193 links_are_consistent(&lanes)?;260 links_are_consistent(&lanes)?;
194 let next_link = lanes261 let next_link = lanes
195 .iter()262 .iter()
196- .flatten()263+ .flat_map(|l| &l.clips)
197 .filter_map(|c| c.link)264 .filter_map(|c| c.link)
198 .max()265 .max()
199 // Saturating so a crafted file cannot make the counter wrap: at the266 // Saturating so a crafted file cannot make the counter wrap: at the
@@ -207,14 +274,56 @@ impl Project {
207 })274 })
208 }275 }
209 276
210- /// The video lane -- what an export renders and what a single-lane caller277+ /// The first video lane -- what an export renders and what a single-lane
211- /// still means by "the clips".278+ /// caller still means by "the clips".
212 pub fn clips(&self) -> &[Clip] {279 pub fn clips(&self) -> &[Clip] {
213- self.lane(Lane::Video)280+ self.lane(Lane::V1)
214 }281 }
215 282
283+ /// The clips of `lane`, or nothing at all for a lane that is not there.
216 pub fn lane(&self, lane: Lane) -> &[Clip] {284 pub fn lane(&self, lane: Lane) -> &[Clip] {
217- &self.lanes[lane.index()]285+ self.index(lane).map_or(&[][..], |i| &self.lanes[i].clips)
286+ }
287+
288+ /// Every lane's handle, in display order -- what a walk over "all lanes"
289+ /// iterates, and what a front-end lays out top to bottom.
290+ pub fn lanes(&self) -> Vec<Lane> {
291+ handles(&self.lanes)
292+ }
293+
294+ /// How many lanes of `kind` there are: `Lane::new(kind, ord)` names a lane
295+ /// for every `ord` below it, and none at or above it.
296+ pub fn lane_count(&self, kind: LaneKind) -> usize {
297+ self.lanes.iter().filter(|l| l.kind == kind).count()
298+ }
299+
300+ /// Appends an empty lane of `kind` and hands back its handle. One undo
301+ /// step, because the lane list is state a front-end shows: an added lane
302+ /// that could not be taken back would be the one edit with no way out.
303+ /// Nothing plays differently until something is placed on it.
304+ pub fn add_lane(&mut self, kind: LaneKind) -> Lane {
305+ self.snapshot();
306+ self.lanes.push(LaneData {
307+ kind,
308+ clips: Vec::new(),
309+ });
310+ Lane::new(kind, self.lane_count(kind) - 1)
311+ }
312+
313+ /// Where `lane` sits in [`Project::lanes`], or `None` for a lane that is
314+ /// not there. The one place a handle becomes a position.
315+ fn index(&self, lane: Lane) -> Option<usize> {
316+ self.lanes
317+ .iter()
318+ .enumerate()
319+ .filter(|(_, l)| l.kind == lane.kind)
320+ .map(|(i, _)| i)
321+ .nth(lane.ord)
322+ }
323+
324+ fn lane_mut(&mut self, lane: Lane) -> Option<&mut Vec<Clip>> {
325+ let i = self.index(lane)?;
326+ Some(&mut self.lanes[i].clips)
218 }327 }
219 328
220 /// The files the clips index into, in import order; index 0 is the file the329 /// The files the clips index into, in import order; index 0 is the file the
@@ -238,7 +347,7 @@ impl Project {
238 }347 }
239 }348 }
240 349
241- /// Append a whole-file clip of `source` to the end of *both* lanes, grouped350+ /// Append a whole-file clip of `source` to the end of *every* lane, grouped
242 /// -- an import lands as one take. One history snapshot, so an import is one351 /// -- an import lands as one take. One history snapshot, so an import is one
243 /// undo step, and undoing it leaves the (harmless) source entry behind,352 /// undo step, and undoing it leaves the (harmless) source entry behind,
244 /// because indexes are forever. Refused for an unknown source index.353 /// because indexes are forever. Refused for an unknown source index.
@@ -255,8 +364,8 @@ impl Project {
255 source,364 source,
256 link: Some(self.new_link()),365 link: Some(self.new_link()),
257 };366 };
258- for lane in &mut self.lanes {367+ for data in &mut self.lanes {
259- lane.push(clip);368+ data.clips.push(clip);
260 }369 }
261 true370 true
262 }371 }
@@ -268,11 +377,31 @@ impl Project {
268 /// nothing plays refuse a future load. New indexes are assigned in order of377 /// nothing plays refuse a future load. New indexes are assigned in order of
269 /// first use -- video lane first, then audio -- so the same project always378 /// first use -- video lane first, then audio -- so the same project always
270 /// emits the same bytes.379 /// emits the same bytes.
271- pub fn without_orphan_sources(&self) -> (Vec<PathBuf>, Vec<Clip>, Vec<Clip>) {380+ ///
381+ /// Refused, by name, for a timeline with more than one lane of a kind: the
382+ /// `.edith` format has one line keyword per kind, so writing a third lane
383+ /// would silently drop it. The model runs ahead of the format here on
384+ /// purpose -- the bump is its own slice -- and a refused save is the one
385+ /// answer that loses nothing.
386+ pub fn without_orphan_sources(&self) -> crate::Result<(Vec<PathBuf>, Vec<Clip>, Vec<Clip>)> {
387+ for kind in [LaneKind::Video, LaneKind::Audio] {
388+ let n = self.lane_count(kind);
389+ if n > 1 {
390+ let name = match kind {
391+ LaneKind::Video => "video",
392+ LaneKind::Audio => "audio",
393+ };
394+ return Err(format!(
395+ "this timeline has {n} {name} lanes; a project file holds one of each -- \
396+ saving more than two lanes needs a newer format"
397+ )
398+ .into());
399+ }
400+ }
272 let mut moved = vec![None; self.sources.len()];401 let mut moved = vec![None; self.sources.len()];
273 let mut sources = Vec::new();402 let mut sources = Vec::new();
274 let mut lanes = self.lanes.clone();403 let mut lanes = self.lanes.clone();
275- for c in lanes.iter_mut().flatten() {404+ for c in lanes.iter_mut().flat_map(|l| &mut l.clips) {
276 let old = c.source;405 let old = c.source;
277 c.source = match moved[old] {406 c.source = match moved[old] {
278 Some(new) => new,407 Some(new) => new,
@@ -283,8 +412,14 @@ impl Project {
283 }412 }
284 };413 };
285 }414 }
286- let [video, audio] = lanes;415+ let (mut video, mut audio) = (Vec::new(), Vec::new());
287- (sources, video, audio)416+ for data in lanes {
417+ match data.kind {
418+ LaneKind::Video => video = data.clips,
419+ LaneKind::Audio => audio = data.clips,
420+ }
421+ }
422+ Ok((sources, video, audio))
288 }423 }
289 424
290 /// Length of the timeline in frames: where the *last* lane runs out. A lane425 /// Length of the timeline in frames: where the *last* lane runs out. A lane
@@ -292,15 +427,15 @@ impl Project {
292 pub fn timeline_frames(&self) -> u32 {427 pub fn timeline_frames(&self) -> u32 {
293 self.lanes428 self.lanes
294 .iter()429 .iter()
295- .filter_map(|lane| lane.last().map(Clip::end))430+ .filter_map(|l| l.clips.last().map(Clip::end))
296 .max()431 .max()
297 .unwrap_or(0)432 .unwrap_or(0)
298 }433 }
299 434
300- /// `(timeline_start, len)` per video clip, in order -- what a UI lane needs435+ /// `(timeline_start, len)` per `V1` clip, in order -- what a UI lane needs
301 /// to lay clips out. Gaps show up as the holes between consecutive entries.436 /// to lay clips out. Gaps show up as the holes between consecutive entries.
302 pub fn clip_spans(&self) -> Vec<(u32, u32)> {437 pub fn clip_spans(&self) -> Vec<(u32, u32)> {
303- self.lane_spans(Lane::Video)438+ self.lane_spans(Lane::V1)
304 }439 }
305 440
306 pub fn lane_spans(&self, lane: Lane) -> Vec<(u32, u32)> {441 pub fn lane_spans(&self, lane: Lane) -> Vec<(u32, u32)> {
@@ -319,9 +454,9 @@ impl Project {
319 ))454 ))
320 }455 }
321 456
322- /// [`map`](Project::map) on the video lane -- the mapping a decoder follows.457+ /// [`map`](Project::map) on `V1` -- the mapping a decoder follows.
323 pub fn map_timeline(&self, timeline_frame: u32) -> Option<(usize, u32)> {458 pub fn map_timeline(&self, timeline_frame: u32) -> Option<(usize, u32)> {
324- self.map(Lane::Video, timeline_frame)459+ self.map(Lane::V1, timeline_frame)
325 }460 }
326 461
327 /// What `lane` holds from `timeline_frame` on: the rest of the clip covering462 /// What `lane` holds from `timeline_frame` on: the rest of the clip covering
@@ -376,53 +511,40 @@ impl Project {
376 /// placement's own start, in a gap, and past the end -- all of which would511 /// placement's own start, in a gap, and past the end -- all of which would
377 /// produce an empty clip or nothing at all.512 /// produce an empty clip or nothing at all.
378 ///513 ///
379- /// The two lanes' halves share an id only where they are the *same* span:514+ /// Lanes' halves share an id only where they are the *same* span: the lanes
380- /// the lanes are edited apart, so the clip being cut here may start (or515+ /// are edited apart, so the clip being cut here may start (or end)
381- /// end) somewhere else in the other lane, and a group id whose two clips516+ /// somewhere else on another lane, and a group id whose clips disagree
382- /// disagree about their span is not one take (see [`links_are_consistent`],517+ /// about their span is not one take (see [`links_are_consistent`], which
383- /// which refuses to load one).518+ /// refuses to load one).
384 ///519 ///
385 /// Metadata only: no mapping changes, in any lane.520 /// Metadata only: no mapping changes, in any lane.
386 pub fn split(&mut self, timeline_frame: u32) -> bool {521 pub fn split(&mut self, timeline_frame: u32) -> bool {
387- let cut = Lane::ALL522+ let cut: Vec<Option<Clip>> = self
388- .map(|l| splittable(self.lane(l), timeline_frame).map(|idx| self.lane(l)[idx]));523+ .lanes
524+ .iter()
525+ .map(|l| splittable(&l.clips, timeline_frame).map(|idx| l.clips[idx]))
526+ .collect();
389 if cut.iter().all(Option::is_none) {527 if cut.iter().all(Option::is_none) {
390 return false;528 return false;
391 }529 }
392 self.snapshot();530 self.snapshot();
393- let same = |f: fn(&Clip) -> u32| match cut {
394- [Some(a), Some(b)] => f(&a) == f(&b),
395- _ => false,
396- };
397- let (left, right) = (self.new_link(), self.new_link());
398 // Each side is its own question: two clips may start together and end531 // Each side is its own question: two clips may start together and end
399- // apart, and the halves that do line up stay one take.532+ // apart, and every lane whose halves do line up stays one take.
400- let ids = [533+ let starts: Vec<Option<u32>> = cut.iter().map(|c| c.map(|c| c.start)).collect();
401- (left, right),534+ let ends: Vec<Option<u32>> = cut.iter().map(|c| c.map(|c| c.end())).collect();
402- (535+ let left = self.group_ids(&starts);
403- if same(|c| c.start) {536+ let right = self.group_ids(&ends);
404- left537+ for ((data, left), right) in self.lanes.iter_mut().zip(left).zip(right) {
405- } else {538+ let Some(idx) = splittable(&data.clips, timeline_frame) else {
406- self.new_link()
407- },
408- if same(Clip::end) {
409- right
410- } else {
411- self.new_link()
412- },
413- ),
414- ];
415- for (lane, (left, right)) in self.lanes.iter_mut().zip(ids) {
416- let Some(idx) = splittable(lane, timeline_frame) else {
417 continue;539 continue;
418 };540 };
419- let mut tail = lane[idx];541+ let mut tail = data.clips[idx];
420 tail.in_frame += timeline_frame - tail.start;542 tail.in_frame += timeline_frame - tail.start;
421 tail.start = timeline_frame;543 tail.start = timeline_frame;
422- tail.link = Some(right);544+ tail.link = right;
423- lane[idx].out_frame = tail.in_frame;545+ data.clips[idx].out_frame = tail.in_frame;
424- lane[idx].link = Some(left);546+ data.clips[idx].link = left;
425- lane.insert(idx + 1, tail);547+ data.clips.insert(idx + 1, tail);
426 }548 }
427 true549 true
428 }550 }
@@ -437,29 +559,26 @@ impl Project {
437 /// reason.559 /// reason.
438 pub fn regroup(&mut self, timeline_frame: u32) -> bool {560 pub fn regroup(&mut self, timeline_frame: u32) -> bool {
439 // What each lane would end up covering, if it joins here at all.561 // What each lane would end up covering, if it joins here at all.
440- let joined = Lane::ALL.map(|l| {562+ let joined: Vec<Option<(u32, u32)>> = self
441- joinable(self.lane(l), timeline_frame)563+ .lanes
442- .map(|idx| (self.lane(l)[idx].start, self.lane(l)[idx + 1].end()))564+ .iter()
443- });565+ .map(|l| {
566+ joinable(&l.clips, timeline_frame)
567+ .map(|idx| (l.clips[idx].start, l.clips[idx + 1].end()))
568+ })
569+ .collect();
444 if joined.iter().all(Option::is_none) {570 if joined.iter().all(Option::is_none) {
445 return false;571 return false;
446 }572 }
447 self.snapshot();573 self.snapshot();
448- let link = self.new_link();574+ let ids = self.group_ids(&joined);
449- let ids = [575+ for (data, link) in self.lanes.iter_mut().zip(ids) {
450- link,576+ let Some(idx) = joinable(&data.clips, timeline_frame) else {
451- match joined {
452- [Some(a), Some(b)] if a == b => link,
453- _ => self.new_link(),
454- },
455- ];
456- for (lane, link) in self.lanes.iter_mut().zip(ids) {
457- let Some(idx) = joinable(lane, timeline_frame) else {
458 continue;577 continue;
459 };578 };
460- lane[idx].out_frame = lane[idx + 1].out_frame;579+ data.clips[idx].out_frame = data.clips[idx + 1].out_frame;
461- lane[idx].link = Some(link);580+ data.clips[idx].link = link;
462- lane.remove(idx + 1);581+ data.clips.remove(idx + 1);
463 }582 }
464 true583 true
465 }584 }
@@ -476,10 +595,12 @@ impl Project {
476 /// back over the clip it came from -- would put that id on two clips of one595 /// back over the clip it came from -- would put that id on two clips of one
477 /// lane, which is what a link may never mean (see [`links_are_consistent`]).596 /// lane, which is what a link may never mean (see [`links_are_consistent`]).
478 /// `None` rather than a fresh id because a one-lane placement has nothing on597 /// `None` rather than a fresh id because a one-lane placement has nothing on
479- /// the other lane to be grouped *with*; [`Project::regroup`] is how clips598+ /// another lane to be grouped *with*; [`Project::regroup`] is how clips
480 /// become a group again.599 /// become a group again.
600+ ///
601+ /// Refused for an empty `clip` and for a lane that is not there.
481 pub fn place(&mut self, lane: Lane, timeline_frame: u32, clip: Clip) -> bool {602 pub fn place(&mut self, lane: Lane, timeline_frame: u32, clip: Clip) -> bool {
482- if clip.out_frame <= clip.in_frame {603+ if clip.out_frame <= clip.in_frame || self.index(lane).is_none() {
483 return false;604 return false;
484 }605 }
485 self.snapshot();606 self.snapshot();
@@ -488,15 +609,15 @@ impl Project {
488 link: None,609 link: None,
489 ..clip610 ..clip
490 };611 };
491- let lane = &mut self.lanes[lane.index()];612+ let clips = self.lane_mut(lane).expect("checked above");
492- clear(lane, clip.start, clip.end());613+ clear(clips, clip.start, clip.end());
493- let idx = lane.partition_point(|c| c.start < clip.start);614+ let idx = clips.partition_point(|c| c.start < clip.start);
494- lane.insert(idx, clip);615+ clips.insert(idx, clip);
495- debug_assert!(sorted_disjoint(lane));616+ debug_assert!(sorted_disjoint(clips));
496 true617 true
497 }618 }
498 619
499- /// Insert `clip` into *both* lanes at `timeline_frame` as one new group,620+ /// Insert `clip` into *every* lane at `timeline_frame` as one new group,
500 /// pushing everything from there on later by its length -- the grouped,621 /// pushing everything from there on later by its length -- the grouped,
501 /// rippling paste a clipboard does. Mid-clip the clip it lands in is split622 /// rippling paste a clipboard does. Mid-clip the clip it lands in is split
502 /// around it; at or past the end of the timeline it is appended, because a623 /// around it; at or past the end of the timeline it is appended, because a
@@ -518,33 +639,34 @@ impl Project {
518 link: Some(self.new_link()),639 link: Some(self.new_link()),
519 ..clip640 ..clip
520 };641 };
521- for lane in &mut self.lanes {642+ for data in &mut self.lanes {
522- open_room(lane, at, clip.len());643+ open_room(&mut data.clips, at, clip.len());
523- let idx = lane.partition_point(|c| c.start < at);644+ let idx = data.clips.partition_point(|c| c.start < at);
524- lane.insert(idx, clip);645+ data.clips.insert(idx, clip);
525- debug_assert!(sorted_disjoint(lane));646+ debug_assert!(sorted_disjoint(&data.clips));
526 }647 }
527 true648 true
528 }649 }
529 650
530 /// Lift the clip at `idx` out of `lane`, leaving a gap: black frames or651 /// Lift the clip at `idx` out of `lane`, leaving a gap: black frames or
531- /// silence, and nothing else moves. Refused for an out-of-range index and652+ /// silence, and nothing else moves. Refused for an out-of-range index (which
532- /// for the lift that would leave *both* lanes empty -- an empty timeline is653+ /// a lane that is not there always is) and for the lift that would leave
533- /// the front-end's state, not a project's (see the never-empty invariant).654+ /// *every* lane empty -- an empty timeline is the front-end's state, not a
655+ /// project's (see the never-empty invariant).
534 pub fn lift(&mut self, lane: Lane, idx: usize) -> bool {656 pub fn lift(&mut self, lane: Lane, idx: usize) -> bool {
535- let placed: usize = self.lanes.iter().map(Vec::len).sum();657+ let placed: usize = self.lanes.iter().map(|l| l.clips.len()).sum();
536 if idx >= self.lane(lane).len() || placed == 1 {658 if idx >= self.lane(lane).len() || placed == 1 {
537 return false;659 return false;
538 }660 }
539 self.snapshot();661 self.snapshot();
540- self.lanes[lane.index()].remove(idx);662+ self.lane_mut(lane).expect("checked above").remove(idx);
541 true663 true
542 }664 }
543 665
544 /// Cut the timeline frames `[at, at + len)` out of *every* lane and close666 /// Cut the timeline frames `[at, at + len)` out of *every* lane and close
545 /// the hole: everything after slides back by `len`. The rippling delete --667 /// the hole: everything after slides back by `len`. The rippling delete --
546 /// [`lift`](Project::lift) is the one that leaves a gap. Refused for an668 /// [`lift`](Project::lift) is the one that leaves a gap. Refused for an
547- /// empty range and when it would leave both lanes empty.669+ /// empty range and when it would leave every lane empty.
548 pub fn ripple_delete(&mut self, at: u32, len: u32) -> bool {670 pub fn ripple_delete(&mut self, at: u32, len: u32) -> bool {
549 if len == 0 {671 if len == 0 {
550 return false;672 return false;
@@ -552,8 +674,9 @@ impl Project {
552 let survivors: usize = self674 let survivors: usize = self
553 .lanes675 .lanes
554 .iter()676 .iter()
555- .map(|lane| {677+ .map(|l| {
556- lane.iter()678+ l.clips
679+ .iter()
557 .filter(|c| c.start < at || c.end() > at + len)680 .filter(|c| c.start < at || c.end() > at + len)
558 .count()681 .count()
559 })682 })
@@ -562,17 +685,17 @@ impl Project {
562 return false;685 return false;
563 }686 }
564 self.snapshot();687 self.snapshot();
565- for lane in &mut self.lanes {688+ for data in &mut self.lanes {
566- clear(lane, at, at + len);689+ clear(&mut data.clips, at, at + len);
567- for c in lane.iter_mut().filter(|c| c.start >= at) {690+ for c in data.clips.iter_mut().filter(|c| c.start >= at) {
568 c.start -= len;691 c.start -= len;
569 }692 }
570- debug_assert!(sorted_disjoint(lane));693+ debug_assert!(sorted_disjoint(&data.clips));
571 }694 }
572 true695 true
573 }696 }
574 697
575- /// Remove the video clip at `idx` and everything under it, closing the gap698+ /// Remove the `V1` clip at `idx` and everything under it, closing the gap
576 /// -- the whole-group delete a single-lane front-end means. `false` for a699 /// -- the whole-group delete a single-lane front-end means. `false` for a
577 /// bad index. Changes the mapping: the caller must reseek.700 /// bad index. Changes the mapping: the caller must reseek.
578 pub fn delete(&mut self, idx: usize) -> bool {701 pub fn delete(&mut self, idx: usize) -> bool {
@@ -582,8 +705,8 @@ impl Project {
582 self.ripple_delete(clip.start, clip.len())705 self.ripple_delete(clip.start, clip.len())
583 }706 }
584 707
585- /// Restore both lanes from before the last successful edit. `false` when708+ /// Restore every lane from before the last successful edit -- the clips and
586- /// there is nothing left to undo.709+ /// the lane list both. `false` when there is nothing left to undo.
587 pub fn undo(&mut self) -> bool {710 pub fn undo(&mut self) -> bool {
588 match self.history.pop() {711 match self.history.pop() {
589 Some(prev) => {712 Some(prev) => {
@@ -596,7 +719,7 @@ impl Project {
596 719
597 /// Half-open `(source, start, end)` segments in *source* seconds, from720 /// Half-open `(source, start, end)` segments in *source* seconds, from
598 /// `timeline_frame` to the end of the timeline -- the play list for the721 /// `timeline_frame` to the end of the timeline -- the play list for the
599- /// audio worker, read off the **audio** lane. A `None` source is a gap: the722+ /// audio worker, read off **`A1`**. A `None` source is a gap: the
600 /// worker synthesises that many seconds of silence, which is what keeps the723 /// worker synthesises that many seconds of silence, which is what keeps the
601 /// audio master clock counting across a hole instead of stalling on it.724 /// audio master clock counting across a hole instead of stalling on it.
602 /// The first entry is partial when the position is mid-clip. Empty when the725 /// The first entry is partial when the position is mid-clip. Empty when the
@@ -605,7 +728,7 @@ impl Project {
605 if !(fps.is_finite() && fps > 0.0) {728 if !(fps.is_finite() && fps > 0.0) {
606 return Vec::new();729 return Vec::new();
607 }730 }
608- self.spans_from(Lane::Audio, timeline_frame)731+ self.spans_from(Lane::A1, timeline_frame)
609 .iter()732 .iter()
610 .map(|span| match span.from {733 .map(|span| match span.from {
611 // A clip's window is in *source* seconds: where in the file it734 // A clip's window is in *source* seconds: where in the file it
@@ -632,6 +755,50 @@ impl Project {
632 self.next_link = self.next_link.saturating_add(1);755 self.next_link = self.next_link.saturating_add(1);
633 id756 id
634 }757 }
758+
759+ /// One fresh group id per *distinct* key, in lane order, and `None` where a
760+ /// lane has no key -- how [`split`](Project::split) and
761+ /// [`regroup`](Project::regroup) hand out ids across however many lanes.
762+ /// Lanes sharing a key end up sharing an id, which is exactly the rule
763+ /// [`links_are_consistent`] enforces: one id, one span.
764+ fn group_ids<K: PartialEq>(&mut self, keys: &[Option<K>]) -> Vec<Option<u32>> {
765+ // Linear, over a handful of lanes: a hash of a lane list would cost
766+ // more than it saves and would not be deterministic for free.
767+ let mut seen: Vec<(&K, u32)> = Vec::new();
768+ let mut out = Vec::with_capacity(keys.len());
769+ for key in keys {
770+ out.push(key.as_ref().map(|k| {
771+ match seen.iter().find(|(other, _)| *other == k) {
772+ Some(&(_, id)) => id,
773+ None => {
774+ let id = self.new_link();
775+ seen.push((k, id));
776+ id
777+ }
778+ }
779+ }));
780+ }
781+ out
782+ }
783+}
784+
785+/// The handle of every lane, in storage order -- the one definition of what
786+/// [`Lane::ord`] counts.
787+fn handles(lanes: &[LaneData]) -> Vec<Lane> {
788+ let (mut video, mut audio) = (0, 0);
789+ lanes
790+ .iter()
791+ .map(|l| match l.kind {
792+ LaneKind::Video => {
793+ video += 1;
794+ Lane::new(LaneKind::Video, video - 1)
795+ }
796+ LaneKind::Audio => {
797+ audio += 1;
798+ Lane::new(LaneKind::Audio, audio - 1)
799+ }
800+ })
801+ .collect()
635 }802 }
636 803
637 /// Index of the clip covering `frame`, or `None` for a gap or past the end.804 /// Index of the clip covering `frame`, or `None` for a gap or past the end.
@@ -667,37 +834,53 @@ fn sorted_disjoint(clips: &[Clip]) -> bool {
667 && clips.windows(2).all(|w| w[0].end() <= w[1].start)834 && clips.windows(2).all(|w| w[0].end() <= w[1].start)
668 }835 }
669 836
670-/// The grouping invariant, checked in release at [`Project::from_parts`]: a link837+/// The grouping invariant, checked in release at [`Project::from_parts`] and
671-/// id names **at most one** clip per lane, and when it names one in each, the two838+/// asserted by the tests after every edit: a link id names **at most one** clip
672-/// cover the same timeline span -- that is all "these move together" can mean.839+/// per lane, and every clip carrying it covers the same timeline span -- that is
840+/// all "these move together" can mean.
673 ///841 ///
674-/// A link the *other* lane does not carry is legal and is not an error: lifting842+/// Deliberately *not* a pairing of two lanes: with N lanes a take may run on
675-/// one half of a group ([`Project::lift`]) leaves exactly that, and a save of843+/// `V1`, `V2` and `A1` at once, and the rule that makes an id meaningful is span
676-/// that timeline has to load again.844+/// identity, not which lane (or which `ord`) the partner sits on. Two lanes are
677-fn links_are_consistent(lanes: &[Vec<Clip>; 2]) -> crate::Result<()> {845+/// the case where it reads as "the picture and its sound".
678- let find = |lane: &Vec<Clip>, id: u32| lane.iter().find(|c| c.link == Some(id)).copied();846+///
679- for (lane, name) in lanes.iter().zip(["video", "audio"]) {847+/// A link no other lane carries is legal and is not an error: lifting one half
680- for (i, c) in lane.iter().enumerate() {848+/// of a group ([`Project::lift`]) leaves exactly that, and a save of that
849+/// timeline has to load again.
850+fn links_are_consistent(lanes: &[LaneData]) -> crate::Result<()> {
851+ let handles = handles(lanes);
852+ for (data, lane) in lanes.iter().zip(&handles) {
853+ for (i, c) in data.clips.iter().enumerate() {
681 let Some(id) = c.link else { continue };854 let Some(id) = c.link else { continue };
682- if lane[..i].iter().any(|prev| prev.link == Some(id)) {855+ if data.clips[..i].iter().any(|prev| prev.link == Some(id)) {
683- return Err(format!("link {id} names two clips in the {name} lane").into());856+ return Err(format!(
857+ "link {id} names two clips in the {} lane",
858+ lane.label()
859+ )
860+ .into());
684 }861 }
685 }862 }
686 }863 }
687- for a in lanes[0].iter().filter(|c| c.link.is_some()) {864+ // First lane to carry an id fixes the span every other lane must agree on.
688- let id = a.link.expect("filtered");865+ let mut seen: Vec<(u32, Lane, u32, u32)> = Vec::new();
689- let Some(b) = find(&lanes[1], id) else {866+ for (data, &lane) in lanes.iter().zip(&handles) {
690- continue;867+ for c in &data.clips {
691- };868+ let Some(id) = c.link else { continue };
692- if (a.start, a.end()) != (b.start, b.end()) {869+ match seen.iter().find(|(other, ..)| *other == id) {
693- return Err(format!(870+ Some(&(_, first, start, end)) => {
694- "link {id} covers [{}, {}) in video and [{}, {}) in audio",871+ if (start, end) != (c.start, c.end()) {
695- a.start,872+ return Err(format!(
696- a.end(),873+ "link {id} covers [{start}, {end}) in {} and [{}, {}) in {}",
697- b.start,874+ first.label(),
698- b.end()875+ c.start,
699- )876+ c.end(),
700- .into());877+ lane.label()
878+ )
879+ .into());
880+ }
881+ }
882+ None => seen.push((id, lane, c.start, c.end())),
883+ }
701 }884 }
702 }885 }
703 Ok(())886 Ok(())
@@ -787,22 +970,30 @@ mod tests {
787 }970 }
788 }971 }
789 972
790- /// Both lanes with their group ids blanked, for comparing shape.973+ /// Every lane with its group ids blanked, for comparing shape.
791- fn shape(p: &Project) -> [Vec<Clip>; 2] {974+ fn shape(p: &Project) -> Vec<Vec<Clip>> {
792- Lane::ALL.map(|l| {975+ p.lanes()
793- p.lane(l)976+ .into_iter()
794- .iter()977+ .map(|l| {
795- .map(|c| Clip { link: None, ..*c })978+ p.lane(l)
796- .collect()979+ .iter()
797- })980+ .map(|c| Clip { link: None, ..*c })
981+ .collect()
982+ })
983+ .collect()
798 }984 }
799 985
800 /// The *source frame* every timeline frame reads, per lane -- the traversal986 /// The *source frame* every timeline frame reads, per lane -- the traversal
801 /// a player performs. Deliberately not the clip index: a split changes which987 /// a player performs. Deliberately not the clip index: a split changes which
802 /// clip a frame belongs to, and nothing else.988 /// clip a frame belongs to, and nothing else.
803- fn traversal(p: &Project) -> Vec<[Option<u32>; 2]> {989+ fn traversal(p: &Project) -> Vec<Vec<Option<u32>>> {
804 (0..p.timeline_frames() + 2)990 (0..p.timeline_frames() + 2)
805- .map(|f| Lane::ALL.map(|l| p.map(l, f).map(|(_, source)| source)))991+ .map(|f| {
992+ p.lanes()
993+ .into_iter()
994+ .map(|l| p.map(l, f).map(|(_, source)| source))
995+ .collect()
996+ })
806 .collect()997 .collect()
807 }998 }
808 999
@@ -826,11 +1017,11 @@ mod tests {
826 fn single_is_the_whole_file_on_both_lanes() {1017 fn single_is_the_whole_file_on_both_lanes() {
827 let p = Project::single(FILE, 150);1018 let p = Project::single(FILE, 150);
828 assert_eq!(p.clips().len(), 1);1019 assert_eq!(p.clips().len(), 1);
829- assert_eq!(p.lane(Lane::Audio).len(), 1);1020+ assert_eq!(p.lane(Lane::A1).len(), 1);
830 assert_eq!(p.timeline_frames(), 150);1021 assert_eq!(p.timeline_frames(), 150);
831 assert_eq!(p.clip_spans(), vec![(0, 150)]);1022 assert_eq!(p.clip_spans(), vec![(0, 150)]);
832 // grouped: video and audio carry the same link1023 // grouped: video and audio carry the same link
833- assert_eq!(p.clips()[0].link, p.lane(Lane::Audio)[0].link);1024+ assert_eq!(p.clips()[0].link, p.lane(Lane::A1)[0].link);
834 assert!(p.clips()[0].link.is_some());1025 assert!(p.clips()[0].link.is_some());
835 // degenerate mapping: timeline == source1026 // degenerate mapping: timeline == source
836 assert_eq!(p.map_timeline(0), Some((0, 0)));1027 assert_eq!(p.map_timeline(0), Some((0, 0)));
@@ -847,11 +1038,11 @@ mod tests {
847 let before_shape = shape(&p);1038 let before_shape = shape(&p);
848 1039
849 assert!(p.split(4));1040 assert!(p.split(4));
850- for l in Lane::ALL {1041+ for l in p.lanes() {
851- assert_eq!(p.lane(l).len(), 2, "{l:?} split");1042+ assert_eq!(p.lane(l).len(), 2, "{} split", l.label());
852 }1043 }
853 // The two sides are two groups, one per side, matching across the lanes.1044 // The two sides are two groups, one per side, matching across the lanes.
854- let (v, a) = (p.lane(Lane::Video), p.lane(Lane::Audio));1045+ let (v, a) = (p.lane(Lane::V1), p.lane(Lane::A1));
855 assert_eq!(v[0].link, a[0].link);1046 assert_eq!(v[0].link, a[0].link);
856 assert_eq!(v[1].link, a[1].link);1047 assert_eq!(v[1].link, a[1].link);
857 assert_ne!(v[0].link, v[1].link, "the halves are no longer one take");1048 assert_ne!(v[0].link, v[1].link, "the halves are no longer one take");
@@ -862,8 +1053,8 @@ mod tests {
862 assert_eq!(shape(&p), before_shape, "bit-exact back to one clip");1053 assert_eq!(shape(&p), before_shape, "bit-exact back to one clip");
863 assert_eq!(traversal(&p), before);1054 assert_eq!(traversal(&p), before);
864 assert_eq!(1055 assert_eq!(
865- p.lane(Lane::Video)[0].link,1056+ p.lane(Lane::V1)[0].link,
866- p.lane(Lane::Audio)[0].link,1057+ p.lane(Lane::A1)[0].link,
867 "and the rejoined clip is one group again"1058 "and the rejoined clip is one group again"
868 );1059 );
869 }1060 }
@@ -884,8 +1075,8 @@ mod tests {
884 1075
885 // ...and a frame that is a gap in both lanes has nothing to split.1076 // ...and a frame that is a gap in both lanes has nothing to split.
886 let mut p = three();1077 let mut p = three();
887- assert!(p.lift(Lane::Video, 1));1078+ assert!(p.lift(Lane::V1, 1));
888- assert!(p.lift(Lane::Audio, 1));1079+ assert!(p.lift(Lane::A1, 1));
889 assert!(!p.split(4), "a gap is not a clip");1080 assert!(!p.split(4), "a gap is not a clip");
890 }1081 }
891 1082
@@ -898,11 +1089,11 @@ mod tests {
898 // A boundary with a gap on one side, and one where the sources do not1089 // A boundary with a gap on one side, and one where the sources do not
899 // meet, are both refused.1090 // meet, are both refused.
900 let mut p = three();1091 let mut p = three();
901- assert!(p.lift(Lane::Video, 1));1092+ assert!(p.lift(Lane::V1, 1));
902- assert!(p.lift(Lane::Audio, 1));1093+ assert!(p.lift(Lane::A1, 1));
903 assert!(!p.regroup(3), "nothing starts at 3 any more");1094 assert!(!p.regroup(3), "nothing starts at 3 any more");
904 let mut p = three();1095 let mut p = three();
905- for l in Lane::ALL {1096+ for l in p.lanes() {
906 assert!(p.place(l, 3, clip(0, 100, 102, 0)));1097 assert!(p.place(l, 3, clip(0, 100, 102, 0)));
907 }1098 }
908 assert!(!p.regroup(3), "source 100 does not follow source 3");1099 assert!(!p.regroup(3), "source 100 does not follow source 3");
@@ -933,14 +1124,14 @@ mod tests {
933 assert_eq!(p.map_timeline(9), None);1124 assert_eq!(p.map_timeline(9), None);
934 // A span is the rest of the clip from where it was asked about.1125 // A span is the rest of the clip from where it was asked about.
935 assert_eq!(1126 assert_eq!(
936- p.span_at(Lane::Video, 6),1127+ p.span_at(Lane::V1, 6),
937 Some(Span {1128 Some(Span {
938 start: 6,1129 start: 6,
939 len: 3,1130 len: 3,
940 from: Some((0, 6))1131 from: Some((0, 6))
941 })1132 })
942 );1133 );
943- assert_eq!(p.span_at(Lane::Video, 9), None);1134+ assert_eq!(p.span_at(Lane::V1, 9), None);
944 }1135 }
945 1136
946 /// The clip a copy would hand back: source `[100, 102)`, unrelated to1137 /// The clip a copy would hand back: source `[100, 102)`, unrelated to
@@ -1028,7 +1219,7 @@ mod tests {
1028 assert!(p.delete(1));1219 assert!(p.delete(1));
1029 assert_eq!(p.timeline_frames(), 7);1220 assert_eq!(p.timeline_frames(), 7);
1030 assert_eq!(p.clip_spans(), vec![(0, 3), (3, 4)]);1221 assert_eq!(p.clip_spans(), vec![(0, 3), (3, 4)]);
1031- assert_eq!(p.lane_spans(Lane::Audio), vec![(0, 3), (3, 4)]);1222+ assert_eq!(p.lane_spans(Lane::A1), vec![(0, 3), (3, 4)]);
1032 // timeline 3 used to be source 3; the gap closed so it is source 5 now1223 // timeline 3 used to be source 3; the gap closed so it is source 5 now
1033 assert_eq!(p.map_timeline(3), Some((1, 5)));1224 assert_eq!(p.map_timeline(3), Some((1, 5)));
1034 assert_eq!(p.map_timeline(6), Some((1, 8)));1225 assert_eq!(p.map_timeline(6), Some((1, 8)));
@@ -1058,32 +1249,32 @@ mod tests {
1058 fn a_lift_leaves_a_gap_and_moves_nothing() {1249 fn a_lift_leaves_a_gap_and_moves_nothing() {
1059 let mut p = three();1250 let mut p = three();
1060 let video_before = shape(&p)[0].clone();1251 let video_before = shape(&p)[0].clone();
1061- assert!(p.lift(Lane::Audio, 1));1252+ assert!(p.lift(Lane::A1, 1));
1062 assert_eq!(shape(&p)[0], video_before, "the picture never moved");1253 assert_eq!(shape(&p)[0], video_before, "the picture never moved");
1063 assert_eq!(p.timeline_frames(), 9, "nor did the timeline get shorter");1254 assert_eq!(p.timeline_frames(), 9, "nor did the timeline get shorter");
1064- assert_eq!(p.lane_spans(Lane::Audio), vec![(0, 3), (5, 4)]);1255+ assert_eq!(p.lane_spans(Lane::A1), vec![(0, 3), (5, 4)]);
1065 // The hole is a gap: mapped as nothing, spanned as a gap of its length.1256 // The hole is a gap: mapped as nothing, spanned as a gap of its length.
1066- assert_eq!(p.map(Lane::Audio, 4), None);1257+ assert_eq!(p.map(Lane::A1, 4), None);
1067 assert_eq!(1258 assert_eq!(
1068- p.span_at(Lane::Audio, 3),1259+ p.span_at(Lane::A1, 3),
1069 Some(Span {1260 Some(Span {
1070 start: 3,1261 start: 3,
1071 len: 2,1262 len: 2,
1072 from: None1263 from: None
1073 })1264 })
1074 );1265 );
1075- assert_eq!(p.map(Lane::Video, 4), Some((1, 4)), "video plays on");1266+ assert_eq!(p.map(Lane::V1, 4), Some((1, 4)), "video plays on");
1076 assert!(p.undo());1267 assert!(p.undo());
1077- assert_eq!(p.lane_spans(Lane::Audio), vec![(0, 3), (3, 2), (5, 4)]);1268+ assert_eq!(p.lane_spans(Lane::A1), vec![(0, 3), (3, 2), (5, 4)]);
1078 }1269 }
1079 1270
1080 #[test]1271 #[test]
1081 fn a_trailing_gap_is_a_gap_to_the_end_of_the_timeline() {1272 fn a_trailing_gap_is_a_gap_to_the_end_of_the_timeline() {
1082 let mut p = three();1273 let mut p = three();
1083- assert!(p.lift(Lane::Audio, 2));1274+ assert!(p.lift(Lane::A1, 2));
1084 assert_eq!(p.timeline_frames(), 9, "video still runs to 9");1275 assert_eq!(p.timeline_frames(), 9, "video still runs to 9");
1085 assert_eq!(1276 assert_eq!(
1086- p.span_at(Lane::Audio, 5),1277+ p.span_at(Lane::A1, 5),
1087 Some(Span {1278 Some(Span {
1088 start: 5,1279 start: 5,
1089 len: 4,1280 len: 4,
@@ -1091,11 +1282,11 @@ mod tests {
1091 }),1282 }),
1092 "the audio lane holds silence to the end of the picture"1283 "the audio lane holds silence to the end of the picture"
1093 );1284 );
1094- assert_eq!(p.span_at(Lane::Audio, 9), None);1285+ assert_eq!(p.span_at(Lane::A1, 9), None);
1095 // Every lane covers the timeline exactly, gaps included.1286 // Every lane covers the timeline exactly, gaps included.
1096- for l in Lane::ALL {1287+ for l in p.lanes() {
1097 let spans = p.spans_from(l, 0);1288 let spans = p.spans_from(l, 0);
1098- assert_eq!(spans.iter().map(|s| s.len).sum::<u32>(), 9, "{l:?}");1289+ assert_eq!(spans.iter().map(|s| s.len).sum::<u32>(), 9, "{}", l.label());
1099 assert_eq!(spans[0].start, 0);1290 assert_eq!(spans[0].start, 0);
1100 }1291 }
1101 }1292 }
@@ -1103,9 +1294,9 @@ mod tests {
1103 #[test]1294 #[test]
1104 fn the_last_clip_of_the_last_lane_cannot_be_lifted() {1295 fn the_last_clip_of_the_last_lane_cannot_be_lifted() {
1105 let mut p = Project::single(FILE, 9);1296 let mut p = Project::single(FILE, 9);
1106- assert!(p.lift(Lane::Audio, 0), "a silent timeline is fine");1297+ assert!(p.lift(Lane::A1, 0), "a silent timeline is fine");
1107- assert!(!p.lift(Lane::Video, 0), "an empty one is not");1298+ assert!(!p.lift(Lane::V1, 0), "an empty one is not");
1108- assert!(!p.lift(Lane::Audio, 0), "index past the end");1299+ assert!(!p.lift(Lane::A1, 0), "index past the end");
1109 assert_eq!(p.timeline_frames(), 9);1300 assert_eq!(p.timeline_frames(), 9);
1110 }1301 }
1111 1302
@@ -1115,7 +1306,7 @@ mod tests {
1115 let audio_before = shape(&p)[1].clone();1306 let audio_before = shape(&p)[1].clone();
1116 // Straddles [3,5) and eats into [5,9): the first is trimmed, the second1307 // Straddles [3,5) and eats into [5,9): the first is trimmed, the second
1117 // is trimmed, nothing shifts.1308 // is trimmed, nothing shifts.
1118- assert!(p.place(Lane::Video, 4, clip(0, 100, 102, 0)));1309+ assert!(p.place(Lane::V1, 4, clip(0, 100, 102, 0)));
1119 assert_eq!(1310 assert_eq!(
1120 shape(&p)[0],1311 shape(&p)[0],
1121 vec![1312 vec![
@@ -1130,23 +1321,23 @@ mod tests {
1130 1321
1131 // Placed inside one clip, it splits it in two.1322 // Placed inside one clip, it splits it in two.
1132 let mut p = Project::single(FILE, 9);1323 let mut p = Project::single(FILE, 9);
1133- assert!(p.place(Lane::Video, 4, clip(0, 100, 101, 0)));1324+ assert!(p.place(Lane::V1, 4, clip(0, 100, 101, 0)));
1134 assert_eq!(1325 assert_eq!(
1135 shape(&p)[0],1326 shape(&p)[0],
1136 vec![clip(0, 0, 4, 0), clip(4, 100, 101, 0), clip(5, 5, 9, 0)]1327 vec![clip(0, 0, 4, 0), clip(4, 100, 101, 0), clip(5, 5, 9, 0)]
1137 );1328 );
1138 // ...and placed past the end it makes a gap, which is the whole point.1329 // ...and placed past the end it makes a gap, which is the whole point.
1139- assert!(p.place(Lane::Video, 20, clip(0, 100, 102, 0)));1330+ assert!(p.place(Lane::V1, 20, clip(0, 100, 102, 0)));
1140 assert_eq!(p.timeline_frames(), 22);1331 assert_eq!(p.timeline_frames(), 22);
1141 assert_eq!(1332 assert_eq!(
1142- p.span_at(Lane::Video, 9),1333+ p.span_at(Lane::V1, 9),
1143 Some(Span {1334 Some(Span {
1144 start: 9,1335 start: 9,
1145 len: 11,1336 len: 11,
1146 from: None1337 from: None
1147 })1338 })
1148 );1339 );
1149- assert!(!p.place(Lane::Video, 0, clip(0, 7, 7, 0)), "empty clip");1340+ assert!(!p.place(Lane::V1, 0, clip(0, 7, 7, 0)), "empty clip");
1150 }1341 }
1151 1342
1152 #[test]1343 #[test]
@@ -1224,7 +1415,7 @@ mod tests {
1224 #[test]1415 #[test]
1225 fn a_gap_in_the_audio_lane_is_a_silent_segment_of_its_own_length() {1416 fn a_gap_in_the_audio_lane_is_a_silent_segment_of_its_own_length() {
1226 let mut p = three();1417 let mut p = three();
1227- assert!(p.lift(Lane::Audio, 1)); // silence over timeline [3, 5)1418+ assert!(p.lift(Lane::A1, 1)); // silence over timeline [3, 5)
1228 assert_eq!(1419 assert_eq!(
1229 p.segments_from(0, FPS),1420 p.segments_from(0, FPS),
1230 vec![1421 vec![
@@ -1243,8 +1434,8 @@ mod tests {
1243 vec![(None, 0.0, 1.0 / 30.0), (Some(0), 5.0 / 30.0, 9.0 / 30.0)]1434 vec![(None, 0.0, 1.0 / 30.0), (Some(0), 5.0 / 30.0, 9.0 / 30.0)]
1244 );1435 );
1245 // ...and a lane that is nothing but gap is a run of silence.1436 // ...and a lane that is nothing but gap is a run of silence.
1246- assert!(p.lift(Lane::Audio, 0));1437+ assert!(p.lift(Lane::A1, 0));
1247- assert!(p.lift(Lane::Audio, 0));1438+ assert!(p.lift(Lane::A1, 0));
1248 assert_eq!(p.segments_from(0, FPS), vec![(None, 0.0, 0.3)]);1439 assert_eq!(p.segments_from(0, FPS), vec![(None, 0.0, 0.3)]);
1249 }1440 }
1250 1441
@@ -1361,10 +1552,10 @@ mod tests {
1361 // Import a second file, undo it: source 1 is now an orphan.1552 // Import a second file, undo it: source 1 is now an orphan.
1362 let mut p = two_sources();1553 let mut p = two_sources();
1363 assert!(p.undo());1554 assert!(p.undo());
1364- let (sources, video, audio) = p.without_orphan_sources();1555+ let (sources, video, audio) = p.without_orphan_sources().expect("two lanes");
1365 assert_eq!(sources, vec![PathBuf::from(FILE)], "the orphan is gone");1556 assert_eq!(sources, vec![PathBuf::from(FILE)], "the orphan is gone");
1366 assert_eq!(video, three().clips(), "the clips are untouched");1557 assert_eq!(video, three().clips(), "the clips are untouched");
1367- assert_eq!(audio, three().lane(Lane::Audio));1558+ assert_eq!(audio, three().lane(Lane::A1));
1368 1559
1369 // Three sources where only the middle one is orphaned: the survivors1560 // Three sources where only the middle one is orphaned: the survivors
1370 // renumber, and the clips follow.1561 // renumber, and the clips follow.
@@ -1372,7 +1563,7 @@ mod tests {
1372 assert_eq!(p.import(FILE2), 1);1563 assert_eq!(p.import(FILE2), 1);
1373 assert_eq!(p.import("/nonexistent/c.mp4"), 2);1564 assert_eq!(p.import("/nonexistent/c.mp4"), 2);
1374 assert!(p.append_clip(2, 4));1565 assert!(p.append_clip(2, 4));
1375- let (sources, video, audio) = p.without_orphan_sources();1566+ let (sources, video, audio) = p.without_orphan_sources().expect("two lanes");
1376 assert_eq!(1567 assert_eq!(
1377 sources,1568 sources,
1378 vec![PathBuf::from(FILE), PathBuf::from("/nonexistent/c.mp4")]1569 vec![PathBuf::from(FILE), PathBuf::from("/nonexistent/c.mp4")]
@@ -1386,7 +1577,7 @@ mod tests {
1386 1577
1387 #[test]1578 #[test]
1388 fn from_parts_has_no_history_and_checks_the_invariants() {1579 fn from_parts_has_no_history_and_checks_the_invariants() {
1389- let (sources, video, audio) = three().without_orphan_sources();1580+ let (sources, video, audio) = three().without_orphan_sources().expect("two lanes");
1390 let mut p = Project::from_parts(sources.clone(), video.clone(), audio.clone())1581 let mut p = Project::from_parts(sources.clone(), video.clone(), audio.clone())
1391 .expect("valid parts");1582 .expect("valid parts");
1392 assert_eq!(p.clips(), three().clips());1583 assert_eq!(p.clips(), three().clips());
@@ -1418,9 +1609,13 @@ mod tests {
1418 }1609 }
1419 1610
1420 /// The grouping rules, at the untrusted door and after every edit that can1611 /// The grouping rules, at the untrusted door and after every edit that can
1421- /// touch a link. A link id is at most one clip per lane and, when both lanes1612+ /// touch a link. A link id is at most one clip per lane and, wherever it is
1422- /// carry it, one span -- and no sequence of edits may produce otherwise,1613+ /// carried, one span -- and no sequence of edits may produce otherwise,
1423 /// because what an edit produces is what a save writes and a load reads.1614 /// because what an edit produces is what a save writes and a load reads.
1615+ ///
1616+ /// Amended for the lane model: the two errors name their lane `V1`/`A1`
1617+ /// rather than "video"/"audio", because with N lanes "the video lane" is no
1618+ /// longer a lane. Same causes, same door, same claim.
1424 #[test]1619 #[test]
1425 fn a_link_id_is_never_two_clips_of_one_lane() {1620 fn a_link_id_is_never_two_clips_of_one_lane() {
1426 let sources = vec![PathBuf::from(FILE)];1621 let sources = vec![PathBuf::from(FILE)];
@@ -1440,18 +1635,18 @@ mod tests {
1440 };1635 };
1441 assert!(1636 assert!(
1442 err(vec![linked(0, 0, 3, 7), linked(3, 3, 5, 7)], Vec::new())1637 err(vec![linked(0, 0, 3, 7), linked(3, 3, 5, 7)], Vec::new())
1443- .contains("link 7 names two clips in the video lane"),1638+ .contains("link 7 names two clips in the V1 lane"),
1444 "a duplicate id inside one lane is refused by name"1639 "a duplicate id inside one lane is refused by name"
1445 );1640 );
1446 assert!(1641 assert!(
1447 err(vec![linked(0, 0, 5, 2)], vec![linked(0, 0, 3, 2)])1642 err(vec![linked(0, 0, 5, 2)], vec![linked(0, 0, 3, 2)])
1448- .contains("link 2 covers [0, 5) in video and [0, 3) in audio"),1643+ .contains("link 2 covers [0, 5) in V1 and [0, 3) in A1"),
1449 "a pair that does not cover one span is refused by name"1644 "a pair that does not cover one span is refused by name"
1450 );1645 );
1451 // A one-sided link is *not* an error: it is what a lift leaves behind.1646 // A one-sided link is *not* an error: it is what a lift leaves behind.
1452 let mut p = Project::single(FILE, 9);1647 let mut p = Project::single(FILE, 9);
1453- assert!(p.lift(Lane::Audio, 0));1648+ assert!(p.lift(Lane::A1, 0));
1454- let (sources, video, audio) = p.clone().without_orphan_sources();1649+ let (sources, video, audio) = p.clone().without_orphan_sources().expect("two lanes");
1455 assert!(1650 assert!(
1456 Project::from_parts(sources, video, audio).is_ok(),1651 Project::from_parts(sources, video, audio).is_ok(),
1457 "a lifted lane's project has to load again"1652 "a lifted lane's project has to load again"
@@ -1459,8 +1654,11 @@ mod tests {
1459 1654
1460 // The edits: nothing below may break either rule.1655 // The edits: nothing below may break either rule.
1461 let consistent = |p: &Project, what: &str| {1656 let consistent = |p: &Project, what: &str| {
1462- let lanes = Lane::ALL.map(|l| p.lane(l).to_vec());1657+ assert!(
1463- assert!(links_are_consistent(&lanes).is_ok(), "{what}: {lanes:?}");1658+ links_are_consistent(&p.lanes).is_ok(),
1659+ "{what}: {:?}",
1660+ p.lanes
1661+ );
1464 };1662 };
1465 let mut p = three();1663 let mut p = three();
1466 let copied = p.clips()[0];1664 let copied = p.clips()[0];
@@ -1468,9 +1666,9 @@ mod tests {
1468 copied.link.is_some(),1666 copied.link.is_some(),
1469 "the clipboard clip carries its group"1667 "the clipboard clip carries its group"
1470 );1668 );
1471- assert!(p.lift(Lane::Video, 0));1669+ assert!(p.lift(Lane::V1, 0));
1472- assert!(p.place(Lane::Video, 0, copied));1670+ assert!(p.place(Lane::V1, 0, copied));
1473- assert!(p.place(Lane::Video, 20, copied), "and again, further out");1671+ assert!(p.place(Lane::V1, 20, copied), "and again, further out");
1474 assert_eq!(1672 assert_eq!(
1475 p.clips().iter().filter(|c| c.link == copied.link).count(),1673 p.clips().iter().filter(|c| c.link == copied.link).count(),
1476 0,1674 0,
@@ -1478,7 +1676,7 @@ mod tests {
1478 );1676 );
1479 consistent(&p, "lift + place twice");1677 consistent(&p, "lift + place twice");
1480 assert!(1678 assert!(
1481- p.place(Lane::Audio, 4, copied),1679+ p.place(Lane::A1, 4, copied),
1482 "over a linked clip's middle"1680 "over a linked clip's middle"
1483 );1681 );
1484 consistent(&p, "place through a grouped clip");1682 consistent(&p, "place through a grouped clip");
@@ -1499,13 +1697,13 @@ mod tests {
1499 #[test]1697 #[test]
1500 fn every_reachable_state_reloads() {1698 fn every_reachable_state_reloads() {
1501 let mut p = Project::single(FILE, 150);1699 let mut p = Project::single(FILE, 150);
1502- assert!(p.place(Lane::Audio, 3, clip(0, 0, 50, 0)));1700+ assert!(p.place(Lane::A1, 3, clip(0, 0, 50, 0)));
1503 assert!(p.split(10), "the lanes are cut apart at 10");1701 assert!(p.split(10), "the lanes are cut apart at 10");
1504 reloads(&p, "place on one lane, then split");1702 reloads(&p, "place on one lane, then split");
1505 1703
1506 let mut p = Project::single(FILE, 150);1704 let mut p = Project::single(FILE, 150);
1507 assert!(p.split(30));1705 assert!(p.split(30));
1508- assert!(p.lift(Lane::Video, 0), "the picture goes, the sound stays");1706+ assert!(p.lift(Lane::V1, 0), "the picture goes, the sound stays");
1509 assert!(p.regroup(30), "only the audio lane can rejoin");1707 assert!(p.regroup(30), "only the audio lane can rejoin");
1510 assert!(p.split(60));1708 assert!(p.split(60));
1511 reloads(&p, "lift, regroup one lane, split");1709 reloads(&p, "lift, regroup one lane, split");
@@ -1532,16 +1730,16 @@ mod tests {
1532 // -- the input that made a placement duplicate an id.1730 // -- the input that made a placement duplicate an id.
1533 let copied = *p1731 let copied = *p
1534 .lane(if next(2) == 0 {1732 .lane(if next(2) == 0 {
1535- Lane::Video1733+ Lane::V1
1536 } else {1734 } else {
1537- Lane::Audio1735+ Lane::A1
1538 })1736 })
1539 .get(next(4) as usize)1737 .get(next(4) as usize)
1540 .unwrap_or(&clip(0, 0, 5, 0));1738 .unwrap_or(&clip(0, 0, 5, 0));
1541 let lane = if next(2) == 0 {1739 let lane = if next(2) == 0 {
1542- Lane::Video1740+ Lane::V1
1543 } else {1741 } else {
1544- Lane::Audio1742+ Lane::A1
1545 };1743 };
1546 let idx = next(4) as usize;1744 let idx = next(4) as usize;
1547 let _ = match next(9) {1745 let _ = match next(9) {
@@ -1563,9 +1761,253 @@ mod tests {
1563 /// The save/load round trip a project must survive: the parts a save writes,1761 /// The save/load round trip a project must survive: the parts a save writes,
1564 /// handed back to the constructor a load goes through.1762 /// handed back to the constructor a load goes through.
1565 fn reloads(p: &Project, what: &str) {1763 fn reloads(p: &Project, what: &str) {
1566- let (sources, video, audio) = p.clone().without_orphan_sources();1764+ let (sources, video, audio) = p.clone().without_orphan_sources().expect("two lanes");
1567 if let Err(e) = Project::from_parts(sources, video, audio) {1765 if let Err(e) = Project::from_parts(sources, video, audio) {
1568 panic!("{what}: saved but would not load: {e}\n{:?}", p.lanes);1766 panic!("{what}: saved but would not load: {e}\n{:?}", p.lanes);
1569 }1767 }
1570 }1768 }
1769+
1770+ /// What [`reloads`] proves for a timeline the file format cannot hold yet:
1771+ /// the two invariants [`Project::from_parts`] checks that are about *lanes*
1772+ /// -- each one sorted and disjoint, and one span per group id -- asserted
1773+ /// directly, since a save of more than two lanes is refused on purpose.
1774+ fn invariants_hold(p: &Project, what: &str) {
1775+ for lane in p.lanes() {
1776+ assert!(
1777+ sorted_disjoint(p.lane(lane)),
1778+ "{what}: {} is out of order or overlaps itself: {:?}",
1779+ lane.label(),
1780+ p.lane(lane)
1781+ );
1782+ }
1783+ if let Err(e) = links_are_consistent(&p.lanes) {
1784+ panic!("{what}: {e}\n{:?}", p.lanes);
1785+ }
1786+ }
1787+
1788+ /// A lane is a lane: `V2` is added, counted, reached by `(kind, ord)`, and
1789+ /// edited without any other lane hearing about it. A handle naming a lane
1790+ /// that is not there reads as empty and refuses to mutate.
1791+ #[test]
1792+ fn a_third_lane_is_a_peer() {
1793+ let mut p = three();
1794+ assert_eq!(p.lane_count(LaneKind::Video), 1);
1795+ assert_eq!(p.lane_count(LaneKind::Audio), 1);
1796+ let v2 = p.add_lane(LaneKind::Video);
1797+ assert_eq!(v2, Lane::new(LaneKind::Video, 1));
1798+ assert_eq!(v2.label(), "V2");
1799+ assert_eq!(p.lane_count(LaneKind::Video), 2);
1800+ assert_eq!(p.lanes(), vec![Lane::V1, Lane::A1, v2]);
1801+ assert!(p.lane(v2).is_empty(), "a new lane holds nothing");
1802+
1803+ // A handle for a lane that is not there: empty, and no mutation takes.
1804+ let v3 = Lane::new(LaneKind::Video, 2);
1805+ assert!(p.lane(v3).is_empty());
1806+ assert!(!p.place(v3, 0, clip(0, 0, 3, 0)), "no lane, no placement");
1807+ assert!(!p.lift(v3, 0));
1808+ assert_eq!(p.lane_count(LaneKind::Video), 2, "and none was made");
1809+
1810+ // Placing on V2 moves nothing else, and the lane can outrun the rest.
1811+ let before = shape(&p);
1812+ assert!(p.place(v2, 4, clip(0, 20, 32, 0)));
1813+ assert_eq!(shape(&p)[0], before[0], "V1 never moved");
1814+ assert_eq!(shape(&p)[1], before[1], "A1 never moved");
1815+ assert_eq!(p.lane_spans(v2), vec![(4, 12)]);
1816+ assert_eq!(p.timeline_frames(), 16, "the last lane to end sets the length");
1817+ assert_eq!(p.map(v2, 5), Some((0, 21)));
1818+ assert_eq!(p.map(v2, 3), None, "V2's own leading gap");
1819+ assert_eq!(
1820+ p.span_at(v2, 0),
1821+ Some(Span {
1822+ start: 0,
1823+ len: 4,
1824+ from: None
1825+ })
1826+ );
1827+ // Every lane still covers the whole timeline, gaps included.
1828+ for l in p.lanes() {
1829+ let spans = p.spans_from(l, 0);
1830+ assert_eq!(
1831+ spans.iter().map(|s| s.len).sum::<u32>(),
1832+ 16,
1833+ "{}",
1834+ l.label()
1835+ );
1836+ }
1837+ // ...and playback still reads V1 and A1, whatever else is there.
1838+ assert_eq!(p.clips(), p.lane(Lane::V1));
1839+ assert_eq!(p.map_timeline(4), p.map(Lane::V1, 4));
1840+ let segments = p.segments_from(0, FPS);
1841+ assert_eq!(segments[..3], three().segments_from(0, FPS)[..]);
1842+ assert_eq!(
1843+ segments[3],
1844+ (None, 0.0, 7.0 / FPS),
1845+ "A1 keeps the clock counting over the picture V2 added"
1846+ );
1847+ invariants_hold(&p, "place on V2");
1848+
1849+ // A lift is that lane's business too, and the lane list undoes.
1850+ assert!(p.lift(v2, 0));
1851+ assert!(p.lane(v2).is_empty());
1852+ assert_eq!(p.timeline_frames(), 9, "V2 no longer runs the longest");
1853+ assert!(p.undo());
1854+ assert_eq!(p.lane_spans(v2), vec![(4, 12)]);
1855+ assert!(p.undo());
1856+ assert!(p.lane(v2).is_empty(), "the placement came off V2");
1857+ assert!(p.undo(), "and one more step takes the lane itself back");
1858+ assert_eq!(p.lane_count(LaneKind::Video), 1);
1859+ assert_eq!(shape(&p), shape(&three()));
1860+ }
1861+
1862+ /// The grouping rule across more than two lanes: a link id is one *span*,
1863+ /// on however many lanes carry it -- not a video/audio pair and not a
1864+ /// pairing by `ord`. So a split shares an id with every lane whose half
1865+ /// lines up, and gives its own to every lane whose half does not.
1866+ #[test]
1867+ fn a_group_id_is_one_span_across_every_lane() {
1868+ let mut p = Project::single(FILE, 9);
1869+ let v2 = p.add_lane(LaneKind::Video);
1870+ assert!(p.place(v2, 0, clip(0, 0, 9, 0)), "three lanes, one span");
1871+ assert!(p.split(4));
1872+ let side = |p: &Project, i: usize| -> Vec<Option<u32>> {
1873+ p.lanes().into_iter().map(|l| p.lane(l)[i].link).collect()
1874+ };
1875+ let (left, right) = (side(&p, 0), side(&p, 1));
1876+ assert!(
1877+ left[0].is_some() && left.iter().all(|id| *id == left[0]),
1878+ "one id for three left halves: {left:?}"
1879+ );
1880+ assert!(right.iter().all(|id| *id == right[0]), "{right:?}");
1881+ assert_ne!(left[0], right[0], "the halves are no longer one take");
1882+ invariants_hold(&p, "split across three lanes");
1883+
1884+ // V2 ends early: same start, so the left halves are one take; different
1885+ // end, so the right halves cannot be.
1886+ let mut p = Project::single(FILE, 9);
1887+ let v2 = p.add_lane(LaneKind::Video);
1888+ assert!(p.place(v2, 0, clip(0, 0, 6, 0)));
1889+ assert!(p.split(3));
1890+ assert_eq!(p.lane(Lane::V1)[0].link, p.lane(v2)[0].link, "same [0, 3)");
1891+ assert_ne!(p.lane(Lane::V1)[1].link, p.lane(v2)[1].link, "[3,9) vs [3,6)");
1892+ assert_eq!(p.lane(Lane::V1)[1].link, p.lane(Lane::A1)[1].link);
1893+ invariants_hold(&p, "split where one lane ends early");
1894+
1895+ // The inverse rejoins all three, and groups them the same way.
1896+ assert!(p.regroup(3));
1897+ assert_eq!(p.lane(Lane::V1)[0].link, p.lane(Lane::A1)[0].link);
1898+ assert_ne!(
1899+ p.lane(Lane::V1)[0].link,
1900+ p.lane(v2)[0].link,
1901+ "V2 rejoins into a span of its own"
1902+ );
1903+ invariants_hold(&p, "regroup across three lanes");
1904+
1905+ // ...and the rule is enforced, not merely produced: two video lanes
1906+ // carrying one id over two spans is refused, by lane name.
1907+ let linked = |out_frame, link| Clip {
1908+ start: 0,
1909+ in_frame: 0,
1910+ out_frame,
1911+ source: 0,
1912+ link: Some(link),
1913+ };
1914+ let lanes = vec![
1915+ LaneData {
1916+ kind: LaneKind::Video,
1917+ clips: vec![linked(3, 4)],
1918+ },
1919+ LaneData {
1920+ kind: LaneKind::Video,
1921+ clips: vec![linked(5, 4)],
1922+ },
1923+ ];
1924+ assert_eq!(
1925+ links_are_consistent(&lanes).unwrap_err().to_string(),
1926+ "link 4 covers [0, 3) in V1 and [0, 5) in V2"
1927+ );
1928+ }
1929+
1930+ /// The model runs ahead of the file format on purpose, so a save of what the
1931+ /// format cannot hold is refused by name rather than silently dropping a
1932+ /// lane -- and a two-lane project still writes exactly the parts it always
1933+ /// did.
1934+ #[test]
1935+ fn a_save_refuses_more_lanes_than_the_format_holds() {
1936+ let mut p = three();
1937+ let before = p.without_orphan_sources().expect("two lanes save");
1938+ let v2 = p.add_lane(LaneKind::Video);
1939+ let err = p.without_orphan_sources().expect_err("refused").to_string();
1940+ assert!(
1941+ err.contains("2 video lanes") && err.contains("newer format"),
1942+ "{err}"
1943+ );
1944+ // Even empty: what cannot be written must not be quietly left behind.
1945+ assert!(p.lane(v2).is_empty());
1946+ assert!(p.undo(), "and the lane undoes");
1947+ assert_eq!(
1948+ p.without_orphan_sources().expect("saveable again"),
1949+ before,
1950+ "byte for byte the same parts a two-lane save always wrote"
1951+ );
1952+
1953+ let mut p = three();
1954+ p.add_lane(LaneKind::Audio);
1955+ assert!(
1956+ p.without_orphan_sources()
1957+ .unwrap_err()
1958+ .to_string()
1959+ .contains("2 audio lanes")
1960+ );
1961+ }
1962+
1963+ /// [`random_edit_sequences_reload`]'s sweep on a timeline that starts with
1964+ /// three lanes and may grow more: every lane's own order and the one
1965+ /// span-per-id rule, after every op. Amended rather than merged into that
1966+ /// test because a >2-lane project cannot round-trip through the v2 file
1967+ /// format -- [`invariants_hold`] checks what a reload would have checked.
1968+ #[test]
1969+ fn random_edit_sequences_keep_many_lanes_consistent() {
1970+ for seed in 0..200u64 {
1971+ let mut rng = seed.wrapping_mul(6_364_136_223_846_793_005).wrapping_add(1);
1972+ let mut next = move |n: u32| {
1973+ rng ^= rng << 13;
1974+ rng ^= rng >> 7;
1975+ rng ^= rng << 17;
1976+ (rng >> 33) as u32 % n
1977+ };
1978+ let mut p = Project::single(FILE, 40);
1979+ let v2 = p.add_lane(LaneKind::Video);
1980+ assert!(p.place(v2, 5, clip(0, 0, 20, 0)));
1981+ let lanes = [Lane::V1, Lane::A1, v2];
1982+ for step in 0..24 {
1983+ let frame = next(44);
1984+ let copied = *p
1985+ .lane(lanes[next(3) as usize])
1986+ .get(next(4) as usize)
1987+ .unwrap_or(&clip(0, 0, 5, 0));
1988+ let lane = lanes[next(3) as usize];
1989+ let idx = next(4) as usize;
1990+ let _ = match next(10) {
1991+ 0 => p.split(frame),
1992+ 1 => p.regroup(frame),
1993+ 2 => p.lift(lane, idx),
1994+ 3 => p.place(lane, frame, copied),
1995+ 4 => p.paste(frame, copied),
1996+ 5 => p.ripple_delete(frame, next(9)),
1997+ 6 => p.delete(idx),
1998+ 7 => p.undo(),
1999+ 8 => {
2000+ p.add_lane(if next(2) == 0 {
2001+ LaneKind::Video
2002+ } else {
2003+ LaneKind::Audio
2004+ });
2005+ true
2006+ }
2007+ _ => p.append_clip(0, 1 + next(9)),
2008+ };
2009+ invariants_hold(&p, &format!("seed {seed}, step {step}"));
2010+ }
2011+ }
2012+ }
1571 }2013 }
crates/engine/tests/export.rsmodified+3 -3
@@ -563,7 +563,7 @@ fn a_leading_audio_gap_keeps_the_sound_after_it_in_place() {
563 let source = asset("test_av.mp4");563 let source = asset("test_av.mp4");
564 let mut session = PlaybackSession::open(&source).expect("open source");564 let mut session = PlaybackSession::open(&source).expect("open source");
565 assert!(session.cut_at(1.0), "cut at 1 s");565 assert!(session.cut_at(1.0), "cut at 1 s");
566- assert!(session.lift_clip(Lane::Audio, 0), "lift the first second");566+ assert!(session.lift_clip(Lane::A1, 0), "lift the first second");
567 session.pause();567 session.pause();
568 let out = out_path("leading_gap");568 let out = out_path("leading_gap");
569 let handle = session.export_to(&out);569 let handle = session.export_to(&out);
@@ -614,8 +614,8 @@ fn exports_a_gapped_timeline_as_black_and_silence() {
614 assert!(session.cut_at(2.0), "split at 2 s");614 assert!(session.cut_at(2.0), "split at 2 s");
615 // Lift the middle out of *both* lanes: one second of black and silence in615 // Lift the middle out of *both* lanes: one second of black and silence in
616 // the middle of a five-second timeline, with the length unchanged.616 // the middle of a five-second timeline, with the length unchanged.
617- assert!(session.lift_clip(Lane::Video, 1));617+ assert!(session.lift_clip(Lane::V1, 1));
618- assert!(session.lift_clip(Lane::Audio, 1));618+ assert!(session.lift_clip(Lane::A1, 1));
619 session.pause();619 session.pause();
620 let timeline = session.timeline_duration();620 let timeline = session.timeline_duration();
621 let frames = (timeline * FPS).round() as u32;621 let frames = (timeline * FPS).round() as u32;
crates/engine/tests/playback.rsmodified+2 -2
@@ -935,7 +935,7 @@ fn a_video_gap_plays_black_without_shortening_the_timeline() {
935 assert!(session.cut_at(2.0), "split at 2 s");935 assert!(session.cut_at(2.0), "split at 2 s");
936 assert!(session.cut_at(3.5), "split at 3.5 s");936 assert!(session.cut_at(3.5), "split at 3.5 s");
937 assert!(937 assert!(
938- session.lift_clip(Lane::Video, 1),938+ session.lift_clip(Lane::V1, 1),
939 "lift the middle picture out"939 "lift the middle picture out"
940 );940 );
941 assert_eq!(941 assert_eq!(
@@ -998,7 +998,7 @@ fn an_audio_gap_is_silent_and_the_clock_keeps_counting() {
998 assert!(session.cut_at(2.0), "split at 2 s");998 assert!(session.cut_at(2.0), "split at 2 s");
999 // Silence over [1, 2) s while the picture plays on -- the two lanes part.999 // Silence over [1, 2) s while the picture plays on -- the two lanes part.
1000 assert!(1000 assert!(
1001- session.lift_clip(Lane::Audio, 1),1001+ session.lift_clip(Lane::A1, 1),
1002 "lift the middle sound out"1002 "lift the middle sound out"
1003 );1003 );
1004 assert_eq!(session.clip_spans().len(), 3, "the video lane is untouched");1004 assert_eq!(session.clip_spans().len(), 3, "the video lane is untouched");
crates/engine/tests/saveload.rsmodified+1 -1
@@ -79,7 +79,7 @@ fn a_version_1_project_loads_fully_grouped_and_saves_as_version_2() {
79 "v1 clips queue up, the second starting where the first ended"79 "v1 clips queue up, the second starting where the first ended"
80 );80 );
81 assert_eq!(81 assert_eq!(
82- loaded.lane_spans_by_source(engine::project::Lane::Audio),82+ loaded.lane_spans_by_source(engine::project::Lane::A1),
83 loaded.clip_spans_by_source(),83 loaded.clip_spans_by_source(),
84 "both lanes, fully grouped: a v1 timeline had no holes"84 "both lanes, fully grouped: a v1 timeline had no holes"
85 );85 );