forge
Explore
Log in

Don't you dare go Hollow

Imported files land in the library, never on the timeline

Browse files at this commit

5cb33d89e8c3b356830324c07dbec1e2a0ea3c6aAhmet Kaan GümüşParent: a3e9dc2
  • feat
    • imported files land in the library, never on the timeline
Show full message
✨ feat(import): imported files land in the library, never on the timeline

An import is not a decision about where a file plays. It registers a source,
notes its native length and stops there; the timeline changes when the user
drags the row onto a lane.

- `PlaybackSession::import`/`import_audio` probe, check and register only,
  returning the source index. No clip, no reseek, and no undo step -- a
  library row changes nothing playable, so there is nothing for `z` to take
  back, and the notice no longer pretends otherwise.
- `PlaybackSession::file_frames` is the native length of a file this session
  has taken in, so a row that has never been placed is placeable at its full
  length. `place_stream_at` takes it from there instead of a `frames`
  argument, and the app drops the clips-derived guesser that returned 0 for a
  source with no clips.
- `PlaybackSession::open_library` is the first import into an empty window:
  the file's canvas, rate and clock over an empty timeline.
- Doors: the Import button, a file dropped on the window and every argv
  argument after the first fill the library. A file *named first* at launch is
  an open, not an import, and still becomes the timeline.
