forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'worktree-agent-ab8e2cda98faad2e0'

Browse files at this commit

2dd4b740d1c175aa3ac8bfb145471610be0f4841Ahmet Kaan GümüşParent: c3b6ce2dc82aff
crates/app/src/main.rsmodified+12 -2
@@ -988,7 +988,7 @@ impl Player {
988988 _ => false,
989989 };
990990 if selected.is_some() && !deleted {
991- self.notice = Some("NOTHING DELETED — the timeline cannot be emptied".into());
991+ self.notice = Some("NOTHING DELETED — that clip is no longer there".into());
992992 }
993993 if deleted {
994994 self.reset_after_reseek();
@@ -1008,7 +1008,7 @@ impl Player {
10081008 if session.lift_clip(lane, idx) {
10091009 self.reset_after_reseek();
10101010 } else {
1011- self.notice = Some("NOTHING LIFTED — the timeline cannot be emptied".into());
1011+ self.notice = Some("NOTHING LIFTED — that half is no longer there".into());
10121012 }
10131013 }
10141014 (Some(_), None) => {
@@ -1609,6 +1609,16 @@ impl Player {
16091609 cx.notify();
16101610 return;
16111611 };
1612+ // An emptied timeline is a timeline; it is simply not a file. Refused by
1613+ // name here rather than written as a project of no frames -- and the
1614+ // engine refuses it again on the worker (`export::start`), so a caller
1615+ // that is not this button cannot get past it either. Two fences on
1616+ // purpose: this one is the one with a keystroke to blame.
1617+ if session.is_empty() {
1618+ self.notice = Some("NOTHING TO EXPORT — the timeline is empty".into());
1619+ cx.notify();
1620+ return;
1621+ }
16121622 session.pause();
16131623 self.export = Some(session.export_to_with(&self.export_path, &settings));
16141624 // The card has been answered; the progress line takes the panel from
crates/engine/src/edith.rsmodified+25 -19
@@ -504,9 +504,9 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
504504 }
505505 }
506506 }
507- if doc.lanes.iter().all(|(_, clips)| clips.is_empty()) {
508- return Err("no clips: an empty timeline is not a project".into());
509- }
507+ // A file whose lanes are all empty *is* a project -- the emptied timeline,
508+ // saved. What it may not be is laneless; [`crate::Project::from_parts`]
509+ // refuses that one, by the name it has there.
510510 Ok(doc)
511511 }
512512
@@ -870,13 +870,10 @@ mod tests {
870870 ] {
871871 assert_eq!(parse(file.as_bytes(), &dir).unwrap_err().to_string(), want);
872872 }
873- // Lanes and nothing on them is not a project.
874- assert_eq!(
875- parse(b"edith 4\nsource 0 a.mp4\nvideo 1\naudio 1\n", &dir)
876- .unwrap_err()
877- .to_string(),
878- "no clips: an empty timeline is not a project"
879- );
873+ // Lanes and nothing on them is the emptied timeline, saved: a project.
874+ let empty = parse(b"edith 4\nsource 0 a.mp4\nvideo 1\naudio 1\n", &dir).expect("parse");
875+ assert!(empty.lanes.iter().all(|(_, clips)| clips.is_empty()));
876+ assert_eq!(empty.lanes.len(), 2, "and its lanes survive the round trip");
880877 }
881878
882879 /// One band, spelled the way an eq line spells it.
@@ -1539,19 +1536,28 @@ mod tests {
15391536 }
15401537 }
15411538
1539+ /// The emptied timeline writes and reads back: every lane declared, no clip
1540+ /// on any of them, and the source that gave the project its frame rate still
1541+ /// named. Nothing about the format changes for it -- an empty lane already
1542+ /// had a line of its own.
15421543 #[test]
1543- fn a_project_without_clips_is_not_a_project() {
1544+ fn a_project_without_clips_round_trips() {
15441545 let dir = PathBuf::from("/proj");
1546+ let source = Source {
1547+ path: PathBuf::from("/proj/a.mp4"),
1548+ audio_stream: 0,
1549+ };
1550+ let bytes = flat(&dir, &[source.clone()], &two(Vec::new(), Vec::new()), 0);
1551+ let back = parse(&bytes, &dir).expect("an emptied timeline is a project");
1552+ assert_eq!(back.sources, vec![source]);
1553+ assert_eq!(back.lanes, two(Vec::new(), Vec::new()));
1554+ assert_eq!(back.playhead, 0);
1555+ // Older dialects, where the two lanes are implied rather than declared.
15451556 assert_eq!(
1546- parse(b"edith 1\nsource a.mp4\n", &dir)
1547- .unwrap_err()
1548- .to_string(),
1549- "no clips: an empty timeline is not a project"
1550- );
1551- assert_eq!(
1552- parse(b"edith 1\n", &dir).unwrap_err().to_string(),
1553- "no clips: an empty timeline is not a project"
1557+ parse(b"edith 1\nsource a.mp4\n", &dir).expect("v1").lanes,
1558+ two(Vec::new(), Vec::new())
15541559 );
1560+ assert!(parse(b"edith 1\n", &dir).expect("a project of nothing").sources.is_empty());
15551561 }
15561562
15571563 /// Every truncation of a good file either parses or refuses; none panics.
crates/engine/src/export.rsmodified+11 -0
@@ -165,7 +165,18 @@ pub fn start(
165165 // The rename is the last step and the only one that publishes a file
166166 // under the name the caller asked for; it stays on the same directory,
167167 // so it is atomic.
168+ //
169+ // An emptied timeline is a legal project and an illegal file: no
170+ // picture, no sound, and a muxer that is never created because no coded
171+ // frame arrives. Refused by name here -- before the format is even
172+ // looked at, so an mp4 and a WAV refuse in the same words -- rather than
173+ // left to write a file of no frames that nothing opens. Every caller of
174+ // `start` comes through this, the app's own door
175+ // (`PlaybackSession::is_empty`) being only the first fence.
168176 let written = match settings.format {
177+ _ if project.timeline_frames() == 0 => {
178+ Err("the timeline is empty: there is nothing to export".into())
179+ }
169180 Format::Mp4 => run(&project, &meta, &part, &worker, &settings),
170181 format => run_audio(&project, &meta, &part, &worker, format),
171182 };
crates/engine/src/playback.rsmodified+60 -28
@@ -128,7 +128,13 @@ pub struct PlaybackSession {
128128 /// clip index: a `split` cuts the clip under a running worker, and only the
129129 /// mapping survives that. A span with no source is a *gap*, and the worker
130130 /// feeding it emits black frames indexed from zero.
131- span: Span,
131+ ///
132+ /// `None` is the *emptied* timeline -- no clip on any lane, so there is no
133+ /// stretch to be inside of. It is a state, not a failure: the picture is
134+ /// black ([`start_span`](Self::start_span) feeds one black frame for it),
135+ /// the sound is silence, the duration is zero, and placing anything reseeks
136+ /// straight back out of it.
137+ span: Option<Span>,
132138 /// The last clip has been played out; see [`PlaybackSession::is_eos`].
133139 eos: bool,
134140 }
@@ -174,7 +180,7 @@ impl PlaybackSession {
174180 // One clip per lane covering the file, so timeline == source until the
175181 // first edit -- and the range opened above is exactly that clip's.
176182 let project = Project::single(&path, meta.frame_count);
177- let span = project.composite_span_at(0).expect("never empty");
183+ let span = project.composite_span_at(0);
178184 Ok(Self {
179185 meta,
180186 native: (meta.width, meta.height),
@@ -290,7 +296,7 @@ impl PlaybackSession {
290296
291297 let playhead = doc.playhead;
292298 let project = Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color)?;
293- let span = project.composite_span_at(0).expect("never empty");
299+ let span = project.composite_span_at(0);
294300 // Last, because it is the one thing here that cannot be taken back: the
295301 // feeder thread outlives the `Audio` value (it holds its own clones) and
296302 // only a session's `drop` retires it, so a refusal above this line would
@@ -370,9 +376,12 @@ impl PlaybackSession {
370376 match self.frames.try_recv() {
371377 Ok(mut frame) => {
372378 // A gap's worker indexes from zero, a decoder's from its in
373- // point: `base` is whichever this span started at.
374- let base = self.span.from.map_or(0, |(_, in_frame)| in_frame);
375- frame.index = self.span.start + frame.index.saturating_sub(base);
379+ // point: `base` is whichever this span started at. An empty
380+ // timeline has no span, and its one black frame is frame 0.
381+ let (start, base) = self
382+ .span
383+ .map_or((0, 0), |s| (s.start, s.from.map_or(0, |(_, i)| i)));
384+ frame.index = start + frame.index.saturating_sub(base);
376385 return Some(frame);
377386 }
378387 Err(TryRecvError::Empty) => return None,
@@ -415,35 +424,47 @@ impl PlaybackSession {
415424 /// than remembered as a clip index, because a `split` while playing cuts the
416425 /// clip under the running worker and only the mapping stays true.
417426 fn next_clip(&mut self) -> bool {
418- let next = self.span.end();
427+ // No span is the emptied timeline: it was played out the moment its one
428+ // black frame went by, and there is no "next" to walk to.
429+ let next = match self.span {
430+ Some(span) => span.end(),
431+ None => return false,
432+ };
419433 let Some(span) = self.project.composite_span_at(next) else {
420434 return false;
421435 };
422436 // We only get here on a disconnect, so the old worker has already
423437 // returned; cancel anyway, so `retire` treats every path alike.
424438 self.worker.cancel();
425- self.start_span(span);
439+ self.start_span(Some(span));
426440 true
427441 }
428442
429443 /// Points the video worker at `span`: a decoder over its source range, or a
430- /// black-frame generator for a gap. The old worker must already have been
431- /// cancelled -- this is the half both `seek` and `next_clip` share.
444+ /// black-frame generator for a gap -- and for `None`, the emptied timeline,
445+ /// which is one frame of black so the viewer shows the nothing that is
446+ /// there rather than the last picture of the clip that was deleted. The old
447+ /// worker must already have been cancelled -- this is the half both `seek`
448+ /// and `next_clip` share.
432449 ///
433450 /// A source that will not open leaves the *span* installed anyway: the
434451 /// timeline still moves, there are simply no more pictures, and the
435452 /// disconnected receiver carries the session on to the next span.
436- fn start_span(&mut self, span: Span) {
437- let opened = match span.from {
453+ fn start_span(&mut self, span: Option<Span>) {
454+ let opened = match span {
438455 // The grade is the composite's at this frame -- the same clip the
439456 // span itself came from -- and it is constant across the span, so
440457 // the worker carries it and every frame it converts wears it.
441- Some((source, in_frame)) => DecodeSession::open_worker(
458+ Some(Span {
459+ start,
460+ len,
461+ from: Some((source, in_frame)),
462+ }) => DecodeSession::open_worker(
442463 &self.project.sources()[source].path,
443464 in_frame,
444- in_frame + span.len,
465+ in_frame + len,
445466 self.project
446- .composite_color_at(span.start)
467+ .composite_color_at(start)
447468 .copied()
448469 .unwrap_or_default(),
449470 // ...and the canvas it is placed on: the project's resolution
@@ -452,15 +473,18 @@ impl PlaybackSession {
452473 Composer::new(
453474 self.meta.width,
454475 self.meta.height,
455- self.project.composite_fit_at(span.start),
476+ self.project.composite_fit_at(start),
456477 ),
457478 )
458479 .map(|(_, stream)| stream)
459- .inspect_err(|e| eprintln!("timeline frame {}: video open failed: {e}", span.start)),
460- None => Ok(DecodeSession::open_black(
480+ .inspect_err(|e| eprintln!("timeline frame {start}: video open failed: {e}")),
481+ // A gap: black for as long as it runs. An emptied timeline has no
482+ // span at all and gets one frame of it -- enough to put black on
483+ // screen, and it ends where the timeline does, at once.
484+ gap => Ok(DecodeSession::open_black(
461485 self.meta.width,
462486 self.meta.height,
463- span.len,
487+ gap.map_or(1, |s| s.len),
464488 )),
465489 };
466490 if let Ok(stream) = opened {
@@ -480,6 +504,14 @@ impl PlaybackSession {
480504 f64::from(self.project.timeline_frames()) / self.meta.frame_rate
481505 }
482506
507+ /// Whether no lane holds anything: the emptied timeline, which plays black
508+ /// and silent and is zero seconds long. A state, not a failure -- but the
509+ /// one a caller with nothing to render (an export) has to refuse by name
510+ /// rather than write a file of no frames.
511+ pub fn is_empty(&self) -> bool {
512+ self.project.timeline_frames() == 0
513+ }
514+
483515 /// `(start, len)` per clip in timeline seconds, in order: what a clips lane
484516 /// needs to lay itself out. Selection is the caller's business.
485517 pub fn clip_spans(&self) -> Vec<(f64, f64)> {
@@ -575,8 +607,9 @@ impl PlaybackSession {
575607
576608 /// Lifts one lane's clip out, leaving a gap: black frames on the video lane,
577609 /// silence on the audio one, and nothing else moves. Reseeks, because what
578- /// the playhead sits on has changed. `false` for a bad index and for the
579- /// lift that would leave the whole timeline empty.
610+ /// the playhead sits on has changed. `false` for a bad index -- the lift of
611+ /// the last placement there is empties the timeline, which is a state
612+ /// ([`is_empty`](Self::is_empty)) and one undo away.
580613 pub fn lift_clip(&mut self, lane: Lane, idx: usize) -> bool {
581614 self.edit(|p| p.lift(lane, idx))
582615 }
@@ -785,7 +818,8 @@ impl PlaybackSession {
785818 /// on every lane. Unlike a split this *does* move every following frame, so
786819 /// the session reseeks to wherever the playhead now points.
787820 /// [`lift_clip`](Self::lift_clip) is the one that leaves a hole instead.
788- /// `false` for a bad index or the last remaining clip.
821+ /// `false` for a bad index; the last remaining clip goes like any other and
822+ /// leaves the timeline empty ([`is_empty`](Self::is_empty)).
789823 ///
790824 /// The lane travels because the index is a lane's own: `V2`'s third clip is
791825 /// not `V1`'s, and a front-end that could only say "the third clip" would
@@ -976,12 +1010,10 @@ impl PlaybackSession {
9761010 // [`retire`](Self::retire), which is what keeps a scrub off the price
9771011 // of a VA-API init.
9781012 self.worker.cancel();
979- // `target` is inside the timeline (never empty), so this always spans;
980- // the span runs from there to the end of whatever it landed in -- a
981- // clip, or a gap, which starts a black-frame worker instead.
982- if let Some(span) = self.project.composite_span_at(target) {
983- self.start_span(span);
984- }
1013+ // The span runs from `target` to the end of whatever it landed in -- a
1014+ // clip, or a gap, which starts a black-frame worker instead. `None` is
1015+ // the emptied timeline, black too, and `start_span` says so.
1016+ self.start_span(self.project.composite_span_at(target));
9851017 self.eos = false;
9861018
9871019 let mut audio_running = false;
crates/engine/src/project.rsmodified+67 -32
@@ -299,10 +299,16 @@ impl Project {
299299 /// [`Project::undo`] is `false` until the first edit of the new session.
300300 /// This is the one door untrusted parts come in through, so every invariant
301301 /// every other constructor keeps is checked here, by name and in release:
302- /// every lane empty, an empty clip, a clip naming a source (or an equalizer,
302+ /// no lanes at all, an empty clip, a clip naming a source (or an equalizer,
303303 /// or a colour) that is not there, a clip whose end overflows, a lane that is
304304 /// unsorted or self-overlapping, and the grouping rules of [`Clip::link`]
305305 /// below.
306+ ///
307+ /// A project whose lanes are all *empty* is not among them: an emptied
308+ /// timeline is a project like any other -- it plays black and silent, it
309+ /// saves, and it loads back. What a project cannot be is laneless, because
310+ /// [`Project::lanes`] is what a front-end lays out and what every `Lane`
311+ /// handle indexes into.
306312 pub fn from_parts(
307313 sources: Vec<Source>,
308314 lanes: Vec<(LaneKind, Vec<Clip>)>,
@@ -315,8 +321,8 @@ impl Project {
315321 if let Some(bad) = color.iter().position(|p| !color_finite(p)) {
316322 return Err(format!("color {bad} holds a value that is not a finite number").into());
317323 }
318- if lanes.iter().all(|(_, clips)| clips.is_empty()) {
319- return Err("every lane is empty: that is not a project".into());
324+ if lanes.is_empty() {
325+ return Err("no lanes at all: that is not a project".into());
320326 }
321327 let lanes: Vec<LaneData> = lanes
322328 .into_iter()
@@ -421,9 +427,8 @@ impl Project {
421427 /// that could not be taken back would be the one edit with no way out.
422428 /// Nothing plays differently until something is placed on it.
423429 ///
424- /// The new lane being empty is fine even though [`Project::from_parts`]
425- /// refuses an all-empty project: the lanes that were there still hold the
426- /// timeline, and "no lane holds anything" is what that door refuses.
430+ /// An empty lane is a lane like any other -- so is a whole project of them
431+ /// ([`Project::from_parts`]); nothing plays until something is placed.
427432 pub fn add_lane(&mut self, kind: LaneKind) -> Lane {
428433 self.snapshot();
429434 self.lanes.push(LaneData {
@@ -525,6 +530,11 @@ impl Project {
525530 /// [`set_color`](Project::set_color) leaves settings nothing plays behind,
526531 /// and this is the one moment they can go -- the indexes that survive it are
527532 /// only the ones a clip names.
533+ ///
534+ /// One exception, and it is the emptied timeline's: a project no clip plays
535+ /// from still keeps source 0. It is the file a session is scaffolded from --
536+ /// its frame rate is the timeline's and is written nowhere else -- so a save
537+ /// that pruned it would write a project that cannot be loaded back at all.
528538 pub fn without_orphan_sources(&self) -> Parts {
529539 let mut moved = vec![None; self.sources.len()];
530540 let mut sources = Vec::new();
@@ -566,6 +576,9 @@ impl Project {
566576 });
567577 }
568578 }
579+ if sources.is_empty() {
580+ sources.extend(self.sources.first().cloned());
581+ }
569582 (
570583 sources,
571584 lanes.into_iter().map(|l| (l.kind, l.clips)).collect(),
@@ -1108,13 +1121,12 @@ impl Project {
11081121 }
11091122
11101123 /// Lift the clip at `idx` out of `lane`, leaving a gap: black frames or
1111- /// silence, and nothing else moves. Refused for an out-of-range index (which
1112- /// a lane that is not there always is) and for the lift that would leave
1113- /// *every* lane empty -- an empty timeline is the front-end's state, not a
1114- /// project's (see the never-empty invariant).
1124+ /// silence, and nothing else moves. Refused only for an out-of-range index
1125+ /// (which a lane that is not there always is) -- lifting the last placement
1126+ /// there is leaves an *empty* timeline, which is a state the project holds
1127+ /// like any other and an undo brings back.
11151128 pub fn lift(&mut self, lane: Lane, idx: usize) -> bool {
1116- let placed: usize = self.lanes.iter().map(|l| l.clips.len()).sum();
1117- if idx >= self.lane(lane).len() || placed == 1 {
1129+ if idx >= self.lane(lane).len() {
11181130 return false;
11191131 }
11201132 self.snapshot();
@@ -1124,23 +1136,17 @@ impl Project {
11241136
11251137 /// Cut the timeline frames `[at, at + len)` out of *every* lane and close
11261138 /// the hole: everything after slides back by `len`. The rippling delete --
1127- /// [`lift`](Project::lift) is the one that leaves a gap. Refused for an
1128- /// empty range and when it would leave every lane empty.
1139+ /// [`lift`](Project::lift) is the one that leaves a gap. Refused only for an
1140+ /// empty range; a delete that leaves nothing behind empties the timeline,
1141+ /// which is a state like any other and one undo away.
11291142 pub fn ripple_delete(&mut self, at: u32, len: u32) -> bool {
11301143 if len == 0 {
11311144 return false;
11321145 }
1133- let survivors: usize = self
1134- .lanes
1135- .iter()
1136- .map(|l| {
1137- l.clips
1138- .iter()
1139- .filter(|c| c.start < at || c.end() > at + len)
1140- .count()
1141- })
1142- .sum();
1143- if survivors == 0 {
1146+ // Nothing reaches past `at`: there is nothing to cut and nothing to
1147+ // slide back, and a delete that changes nothing must not cost an undo
1148+ // step (see [`snapshot`](Project::snapshot)).
1149+ if !self.lanes.iter().flat_map(|l| &l.clips).any(|c| c.end() > at) {
11441150 return false;
11451151 }
11461152 self.snapshot();
@@ -1931,7 +1937,11 @@ mod tests {
19311937
19321938 assert!(!p.delete(2), "index past the end");
19331939 assert!(p.delete(1));
1934- assert!(!p.delete(0), "the last remaining clip stays");
1940+ assert!(p.delete(0), "and the last remaining clip goes too");
1941+ assert_eq!(p.clips().len(), 0);
1942+ assert_eq!(p.timeline_frames(), 0, "the timeline is emptiable");
1943+ assert!(!p.delete(0), "there is nothing left to delete");
1944+ assert!(p.undo(), "one gesture, one undo");
19351945 assert_eq!(p.clips().len(), 1);
19361946 }
19371947
@@ -1982,13 +1992,28 @@ mod tests {
19821992 }
19831993 }
19841994
1995+ /// The timeline is emptiable: the last placement comes off like any other,
1996+ /// the project holds "nothing on any lane" as a state, and one undo per
1997+ /// gesture brings it back.
19851998 #[test]
1986- fn the_last_clip_of_the_last_lane_cannot_be_lifted() {
1999+ fn the_last_clip_of_the_last_lane_lifts_and_undoes() {
19872000 let mut p = Project::single(FILE, 9);
19882001 assert!(p.lift(Lane::A1, 0), "a silent timeline is fine");
1989- assert!(!p.lift(Lane::V1, 0), "an empty one is not");
2002+ assert!(p.lift(Lane::V1, 0), "and an empty one is a timeline too");
2003+ assert_eq!(p.timeline_frames(), 0);
2004+ assert_eq!(p.composite_span_at(0), None, "nothing to show");
2005+ assert!(p.audio_segments_from(0, FPS).len() == 1, "one all-gap list");
19902006 assert!(!p.lift(Lane::A1, 0), "index past the end");
1991- assert_eq!(p.timeline_frames(), 9);
2007+ assert!(p.undo(), "and the last lift comes back");
2008+ assert_eq!(p.lane_spans(Lane::V1), vec![(0, 9)]);
2009+ // A saved-and-loaded empty timeline is a project like any other, and it
2010+ // still names the file its frame rate came from.
2011+ assert!(p.lift(Lane::V1, 0));
2012+ let (sources, lanes, eq, color) = p.without_orphan_sources();
2013+ assert_eq!(sources.len(), 1, "source 0 survives an emptied timeline");
2014+ let back = Project::from_parts(sources, lanes, eq, color).expect("an empty project loads");
2015+ assert_eq!(back.timeline_frames(), 0);
2016+ assert_eq!(back.lanes().len(), 2, "and it kept its lanes");
19922017 }
19932018
19942019 /// What a keyboard selection walks: one answer per lane, gaps included --
@@ -2121,7 +2146,16 @@ mod tests {
21212146 assert_eq!(shape(&p)[1], shape(&p)[0]);
21222147 assert_eq!(p.timeline_frames(), 5);
21232148 assert!(!p.ripple_delete(0, 0), "an empty range is not a delete");
2124- assert!(!p.ripple_delete(0, 100), "and one that empties every lane");
2149+ assert!(p.undo());
2150+ assert_eq!(shape(&p), shape(&three()));
2151+ // One that takes everything is a delete like any other: the timeline
2152+ // empties, and the undo it cost brings it back whole.
2153+ assert!(p.ripple_delete(0, 100), "the timeline is emptiable");
2154+ assert_eq!(p.timeline_frames(), 0);
2155+ assert!(
2156+ !p.ripple_delete(0, 100),
2157+ "and a delete with nothing left to take is not an undo step"
2158+ );
21252159 assert!(p.undo());
21262160 assert_eq!(shape(&p), shape(&three()));
21272161 }
@@ -2572,7 +2606,8 @@ mod tests {
25722606 assert!(p.split(4), "...and is editable from there");
25732607 assert!(p.undo());
25742608
2575- // A lane may be empty; every lane may not, and neither may no lane.
2609+ // A lane may be empty, and so may every lane -- an emptied timeline is a
2610+ // project. No lane at all is not one: there would be nothing to place on.
25762611 assert!(
25772612 Project::from_parts(
25782613 sources.clone(),
@@ -2589,7 +2624,7 @@ mod tests {
25892624 Vec::new(),
25902625 Vec::new(),
25912626 )
2592- .is_err()
2627+ .is_ok()
25932628 );
25942629 assert!(Project::from_parts(sources.clone(), Vec::new(), Vec::new(), Vec::new()).is_err());
25952630 let bad: [Vec<Clip>; 5] = [
crates/engine/tests/playback.rsmodified+100 -0
@@ -11,6 +11,7 @@ use std::path::{Path, PathBuf};
1111 use std::thread::sleep;
1212 use std::time::{Duration, Instant};
1313
14+use engine::export::{ExportSettings, Format};
1415 use engine::project::Lane;
1516 use engine::{DecodeSession, Frame, PlaybackSession};
1617
@@ -1122,3 +1123,102 @@ fn an_audio_gap_is_silent_and_the_clock_keeps_counting() {
11221123 );
11231124 eprintln!("audio gap: clock at {now:.3}s of {duration:.3}s, frame {last_index:?}");
11241125 }
1126+
1127+/// The emptied timeline, end to end: the last clip deletes like any other, what
1128+/// is left plays as black and silence with a duration of zero, it saves and
1129+/// loads back as the project it is, and one undo brings the clip back. Silent
1130+/// fixture, so this runs anywhere.
1131+#[test]
1132+fn an_emptied_timeline_plays_black_saves_loads_and_undoes() {
1133+ let path = asset("test_baseline.mp4");
1134+ let mut session = open(&path);
1135+ let whole = session.timeline_duration();
1136+ assert!(whole > 0.0);
1137+
1138+ // The sole take goes -- picture and sound of it, on every lane at once.
1139+ assert!(
1140+ session.delete_clip(Lane::V1, 0),
1141+ "the last clip deletes like any other"
1142+ );
1143+ assert!(session.is_empty(), "and the timeline is empty");
1144+ assert_eq!(session.timeline_duration(), 0.0);
1145+ assert!(session.clip_spans().is_empty());
1146+ assert_eq!(session.lanes().len(), 2, "the lanes are still there");
1147+
1148+ // It scrubs: every seek lands at zero and shows black rather than the
1149+ // picture of the clip that was deleted.
1150+ for t in [0.0, -1.0, whole, 1e9] {
1151+ session.seek(t);
1152+ assert_eq!(session.now(), 0.0, "seek to {t} on an empty timeline");
1153+ let deadline = Instant::now() + Duration::from_secs(5);
1154+ let mut black = None;
1155+ while black.is_none() && Instant::now() < deadline {
1156+ session.tick();
1157+ black = session.try_frame();
1158+ sleep(Duration::from_millis(4));
1159+ }
1160+ let frame = black.expect("an empty timeline shows one black frame");
1161+ assert_eq!(frame.index, 0);
1162+ assert!(
1163+ frame.bgra.chunks_exact(4).all(|p| p[..3] == [0, 0, 0]),
1164+ "and it is black"
1165+ );
1166+ }
1167+ // It plays: nothing to show, so it is at its end at once, and nothing hangs.
1168+ session.play();
1169+ let mut last_index = None;
1170+ run_for(&mut session, &mut last_index, Duration::from_millis(200));
1171+ assert!(session.is_eos(), "an empty timeline is played out at once");
1172+ session.pause();
1173+
1174+ // Exporting nothing is a refusal in words, not a file of no frames -- and
1175+ // in the *same* words whichever format asked, because the fence sits in
1176+ // `export::start` ahead of the format, not in the mp4 path alone.
1177+ for format in [Format::Mp4, Format::Wav, Format::Flac] {
1178+ let out = std::env::temp_dir().join(format!("ve_nothing_{}", std::process::id()));
1179+ let handle = session.export_to_with(
1180+ &out,
1181+ &ExportSettings {
1182+ format,
1183+ ..ExportSettings::default()
1184+ },
1185+ );
1186+ let deadline = Instant::now() + Duration::from_secs(10);
1187+ let err = loop {
1188+ if let Some(result) = handle.result() {
1189+ break result.expect_err("an empty timeline cannot be exported");
1190+ }
1191+ assert!(Instant::now() < deadline, "{format:?} export never settled");
1192+ sleep(Duration::from_millis(10));
1193+ };
1194+ assert_eq!(
1195+ err.to_string(),
1196+ "the timeline is empty: there is nothing to export",
1197+ "{format:?}"
1198+ );
1199+ assert!(!out.exists(), "{format:?} wrote a file anyway");
1200+ }
1201+
1202+ // It saves and loads back -- still a project, still two lanes, and still
1203+ // naming the file whose frame rate the timeline counts in.
1204+ let dir = std::env::temp_dir().join(format!("ve_empty_{}", std::process::id()));
1205+ let _ = std::fs::remove_dir_all(&dir);
1206+ std::fs::create_dir_all(&dir).expect("scratch dir");
1207+ let project = dir.join("empty.edith");
1208+ session
1209+ .save_project(&project)
1210+ .expect("save an empty timeline");
1211+ let loaded = PlaybackSession::open_project(&project).expect("load it back");
1212+ assert!(loaded.is_empty(), "what came back is the empty timeline");
1213+ assert_eq!(loaded.lanes().len(), 2);
1214+ assert_eq!(loaded.sources().len(), 1, "source 0 is kept, orphan or not");
1215+ assert_eq!(loaded.meta().frame_rate, session.meta().frame_rate);
1216+ drop(loaded);
1217+ let _ = std::fs::remove_dir_all(&dir);
1218+
1219+ // ...and one gesture is one undo: the take comes back whole.
1220+ assert!(session.undo(), "the delete undoes");
1221+ assert!(!session.is_empty());
1222+ assert!((session.timeline_duration() - whole).abs() < 1e-9);
1223+ assert_eq!(session.clip_spans().len(), 1);
1224+}