forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

multicam.rs133 lines, 6.4 KiBHistoryRawDownload
1//! Multicam on the window's side: the oracle's rules, the number keys, the angle monitor's place
2//! in the viewer (a flex sibling of the program picture, never over the timeline), and the
3//! timeline's angle label.
4
5use super::*;
6use crate::oracle::{Ctx, Enable, enable};
7use keymap::ActionId;
8
9const ANGLE_KEYS: [ActionId; 9] = [
10 ActionId::Angle1,
11 ActionId::Angle2,
12 ActionId::Angle3,
13 ActionId::Angle4,
14 ActionId::Angle5,
15 ActionId::Angle6,
16 ActionId::Angle7,
17 ActionId::Angle8,
18 ActionId::Angle9,
19];
20
21#[test]
22fn the_digits_are_the_angle_keys() {
23 let keymap = keymap::Keymap::defaults();
24 for (i, a) in ANGLE_KEYS.iter().enumerate() {
25 assert_eq!(a.angle_number(), Some(i + 1));
26 assert_eq!(keymap.lookup(&(i + 1).to_string(), false, false, false), Some(*a), "key {}", i + 1);
27 }
28 assert_eq!(ActionId::Cut.angle_number(), None);
29}
30
31#[test]
32fn creating_needs_two_picks_and_flattening_a_multicam_clip() {
33 let mut ctx = Ctx { timeline: true, ..Ctx::default() };
34 assert!(matches!(enable(ActionId::CreateMulticam, ctx.clone()), Enable::No(_)));
35 ctx.media_picks = 1;
36 assert!(matches!(enable(ActionId::CreateMulticam, ctx.clone()), Enable::No(_)));
37 ctx.media_picks = 2;
38 assert!(matches!(enable(ActionId::CreateMulticam, ctx.clone()), Enable::Yes));
39 assert!(matches!(enable(ActionId::FlattenMulticam, ctx.clone()), Enable::No(_)));
40}
41
42#[test]
43fn the_angle_keys_are_silent_outside_the_monitor_and_bounded_by_the_angles() {
44 let mut ctx = Ctx { timeline: true, ..Ctx::default() };
45 for a in ANGLE_KEYS {
46 assert!(matches!(enable(a, ctx.clone()), Enable::Hidden(_)), "{a:?} monitor off");
47 }
48 ctx.monitor = true;
49 ctx.angles_here = 2;
50 assert!(matches!(enable(ActionId::Angle2, ctx.clone()), Enable::Yes));
51 assert!(matches!(enable(ActionId::Angle3, ctx.clone()), Enable::No(_)));
52 ctx.angles_here = 0;
53 assert!(matches!(enable(ActionId::Angle1, ctx.clone()), Enable::Hidden(_)));
54}
55
56/// The program picture is always drawn at its own geometry; the monitor sits over the free strip
57/// beside it, and only a strip narrower than the minimum makes it a sibling that shares the row.
58/// Nothing floats over the timeline.
59#[test]
60fn the_angle_monitor_keeps_the_program_picture_in_place() {
61 let stance = src_text("ui/stance.rs");
62 let at = stance.find(".id(\"stance-picture\")").expect("the picture row");
63 let row = &stance[at..at + 4000];
64 assert!(row.contains(".children(program_and_monitor("), "the picture box holds the program and the monitor");
65 let helper = &stance[stance.find("fn program_and_monitor").expect("the helper")..];
66 assert!(helper.contains("let program = match"), "the program picture is built first, in every case");
67 assert!(helper.contains(".absolute()") && helper.contains("Some(strip) =>"), "beside the picture, the monitor is an overlay on the free strip");
68 assert!(stance.contains("const MONITOR_STRIP_MIN: f32 = 200.;"), "a strip under 200 px is the fallback");
69 assert!(stance.contains("let strip = monitor_strip(player, window)"), "the strip is read from the picture as drawn");
70 assert!(!stance.contains(".children(if player.angle_monitor"), "the monitor is not a sibling beside the picture");
71 let monitor = src_text("player/multicam.rs");
72 let view = &monitor[monitor.find("fn angle_monitor_view").expect("the monitor")..];
73 assert!(!view.contains(".absolute()"), "the monitor takes room and covers nothing");
74 assert!(view.contains("No multicam clip under the playhead"), "no multicam clip under the playhead, a calm placeholder");
75 assert_eq!(crate::player::multicam::monitor_rows(2), [1, 1]);
76 assert_eq!(crate::player::multicam::monitor_rows(3), [2, 1]);
77 assert_eq!(crate::player::multicam::monitor_rows(4), [2, 2]);
78 assert_eq!(crate::player::multicam::monitor_rows(5), [3, 2]);
79 // Beside the picture the strip holds two across.
80 assert_eq!(crate::player::multicam::monitor_rows_within(4, 2), [2, 2]);
81 assert_eq!(crate::player::multicam::monitor_rows_within(9, 2), [2, 2, 2, 2, 1]);
82}
83
84#[test]
85fn the_timeline_names_the_angle_each_segment_shows() {
86 let clip = src_text("ui/bench_stance/clip.rs");
87 assert!(clip.contains("multicam_at(lane, idx)") && clip.contains("clip.angle.video"));
88}
89
90#[test]
91fn the_view_menu_has_the_monitor_switch_and_the_clip_menu_the_create_row() {
92 let bar = src_text("ui/menubar.rs");
93 assert!(bar.contains("Switch(ActionId::ToggleAngleMonitor)"));
94 assert!(bar.contains("Act(ActionId::CreateMulticam)"));
95 assert!(bar.contains("Act(ActionId::FlattenMulticam)"));
96}
97
98#[test]
99fn the_live_angle_wears_the_accent_ring_without_changing_the_tile() {
100 let monitor = src_text("player/multicam.rs");
101 assert!(monitor.contains(".border_2()") && monitor.contains("ACCENT_PRIMARY()"), "a 2px border on every tile, accent on the live one");
102 assert!(monitor.contains("Syncing angles"), "the sync reports its percent in the status bar");
103 assert!(monitor.contains("std::thread::spawn"), "the sync runs off the window's thread");
104}
105
106/// A Ctrl-click on a source row adds it to the picks, a plain click picks it alone, and a double
107/// click opens the source instead of picking.
108#[test]
109fn a_ctrl_click_on_a_source_row_adds_to_the_picks() {
110 use gpui::Modifiers;
111 use crate::ui::dock_stance::click_adds_to_picks;
112 let ctrl = Modifiers { control: true, ..Default::default() };
113 let shift = Modifiers { shift: true, ..Default::default() };
114 assert!(click_adds_to_picks(ctrl, 1), "Ctrl-click adds");
115 assert!(click_adds_to_picks(shift, 1), "Shift-click adds too (no range)");
116 assert!(!click_adds_to_picks(Modifiers::default(), 1), "a plain click picks that row alone");
117 assert!(!click_adds_to_picks(ctrl, 2), "a double click opens the source");
118}
119
120/// Two Ctrl-clicks after a plain pick leave two picks; a third Ctrl-click on one of them takes it
121/// back out. The first Ctrl-click takes the row that was selected along with it.
122#[test]
123fn ctrl_clicks_build_two_picks_and_a_repeat_removes_one() {
124 use crate::player::multicam::toggle_pick;
125 use std::path::PathBuf;
126 let a = (PathBuf::from("/m/a.mp4"), 0);
127 let b = (PathBuf::from("/m/b.mp4"), 0);
128 let mut picks = Vec::new();
129 toggle_pick(&mut picks, Some(a.clone()), b.clone());
130 assert_eq!(picks, vec![a.clone(), b.clone()], "two picks");
131 toggle_pick(&mut picks, Some(b.clone()), a.clone());
132 assert_eq!(picks, vec![b.clone()], "a Ctrl-click on a pick removes it");
133}