forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

audio_only_mp4_reopen.rs116 lines, 4.2 KiBHistoryRawDownload
1//! An audio-only mp4 (no picture track, sound only) must reopen wherever it
2//! sits in a project: first, in the middle, or last, and with clips placed
3//! from it. Import already takes this file as a song; the load path has to
4//! take it the same way, or a project that saved fine refuses to open.
5//!
6//! ```text
7//! cargo test -p engine --release --test audio_only_mp4_reopen -- --nocapture
8//! ```
9
10use std::path::{Path, PathBuf};
11
12use engine::PlaybackSession;
13use engine::scratch::Scratch;
14
15fn asset(name: &str) -> PathBuf {
16 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
17 .join("../../assets")
18 .join(name)
19}
20
21fn copy_in(dir: &Path, name: &str) -> PathBuf {
22 let to = dir.join(name);
23 std::fs::copy(asset(name), &to).expect("copy the fixture");
24 to
25}
26
27/// Saves, reopens, and checks the reopened timeline is the one that was saved.
28fn save_and_reopen(session: &PlaybackSession, path: &Path) -> PlaybackSession {
29 session.save_project(path).expect("save");
30 let loaded = PlaybackSession::open_project(path).unwrap_or_else(|e| {
31 panic!("a project with an audio-only mp4 must reopen: {e}")
32 });
33 assert_eq!(loaded.sources(), session.sources());
34 assert_eq!(loaded.timeline_duration(), session.timeline_duration());
35 loaded
36}
37
38/// Source positions: the audio-only file alone, first, second, and last, each
39/// saved and reopened. The picture-carrying file is the scaffold whenever it
40/// is present, so the audio-only one is held by the load path's own checks.
41#[test]
42fn audio_only_mp4_reopens_in_every_source_position() {
43 let dir = Scratch::dir("ve_audio_only_mp4_positions");
44 let video = copy_in(&dir, "test_av.mp4");
45 let audio = copy_in(&dir, "test_audio_only.mp4");
46
47 // Alone.
48 {
49 let session = PlaybackSession::open(&audio).expect("open the audio-only file");
50 session.set_gain(0.0);
51 let path = dir.join("alone.edith");
52 save_and_reopen(&session, &path);
53 }
54
55 // First, then the picture file.
56 {
57 let mut session = PlaybackSession::open(&audio).expect("open the audio-only file");
58 session.set_gain(0.0);
59 session.import(&video).expect("import the picture file second");
60 let path = dir.join("first.edith");
61 save_and_reopen(&session, &path);
62 }
63
64 // The picture file first, then the audio-only one.
65 {
66 let mut session = PlaybackSession::open(&video).expect("open the picture file");
67 session.set_gain(0.0);
68 session.import(&audio).expect("import the audio-only file second");
69 let path = dir.join("second.edith");
70 save_and_reopen(&session, &path);
71 }
72
73 std::fs::remove_dir_all(&dir).expect("cleanup");
74}
75
76/// Clips placed from the audio-only file, in both positions, come back on the
77/// same lanes at the same places, and the reopened project plays from them.
78#[test]
79fn clips_from_an_audio_only_mp4_survive_a_reopen() {
80 let dir = Scratch::dir("ve_audio_only_mp4_clips");
81 let video = copy_in(&dir, "test_av.mp4");
82 let audio = copy_in(&dir, "test_audio_only.mp4");
83
84 let mut session = PlaybackSession::open(&video).expect("open the picture file");
85 session.set_gain(0.0);
86 session.import(&audio).expect("import the audio-only file");
87 let end = session.timeline_duration();
88 assert!(
89 session
90 .place_stream_at(end, &audio, 0, None)
91 .expect("the audio-only file is placeable on the timeline"),
92 "the placement was accepted"
93 );
94 // And a second clip from the same audio-only file, at the front.
95 session
96 .place_stream_at(0.0, &audio, 0, None)
97 .expect("a second clip from the audio-only file");
98
99 let path = dir.join("clips.edith");
100 let loaded = save_and_reopen(&session, &path);
101 for lane in session.lanes() {
102 assert_eq!(
103 loaded.lane_clips(lane).len(),
104 session.lane_clips(lane).len(),
105 "clip count on {lane:?}"
106 );
107 }
108
109 // The reopened session still composes its picture from the first source.
110 let frame = loaded
111 .compose_at(0, 320, 180)
112 .expect("the reopened timeline composes a frame");
113 assert_eq!((frame.width, frame.height), (320, 180));
114
115 std::fs::remove_dir_all(&dir).expect("cleanup");
116}