forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

audio_lane.rs53 lines, 2.4 KiBHistoryRawDownload
1//! The audio lane's behaviour the GUI gestures rely on: the clip volume envelope's keys
2//! (add, move, remove, one undo each) and the ruler's audible scrub gate.
3
4use super::*;
5use crate::player::transport::scrub_snippet_wanted;
6use engine::GainKey;
7
8/// Adding a key puts it in frame order, moving one keeps the others where they were, and
9/// removing one leaves the rest; each is one undo step back to the envelope before it.
10#[test]
11fn envelope_keys_add_move_and_remove_through_the_session_one_undo_each() {
12 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
13 let lane = Lane::A1;
14 let clip = session.lane_clips(lane)[0].clone();
15 let before = clip.gain_keys.clone();
16 let (first, last) = (clip.in_frame + 10, clip.in_frame + 40);
17
18 assert!(session.add_gain_key(lane, 0, GainKey::new(last, -12.)));
19 assert!(session.add_gain_key(lane, 0, GainKey::new(first, -6.)));
20 let added = session.gain_keys_of(lane, 0).to_vec();
21 let ats: Vec<u32> = added.iter().map(|k| k.at).collect();
22 assert!(ats.windows(2).all(|w| w[0] < w[1]), "keys sorted: {ats:?}");
23 assert!(session.undo());
24 let only_last = session.gain_keys_of(lane, 0).to_vec();
25 assert!(session.redo());
26 assert_eq!(session.gain_keys_of(lane, 0), added.as_slice());
27
28 let mut moved = added.clone();
29 let i = moved.iter().position(|k| k.at == first).unwrap();
30 moved[i] = GainKey::new(first + 3, -9.);
31 assert!(session.set_gain_keys(lane, 0, moved.clone()));
32 assert!(session.gain_keys_of(lane, 0).iter().any(|k| k.at == first + 3 && k.db == -9.));
33
34 assert!(session.remove_gain_key(lane, 0, first + 3));
35 assert_eq!(session.gain_keys_of(lane, 0).len(), added.len() - 1);
36
37 assert!(session.undo());
38 assert_eq!(session.gain_keys_of(lane, 0), moved.as_slice());
39 assert!(session.undo());
40 assert_eq!(session.gain_keys_of(lane, 0), added.as_slice());
41 assert!(session.undo());
42 assert_eq!(session.gain_keys_of(lane, 0), only_last.as_slice());
43 assert!(session.undo());
44 assert_eq!(session.gain_keys_of(lane, 0), before.as_slice());
45}
46
47/// Dragging the ruler sounds a snippet only while paused and the switch is on.
48#[test]
49fn a_ruler_scrub_is_heard_only_while_paused_and_switched_on() {
50 assert!(scrub_snippet_wanted(true, true));
51 assert!(!scrub_snippet_wanted(true, false), "playing: the timeline is already sounding");
52 assert!(!scrub_snippet_wanted(false, true), "switched off");
53}