forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

placement_walls.rs206 lines, 7.2 KiBHistoryRawDownload
1//! Every placement door holds each lane's clip to that lane's wall, so a clip
2//! the save would refuse can never be placed, and an autosave never refuses.
3//!
4//! The asset is `test_23976fps.mp4`: 2.002 s of picture (61 frames on the 30
5//! fps timeline) and 2.000 s of sound (60 frames). A clip of it on an audio lane
6//! that ran 61 frames is the bug this file guards: the save checks each lane
7//! against its own table, and the sound's is 60.
8//!
9//! ```text
10//! cargo test -p engine --test placement_walls
11//! ```
12
13use std::path::PathBuf;
14
15use engine::project::{Lane, LaneKind, Speed};
16use engine::scale::FitPolicy;
17use engine::scratch::Scratch;
18use engine::PlaybackSession;
19use engine::project::Clip;
20
21fn asset(name: &str) -> PathBuf {
22 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
23 .join("../../assets")
24 .join(name)
25}
26
27/// A 30 fps timeline with `test_23976fps.mp4` in its library, silent.
28fn session() -> (PlaybackSession, usize) {
29 let mut s = PlaybackSession::open(asset("test_av.mp4")).expect("open");
30 s.set_gain(0.0);
31 let idx = s.import(&asset("test_23976fps.mp4")).expect("import");
32 assert_eq!(s.file_frames(&asset("test_23976fps.mp4")), 61, "picture is 61 frames");
33 (s, idx)
34}
35
36/// A clip of `source` over `in_frame..out_frame`, as the MCP builds one.
37fn clip(source: usize, in_frame: u32, out_frame: u32) -> Clip {
38 Clip {
39 speed_keys: Vec::new(),
40 reversed: false,
41 stabilise: None, deinterlace: Default::default(), mark: Default::default(),
42 angle: Default::default(),
43 fade_in: 0,
44 fade_out: 0,
45 transition_out: 0,
46 transition_kind: Default::default(),
47 visualizer: 0,
48 viz_paint: 0,
49 gain_db: 0.0,
50 gain_keys: Vec::new(),
51 pan: 0,
52 pitch: 0.0,
53 transform_keys: Vec::new(),
54 opacity_keys: Vec::new(),
55 color_keys: Vec::new(),
56 effects: Vec::new(),
57 start: 0,
58 in_frame,
59 out_frame,
60 source,
61 link: None,
62 eq: None,
63 color: None,
64 transform: None,
65 fit: FitPolicy::default(),
66 speed: Speed::NORMAL,
67 }
68}
69
70fn a(n: usize) -> Lane {
71 Lane::new(LaneKind::Audio, n)
72}
73
74fn v(n: usize) -> Lane {
75 Lane::new(LaneKind::Video, n)
76}
77
78/// Every lane's clips are inside their walls (61 on picture, 60 on sound), and
79/// the project saves and reopens with no clamp warning -- which is what the
80/// save and the load both demand.
81fn assert_holds(s: &PlaybackSession, label: &str) {
82 for lane in s.lanes() {
83 for (i, c) in s.lane_clips(lane).iter().enumerate() {
84 let wall = match lane.kind {
85 LaneKind::Audio => 60,
86 _ => 61,
87 };
88 if c.source == s.sources().len() - 1 {
89 assert!(
90 c.out_frame <= wall,
91 "{label}: {lane:?} clip {i} ends at {} past its wall {wall}",
92 c.out_frame
93 );
94 }
95 }
96 }
97 let dir = Scratch::dir("placement_walls");
98 let path = dir.join(format!("{}.edith", label.replace(|c: char| !c.is_alphanumeric(), "_")));
99 s.save_project(&path)
100 .unwrap_or_else(|e| panic!("{label}: save refused: {e}"));
101 let reopened = PlaybackSession::open_project(&path).expect("reopen");
102 assert!(
103 reopened.load_warnings().is_empty(),
104 "{label}: reopen clamped: {:?}",
105 reopened.load_warnings()
106 );
107}
108
109#[test]
110fn place_stream_at_every_lane_holds_to_its_wall() {
111 let file = asset("test_23976fps.mp4");
112 for (label, onto) in [
113 ("grouped", None),
114 ("V1", Some(v(0))),
115 ("V2", Some(v(1))),
116 ("A1", Some(a(0))),
117 ("A2", Some(a(1))),
118 ] {
119 let (mut s, _) = session();
120 let end = s.timeline_duration();
121 s.place_stream_at(end, &file, 0, onto)
122 .unwrap_or_else(|e| panic!("{label}: {e}"));
123 assert_holds(&s, &format!("place_stream_at {label}"));
124 }
125}
126
127#[test]
128fn place_at_with_a_range_past_the_sound_holds_to_the_sound() {
129 for lane in [v(0), v(1), a(0), a(1)] {
130 let (mut s, src) = session();
131 // A further lane is added first, as the MCP's `lane_add` does.
132 let lane = match lane.ord {
133 0 => lane,
134 _ => s.add_lane(lane.kind),
135 };
136 let at = s.timeline_duration();
137 // The whole picture, 61 frames: on a video lane that is the wall; on an
138 // audio lane the sound's 60 must cut it back.
139 assert!(s.place_at(lane, at, clip(src, 0, 61)), "{lane:?}: placed");
140 let landed = s.lane_clips(lane).last().expect("a clip").frames();
141 let want = match lane.kind {
142 LaneKind::Audio => 60,
143 _ => 61,
144 };
145 assert_eq!(landed, want, "{lane:?} holds to its own wall");
146 assert_holds(&s, &format!("place_at {lane:?}"));
147 }
148}
149
150#[test]
151fn place_at_past_the_wall_entirely_is_refused_not_saved_wrong() {
152 let (mut s, src) = session();
153 let at = s.timeline_duration();
154 // In-point at the sound's end: no sound frame is left for an audio lane.
155 assert!(!s.place_at(a(0), at, clip(src, 60, 61)));
156 assert_holds(&s, "refused sound");
157}
158
159#[test]
160fn paste_and_paste_set_hold_each_item_to_its_lane() {
161 let (mut s, src) = session();
162 let at = s.timeline_duration();
163 assert!(s.paste_at(at, clip(src, 0, 61)), "paste lands");
164 assert_holds(&s, "paste_at");
165
166 let (mut s, src) = session();
167 let at = s.timeline_duration();
168 assert!(s.paste_set_at(at, &[(v(0), clip(src, 0, 61)), (a(0), clip(src, 0, 61))]));
169 assert_eq!(s.lane_clips(a(0)).last().expect("sound").frames(), 60);
170 assert_eq!(s.lane_clips(v(0)).last().expect("picture").frames(), 61);
171 assert_holds(&s, "paste_set_at");
172}
173
174#[test]
175fn autosave_writes_a_project_that_runs_past_its_source() {
176 let (mut s, src) = session();
177 let at = s.timeline_duration();
178 assert!(s.place_at(a(0), at, clip(src, 0, 61)));
179 let dir = Scratch::dir("placement_walls_autosave");
180 let path = dir.join("autosave.edith");
181 s.save_autosave(&path).expect("an autosave is never refused");
182 assert!(path.exists(), "the autosave wrote its file");
183 // The reopen clamps with a warning rather than refusing, so the file opens.
184 let reopened = PlaybackSession::open_project(&path).expect("the autosave reopens");
185 assert!(!reopened.sources().is_empty());
186}
187
188/// A drop overwrites: a file let go over what is already there for its own length replaces it,
189/// and nothing after it moves. The insert door, on the same frames, pushes the rest along.
190#[test]
191fn place_stream_overwrite_at_replaces_and_holds_the_timeline_length() {
192 let file = asset("test_23976fps.mp4");
193 let (mut s, _) = session();
194 s.place_stream_at(0.0, &file, 0, None).expect("first placement");
195 let before = s.timeline_duration();
196 s.place_stream_overwrite_at(0.0, &file, 0, None)
197 .expect("overwrite over the clip");
198 assert_eq!(s.timeline_duration(), before, "an overwrite pushes nothing past the end");
199 assert_holds(&s, "overwrite over a take");
200
201 let (mut t, _) = session();
202 t.place_stream_at(0.0, &file, 0, None).expect("first placement");
203 let before = t.timeline_duration();
204 t.place_stream_at(0.0, &file, 0, None).expect("insert over the clip");
205 assert!(t.timeline_duration() > before, "an insert pushes the clip under it along");
206}