Imported files land in the library, never on the timeline
Browse files at this commit5cb33d89e8c3b356830324c07dbec1e2a0ea3c6aParent: a3e9dc2- feat
- imported files land in the library, never on the timeline
6 changed files +424 -292
- crates/app/src/main.rs +138 -170
- crates/engine/src/playback.rs +75 -53
- crates/engine/tests/audio_files.rs +41 -11
- crates/engine/tests/playback.rs +140 -48
- crates/engine/tests/saveload.rs +20 -10
- scripts/gen_fixtures.sh +10 -0
crates/app/src/main.rsmodified+138 -170
| @@ -19,9 +19,9 @@ use engine::{Clip, ExportHandle, Frame, PlaybackSession}; | ||
| 19 | 19 | use gpui::{ |
| 20 | 20 | AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, FocusHandle, |
| 21 | 21 | KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, PathBuilder, Pixels, |
| 22 | - Point, | |
| 23 | - RenderImage, SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, WindowBounds, | |
| 24 | - WindowOptions, canvas, div, img, point, prelude::*, px, relative, rgb, rgba, size, | |
| 22 | + Point, RenderImage, SharedString, Size, Stateful, TextAlign, TitlebarOptions, Window, | |
| 23 | + WindowBounds, WindowOptions, canvas, div, img, point, prelude::*, px, relative, rgb, rgba, | |
| 24 | + size, | |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | 27 | /// Editor chrome: three grays and one accent, all darker than the picture so the |
| @@ -1446,17 +1446,13 @@ impl Player { | ||
| 1446 | 1446 | cx.notify(); |
| 1447 | 1447 | return; |
| 1448 | 1448 | } |
| 1449 | - let frames = self.session.as_ref().map_or(0, |session| { | |
| 1450 | - source_frames(lane_clips(session), session.sources(), path) | |
| 1451 | - }); | |
| 1452 | - // Zero means nothing on the timeline plays from that file any more | |
| 1453 | - // -- an undone import leaves the source entry behind (project.rs:264) | |
| 1454 | - // -- so there is no length to insert and no file to ask for one. | |
| 1455 | - let placed = match (&mut self.session, frames) { | |
| 1456 | - (Some(session), 1..) => { | |
| 1457 | - session.place_stream_at(session.now(), path, stream, frames, onto) | |
| 1458 | - } | |
| 1459 | - _ => Ok(false), | |
| 1449 | + // The engine's own length for the file, noted when the import took it | |
| 1450 | + // in: a row that has never been on a lane is placeable at its full | |
| 1451 | + // length, which is the whole point of an import that only fills the | |
| 1452 | + // library. | |
| 1453 | + let placed = match &mut self.session { | |
| 1454 | + Some(session) => session.place_stream_at(session.now(), path, stream, onto), | |
| 1455 | + None => Ok(false), | |
| 1460 | 1456 | }; |
| 1461 | 1457 | match placed { |
| 1462 | 1458 | Ok(true) => { |
| @@ -1467,9 +1463,7 @@ impl Player { | ||
| 1467 | 1463 | // says which property disagrees, exactly as a refused import does. |
| 1468 | 1464 | Err(e) => self.notice = Some(format!("NOTHING ADDED — {e}").into()), |
| 1469 | 1465 | Ok(false) => { |
| 1470 | - self.notice = Some( | |
| 1471 | - "NOTHING ADDED — no clip on the timeline plays from that file any more".into(), | |
| 1472 | - ) | |
| 1466 | + self.notice = Some("NOTHING ADDED — that file could not be placed here".into()) | |
| 1473 | 1467 | } |
| 1474 | 1468 | } |
| 1475 | 1469 | cx.notify(); |
| @@ -1488,37 +1482,48 @@ impl Player { | ||
| 1488 | 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, so | |
| 1492 | - /// the export guard on the key handler does not cover it and this checks for | |
| 1493 | - /// itself. The engine reseeks, so like a delete it owes the flag reset; a | |
| 1494 | - /// refusal is shown as the engine worded it and changes nothing. | |
| 1485 | + /// Takes a file into the library and nowhere else: the timeline is not | |
| 1486 | + /// touched, and the row is dragged onto a lane when it is wanted there. A | |
| 1487 | + /// drop is not a key press, so the export guard on the key handler does not | |
| 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 | 1490 | fn import(&mut self, path: &std::path::Path, cx: &mut Context<Self>) { |
| 1496 | 1491 | if self.exporting().is_some() { |
| 1497 | 1492 | return; |
| 1498 | 1493 | } |
| 1499 | - // An empty window has nothing to append to: there the first file *is* | |
| 1500 | - // the timeline and is opened as one, which is the same fork a launch | |
| 1501 | - // makes between its first argument and the rest. | |
| 1494 | + // An empty window has no library to add to yet: the file opens one, and | |
| 1495 | + // the timeline under it stays empty, because an import is an import | |
| 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 | 1499 | let text = match self.session.as_mut().map(|session| session.import(path)) { |
| 1503 | - Some(Ok(())) => { | |
| 1504 | - self.reset_after_reseek(); | |
| 1505 | - format!("IMPORTED {}", file_name(path)) | |
| 1506 | - } | |
| 1500 | + Some(Ok(_)) => format!( | |
| 1501 | + "IMPORTED {} to the library — drag it onto a lane to place it", | |
| 1502 | + file_name(path) | |
| 1503 | + ), | |
| 1507 | 1504 | Some(Err(e)) => format!("IMPORT FAILED: {e}"), |
| 1508 | - None => self.open_media(path), | |
| 1505 | + None => self.open_media(path, false), | |
| 1509 | 1506 | }; |
| 1510 | 1507 | eprintln!("{text}"); |
| 1511 | 1508 | self.notice = Some(text.into()); |
| 1512 | 1509 | cx.notify(); |
| 1513 | 1510 | } |
| 1514 | 1511 | |
| 1515 | - /// Takes a file as the whole timeline, which is what an empty window is | |
| 1516 | - /// waiting for. Everything derived from the media -- the clock, the title, | |
| 1517 | - /// where an export and a save go -- is set here, exactly as a launch with a | |
| 1518 | - /// file argument sets it. Paused with its first frame showing, like every | |
| 1519 | - /// other way a timeline arrives. | |
| 1520 | - fn open_media(&mut self, path: &std::path::Path) -> String { | |
| 1521 | - match PlaybackSession::open(path) { | |
| 1512 | + /// Takes a file as the session an empty window is waiting for. Everything | |
| 1513 | + /// derived from the media -- the clock, the title, where an export and a | |
| 1514 | + /// save go -- is set here, exactly as a launch with a file argument sets | |
| 1515 | + /// it. Paused with its first frame showing, like every other way a timeline | |
| 1516 | + /// arrives. | |
| 1517 | + /// | |
| 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 | 1527 | Ok(session) => { |
| 1523 | 1528 | self.fps = session.meta().frame_rate; |
| 1524 | 1529 | // Read before the session moves: a file that plays silent says |
| @@ -1534,7 +1539,16 @@ impl Player { | ||
| 1534 | 1539 | self.project_path = project_path(path); |
| 1535 | 1540 | self.name = file_name(path).into(); |
| 1536 | 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 | 1553 | Err(e) => format!("OPEN FAILED: {e}"), |
| 1540 | 1554 | } |
| @@ -1553,7 +1567,7 @@ impl Player { | ||
| 1553 | 1567 | let picked = picked.await; |
| 1554 | 1568 | this.update(cx, |this, cx| match picked { |
| 1555 | 1569 | // 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 | 1571 | Ok(Some(path)) if is_project(&path) => this.load_project(&path, cx), |
| 1558 | 1572 | Ok(Some(path)) => this.import(&path, cx), |
| 1559 | 1573 | // Cancelled: the user already knows what happened. |
| @@ -2141,7 +2155,7 @@ impl Render for Player { | ||
| 2141 | 2155 | return; |
| 2142 | 2156 | } |
| 2143 | 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 | 2159 | if is_project(path) { |
| 2146 | 2160 | this.load_project(path, cx); |
| 2147 | 2161 | } else { |
| @@ -2324,12 +2338,13 @@ impl Player { | ||
| 2324 | 2338 | // the door (the import policy, ledger:436), so the session's own meta |
| 2325 | 2339 | // describes every row and nothing has to be probed to say so. |
| 2326 | 2340 | let meta = self.session.as_ref().map(PlaybackSession::meta); |
| 2327 | - let clips: Vec<Clip> = self | |
| 2328 | - .session | |
| 2329 | - .as_ref() | |
| 2330 | - .map_or_else(Vec::new, |session| lane_clips(session).copied().collect()); | |
| 2341 | + // Its own length, not one derived from what is on the lanes: a row | |
| 2342 | + // imported and never placed is a row with a length, and it is the | |
| 2343 | + // length a drag would put down. | |
| 2331 | 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 | 2349 | .into_iter() |
| 2335 | 2350 | .enumerate() |
| @@ -2461,7 +2476,7 @@ impl Player { | ||
| 2461 | 2476 | "import", |
| 2462 | 2477 | None, |
| 2463 | 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 | 2480 | !exporting, |
| 2466 | 2481 | cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_import(cx)), |
| 2467 | 2482 | )), |
| @@ -2824,8 +2839,10 @@ impl Player { | ||
| 2824 | 2839 | .id("notice") |
| 2825 | 2840 | .when(exported.is_some(), |d| { |
| 2826 | 2841 | d.tooltip(|_, cx| { |
| 2827 | - cx.new(|_| Tip("Open file location — shows the export in the file manager".into())) | |
| 2828 | - .into() | |
| 2842 | + cx.new(|_| { | |
| 2843 | + Tip("Open file location — shows the export in the file manager".into()) | |
| 2844 | + }) | |
| 2845 | + .into() | |
| 2829 | 2846 | }) |
| 2830 | 2847 | }) |
| 2831 | 2848 | .flex_none() |
| @@ -3581,14 +3598,7 @@ impl Player { | ||
| 3581 | 3598 | format!("{} – {}", secs(clip.in_frame), secs(clip.out_frame)), |
| 3582 | 3599 | ), |
| 3583 | 3600 | ("This clip", secs(clip.len())), |
| 3584 | - ( | |
| 3585 | - "Source duration", | |
| 3586 | - secs(source_frames( | |
| 3587 | - lane_clips(session), | |
| 3588 | - session.sources(), | |
| 3589 | - &source.path, | |
| 3590 | - )), | |
| 3591 | - ), | |
| 3601 | + ("Source duration", secs(session.file_frames(&source.path))), | |
| 3592 | 3602 | ] { |
| 3593 | 3603 | rows.push( |
| 3594 | 3604 | row(rows.len()) |
| @@ -4190,41 +4200,6 @@ fn unseen_paths(sources: &[Source], streams: &HashMap<PathBuf, Vec<StreamInfo>>) | ||
| 4190 | 4200 | 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 | 4203 | /// Which timeline frame the playhead is on, by the rule the engine's own edits |
| 4229 | 4204 | /// use (playback.rs `secs_to_frame`): the frame that has started, with the |
| 4230 | 4205 | /// epsilon that keeps a clock sitting exactly on a boundary from reading as the |
| @@ -5226,10 +5201,10 @@ mod tests { | ||
| 5226 | 5201 | RULER_HIT_H, SELECTED, SOURCE_TINTS, SURFACE, SWATCH_W, Source, StreamInfo, Volume, |
| 5227 | 5202 | WAVE_BPS, WAVE_COL, Wave, applicable, band_label, can_add, cancels_export, color_snap, |
| 5228 | 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, | |
| 5230 | - menu_at, mp4_refusal, normalise, panel_h, project_path, push_digit, retarget, scrub_due, | |
| 5231 | - show_label, source_frames, source_tint, start_frac, timecode, unseen_paths, unseen_sources, | |
| 5232 | - whole_take, width_frac, window_title, | |
| 5204 | + frame_at, histogram, is_bare_modifier, is_project, keymap, lanes_h, marked, menu_at, | |
| 5205 | + mp4_refusal, normalise, panel_h, project_path, push_digit, retarget, scrub_due, show_label, | |
| 5206 | + source_tint, start_frac, timecode, unseen_paths, unseen_sources, whole_take, width_frac, | |
| 5207 | + window_title, | |
| 5233 | 5208 | }; |
| 5234 | 5209 | use super::{file_name, file_uri, library_rows}; |
| 5235 | 5210 | |
| @@ -5237,7 +5212,10 @@ mod tests { | ||
| 5237 | 5212 | /// the ones the bus would otherwise read as something else. |
| 5238 | 5213 | #[test] |
| 5239 | 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 | 5219 | assert_eq!( |
| 5242 | 5220 | file_uri(std::path::Path::new("/home/x/out dir/my export.mp4")), |
| 5243 | 5221 | "file:///home/x/out%20dir/my%20export.mp4" |
| @@ -5260,21 +5238,6 @@ mod tests { | ||
| 5260 | 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 | 5241 | /// A source entry for `path` on `stream`, as the project keeps them. |
| 5279 | 5242 | fn source(path: &str, stream: usize) -> Source { |
| 5280 | 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 files | |
| 5287 | - /// there are, how long each one is, and therefore which tint each row wears | |
| 5288 | - /// -- one index into one list, so a swatch cannot name a different file from | |
| 5289 | - /// the boxes it is meant to point at. | |
| 5249 | + /// An import fills the *library* and nothing else -- the whole point of | |
| 5250 | + /// this door: the row is there at the file's own length before any clip | |
| 5251 | + /// plays it, wearing the tint the lanes will tint that clip with, and the | |
| 5252 | + /// timeline is exactly as long as it was. Placing it is the drag, and the | |
| 5253 | + /// drag is a separate act. | |
| 5290 | 5254 | #[test] |
| 5291 | - fn a_rows_swatch_and_duration_come_off_the_clips_that_name_it() { | |
| 5292 | - // Source 0 whole, source 1 trimmed to half of what it was, source 2 on | |
| 5293 | - // the audio lane only (its picture was lifted), source 3 imported and | |
| 5294 | - // then undone -- an entry with nothing playing from it. | |
| 5295 | - let sources: Vec<Source> = (0..4).map(|i| source(&format!("/m/{i}.mp4"), 0)).collect(); | |
| 5296 | - let video = [clip(0, 150), clip(1, 60)]; | |
| 5297 | - let audio = [clip(0, 150), clip(1, 30), clip(2, 90)]; | |
| 5298 | - for (row, frames) in [(0, 150), (1, 60), (2, 90), (3, 0)] { | |
| 5299 | - assert_eq!( | |
| 5300 | - source_frames(video.iter().chain(&audio), &sources, &sources[row].path), | |
| 5301 | - frames, | |
| 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; | |
| 5255 | + fn an_import_adds_a_row_at_its_own_length_and_leaves_the_lanes_alone() { | |
| 5256 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | |
| 5257 | + session.set_gain(0.0); | |
| 5258 | + let before = session.timeline_duration(); | |
| 5259 | + let clips: Vec<usize> = session | |
| 5260 | + .lanes() | |
| 5261 | + .into_iter() | |
| 5262 | + .map(|lane| session.lane_clips(lane).len()) | |
| 5263 | + .collect(); | |
| 5264 | + session.import(&asset("test_av2.mp4")).expect("av2 matches"); | |
| 5265 | + assert_eq!(session.sources().len(), 2, "the library grew"); | |
| 5312 | 5266 | assert_eq!( |
| 5313 | - source_frames([clip(0, 10), clip(0, 90)].iter(), &one, path), | |
| 5314 | - 90 | |
| 5267 | + session.timeline_duration(), | |
| 5268 | + before, | |
| 5269 | + "an import must not place a clip" | |
| 5315 | 5270 | ); |
| 5316 | 5271 | assert_eq!( |
| 5317 | - source_frames([clip(0, 90), clip(0, 10)].iter(), &one, path), | |
| 5318 | - 90 | |
| 5272 | + session | |
| 5273 | + .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); | |
| 5321 | - // Two audio streams of one file are two source entries and one length: | |
| 5322 | - // the second stream's row is placeable the moment the file is there, | |
| 5323 | - // before any clip names that entry. | |
| 5324 | - let two = [source("/m/0.mp4", 0), source("/m/0.mp4", 1)]; | |
| 5325 | - assert_eq!(source_frames([clip(0, 90)].iter(), &two, &two[1].path), 90); | |
| 5280 | + // The rows the panel draws: one per source, each its file's own length | |
| 5281 | + // -- source 1 has no clip anywhere and is still 4 s at 30 fps. | |
| 5282 | + let rows = library_rows(session.sources(), &HashMap::new(), None, |path| { | |
| 5283 | + session.file_frames(path) | |
| 5284 | + }); | |
| 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 | 5296 | /// The window opened on a song and nothing else -- the launch argument, the |
| @@ -5351,7 +5319,7 @@ mod tests { | ||
| 5351 | 5319 | .iter() |
| 5352 | 5320 | .find(|s| s.index == session.sources()[0].audio_stream) |
| 5353 | 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 | 5323 | let rows = library_rows(session.sources(), &streams, rate, |_| frames); |
| 5356 | 5324 | assert_eq!(rows.len(), 1); |
| 5357 | 5325 | assert_eq!(rows[0].name, "test_tone.mp3"); |
| @@ -5363,7 +5331,7 @@ mod tests { | ||
| 5363 | 5331 | session.seek(1.0); |
| 5364 | 5332 | assert!( |
| 5365 | 5333 | 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 | 5335 | .expect("its own file is on this timeline") |
| 5368 | 5336 | ); |
| 5369 | 5337 | assert_eq!(session.lane_clips(Lane::A1).len(), 2); |
| @@ -5588,14 +5556,11 @@ mod tests { | ||
| 5588 | 5556 | assert!(refusal.contains("audio"), "refusal must name it: {refusal}"); |
| 5589 | 5557 | assert_eq!(session.sources().len(), 1, "a refusal added a row"); |
| 5590 | 5558 | // 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 | 5560 | session.import(&asset("test_av2.mp4")).expect("av2 matches"); |
| 5593 | 5561 | assert_eq!(session.sources().len(), 2); |
| 5594 | 5562 | let second = session.sources()[1].path.clone(); |
| 5595 | - assert_eq!( | |
| 5596 | - source_frames(lane_clips(&session), session.sources(), &second), | |
| 5597 | - 120 | |
| 5598 | - ); | |
| 5563 | + assert_eq!(session.file_frames(&second), 120); | |
| 5599 | 5564 | assert_eq!(timecode(120. / 30., 30.), "00:00:04:00"); |
| 5600 | 5565 | } |
| 5601 | 5566 | |
| @@ -5607,21 +5572,22 @@ mod tests { | ||
| 5607 | 5572 | let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); |
| 5608 | 5573 | session.set_gain(0.0); |
| 5609 | 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 | 5577 | // Two seconds in, which is inside the first take: the insert splits it. |
| 5612 | 5578 | session.seek(2.0); |
| 5613 | 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 | 5581 | // Through the engine door `insert_source` uses, with the row's own |
| 5616 | 5582 | // stream: the button, the drop and this are one call. |
| 5617 | 5583 | assert!( |
| 5618 | 5584 | session |
| 5619 | - .place_stream_at(2.0, &second, 0, frames, None) | |
| 5585 | + .place_stream_at(2.0, &second, 0, None) | |
| 5620 | 5586 | .expect("av2 is already on the timeline") |
| 5621 | 5587 | ); |
| 5622 | 5588 | // The whole of source 1 went in and nothing was painted over: the |
| 5623 | 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 | 5591 | let (video, audio) = (session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)); |
| 5626 | 5592 | // One take, not a video clip with no sound under it: both lanes hold |
| 5627 | 5593 | // the same clip at the same place, in the same group. |
| @@ -5644,21 +5610,18 @@ mod tests { | ||
| 5644 | 5610 | PlaybackSession::open(asset("test_multilang.mp4")).expect("open the fixture"); |
| 5645 | 5611 | session.set_gain(0.0); |
| 5646 | 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 | 5614 | let end = session.timeline_duration(); |
| 5649 | 5615 | assert!( |
| 5650 | 5616 | session |
| 5651 | - .place_stream_at(end, &path, 1, frames, None) | |
| 5617 | + .place_stream_at(end, &path, 1, None) | |
| 5652 | 5618 | .expect("the French track shares the timeline's parameters") |
| 5653 | 5619 | ); |
| 5654 | 5620 | assert_eq!(session.sources()[1].audio_stream, 1); |
| 5655 | 5621 | assert_eq!(session.timeline_duration(), end * 2.0); |
| 5656 | 5622 | // Both rows are the same file, so both rows are that file's length -- |
| 5657 | 5623 | // the second one before any clip of its own existed. |
| 5658 | - assert_eq!( | |
| 5659 | - source_frames(lane_clips(&session), session.sources(), &path), | |
| 5660 | - frames | |
| 5661 | - ); | |
| 5624 | + assert_eq!(session.file_frames(&path), frames); | |
| 5662 | 5625 | } |
| 5663 | 5626 | |
| 5664 | 5627 | /// The trim-a-clip path through the doors the edge drag uses: |
| @@ -5701,7 +5664,11 @@ mod tests { | ||
| 5701 | 5664 | |
| 5702 | 5665 | // ...and dragged back out, as far as the file goes and no further. |
| 5703 | 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 | 5673 | // The head takes the in-point with it, so what plays at the new start |
| 5707 | 5674 | // is source frame 10 rather than source frame 0. |
| @@ -5780,10 +5747,9 @@ mod tests { | ||
| 5780 | 5747 | // A library row let go over that row: the same door the Add button |
| 5781 | 5748 | // uses, told which lane it was let go over. |
| 5782 | 5749 | let path = session.sources()[0].path.clone(); |
| 5783 | - let frames = source_frames(lane_clips(&session), session.sources(), &path); | |
| 5784 | 5750 | assert!( |
| 5785 | 5751 | session |
| 5786 | - .place_stream_at(1.0, &path, 0, frames, Some(v2)) | |
| 5752 | + .place_stream_at(1.0, &path, 0, Some(v2)) | |
| 5787 | 5753 | .expect("its own file is on this timeline") |
| 5788 | 5754 | ); |
| 5789 | 5755 | assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2"); |
| @@ -5809,7 +5775,7 @@ mod tests { | ||
| 5809 | 5775 | assert_eq!(mp4_refusal(&session), None, "an empty lane carries nothing"); |
| 5810 | 5776 | assert!( |
| 5811 | 5777 | session |
| 5812 | - .place_stream_at(0.0, &path, 0, frames, Some(a2)) | |
| 5778 | + .place_stream_at(0.0, &path, 0, Some(a2)) | |
| 5813 | 5779 | .expect("its own file is on this timeline") |
| 5814 | 5780 | ); |
| 5815 | 5781 | assert_eq!( |
| @@ -6761,8 +6727,8 @@ mod tests { | ||
| 6761 | 6727 | fn main() { |
| 6762 | 6728 | let arg = std::env::args().nth(1).map(PathBuf::from); |
| 6763 | 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 at | |
| 6765 | - // all opens the window empty -- the timeline then arrives by drop or by the | |
| 6730 | + // Either way the rest of argv is imported into its library. No argument at | |
| 6731 | + // all opens the window empty -- the library then arrives by drop or by the | |
| 6766 | 6732 | // Import button, and everything below is derived from it at that point |
| 6767 | 6733 | // instead. |
| 6768 | 6734 | let mut session = match &arg { |
| @@ -6792,8 +6758,10 @@ fn main() { | ||
| 6792 | 6758 | if let Some(text) = ¬ice { |
| 6793 | 6759 | eprintln!("{text}"); |
| 6794 | 6760 | } |
| 6795 | - // The first file makes the timeline, the rest are appended to it. A refusal | |
| 6796 | - // is not fatal -- the others still load -- but the window must not open | |
| 6761 | + // The first file makes the timeline -- naming a file to open is a decision | |
| 6762 | + // 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 | 6765 | // silently pretending the file was taken, so the first one seeds the notice. |
| 6798 | 6766 | for extra in std::env::args().skip(2) { |
| 6799 | 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 | 246 | /// Opens a standalone audio file ([`crate::is_audio`]) as a timeline of its |
| 220 | 247 | /// own: one clip on `A1`, nothing on the video lane, and a picture that is |
| 221 | 248 | /// the black of an uncovered canvas ([`AUDIO_ONLY_CANVAS`]) for as long as |
| @@ -775,6 +802,25 @@ impl PlaybackSession { | ||
| 775 | 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 | 824 | /// The clip the picture is coming from at `timeline_secs`: the lane it sits |
| 779 | 825 | /// on and its index there, by the same topmost-lane-wins rule the decoder |
| 780 | 826 | /// follows. `None` over a gap and past the end. What a card that grades |
| @@ -880,7 +926,7 @@ impl PlaybackSession { | ||
| 880 | 926 | self.edit(|p| p.paste(at, clip)) |
| 881 | 927 | } |
| 882 | 928 | |
| 883 | - /// Places `frames` of `path` played on its audio `stream` at | |
| 929 | + /// Places the whole of `path` played on its audio `stream` at | |
| 884 | 930 | /// `timeline_secs`, the way [`paste_at`](Self::paste_at) places a copy -- |
| 885 | 931 | /// the door a library row goes through, and the only way a stream other |
| 886 | 932 | /// than the one an import brought in reaches the timeline. The `(file, |
| @@ -908,20 +954,22 @@ impl PlaybackSession { | ||
| 908 | 954 | timeline_secs: f64, |
| 909 | 955 | path: &Path, |
| 910 | 956 | stream: usize, |
| 911 | - frames: u32, | |
| 912 | 957 | onto: Option<Lane>, |
| 913 | 958 | ) -> crate::Result<bool> { |
| 914 | 959 | let wanted = Source::new(path, stream); |
| 915 | - // Another stream of a file whose picture is *already* on the timeline: | |
| 916 | - // that is what a library row is, and it is why nothing here has to | |
| 917 | - // check dimensions or frame rate -- the file passed that at import. | |
| 918 | - if !self.project.sources().iter().any(|s| s.path == wanted.path) { | |
| 960 | + // Another stream of a file this session has taken in: that is what a | |
| 961 | + // library row is, and it is why nothing here has to check dimensions or | |
| 962 | + // frame rate -- the file passed that at import. Its length is the one | |
| 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 | 967 | return Err(format!("{} is not on this timeline", path.display()).into()); |
| 920 | 968 | } |
| 921 | 969 | let first = self.first_audio()?; |
| 922 | 970 | audio_matches(&wanted, &first)?; |
| 923 | 971 | let source = self.project.import(path, stream); |
| 924 | - self.note_frames(source, frames.max(1)); | |
| 972 | + self.note_frames(source, frames); | |
| 925 | 973 | let clip = Clip { |
| 926 | 974 | start: 0, |
| 927 | 975 | in_frame: 0, |
| @@ -993,15 +1041,24 @@ impl PlaybackSession { | ||
| 993 | 1041 | self.edit(Project::undo) |
| 994 | 1042 | } |
| 995 | 1043 | |
| 996 | - /// Appends the whole of `path` to the end of the timeline. One undo step, | |
| 997 | - /// and the file becomes a source only if it is not one already. | |
| 1044 | + /// Takes `path` into the **library**: it becomes a source of this session, | |
| 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 | 1056 | /// Refused unless it can join the timeline -- same codec, same frame rate, |
| 1000 | 1057 | /// same audio parameters or both silent; the `Err` names the property that |
| 1001 | 1058 | /// disagrees, for a caller to show. Nothing is changed by a refusal. A |
| 1002 | 1059 | /// *resolution* of its own is not a refusal: the clip is placed on the |
| 1003 | 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 | 1062 | if crate::is_audio(path) { |
| 1006 | 1063 | return self.import_audio(path); |
| 1007 | 1064 | } |
| @@ -1011,64 +1068,29 @@ impl PlaybackSession { | ||
| 1011 | 1068 | // [`place_stream_at`](Self::place_stream_at) is how any other one of |
| 1012 | 1069 | // its streams reaches the timeline afterwards. |
| 1013 | 1070 | matches_timeline(&Source::new(path, 0), &meta, &self.meta, &first)?; |
| 1014 | - | |
| 1015 | - let old_end = self.timeline_duration(); | |
| 1016 | 1071 | let source = self.project.import(path, 0); |
| 1017 | 1072 | self.note_frames(source, meta.frame_count); |
| 1018 | - // Refused only for an unknown index, and this one just came from `import`. | |
| 1019 | - self.project.append_clip(source, meta.frame_count); | |
| 1020 | - // Reseek like any other edit, even though nothing before the playhead | |
| 1021 | - // moved: the running audio worker's segment list stops at the old end, | |
| 1022 | - // so without this the appended clip would play silent. At EOS the wall | |
| 1023 | - // clock has run on past the timeline, so resume from the join instead | |
| 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. | |
| 1073 | + Ok(source) | |
| 1074 | + } | |
| 1075 | + | |
| 1076 | + /// The same registration for a standalone audio file: a song has no | |
| 1077 | + /// picture, so the length noted for it is its playing time rounded up to | |
| 1078 | + /// whole frames, which is the only frame count such a source has. | |
| 1035 | 1079 | /// |
| 1036 | 1080 | /// Refused in the same words as any other import when its rate or layout |
| 1037 | 1081 | /// disagrees with the timeline's -- one output device, one set of |
| 1038 | 1082 | /// parameters -- and refused outright on a silent timeline, which has no |
| 1039 | 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 | 1085 | let first = self.first_audio()?; |
| 1042 | 1086 | // Stream 0, and there is no other: a standalone audio file carries one |
| 1043 | 1087 | // track (`AudioSession::probe_streams`), so nothing here has a stream |
| 1044 | 1088 | // to pick the way `place_stream_at` does for an mp4. |
| 1045 | 1089 | audio_matches(&Source::new(path, 0), &first)?; |
| 1046 | 1090 | let frames = audio_frames(path, self.meta.frame_rate)?; |
| 1047 | - | |
| 1048 | - let old_end = self.timeline_duration(); | |
| 1049 | 1091 | let source = self.project.import(path, 0); |
| 1050 | 1092 | self.note_frames(source, frames); |
| 1051 | - let at = self.project.timeline_frames(); | |
| 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(()) | |
| 1093 | + Ok(source) | |
| 1072 | 1094 | } |
| 1073 | 1095 | |
| 1074 | 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 | 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 | 49 | /// The message of a call that had to be refused. Not `expect_err`: that wants |
| 36 | 50 | /// `Debug` on the success side, and neither a session nor a packet has it. |
| 37 | 51 | fn refusal<T>(result: engine::Result<T>) -> String { |
| @@ -119,11 +133,24 @@ fn duration_comes_from_the_header_or_the_decode() { | ||
| 119 | 133 | fn a_song_joins_a_video_timeline_on_the_audio_lane() { |
| 120 | 134 | let mut session = open(asset("test_av.mp4")); |
| 121 | 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 | 138 | session |
| 123 | 139 | .import(&asset("test_tone.mp3")) |
| 124 | 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 | 154 | assert!( |
| 128 | 155 | (session.timeline_duration() - (before + 3.0)).abs() < 0.05, |
| 129 | 156 | "{} s of timeline, want {}", |
| @@ -151,7 +178,7 @@ fn a_rate_the_device_cannot_mix_is_refused_at_the_door() { | ||
| 151 | 178 | refusal(session.import(&asset("test_tone_48k.wav"))), |
| 152 | 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 | 182 | assert_eq!(session.sources().len(), 1); |
| 156 | 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 | 255 | let mut session = open(asset("test_tone.mp3")); |
| 229 | 256 | // A second song joins it, the same way one joins a timeline of video: no |
| 230 | 257 | // picture is needed for the import to have something to hold it to. |
| 231 | - session | |
| 232 | - .import(&asset("test_tone.flac")) | |
| 233 | - .expect("a song joins a song"); | |
| 258 | + import_and_place(&mut session, &asset("test_tone.flac")); | |
| 234 | 259 | assert_eq!(session.lane_clips(Lane::A1).len(), 2); |
| 235 | 260 | assert!(session.lane_clips(Lane::V1).is_empty()); |
| 236 | 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 | 329 | #[test] |
| 305 | 330 | fn a_video_joins_a_timeline_a_song_started() { |
| 306 | 331 | let mut session = open(asset("test_tone.mp3")); |
| 307 | - session | |
| 308 | - .import(&asset("test_av.mp4")) | |
| 309 | - .expect("30 fps H.264 matches the audio-only canvas"); | |
| 332 | + import_and_place(&mut session, &asset("test_av.mp4")); | |
| 310 | 333 | assert_eq!(session.lane_clips(Lane::V1).len(), 1, "a picture at last"); |
| 311 | 334 | assert_eq!(session.lane_clips(Lane::A1).len(), 2); |
| 312 | 335 | // 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 | 339 | let e = refusal(session.import(&asset("test_tone_48k.wav"))); |
| 315 | 340 | assert_eq!( |
| 316 | 341 | e, |
| 317 | 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 | 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 | 394 | let mut session = open(copy("test_av.mp4")); |
| 365 | - session.import(©("test_tone.flac")).expect("import"); | |
| 395 | + import_and_place(&mut session, ©("test_tone.flac")); | |
| 366 | 396 | // And one placed at the playhead, the way a library row dropped on the |
| 367 | 397 | // audio lane arrives -- so the reload has both doors to restore. |
| 368 | 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 | 462 | let mut session = open(copy("test_av.mp4")); |
| 433 | - session.import(©("test_tone.flac")).expect("import"); | |
| 463 | + import_and_place(&mut session, ©("test_tone.flac")); | |
| 434 | 464 | let song = session.lane_clips(Lane::A1)[1]; |
| 435 | 465 | let video_before = session.lane_clips(Lane::V1).to_vec(); |
| 436 | 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 | 645 | /// Frame count straight from the container, without decoding anything. |
| 630 | 646 | fn frame_count(path: &Path) -> u32 { |
| 631 | 647 | engine::demux::Demuxer::open(path) |
| @@ -634,17 +650,28 @@ fn frame_count(path: &Path) -> u32 { | ||
| 634 | 650 | .frame_count |
| 635 | 651 | } |
| 636 | 652 | |
| 637 | -/// Import: a second file appended to the timeline, played through as one | |
| 638 | -/// stream. No audio needed for the pictures, so this runs anywhere. | |
| 653 | +/// An imported file dragged onto the end of the timeline, played through as | |
| 654 | +/// one stream. No audio needed for the pictures, so this runs anywhere. | |
| 639 | 655 | #[test] |
| 640 | -fn import_appends_a_second_source_and_plays_across_the_join() { | |
| 656 | +fn a_placed_import_plays_across_the_join() { | |
| 641 | 657 | let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4")); |
| 642 | 658 | let mut session = open(&av); |
| 643 | 659 | let (fps, first) = (session.meta().frame_rate, session.meta().frame_count); |
| 644 | 660 | let second = frame_count(&av2); |
| 645 | 661 | assert_eq!((first, second), (150, 120), "fixtures changed"); |
| 646 | 662 | |
| 663 | + // The import alone fills the library: nothing on the lanes moved. | |
| 647 | 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 | 675 | assert_eq!(session.clip_spans().len(), 2); |
| 649 | 676 | assert_eq!( |
| 650 | 677 | session |
| @@ -653,7 +680,7 @@ fn import_appends_a_second_source_and_plays_across_the_join() { | ||
| 653 | 680 | .map(|&(.., s)| s) |
| 654 | 681 | .collect::<Vec<_>>(), |
| 655 | 682 | vec![0, 1], |
| 656 | - "the appended clip plays the imported file" | |
| 683 | + "the placed clip plays the imported file" | |
| 657 | 684 | ); |
| 658 | 685 | assert!( |
| 659 | 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 | 791 | /// One timeline, one set of parameters: everything else is refused by name and |
| 725 | 792 | /// changes nothing. |
| 726 | 793 | #[test] |
| @@ -746,6 +813,15 @@ fn import_refuses_what_does_not_match() { | ||
| 746 | 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 | 825 | // Same size and rate, no audio track: the timeline has one. |
| 750 | 826 | let err = session |
| 751 | 827 | .import(&asset("test_baseline.mp4")) |
| @@ -758,6 +834,7 @@ fn import_refuses_what_does_not_match() { | ||
| 758 | 834 | "a missing file is an error, not a panic" |
| 759 | 835 | ); |
| 760 | 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 | 838 | assert!((session.timeline_duration() - 5.0).abs() < 1e-9); |
| 762 | 839 | |
| 763 | 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 | 857 | let mut session = open(asset("test_baseline.mp4")); |
| 781 | 858 | assert_eq!(session.resolution(), (1280, 720), "source 0's picture"); |
| 782 | 859 | assert_eq!(session.native_resolution(), (1280, 720)); |
| 783 | - session | |
| 784 | - .import(&asset("test_mismatch.mp4")) | |
| 785 | - .expect("640x360 must join a 1280x720 timeline"); | |
| 860 | + import_and_place(&mut session, &asset("test_mismatch.mp4")); | |
| 786 | 861 | // 150 frames of the first file, then 60 of the second, at 30 fps. |
| 787 | 862 | assert_eq!(session.clip_spans().len(), 2); |
| 788 | 863 | assert!((session.timeline_duration() - 7.0).abs() < 1e-9); |
| @@ -805,9 +880,7 @@ fn media_of_two_resolutions_share_one_timeline() { | ||
| 805 | 880 | #[test] |
| 806 | 881 | fn a_fitted_clip_is_letterboxed_and_a_filled_one_is_not() { |
| 807 | 882 | let mut session = open(asset("test_baseline.mp4")); |
| 808 | - session | |
| 809 | - .import(&asset("test_mismatch.mp4")) | |
| 810 | - .expect("640x360 joins"); | |
| 883 | + import_and_place(&mut session, &asset("test_mismatch.mp4")); | |
| 811 | 884 | // A 4:3 project: both clips are 16:9, so both are letterboxed on it. 960x720 |
| 812 | 885 | // holds the whole 640x360 picture as 960x540 with 90 rows of bar either way |
| 813 | 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 handed | |
| 864 | -/// out once and reused, which is what keeps clipboard clips valid forever. | |
| 936 | +/// The same file twice is one library row -- a source index is handed out once | |
| 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 | 939 | #[test] |
| 866 | 940 | fn importing_one_file_twice_reuses_its_source() { |
| 867 | 941 | let mut session = open(asset("test_av.mp4")); |
| 868 | 942 | let av2 = asset("test_av2.mp4"); |
| 869 | - session.import(&av2).expect("first import"); | |
| 870 | - session.import(&av2).expect("second import"); | |
| 943 | + assert_eq!(session.import(&av2).expect("first import"), 1); | |
| 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 | 953 | assert_eq!( |
| 872 | 954 | session |
| 873 | 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 the | |
| 888 | -/// join, not at wherever the free-running clock got to. | |
| 969 | +/// A library row placed after the timeline has been played out revives the | |
| 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 | 976 | #[test] |
| 890 | -fn import_at_eos_resumes_into_the_new_clip() { | |
| 977 | +fn a_placement_at_eos_revives_the_session() { | |
| 891 | 978 | let av2 = asset("test_av2.mp4"); |
| 892 | 979 | let mut session = open(asset("test_av.mp4")); |
| 893 | 980 | let first = session.meta().frame_count; |
| @@ -897,18 +984,24 @@ fn import_at_eos_resumes_into_the_new_clip() { | ||
| 897 | 984 | assert!(session.is_eos()); |
| 898 | 985 | |
| 899 | 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 | 987 | assert!( |
| 904 | - landed.bgra == source_frame(&av2, 0), | |
| 905 | - "the resume is not showing the imported file" | |
| 988 | + session.is_eos(), | |
| 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 | 1000 | assert_eq!( |
| 908 | - drain_to_eof(&mut session).1, | |
| 909 | - Some(first + frame_count(&av2) - 1), | |
| 910 | - "the appended clip did not play out" | |
| 1001 | + session.timeline_duration(), | |
| 1002 | + f64::from(first + frame_count(&av2)) / session.meta().frame_rate | |
| 911 | 1003 | ); |
| 1004 | + assert_eq!(session.clip_spans().len(), 2); | |
| 912 | 1005 | } |
| 913 | 1006 | |
| 914 | 1007 | /// A source deleted mid-session: the clip that names it contributes no pictures |
| @@ -920,7 +1013,7 @@ fn a_vanished_source_is_skipped() { | ||
| 920 | 1013 | std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture"); |
| 921 | 1014 | let mut session = open(asset("test_av.mp4")); |
| 922 | 1015 | let first = session.meta().frame_count; |
| 923 | - session.import(&scratch).expect("import the copy"); | |
| 1016 | + import_and_place(&mut session, &scratch); | |
| 924 | 1017 | std::fs::remove_file(&scratch).expect("unlink"); |
| 925 | 1018 | |
| 926 | 1019 | session.seek(0.0); |
| @@ -931,9 +1024,9 @@ fn a_vanished_source_is_skipped() { | ||
| 931 | 1024 | assert!(session.is_eos(), "the timeline still ends"); |
| 932 | 1025 | } |
| 933 | 1026 | |
| 934 | -/// Importing while the device is running: the import reseeks under the | |
| 935 | -/// playhead, so what must not happen is a stall -- the joined timeline still | |
| 936 | -/// plays out whole. No audio needed, so this runs anywhere. | |
| 1027 | +/// Importing and placing while the device is running: the placement reseeks | |
| 1028 | +/// under the playhead, so what must not happen is a stall -- the joined | |
| 1029 | +/// timeline still plays out whole. No audio needed, so this runs anywhere. | |
| 937 | 1030 | #[test] |
| 938 | 1031 | fn import_during_play_does_not_stall() { |
| 939 | 1032 | let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4")); |
| @@ -945,9 +1038,9 @@ fn import_during_play_does_not_stall() { | ||
| 945 | 1038 | run_for(&mut session, &mut last_index, Duration::from_millis(300)); |
| 946 | 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 | 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 | 1045 | // From here on the indices go *backwards* once: `run_for` decodes far ahead |
| 953 | 1046 | // 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 stays | |
| 965 | -/// behind (documented, harmless -- source indexes are forever), and the session | |
| 966 | -/// is still playable on the restored timeline. | |
| 1057 | +/// An import is *not* an undo step -- a library row changes nothing playable, | |
| 1058 | +/// so there is nothing for `z` to take back -- and the placement that follows | |
| 1059 | +/// is one. Undoing it leaves the row in the library, where the user put it. | |
| 967 | 1060 | #[test] |
| 968 | -fn undo_after_import_is_one_step() { | |
| 1061 | +fn an_import_is_not_an_undo_step_but_its_placement_is() { | |
| 969 | 1062 | let av2 = asset("test_av2.mp4"); |
| 970 | 1063 | let mut session = open(asset("test_av.mp4")); |
| 971 | 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 | 1069 | assert_eq!(session.clip_spans().len(), 2); |
| 973 | 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 | 1073 | assert_eq!(session.clip_spans().len(), 1, "one step, back to one clip"); |
| 977 | 1074 | assert!( |
| 978 | 1075 | (session.timeline_duration() - 5.0).abs() < 1e-9, |
| 979 | 1076 | "undo did not restore the duration: {}", |
| 980 | 1077 | session.timeline_duration() |
| 981 | 1078 | ); |
| 982 | - | |
| 983 | - // The orphan source is only observable on the project -- `PlaybackSession` | |
| 984 | - // exposes sources through `clip_spans_by_source`, and the undone clip is | |
| 985 | - // exactly the one that named it. | |
| 986 | - let mut project = engine::Project::single(asset("test_av.mp4"), 150); | |
| 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"); | |
| 1079 | + assert_eq!( | |
| 1080 | + session.sources().len(), | |
| 1081 | + 2, | |
| 1082 | + "the library row survives an undo of the clip that used it" | |
| 1083 | + ); | |
| 992 | 1084 | |
| 993 | 1085 | // Still playable: the undo reseeked to the (paused) playhead at zero. |
| 994 | 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 | 1090 | /// 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 | 1096 | #[ignore = "needs a running PipeWire daemon"] |
| 1005 | 1097 | fn audio_runs_across_a_source_join() { |
| 1006 | 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 | 1100 | let first = session.meta().frame_count; |
| 1009 | 1101 | |
| 1010 | 1102 | 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 | 44 | let media = copy_in(&dir, "test_multilang.mp4"); |
| 45 | 45 | let mut session = PlaybackSession::open(&media).expect("open the fixture"); |
| 46 | 46 | 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 | 47 | let end = session.timeline_duration(); |
| 49 | 48 | |
| 50 | 49 | // Stream 1 is the French track, same rate and layout as stream 0, so it |
| 51 | 50 | // can join this timeline; it lands as a second source of the same file. |
| 52 | 51 | assert!( |
| 53 | 52 | session |
| 54 | - .place_stream_at(end, &media, 1, frames, None) | |
| 53 | + .place_stream_at(end, &media, 1, None) | |
| 55 | 54 | .expect("stream 1 matches the timeline") |
| 56 | 55 | ); |
| 57 | 56 | assert_eq!( |
| @@ -83,15 +82,14 @@ fn a_picked_audio_stream_lands_saves_and_comes_back() { | ||
| 83 | 82 | let other = copy_in(&dir, "test_multiaudio.mp4"); |
| 84 | 83 | let mut session = PlaybackSession::open(&other).expect("open the fixture"); |
| 85 | 84 | session.set_gain(0.0); |
| 86 | - let frames = session.clip_at(0).expect("one clip").out_frame; | |
| 87 | 85 | let err = session |
| 88 | - .place_stream_at(0.0, &other, 1, frames, None) | |
| 86 | + .place_stream_at(0.0, &other, 1, None) | |
| 89 | 87 | .expect_err("22.05 kHz mono cannot join a 44.1 kHz stereo timeline") |
| 90 | 88 | .to_string(); |
| 91 | 89 | assert!(err.contains("22050"), "unhelpful refusal: {err}"); |
| 92 | 90 | assert!( |
| 93 | 91 | session |
| 94 | - .place_stream_at(0.0, &media, 1, frames, None) | |
| 92 | + .place_stream_at(0.0, &media, 1, None) | |
| 95 | 93 | .expect_err("a file that is not a source") |
| 96 | 94 | .to_string() |
| 97 | 95 | .contains("not on this timeline") |
| @@ -120,7 +118,9 @@ fn a_trimmed_timeline_saves_and_opens_again() { | ||
| 120 | 118 | session.save_project(&path).expect("save"); |
| 121 | 119 | let loaded = PlaybackSession::open_project(&path).expect("a trimmed project opens"); |
| 122 | 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 | 124 | Some((5, 5, whole.end() / 2)), |
| 125 | 125 | "the trimmed range is what came back" |
| 126 | 126 | ); |
| @@ -142,9 +142,17 @@ fn a_trimmed_timeline_saves_and_opens_again() { | ||
| 142 | 142 | /// with something to lose in every field. |
| 143 | 143 | fn edited(dir: &Path) -> PlaybackSession { |
| 144 | 144 | let mut session = PlaybackSession::open(copy_in(dir, "test_av.mp4")).expect("open"); |
| 145 | - session | |
| 146 | - .import(©_in(dir, "test_av2.mp4")) | |
| 147 | - .expect("import the second file"); | |
| 145 | + // Imported into the library, then dragged onto the end -- the two acts a | |
| 146 | + // second file on the timeline takes. | |
| 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 | 156 | assert!(session.cut_at(2.0), "cut inside the first file"); |
| 149 | 157 | assert!(session.cut_at(6.5), "cut inside the second file"); |
| 150 | 158 | assert!( |
| @@ -505,10 +513,12 @@ fn a_folder_of_media_and_its_project_can_be_moved() { | ||
| 505 | 513 | fn orphan_sources_are_not_written() { |
| 506 | 514 | let dir = scratch("orphans"); |
| 507 | 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 | 519 | session |
| 509 | 520 | .import(©_in(&dir, "test_av2.mp4")) |
| 510 | 521 | .expect("import"); |
| 511 | - assert!(session.undo(), "take the import back"); | |
| 512 | 522 | assert_eq!( |
| 513 | 523 | session.sources().len(), |
| 514 | 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 | 117 | # has something concrete to refuse. |
| 118 | 118 | ffmpeg -y -f lavfi -i testsrc2=size=640x360:rate=30:duration=2 \ |
| 119 | 119 | -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 | 130 | # Standalone audio fixtures: the same 440/880 Hz tone with the 1 Hz pulse the |
| 121 | 131 | # A/V fixture carries, at test_av.mp4's own 44.1k stereo -- so an imported song |
| 122 | 132 | # can share a timeline with the video clips and the peaks tests can reuse the |