- Fixture + tests: a 25 fps H.264 file, refused by name at both video doors.
crates/app/src/main.rsmodified+138 -170
@@ -19,9 +19,9 @@ use engine::{Clip, ExportHandle, Frame, PlaybackSession};
19 use gpui::{19 use gpui::{
20 AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, FocusHandle,20 AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, FocusHandle,
21 KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels,21 KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels,
22- Point,22+ Point, RenderImage, SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window,
23- RenderImage, SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, WindowBounds,23+ WindowBounds, WindowOptions, canvas, div, img, point, prelude::*, px, relative, rgb, rgba,
24- WindowOptions, canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size,24+ size,
25 };25 };
26 26
27 /// Editor chrome: three grays and one accent, all darker than the picture so the27 /// Editor chrome: three grays and one accent, all darker than the picture so the
@@ -1446,17 +1446,13 @@ impl Player {
1446 cx.notify();1446 cx.notify();
1447 return;1447 return;
1448 }1448 }
1449- let frames = self.session.as_ref().map_or(0, |session| {1449+ // The engine's own length for the file, noted when the import took it
1450- source_frames(lane_clips(session), session.sources(), path)1450+ // in: a row that has never been on a lane is placeable at its full
1451- });1451+ // length, which is the whole point of an import that only fills the
1452- // Zero means nothing on the timeline plays from that file any more1452+ // library.
1453- // -- an undone import leaves the source entry behind (project.rs:264)1453+ let placed = match &mut self.session {
1454- // -- so there is no length to insert and no file to ask for one.1454+ Some(session) => session.place_stream_at(session.now(), path, stream, onto),
1455- let placed = match (&mut self.session, frames) {1455+ None => Ok(false),
1456- (Some(session), 1..) => {
1457- session.place_stream_at(session.now(), path, stream, frames, onto)
1458- }
1459- _ => Ok(false),
1460 };1456 };
1461 match placed {1457 match placed {
1462 Ok(true) => {1458 Ok(true) => {
@@ -1467,9 +1463,7 @@ impl Player {
1467 // says which property disagrees, exactly as a refused import does.1463 // says which property disagrees, exactly as a refused import does.
1468 Err(e) => self.notice = Some(format!("NOTHING ADDED — {e}").into()),1464 Err(e) => self.notice = Some(format!("NOTHING ADDED — {e}").into()),
1469 Ok(false) => {1465 Ok(false) => {
1470- self.notice = Some(1466+ self.notice = Some("NOTHING ADDED — that file could not be placed here".into())
1471- "NOTHING ADDED — no clip on the timeline plays from that file any more".into(),
1472- )
1473 }1467 }
1474 }1468 }
1475 cx.notify();1469 cx.notify();
@@ -1488,37 +1482,48 @@ impl Player {
1488 Some((info.sample_rate, info.channels))1482 Some((info.sample_rate, info.channels))
1489 }1483 }
1490 1484
1491- /// Appends a file to the end of the timeline. A drop is not a key press, so1485+ /// Takes a file into the library and nowhere else: the timeline is not
1492- /// the export guard on the key handler does not cover it and this checks for1486+ /// touched, and the row is dragged onto a lane when it is wanted there. A
1493- /// itself. The engine reseeks, so like a delete it owes the flag reset; a1487+ /// drop is not a key press, so the export guard on the key handler does not
1494- /// refusal is shown as the engine worded it and changes nothing.1488+ /// cover it and this checks for itself. Nothing moves, so nothing reseeks;
1489+ /// a refusal is shown as the engine worded it and changes nothing.
1495 fn import(&mut self, path: &std::path::Path, cx: &mut Context<Self>) {1490 fn import(&mut self, path: &std::path::Path, cx: &mut Context<Self>) {
1496 if self.exporting().is_some() {1491 if self.exporting().is_some() {
1497 return;1492 return;
1498 }1493 }
1499- // An empty window has nothing to append to: there the first file *is*1494+ // An empty window has no library to add to yet: the file opens one, and
1500- // the timeline and is opened as one, which is the same fork a launch1495+ // the timeline under it stays empty, because an import is an import
1501- // makes between its first argument and the rest.1496+ // whether or not a session was already up. A file *named at launch* is
1497+ // the other fork -- that one is an open, and it does become the
1498+ // timeline (`main`).
1502 let text = match self.session.as_mut().map(|session| session.import(path)) {1499 let text = match self.session.as_mut().map(|session| session.import(path)) {
1503- Some(Ok(())) => {1500+ Some(Ok(_)) => format!(
1504- self.reset_after_reseek();1501+ "IMPORTED {} to the library — drag it onto a lane to place it",
1505- format!("IMPORTED {}", file_name(path))1502+ file_name(path)
1506- }1503+ ),
1507 Some(Err(e)) => format!("IMPORT FAILED: {e}"),1504 Some(Err(e)) => format!("IMPORT FAILED: {e}"),
1508- None => self.open_media(path),1505+ None => self.open_media(path, false),
1509 };1506 };
1510 eprintln!("{text}");1507 eprintln!("{text}");
1511 self.notice = Some(text.into());1508 self.notice = Some(text.into());
1512 cx.notify();1509 cx.notify();
1513 }1510 }
1514 1511
1515- /// Takes a file as the whole timeline, which is what an empty window is1512+ /// Takes a file as the session an empty window is waiting for. Everything
1516- /// waiting for. Everything derived from the media -- the clock, the title,1513+ /// derived from the media -- the clock, the title, where an export and a
1517- /// where an export and a save go -- is set here, exactly as a launch with a1514+ /// save go -- is set here, exactly as a launch with a file argument sets
1518- /// file argument sets it. Paused with its first frame showing, like every1515+ /// it. Paused with its first frame showing, like every other way a timeline
1519- /// other way a timeline arrives.1516+ /// arrives.
1520- fn open_media(&mut self, path: &std::path::Path) -> String {1517+ ///
1521- match PlaybackSession::open(path) {1518+ /// `place` is the difference between the two doors that come here: a file
1519+ /// *opened* is the timeline, one *imported* into an empty window fills the
1520+ /// library and leaves the lanes empty for a drag.
1521+ fn open_media(&mut self, path: &std::path::Path, place: bool) -> String {
1522+ let opened = match place {
1523+ true => PlaybackSession::open(path),
1524+ false => PlaybackSession::open_library(path),
1525+ };
1526+ match opened {
1522 Ok(session) => {1527 Ok(session) => {
1523 self.fps = session.meta().frame_rate;1528 self.fps = session.meta().frame_rate;
1524 // Read before the session moves: a file that plays silent says1529 // Read before the session moves: a file that plays silent says
@@ -1534,7 +1539,16 @@ impl Player {
1534 self.project_path = project_path(path);1539 self.project_path = project_path(path);
1535 self.name = file_name(path).into();1540 self.name = file_name(path).into();
1536 self.reset_after_reseek();1541 self.reset_after_reseek();
1537- format!("OPENED {}{}", file_name(path), silent.unwrap_or_default())1542+ let name = file_name(path);
1543+ // The library is filled and the timeline is empty; the only
1544+ // thing that says so is this line, so it says what to do next.
1545+ let what = match place {
1546+ true => format!("OPENED {name}"),
1547+ false => {
1548+ format!("IMPORTED {name} to the library — drag it onto a lane to place it")
1549+ }
1550+ };
1551+ format!("{what}{}", silent.unwrap_or_default())
1538 }1552 }
1539 Err(e) => format!("OPEN FAILED: {e}"),1553 Err(e) => format!("OPEN FAILED: {e}"),
1540 }1554 }
@@ -1553,7 +1567,7 @@ impl Player {
1553 let picked = picked.await;1567 let picked = picked.await;
1554 this.update(cx, |this, cx| match picked {1568 this.update(cx, |this, cx| match picked {
1555 // The same fork the drop handler makes: a project replaces the1569 // The same fork the drop handler makes: a project replaces the
1556- // timeline, media is appended to it.1570+ // timeline, media joins the library.
1557 Ok(Some(path)) if is_project(&path) => this.load_project(&path, cx),1571 Ok(Some(path)) if is_project(&path) => this.load_project(&path, cx),
1558 Ok(Some(path)) => this.import(&path, cx),1572 Ok(Some(path)) => this.import(&path, cx),
1559 // Cancelled: the user already knows what happened.1573 // Cancelled: the user already knows what happened.
@@ -2141,7 +2155,7 @@ impl Render for Player {
2141 return;2155 return;
2142 }2156 }
2143 for path in paths.paths() {2157 for path in paths.paths() {
2144- // A project replaces the timeline, media is appended to it.2158+ // A project replaces the timeline, media joins the library.
2145 if is_project(path) {2159 if is_project(path) {
2146 this.load_project(path, cx);2160 this.load_project(path, cx);
2147 } else {2161 } else {
@@ -2324,12 +2338,13 @@ impl Player {
2324 // the door (the import policy, ledger:436), so the session's own meta2338 // the door (the import policy, ledger:436), so the session's own meta
2325 // describes every row and nothing has to be probed to say so.2339 // describes every row and nothing has to be probed to say so.
2326 let meta = self.session.as_ref().map(PlaybackSession::meta);2340 let meta = self.session.as_ref().map(PlaybackSession::meta);
2327- let clips: Vec<Clip> = self2341+ // Its own length, not one derived from what is on the lanes: a row
2328- .session2342+ // imported and never placed is a row with a length, and it is the
2329- .as_ref()2343+ // length a drag would put down.
2330- .map_or_else(Vec::new, |session| lane_clips(session).copied().collect());
2331 let rows: Vec<_> = library_rows(sources, &self.streams, self.timeline_audio(), |path| {2344 let rows: Vec<_> = library_rows(sources, &self.streams, self.timeline_audio(), |path| {
2332- source_frames(clips.iter(), sources, path)2345+ self.session
2346+ .as_ref()
2347+ .map_or(0, |session| session.file_frames(path))
2333 })2348 })
2334 .into_iter()2349 .into_iter()
2335 .enumerate()2350 .enumerate()
@@ -2461,7 +2476,7 @@ impl Player {
2461 "import",2476 "import",
2462 None,2477 None,
2463 "Import",2478 "Import",
2464- "opens a file chooser — or drop a file on the window".to_string(),2479+ "adds a file to this list — or drop one on the window".to_string(),
2465 !exporting,2480 !exporting,
2466 cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_import(cx)),2481 cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_import(cx)),
2467 )),2482 )),
@@ -2824,8 +2839,10 @@ impl Player {
2824 .id("notice")2839 .id("notice")
2825 .when(exported.is_some(), |d| {2840 .when(exported.is_some(), |d| {
2826 d.tooltip(|_, cx| {2841 d.tooltip(|_, cx| {
2827- cx.new(|_| Tip("Open file location — shows the export in the file manager".into()))2842+ cx.new(|_| {
2828- .into()2843+ Tip("Open file location — shows the export in the file manager".into())
2844+ })
2845+ .into()
2829 })2846 })
2830 })2847 })
2831 .flex_none()2848 .flex_none()
@@ -3581,14 +3598,7 @@ impl Player {
3581 format!("{} – {}", secs(clip.in_frame), secs(clip.out_frame)),3598 format!("{} – {}", secs(clip.in_frame), secs(clip.out_frame)),
3582 ),3599 ),
3583 ("This clip", secs(clip.len())),3600 ("This clip", secs(clip.len())),
3584- (3601+ ("Source duration", secs(session.file_frames(&source.path))),
3585- "Source duration",
3586- secs(source_frames(
3587- lane_clips(session),
3588- session.sources(),
3589- &source.path,
3590- )),
3591- ),
3592 ] {3602 ] {
3593 rows.push(3603 rows.push(
3594 row(rows.len())3604 row(rows.len())
@@ -4190,41 +4200,6 @@ fn unseen_paths(sources: &[Source], streams: &HashMap<PathBuf, Vec<StreamInfo>>)
4190 out4200 out
4191 }4201 }
4192 4202
4193-/// Every lane's clips, which is everything the timeline knows about its sources.
4194-/// Every lane, not the first two: a clip that plays only on `V2` is still a clip
4195-/// the source is used by, and a walk that missed it would call the file unused.
4196-fn lane_clips(session: &PlaybackSession) -> impl Iterator<Item = &Clip> {
4197- session
4198- .lanes()
4199- .into_iter()
4200- .flat_map(|lane| session.lane_clips(lane))
4201-}
4202-
4203-/// How long a source is, as the timeline knows it: the furthest frame any clip
4204-/// plays from *the file*. Exact for a source the timeline still holds whole --
4205-/// which is every source the moment it is imported -- and never longer than the
4206-/// file, since every clip was checked against it, so a clip built from this can
4207-/// always be played. Zero for a file nothing plays from any more.
4208-///
4209-/// By file rather than by source entry, because a second audio stream of a file
4210-/// already on the timeline is a row that has no clips of its own yet, and every
4211-/// stream of a file is the same length -- the picture is what the length is.
4212-///
4213-/// ponytail: a source trimmed on the timeline reads as its trimmed length. The
4214-/// file's own length would need a `Demuxer::open` probe per source, off the
4215-/// render path like the peak decode is -- that is the upgrade path.
4216-fn source_frames<'a>(
4217- clips: impl Iterator<Item = &'a Clip>,
4218- sources: &[Source],
4219- path: &Path,
4220-) -> u32 {
4221- clips
4222- .filter(|clip| sources.get(clip.source).is_some_and(|s| s.path == path))
4223- .map(|clip| clip.out_frame)
4224- .max()
4225- .unwrap_or(0)
4226-}
4227-
4228 /// Which timeline frame the playhead is on, by the rule the engine's own edits4203 /// Which timeline frame the playhead is on, by the rule the engine's own edits
4229 /// use (playback.rs `secs_to_frame`): the frame that has started, with the4204 /// use (playback.rs `secs_to_frame`): the frame that has started, with the
4230 /// epsilon that keeps a clock sitting exactly on a boundary from reading as the4205 /// epsilon that keeps a clock sitting exactly on a boundary from reading as the
@@ -5226,10 +5201,10 @@ mod tests {
5226 RULER_HIT_H, SELECTED, SOURCE_TINTS, SURFACE, SWATCH_W, Source, StreamInfo, Volume,5201 RULER_HIT_H, SELECTED, SOURCE_TINTS, SURFACE, SWATCH_W, Source, StreamInfo, Volume,
5227 WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add, cancels_export, color_snap,5202 WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add, cancels_export, color_snap,
5228 envelope, eq_x, eq_y, export_path, export_settings, format_line, frac_along, frac_down,5203 envelope, eq_x, eq_y, export_path, export_settings, format_line, frac_along, frac_down,
5229- frame_at, histogram, is_bare_modifier, is_project, keymap, lane_clips, lanes_h, marked,5204+ frame_at, histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, menu_at,
5230- menu_at, mp4_refusal, normalise, panel_h, project_path, push_digit, retarget, scrub_due,5205+ mp4_refusal, normalise, panel_h, project_path, push_digit, retarget, scrub_due, show_label,
5231- show_label, source_frames, source_tint, start_frac, timecode, unseen_paths, unseen_sources,5206+ source_tint, start_frac, timecode, unseen_paths, unseen_sources, whole_take, width_frac,
5232- whole_take, width_frac, window_title,5207+ window_title,
5233 };5208 };
5234 use super::{file_name, file_uri, library_rows};5209 use super::{file_name, file_uri, library_rows};
5235 5210
@@ -5237,7 +5212,10 @@ mod tests {
5237 /// the ones the bus would otherwise read as something else.5212 /// the ones the bus would otherwise read as something else.
5238 #[test]5213 #[test]
5239 fn file_uri_encodes_what_a_path_carries() {5214 fn file_uri_encodes_what_a_path_carries() {
5240- assert_eq!(file_uri(std::path::Path::new("/a/b.mp4")), "file:///a/b.mp4");5215+ assert_eq!(
5216+ file_uri(std::path::Path::new("/a/b.mp4")),
5217+ "file:///a/b.mp4"
5218+ );
5241 assert_eq!(5219 assert_eq!(
5242 file_uri(std::path::Path::new("/home/x/out dir/my export.mp4")),5220 file_uri(std::path::Path::new("/home/x/out dir/my export.mp4")),
5243 "file:///home/x/out%20dir/my%20export.mp4"5221 "file:///home/x/out%20dir/my%20export.mp4"
@@ -5260,21 +5238,6 @@ mod tests {
5260 .join(name)5238 .join(name)
5261 }5239 }
5262 5240
5263- /// A clip of `source`, `frames` long, at the top of the timeline. Only the
5264- /// two fields the library reads are meant to be looked at.
5265- fn clip(source: usize, frames: u32) -> Clip {
5266- Clip {
5267- start: 0,
5268- in_frame: 0,
5269- out_frame: frames,
5270- source,
5271- link: None,
5272- eq: None,
5273- color: None,
5274- fit: FitPolicy::default(),
5275- }
5276- }
5277-
5278 /// A source entry for `path` on `stream`, as the project keeps them.5241 /// A source entry for `path` on `stream`, as the project keeps them.
5279 fn source(path: &str, stream: usize) -> Source {5242 fn source(path: &str, stream: usize) -> Source {
5280 Source {5243 Source {
@@ -5283,46 +5246,51 @@ mod tests {
5283 }5246 }
5284 }5247 }
5285 5248
5286- /// The whole of the library's row data comes off the clips: which files5249+ /// An import fills the *library* and nothing else -- the whole point of
5287- /// there are, how long each one is, and therefore which tint each row wears5250+ /// this door: the row is there at the file's own length before any clip
5288- /// -- one index into one list, so a swatch cannot name a different file from5251+ /// plays it, wearing the tint the lanes will tint that clip with, and the
5289- /// the boxes it is meant to point at.5252+ /// timeline is exactly as long as it was. Placing it is the drag, and the
5253+ /// drag is a separate act.
5290 #[test]5254 #[test]
5291- fn a_rows_swatch_and_duration_come_off_the_clips_that_name_it() {5255+ fn an_import_adds_a_row_at_its_own_length_and_leaves_the_lanes_alone() {
5292- // Source 0 whole, source 1 trimmed to half of what it was, source 2 on5256+ let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
5293- // the audio lane only (its picture was lifted), source 3 imported and5257+ session.set_gain(0.0);
5294- // then undone -- an entry with nothing playing from it.5258+ let before = session.timeline_duration();
5295- let sources: Vec<Source> = (0..4).map(|i| source(&format!("/m/{i}.mp4"), 0)).collect();5259+ let clips: Vec<usize> = session
5296- let video = [clip(0, 150), clip(1, 60)];5260+ .lanes()
5297- let audio = [clip(0, 150), clip(1, 30), clip(2, 90)];5261+ .into_iter()
5298- for (row, frames) in [(0, 150), (1, 60), (2, 90), (3, 0)] {5262+ .map(|lane| session.lane_clips(lane).len())
5299- assert_eq!(5263+ .collect();
5300- source_frames(video.iter().chain(&audio), &sources, &sources[row].path),5264+ session.import(&asset("test_av2.mp4")).expect("av2 matches");
5301- frames,5265+ assert_eq!(session.sources().len(), 2, "the library grew");
5302- "row {row}"
5303- );
5304- // The swatch is the clip colour, by the same index and the same
5305- // function -- what makes the panel and the lanes one association.
5306- assert_eq!(source_tint(row), SOURCE_TINTS[row % SOURCE_TINTS.len()]);
5307- }
5308- // The longest clip of a file wins, whichever lane it is in and
5309- // whatever order the lanes are read in.
5310- let one = [source("/m/0.mp4", 0)];
5311- let path = &one[0].path;
5312 assert_eq!(5266 assert_eq!(
5313- source_frames([clip(0, 10), clip(0, 90)].iter(), &one, path),5267+ session.timeline_duration(),
5314- 905268+ before,
5269+ "an import must not place a clip"
5315 );5270 );
5316 assert_eq!(5271 assert_eq!(
5317- source_frames([clip(0, 90), clip(0, 10)].iter(), &one, path),5272+ session
5318- 905273+ .lanes()
5274+ .into_iter()
5275+ .map(|lane| session.lane_clips(lane).len())
5276+ .collect::<Vec<_>>(),
5277+ clips,
5278+ "no lane moved"
5319 );5279 );
5320- assert_eq!(source_frames([].iter(), &one, path), 0);5280+ // The rows the panel draws: one per source, each its file's own length
5321- // Two audio streams of one file are two source entries and one length:5281+ // -- source 1 has no clip anywhere and is still 4 s at 30 fps.
5322- // the second stream's row is placeable the moment the file is there,5282+ let rows = library_rows(session.sources(), &HashMap::new(), None, |path| {
5323- // before any clip names that entry.5283+ session.file_frames(path)
5324- let two = [source("/m/0.mp4", 0), source("/m/0.mp4", 1)];5284+ });
5325- assert_eq!(source_frames([clip(0, 90)].iter(), &two, &two[1].path), 90);5285+ assert_eq!(rows.len(), 2);
5286+ assert_eq!(rows[0].frames, 150, "5 s at 30 fps");
5287+ assert_eq!(rows[1].frames, 120, "4 s at 30 fps, never placed");
5288+ // The swatch is the clip colour, by the same index and the same
5289+ // function -- what makes the panel and the lanes one association.
5290+ for row in 0..rows.len() {
5291+ assert_eq!(rows[row].tint, row);
5292+ assert_eq!(source_tint(row), SOURCE_TINTS[row % SOURCE_TINTS.len()]);
5293+ }
5326 }5294 }
5327 5295
5328 /// The window opened on a song and nothing else -- the launch argument, the5296 /// The window opened on a song and nothing else -- the launch argument, the
@@ -5351,7 +5319,7 @@ mod tests {
5351 .iter()5319 .iter()
5352 .find(|s| s.index == session.sources()[0].audio_stream)5320 .find(|s| s.index == session.sources()[0].audio_stream)
5353 .map(|s| (s.sample_rate, s.channels));5321 .map(|s| (s.sample_rate, s.channels));
5354- let frames = source_frames(lane_clips(&session), session.sources(), &path);5322+ let frames = session.file_frames(&path);
5355 let rows = library_rows(session.sources(), &streams, rate, |_| frames);5323 let rows = library_rows(session.sources(), &streams, rate, |_| frames);
5356 assert_eq!(rows.len(), 1);5324 assert_eq!(rows.len(), 1);
5357 assert_eq!(rows[0].name, "test_tone.mp3");5325 assert_eq!(rows[0].name, "test_tone.mp3");
@@ -5363,7 +5331,7 @@ mod tests {
5363 session.seek(1.0);5331 session.seek(1.0);
5364 assert!(5332 assert!(
5365 session5333 session
5366- .place_stream_at(1.0, &path, 0, frames, Some(Lane::A1))5334+ .place_stream_at(1.0, &path, 0, Some(Lane::A1))
5367 .expect("its own file is on this timeline")5335 .expect("its own file is on this timeline")
5368 );5336 );
5369 assert_eq!(session.lane_clips(Lane::A1).len(), 2);5337 assert_eq!(session.lane_clips(Lane::A1).len(), 2);
@@ -5588,14 +5556,11 @@ mod tests {
5588 assert!(refusal.contains("audio"), "refusal must name it: {refusal}");5556 assert!(refusal.contains("audio"), "refusal must name it: {refusal}");
5589 assert_eq!(session.sources().len(), 1, "a refusal added a row");5557 assert_eq!(session.sources().len(), 1, "a refusal added a row");
5590 // An accepted one does add a row, and it reads as the whole file: 4 s5558 // An accepted one does add a row, and it reads as the whole file: 4 s
5591- // at 30 fps, exactly what was appended.5559+ // at 30 fps, its own length and not one taken off the lanes.
5592 session.import(&asset("test_av2.mp4")).expect("av2 matches");5560 session.import(&asset("test_av2.mp4")).expect("av2 matches");
5593 assert_eq!(session.sources().len(), 2);5561 assert_eq!(session.sources().len(), 2);
5594 let second = session.sources()[1].path.clone();5562 let second = session.sources()[1].path.clone();
5595- assert_eq!(5563+ assert_eq!(session.file_frames(&second), 120);
5596- source_frames(lane_clips(&session), session.sources(), &second),
5597- 120
5598- );
5599 assert_eq!(timecode(120. / 30., 30.), "00:00:04:00");5564 assert_eq!(timecode(120. / 30., 30.), "00:00:04:00");
5600 }5565 }
5601 5566
@@ -5607,21 +5572,22 @@ mod tests {
5607 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");5572 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
5608 session.set_gain(0.0);5573 session.set_gain(0.0);
5609 session.import(&asset("test_av2.mp4")).expect("av2 matches");5574 session.import(&asset("test_av2.mp4")).expect("av2 matches");
5610- assert_eq!(session.timeline_duration(), 9.0);5575+ // In the library only: the 5 s the fixture is, still.
5576+ assert_eq!(session.timeline_duration(), 5.0);
5611 // Two seconds in, which is inside the first take: the insert splits it.5577 // Two seconds in, which is inside the first take: the insert splits it.
5612 session.seek(2.0);5578 session.seek(2.0);
5613 let second = session.sources()[1].path.clone();5579 let second = session.sources()[1].path.clone();
5614- let frames = source_frames(lane_clips(&session), session.sources(), &second);5580+ let frames = session.file_frames(&second);
5615 // Through the engine door `insert_source` uses, with the row's own5581 // Through the engine door `insert_source` uses, with the row's own
5616 // stream: the button, the drop and this are one call.5582 // stream: the button, the drop and this are one call.
5617 assert!(5583 assert!(
5618 session5584 session
5619- .place_stream_at(2.0, &second, 0, frames, None)5585+ .place_stream_at(2.0, &second, 0, None)
5620 .expect("av2 is already on the timeline")5586 .expect("av2 is already on the timeline")
5621 );5587 );
5622 // The whole of source 1 went in and nothing was painted over: the5588 // The whole of source 1 went in and nothing was painted over: the
5623 // timeline is longer by exactly that file.5589 // timeline is longer by exactly that file.
5624- assert_eq!(session.timeline_duration(), 13.0);5590+ assert_eq!(session.timeline_duration(), 9.0);
5625 let (video, audio) = (session.lane_clips(Lane::V1), session.lane_clips(Lane::A1));5591 let (video, audio) = (session.lane_clips(Lane::V1), session.lane_clips(Lane::A1));
5626 // One take, not a video clip with no sound under it: both lanes hold5592 // One take, not a video clip with no sound under it: both lanes hold
5627 // the same clip at the same place, in the same group.5593 // the same clip at the same place, in the same group.
@@ -5644,21 +5610,18 @@ mod tests {
5644 PlaybackSession::open(asset("test_multilang.mp4")).expect("open the fixture");5610 PlaybackSession::open(asset("test_multilang.mp4")).expect("open the fixture");
5645 session.set_gain(0.0);5611 session.set_gain(0.0);
5646 let path = session.sources()[0].path.clone();5612 let path = session.sources()[0].path.clone();
5647- let frames = source_frames(lane_clips(&session), session.sources(), &path);5613+ let frames = session.file_frames(&path);
5648 let end = session.timeline_duration();5614 let end = session.timeline_duration();
5649 assert!(5615 assert!(
5650 session5616 session
5651- .place_stream_at(end, &path, 1, frames, None)5617+ .place_stream_at(end, &path, 1, None)
5652 .expect("the French track shares the timeline's parameters")5618 .expect("the French track shares the timeline's parameters")
5653 );5619 );
5654 assert_eq!(session.sources()[1].audio_stream, 1);5620 assert_eq!(session.sources()[1].audio_stream, 1);
5655 assert_eq!(session.timeline_duration(), end * 2.0);5621 assert_eq!(session.timeline_duration(), end * 2.0);
5656 // Both rows are the same file, so both rows are that file's length --5622 // Both rows are the same file, so both rows are that file's length --
5657 // the second one before any clip of its own existed.5623 // the second one before any clip of its own existed.
5658- assert_eq!(5624+ assert_eq!(session.file_frames(&path), frames);
5659- source_frames(lane_clips(&session), session.sources(), &path),
5660- frames
5661- );
5662 }5625 }
5663 5626
5664 /// The trim-a-clip path through the doors the edge drag uses:5627 /// The trim-a-clip path through the doors the edge drag uses:
@@ -5701,7 +5664,11 @@ mod tests {
5701 5664
5702 // ...and dragged back out, as far as the file goes and no further.5665 // ...and dragged back out, as far as the file goes and no further.
5703 assert!(session.trim_clip(Lane::V1, 0, Edge::End, 9_999));5666 assert!(session.trim_clip(Lane::V1, 0, Edge::End, 9_999));
5704- assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the whole take back");5667+ assert_eq!(
5668+ session.lane_clips(Lane::V1)[0],
5669+ whole,
5670+ "the whole take back"
5671+ );
5705 5672
5706 // The head takes the in-point with it, so what plays at the new start5673 // The head takes the in-point with it, so what plays at the new start
5707 // is source frame 10 rather than source frame 0.5674 // is source frame 10 rather than source frame 0.
@@ -5780,10 +5747,9 @@ mod tests {
5780 // A library row let go over that row: the same door the Add button5747 // A library row let go over that row: the same door the Add button
5781 // uses, told which lane it was let go over.5748 // uses, told which lane it was let go over.
5782 let path = session.sources()[0].path.clone();5749 let path = session.sources()[0].path.clone();
5783- let frames = source_frames(lane_clips(&session), session.sources(), &path);
5784 assert!(5750 assert!(
5785 session5751 session
5786- .place_stream_at(1.0, &path, 0, frames, Some(v2))5752+ .place_stream_at(1.0, &path, 0, Some(v2))
5787 .expect("its own file is on this timeline")5753 .expect("its own file is on this timeline")
5788 );5754 );
5789 assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2");5755 assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2");
@@ -5809,7 +5775,7 @@ mod tests {
5809 assert_eq!(mp4_refusal(&session), None, "an empty lane carries nothing");5775 assert_eq!(mp4_refusal(&session), None, "an empty lane carries nothing");
5810 assert!(5776 assert!(
5811 session5777 session
5812- .place_stream_at(0.0, &path, 0, frames, Some(a2))5778+ .place_stream_at(0.0, &path, 0, Some(a2))
5813 .expect("its own file is on this timeline")5779 .expect("its own file is on this timeline")
5814 );5780 );
5815 assert_eq!(5781 assert_eq!(
@@ -6761,8 +6727,8 @@ mod tests {
6761 fn main() {6727 fn main() {
6762 let arg = std::env::args().nth(1).map(PathBuf::from);6728 let arg = std::env::args().nth(1).map(PathBuf::from);
6763 // A `.edith` restores a whole timeline, anything else *is* the timeline.6729 // A `.edith` restores a whole timeline, anything else *is* the timeline.
6764- // Either way the rest of argv is appended to what comes out. No argument at6730+ // Either way the rest of argv is imported into its library. No argument at
6765- // all opens the window empty -- the timeline then arrives by drop or by the6731+ // all opens the window empty -- the library then arrives by drop or by the
6766 // Import button, and everything below is derived from it at that point6732 // Import button, and everything below is derived from it at that point
6767 // instead.6733 // instead.
6768 let mut session = match &arg {6734 let mut session = match &arg {
@@ -6792,8 +6758,10 @@ fn main() {
6792 if let Some(text) = &notice {6758 if let Some(text) = &notice {
6793 eprintln!("{text}");6759 eprintln!("{text}");
6794 }6760 }
6795- // The first file makes the timeline, the rest are appended to it. A refusal6761+ // The first file makes the timeline -- naming a file to open is a decision
6796- // is not fatal -- the others still load -- but the window must not open6762+ // about what to watch -- and the rest are imports like any other: rows in
6763+ // the library, dragged onto a lane when they are wanted there. A refusal is
6764+ // not fatal -- the others still load -- but the window must not open
6797 // silently pretending the file was taken, so the first one seeds the notice.6765 // silently pretending the file was taken, so the first one seeds the notice.
6798 for extra in std::env::args().skip(2) {6766 for extra in std::env::args().skip(2) {
6799 // Only reachable with a first argument, so there is a timeline.6767 // Only reachable with a first argument, so there is a timeline.
crates/engine/src/playback.rsmodified+75 -53
@@ -216,6 +216,33 @@ impl PlaybackSession {
216 })216 })
217 }217 }
218 218
219+ /// Opens `path` into the **library alone**: everything
220+ /// [`open`](Self::open) scaffolds from it -- the resolution, the frame
221+ /// rate, the clock, the source entry and its length -- over an *empty*
222+ /// timeline. What an import into a window that has no session yet makes,
223+ /// since an import registers a source and never places a clip
224+ /// ([`import`](Self::import)); the file reaches a lane when it is dragged
225+ /// there.
226+ ///
227+ /// Nothing to undo, like the import it stands in for: the lanes start
228+ /// empty rather than being emptied, so no snapshot is pushed.
229+ pub fn open_library(path: impl AsRef<Path>) -> crate::Result<Self> {
230+ let mut session = Self::open(path)?;
231+ // The pair of lanes an opened file comes up with (`Project::single`,
232+ // `open_audio_only`), emptied -- the source list and so the noted
233+ // counts are carried over untouched, which is what keeps a library row
234+ // placeable at its full length.
235+ session.project = Project::from_parts(
236+ session.project.sources().to_vec(),
237+ vec![(LaneKind::Video, Vec::new()), (LaneKind::Audio, Vec::new())],
238+ Vec::new(),
239+ Vec::new(),
240+ )?;
241+ // Onto the emptied mapping: black picture, silence, zero duration.
242+ session.seek(0.);
243+ Ok(session)
244+ }
245+
219 /// Opens a standalone audio file ([`crate::is_audio`]) as a timeline of its246 /// Opens a standalone audio file ([`crate::is_audio`]) as a timeline of its
220 /// own: one clip on `A1`, nothing on the video lane, and a picture that is247 /// own: one clip on `A1`, nothing on the video lane, and a picture that is
221 /// the black of an uncovered canvas ([`AUDIO_ONLY_CANVAS`]) for as long as248 /// the black of an uncovered canvas ([`AUDIO_ONLY_CANVAS`]) for as long as
@@ -775,6 +802,25 @@ impl PlaybackSession {
775 debug_assert_eq!(self.counts.len(), self.project.sources().len());802 debug_assert_eq!(self.counts.len(), self.project.sources().len());
776 }803 }
777 804
805+ /// How long the whole of `path` is, in timeline frames: the length noted
806+ /// when it became a source, so a file sitting in the library with no clip
807+ /// anywhere still knows how much of itself there is to place. `0` for a
808+ /// file this session has never taken in.
809+ ///
810+ /// By path and not by stream, because a file is one length however many
811+ /// audio tracks it carries -- the picture's frame count for an mp4, the
812+ /// playing time for a song.
813+ pub fn file_frames(&self, path: &Path) -> u32 {
814+ let at = |wanted: &Path| self.project.sources().iter().position(|s| s.path == wanted);
815+ // A source's own path is canonical ([`Source::new`]), so a caller
816+ // handing one back from [`sources`](Self::sources) -- which is every
817+ // library row -- hits on the first walk and never pays for the
818+ // `canonicalize` syscall the second one makes.
819+ at(path)
820+ .or_else(|| at(&Source::new(path, 0).path))
821+ .map_or(0, |i| self.counts[i])
822+ }
823+
778 /// The clip the picture is coming from at `timeline_secs`: the lane it sits824 /// The clip the picture is coming from at `timeline_secs`: the lane it sits
779 /// on and its index there, by the same topmost-lane-wins rule the decoder825 /// on and its index there, by the same topmost-lane-wins rule the decoder
780 /// follows. `None` over a gap and past the end. What a card that grades826 /// follows. `None` over a gap and past the end. What a card that grades
@@ -880,7 +926,7 @@ impl PlaybackSession {
880 self.edit(|p| p.paste(at, clip))926 self.edit(|p| p.paste(at, clip))
881 }927 }
882 928
883- /// Places `frames` of `path` played on its audio `stream` at929+ /// Places the whole of `path` played on its audio `stream` at
884 /// `timeline_secs`, the way [`paste_at`](Self::paste_at) places a copy --930 /// `timeline_secs`, the way [`paste_at`](Self::paste_at) places a copy --
885 /// the door a library row goes through, and the only way a stream other931 /// the door a library row goes through, and the only way a stream other
886 /// than the one an import brought in reaches the timeline. The `(file,932 /// than the one an import brought in reaches the timeline. The `(file,
@@ -908,20 +954,22 @@ impl PlaybackSession {
908 timeline_secs: f64,954 timeline_secs: f64,
909 path: &Path,955 path: &Path,
910 stream: usize,956 stream: usize,
911- frames: u32,
912 onto: Option<Lane>,957 onto: Option<Lane>,
913 ) -> crate::Result<bool> {958 ) -> crate::Result<bool> {
914 let wanted = Source::new(path, stream);959 let wanted = Source::new(path, stream);
915- // Another stream of a file whose picture is *already* on the timeline:960+ // Another stream of a file this session has taken in: that is what a
916- // that is what a library row is, and it is why nothing here has to961+ // library row is, and it is why nothing here has to check dimensions or
917- // check dimensions or frame rate -- the file passed that at import.962+ // frame rate -- the file passed that at import. Its length is the one
918- if !self.project.sources().iter().any(|s| s.path == wanted.path) {963+ // the import noted, so a source that has never been placed is as
964+ // placeable as one that is already on a lane.
965+ let frames = self.file_frames(&wanted.path);
966+ if frames == 0 {
919 return Err(format!("{} is not on this timeline", path.display()).into());967 return Err(format!("{} is not on this timeline", path.display()).into());
920 }968 }
921 let first = self.first_audio()?;969 let first = self.first_audio()?;
922 audio_matches(&wanted, &first)?;970 audio_matches(&wanted, &first)?;
923 let source = self.project.import(path, stream);971 let source = self.project.import(path, stream);
924- self.note_frames(source, frames.max(1));972+ self.note_frames(source, frames);
925 let clip = Clip {973 let clip = Clip {
926 start: 0,974 start: 0,
927 in_frame: 0,975 in_frame: 0,
@@ -993,15 +1041,24 @@ impl PlaybackSession {
993 self.edit(Project::undo)1041 self.edit(Project::undo)
994 }1042 }
995 1043
996- /// Appends the whole of `path` to the end of the timeline. One undo step,1044+ /// Takes `path` into the **library**: it becomes a source of this session,
997- /// and the file becomes a source only if it is not one already.1045+ /// with its length noted ([`file_frames`](Self::file_frames)), and nothing
1046+ /// is placed on any lane. What reaches the timeline is decided afterwards,
1047+ /// by dragging the row onto a lane
1048+ /// ([`place_stream_at`](Self::place_stream_at)) -- importing a file is not
1049+ /// a decision about where it plays.
1050+ ///
1051+ /// The source index, new or the one this file already had: importing twice
1052+ /// registers once. *Not* an undo step -- a source entry alone changes
1053+ /// nothing playable, so there is nothing for [`undo`](Self::undo) to take
1054+ /// back, and nothing reseeks.
998 ///1055 ///
999 /// Refused unless it can join the timeline -- same codec, same frame rate,1056 /// Refused unless it can join the timeline -- same codec, same frame rate,
1000 /// same audio parameters or both silent; the `Err` names the property that1057 /// same audio parameters or both silent; the `Err` names the property that
1001 /// disagrees, for a caller to show. Nothing is changed by a refusal. A1058 /// disagrees, for a caller to show. Nothing is changed by a refusal. A
1002 /// *resolution* of its own is not a refusal: the clip is placed on the1059 /// *resolution* of its own is not a refusal: the clip is placed on the
1003 /// project canvas by its fit policy ([`PlaybackSession::set_fit`]).1060 /// project canvas by its fit policy ([`PlaybackSession::set_fit`]).
1004- pub fn import(&mut self, path: &Path) -> crate::Result<()> {1061+ pub fn import(&mut self, path: &Path) -> crate::Result<usize> {
1005 if crate::is_audio(path) {1062 if crate::is_audio(path) {
1006 return self.import_audio(path);1063 return self.import_audio(path);
1007 }1064 }
@@ -1011,64 +1068,29 @@ impl PlaybackSession {
1011 // [`place_stream_at`](Self::place_stream_at) is how any other one of1068 // [`place_stream_at`](Self::place_stream_at) is how any other one of
1012 // its streams reaches the timeline afterwards.1069 // its streams reaches the timeline afterwards.
1013 matches_timeline(&Source::new(path, 0), &meta, &self.meta, &first)?;1070 matches_timeline(&Source::new(path, 0), &meta, &self.meta, &first)?;
1014-
1015- let old_end = self.timeline_duration();
1016 let source = self.project.import(path, 0);1071 let source = self.project.import(path, 0);
1017 self.note_frames(source, meta.frame_count);1072 self.note_frames(source, meta.frame_count);
1018- // Refused only for an unknown index, and this one just came from `import`.1073+ Ok(source)
1019- self.project.append_clip(source, meta.frame_count);1074+ }
1020- // Reseek like any other edit, even though nothing before the playhead1075+
1021- // moved: the running audio worker's segment list stops at the old end,1076+ /// The same registration for a standalone audio file: a song has no
1022- // so without this the appended clip would play silent. At EOS the wall1077+ /// picture, so the length noted for it is its playing time rounded up to
1023- // clock has run on past the timeline, so resume from the join instead1078+ /// whole frames, which is the only frame count such a source has.
1024- // of wherever it got to -- and the seek is what clears `eos`.
1025- let at = if self.eos { old_end } else { self.now() };
1026- self.seek(at);
1027- Ok(())
1028- }
1029-
1030- /// Appends a standalone audio file to the end of the timeline, on the
1031- /// **audio lane alone**: a song has no picture, so there is nothing to put
1032- /// on the video lane and the timeline shows black under it. Its length is
1033- /// its playing time rounded up to whole frames, which is the only frame
1034- /// count such a source has.
1035 ///1079 ///
1036 /// Refused in the same words as any other import when its rate or layout1080 /// Refused in the same words as any other import when its rate or layout
1037 /// disagrees with the timeline's -- one output device, one set of1081 /// disagrees with the timeline's -- one output device, one set of
1038 /// parameters -- and refused outright on a silent timeline, which has no1082 /// parameters -- and refused outright on a silent timeline, which has no
1039 /// device open at all. Nothing is changed by a refusal.1083 /// device open at all. Nothing is changed by a refusal.
1040- fn import_audio(&mut self, path: &Path) -> crate::Result<()> {1084+ fn import_audio(&mut self, path: &Path) -> crate::Result<usize> {
1041 let first = self.first_audio()?;1085 let first = self.first_audio()?;
1042 // Stream 0, and there is no other: a standalone audio file carries one1086 // Stream 0, and there is no other: a standalone audio file carries one
1043 // track (`AudioSession::probe_streams`), so nothing here has a stream1087 // track (`AudioSession::probe_streams`), so nothing here has a stream
1044 // to pick the way `place_stream_at` does for an mp4.1088 // to pick the way `place_stream_at` does for an mp4.
1045 audio_matches(&Source::new(path, 0), &first)?;1089 audio_matches(&Source::new(path, 0), &first)?;
1046 let frames = audio_frames(path, self.meta.frame_rate)?;1090 let frames = audio_frames(path, self.meta.frame_rate)?;
1047-
1048- let old_end = self.timeline_duration();
1049 let source = self.project.import(path, 0);1091 let source = self.project.import(path, 0);
1050 self.note_frames(source, frames);1092 self.note_frames(source, frames);
1051- let at = self.project.timeline_frames();1093+ Ok(source)
1052- self.project.place(
1053- Lane::A1,
1054- at,
1055- Clip {
1056- start: at,
1057- in_frame: 0,
1058- out_frame: frames,
1059- source,
1060- link: None,
1061- eq: None,
1062- color: None,
1063- fit: FitPolicy::default(),
1064- },
1065- );
1066- // Same reason as a video import: the running audio worker's segment
1067- // list stops at the old end, so without a reseek the appended clip
1068- // would play silent.
1069- let at = if self.eos { old_end } else { self.now() };
1070- self.seek(at);
1071- Ok(())
1072 }1094 }
1073 1095
1074 /// Applies an edit and, if it took, reseeks onto the new mapping. `seek`1096 /// Applies an edit and, if it took, reseeks onto the new mapping. `seek`
crates/engine/tests/audio_files.rsmodified+41 -11
@@ -32,6 +32,20 @@ fn asset(name: &str) -> PathBuf {
32 .join(name)32 .join(name)
33 }33 }
34 34
35+/// The two acts a file on the timeline now takes, in the order a user does
36+/// them: taken into the library (`PlaybackSession::import` places nothing),
37+/// then dragged onto the end of the timeline.
38+fn import_and_place(session: &mut PlaybackSession, path: &Path) {
39+ session.import(path).expect("the file joins this timeline");
40+ let end = session.timeline_duration();
41+ assert!(
42+ session
43+ .place_stream_at(end, path, 0, None)
44+ .expect("a file just imported is on this timeline"),
45+ "the drag onto the end of the timeline"
46+ );
47+}
48+
35 /// The message of a call that had to be refused. Not `expect_err`: that wants49 /// The message of a call that had to be refused. Not `expect_err`: that wants
36 /// `Debug` on the success side, and neither a session nor a packet has it.50 /// `Debug` on the success side, and neither a session nor a packet has it.
37 fn refusal<T>(result: engine::Result<T>) -> String {51 fn refusal<T>(result: engine::Result<T>) -> String {
@@ -119,11 +133,24 @@ fn duration_comes_from_the_header_or_the_decode() {
119 fn a_song_joins_a_video_timeline_on_the_audio_lane() {133 fn a_song_joins_a_video_timeline_on_the_audio_lane() {
120 let mut session = open(asset("test_av.mp4"));134 let mut session = open(asset("test_av.mp4"));
121 let before = session.timeline_duration();135 let before = session.timeline_duration();
136+ // The import alone is a library row: the lanes are untouched until it is
137+ // dragged onto one.
122 session138 session
123 .import(&asset("test_tone.mp3"))139 .import(&asset("test_tone.mp3"))
124 .expect("import the song");140 .expect("import the song");
141+ assert_eq!(session.sources().len(), 2, "the library grew");
142+ assert_eq!(session.lane_clips(Lane::A1).len(), 1, "an import placed it");
143+ assert_eq!(session.timeline_duration(), before);
144+ assert_eq!(session.file_frames(&asset("test_tone.mp3")), 90);
145+ let end = session.timeline_duration();
146+ assert!(
147+ session
148+ .place_stream_at(end, &asset("test_tone.mp3"), 0, None)
149+ .expect("a song just imported is on this timeline")
150+ );
125 151
126- // 3 s at 30 fps, appended: the audio lane runs 90 frames past the video.152+ // 3 s at 30 fps, placed at the end: the audio lane runs 90 frames past the
153+ // video.
127 assert!(154 assert!(
128 (session.timeline_duration() - (before + 3.0)).abs() < 0.05,155 (session.timeline_duration() - (before + 3.0)).abs() < 0.05,
129 "{} s of timeline, want {}",156 "{} s of timeline, want {}",
@@ -151,7 +178,7 @@ fn a_rate_the_device_cannot_mix_is_refused_at_the_door() {
151 refusal(session.import(&asset("test_tone_48k.wav"))),178 refusal(session.import(&asset("test_tone_48k.wav"))),
152 "audio 48000 Hz 2 ch does not match the timeline's 44100 Hz 2 ch"179 "audio 48000 Hz 2 ch does not match the timeline's 44100 Hz 2 ch"
153 );180 );
154- // Refused means unchanged: no source, no clip, no length.181+ // Refused means unchanged: no library row, no clip, no length.
155 assert_eq!(session.sources().len(), 1);182 assert_eq!(session.sources().len(), 1);
156 assert_eq!(session.lane_clips(Lane::A1).len(), 1);183 assert_eq!(session.lane_clips(Lane::A1).len(), 1);
157 }184 }
@@ -228,9 +255,7 @@ fn an_audio_only_project_saves_reloads_and_exports_its_sound() {
228 let mut session = open(asset("test_tone.mp3"));255 let mut session = open(asset("test_tone.mp3"));
229 // A second song joins it, the same way one joins a timeline of video: no256 // A second song joins it, the same way one joins a timeline of video: no
230 // picture is needed for the import to have something to hold it to.257 // picture is needed for the import to have something to hold it to.
231- session258+ import_and_place(&mut session, &asset("test_tone.flac"));
232- .import(&asset("test_tone.flac"))
233- .expect("a song joins a song");
234 assert_eq!(session.lane_clips(Lane::A1).len(), 2);259 assert_eq!(session.lane_clips(Lane::A1).len(), 2);
235 assert!(session.lane_clips(Lane::V1).is_empty());260 assert!(session.lane_clips(Lane::V1).is_empty());
236 assert!((session.timeline_duration() - 6.0).abs() < 0.1);261 assert!((session.timeline_duration() - 6.0).abs() < 0.1);
@@ -304,18 +329,23 @@ fn an_audio_only_project_saves_reloads_and_exports_its_sound() {
304 #[test]329 #[test]
305 fn a_video_joins_a_timeline_a_song_started() {330 fn a_video_joins_a_timeline_a_song_started() {
306 let mut session = open(asset("test_tone.mp3"));331 let mut session = open(asset("test_tone.mp3"));
307- session332+ import_and_place(&mut session, &asset("test_av.mp4"));
308- .import(&asset("test_av.mp4"))
309- .expect("30 fps H.264 matches the audio-only canvas");
310 assert_eq!(session.lane_clips(Lane::V1).len(), 1, "a picture at last");333 assert_eq!(session.lane_clips(Lane::V1).len(), 1, "a picture at last");
311 assert_eq!(session.lane_clips(Lane::A1).len(), 2);334 assert_eq!(session.lane_clips(Lane::A1).len(), 2);
312 // And a file at another rate is refused in the timeline's own words rather335 // And a file at another rate is refused in the timeline's own words rather
313- // than silently retiming the song already on the lane.336+ // than silently retiming the song already on the lane -- the sample rate at
337+ // one door, the *frame* rate at the other: the canvas a song scaffolds has
338+ // a frame rate of its own (30 fps), and a 25 fps picture cannot join it.
314 let e = refusal(session.import(&asset("test_tone_48k.wav")));339 let e = refusal(session.import(&asset("test_tone_48k.wav")));
315 assert_eq!(340 assert_eq!(
316 e,341 e,
317 "audio 48000 Hz 2 ch does not match the timeline's 44100 Hz 2 ch"342 "audio 48000 Hz 2 ch does not match the timeline's 44100 Hz 2 ch"
318 );343 );
344+ assert_eq!(
345+ refusal(session.import(&asset("test_25fps.mp4"))),
346+ "25.000 fps does not match the timeline's 30.000 fps"
347+ );
348+ assert_eq!(session.sources().len(), 2, "a refusal left a library row");
319 }349 }
320 350
321 /// Blocks until the export settles, whichever way it settled.351 /// Blocks until the export settles, whichever way it settled.
@@ -362,7 +392,7 @@ fn a_song_survives_a_save_and_a_reload() {
362 };392 };
363 393
364 let mut session = open(copy("test_av.mp4"));394 let mut session = open(copy("test_av.mp4"));
365- session.import(&copy("test_tone.flac")).expect("import");395+ import_and_place(&mut session, &copy("test_tone.flac"));
366 // And one placed at the playhead, the way a library row dropped on the396 // And one placed at the playhead, the way a library row dropped on the
367 // audio lane arrives -- so the reload has both doors to restore.397 // audio lane arrives -- so the reload has both doors to restore.
368 let song = session.lane_clips(Lane::A1)[1];398 let song = session.lane_clips(Lane::A1)[1];
@@ -430,7 +460,7 @@ fn a_pasted_song_never_lands_on_the_video_lane() {
430 };460 };
431 461
432 let mut session = open(copy("test_av.mp4"));462 let mut session = open(copy("test_av.mp4"));
433- session.import(&copy("test_tone.flac")).expect("import");463+ import_and_place(&mut session, &copy("test_tone.flac"));
434 let song = session.lane_clips(Lane::A1)[1];464 let song = session.lane_clips(Lane::A1)[1];
435 let video_before = session.lane_clips(Lane::V1).to_vec();465 let video_before = session.lane_clips(Lane::V1).to_vec();
436 assert!(session.paste_at(0.0, song), "paste the copied song");466 assert!(session.paste_at(0.0, song), "paste the copied song");
crates/engine/tests/playback.rsmodified+140 -48
@@ -626,6 +626,22 @@ fn edits_keep_the_audio_clock() {
626 );626 );
627 }627 }
628 628
629+/// The two acts a second file on the timeline now takes, in the order a user
630+/// does them: taken into the library, then dragged onto the end of the
631+/// timeline. An import registers a source and places nothing
632+/// (`PlaybackSession::import`), so every test that wants a second source *on*
633+/// the lanes does both.
634+fn import_and_place(session: &mut PlaybackSession, path: &Path) {
635+ session.import(path).expect("the file joins this timeline");
636+ let end = session.timeline_duration();
637+ assert!(
638+ session
639+ .place_stream_at(end, path, 0, None)
640+ .expect("a file just imported is on this timeline"),
641+ "the drag onto the end of the timeline"
642+ );
643+}
644+
629 /// Frame count straight from the container, without decoding anything.645 /// Frame count straight from the container, without decoding anything.
630 fn frame_count(path: &Path) -> u32 {646 fn frame_count(path: &Path) -> u32 {
631 engine::demux::Demuxer::open(path)647 engine::demux::Demuxer::open(path)
@@ -634,17 +650,28 @@ fn frame_count(path: &Path) -> u32 {
634 .frame_count650 .frame_count
635 }651 }
636 652
637-/// Import: a second file appended to the timeline, played through as one653+/// An imported file dragged onto the end of the timeline, played through as
638-/// stream. No audio needed for the pictures, so this runs anywhere.654+/// one stream. No audio needed for the pictures, so this runs anywhere.
639 #[test]655 #[test]
640-fn import_appends_a_second_source_and_plays_across_the_join() {656+fn a_placed_import_plays_across_the_join() {
641 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));657 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));
642 let mut session = open(&av);658 let mut session = open(&av);
643 let (fps, first) = (session.meta().frame_rate, session.meta().frame_count);659 let (fps, first) = (session.meta().frame_rate, session.meta().frame_count);
644 let second = frame_count(&av2);660 let second = frame_count(&av2);
645 assert_eq!((first, second), (150, 120), "fixtures changed");661 assert_eq!((first, second), (150, 120), "fixtures changed");
646 662
663+ // The import alone fills the library: nothing on the lanes moved.
647 session.import(&av2).expect("test_av2 matches test_av");664 session.import(&av2).expect("test_av2 matches test_av");
665+ assert_eq!(session.clip_spans().len(), 1, "an import placed a clip");
666+ assert!((session.timeline_duration() - 5.0).abs() < 1e-9);
667+ assert_eq!(session.file_frames(&av2), second, "its own length is noted");
668+ // ...and the drag puts it at the end.
669+ let end = session.timeline_duration();
670+ assert!(
671+ session
672+ .place_stream_at(end, &av2, 0, None)
673+ .expect("a file just imported is on this timeline")
674+ );
648 assert_eq!(session.clip_spans().len(), 2);675 assert_eq!(session.clip_spans().len(), 2);
649 assert_eq!(676 assert_eq!(
650 session677 session
@@ -653,7 +680,7 @@ fn import_appends_a_second_source_and_plays_across_the_join() {
653 .map(|&(.., s)| s)680 .map(|&(.., s)| s)
654 .collect::<Vec<_>>(),681 .collect::<Vec<_>>(),
655 vec![0, 1],682 vec![0, 1],
656- "the appended clip plays the imported file"683+ "the placed clip plays the imported file"
657 );684 );
658 assert!(685 assert!(
659 (session.timeline_duration() - 9.0).abs() < 1e-9,686 (session.timeline_duration() - 9.0).abs() < 1e-9,
@@ -721,6 +748,46 @@ fn import_appends_a_second_source_and_plays_across_the_join() {
721 );748 );
722 }749 }
723 750
751+/// The first import into a window with nothing open: the file fills the library
752+/// and the timeline stays *empty*, and the drag that follows is what puts it on
753+/// a lane -- at the file's own length, which nothing on the timeline could have
754+/// told the session. The whole point of an import that places nothing.
755+#[test]
756+fn the_first_import_opens_a_library_over_an_empty_timeline() {
757+ let av = asset("test_av.mp4");
758+ let mut session = PlaybackSession::open_library(&av).expect("open into the library");
759+ session.set_gain(0.0);
760+ assert!(session.is_empty(), "the timeline must start empty");
761+ assert_eq!(session.timeline_duration(), 0.0);
762+ assert!(session.clip_spans().is_empty());
763+ // But it is a session: the file's own picture, rate and clock, and its row.
764+ assert_eq!(session.sources().len(), 1, "the library row");
765+ assert_eq!(session.resolution(), (1280, 720));
766+ assert_eq!(session.meta().frame_rate, 30.0);
767+ assert_eq!(session.file_frames(&av), 150, "5 s at 30 fps, never placed");
768+ assert!(!session.undo(), "opening a library is not an undo step");
769+
770+ // The drag: the row goes onto the timeline whole, and it plays from there.
771+ assert!(
772+ session
773+ .place_stream_at(0.0, &av, 0, None)
774+ .expect("its own file is on this timeline")
775+ );
776+ assert!(!session.is_empty(), "the drag left the timeline empty");
777+ assert!((session.timeline_duration() - 5.0).abs() < 1e-9);
778+ session.seek(0.0);
779+ let landed = next_frame(&mut session, "the dragged clip");
780+ assert_eq!(landed.index, 0);
781+ assert!(
782+ landed.bgra == source_frame(&av, 0),
783+ "the placed clip is not playing its file"
784+ );
785+ // ...and it is an edit like any other, so one `z` takes it back to empty.
786+ assert!(session.undo(), "undo the drag");
787+ assert!(session.is_empty());
788+ assert_eq!(session.sources().len(), 1, "the row survives the undo");
789+}
790+
724 /// One timeline, one set of parameters: everything else is refused by name and791 /// One timeline, one set of parameters: everything else is refused by name and
725 /// changes nothing.792 /// changes nothing.
726 #[test]793 #[test]
@@ -746,6 +813,15 @@ fn import_refuses_what_does_not_match() {
746 "a resolution of its own is not a refusal any more: {err}"813 "a resolution of its own is not a refusal any more: {err}"
747 );814 );
748 815
816+ // Same codec, same audio, 25 fps: the one property left, named with both
817+ // rates. Mixing rates would mean retiming the timeline itself, and there is
818+ // no resampler for that, so the refusal is the honest answer.
819+ let err = session
820+ .import(&asset("test_25fps.mp4"))
821+ .expect_err("25 fps must not join a 30 fps timeline")
822+ .to_string();
823+ assert_eq!(err, "25.000 fps does not match the timeline's 30.000 fps");
824+
749 // Same size and rate, no audio track: the timeline has one.825 // Same size and rate, no audio track: the timeline has one.
750 let err = session826 let err = session
751 .import(&asset("test_baseline.mp4"))827 .import(&asset("test_baseline.mp4"))
@@ -758,6 +834,7 @@ fn import_refuses_what_does_not_match() {
758 "a missing file is an error, not a panic"834 "a missing file is an error, not a panic"
759 );835 );
760 assert_eq!(session.clip_spans().len(), 1, "a refusal changes nothing");836 assert_eq!(session.clip_spans().len(), 1, "a refusal changes nothing");
837+ assert_eq!(session.sources().len(), 1, "a refusal left a library row");
761 assert!((session.timeline_duration() - 5.0).abs() < 1e-9);838 assert!((session.timeline_duration() - 5.0).abs() < 1e-9);
762 839
763 // The mirror: audio into a silent timeline is refused just as loudly.840 // The mirror: audio into a silent timeline is refused just as loudly.
@@ -780,9 +857,7 @@ fn media_of_two_resolutions_share_one_timeline() {
780 let mut session = open(asset("test_baseline.mp4"));857 let mut session = open(asset("test_baseline.mp4"));
781 assert_eq!(session.resolution(), (1280, 720), "source 0's picture");858 assert_eq!(session.resolution(), (1280, 720), "source 0's picture");
782 assert_eq!(session.native_resolution(), (1280, 720));859 assert_eq!(session.native_resolution(), (1280, 720));
783- session860+ import_and_place(&mut session, &asset("test_mismatch.mp4"));
784- .import(&asset("test_mismatch.mp4"))
785- .expect("640x360 must join a 1280x720 timeline");
786 // 150 frames of the first file, then 60 of the second, at 30 fps.861 // 150 frames of the first file, then 60 of the second, at 30 fps.
787 assert_eq!(session.clip_spans().len(), 2);862 assert_eq!(session.clip_spans().len(), 2);
788 assert!((session.timeline_duration() - 7.0).abs() < 1e-9);863 assert!((session.timeline_duration() - 7.0).abs() < 1e-9);
@@ -805,9 +880,7 @@ fn media_of_two_resolutions_share_one_timeline() {
805 #[test]880 #[test]
806 fn a_fitted_clip_is_letterboxed_and_a_filled_one_is_not() {881 fn a_fitted_clip_is_letterboxed_and_a_filled_one_is_not() {
807 let mut session = open(asset("test_baseline.mp4"));882 let mut session = open(asset("test_baseline.mp4"));
808- session883+ import_and_place(&mut session, &asset("test_mismatch.mp4"));
809- .import(&asset("test_mismatch.mp4"))
810- .expect("640x360 joins");
811 // A 4:3 project: both clips are 16:9, so both are letterboxed on it. 960x720884 // A 4:3 project: both clips are 16:9, so both are letterboxed on it. 960x720
812 // holds the whole 640x360 picture as 960x540 with 90 rows of bar either way885 // holds the whole 640x360 picture as 960x540 with 90 rows of bar either way
813 // (fit_rect's own arithmetic, asserted in scale.rs).886 // (fit_rect's own arithmetic, asserted in scale.rs).
@@ -860,14 +933,23 @@ fn a_project_at_the_media_size_is_the_decoder_untouched() {
860 );933 );
861 }934 }
862 935
863-/// The same file twice is two clips of one source -- a source index is handed936+/// The same file twice is one library row -- a source index is handed out once
864-/// out once and reused, which is what keeps clipboard clips valid forever.937+/// and reused, which is what keeps clipboard clips valid forever -- and two
938+/// drags of that one row are two clips of it.
865 #[test]939 #[test]
866 fn importing_one_file_twice_reuses_its_source() {940 fn importing_one_file_twice_reuses_its_source() {
867 let mut session = open(asset("test_av.mp4"));941 let mut session = open(asset("test_av.mp4"));
868 let av2 = asset("test_av2.mp4");942 let av2 = asset("test_av2.mp4");
869- session.import(&av2).expect("first import");943+ assert_eq!(session.import(&av2).expect("first import"), 1);
870- session.import(&av2).expect("second import");944+ assert_eq!(
945+ session.import(&av2).expect("second import"),
946+ 1,
947+ "the second import is the same row"
948+ );
949+ assert_eq!(session.sources().len(), 2, "one row for one file");
950+ import_and_place(&mut session, &av2);
951+ import_and_place(&mut session, &av2);
952+ assert_eq!(session.sources().len(), 2, "and still one row");
871 assert_eq!(953 assert_eq!(
872 session954 session
873 .clip_spans_by_source()955 .clip_spans_by_source()
@@ -884,10 +966,15 @@ fn importing_one_file_twice_reuses_its_source() {
884 );966 );
885 }967 }
886 968
887-/// Importing after the timeline has been played out revives the session at the969+/// A library row placed after the timeline has been played out revives the
888-/// join, not at wherever the free-running clock got to.970+/// session: the placement reseeks like every other edit, and that is what
971+/// clears `eos`. The import itself changes nothing, played out or not.
972+///
973+/// Where it resumes is not asserted, for the reason `paste_at_eos_revives_the_
974+/// session` does not assert it either: an edit reseeks to `now()`, and at EOS
975+/// the free-running clock has gone past the end.
889 #[test]976 #[test]
890-fn import_at_eos_resumes_into_the_new_clip() {977+fn a_placement_at_eos_revives_the_session() {
891 let av2 = asset("test_av2.mp4");978 let av2 = asset("test_av2.mp4");
892 let mut session = open(asset("test_av.mp4"));979 let mut session = open(asset("test_av.mp4"));
893 let first = session.meta().frame_count;980 let first = session.meta().frame_count;
@@ -897,18 +984,24 @@ fn import_at_eos_resumes_into_the_new_clip() {
897 assert!(session.is_eos());984 assert!(session.is_eos());
898 985
899 session.import(&av2).expect("import at EOS");986 session.import(&av2).expect("import at EOS");
900- assert!(!session.is_eos(), "the import did not revive the session");
901- let landed = next_frame(&mut session, "import at EOS");
902- assert_eq!(landed.index, first, "resumed at the join");
903 assert!(987 assert!(
904- landed.bgra == source_frame(&av2, 0),988+ session.is_eos(),
905- "the resume is not showing the imported file"989+ "an import is not an edit: it cannot revive"
990+ );
991+ assert!(
992+ session
993+ .place_stream_at(session.timeline_duration(), &av2, 0, None)
994+ .expect("a file just imported is on this timeline")
995+ );
996+ assert!(
997+ !session.is_eos(),
998+ "the placement did not revive the session"
906 );999 );
907 assert_eq!(1000 assert_eq!(
908- drain_to_eof(&mut session).1,1001+ session.timeline_duration(),
909- Some(first + frame_count(&av2) - 1),1002+ f64::from(first + frame_count(&av2)) / session.meta().frame_rate
910- "the appended clip did not play out"
911 );1003 );
1004+ assert_eq!(session.clip_spans().len(), 2);
912 }1005 }
913 1006
914 /// A source deleted mid-session: the clip that names it contributes no pictures1007 /// A source deleted mid-session: the clip that names it contributes no pictures
@@ -920,7 +1013,7 @@ fn a_vanished_source_is_skipped() {
920 std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture");1013 std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture");
921 let mut session = open(asset("test_av.mp4"));1014 let mut session = open(asset("test_av.mp4"));
922 let first = session.meta().frame_count;1015 let first = session.meta().frame_count;
923- session.import(&scratch).expect("import the copy");1016+ import_and_place(&mut session, &scratch);
924 std::fs::remove_file(&scratch).expect("unlink");1017 std::fs::remove_file(&scratch).expect("unlink");
925 1018
926 session.seek(0.0);1019 session.seek(0.0);
@@ -931,9 +1024,9 @@ fn a_vanished_source_is_skipped() {
931 assert!(session.is_eos(), "the timeline still ends");1024 assert!(session.is_eos(), "the timeline still ends");
932 }1025 }
933 1026
934-/// Importing while the device is running: the import reseeks under the1027+/// Importing and placing while the device is running: the placement reseeks
935-/// playhead, so what must not happen is a stall -- the joined timeline still1028+/// under the playhead, so what must not happen is a stall -- the joined
936-/// plays out whole. No audio needed, so this runs anywhere.1029+/// timeline still plays out whole. No audio needed, so this runs anywhere.
937 #[test]1030 #[test]
938 fn import_during_play_does_not_stall() {1031 fn import_during_play_does_not_stall() {
939 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));1032 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));
@@ -945,9 +1038,9 @@ fn import_during_play_does_not_stall() {
945 run_for(&mut session, &mut last_index, Duration::from_millis(300));1038 run_for(&mut session, &mut last_index, Duration::from_millis(300));
946 assert!(last_index.is_some(), "no frames before the import");1039 assert!(last_index.is_some(), "no frames before the import");
947 1040
948- session.import(&av2).expect("import while playing");1041+ import_and_place(&mut session, &av2);
949 assert_eq!(session.clip_spans().len(), 2);1042 assert_eq!(session.clip_spans().len(), 2);
950- assert!(session.is_playing(), "the import stopped the clock");1043+ assert!(session.is_playing(), "the placement stopped the clock");
951 1044
952 // From here on the indices go *backwards* once: `run_for` decodes far ahead1045 // From here on the indices go *backwards* once: `run_for` decodes far ahead
953 // of the clock (ledger), and the import reseeks to `now()` -- which is why1046 // of the clock (ledger), and the import reseeks to `now()` -- which is why
@@ -961,38 +1054,37 @@ fn import_during_play_does_not_stall() {
961 );1054 );
962 }1055 }
963 1056
964-/// An import is *one* undo step: the appended clip goes, the source entry stays1057+/// An import is *not* an undo step -- a library row changes nothing playable,
965-/// behind (documented, harmless -- source indexes are forever), and the session1058+/// so there is nothing for `z` to take back -- and the placement that follows
966-/// is still playable on the restored timeline.1059+/// is one. Undoing it leaves the row in the library, where the user put it.
967 #[test]1060 #[test]
968-fn undo_after_import_is_one_step() {1061+fn an_import_is_not_an_undo_step_but_its_placement_is() {
969 let av2 = asset("test_av2.mp4");1062 let av2 = asset("test_av2.mp4");
970 let mut session = open(asset("test_av.mp4"));1063 let mut session = open(asset("test_av.mp4"));
971 session.import(&av2).expect("import");1064 session.import(&av2).expect("import");
1065+ assert!(!session.undo(), "an import must not be undoable");
1066+ assert_eq!(session.sources().len(), 2, "and it is still in the library");
1067+
1068+ import_and_place(&mut session, &av2);
972 assert_eq!(session.clip_spans().len(), 2);1069 assert_eq!(session.clip_spans().len(), 2);
973 assert!((session.timeline_duration() - 9.0).abs() < 1e-9);1070 assert!((session.timeline_duration() - 9.0).abs() < 1e-9);
974 1071
975- assert!(session.undo(), "undo the import");1072+ assert!(session.undo(), "undo the placement");
976 assert_eq!(session.clip_spans().len(), 1, "one step, back to one clip");1073 assert_eq!(session.clip_spans().len(), 1, "one step, back to one clip");
977 assert!(1074 assert!(
978 (session.timeline_duration() - 5.0).abs() < 1e-9,1075 (session.timeline_duration() - 5.0).abs() < 1e-9,
979 "undo did not restore the duration: {}",1076 "undo did not restore the duration: {}",
980 session.timeline_duration()1077 session.timeline_duration()
981 );1078 );
982-1079+ assert_eq!(
983- // The orphan source is only observable on the project -- `PlaybackSession`1080+ session.sources().len(),
984- // exposes sources through `clip_spans_by_source`, and the undone clip is1081+ 2,
985- // exactly the one that named it.1082+ "the library row survives an undo of the clip that used it"
986- let mut project = engine::Project::single(asset("test_av.mp4"), 150);1083+ );
987- let source = project.import(&av2, 0);
988- assert!(project.append_clip(source, 120));
989- assert!(project.undo());
990- assert_eq!(project.clips().len(), 1);
991- assert_eq!(project.sources().len(), 2, "the source entry stays behind");
992 1084
993 // Still playable: the undo reseeked to the (paused) playhead at zero.1085 // Still playable: the undo reseeked to the (paused) playhead at zero.
994 session.play();1086 session.play();
995- assert_eq!(next_index(&mut session, "undo of an import"), 0);1087+ assert_eq!(next_index(&mut session, "undo of a placement"), 0);
996 }1088 }
997 1089
998 /// The audio path across a source join: one worker spans both files, so the1090 /// The audio path across a source join: one worker spans both files, so the
@@ -1004,7 +1096,7 @@ fn undo_after_import_is_one_step() {
1004 #[ignore = "needs a running PipeWire daemon"]1096 #[ignore = "needs a running PipeWire daemon"]
1005 fn audio_runs_across_a_source_join() {1097 fn audio_runs_across_a_source_join() {
1006 let mut session = open(asset("test_av.mp4"));1098 let mut session = open(asset("test_av.mp4"));
1007- session.import(&asset("test_av2.mp4")).expect("import");1099+ import_and_place(&mut session, &asset("test_av2.mp4"));
1008 let first = session.meta().frame_count;1100 let first = session.meta().frame_count;
1009 1101
1010 session.seek(4.5); // half a second before the join1102 session.seek(4.5); // half a second before the join
crates/engine/tests/saveload.rsmodified+20 -10
@@ -44,14 +44,13 @@ fn a_picked_audio_stream_lands_saves_and_comes_back() {
44 let media = copy_in(&dir, "test_multilang.mp4");44 let media = copy_in(&dir, "test_multilang.mp4");
45 let mut session = PlaybackSession::open(&media).expect("open the fixture");45 let mut session = PlaybackSession::open(&media).expect("open the fixture");
46 session.set_gain(0.0); // silent like the rest of the suites46 session.set_gain(0.0); // silent like the rest of the suites
47- let frames = session.clip_at(0).expect("one clip").out_frame;
48 let end = session.timeline_duration();47 let end = session.timeline_duration();
49 48
50 // Stream 1 is the French track, same rate and layout as stream 0, so it49 // Stream 1 is the French track, same rate and layout as stream 0, so it
51 // can join this timeline; it lands as a second source of the same file.50 // can join this timeline; it lands as a second source of the same file.
52 assert!(51 assert!(
53 session52 session
54- .place_stream_at(end, &media, 1, frames, None)53+ .place_stream_at(end, &media, 1, None)
55 .expect("stream 1 matches the timeline")54 .expect("stream 1 matches the timeline")
56 );55 );
57 assert_eq!(56 assert_eq!(
@@ -83,15 +82,14 @@ fn a_picked_audio_stream_lands_saves_and_comes_back() {
83 let other = copy_in(&dir, "test_multiaudio.mp4");82 let other = copy_in(&dir, "test_multiaudio.mp4");
84 let mut session = PlaybackSession::open(&other).expect("open the fixture");83 let mut session = PlaybackSession::open(&other).expect("open the fixture");
85 session.set_gain(0.0);84 session.set_gain(0.0);
86- let frames = session.clip_at(0).expect("one clip").out_frame;
87 let err = session85 let err = session
88- .place_stream_at(0.0, &other, 1, frames, None)86+ .place_stream_at(0.0, &other, 1, None)
89 .expect_err("22.05 kHz mono cannot join a 44.1 kHz stereo timeline")87 .expect_err("22.05 kHz mono cannot join a 44.1 kHz stereo timeline")
90 .to_string();88 .to_string();
91 assert!(err.contains("22050"), "unhelpful refusal: {err}");89 assert!(err.contains("22050"), "unhelpful refusal: {err}");
92 assert!(90 assert!(
93 session91 session
94- .place_stream_at(0.0, &media, 1, frames, None)92+ .place_stream_at(0.0, &media, 1, None)
95 .expect_err("a file that is not a source")93 .expect_err("a file that is not a source")
96 .to_string()94 .to_string()
97 .contains("not on this timeline")95 .contains("not on this timeline")
@@ -120,7 +118,9 @@ fn a_trimmed_timeline_saves_and_opens_again() {
120 session.save_project(&path).expect("save");118 session.save_project(&path).expect("save");
121 let loaded = PlaybackSession::open_project(&path).expect("a trimmed project opens");119 let loaded = PlaybackSession::open_project(&path).expect("a trimmed project opens");
122 assert_eq!(120 assert_eq!(
123- loaded.clip_at(0).map(|c| (c.start, c.in_frame, c.out_frame)),121+ loaded
122+ .clip_at(0)
123+ .map(|c| (c.start, c.in_frame, c.out_frame)),
124 Some((5, 5, whole.end() / 2)),124 Some((5, 5, whole.end() / 2)),
125 "the trimmed range is what came back"125 "the trimmed range is what came back"
126 );126 );
@@ -142,9 +142,17 @@ fn a_trimmed_timeline_saves_and_opens_again() {
142 /// with something to lose in every field.142 /// with something to lose in every field.
143 fn edited(dir: &Path) -> PlaybackSession {143 fn edited(dir: &Path) -> PlaybackSession {
144 let mut session = PlaybackSession::open(copy_in(dir, "test_av.mp4")).expect("open");144 let mut session = PlaybackSession::open(copy_in(dir, "test_av.mp4")).expect("open");
145- session145+ // Imported into the library, then dragged onto the end -- the two acts a
146- .import(&copy_in(dir, "test_av2.mp4"))146+ // second file on the timeline takes.
147- .expect("import the second file");147+ let second = copy_in(dir, "test_av2.mp4");
148+ session.import(&second).expect("import the second file");
149+ let end = session.timeline_duration();
150+ assert!(
151+ session
152+ .place_stream_at(end, &second, 0, None)
153+ .expect("a file just imported is on this timeline"),
154+ "drag it onto the end"
155+ );
148 assert!(session.cut_at(2.0), "cut inside the first file");156 assert!(session.cut_at(2.0), "cut inside the first file");
149 assert!(session.cut_at(6.5), "cut inside the second file");157 assert!(session.cut_at(6.5), "cut inside the second file");
150 assert!(158 assert!(
@@ -505,10 +513,12 @@ fn a_folder_of_media_and_its_project_can_be_moved() {
505 fn orphan_sources_are_not_written() {513 fn orphan_sources_are_not_written() {
506 let dir = scratch("orphans");514 let dir = scratch("orphans");
507 let mut session = PlaybackSession::open(copy_in(&dir, "test_av.mp4")).expect("open");515 let mut session = PlaybackSession::open(copy_in(&dir, "test_av.mp4")).expect("open");
516+ // An import that was never dragged onto a lane *is* the orphan: a library
517+ // row with no clip naming it. (So is one whose clip was undone -- the same
518+ // entry, reached the other way.)
508 session519 session
509 .import(&copy_in(&dir, "test_av2.mp4"))520 .import(&copy_in(&dir, "test_av2.mp4"))
510 .expect("import");521 .expect("import");
511- assert!(session.undo(), "take the import back");
512 assert_eq!(522 assert_eq!(
513 session.sources().len(),523 session.sources().len(),
514 2,524 2,
scripts/gen_fixtures.shmodified+10 -0
@@ -117,6 +117,16 @@ ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
117 # has something concrete to refuse.117 # has something concrete to refuse.
118 ffmpeg -y -f lavfi -i testsrc2=size=640x360:rate=30:duration=2 \118 ffmpeg -y -f lavfi -i testsrc2=size=640x360:rate=30:duration=2 \
119 -an -c:v libx264 -profile:v baseline -pix_fmt yuv420p assets/test_mismatch.mp4119 -an -c:v libx264 -profile:v baseline -pix_fmt yuv420p assets/test_mismatch.mp4
120+# Frame-rate fixture: test_av.mp4 in every respect a timeline is held to -- same
121+# codec, same profile, same 44.1k stereo AAC -- except that it runs at 25 fps.
122+# The only thing left for an import to refuse is the rate, which is what makes
123+# the refusal's wording testable.
124+ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=25:duration=2 \
125+ -f lavfi -i "sine=frequency=440:duration=2" \
126+ -f lavfi -i "sine=frequency=880:duration=2" \
127+ -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
128+ -map 0:v -map "[a]" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
129+ -c:a aac -b:a 128k assets/test_25fps.mp4
120 # Standalone audio fixtures: the same 440/880 Hz tone with the 1 Hz pulse the130 # Standalone audio fixtures: the same 440/880 Hz tone with the 1 Hz pulse the
121 # A/V fixture carries, at test_av.mp4's own 44.1k stereo -- so an imported song131 # A/V fixture carries, at test_av.mp4's own 44.1k stereo -- so an imported song
122 # can share a timeline with the video clips and the peaks tests can reuse the132 # can share a timeline with the video clips and the peaks tests can reuse the