forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

pro_trims.rs59 lines, 2.3 KiBHistoryRawDownload
1//! Roll, slip and slide through a session, against a real file's length: the
2//! source walls come from the media, a take moves together, each is one undo.
3//!
4//! ```text
5//! cargo test -p engine --test pro_trims
6//! ```
7
8use std::path::PathBuf;
9
10use engine::project::Lane;
11use engine::PlaybackSession;
12
13fn asset(name: &str) -> PathBuf {
14 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../assets").join(name)
15}
16
17/// `test_av.mp4` is 150 frames at 30 fps; cut at 1 s and 3 s: V1+A1 as 0..30, 30..90, 90..150.
18fn cut_in_three() -> PlaybackSession {
19 let mut s = PlaybackSession::open(asset("test_av.mp4")).expect("open");
20 s.set_gain(0.0);
21 assert!(s.cut_at(1.0) && s.cut_at(3.0));
22 assert_eq!(s.lane_clips(Lane::V1).len(), 3);
23 s
24}
25
26fn spans(s: &PlaybackSession, lane: Lane) -> Vec<(u32, u32, u32, u32)> {
27 s.lane_clips(lane).iter().map(|c| (c.start, c.end(), c.in_frame, c.out_frame)).collect()
28}
29
30#[test]
31fn roll_moves_a_cut_and_undo_puts_it_back() {
32 let mut s = cut_in_three();
33 let depth = s.undo_depth();
34 assert_eq!(s.roll_room(Lane::V1, 0).map(|r| r.0 >= 1), Some(true));
35 assert_eq!(s.roll_clip(Lane::V1, 0, 45), Some(45));
36 for lane in [Lane::V1, Lane::A1] {
37 assert_eq!(spans(&s, lane), [(0, 45, 0, 45), (45, 90, 45, 90), (90, 150, 90, 150)], "{lane:?}");
38 }
39 assert_eq!(s.undo_depth(), depth + 1);
40 assert!(s.undo());
41 assert_eq!(spans(&s, Lane::V1), [(0, 30, 0, 30), (30, 90, 30, 90), (90, 150, 90, 150)]);
42 assert_eq!(s.roll_clip(Lane::V1, 2, 100), None, "the last clip has no cut behind it");
43}
44
45#[test]
46fn slip_stops_at_the_file_and_slide_keeps_the_length() {
47 let mut s = cut_in_three();
48 assert_eq!(s.slip_room(Lane::V1, 1), Some((-30, 60)));
49 assert_eq!(s.slip_clip(Lane::V1, 1, 1000), Some(60), "clamped to the file's last frame");
50 assert_eq!(spans(&s, Lane::V1)[1], (30, 90, 90, 150));
51 assert!(s.undo());
52 assert_eq!(s.slide_clip(Lane::V1, 1, 40), Some(40));
53 for lane in [Lane::V1, Lane::A1] {
54 assert_eq!(spans(&s, lane), [(0, 40, 0, 40), (40, 100, 30, 90), (100, 150, 100, 150)], "{lane:?}");
55 }
56 assert_eq!(s.slide_clip(Lane::V1, 0, 5), None, "no clip before it");
57 assert!(s.undo());
58 assert_eq!(spans(&s, Lane::V1), [(0, 30, 0, 30), (30, 90, 30, 90), (90, 150, 90, 150)]);
59}