From 9a6ef8129737597c7f8c06669fd11db2e0da33d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 10 Aug 2026 14:46:43 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(timeline):=20the=20last=20clip?= =?UTF-8?q?=20deletes=20and=20the=20timeline=20empties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The never-empty-TIMELINE invariant is gone: an emptied timeline is now a state of the model, not an edge case a refusal kept unreachable. Emptiness is honest all the way down -- `PlaybackSession::span` is an `Option` whose `None` *is* the empty timeline, and `start_span` feeds it one black frame, so the viewer shows the nothing that is there rather than the last picture of the clip that was deleted. * `Project::lift` and `Project::ripple_delete` refuse only what is not an edit (a bad index, an empty range, a delete with nothing left to take -- the last so a no-op still costs no undo step); * `Project::from_parts` and the `.edith` loader take an all-empty project and refuse a *laneless* one instead, which is the invariant that was really being defended; * `without_orphan_sources` keeps source 0 when no clip names anything: it carries the frame rate the timeline counts in, and pruning it wrote a project that could not be loaded back; * the app's two "the timeline cannot be emptied" notices are gone, and an export of an empty timeline is refused by name instead of writing a file of no frames. The never-empty-CLIP invariant (len >= 1) is untouched. --- crates/app/src/main.rs | 11 +++- crates/engine/src/edith.rs | 44 ++++++++------- crates/engine/src/playback.rs | 88 +++++++++++++++++++---------- crates/engine/src/project.rs | 99 ++++++++++++++++++++++----------- crates/engine/tests/playback.rs | 71 +++++++++++++++++++++++ 5 files changed, 232 insertions(+), 81 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 0f873f9..7eaa60f 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -929,7 +929,7 @@ impl Player { _ => false, }; if selected.is_some() && !deleted { - self.notice = Some("NOTHING DELETED — the timeline cannot be emptied".into()); + self.notice = Some("NOTHING DELETED — that clip is no longer there".into()); } if deleted { self.reset_after_reseek(); @@ -949,7 +949,7 @@ impl Player { if session.lift_clip(lane, idx) { self.reset_after_reseek(); } else { - self.notice = Some("NOTHING LIFTED — the timeline cannot be emptied".into()); + self.notice = Some("NOTHING LIFTED — that half is no longer there".into()); } } (Some(_), None) => { @@ -1503,6 +1503,13 @@ impl Player { cx.notify(); return; }; + // An emptied timeline is a timeline; it is simply not a file. Refused by + // name here rather than written as a project of no frames. + if session.is_empty() { + self.notice = Some("NOTHING TO EXPORT — the timeline is empty".into()); + cx.notify(); + return; + } session.pause(); self.export = Some(session.export_to_with(&self.export_path, &settings)); // The card has been answered; the progress line takes the panel from diff --git a/crates/engine/src/edith.rs b/crates/engine/src/edith.rs index 947bee0..0e5208c 100644 --- a/crates/engine/src/edith.rs +++ b/crates/engine/src/edith.rs @@ -504,9 +504,9 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result { } } } - if doc.lanes.iter().all(|(_, clips)| clips.is_empty()) { - return Err("no clips: an empty timeline is not a project".into()); - } + // A file whose lanes are all empty *is* a project -- the emptied timeline, + // saved. What it may not be is laneless; [`crate::Project::from_parts`] + // refuses that one, by the name it has there. Ok(doc) } @@ -870,13 +870,10 @@ mod tests { ] { assert_eq!(parse(file.as_bytes(), &dir).unwrap_err().to_string(), want); } - // Lanes and nothing on them is not a project. - assert_eq!( - parse(b"edith 4\nsource 0 a.mp4\nvideo 1\naudio 1\n", &dir) - .unwrap_err() - .to_string(), - "no clips: an empty timeline is not a project" - ); + // Lanes and nothing on them is the emptied timeline, saved: a project. + let empty = parse(b"edith 4\nsource 0 a.mp4\nvideo 1\naudio 1\n", &dir).expect("parse"); + assert!(empty.lanes.iter().all(|(_, clips)| clips.is_empty())); + assert_eq!(empty.lanes.len(), 2, "and its lanes survive the round trip"); } /// One band, spelled the way an eq line spells it. @@ -1539,19 +1536,28 @@ mod tests { } } + /// The emptied timeline writes and reads back: every lane declared, no clip + /// on any of them, and the source that gave the project its frame rate still + /// named. Nothing about the format changes for it -- an empty lane already + /// had a line of its own. #[test] - fn a_project_without_clips_is_not_a_project() { + fn a_project_without_clips_round_trips() { let dir = PathBuf::from("/proj"); + let source = Source { + path: PathBuf::from("/proj/a.mp4"), + audio_stream: 0, + }; + let bytes = flat(&dir, &[source.clone()], &two(Vec::new(), Vec::new()), 0); + let back = parse(&bytes, &dir).expect("an emptied timeline is a project"); + assert_eq!(back.sources, vec![source]); + assert_eq!(back.lanes, two(Vec::new(), Vec::new())); + assert_eq!(back.playhead, 0); + // Older dialects, where the two lanes are implied rather than declared. assert_eq!( - parse(b"edith 1\nsource a.mp4\n", &dir) - .unwrap_err() - .to_string(), - "no clips: an empty timeline is not a project" - ); - assert_eq!( - parse(b"edith 1\n", &dir).unwrap_err().to_string(), - "no clips: an empty timeline is not a project" + parse(b"edith 1\nsource a.mp4\n", &dir).expect("v1").lanes, + two(Vec::new(), Vec::new()) ); + assert!(parse(b"edith 1\n", &dir).expect("a project of nothing").sources.is_empty()); } /// Every truncation of a good file either parses or refuses; none panics. diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index ead2615..b819601 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -128,7 +128,13 @@ pub struct PlaybackSession { /// clip index: a `split` cuts the clip under a running worker, and only the /// mapping survives that. A span with no source is a *gap*, and the worker /// feeding it emits black frames indexed from zero. - span: Span, + /// + /// `None` is the *emptied* timeline -- no clip on any lane, so there is no + /// stretch to be inside of. It is a state, not a failure: the picture is + /// black ([`start_span`](Self::start_span) feeds one black frame for it), + /// the sound is silence, the duration is zero, and placing anything reseeks + /// straight back out of it. + span: Option, /// The last clip has been played out; see [`PlaybackSession::is_eos`]. eos: bool, } @@ -174,7 +180,7 @@ impl PlaybackSession { // One clip per lane covering the file, so timeline == source until the // first edit -- and the range opened above is exactly that clip's. let project = Project::single(&path, meta.frame_count); - let span = project.composite_span_at(0).expect("never empty"); + let span = project.composite_span_at(0); Ok(Self { meta, native: (meta.width, meta.height), @@ -290,7 +296,7 @@ impl PlaybackSession { let playhead = doc.playhead; let project = Project::from_parts(doc.sources, doc.lanes, doc.eq, doc.color)?; - let span = project.composite_span_at(0).expect("never empty"); + let span = project.composite_span_at(0); // Last, because it is the one thing here that cannot be taken back: the // feeder thread outlives the `Audio` value (it holds its own clones) and // only a session's `drop` retires it, so a refusal above this line would @@ -370,9 +376,12 @@ impl PlaybackSession { match self.frames.try_recv() { Ok(mut frame) => { // A gap's worker indexes from zero, a decoder's from its in - // point: `base` is whichever this span started at. - let base = self.span.from.map_or(0, |(_, in_frame)| in_frame); - frame.index = self.span.start + frame.index.saturating_sub(base); + // point: `base` is whichever this span started at. An empty + // timeline has no span, and its one black frame is frame 0. + let (start, base) = self + .span + .map_or((0, 0), |s| (s.start, s.from.map_or(0, |(_, i)| i))); + frame.index = start + frame.index.saturating_sub(base); return Some(frame); } Err(TryRecvError::Empty) => return None, @@ -415,35 +424,47 @@ impl PlaybackSession { /// than remembered as a clip index, because a `split` while playing cuts the /// clip under the running worker and only the mapping stays true. fn next_clip(&mut self) -> bool { - let next = self.span.end(); + // No span is the emptied timeline: it was played out the moment its one + // black frame went by, and there is no "next" to walk to. + let next = match self.span { + Some(span) => span.end(), + None => return false, + }; let Some(span) = self.project.composite_span_at(next) else { return false; }; // We only get here on a disconnect, so the old worker has already // returned; cancel anyway, so `retire` treats every path alike. self.worker.cancel(); - self.start_span(span); + self.start_span(Some(span)); true } /// Points the video worker at `span`: a decoder over its source range, or a - /// black-frame generator for a gap. The old worker must already have been - /// cancelled -- this is the half both `seek` and `next_clip` share. + /// black-frame generator for a gap -- and for `None`, the emptied timeline, + /// which is one frame of black so the viewer shows the nothing that is + /// there rather than the last picture of the clip that was deleted. The old + /// worker must already have been cancelled -- this is the half both `seek` + /// and `next_clip` share. /// /// A source that will not open leaves the *span* installed anyway: the /// timeline still moves, there are simply no more pictures, and the /// disconnected receiver carries the session on to the next span. - fn start_span(&mut self, span: Span) { - let opened = match span.from { + fn start_span(&mut self, span: Option) { + let opened = match span { // The grade is the composite's at this frame -- the same clip the // span itself came from -- and it is constant across the span, so // the worker carries it and every frame it converts wears it. - Some((source, in_frame)) => DecodeSession::open_worker( + Some(Span { + start, + len, + from: Some((source, in_frame)), + }) => DecodeSession::open_worker( &self.project.sources()[source].path, in_frame, - in_frame + span.len, + in_frame + len, self.project - .composite_color_at(span.start) + .composite_color_at(start) .copied() .unwrap_or_default(), // ...and the canvas it is placed on: the project's resolution @@ -452,15 +473,18 @@ impl PlaybackSession { Composer::new( self.meta.width, self.meta.height, - self.project.composite_fit_at(span.start), + self.project.composite_fit_at(start), ), ) .map(|(_, stream)| stream) - .inspect_err(|e| eprintln!("timeline frame {}: video open failed: {e}", span.start)), - None => Ok(DecodeSession::open_black( + .inspect_err(|e| eprintln!("timeline frame {start}: video open failed: {e}")), + // A gap: black for as long as it runs. An emptied timeline has no + // span at all and gets one frame of it -- enough to put black on + // screen, and it ends where the timeline does, at once. + gap => Ok(DecodeSession::open_black( self.meta.width, self.meta.height, - span.len, + gap.map_or(1, |s| s.len), )), }; if let Ok(stream) = opened { @@ -480,6 +504,14 @@ impl PlaybackSession { f64::from(self.project.timeline_frames()) / self.meta.frame_rate } + /// Whether no lane holds anything: the emptied timeline, which plays black + /// and silent and is zero seconds long. A state, not a failure -- but the + /// one a caller with nothing to render (an export) has to refuse by name + /// rather than write a file of no frames. + pub fn is_empty(&self) -> bool { + self.project.timeline_frames() == 0 + } + /// `(start, len)` per clip in timeline seconds, in order: what a clips lane /// needs to lay itself out. Selection is the caller's business. pub fn clip_spans(&self) -> Vec<(f64, f64)> { @@ -575,8 +607,9 @@ impl PlaybackSession { /// Lifts one lane's clip out, leaving a gap: black frames on the video lane, /// silence on the audio one, and nothing else moves. Reseeks, because what - /// the playhead sits on has changed. `false` for a bad index and for the - /// lift that would leave the whole timeline empty. + /// the playhead sits on has changed. `false` for a bad index -- the lift of + /// the last placement there is empties the timeline, which is a state + /// ([`is_empty`](Self::is_empty)) and one undo away. pub fn lift_clip(&mut self, lane: Lane, idx: usize) -> bool { self.edit(|p| p.lift(lane, idx)) } @@ -775,7 +808,8 @@ impl PlaybackSession { /// on every lane. Unlike a split this *does* move every following frame, so /// the session reseeks to wherever the playhead now points. /// [`lift_clip`](Self::lift_clip) is the one that leaves a hole instead. - /// `false` for a bad index or the last remaining clip. + /// `false` for a bad index; the last remaining clip goes like any other and + /// leaves the timeline empty ([`is_empty`](Self::is_empty)). /// /// The lane travels because the index is a lane's own: `V2`'s third clip is /// not `V1`'s, and a front-end that could only say "the third clip" would @@ -966,12 +1000,10 @@ impl PlaybackSession { // [`retire`](Self::retire), which is what keeps a scrub off the price // of a VA-API init. self.worker.cancel(); - // `target` is inside the timeline (never empty), so this always spans; - // the span runs from there to the end of whatever it landed in -- a - // clip, or a gap, which starts a black-frame worker instead. - if let Some(span) = self.project.composite_span_at(target) { - self.start_span(span); - } + // The span runs from `target` to the end of whatever it landed in -- a + // clip, or a gap, which starts a black-frame worker instead. `None` is + // the emptied timeline, black too, and `start_span` says so. + self.start_span(self.project.composite_span_at(target)); self.eos = false; let mut audio_running = false; diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index aaabd70..d238c4b 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -299,10 +299,16 @@ impl Project { /// [`Project::undo`] is `false` until the first edit of the new session. /// This is the one door untrusted parts come in through, so every invariant /// every other constructor keeps is checked here, by name and in release: - /// every lane empty, an empty clip, a clip naming a source (or an equalizer, + /// no lanes at all, an empty clip, a clip naming a source (or an equalizer, /// or a colour) that is not there, a clip whose end overflows, a lane that is /// unsorted or self-overlapping, and the grouping rules of [`Clip::link`] /// below. + /// + /// A project whose lanes are all *empty* is not among them: an emptied + /// timeline is a project like any other -- it plays black and silent, it + /// saves, and it loads back. What a project cannot be is laneless, because + /// [`Project::lanes`] is what a front-end lays out and what every `Lane` + /// handle indexes into. pub fn from_parts( sources: Vec, lanes: Vec<(LaneKind, Vec)>, @@ -315,8 +321,8 @@ impl Project { if let Some(bad) = color.iter().position(|p| !color_finite(p)) { return Err(format!("color {bad} holds a value that is not a finite number").into()); } - if lanes.iter().all(|(_, clips)| clips.is_empty()) { - return Err("every lane is empty: that is not a project".into()); + if lanes.is_empty() { + return Err("no lanes at all: that is not a project".into()); } let lanes: Vec = lanes .into_iter() @@ -421,9 +427,8 @@ impl Project { /// that could not be taken back would be the one edit with no way out. /// Nothing plays differently until something is placed on it. /// - /// The new lane being empty is fine even though [`Project::from_parts`] - /// refuses an all-empty project: the lanes that were there still hold the - /// timeline, and "no lane holds anything" is what that door refuses. + /// An empty lane is a lane like any other -- so is a whole project of them + /// ([`Project::from_parts`]); nothing plays until something is placed. pub fn add_lane(&mut self, kind: LaneKind) -> Lane { self.snapshot(); self.lanes.push(LaneData { @@ -525,6 +530,11 @@ impl Project { /// [`set_color`](Project::set_color) leaves settings nothing plays behind, /// and this is the one moment they can go -- the indexes that survive it are /// only the ones a clip names. + /// + /// One exception, and it is the emptied timeline's: a project no clip plays + /// from still keeps source 0. It is the file a session is scaffolded from -- + /// its frame rate is the timeline's and is written nowhere else -- so a save + /// that pruned it would write a project that cannot be loaded back at all. pub fn without_orphan_sources(&self) -> Parts { let mut moved = vec![None; self.sources.len()]; let mut sources = Vec::new(); @@ -566,6 +576,9 @@ impl Project { }); } } + if sources.is_empty() { + sources.extend(self.sources.first().cloned()); + } ( sources, lanes.into_iter().map(|l| (l.kind, l.clips)).collect(), @@ -1069,13 +1082,12 @@ impl Project { } /// Lift the clip at `idx` out of `lane`, leaving a gap: black frames or - /// silence, and nothing else moves. Refused for an out-of-range index (which - /// a lane that is not there always is) and for the lift that would leave - /// *every* lane empty -- an empty timeline is the front-end's state, not a - /// project's (see the never-empty invariant). + /// silence, and nothing else moves. Refused only for an out-of-range index + /// (which a lane that is not there always is) -- lifting the last placement + /// there is leaves an *empty* timeline, which is a state the project holds + /// like any other and an undo brings back. pub fn lift(&mut self, lane: Lane, idx: usize) -> bool { - let placed: usize = self.lanes.iter().map(|l| l.clips.len()).sum(); - if idx >= self.lane(lane).len() || placed == 1 { + if idx >= self.lane(lane).len() { return false; } self.snapshot(); @@ -1085,23 +1097,17 @@ impl Project { /// Cut the timeline frames `[at, at + len)` out of *every* lane and close /// the hole: everything after slides back by `len`. The rippling delete -- - /// [`lift`](Project::lift) is the one that leaves a gap. Refused for an - /// empty range and when it would leave every lane empty. + /// [`lift`](Project::lift) is the one that leaves a gap. Refused only for an + /// empty range; a delete that leaves nothing behind empties the timeline, + /// which is a state like any other and one undo away. pub fn ripple_delete(&mut self, at: u32, len: u32) -> bool { if len == 0 { return false; } - let survivors: usize = self - .lanes - .iter() - .map(|l| { - l.clips - .iter() - .filter(|c| c.start < at || c.end() > at + len) - .count() - }) - .sum(); - if survivors == 0 { + // Nothing reaches past `at`: there is nothing to cut and nothing to + // slide back, and a delete that changes nothing must not cost an undo + // step (see [`snapshot`](Project::snapshot)). + if !self.lanes.iter().flat_map(|l| &l.clips).any(|c| c.end() > at) { return false; } self.snapshot(); @@ -1892,7 +1898,11 @@ mod tests { assert!(!p.delete(2), "index past the end"); assert!(p.delete(1)); - assert!(!p.delete(0), "the last remaining clip stays"); + assert!(p.delete(0), "and the last remaining clip goes too"); + assert_eq!(p.clips().len(), 0); + assert_eq!(p.timeline_frames(), 0, "the timeline is emptiable"); + assert!(!p.delete(0), "there is nothing left to delete"); + assert!(p.undo(), "one gesture, one undo"); assert_eq!(p.clips().len(), 1); } @@ -1943,13 +1953,28 @@ mod tests { } } + /// The timeline is emptiable: the last placement comes off like any other, + /// the project holds "nothing on any lane" as a state, and one undo per + /// gesture brings it back. #[test] - fn the_last_clip_of_the_last_lane_cannot_be_lifted() { + fn the_last_clip_of_the_last_lane_lifts_and_undoes() { let mut p = Project::single(FILE, 9); assert!(p.lift(Lane::A1, 0), "a silent timeline is fine"); - assert!(!p.lift(Lane::V1, 0), "an empty one is not"); + assert!(p.lift(Lane::V1, 0), "and an empty one is a timeline too"); + assert_eq!(p.timeline_frames(), 0); + assert_eq!(p.composite_span_at(0), None, "nothing to show"); + assert!(p.audio_segments_from(0, FPS).len() == 1, "one all-gap list"); assert!(!p.lift(Lane::A1, 0), "index past the end"); - assert_eq!(p.timeline_frames(), 9); + assert!(p.undo(), "and the last lift comes back"); + assert_eq!(p.lane_spans(Lane::V1), vec![(0, 9)]); + // A saved-and-loaded empty timeline is a project like any other, and it + // still names the file its frame rate came from. + assert!(p.lift(Lane::V1, 0)); + let (sources, lanes, eq, color) = p.without_orphan_sources(); + assert_eq!(sources.len(), 1, "source 0 survives an emptied timeline"); + let back = Project::from_parts(sources, lanes, eq, color).expect("an empty project loads"); + assert_eq!(back.timeline_frames(), 0); + assert_eq!(back.lanes().len(), 2, "and it kept its lanes"); } /// What a keyboard selection walks: one answer per lane, gaps included -- @@ -2021,7 +2046,16 @@ mod tests { assert_eq!(shape(&p)[1], shape(&p)[0]); assert_eq!(p.timeline_frames(), 5); assert!(!p.ripple_delete(0, 0), "an empty range is not a delete"); - assert!(!p.ripple_delete(0, 100), "and one that empties every lane"); + assert!(p.undo()); + assert_eq!(shape(&p), shape(&three())); + // One that takes everything is a delete like any other: the timeline + // empties, and the undo it cost brings it back whole. + assert!(p.ripple_delete(0, 100), "the timeline is emptiable"); + assert_eq!(p.timeline_frames(), 0); + assert!( + !p.ripple_delete(0, 100), + "and a delete with nothing left to take is not an undo step" + ); assert!(p.undo()); assert_eq!(shape(&p), shape(&three())); } @@ -2472,7 +2506,8 @@ mod tests { assert!(p.split(4), "...and is editable from there"); assert!(p.undo()); - // A lane may be empty; every lane may not, and neither may no lane. + // A lane may be empty, and so may every lane -- an emptied timeline is a + // project. No lane at all is not one: there would be nothing to place on. assert!( Project::from_parts( sources.clone(), @@ -2489,7 +2524,7 @@ mod tests { Vec::new(), Vec::new(), ) - .is_err() + .is_ok() ); assert!(Project::from_parts(sources.clone(), Vec::new(), Vec::new(), Vec::new()).is_err()); let bad: [Vec; 5] = [ diff --git a/crates/engine/tests/playback.rs b/crates/engine/tests/playback.rs index d4c7ff1..61dec86 100644 --- a/crates/engine/tests/playback.rs +++ b/crates/engine/tests/playback.rs @@ -1122,3 +1122,74 @@ fn an_audio_gap_is_silent_and_the_clock_keeps_counting() { ); eprintln!("audio gap: clock at {now:.3}s of {duration:.3}s, frame {last_index:?}"); } + +/// The emptied timeline, end to end: the last clip deletes like any other, what +/// is left plays as black and silence with a duration of zero, it saves and +/// loads back as the project it is, and one undo brings the clip back. Silent +/// fixture, so this runs anywhere. +#[test] +fn an_emptied_timeline_plays_black_saves_loads_and_undoes() { + let path = asset("test_baseline.mp4"); + let mut session = open(&path); + let whole = session.timeline_duration(); + assert!(whole > 0.0); + + // The sole take goes -- picture and sound of it, on every lane at once. + assert!( + session.delete_clip(Lane::V1, 0), + "the last clip deletes like any other" + ); + assert!(session.is_empty(), "and the timeline is empty"); + assert_eq!(session.timeline_duration(), 0.0); + assert!(session.clip_spans().is_empty()); + assert_eq!(session.lanes().len(), 2, "the lanes are still there"); + + // It scrubs: every seek lands at zero and shows black rather than the + // picture of the clip that was deleted. + for t in [0.0, -1.0, whole, 1e9] { + session.seek(t); + assert_eq!(session.now(), 0.0, "seek to {t} on an empty timeline"); + let deadline = Instant::now() + Duration::from_secs(5); + let mut black = None; + while black.is_none() && Instant::now() < deadline { + session.tick(); + black = session.try_frame(); + sleep(Duration::from_millis(4)); + } + let frame = black.expect("an empty timeline shows one black frame"); + assert_eq!(frame.index, 0); + assert!( + frame.bgra.chunks_exact(4).all(|p| p[..3] == [0, 0, 0]), + "and it is black" + ); + } + // It plays: nothing to show, so it is at its end at once, and nothing hangs. + session.play(); + let mut last_index = None; + run_for(&mut session, &mut last_index, Duration::from_millis(200)); + assert!(session.is_eos(), "an empty timeline is played out at once"); + session.pause(); + + // It saves and loads back -- still a project, still two lanes, and still + // naming the file whose frame rate the timeline counts in. + let dir = std::env::temp_dir().join(format!("ve_empty_{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let project = dir.join("empty.edith"); + session + .save_project(&project) + .expect("save an empty timeline"); + let loaded = PlaybackSession::open_project(&project).expect("load it back"); + assert!(loaded.is_empty(), "what came back is the empty timeline"); + assert_eq!(loaded.lanes().len(), 2); + assert_eq!(loaded.sources().len(), 1, "source 0 is kept, orphan or not"); + assert_eq!(loaded.meta().frame_rate, session.meta().frame_rate); + drop(loaded); + let _ = std::fs::remove_dir_all(&dir); + + // ...and one gesture is one undo: the take comes back whole. + assert!(session.undo(), "the delete undoes"); + assert!(!session.is_empty()); + assert!((session.timeline_duration() - whole).abs() < 1e-9); + assert_eq!(session.clip_spans().len(), 1); +}