//! Importing, the library column, the menus, and every edit a clip or a //! track can be handed. use super::*; use crate::GapPick; use crate::player::timeline_edit::live_gap; use crate::ui::stance::{clip_readout, fps_label, gap_readout}; /// What the file manager is handed: the parts a path keeps as they are, and /// the ones the bus would otherwise read as something else. #[test] fn file_uri_encodes_what_a_path_carries() { assert_eq!( file_uri(std::path::Path::new("/a/b.mp4")), "file:///a/b.mp4" ); assert_eq!( file_uri(std::path::Path::new("/home/x/out dir/my export.mp4")), "file:///home/x/out%20dir/my%20export.mp4" ); assert_eq!( file_uri(std::path::Path::new("/tmp/ünlü#1?.mp4")), "file:///tmp/%C3%BCnl%C3%BC%231%3F.mp4" ); } /// An import fills the *library* and nothing else -- the whole point of /// this door: the row is there at the file's own length before any clip /// plays it, wearing the tint the lanes will tint that clip with, and the /// timeline is exactly as long as it was. Placing it is the drag, and the /// drag is a separate act. #[test] fn an_import_adds_a_row_at_its_own_length_and_leaves_the_lanes_alone() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let before = session.timeline_duration(); let clips: Vec = session .lanes() .into_iter() .map(|lane| session.lane_clips(lane).len()) .collect(); session.import(&asset("test_av2.mp4")).expect("av2 matches"); assert_eq!(session.sources().len(), 2, "the library grew"); assert_eq!( session.timeline_duration(), before, "an import must not place a clip" ); assert_eq!( session .lanes() .into_iter() .map(|lane| session.lane_clips(lane).len()) .collect::>(), clips, "no lane moved" ); // The rows the panel draws: one per source, each its file's own length // -- source 1 has no clip anywhere and is still 4 s at 30 fps. let rows = library_rows( session.sources(), &HashMap::new(), &HashMap::new(), None, |path| session.file_frames(path), ); assert_eq!(rows.len(), 2); assert_eq!(rows[0].frames, 150, "5 s at 30 fps"); assert_eq!(rows[1].frames, 120, "4 s at 30 fps, never placed"); // The swatch is the clip colour, by the same index and the same // function -- what makes the panel and the lanes one association. for (row, r) in rows.iter().enumerate() { assert_eq!(r.tint, row); assert_eq!(source_tint(row), SOURCE_TINTS()[row % SOURCE_TINTS().len()]); } } /// The window opened on a song and nothing else -- the launch argument, the /// drop on an empty window and the Import button all end in the same /// `PlaybackSession::open`. The library lists it placeable, the lane door /// the Add button and a drag share puts it on `A1`, and the one format that /// needs a picture says so on its own row instead of failing at the end of /// an export. #[test] fn a_song_opens_the_window_by_itself() { let mut session = PlaybackSession::open(asset("test_tone.mp3")).expect("a song is a timeline"); session.set_gain(0.0); // The source's own path, which is the canonical one a row carries. let path = session.sources()[0].path.clone(); assert!(session.lane_clips(Lane::V1).is_empty(), "no picture"); assert_eq!(session.lane_clips(Lane::A1).len(), 1); // The library row: probed like any other source, and not greyed -- // `unusable` is what the panel dims a row with. let streams = HashMap::from([( path.clone(), engine::AudioSession::probe_streams(&path).expect("probe the song"), )]); let rate = streams[&path] .iter() .find(|s| s.index == session.sources()[0].audio_stream) .map(|s| (s.sample_rate, s.channels)); let frames = session.file_frames(&path); let rows = library_rows(session.sources(), &streams, &HashMap::new(), rate, |_| { frames }); assert_eq!(rows.len(), 1); assert_eq!(rows[0].name, "test_tone.mp3"); assert_eq!(rows[0].unusable, None, "the row is placeable"); assert_eq!(rows[0].frames, 90, "3 s at the audio-only 30 fps"); // ...and it places, on the audio lane, through the door `insert_source` // uses: a second copy of the song at the playhead. session.seek(1.0); assert!( session .place_stream_at(1.0, &path, 0, Some(Lane::A1)) .expect("its own file is on this timeline") ); assert_eq!(session.lane_clips(Lane::A1).len(), 2); assert!(session.lane_clips(Lane::V1).is_empty(), "still no picture"); // The Matroska and WebM rows carry the reason rather than the format's // detail line, each naming itself. The mp4 rows are not refused: the engine // writes an mp4 of a picture-less timeline as the sound alone. The audio // formats are what this timeline is and are never refused. assert_eq!( format_refusal(&session, Format::Av1).as_deref(), Some("no picture — an AV1 Matroska would be black; export an mp4, M4A, WAV, FLAC, MP3 or Ogg") ); assert_eq!( format_refusal(&session, Format::Webm).as_deref(), Some("no picture — a WebM would be black; export an mp4, M4A, WAV, FLAC, MP3 or Ogg") ); assert_eq!(format_refusal(&session, Format::Mp4), None, "an mp4 of it is the sound alone"); assert_eq!(format_refusal(&session, Format::Av1Mp4), None, "an AV1 mp4 of it is the sound alone"); assert_eq!(format_refusal(&session, Format::M4a), None); assert_eq!(format_refusal(&session, Format::Wav), None); assert_eq!(format_refusal(&session, Format::Flac), None); assert_eq!(format_refusal(&session, Format::Mp3), None); } /// A file's every audio track gets a row: the ones the timeline can take /// are placeable, the ones it cannot are listed greyed with the reason. /// Which rows exist at all is the branchy part of the panel, so it is /// planned as data and checked here rather than through the pointer. #[test] fn every_audio_stream_of_a_file_is_a_row_usable_or_not() { let multi = PathBuf::from("/m/movie.mp4"); let sources = [source("/m/movie.mp4", 0)]; let mut streams = HashMap::new(); streams.insert( multi.clone(), vec![ info(0, 44_100, 2, None, true), info(1, 44_100, 2, Some("fra"), true), info(2, 22_050, 1, Some("deu"), true), info(3, 0, 0, None, false), ], ); let rows = library_rows( &sources, &streams, &HashMap::new(), Some((44_100, 2)), |_| 90, ); assert_eq!( rows.iter().map(|r| r.stream).collect::>(), [0, 1, 2, 3], "one row per audio stream, in file order" ); assert!( rows.iter().all(|r| r.path == multi && r.tint == 0), "every stream of one file wears the file's own tint" ); assert_eq!(rows[0].name, "movie.mp4 [audio 1]"); assert_eq!(rows[1].name, "movie.mp4 [audio 2]"); assert_eq!(rows[1].detail, "fra 44.1 kHz stereo"); // Placeable: the one already on the timeline, and the one that matches // it. The mono track cannot join a stereo timeline -- one device and one // copied AAC track for the whole of it -- and the codec we cannot read // cannot join anything. Both say which. Its 22 kHz is *not* part of that // any more: a rate of its own is resampled at the decoder's door, and a // row greyed for one the engine accepts is this picker telling a lie. assert_eq!((&rows[0].unusable, &rows[1].unusable), (&None, &None)); assert_eq!(rows[2].unusable.as_deref(), Some("the timeline is stereo")); assert_eq!( unusable(&info(9, 48_000, 2, None, true), Some((44_100, 2))), None, "48 kHz stereo joins a 44.1 kHz stereo timeline" ); assert_eq!(rows[3].unusable.as_deref(), Some("unsupported codec")); assert_eq!( rows[3].detail, "", "a stream we cannot parse claims nothing" ); // Every row is the same file, so every row is that file's length. assert!(rows.iter().all(|r| r.frames == 90)); // The single-stream case is exactly one row and no stream tag: no // regression for the media everything else in the world is. let plain = [source("/m/plain.mp4", 0)]; let mut one = HashMap::new(); one.insert( PathBuf::from("/m/plain.mp4"), vec![info(0, 44_100, 2, None, true)], ); let rows = library_rows(&plain, &one, &HashMap::new(), Some((44_100, 2)), |_| 90); assert_eq!(rows.len(), 1); assert_eq!(rows[0].name, "plain.mp4"); assert_eq!( rows[0].detail, "", "one audio track is the row it has always been: name and length" ); // ...as is a silent file, and a file not probed yet. let mut silent = HashMap::new(); silent.insert(PathBuf::from("/m/plain.mp4"), Vec::new()); for probe in [silent, HashMap::new()] { let rows = library_rows(&plain, &probe, &HashMap::new(), None, |_| 90); assert_eq!(rows.len(), 1); assert_eq!(rows[0].name, "plain.mp4"); assert_eq!(rows[0].detail, ""); } // A second stream *placed* on the timeline is a source entry of its // own: it keeps its row, no duplicate appears for it, and the rows of // one file stay together whatever order the entries came in. let placed = [ source("/m/movie.mp4", 0), source("/m/other.mp4", 0), source("/m/movie.mp4", 2), ]; streams.insert( PathBuf::from("/m/other.mp4"), vec![info(0, 44_100, 2, None, true)], ); let rows = library_rows( &placed, &streams, &HashMap::new(), Some((44_100, 2)), |_| 90, ); assert_eq!( rows.iter() .map(|r| (file_name(&r.path), r.stream)) .collect::>(), [ ("movie.mp4".to_string(), 0), ("other.mp4".to_string(), 0), ("movie.mp4".to_string(), 2), ("movie.mp4".to_string(), 1), ("movie.mp4".to_string(), 3), ] ); assert!( rows[2].unusable.is_none(), "a stream already on the timeline is playing, whatever a probe says" ); assert_eq!(rows[1].tint, 1, "the other file is the other tint"); } /// A file the decoder refuses says so on its own row, in the decoder's own /// words. The refusal is the only thing a person can act on for a file that /// will not play, and before this the row drew an empty second line -- the /// same line a song draws, which claims nothing and means nothing. /// /// Dumped through the real [`engine::decode::probe`], not a hand-written /// `Err`: a `.mkv` that is not a container is refused by the demuxer, with no /// plugin and no hardware involved, so the words under test are the ones the /// engine really produces. #[test] fn a_refused_file_names_the_refusal_on_its_row() { let junk = std::env::temp_dir().join(format!("edith-lane-j-refused-{}.mkv", std::process::id())); std::fs::write(&junk, b"not a container, and never will be").expect("write the junk file"); let words = engine::decode::probe(&junk) .expect_err("a file that is not a stream is refused") .to_string(); assert!( !words.is_empty(), "a refusal that says nothing says nothing" ); let mut decoders = HashMap::new(); decoders.insert(junk.clone(), Decoder::from(engine::decode::probe(&junk))); let rows = library_rows( &[Source { path: junk.clone(), audio_stream: 0, ..Default::default() }], &HashMap::new(), &decoders, None, |_| 0, ); assert_eq!( rows[0].detail, words, "the row carries the refusal verbatim" ); // A probe still running says nothing, and must keep saying nothing: an // empty second line is a real answer here, not a missing one. let mut pending = HashMap::new(); pending.insert(junk.clone(), Decoder::Pending); let rows = library_rows( &[Source { path: junk.clone(), audio_stream: 0, ..Default::default() }], &HashMap::new(), &pending, None, |_| 0, ); assert_eq!(rows[0].detail, "", "an unasked decoder claims nothing"); std::fs::remove_file(&junk).ok(); } /// What the clip menu offers, and where it hangs. The two items that act on /// the playhead rather than on the clicked clip are the ones that can be /// inapplicable, and a menu at the edge of the window has to come back inside /// it or its last item cannot be clicked at all. /// /// A caption's own menu, opened on a box that is not a clip: the rows that act /// on it -- Delete, which routes to `Player::lift_sub`, and the group pair now /// that a caption may be grouped by hand -- the timeline's global items beside /// them, and nothing else drawn at all. What a placed subtitle used to have no /// menu, and no stroke, to do. #[test] fn a_caption_is_deleted_by_the_same_row_and_stroke_every_box_is() { use keymap::ActionId; // A subtitle lane holds no `Clip`, so this is what the player reads off a // right-clicked caption: nothing in the clip index space, and `caption`. let cap = Ctx { caption: true, timeline: true, ..Ctx::default() }; assert!(cap.clip.is_none(), "a caption is never a clip"); assert_eq!( enable(ActionId::Delete, cap.clone()), Enable::Yes, "the one thing a placed caption could always be asked to do", ); // The clip rows are refusals of *kind* on a caption, so the menu leaves // them out rather than drawing "nothing selected" over a clicked box. for clip_only in [ActionId::Copy, ActionId::Lift, ActionId::Equalizer] { assert_eq!( enable(clip_only, cap.clone()), Enable::Hidden("this is a caption"), "{clip_only:?} is not a row on a caption", ); } // The group rows are the caption's now: a caption out of any group says so // in the detach's own words, and Group over one pick is the partner hunt. assert_eq!( enable(ActionId::Detach, cap.clone()), Enable::No("this caption is not grouped") ); assert_eq!(enable(ActionId::Group, cap.clone()), Enable::Yes); // ...and a caption in a group detaches like a clip does. let grouped = Ctx { caption: true, caption_link: Some(3), timeline: true, ..Ctx::default() }; assert_eq!(enable(ActionId::Detach, grouped), Enable::Yes); // ...and the playhead's actions are *not* refusals: the split and the // regroup act at the line and the cards fall back to the clip under it, so // a caption in hand is no reason for them to go dead -- which, hidden, is // exactly what they went: `Player::act` returns without a word on `Hidden`, // and no click on the bed clears the mark that put them there. for playhead in [ ActionId::Cut, ActionId::Regroup, ActionId::Color, ActionId::Speed, ActionId::Fit, ActionId::Silence, ] { assert_eq!( enable(playhead, cap.clone()), Enable::Yes, "{playhead:?} is about the playhead and not about the mark", ); } // ...but live is not *listed*: every one of those rows reaches the clip // under the playhead and not the caption, and a menu opened on a caption // that offered a grade would read as the caption's. The caption's menu is // its own rows and the global pair the card already names as global. assert_eq!( menu_items(cap.clone()), vec![ ActionId::Paste, ActionId::Group, ActionId::Detach, // Below the rule line the render draws before it, like every // other row that takes something away (DESIGN §9). ActionId::Delete, ], "the caption's menu is its removal, the group pair, and paste", ); // ...and the same reading with a clip under it is the clip menu, untouched: // the flag is off wherever a `Clip` was clicked. assert!( menu_items(Ctx { timeline: true, ..Ctx::default() }) .contains(&ActionId::Cut) ); } /// A timeline with a subtitle palette and an empty subtitle lane: what a /// caption is placed on, at the fixture's own rate. fn with_subtitle_lane() -> (PlaybackSession, Lane) { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); subtitle_notice(&mut session, &asset("test_subs.mkv")).expect("the mkv carries subtitles"); let lane = session.add_lane(LaneKind::Subtitle); (session, lane) } /// A second of palette track 0, to be placed wherever the test drops it. fn one_second(start: u32) -> SubClip { SubClip { start, frames: 30, track: 0, in_us: 0, out_us: 1_000_000, link: None, } } /// A drop the engine *refuses* moves nothing -- so it must move no mark either. /// A drag towards the left edge saturates to frame 0 (`landing`), and reading /// the mark back off the frame the drop asked for handed it to whatever caption /// already covered frame 0: the next Delete then lifted a caption the hand never /// touched. The mark stays on the caption that did not move. #[test] fn a_refused_caption_drop_leaves_the_mark_where_it_was() { use crate::sub_mark; let (mut session, lane) = with_subtitle_lane(); session .place_sub(lane, 0, one_second(0)) .expect("A goes down"); session .place_sub(lane, 60, one_second(0)) .expect("B goes down after it"); let before = session.sub_lane(lane).to_vec(); // The mark is on B, the caption in hand: index 1 of the lane. assert_eq!(sub_mark(session.sub_lane(lane), 60), Some(1)); let err = session .move_sub(lane, 1, lane, 0) .expect_err("A already covers frame 0"); assert!(err.to_string().contains("already covers"), "{err}"); assert_eq!(session.sub_lane(lane), before, "a refusal moved nothing"); // The trap this pins: the frame the drop *asked* for names A, so the old // re-read marked A -- the caption nobody dragged -- and `x` lifted it. assert_eq!( sub_mark(session.sub_lane(lane), 0), Some(0), "frame 0 is A's, which is why a refused drop must not re-read the mark", ); // Nothing was renumbered, so B is still index 1 and still the marked one. assert_eq!(sub_mark(session.sub_lane(lane), 60), Some(1)); } /// A lane inserts its captions in start order (`Project::place_sub`), so one /// placed *before* the marked caption slides it one along: the mark left on its /// old index would name the caption that just arrived, and `x` would lift that /// one instead. The mark is kept by the caption's start frame, which is its name /// on its lane, so it follows the caption it was on. #[test] fn a_caption_placed_before_the_marked_one_leaves_the_mark_on_the_original() { use crate::sub_mark; let (mut session, lane) = with_subtitle_lane(); session .place_sub(lane, 100, one_second(0)) .expect("A goes down"); let marked = session.sub_lane(lane)[0].start; assert_eq!(sub_mark(session.sub_lane(lane), marked), Some(0)); session .place_sub(lane, 0, one_second(0)) .expect("the new one goes down before it"); assert_eq!( session .sub_lane(lane) .iter() .map(|s| s.start) .collect::>(), [0, 100], "the lane holds them in start order", ); // What the player does with the mark across that placement. let mark = sub_mark(session.sub_lane(lane), marked).expect("A is still there"); assert_eq!(mark, 1, "A slid one along and the mark went with it"); // ...and the Delete that stroke reaches takes A, not the caption that // arrived: `Player::delete_selected` routes a caption's mark to `lift_sub`. assert!(session.lift_sub(lane, mark)); assert_eq!( session .sub_lane(lane) .iter() .map(|s| s.start) .collect::>(), [0], "the caption the user marked is the one that died", ); } /// A caption a hand grouped with a clip pairs it for the whole-take question: /// deleting the picture takes the group, because the group -- not the lane's /// kind -- is what pairs. The engine door is the one the menu's Group row /// reaches (`group_all`), tested here from the selection's own side of it. #[test] fn a_caption_grouped_with_a_clip_pairs_it_for_the_whole_take_question() { let (mut session, lane) = with_subtitle_lane(); session .place_sub(lane, 0, one_second(0)) .expect("the caption goes down"); session .group_all(&[(Lane::V1, 0), (lane, 0)]) .expect("a clip and a caption are a group"); // Paired through the caption it was grouped with, and the question is the // picture's to answer. assert!( whole_take(&session, Lane::V1, 0), "the caption the clip was grouped with pairs it" ); // ...and the ungroup keeps the picture with its take: the caption comes // off, the clip stays linked to what it was grouped with. assert!(session.ungroup(lane, 0)); assert!( whole_take(&session, Lane::V1, 0), "ungrouped, the clip stays linked: the take stays linked" ); } /// An ungrouped clip on a further lane (ord >= 1) is a layer, not a take: it /// sits over the timeline rather than in it, so deleting it lifts a hole /// rather than rippling one closed. Pins the `(_, 1..) => false` arm /// `whole_take` answers before it ever reaches the video/audio arms below. #[test] fn an_ungrouped_clip_on_a_further_lane_is_a_layer_not_a_take() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let v2 = session.add_lane(LaneKind::Video); assert!(session.move_clip_to(Lane::V1, 0, v2, 0), "V1 -> V2"); // Its old pairing with A1 came along with the move -- detach it, an // ungrouped clip is exactly the case this arm is for. assert!(session.ungroup(v2, 0)); assert!( !whole_take(&session, v2, 0), "an ungrouped clip on ord >= 1 is a layer, not a take" ); // ...and its delete lifts, leaving the hole under it open: the take // beneath (there is none here, but the lane) is untouched. assert!(session.lift_clip(v2, 0)); assert!(session.lane_clips(v2).is_empty()); } /// A caption anchor names the media half of its group: the video member for /// the cards that are about the picture, the audio member for the ones about /// the sound. A caption in no group names nothing -- which is what the cards' /// new refusals say out loud. #[test] fn a_caption_anchor_names_the_media_half_of_its_group() { use crate::caption_media_half; let (mut session, lane) = with_subtitle_lane(); session .place_sub(lane, 0, one_second(0)) .expect("the caption goes down"); // Ungrouped: no pictures and no sound behind the words. assert_eq!( caption_media_half(&session, (lane, 0), LaneKind::Video), None ); assert_eq!( caption_media_half(&session, (lane, 0), LaneKind::Audio), None ); // Grouped with the take -- whose sound rides along unasked -- both halves // answer by lane and index. session .group_all(&[(Lane::V1, 0), (lane, 0)]) .expect("a clip and a caption are a group"); assert_eq!( caption_media_half(&session, (lane, 0), LaneKind::Video), Some((Lane::V1, 0)) ); assert_eq!( caption_media_half(&session, (lane, 0), LaneKind::Audio), Some((Lane::A1, 0)) ); } /// The manual group's oracle question: a selection of placements, one per lane. /// Two picks on two lanes is a group waiting to happen; a lane picked twice is /// the one thing a group may never hold; a single pick is the partner hunt. #[test] fn group_is_live_over_a_multi_selection_and_words_a_repeated_lane() { use keymap::ActionId; let distinct = Ctx { timeline: true, picks: 2, pick_lanes: 2, ..Ctx::default() }; assert_eq!(enable(ActionId::Group, distinct), Enable::Yes); let twice = Ctx { timeline: true, picks: 2, pick_lanes: 1, ..Ctx::default() }; assert_eq!( enable(ActionId::Group, twice), Enable::No("a lane is picked twice") ); // One pick and none at all: the partner hunt and its own refusal, which // the player words rather than the oracle. let one = Ctx { timeline: true, picks: 1, pick_lanes: 1, ..Ctx::default() }; assert_eq!(enable(ActionId::Group, one), Enable::Yes); // Nothing picked at all, on an open timeline: the partner hunt's own // refusal, worded by the player rather than the oracle. let none = Ctx { timeline: true, ..Ctx::default() }; assert_eq!(enable(ActionId::Group, none), Enable::Yes); // Stale picks (an edit moved the indices) count as none. let stale = Ctx { timeline: true, picks: 0, pick_lanes: 0, ..Ctx::default() }; assert_eq!(enable(ActionId::Group, stale), Enable::Yes); } /// The playhead's actions with a caption marked: live, and doing what they say. /// Hidden, they were dead *and* silent -- `Player::act` says nothing on a class /// refusal -- from the first click on a caption until something else was /// clicked, and no click on the bed clears that mark. #[test] fn the_playhead_actions_still_work_with_a_caption_marked() { use keymap::ActionId; let cap = Ctx { caption: true, timeline: true, ..Ctx::default() }; assert_eq!(enable(ActionId::Cut, cap.clone()), Enable::Yes); assert_eq!(enable(ActionId::Regroup, cap.clone()), Enable::Yes); // And the edits themselves, on a timeline holding a placed caption: the // split at the playhead and the rejoin at the seam it leaves. let (mut session, lane) = with_subtitle_lane(); session .place_sub(lane, 0, one_second(0)) .expect("it goes down"); let clips = session.lane_clips(Lane::V1).len(); assert!(session.cut_at(2.0), "the playhead splits the clip under it"); assert_eq!(session.lane_clips(Lane::V1).len(), clips + 1); // The refusal is a real state and not a defence against nothing: the // playhead is standing on the seam the split just left, which is exactly the // stroke `Player::cut` words as "Nothing to split — the playhead is already // on a cut". assert!( !session.cut_at(2.0), "a second split on the seam is refused, which is the state the door's \ selection gate is about" ); assert_eq!( session.lane_clips(Lane::V1).len(), clips + 1, "and adds none" ); assert!(session.regroup_at(2.0), "and the seam rejoins"); assert_eq!(session.lane_clips(Lane::V1).len(), clips); assert_eq!(session.sub_lane(lane).len(), 1, "the caption is untouched"); } #[test] fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { use keymap::{ActionId, Keymap}; // Frames 30..90 of the timeline, taken from the head of its source. let clip = Clip { speed_keys: Vec::new(), reversed: false, stabilise: None, deinterlace: Default::default(), mark: Default::default(), angle: Default::default(), fade_in: 0, fade_out: 0, transition_out: 0, transition_kind: Default::default(), visualizer: 0, viz_paint: 0, gain_db: 0.0, gain_keys: Vec::new(), pan: 0, pitch: 0.0, transform_keys: Vec::new(), opacity_keys: Vec::new(), color_keys: Vec::new(), effects: Vec::new(), start: 30, in_frame: 0, out_frame: 60, source: 0, link: None, eq: None, color: None, transform: None, fit: FitPolicy::default(), speed: Speed::NORMAL, }; assert_eq!(clip.end(), 90); let a1 = Lane::A1; let v1 = Lane::V1; // The question the clip menu asks: a timeline is open and the menu was // opened on this clip, at this playhead. let on = |clip: &Clip, lane, action, playhead| { enable( action, Ctx { clip: Some((clip.clone(), lane)), playhead, timeline: true, ..Ctx::default() }, ) }; let offered = |clip: &Clip, lane, action, playhead| on(clip, lane, action, playhead).yes(); // Cut splits from inside only: neither edge has anything to split off. assert!(offered(&clip, v1, ActionId::Cut, 31)); assert!(offered(&clip, v1, ActionId::Cut, 89)); assert!(!offered(&clip, v1, ActionId::Cut, 30)); assert!(!offered(&clip, v1, ActionId::Cut, 90)); assert!(!offered(&clip, v1, ActionId::Cut, 200)); // A slowed clip refuses more than the edges do, and it may not say the // edges' words while doing it: at a quarter speed each of its sixty // source frames is on screen four timeline frames, and only the first of // the four is a frame the file has. The three between are inside the // clip by any reading of the playhead, so "only from inside a clip" // there is a refusal claiming something the screen contradicts. let slow = Clip { fade_in: 0, fade_out: 0, speed: Speed::MIN, ..clip.clone() }; assert_eq!(slow.frames(), 240, "a quarter speed is four times as long"); assert!( offered(&slow, v1, ActionId::Cut, 34), "34 is a source frame" ); assert!(!offered(&slow, v1, ActionId::Cut, 35)); assert_eq!( on(&slow, v1, ActionId::Cut, 35).why(), Some("this speed holds one frame here"), ); assert_eq!( on(&slow, v1, ActionId::Cut, 30).why(), Some("only from inside a clip"), "the head is still the edge's refusal, speed or no speed", ); // Regroup is the other way round: only where this clip meets another. assert!(offered(&clip, v1, ActionId::Regroup, 30)); assert!(offered(&clip, v1, ActionId::Regroup, 90)); assert!(!offered(&clip, v1, ActionId::Regroup, 60)); // Detach is the clip's own business: nothing to take apart in one that // names no group, and whether the group still has another half is the // engine's question. Group is offered on every clip, for that reason. assert!(!offered(&clip, v1, ActionId::Detach, 0)); let grouped = Clip { fade_in: 0, fade_out: 0, link: Some(3), ..clip.clone() }; assert!(offered(&grouped, v1, ActionId::Detach, 60)); assert!(offered(&clip, a1, ActionId::Group, 0)); // The equalizer is the one item the *lane* decides: it filters samples, // and a video clip has none of its own. Never the playhead's business. assert!(offered(&clip, a1, ActionId::Equalizer, 0)); assert!(offered(&clip, a1, ActionId::Equalizer, 60)); assert!(!offered(&clip, v1, ActionId::Equalizer, 60)); // The rest act on the clip that was clicked, so they always mean // something -- the engine words its own refusals. for action in [ActionId::Delete, ActionId::Lift, ActionId::ToggleMute] { assert!(offered(&clip, v1, action, 0)); assert!(offered(&clip, a1, action, 60)); } // Except the grade, which is a picture setting: offered on a video // clip wherever the playhead is, dimmed on a waveform. assert!(offered(&clip, v1, ActionId::Color, 0)); assert!(!offered(&clip, a1, ActionId::Color, 60)); // The transition kinds are the dissolve's family: picture only, so the // palette offers all sixteen over a picture clip and none over a waveform. for action in ActionId::ALL.into_iter().filter(|a| a.transition_kind().is_some()) { assert!(offered(&clip, v1, action, 0), "{action:?} on picture"); assert!(!offered(&clip, a1, action, 60), "{action:?} on sound"); } // The two kinds of no, which is what the row is told apart by: a grade // on a waveform is a *class* answer -- an audio clip has no picture and // never will, so the menu leaves the item out entirely -- where a cut at // the clip's edge is this moment's answer and the next click of the // playhead changes it, so that one is drawn, dimmed, and says why. // // What the menu draws for a clip of each kind, in order: the render // loop's `continue`, as a list. let menu = |lane, image, playhead| { MENU_ITEMS .into_iter() .filter(|&action| { enable( action, Ctx { clip: Some((clip.clone(), lane)), image, playhead, timeline: true, ..Ctx::default() }, ) .listed() }) .collect::>() }; // Sound: no grade and no fit policy, and the equalizer that is the // whole reason an audio clip has a menu of its own. let sound = menu(a1, false, 60); assert!(!sound.contains(&ActionId::Color), "{sound:?}"); assert!(!sound.contains(&ActionId::Fit), "{sound:?}"); assert!(!sound.contains(&ActionId::Reframe), "a sound clip has no subject to follow: {sound:?}"); assert!(sound.contains(&ActionId::Equalizer)); assert!(sound.contains(&ActionId::Silence)); assert!(sound.contains(&ActionId::Visualizer)); // Either half of a take reverses the take. assert!(sound.contains(&ActionId::Reverse), "{sound:?}"); // Picture: the mirror of it. The sound of a take is the audio lane's, // clip for clip, so the equalizer is not this clip's business -- but the // silence scan is, because it opens on the half it is grouped with. let picture = menu(v1, false, 60); assert!(!picture.contains(&ActionId::Equalizer), "{picture:?}"); assert!(picture.contains(&ActionId::Visualizer), "{picture:?}"); assert!(picture.contains(&ActionId::Color)); assert!(picture.contains(&ActionId::Fit)); assert!(picture.contains(&ActionId::Reframe), "{picture:?}"); assert!(picture.contains(&ActionId::Silence)); assert!(picture.contains(&ActionId::Reverse), "{picture:?}"); // A still: picture with no sound anywhere, ever. Graded, fitted and // re-timed like any other clip (a speed reaches a still through the same // rewrite), scanned like none. let still = menu(v1, true, 60); assert!(!still.contains(&ActionId::Silence), "{still:?}"); assert!(!still.contains(&ActionId::Visualizer), "{still:?}"); assert!(!still.contains(&ActionId::Equalizer), "{still:?}"); assert!(!still.contains(&ActionId::Reframe), "a still has no motion to follow: {still:?}"); assert!(still.contains(&ActionId::Color)); assert!(still.contains(&ActionId::Fit)); assert!(still.contains(&ActionId::Speed)); assert!(!still.contains(&ActionId::Reverse), "a still has no footage to reverse: {still:?}"); // Mix is not in the clip menu, but it wears the same class refusal the // dock's verb row hides it by (`ui::dock_stance::ghost_verb`): nothing to // mix for a picture with no sound at all, live everywhere else. let mix_ctx = |lane, image| Ctx { clip: Some((clip.clone(), lane)), image, playhead: 60, timeline: true, ..Ctx::default() }; assert!(!enable(ActionId::Mix, mix_ctx(v1, true)).listed()); assert!(enable(ActionId::Mix, mix_ctx(v1, false)).listed()); assert!(enable(ActionId::Mix, mix_ctx(a1, false)).listed()); // A silent video (no still, but its source's stream table is empty) // refuses Mix and Silence the same way, by `no_sound` rather than `image`. let mute_video = Ctx { clip: Some((clip.clone(), v1)), no_sound: true, playhead: 60, timeline: true, ..Ctx::default() }; assert!(!enable(ActionId::Mix, mute_video.clone()).listed()); assert!(!enable(ActionId::Silence, mute_video).listed()); // ...and the state refusals are on all three, dimmed rather than gone: // at 30 the playhead is on this clip's head, where a cut has nothing to // split off -- a row the next click of the playhead lights. for rows in [menu(a1, false, 30), menu(v1, false, 30), menu(v1, true, 30)] { assert!(rows.contains(&ActionId::Cut), "{rows:?}"); } // The actions card is the other half of the rule: it lists the whole // registry, so a class refusal is dimmed there with its reason and never // dropped -- an action missing from the one surface that lists // everything would read as an action that does not exist. let listed: Vec = keys_rows() .into_iter() .filter_map(|r| match r { KeyRow::Act(action) => Some(action), _ => None, }) .collect(); for (lane, action) in [ (a1, ActionId::Color), (a1, ActionId::Fit), (v1, ActionId::Equalizer), ] { assert!(matches!(on(&clip, lane, action, 60), Enable::Hidden(_))); assert!(listed.contains(&action), "{action:?} left the actions card"); assert!(on(&clip, lane, action, 60).why().is_some()); } assert!(matches!(on(&clip, v1, ActionId::Cut, 30), Enable::No(_))); assert!(matches!( on(&clip, v1, ActionId::Regroup, 60), Enable::No(_) )); assert!(matches!(on(&clip, v1, ActionId::Detach, 0), Enable::No(_))); // Every refusal says something, and says it short enough to sit in the // menu's right-hand column beside a label -- the still's included, which // the card dims with while the menu leaves the row out. for action in MENU_ITEMS { for (lane, image) in [(v1, false), (a1, false), (v1, true)] { for playhead in [0, 30, 60, 90] { let refusal = enable( action, Ctx { clip: Some((clip.clone(), lane)), image, playhead, timeline: true, ..Ctx::default() }, ); if let Some(why) = refusal.why() { assert!(!why.is_empty() && why.len() <= 30, "{action:?}: {why:?}"); } } } } assert!(matches!( enable( ActionId::Silence, Ctx { clip: Some((clip.clone(), v1)), image: true, playhead: 60, timeline: true, ..Ctx::default() } ), Enable::Hidden(_) )); // A video clip the probed stream table says has no audio track at all -- // the row is hidden rather than offered and refused after a scan comes // back with nothing to report (`Player::start_silence_scan`'s `Ok(None)`). assert!(matches!( enable( ActionId::Silence, Ctx { clip: Some((clip, v1)), no_sound: true, playhead: 60, timeline: true, ..Ctx::default() } ), Enable::Hidden(_) )); // The editor as a whole, which is how the actions card asks: with no // timeline nothing is offered, an export leaves only its own cancel, // and the three that act on the marked clip say so when none is. let whole = |action, ctx| enable(action, ctx); assert_eq!( whole(ActionId::Play, Ctx::default()), Enable::No("no timeline open") ); let live = Ctx { timeline: true, playable: true, ..Ctx::default() }; assert!(whole(ActionId::Play, live.clone()).yes()); // ...and an open timeline with nothing on its lanes refuses the // transport in the oracle rather than in the button, which is what // makes the key and the button say the same thing. assert_eq!( whole( ActionId::Play, Ctx { playable: false, ..live.clone() } ), Enable::No("the timeline is empty") ); // The magnet and the monitoring level are the editor's own and answer // with no timeline at all -- the keyboard always fired them there, and // now so does the toolbar. // // ...and so do the two stand-in switches, which is not a nicety: they are // *import* options -- what an arriving film gets made for it, and what its // picture is then decoded from -- so a person answers them before the first // file, and a switch that waited for one was a switch that came too late to // stop the encode it was about. // ...and so do the project settings: they decide what the next file // scaffolds as (`pending_settings`), so a gate that waited for a timeline // refused them exactly when they mean the most. for editor_wide in [ ActionId::ToggleSnap, ActionId::ToggleMute, ActionId::VolumeUp, ActionId::VolumeDown, ActionId::ToggleProxies, ActionId::ToggleAutoProxies, ActionId::Resolution, ] { assert!( whole(editor_wide, Ctx::default()).yes(), "{editor_wide:?} is dead with no file open while its key still fires" ); } assert!(!whole(ActionId::Delete, live.clone()).yes()); assert!(!whole(ActionId::Paste, live.clone()).yes()); assert!( whole( ActionId::Paste, Ctx { clipboard: true, ..live.clone() } ) .yes() ); assert!(!whole(ActionId::CancelExport, live.clone()).yes()); let busy = Ctx { exporting: true, ..live.clone() }; assert!(whole(ActionId::CancelExport, busy.clone()).yes()); for action in ActionId::ALL { // Nothing may touch the edit list while an export is reading it -- // and the palette does not: it repaints this window and writes one // word to the user's own config file, which is why it is one of the // actions besides the cancel that stay live here. Fullscreen is the // same kind of thing: the platform's own window toggle, touching no // edit list either. Settings is NOT among them, on purpose: it opens // the same modal slot the exporting card is already standing in // (`Player::open_settings`), so a permission granted here would be // one nobody could ever act on -- driven and confirmed: both the `,` // chord and the spine glyph leave the exporting card on screen. let allowed = action == ActionId::CancelExport || action == ActionId::Theme || action == ActionId::AccentColour || action == ActionId::ViewZoom || action == ActionId::PlaybackQuality || action == ActionId::GuideStyle || action == ActionId::GuideMask || action == ActionId::Fullscreen || action == ActionId::SubtitleStyle // Moving the ring touches no edit list either -- same kind of // thing as Fullscreen right above it. || action == ActionId::FocusPanels // The shortcuts sheet opens a dock tab and touches no edit list. || action == ActionId::ShowKeys || action == ActionId::About // The video output window and its display: a second window onto the picture. || action == ActionId::ToggleOutputWindow || action == ActionId::OutputDisplay; assert_eq!( whole(action, busy.clone()).yes(), allowed, "{action:?} while an export reads the edit list" ); } // The playhead frame is the engine's own rule, boundary included. assert_eq!(frame_at(1.0, 30.), 30); assert_eq!(frame_at(0.0, 30.), 0); assert_eq!(frame_at(-1.0, 30.), 0); // Where it hangs: at the pointer when it fits, back inside when not. let viewport = size(px(800.), px(400.)); assert_eq!(menu_at(point(px(10.), px(10.)), viewport, 150.), (10., 10.)); assert_eq!( menu_at(point(px(700.), px(380.)), viewport, 150.), ( 800. - crate::layout::MENU_EDGE - MENU_W, 400. - crate::layout::MENU_EDGE - 150. ) ); // A window smaller than the menu loses its bottom, never its top: the // top-left margin wins over the bottom-right one, because the items are // at the top. assert_eq!( menu_at(point(px(90.), px(40.)), size(px(100.), px(50.)), 150.), (crate::layout::MENU_EDGE, crate::layout::MENU_EDGE) ); // Every item is an action the registry knows, so the menu and the keys // menu say the same thing about it -- and none of them is unreachable // by keyboard, which is what makes the hint column worth drawing. let keymap = Keymap::defaults(); for action in MENU_ITEMS { assert!(ActionId::ALL.contains(&action), "{action:?} is not listed"); // The Effects opener has a menu row and no stroke; the popup prints // no hint for a row without one. if !matches!( action, ActionId::Effects | ActionId::TrackMask | ActionId::Reframe | ActionId::NestClips | ActionId::BreakApart | ActionId::OpenCompound | ActionId::FlattenMulticam | ActionId::ClipLabel ) { assert_ne!(keymap.display(action), "unbound", "{action:?}"); } } // ...and the whole card still fits the 640x360 floor, however many items // it grows to: the list is what scrolls where the window is too short // for it, never the card that grows. let items = MENU_ITEMS.len() + 1; // Properties let floor = size(px(640.), px(360.)); assert!( MENU_PAD * 2. + menu_rows_h(items, floor) <= 360., "too tall" ); assert!( menu_rows_h(items, floor) / MENU_ROW_H >= 12., "too few items visible to scan on the smallest window" ); assert_eq!( menu_at(point(px(0.), px(0.)), floor, { MENU_PAD * 2. + menu_rows_h(items, floor) }), (crate::layout::MENU_EDGE, crate::layout::MENU_EDGE) ); // The picker is the same card and the longest list in it is the palette // family list, which grows every time somebody asks for more colours. // Twelve of them still stand on screen *whole* at the floor -- so the // list's `overflow_y_scroll` is a safety net rather than something a // person has to find. The day a family makes this fail is the day the // card owes the affordance line the inspector and the cards carry // ("more below — scroll the …"): a row nobody knows is under the fold // is a row that is not there, and no scroll bar says it. let families = crate::ui::theme::PaletteId::ALL.len(); // With 28px rows (REDESIGN §3.1) the floor shows all but a couple of them and the // list scrolls, as every menu does at that height. assert!( menu_rows_h(families, floor) >= 11. * MENU_ROW_H, "the picker shows fewer than eleven palettes at 640x360" ); // ...and the detail beside each one is short enough to survive the // right-hand column at that width instead of being truncated mid-word. for id in crate::ui::theme::PaletteId::ALL { assert!(id.detail().len() <= 30, "{id:?}: {:?}", id.detail()); } } /// Both menus, at the two things they can be opened on, and the box each /// one is drawn in. Two rules, and the render obeys them by *calling* what /// this calls -- [`menu_items`] and [`row_items`] are the only lists either /// menu is built from, and [`menu_rows_h`] is the height each is both placed /// by and drawn to: /// /// 1. a row exists only where the oracle lists the action for the very thing /// that was right-clicked, so an item can never offer a video action on a /// waveform (the complaint this comes from) and a new action added to /// `MENU_ITEMS` cannot appear where it does not apply; /// 2. the whole card is inside the window, wherever it was opened and /// however long the list -- a menu drawn past the bottom edge is a menu /// whose last items nobody can click. #[test] fn a_menu_offers_only_what_applies_and_is_drawn_inside_the_window() { use keymap::ActionId; let clip = Clip { speed_keys: Vec::new(), reversed: false, stabilise: None, deinterlace: Default::default(), mark: Default::default(), angle: Default::default(), fade_in: 0, fade_out: 0, transition_out: 0, transition_kind: Default::default(), visualizer: 0, viz_paint: 0, gain_db: 0.0, gain_keys: Vec::new(), pan: 0, pitch: 0.0, transform_keys: Vec::new(), opacity_keys: Vec::new(), color_keys: Vec::new(), effects: Vec::new(), start: 30, in_frame: 0, out_frame: 60, source: 0, link: Some(1), eq: None, color: None, transform: None, fit: FitPolicy::default(), speed: Speed::NORMAL, }; let ctx = |lane, image| Ctx { clip: Some((clip.clone(), lane)), image, playhead: 60, timeline: true, ..Ctx::default() }; // The oracle is the whole of what the menu draws: every item it lists is // one the oracle would list, and every item it leaves out is one the // oracle hides -- there is no third answer, and no hand-written list. for (lane, image) in [(Lane::V1, false), (Lane::A1, false), (Lane::V1, true)] { let ctx = ctx(lane, image); let rows = menu_items(ctx.clone()); for action in MENU_ITEMS { assert_eq!( rows.contains(&action), enable(action, ctx.clone()).listed(), "{action:?} on {lane:?}, image={image}" ); } } // Sound has no picture settings; picture has no equalizer of its own; a // still has no sound to scan. The user's own words: an audio clip must // not be offered what only a picture can be given. let sound = menu_items(ctx(Lane::A1, false)); assert!(!sound.contains(&ActionId::Color), "{sound:?}"); assert!(!sound.contains(&ActionId::Fit), "{sound:?}"); assert!(sound.contains(&ActionId::Equalizer)); let picture = menu_items(ctx(Lane::V1, false)); assert!(!picture.contains(&ActionId::Equalizer), "{picture:?}"); assert!(picture.contains(&ActionId::Color)); assert!(!menu_items(ctx(Lane::V1, true)).contains(&ActionId::Silence)); // The library menu is the same rule on the other panel: its items come // off `row_items` and nothing else, and the two that change the timeline // say why rather than being clicked and refused afterwards. let live = RowCtx { timeline: true, usable: true, ..RowCtx::default() }; for ctx in [ live, RowCtx { usable: false, ..live }, RowCtx { placed: 2, ..live }, RowCtx { exporting: true, ..live }, RowCtx::default(), ] { let rows = row_items(ctx); for item in ROW_ITEMS { assert_eq!(rows.contains(&item), row_enable(item, ctx).listed()); } // Whatever the state, the two that need neither timeline nor edit // list are offered: a file is always describable and findable. assert!(row_enable(RowItem::Reveal, ctx).yes()); assert!(row_enable(RowItem::Properties, ctx).yes()); } assert!(row_enable(RowItem::Add, live).yes()); assert!( !row_enable( RowItem::Add, RowCtx { usable: false, ..live } ) .yes(), "a file that cannot join this timeline is not an Add anybody can ask for" ); assert!(!row_enable(RowItem::Remove, RowCtx { placed: 1, ..live }).yes()); // The two removes are both listed (DESIGN §6.7) and exactly one of them // answers yes: a placed source takes "with its clips", an unplaced one the // plain remove, and the other is refused with its reason rather than // hidden. Before this pair existed a placed source had no reachable way // out of the library at all (user 2026-08-21: "can not remove a media from // library"). let placed = RowCtx { placed: 2, ..live }; let items = row_items(placed); assert!(items.contains(&RowItem::RemoveWithClips) && items.contains(&RowItem::Remove)); assert!(row_enable(RowItem::RemoveWithClips, placed).yes()); assert!(!row_enable(RowItem::Remove, placed).yes()); let unplaced = row_items(live); assert!(unplaced.contains(&RowItem::Remove) && unplaced.contains(&RowItem::RemoveWithClips)); assert!(row_enable(RowItem::Remove, live).yes()); assert_eq!( row_enable(RowItem::RemoveWithClips, live).why(), Some("no clip uses it") ); assert!( !row_enable( RowItem::RemoveWithClips, RowCtx { exporting: true, ..placed } ) .yes() ); assert!(!row_enable(RowItem::Add, RowCtx::default()).yes()); // Every refusal is short enough to sit in the hint column beside its // label, the clip menu's rule. for item in ROW_ITEMS { for ctx in [live, RowCtx::default()] { if let Some(why) = row_enable(item, ctx).why() { assert!(!why.is_empty() && why.len() <= 30, "{why:?}"); } } } // ...and the box. Every window from the floor up, every corner of it, // and every list length either menu can have: the card is placed by // `MENU_PAD * 2 + menu_rows_h` and drawn to it, so this is the card. for viewport in [ size(px(640.), px(360.)), size(px(800.), px(600.)), size(px(1280.), px(690.)), // Smaller than the floor the layout is sized for: it still may not // draw outside the window it has. size(px(320.), px(200.)), ] { for rows in 1..=MENU_ITEMS.len() + 1 { let h = MENU_PAD * 2. + menu_rows_h(rows, viewport); for at in [ point(px(0.), px(0.)), point(px(10.), px(10.)), // The click that started all this: low in the window, where // the menu used to hang off the bottom edge. point(px(0.), viewport.height - px(4.)), point(viewport.width - px(4.), viewport.height - px(4.)), point(viewport.width * 2., viewport.height * 2.), ] { let (x, y) = menu_at(at, viewport, h); assert!(x >= 0. && y >= 0., "{x},{y} outside {viewport:?}"); assert!( x + MENU_W <= f32::from(viewport.width) + 0.01, "{rows} rows at {at:?} hang off the right of {viewport:?}" ); assert!( y + h <= f32::from(viewport.height) + 0.01, "{rows} rows at {at:?} hang off the bottom of {viewport:?}" ); } } } // On any window with the room, the whole list is drawn rather than // twelve rows of it and a scroll nobody is told about. // The compound verbs fold into one "Compound" row and the card openers into one "Adjust" // row, so the top level counts each of those folds once. let items = MENU_ITEMS.iter().filter(|a| !crate::menus::compound_item(**a) && !crate::menus::adjust_item(**a)).count() + 2; let real = size(px(1280.), px(820.)); assert_eq!(menu_rows_h(items, real), items as f32 * MENU_ROW_H); assert!(menu_rows_h(items, size(px(640.), px(360.))) < items as f32 * MENU_ROW_H); } /// Defects 2 and 3 of the menu-placement lane, as source guards -- this binary /// has no `VisualTestContext`, so where an element *mounts* and what its dim /// column *says* are read off the source the way every other layout scan here /// is. /// /// 1. All three hanging menus mount on the room's ROOT. Mounted inside /// `stance-centre` the clip menu's window-coordinate anchor was laid out /// from the centre column's own origin and painted under the dock, which is /// the "chords cut mid-word" the user photographed. /// 2. The library menu hangs a row clear of the pointer, so it cannot cover the /// row it is about. /// 3. The library rows carry chords, not prose. DESIGN §4 puts the stroke in /// that column and §8 forbids the instructional copy that used to sit there. #[test] fn the_hanging_menus_mount_at_the_room_root_and_their_rows_wear_chords_not_prose() { // Whitespace-collapsed, so the call still matches however rustfmt wraps it. let stance = src_text("ui/stance.rs") .split_whitespace() .collect::>() .join(" "); let (centre, root) = stance .split_once(".child(divider( Split::Dock,") .expect("the dock seam splits the centre column from the room root"); for menu in [ "children(player.context_card(", "children(player.library_card(", "children(player.picker_card(", ] { assert!( root.contains(menu), "{menu} must mount after the dock, on the room root" ); assert!( !centre.contains(menu), "{menu} mounted inside stance-centre paints under the dock" ); } let library = src_text("ui/library.rs"); assert!( library.contains("menu_at_w(at, viewport, pw, h)") && !library.contains("ROW_CLEAR"), "the library menu opens with its corner on the pointer, like every context menu" ); // Two rows wear a chord: the add, which is the stroke `ui/stance.rs`'s // `enter` branch answers, and preview. Every other row's column is empty. for item in ROW_ITEMS { let hint = item.hint(); match item { RowItem::Add => { assert_eq!(hint, ""); } RowItem::Preview => assert_eq!(hint, "↵"), _ => assert!(hint.is_empty(), "{:?} prints prose: {hint:?}", item.label()), } // §9: no junk drawer. A label that fits the plate whole beside its // chord, and never a sentence. assert!( item.label().split_whitespace().count() <= 4, "{}", item.label() ); } // The two removes must not read as the same verb now that the column // beside them is empty. assert_ne!(RowItem::Remove.label(), RowItem::RemoveWithClips.label()); // The destructive rows are the tail of the list, under the one rule, and // the rule is the clip menu's seam token -- not a second hairline colour. let first = ROW_ITEMS.iter().position(|i| i.destructive()).unwrap(); assert!(ROW_ITEMS[first..].iter().all(|i| i.destructive())); // The rule is the shared popup rule (the seam token lives in `ui/popup.rs`). assert!(library.contains("popup_rule()")); assert!(src_text("ui/popup.rs").contains("bg(rgba(crate::ui::theme::tokens().line))")); assert!( !library.contains("DARK_HAIRLINE"), "the Media menu's rule drifted from the clip menu's" ); } /// The other half of the keys menu's guarantee, and the audit this batch was /// asked for kept as a test: no action may be a stroke and nothing else. /// The actions card answers it for all of them at once -- its rows come off /// [`ActionId::ALL`], so a fortieth action is on it the moment it exists and /// there is no hand-written list here to fall behind. #[test] fn every_action_is_reachable_without_the_keyboard() { use keymap::ActionId; let source = ui_source(); let source = source.as_str(); let element = |id: &str| source.contains(&format!("\"{id}\"")); let listed: Vec = keys_rows() .iter() .filter_map(|r| match r { KeyRow::Act(a) => Some(*a), _ => None, }) .collect(); for action in ActionId::ALL { // Angles 2 to 9 share the one "angle 1–9" row (see `keys_rows`). if action.angle_number().is_some_and(|n| n > 1) { continue; } assert_eq!( listed.iter().filter(|a| **a == action).count(), 1, "{action:?} is reachable by keyboard only" ); } assert_eq!( listed.iter().filter(|a| a.angle_number().is_some()).count(), 1, "the angles are one row on the keys card" ); // The snap's own door was the rail's `⌗` glyph, and the rail is deleted // (DESIGN §5 as amended 2026-09-09, user decision "option C"). Its // replacement landed with the ruler's right-click menu ([`BENCH_ITEMS`]), // which carries the snap with its state in the label. A menu row wears a // *generated* hitmap id (`menu.{action:?}`, overlays.rs), so the door is // asserted on the list the row is built from rather than on a literal id // no source file spells any more. assert!( BENCH_ITEMS.contains(&ActionId::ToggleSnap), "no pointer door for the snap" ); // And the card is a door the pointer can open: the panel's own button. assert!(element("menubar-search"), "no way to open the command palette"); // The card-local strokes have the same rule, and each of them is a thing // on its card: the graph and its two buttons, the colour bars and their // reset, the speed bar and its presets, and the silence card's threshold // bar and scope chips -- the bar is the pointer's only way to a threshold. for id in [ "eq-graph", "eq-reset", "eq-spectrum", "color-bar", "color-reset", "speed-bar", "speed-preset", "speed-mode", "ramp-preset", "ramp-add-key", "ramp-key-remove", "ramp-key-step", "ramp-clear", "silence-threshold", "silence-scope", "mix-row", "eq-gain-field", "silence-apply", "export-confirm", ] { assert!(element(id), "{id} is not on any card"); } // ...and each one is named by the row that carries its stroke, so a // card-local key added to `FIXED` with nothing to click fails here // instead of being noticed by whoever tries to use the card without a // keyboard. `KeyRow::Fixed` is "shown and never offered", which used to // mean the twenty-eight rows below were the one part of this editor no // reachability test read. for fixed in keymap::FIXED.iter() { match fixed.reach { keymap::Reach::Click(id) => assert!( element(id), "{:?} ({}) points at {id}, which is on no card", fixed.chord, fixed.label ), // Nothing to click by decision, not by omission: getting out of // a card, and the hold that repeats what a drag already does. keymap::Reach::Gesture => {} } } } /// The other half of "getting out of a card is a `Reach::Gesture`": the /// gesture has to exist. Every card's scrim closes it on a press, so a hand /// that never touches the keyboard can shut every one of them -- for seven /// cards `esc` was the only exit, which is the same complaint as an action /// reachable by stroke alone, said about the way out instead of the way in. /// /// Read off [`Player::modal`] rather than off a list written here: a card /// counted there and not closed by [`Player::close_card`] fails this test /// the day it is added, which is the only way the two stay in step. #[test] fn every_card_closes_without_the_keyboard() { for card in [ "eq_card", "color_card", "speed_card", "effects_card", "mix_card", "silence_card", "subtitle_style_card", ] { // Every clip card is one shared frame: its head carries the back // and close buttons (`this.close_card()`), and its outer element is // `card_outer`, which swallows nothing a control needs. let src = fn_body(card); assert!( src.contains("self.card_outer(") && (src.contains("dark_card_head") || src.contains("section_header_row")), "{card} is not built on the shared card frame" ); assert!( src.contains("MouseButton::Left, swallow"), "{card}'s body does not swallow its own presses, so a press on \ one of its controls would close the card under itself" ); } let common = src_text("ui/cards/common.rs"); // REDESIGN §3.9: the card's back/close buttons are gone; its section head // in the Clip inspector folds it (`this.close_card()`), `esc` still closes it. let _ = common; assert!(src_text("ui/dock_stance.rs").contains("this.close_card()")); // ...and every state that makes the window modal is a state that press // clears. `exporting()` is not one of them: a running export is a job // with a cancel button, not a card with a scrim. let close = fn_body("close_card"); for field in fn_body("modal").split("self.").skip(1).filter_map(|rest| { let name: String = rest .chars() .take_while(|c| c.is_alphanumeric() || *c == '_') .collect(); (!rest[name.len()..].starts_with('(')).then_some(name) }) { assert!( close.contains(&format!("self.{field}")), "{field} makes the window modal and `close_card` leaves it set: \ that card cannot be closed by pointer" ); } } /// A clip too short to hit is still a clip: at a far zoom-out its box is /// drawn [`HIT_MIN`] wide rather than the fraction of a pixel it is worth, /// because a box nobody can put a pointer on cannot be selected, dragged, /// trimmed or given a menu -- and an invisible unselectable take is strictly /// worse than one drawn a few pixels too wide. #[test] fn a_clip_box_is_never_narrower_than_its_target() { // Two seconds on a bed showing an hour: a fifth of a pixel. let far = Scale { pps: 0.1, start: 0., }; assert!( far.width_px(2.) < 1., "the fixture is not zoomed out enough" ); assert_eq!(clip_width(far.width_px(2.)), HIT_MIN); // Zero is the floor's own case: a clip trimmed to nothing, and the // width a lane draws before its first frame is measured. assert_eq!(clip_width(0.), HIT_MIN); // What is already wide enough keeps its own width, to the pixel: the // floor is a floor and never a resize. let near = Scale::default(); assert_eq!(clip_width(near.width_px(5.)), near.width_px(5.)); // ...and the padding is not trimmable: the strips are asked of the // clip's own width, so a box drawn wider than its length keeps all of // that box as a body to select and drag by ([`trims`]). assert!(!trims(far.width_px(2.))); assert!(clip_width(far.width_px(2.)) >= HIT_MIN); } /// What the Detach and Group items do to a real timeline: a music video's /// sound comes off its picture, Delete on the loose half takes that half /// only, undo puts both back, and Group makes the two one take again -- /// whole-take delete and all. #[test] fn a_detached_half_is_removed_alone_and_groups_again() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); assert!(whole_take(&session, Lane::V1, 0), "one take to start with"); assert!(whole_take(&session, Lane::A1, 0)); let frames = session.lane_clips(Lane::V1)[0].len(); // Detach audio: neither half is a whole take any more, so Delete on // either leaves the other exactly where it is. assert!(session.ungroup(Lane::V1, 0)); assert!( !whole_take(&session, Lane::A1, 0), "the sound is a half now" ); assert!(!whole_take(&session, Lane::V1, 0), "and so is the picture"); assert!(session.lift_clip(Lane::A1, 0)); assert!(session.lane_clips(Lane::A1).is_empty(), "the sound went"); assert_eq!(session.lane_clips(Lane::V1).len(), 1, "the picture stayed"); assert_eq!(session.lane_clips(Lane::V1)[0].len(), frames, "untrimmed"); // One undo per edit, the removal then the detach. assert!(session.undo()); assert_eq!(session.lane_clips(Lane::A1).len(), 1, "the sound is back"); assert!(session.undo()); assert!(whole_take(&session, Lane::A1, 0), "one take again"); // Group: the partner is the clip covering these very frames on the // other track, which is what the item hands the engine. assert!(session.ungroup(Lane::V1, 0)); assert_eq!(span_partner(&session, Lane::V1, 0), Some((Lane::A1, 0))); session .group(Lane::V1, 0, Lane::A1, 0) .expect("both halves still cover the same frames"); assert!( whole_take(&session, Lane::A1, 0), "a take that ripples again" ); assert_eq!( span_partner(&session, Lane::V1, 0), None, "and nothing left on another track to group with" ); } /// Which clip Group reaches when more than one covers the span: the sound, /// whatever order the lanes are stored in. A project file may hold them in /// any order -- a video layer *before* the audio lane among them -- and /// "group this" means the other half of the take, never the layer above it. #[test] fn group_reaches_the_sound_before_a_video_layer_over_it() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let v2 = session.add_lane(LaneKind::Video); // A bare layer, through the one-lane door: a *drop* on V2 brings the // file's sound down with it and would put a third clip over this span. let whole = session.lane_clips(Lane::V1)[0].clone(); assert!( session.place_at(v2, 0.0, whole), "a layer covering the same frames as the take" ); // Saved and loaded back with the lanes in the order a hand-written // project may hold them: the sound last, behind the layer. let dir = engine::scratch::Scratch::dir("ve_group"); let file = dir.join("lanes.edith"); session.save_project(&file).expect("save the project"); let text = std::fs::read_to_string(&file).expect("read it back"); let (sound, rest): (Vec<&str>, Vec<&str>) = text.lines().partition(|l| l.starts_with("audio ")); std::fs::write( &file, format!("{}\n{}\n", rest.join("\n"), sound.join("\n")), ) .expect("write the reordered project"); let mut session = PlaybackSession::open_project(&file).expect("it loads as it stands"); std::fs::remove_dir_all(&dir).ok(); assert_eq!( session.lanes(), vec![Lane::V1, v2, Lane::A1], "the sound is the last lane there" ); // Detached, so Group has a choice to get wrong: the layer covers these // frames too, and it is the lane the walk meets first. assert!(session.ungroup(Lane::V1, 0)); // Group on the picture reaches the sound, not that layer. assert_eq!(span_partner(&session, Lane::V1, 0), Some((Lane::A1, 0))); session .group(Lane::V1, 0, Lane::A1, 0) .expect("the two halves cover the same frames"); // ...and a lane of its own kind is still groupable, once the sound is // spoken for: two video lanes may be one take. assert_eq!( span_partner(&session, Lane::V1, 0), Some((v2, 0)), "the layer is what is left to group with" ); } /// The refusal path, end to end against the real files: an incompatible /// import changes nothing, and the library mirrors `sources()` 1:1, so a /// refused file cannot leave a row behind. #[test] fn a_refused_import_leaves_no_row_and_an_accepted_one_is_whole() { // A mono timeline. Audio no longer refuses on channel count: every // multichannel track is folded to stereo at the decoder's door and a // stereo pair is narrowed onto mono (`engine::audio::widen`), so 5.1 and // stereo sources both join. What is still refused is a file that is not // media at all, here a text file named `.edith`. let mut session = PlaybackSession::open(asset("test_ac3.mp4")).expect("open the fixture"); // Silent like the engine suite: this opens the real device. session.set_gain(0.0); assert_eq!(session.sources().len(), 1); // 640x360 joins now (the project canvas places it), and so does a file // with no sound (it plays silence over its span). let refusal = session .import(&asset("test_h264.edith")) .expect_err("a text file is not media and must not join") .to_string(); assert!(!refusal.is_empty(), "a refusal must say why"); assert_eq!(session.sources().len(), 1, "a refusal added a row"); // An accepted one does add a row, and it reads as the whole file: 3 s // at 30 fps, its own length and not one taken off the lanes. session .import(&asset("test_audio_only.mp4")) .expect("mono matches mono"); assert_eq!(session.sources().len(), 2); let second = session.sources()[1].path.clone(); assert_eq!(session.file_frames(&second), 90); assert_eq!(timecode(90. / 30., 30.), "00:00:03:00"); } /// What the Add button and a dropped row both do, minus the pointer: the /// clip [`Player::insert_source`] builds, put in where the playhead is. One /// call, so what a drop does cannot drift from what the button does. #[test] fn adding_a_row_drops_the_whole_source_in_at_the_playhead() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); session.import(&asset("test_av2.mp4")).expect("av2 matches"); // In the library only: the 5 s the fixture is, still. assert_eq!(session.timeline_duration(), 5.0); // Two seconds in, which is inside the first take: the insert splits it. session.seek(2.0); let second = session.sources()[1].path.clone(); let frames = session.file_frames(&second); // Through the engine door `insert_source` uses, with the row's own // stream: the button, the drop and this are one call. assert!( session .place_stream_at(2.0, &second, 0, None) .expect("av2 is already on the timeline") ); // The whole of source 1 went in and nothing was painted over: the // timeline is longer by exactly that file. assert_eq!(session.timeline_duration(), 9.0); let (video, audio) = (session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)); // One take, not a video clip with no sound under it: both lanes hold // the same clip at the same place, in the same group. let at = |lane: &[Clip]| { lane .iter() .find(|c| c.start == 60) .expect("inserted at 2 s") .clone() }; assert_eq!(at(video), at(audio)); assert_eq!(at(video).source, 1); assert_eq!(at(video).len(), frames); assert!(at(video).link.is_some()); assert_eq!(video.len(), audio.len()); // The same door with a *second audio stream* of a file already there: // a new source entry, the same picture, and the row that was dragged // is what plays. This is the whole user-facing point of the slice. let mut session = PlaybackSession::open(asset("test_multilang.mp4")).expect("open the fixture"); session.set_gain(0.0); let path = session.sources()[0].path.clone(); let frames = session.file_frames(&path); let end = session.timeline_duration(); assert!( session .place_stream_at(end, &path, 1, None) .expect("the French track shares the timeline's parameters") ); assert_eq!(session.sources()[1].audio_stream, 1); assert_eq!(session.timeline_duration(), end * 2.0); // Both rows are the same file, so both rows are that file's length -- // the second one before any clip of its own existed. assert_eq!(session.file_frames(&path), frames); } /// The drop a hand actually makes: a library row let go on the *empty* bed /// past the last clip, which is most of the bed on any timeline shorter /// than the window. The whole chain the release runs, minus gpui's own /// pointer read -- [`Player::place_frame`]'s [`landing`], the frame back /// through the rate as [`Player::insert_source`] hands it over, and the one /// engine door a row goes through -- and the head lands on the frame the /// ghost was drawn on, black in front of it. It used to be swallowed by the /// clipboard's clamp inside `Project::paste` and appended after the last /// clip wherever it was let go, which is the bug this pins. #[test] fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); let fps = session.meta().frame_rate; assert_eq!(session.timeline_duration(), 5.0); // 5 s of timeline on a bed 30 s wide: the open bed past the last clip // is five sixths of it. let bed: Bounds = Bounds { origin: point(px(12.), px(400.)), size: size(px(600.), px(LANE_H)), }; let scale = Scale { pps: 20., start: 0., }; // What `Player::place_frame` answers for a pointer 200 px along the // bed: ten seconds in, five seconds past the end of the timeline, and // no mark anywhere near enough to pull it back. let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)]; let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps), None, &[]); let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps); // The drop's own magnet, not the trims' finer one -- `Player::place_frame` // ships `drop_snap_frames`, and a test computing with `snap_frames` stops // mirroring production the moment the two differ. let (at, cue) = landing(under, 0, 0, true, scale.drop_snap_frames(fps), &marks); assert_eq!((at, cue), (300, None), "the pointer is on frame 300"); // ...and what the release does with it: the frame back through the same // rate every box is drawn at, into the door the Add button uses too. assert!( session .place_stream_at(f64::from(at) / fps, &second, 0, None) .expect("av2 is already on this timeline") ); let head = |lane| { session .lane_clips(lane) .last() .cloned() .expect("the dropped clip") }; assert_eq!( head(Lane::V1).start, at, "the drop landed somewhere other than under the pointer" ); assert_eq!(head(Lane::A1).start, at, "...and its sound with it"); assert!(head(Lane::V1).link.is_some(), "one grouped take"); assert_eq!(head(Lane::V1).link, head(Lane::A1).link); // The bed in front of it stays black: nothing was stretched to reach // it, and the 4 s file is the whole of what was added. assert_eq!(session.timeline_duration(), 14.0); } /// Remove from library, through the door the menu item uses /// ([`Player::remove_source`] calls exactly this): refused by name while /// clips play from the file, and once they do not the row leaves the list. #[test] fn removing_a_row_is_refused_while_it_plays_and_takes_the_row_away() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); // Imported, then dragged onto the end: an import alone fills the // library, and a row with no clip is removable without any refusal to // test. This one has to have a take on the timeline. session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); let end = session.timeline_duration(); assert!( session .place_stream_at(end, &second, 0, None) .expect("a file just imported is on this timeline") ); let streams = HashMap::new(); let rows = |session: &PlaybackSession| { library_rows(session.sources(), &streams, &HashMap::new(), None, |_| 0).len() }; assert_eq!(rows(&session), 2, "a row per source"); let refusal = session .remove_source(&second, 0) .expect_err("its take is still on the timeline") .to_string(); assert!(refusal.contains("still plays"), "{refusal}"); assert!( refusal.contains("V1 (1 clip)") && refusal.contains("A1 (1 clip)"), "the refusal names the lanes to clear: {refusal}" ); assert_eq!(rows(&session), 2, "and the row is still there"); // Delete that take -- the whole group, from either half -- and the file // can go. The list is what says so. let last = session.lane_clips(Lane::V1).len() - 1; assert!(session.delete_clip(Lane::V1, last)); session .remove_source(&second, 0) .expect("nothing plays av2 any more"); assert_eq!(rows(&session), 1, "the row went with it"); assert_eq!(session.sources().len(), 1); // The one file left is held to the same rule and no other: its own take // is still on the lanes, so it stays... let first = session.sources()[0].path.clone(); let refusal = session .remove_source(&first, 0) .expect_err("its take is still on the timeline") .to_string(); assert!(refusal.contains("still plays"), "{refusal}"); // ...and once nothing plays it, the *last* row goes too. What is left // is the empty library `Player::close_session` turns back into the // window the editor launches as -- the user-reported bug was that this // very removal was refused, leaving a row that could never be taken // out. assert!(session.delete_clip(Lane::V1, 0)); session .remove_source(&first, 0) .expect("the only row goes like any other"); assert_eq!(rows(&session), 0, "an empty library"); assert!(session.sources().is_empty()); // And it is still a session: silent, empty, and asked for its length // rather than panicking on a source list that is not there. assert_eq!(session.timeline_duration(), 0.0); assert!( session.save_project(&asset("nothing.edith")).is_err(), "a project naming no file could never be opened again, so it is not written" ); // A row this timeline never had is refused, not panicked on. assert!(session.remove_source(&second, 0).is_err()); } /// The clipboard after a library removal. A copied clip names its file by /// index and a removal renumbers the list, so this is the difference /// between pasting the take that was copied and pasting **another file** /// over the same range ([`clipboard_after_remove`], called by /// [`Player::remove_source`]). #[test] fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() { let clip = |source: usize| Clip { speed_keys: Vec::new(), reversed: false, stabilise: None, deinterlace: Default::default(), mark: Default::default(), angle: Default::default(), fade_in: 0, fade_out: 0, transition_out: 0, transition_kind: Default::default(), visualizer: 0, viz_paint: 0, gain_db: 0.0, gain_keys: Vec::new(), pan: 0, pitch: 0.0, transform_keys: Vec::new(), opacity_keys: Vec::new(), color_keys: Vec::new(), effects: Vec::new(), start: 0, in_frame: 0, out_frame: 30, source, link: None, eq: None, color: None, transform: None, fit: Default::default(), speed: Default::default(), }; // Copied from source 2, source 0 removed: the same file is source 1 now. assert_eq!( clipboard_after_remove(vec![(Lane::V1, clip(2))], 0) .into_iter() .map(|(_, c)| c.source) .collect::>(), vec![1], "the clipboard follows its file down the list" ); // Copied from a source *before* the one that went: untouched. assert_eq!( clipboard_after_remove(vec![(Lane::V1, clip(0))], 2) .into_iter() .map(|(_, c)| c.source) .collect::>(), vec![0] ); // Copied from the row that was just removed: there is nothing left to // paste, and pasting the next file along would be a lie. assert!(clipboard_after_remove(vec![(Lane::V1, clip(1))], 1).is_empty()); assert!(clipboard_after_remove(Vec::new(), 0).is_empty()); // A set with one member's file gone loses only that member -- the rest // of the set survives to be pasted, gaps and lanes intact. let trimmed = clipboard_after_remove(vec![(Lane::V1, clip(1)), (Lane::A1, clip(2))], 1); assert_eq!( trimmed .into_iter() .map(|(_, c)| c.source) .collect::>(), vec![1] ); } /// The trim-a-clip path through the doors the edge drag uses: /// [`Player::trim_to`] clamps the pointer with `trim_room` and /// [`Player::commit_trim`] writes it with `trim_clip`. The clip plays less /// of its file, the sound linked to it follows, the head trim moves the /// in-point, and one undo takes a whole gesture back. /// /// The routing *to* these doors -- the 6 px edge strip claiming the press /// the clip's own body-drag would otherwise take -- is gpui hitbox /// behaviour (`occlude`) and is not reachable without a window. #[test] fn a_clip_trimmed_by_its_edge_plays_less_of_its_file() { use engine::project::Edge; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let whole = session.lane_clips(Lane::V1)[0].clone(); let full = session.timeline_duration(); assert_eq!( session.trim_room(Lane::V1, 0, Edge::End), Some((whole.start + 1, whole.end())), "the file's own last frame is how far the tail goes" ); assert!( !session.trim_clip(Lane::V1, 0, Edge::End, 9_999), "it already plays all of it" ); // Pulled in by a third: the timeline ends earlier and the sound with it. let shorter = whole.end() - whole.len() / 3; assert!(session.trim_clip(Lane::V1, 0, Edge::End, shorter)); assert_eq!(session.lane_clips(Lane::V1)[0].end(), shorter); assert_eq!( session.lane_clips(Lane::A1)[0].end(), shorter, "the linked sound was trimmed with the picture" ); assert!(session.timeline_duration() < full, "and plays out earlier"); // ...and dragged back out, as far as the file goes and no further. assert!(session.trim_clip(Lane::V1, 0, Edge::End, 9_999)); assert_eq!( session.lane_clips(Lane::V1)[0], whole, "the whole take back" ); // The head takes the in-point with it, so what plays at the new start // is source frame 10 rather than source frame 0. assert!(session.trim_clip(Lane::V1, 0, Edge::Start, 10)); let head = session.lane_clips(Lane::V1)[0].clone(); assert_eq!((head.start, head.in_frame), (10, 10)); assert_eq!(session.lane_clips(Lane::A1)[0].in_frame, 10, "sound too"); assert_eq!( session.trim_room(Lane::V1, 0, Edge::Start).map(|r| r.0), Some(0), "and it may be pulled back out to the file's first frame" ); assert!(session.undo(), "one step for the whole drag"); assert_eq!(session.lane_clips(Lane::V1)[0], whole); } /// Trim-to-playhead (debt #42): [`Player::trim_cut_to_playhead`] reads /// `frame_at(session.now(), fps)` and calls exactly the [`PlaybackSession:: /// trim_clip`] primitive [`Player::commit_trim`]'s pointer path does, so /// this exercises that same door at the playhead's own frame -- the clip's /// start moves to where the playhead rests, one undo step takes it back. #[test] fn trim_to_playhead_moves_the_selected_clips_edge_and_undoes_in_one_step() { use engine::project::Edge; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let whole = session.lane_clips(Lane::V1)[0].clone(); let fps = session.meta().frame_rate; // Playhead mid-clip, a second in on a five-second timeline. session.seek(1.0); let playhead = frame_at(session.now(), fps); assert!(playhead > whole.start && playhead < whole.end(), "mid-clip"); // Trim-in: the head follows the playhead, same as a pointer drag would // stop there. assert!(session.trim_clip(Lane::V1, 0, Edge::Start, playhead)); assert_eq!(session.lane_clips(Lane::V1)[0].start, playhead); assert!(session.undo(), "one step for the whole press"); assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the head is back"); // Trim-out: the same door, the tail this time. session.seek(4.0); let playhead = frame_at(session.now(), fps); assert!(playhead > whole.start && playhead < whole.end(), "mid-clip"); assert!(session.trim_clip(Lane::V1, 0, Edge::End, playhead)); assert_eq!(session.lane_clips(Lane::V1)[0].end(), playhead); assert!(session.undo(), "one step for the whole press"); assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the tail is back"); } /// The window's own copy of the rate and the two switches follows the /// *session* across `^z` and `^y`: a history entry carries the project's /// settings beside its lanes ([`engine::Project::snapshot`]), so a step puts /// them back -- and a window that kept its old copies counts every cut, step /// and fade in the rate it just undid, keeps showing a switch the session no /// longer has (`settings_stance`), and pushes that switch at the next session /// it makes. #[test] fn the_windows_settings_caches_follow_the_session_across_undo_and_redo() { use crate::player::actions::{HistoryBefore, SessionCaches, history_step}; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let native = session.meta().frame_rate; let (proxies, auto) = (!session.proxies(), !session.auto_proxies()); // The three picks as the window makes them, with the copies it keeps beside // them (`Player::apply_frame_rate`'s own write, both toggle doors'). assert!(session.set_frame_rate(native * 2.0), "the rate pick"); session.set_proxies(proxies); session.set_auto_proxies(auto); let mut caches = SessionCaches { fps: session.meta().frame_rate, proxies_on: proxies, auto_proxies_on: auto, }; assert_ne!( caches.fps, native, "the test needs a rate that really moved" ); // Back, one step at a time: after each one the window's copies are the // session's, never the pick's. for step in 0..3 { let before = HistoryBefore::of(session.subtitles(), 0); let out = history_step(&before, &mut caches, &mut session, PlaybackSession::undo) .expect("a pick behind this one"); assert_eq!( caches.fps, session.meta().frame_rate, "undo {step}: the rate" ); assert_eq!( caches.proxies_on, session.proxies(), "undo {step}: the switch" ); assert_eq!( caches.auto_proxies_on, session.auto_proxies(), "undo {step}: the auto switch" ); assert!(!out.drop_sub_image, "undo {step}: no palette moved"); } assert_eq!(caches.fps, native, "the rate pick is undone"); assert_eq!( (caches.proxies_on, caches.auto_proxies_on), (!proxies, !auto), "and both switches are back where they were" ); // ...and forward again, where the picks come home. for step in 0..3 { let before = HistoryBefore::of(session.subtitles(), 0); history_step(&before, &mut caches, &mut session, PlaybackSession::redo) .expect("a pick in front of this one"); assert_eq!( caches.fps, session.meta().frame_rate, "redo {step}: the rate" ); assert_eq!( caches.proxies_on, session.proxies(), "redo {step}: the switch" ); } assert_eq!(caches.fps, native * 2.0, "the pick's own rate is back"); assert_eq!(caches.proxies_on, proxies, "and its switch"); } /// Rows above the picked subtitle move the pick down with them /// ([`sub_pick_after_removal`]), and a `^z` of that removal has to move it back /// up: the palette comes home out of the entry, the pick is an *index* into it, /// and an index left where it was highlights one row and names another. The /// plate over the picture goes too, not because it is keyed by the pick -- it is /// keyed by where a cue sits -- but because the step moves the cues under it. #[test] fn the_subtitle_pick_follows_its_track_across_an_undo_of_a_removal() { use crate::player::actions::{HistoryBefore, SessionCaches, history_step}; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); assert_eq!( session.add_subtitle_tracks(vec![ sub("/subs/one.srt", None, "one.srt"), sub("/subs/two.srt", None, "two.srt"), sub("/subs/three.srt", None, "three.srt"), ]), 3, "the palette" ); let mut caches = SessionCaches { fps: session.meta().frame_rate, proxies_on: session.proxies(), auto_proxies_on: session.auto_proxies(), }; // The last row picked, which is where a click on it leaves the pick. let pick = 2; let picked = sub_pick_name(session.subtitles(), pick).expect("a name for the pick"); // The row *above* it goes, through the removal door's own fixup. session .remove_subtitles(0) .expect("a row with nothing on it"); let pick = sub_pick_after_removal(pick, 0, session.subtitles().len()); assert_eq!(pick, 1, "the pick slid down with the rows"); assert_eq!( sub_pick_name(session.subtitles(), pick).as_deref(), Some(picked.as_str()), "and still names the same track" ); let before = HistoryBefore::of(session.subtitles(), pick); let out = history_step(&before, &mut caches, &mut session, PlaybackSession::undo) .expect("the removal is a step like any other cut"); assert_eq!(session.subtitles().len(), 3, "the palette is back"); assert_eq!( out.sub_track, 2, "the row came back above the pick, so the pick moves up" ); assert_eq!( sub_pick_name(session.subtitles(), out.sub_track).as_deref(), Some(picked.as_str()), "and still names the same track" ); assert_ne!( sub_pick_name(session.subtitles(), pick).as_deref(), Some(picked.as_str()), "which is what the index left where it was would have named" ); assert!( out.drop_sub_image, "the drawn plate went through the pick that moved" ); // ...and forward again: the removal, with the fixup it does at its own door. let before = HistoryBefore::of(session.subtitles(), out.sub_track); let out = history_step(&before, &mut caches, &mut session, PlaybackSession::redo) .expect("the removal is in front of this one"); assert_eq!( out.sub_track, 1, "the removal slides the pick down with the rows" ); assert_eq!( sub_pick_name(session.subtitles(), out.sub_track).as_deref(), Some(picked.as_str()) ); assert!(out.drop_sub_image, "and the plate goes with it"); } /// The app-level write-back of a history step is not reachable from this binary /// -- `Player` needs a `TestAppContext` this one has none of -- so the wiring is /// pinned where it can be read: both keyboard doors route through /// [`Player::step_history`], and its body still keeps the three session caches /// and the pick, and still drops the plate. What those values *are* is pinned /// against a real session by the two tests above ([`history_step`] is the free /// function they drive); this is the copy back into the window's own fields, /// which no test can call. #[test] fn a_history_step_still_takes_its_settings_and_its_pick_back_up() { let actions = src_text("player/actions.rs"); for needle in [ "self.step_history(PlaybackSession::undo);", "self.step_history(PlaybackSession::redo);", ] { assert!( actions.contains(needle), "a history door stopped routing through Player::step_history: {needle}" ); } let body = fn_body("step_history"); // The state the step is asked about, and the answer taken back up: every one // of these deleted leaves a cache or the pick stale for the next cut, the // next frame count, or the next repaint. for needle in [ "let mut caches = SessionCaches {", "HistoryBefore::of(", "self.fps = caches.fps;", "self.proxies_on = caches.proxies_on;", "self.auto_proxies_on = caches.auto_proxies_on;", "self.sub_track = outcome.sub_track;", "if outcome.drop_sub_image {", "self.sub_image = None;", "self.reset_after_reseek();", ] { assert!( body.contains(needle), "Player::step_history no longer carries `{needle}` -- a history step \ leaves it behind (the app suite cannot see this: it has no \ TestAppContext to call the door)" ); } } /// The oracle side of trim-to-playhead (debt #42): needs a subject cut *and* /// the playhead actually resting on it, unlike the nudge pair above it which /// only needs a cut -- the "spot" a keyless drag would snap to has to be on /// the clip at all. #[test] fn trim_to_playhead_needs_a_subject_cut_with_the_playhead_on_it() { let clip = Clip { speed_keys: Vec::new(), reversed: false, stabilise: None, deinterlace: Default::default(), mark: Default::default(), angle: Default::default(), fade_in: 0, fade_out: 0, transition_out: 0, transition_kind: Default::default(), visualizer: 0, viz_paint: 0, gain_db: 0.0, gain_keys: Vec::new(), pan: 0, pitch: 0.0, transform_keys: Vec::new(), opacity_keys: Vec::new(), color_keys: Vec::new(), effects: Vec::new(), start: 100, in_frame: 0, out_frame: 60, source: 0, link: None, eq: None, color: None, transform: None, fit: FitPolicy::default(), speed: Speed::NORMAL, }; assert_eq!( enable( ActionId::TrimInToPlayhead, Ctx { timeline: true, ..Ctx::default() } ), Enable::No("no clip is selected"), "nothing marked" ); let off = Ctx { clip: Some((clip.clone(), Lane::V1)), playhead: 5, timeline: true, ..Ctx::default() }; assert_eq!( enable(ActionId::TrimOutToPlayhead, off), Enable::No("the playhead is off this clip") ); let on = Ctx { clip: Some((clip.clone(), Lane::V1)), playhead: clip.start, timeline: true, ..Ctx::default() }; assert_eq!(enable(ActionId::TrimInToPlayhead, on.clone()), Enable::Yes); assert_eq!(enable(ActionId::TrimOutToPlayhead, on), Enable::Yes); } /// The move-a-clip-between-tracks path through the door the drop uses /// ([`Player::move_clip`] calls exactly this): the clip changes row, the /// *picture* comes from the new row afterwards -- which is what "it plays /// from there" means -- and one undo puts it back. #[test] fn a_clip_dragged_onto_another_track_plays_from_it() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let v2 = session.add_lane(LaneKind::Video); assert_eq!(session.video_clip_at(0.0), Some((Lane::V1, 0))); assert!(session.move_clip_to(Lane::V1, 0, v2, 0), "V1 -> V2"); assert!(session.lane_clips(Lane::V1).is_empty(), "it left V1"); assert_eq!(session.lane_clips(v2).len(), 1, "and landed on V2"); assert_eq!( session.video_clip_at(0.0), Some((v2, 0)), "the picture now comes from V2" ); assert_eq!(session.lane_clips(Lane::A1).len(), 1, "its sound stayed"); // Dropped on a lane of the other kind it is refused and nothing moves -- // the notice the front-end shows for it says which kind of lane to use. // (The other refusal, landing on another clip, is the engine's own test // `move_clip_keeps_the_frames_and_refuses_the_rest`.) assert!(!session.move_clip_to(v2, 0, Lane::A1, 0), "picture on A1"); assert_eq!(session.lane_clips(v2).len(), 1, "and it stayed on V2"); assert!( session.move_clip_to(v2, 0, Lane::V1, 0), "dragged back down" ); // One undo per move, and each is a single step. assert!(session.undo(), "the drag back"); assert_eq!(session.video_clip_at(0.0), Some((v2, 0))); assert!(session.undo(), "the drag up"); assert_eq!(session.video_clip_at(0.0), Some((Lane::V1, 0))); assert!(session.lane_clips(v2).is_empty()); } /// The add-a-track path end to end through the doors the buttons and the /// drop use: `+ V` adds a row, a library row let go over it lands there and /// nowhere else, Delete on it leaves the lanes under it where they are, and /// undo takes the whole thing back one step at a time. #[test] fn a_track_can_be_added_dropped_on_edited_and_taken_back() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1]); // What the `+ V` button asks for, and what the row it draws is called. let v2 = session.add_lane(LaneKind::Video); assert_eq!(v2.label(), "V2"); assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1, v2]); assert!(session.lane_clips(v2).is_empty()); // A library row let go over that row: the same door the Add button // uses, told which lane it was let go over. let path = session.sources()[0].path.clone(); assert!( session .place_stream_at(1.0, &path, 0, Some(v2)) .expect("its own file is on this timeline") ); assert_eq!(session.lane_clips(v2).len(), 1, "the drop landed on V2"); assert_eq!(session.lane_clips(v2)[0].start, 30, "at the playhead"); // ...with the sound it came with, on the row of its own the drop added: // a file with audio dropped on a layer used to land silent. let a2 = Lane::new(LaneKind::Audio, 1); assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1, v2, a2]); assert_eq!(session.lane_clips(a2), session.lane_clips(v2), "same take"); assert_eq!( session.lane_clips(v2)[0].link, session.lane_clips(a2)[0].link, "grouped, so a drag moves both" ); // And nowhere else: the first pair is exactly as it was, one take each. assert_eq!(session.lane_clips(Lane::V1).len(), 1); assert_eq!(session.lane_clips(Lane::A1).len(), 1); // ...and it is a project that saves and opens again as it stands: a // grouped pair on a further row is what the file has to carry. let dir = engine::scratch::Scratch::dir("ve_layer"); let file = dir.join("layer.edith"); session.save_project(&file).expect("save the project"); let back = PlaybackSession::open_project(&file).expect("it loads as it stands"); std::fs::remove_dir_all(&dir).ok(); assert_eq!(back.lanes(), session.lanes()); for lane in back.lanes() { assert_eq!(back.lane_clips(lane), session.lane_clips(lane), "{lane:?}"); } // The drop grouped `V2` with the `A2` it added -- a take, same as the // first pair's, just on an added row -- so Delete would close both their // own lanes too (`Project::delete_members`), not drag the first pair out // of step: `delete_members` ripples only a member's own lane. Lift is // tested directly here instead, to check its own hole-left-open law // without going through the Delete key's routing. assert!(whole_take(&session, v2, 0)); assert!(whole_take(&session, Lane::V1, 0)); assert!(whole_take(&session, Lane::A1, 0)); assert_eq!(a2.label(), "A2"); assert!(session.lift_clip(v2, 0)); assert!(session.lane_clips(v2).is_empty()); assert_eq!(session.lane_clips(Lane::V1).len(), 1, "V1 stayed put"); assert_eq!( session.lane_clips(a2).len(), 1, "a lift takes the half it names: the sound is still there to lift" ); assert!(session.lift_clip(a2, 0)); // A second audio lane used to be what an mp4 export could not write -- // it copied one AAC track and a mix is not a copy. It mixes now // (`export::copy_audio`), so no row is greyed by a count of lanes. for format in [Format::Mp4, Format::Av1, Format::Av1Mp4] { assert_eq!( format_refusal(&session, format), None, "two audio lanes are a mix, not a refusal" ); } // Undo, one edit at a time and backwards: the lift of the sound, the // lift of the picture, the drop on V2 with the lane A2 it added, and // last the lane V2 -- an added track is one step like every other edit. for lanes in [4, 4, 3, 2] { assert!(session.undo()); assert_eq!(session.lanes().len(), lanes); } assert_eq!(session.lanes(), vec![Lane::V1, Lane::A1]); assert_eq!(session.lane_clips(Lane::V1).len(), 1); assert_eq!(format_refusal(&session, Format::Mp4), None); } /// [`PlaybackSession::move_selection_to`], the door a selection drag uses /// ([`Player::move_clip`]'s set path): three picks across two lanes, one of /// them the dragged clip, all travel the *same* frame delta in one call -- /// the same all-or-nothing clamp [`Project::move_room`] already gave a /// linked group, generalised to an arbitrary selection. #[test] fn a_selection_drag_moves_every_pick_by_the_same_delta() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let path = session.sources()[0].path.clone(); session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); // clip0 on V1 at the fixture's own start; clip1 on V1 ten seconds in, // appended to the open bed and rippling nothing. assert!( session .place_stream_at(10.0, &second, 0, None) .expect("av2 is on this timeline") ); let clip0 = session.lane_clips(Lane::V1)[0].clone(); let clip1 = session.lane_clips(Lane::V1)[1].clone(); assert_eq!((clip0.start, clip1.start), (0, 300)); // clipC on a second video row, well past both of the above. let v2 = session.add_lane(LaneKind::Video); assert!( session .place_stream_at(20.0, &path, 0, Some(v2)) .expect("test_av.mp4 is on this timeline") ); let clip_c = session.lane_clips(v2)[0].clone(); assert_eq!(clip_c.start, 600); let picks = [(Lane::V1, 0), (Lane::V1, 1), (v2, 0)]; // Drag clip1 fifty frames along its own lane -- the other two picks own // no neighbours of their own here, so nothing narrows the room and the // full fifty-frame ask goes through for all three. assert!(session.move_selection_to(&picks, Lane::V1, 1, Lane::V1, clip1.start + 50)); assert_eq!(session.lane_clips(Lane::V1)[0].start, clip0.start + 50); assert_eq!(session.lane_clips(Lane::V1)[1].start, clip1.start + 50); assert_eq!(session.lane_clips(v2)[0].start, clip_c.start + 50); // Every pick still names the clip it named: found again by the frame it // now starts at -- exactly the lookup `Player::remap_selection` makes // once the move lands, which is what keeps a set-move's selection alive // rather than clearing it. assert_eq!( session.lane_clips(Lane::V1)[0], Clip { start: clip0.start + 50, ..clip0 } ); assert_eq!( session.lane_clips(v2)[0], Clip { start: clip_c.start + 50, ..clip_c } ); assert!(session.undo(), "one step for the whole set-move"); assert_eq!(session.lane_clips(Lane::V1)[0].start, clip0.start); assert_eq!(session.lane_clips(Lane::V1)[1].start, clip1.start); assert_eq!(session.lane_clips(v2)[0].start, clip_c.start); } /// One pick with nowhere to go refuses the whole set: the walk onto another /// clip's own span that already refuses a lone drag /// (`move_clip_keeps_the_frames_and_refuses_the_rest`, in this crate's own /// engine tests) refuses a selection drag exactly the same way, and every /// *other* pick -- which had all the room in the world -- stays exactly /// where it was rather than moving on its own. #[test] fn a_selection_drag_refuses_as_one_set_when_any_pick_cannot_land() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let path = session.sources()[0].path.clone(); session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); assert!( session .place_stream_at(10.0, &second, 0, None) .expect("av2 is on this timeline") ); let clip0 = session.lane_clips(Lane::V1)[0].clone(); let clip1 = session.lane_clips(Lane::V1)[1].clone(); let v2 = session.add_lane(LaneKind::Video); assert!( session .place_stream_at(0.0, &path, 0, Some(v2)) .expect("test_av.mp4 is on this timeline") ); let clip_c = session.lane_clips(v2)[0].clone(); // A clip clip1 is not picked, blocking the road on V2 the drag is about // to try: clip1 dragged onto V2 lands its head inside this one. assert!( session .place_stream_at(10.0, &second, 0, Some(v2)) .expect("av2 is on this timeline") ); let blocker = session.lane_clips(v2)[1].clone(); assert_eq!(blocker.start, 300); let picks = [(Lane::V1, 0), (Lane::V1, 1), (v2, 0)]; // Dragged onto V2 at a frame inside the blocker: refused outright, the // way a lone drag onto another clip already is. assert!(!session.move_selection_to(&picks, Lane::V1, 1, v2, blocker.start + 10)); // Nothing moved -- not clip1 clamped short of the blocker, and not the // two picks that had all the room to spare. assert_eq!(session.lane_clips(Lane::V1)[0], clip0); assert_eq!(session.lane_clips(Lane::V1)[1], clip1); assert_eq!(session.lane_clips(v2)[0], clip_c); assert_eq!(session.lane_clips(v2)[1], blocker); } /// A plain click's copy is one clipboard entry, and one entry still takes /// [`PlaybackSession::paste_at`] -- the door it always has, unchanged by a /// set ever being able to ride [`PlaybackSession::paste_set_at`] instead. #[test] fn a_single_pick_copy_paste_round_trips_unchanged() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); // `open` seeds V1 with the whole fixture as its own clip -- what a plain // click would copy. let copied = session.lane_clips(Lane::V1)[0].clone(); let at = session.timeline_duration(); assert!(session.paste_at(at, copied.clone()), "a free spot always takes it"); let pasted = session.lane_clips(Lane::V1)[1].clone(); assert_eq!( (pasted.source, pasted.in_frame, pasted.out_frame), (copied.source, copied.in_frame, copied.out_frame), "the pasted clip plays the same source frames the copy did" ); assert!(session.undo(), "one step for the paste"); assert_eq!(session.lane_clips(Lane::V1).len(), 1); } /// [`PlaybackSession::paste_set_at`], the set-copy's own door /// ([`Player::paste`]'s multi-entry path): three picks across two lanes, some /// distance apart, keep that same distance and the same lane each landed on /// -- the offset [`Project::paste_set`] moves every item by is the one from /// the earliest pick to `at`, not a collapse onto `V1`/`A1`. #[test] fn a_three_pick_copy_paste_preserves_gaps_and_lane_assignment() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let path = session.sources()[0].path.clone(); session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); assert!( session .place_stream_at(10.0, &second, 0, None) .expect("av2 is on this timeline") ); let clip0 = session.lane_clips(Lane::V1)[0].clone(); let clip1 = session.lane_clips(Lane::V1)[1].clone(); let v2 = session.add_lane(LaneKind::Video); assert!( session .place_stream_at(20.0, &path, 0, Some(v2)) .expect("test_av.mp4 is on this timeline") ); let clip_c = session.lane_clips(v2)[0].clone(); // Copied in click order, out of the lanes each was clicked in -- exactly // what `Player::copy_selected` builds. let items = [(Lane::V1, clip0.clone()), (Lane::V1, clip1.clone()), (v2, clip_c.clone())]; let at = session.timeline_duration(); assert!( session.paste_set_at(at, &items), "a free spot takes the set" ); let new0 = session.lane_clips(Lane::V1)[2].clone(); let new1 = session.lane_clips(Lane::V1)[3].clone(); let new_c = session.lane_clips(v2)[1].clone(); // The gaps between picks survive the trip untouched. assert_eq!(new1.start - new0.start, clip1.start - clip0.start); assert_eq!(new_c.start - new0.start, clip_c.start - clip0.start); // And each still plays the source frames it was copied with, off the // lane it was copied off of. assert_eq!( (new0.source, new0.in_frame, new0.out_frame), (clip0.source, clip0.in_frame, clip0.out_frame) ); assert_eq!( (new_c.source, new_c.in_frame, new_c.out_frame), (clip_c.source, clip_c.in_frame, clip_c.out_frame) ); assert!(session.undo(), "one step for the whole set-paste"); assert_eq!(session.lane_clips(Lane::V1).len(), 2); assert_eq!(session.lane_clips(v2).len(), 1); } /// A set-paste never ripples the bed: a landing that would overlap so much /// as one existing clip on its own lane refuses the *whole* set, exactly as /// [`Project::paste_set`] documents, leaving the project as it was rather /// than placing the picks that had room to spare. #[test] fn a_colliding_set_paste_refuses_whole() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let path = session.sources()[0].path.clone(); session.import(&asset("test_av2.mp4")).expect("av2 matches"); let second = session.sources()[1].path.clone(); assert!( session .place_stream_at(10.0, &second, 0, None) .expect("av2 is on this timeline") ); let clip0 = session.lane_clips(Lane::V1)[0].clone(); let clip1 = session.lane_clips(Lane::V1)[1].clone(); let v2 = session.add_lane(LaneKind::Video); assert!( session .place_stream_at(20.0, &path, 0, Some(v2)) .expect("test_av.mp4 is on this timeline") ); let clip_c = session.lane_clips(v2)[0].clone(); let items = [(Lane::V1, clip0.clone()), (Lane::V1, clip1.clone()), (v2, clip_c.clone())]; // A blocker sat right where the V1 half of the set would land: pasting // at the timeline's own start walks every item straight back onto the // lanes it was copied off of, colliding with everything already there. assert!(!session.paste_set_at(0.0, &items)); assert_eq!(session.lane_clips(Lane::V1)[0], clip0); assert_eq!(session.lane_clips(Lane::V1)[1], clip1); assert_eq!(session.lane_clips(v2)[0], clip_c); assert_eq!(session.lane_clips(Lane::V1).len(), 2); assert_eq!(session.lane_clips(v2).len(), 1); } /// The refactor `move_clip` -> `move_selection` owes: a clip dragged from /// outside the selection (or with nothing else selected) moves exactly as it /// always has -- `move_clip_to`'s own door and `move_selection_to`'s /// selection-of-one both walk the same code, so they cannot drift apart. #[test] fn a_lone_clip_drag_is_unchanged_by_the_selection_path() { use engine::project::LaneKind; let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let v2 = session.add_lane(LaneKind::Video); assert!(session.move_clip_to(Lane::V1, 0, v2, 0), "V1 -> V2"); assert!(session.lane_clips(Lane::V1).is_empty()); assert_eq!(session.lane_clips(v2).len(), 1); // The other kind of lane is refused exactly as before. assert!(!session.move_clip_to(v2, 0, Lane::A1, 0)); // A drop back where it was picked up is a click, still refused. let clip = session.lane_clips(v2)[0].clone(); assert!(!session.move_clip_to(v2, 0, v2, clip.start)); } /// A caption grouped with a clip on an *added* lane closes its lane's hole /// too, not just the first pair's: the same law commit `cdc53a6` gave `V1` /// (`whole_take` -> `Project::delete_members`) has to hold from every anchor /// a Delete can be clicked from, or a grouped caption on `V2`/subtitle /// survives its clip as an orphan link. `whole_take` used to answer `false` /// for any lane with `ord >= 1` no matter what it was grouped with, which /// routed `Player::delete_selected` to `lift_clip` -- the clip's own lane /// left a hole, and the caption it was grouped with was never touched at /// all. #[test] fn a_grouped_clip_on_an_added_lane_closes_its_hole_with_its_caption() { use engine::project::LaneKind; let (mut session, sub_lane) = with_subtitle_lane(); let v2 = session.add_lane(LaneKind::Video); let path = session.sources()[0].path.clone(); assert!( session .place_stream_at(0.0, &path, 0, Some(v2)) .expect("its own file is on this timeline") ); session .place_sub(sub_lane, 0, one_second(0)) .expect("the caption goes down"); session .group_all(&[(v2, 0), (sub_lane, 0)]) .expect("a clip on an added lane and a caption are a group"); // The group pairs the clip for the whole-take question from its own // lane, `ord >= 1` or not. assert!(whole_take(&session, v2, 0)); // Two clips after the group's own -- something to close the hole // against on the caption's lane too. session .place_sub(sub_lane, 60, one_second(60)) .expect("a second caption after it"); assert_eq!(session.sub_lane(sub_lane).len(), 2); // `Player::delete_selected` calls exactly this door once `whole_take` // says yes -- the fix is that it now reaches it from `v2` too. assert!(session.delete_clip(v2, 0)); assert!(session.lane_clips(v2).is_empty(), "the clip is gone"); assert_eq!( session.sub_lane(sub_lane).len(), 1, "its grouped caption went with it, not left as an orphan" ); assert_eq!( session.sub_lane(sub_lane)[0].start, 30, "and the hole under it closed: the caption after it slid up" ); } #[test] fn a_source_is_only_ever_asked_for_its_peaks_once() { let (a, b) = (asset("test_av.mp4"), asset("test_av2.mp4")); // Two files, and two streams of the first: three envelopes, because // one file's two audio tracks are two different waveforms. let sources = [ Source { path: a.clone(), audio_stream: 0, ..Default::default() }, Source { path: a.clone(), audio_stream: 1, ..Default::default() }, Source { path: b.clone(), audio_stream: 0, ..Default::default() }, ]; let keys = |s: &[Source]| { s.iter() .map(|s| (s.path.clone(), s.audio_stream)) .collect::>() }; let mut waves: HashMap<(PathBuf, usize), Wave> = HashMap::new(); assert_eq!( unseen_sources(&sources, &waves, std::time::Instant::now()), keys(&sources) ); // The entry goes in when the decode *starts*, so the sixty repaints a // second that happen while it runs must not start it again -- which is // what this asserts about a key whose value is not an answer yet. waves.insert((a.clone(), 0), Wave::Loading); assert_eq!( unseen_sources(&sources, &waves, std::time::Instant::now()), keys(&sources[1..]), "the file's other stream is a key of its own" ); // A file with no audio is an answer like any other: never re-asked. waves.insert((a, 1), Wave::Silent); waves.insert((b.clone(), 0), Wave::Silent); assert!(unseen_sources(&sources, &waves, std::time::Instant::now()).is_empty()); // A decode that *failed* is not an answer: the reason may have gone away // (the file was still being copied when it arrived), so it is asked again // -- once the stamp is older than the cooldown, so sixty repaints a second // do not become sixty decodes. let now = std::time::Instant::now(); waves.insert((b.clone(), 0), Wave::Failed(now)); assert!( unseen_sources(&sources, &waves, now).is_empty(), "a failure that just landed is not re-asked at once" ); assert_eq!( unseen_sources(&sources, &waves, now + crate::subs::WAVE_RETRY), keys(&sources[2..]), "and is asked again once the cooldown is out" ); // The stream probe is per *file*: the two entries of `a` ask once. let mut streams: HashMap> = HashMap::new(); assert_eq!( unseen_paths(&sources, &streams), vec![asset("test_av.mp4"), b] ); streams.insert(asset("test_av.mp4"), Vec::new()); assert_eq!(unseen_paths(&sources, &streams).len(), 1); } /// The auto switch, which is the whole of what an import asks: with it off no /// film is handed to [`engine::proxy`] at all, and turning Proxies on is what /// asks for the ones the project is missing -- there is no other door, so a /// project that never wants a stand-in never spends a minute encoding one. #[test] fn a_project_that_makes_no_proxies_by_itself_starts_none_until_it_is_cut_on_them() { let sources = [Source { path: asset("test_av.mp4"), audio_stream: 0, ..Default::default() }]; let none: HashMap = HashMap::new(); let one = vec![asset("test_av.mp4")]; // Today's behaviour, both ways round: auto on starts them whether or not // the picture is cut on them -- the cache is warmed for later. assert_eq!(proxies_to_start(true, false, &sources, &none), one); assert_eq!(proxies_to_start(true, true, &sources, &none), one); // Auto off and not cut on them: nothing is started at all. assert!( proxies_to_start(false, false, &sources, &none).is_empty(), "an import started a stand-in the project asked it not to" ); // ...and the switch is the ask: the film comes through the moment Proxies // goes on, because it was left unseen rather than marked done. assert_eq!(proxies_to_start(false, true, &sources, &none), one); // One start per film either way: a film already in the map is one already // asked about, sixty repaints a second notwithstanding. let seen: HashMap = HashMap::from([(asset("test_av.mp4"), ())]); assert!(proxies_to_start(true, true, &sources, &seen).is_empty()); } #[test] fn the_media_column_never_takes_the_picture_over() { for window in [360., 640., 1280., 1920., 3840.] { let w = crate::library_w(window); // The whole point of the budget: the picture keeps the majority of // the row at every size a window can be. assert!(w <= window / 3., "{window}px window gave the list {w}px"); assert!(w >= LIBRARY_MIN_W.min(window / 3.), "{window}px: {w}px"); assert!(w <= LIBRARY_MAX_W); } // It yields: a narrower window gives the list less, never the same. assert!(crate::library_w(640.) < crate::library_w(1280.)); } #[test] fn the_window_is_named_after_the_program_and_what_is_open() { assert_eq!(window_title("test_av.mp4"), "test_av.mp4 — edith"); // An empty window is the program, not "no file open — edith". assert_eq!(window_title(NO_FILE), "edith"); } #[test] fn frac_along_measures_from_the_elements_own_left_edge() { // A ruler inset by the panel's 12 px padding: window x is not bar x. let bar: Bounds = Bounds { origin: point(px(12.), px(400.)), size: size(px(200.), px(6.)), }; assert_eq!(frac_along(px(12.), bar), 0.); assert_eq!(frac_along(px(112.), bar), 0.5); assert_eq!(frac_along(px(212.), bar), 1.); // Outside the bar (a click that slid off) clamps, never extrapolates. assert_eq!(frac_along(px(0.), bar), 0.); assert_eq!(frac_along(px(9999.), bar), 1.); // Never painted: no division by zero, no NaN reaching seek(). assert_eq!(frac_along(px(50.), Bounds::default()), 0.); // The equalizer's axis is the other one, and reads the same way. let graph: Bounds = Bounds { origin: point(px(12.), px(60.)), size: size(px(296.), px(EQ_GRAPH_H)), }; assert_eq!(frac_down(px(60.), graph), 0.); assert_eq!(frac_down(px(60. + EQ_GRAPH_H / 2.), graph), 0.5); assert_eq!(frac_down(px(9999.), graph), 1.); // Never painted reads as flat: an unpainted graph must not slam a band // to +12 dB on the first press. assert_eq!(frac_down(px(50.), Bounds::default()), 0.5); } /// A fade handle's pixels turn into frames at the bed's own scale, and a /// degenerate scale (nothing painted) turns into no movement at all. #[test] fn a_fade_drag_converts_pixels_to_frames_at_the_beds_scale() { use crate::timeline_math::fade_delta_frames; // 100 px/s at 25 fps: one second of pixels is one second of frames. assert_eq!(fade_delta_frames(100., 100., 25.), 25); // Signed: dragging back shrinks the fade by the same conversion. assert_eq!(fade_delta_frames(-50., 100., 25.), -13); // Nothing drawn to drag against moves nothing. assert_eq!(fade_delta_frames(40., 0., 25.), 0); assert_eq!(fade_delta_frames(40., -1., 25.), 0); } /// The cut odometer (DESIGN.md §6): `,` `.` walk it one cut at a time, shift /// strides ten, and either end holds rather than wrapping. #[test] fn walk_cut_strides_and_clamps_at_either_end() { use crate::timeline_math::walk_cut; assert_eq!(walk_cut(3, 10, true, 1), 4); assert_eq!(walk_cut(3, 10, false, 1), 2); assert_eq!(walk_cut(3, 10, true, 10), 9, "clamps at the last cut"); assert_eq!(walk_cut(3, 10, false, 10), 0, "clamps at the first cut"); assert_eq!(walk_cut(9, 10, true, 1), 9, "already at the end holds"); assert_eq!(walk_cut(0, 10, false, 1), 0, "already at the start holds"); // No cuts at all: nothing to land on. assert_eq!(walk_cut(0, 0, true, 1), 0); } /// The no-aim trim (DESIGN.md §6): a frame detent clamped to the room the /// engine already answered, in either direction, and never past it. #[test] fn nudge_edge_moves_one_frame_and_clamps_to_the_room() { use crate::timeline_math::nudge_edge; assert_eq!(nudge_edge(50, 1, 0, 100), 51); assert_eq!(nudge_edge(50, -1, 0, 100), 49); assert_eq!(nudge_edge(0, -1, 0, 100), 0, "the room's own floor holds"); assert_eq!( nudge_edge(100, 1, 0, 100), 100, "the room's own ceiling holds" ); // A 4px-wide clip's room can be one frame wide: still clamps, never // panics on the narrow end. assert_eq!(nudge_edge(5, 1, 5, 5), 5); } /// Loop-trim's restart (DESIGN.md §6): only once the window's far edge is /// reached, and never with the mode off. #[test] fn should_loop_restart_only_at_the_windows_far_edge() { use crate::timeline_math::should_loop_restart; assert!(!should_loop_restart(40, Some((30, 60)))); assert!(should_loop_restart(60, Some((30, 60)))); assert!( should_loop_restart(61, Some((30, 60))), "past it restarts too" ); assert!( !should_loop_restart(60, None), "loop-trim off restarts nothing" ); } /// The paused-then-started repro this predicate was blamed for and cleared /// of: `should_loop_restart` takes no play/pause state at all, so resting /// exactly at the window's far edge -- as a transport paused after playing /// through the cut once, or paused right on arrival by a scrub -- reads /// "restart" from the predicate alone regardless. The bug that froze a /// paused-then-`space`d transport at the loop's start frame was not this: it /// was `Player::toggle_loop_trim` forcing `session.play()` on arm, so the /// user's own next `space` toggled straight back to paused. It is /// `Player::pump`'s `session.is_playing()` guard around this call that must /// hold a paused transport off the seek until playback actually starts. #[test] fn should_loop_restart_is_play_state_blind_the_pump_gates_it() { use crate::timeline_math::should_loop_restart; assert!( should_loop_restart(60, Some((30, 60))), "the predicate alone can't tell paused-at-the-edge from playing-\ into-it -- that distinction is pump's is_playing() guard, not this" ); } /// This binary has no `TestAppContext` to press a live escape through, so the /// guard reads the ordering `render.rs`'s key listener actually runs: every /// card/menu/list close returns before the fallthrough that dispatches /// `ActionId::Deselect` ever runs, so escape with one of them open closes it /// and never touches `self.selected` -- the picks made before the card opened /// are still there once it is gone. #[test] fn escape_closes_a_card_before_it_can_ever_reach_deselect() { // The legacy handler this test named (`render.rs`) is gone; the same // ordering now lives in the darkroom's own root key handler // (`ui::stance::render`'s `on_key_down`). Player fullscreen is no // longer a "picture-only" layout escape leaves a special way -- it is // real OS fullscreen now (`ActionId::Fullscreen`, toggled on `f11`), // so that guard has nothing left to name here. let stance_rs = src_text("ui/stance.rs"); let dispatch = stance_rs .find("if let Some(action) = this.keymap.lookup(key, ctrl, shift, alt) {") .expect("the keymap fallthrough that fires Deselect"); for (guard, label) in [ ("this.text_field_key(event, window, cx)", "the open text fields (one dispatch point)"), ( "if this.param_card_key(key, event.keystroke.modifiers.shift, cx) {", "a param card", ), ( "if this.card_open()", "a card (keys overlay/export/eq/color/...)", ), ( "|| this.context_menu.is_some()", "the clip/row menu or a list", ), ( "if key == ESCAPE && !ctrl && this.preview_session.is_some() {", "an open preview", ), ] { let at = stance_rs .find(guard) .unwrap_or_else(|| panic!("{label}'s own escape guard moved or was renamed")); assert!( at < dispatch, "{label}'s guard reads after the Deselect dispatch -- escape would \ clear the selection before this card ever got a look at the key" ); } } /// A refused split is not an edit, so it may not drop the clip in hand: the /// refused stroke is worded ("Nothing to split — the playhead is already on a /// cut") and the pick is still what the next `x`, `delete` or clip-menu row acts /// on. The clear rides the door's own answer, the way [`Player::regroup`]'s /// always has -- a split that happened is the other way round: the seam it /// leaves renumbers the lane, so a pick kept across it names the wrong clip. /// /// A scan and not a drive: `self.selected` lives on `Player`, which needs a gpui /// `Context` this binary has no harness for. The state itself is driven in /// `the_playhead_actions_still_work_with_a_caption_marked`, which holds the real /// `cut_at` refusal this gate is about. #[test] fn a_refused_split_keeps_the_clip_in_hand() { let body = fn_body("cut"); let (before, after) = body .split_once("if cut {") .expect("the split door no longer gates anything on its own answer"); // The door's own branch, cut apart at its `else`: "runs after `if cut {`" is // satisfied by the shape this fix replaced as well, because the clear sat // below the whole if/else and so inside everything that followed the gate -- // a revert of the fix would have shipped green. What the arm has to be is // inside the then-branch, and nothing that follows the branch may hold one. let then = after .split_once("} else {") .expect("the split door no longer branches on what the cut answered") .0; // One arm's worth of clear, counted with `matches`: `split(..).count()` // counts the pieces *between* matches, so a single occurrence reads as two // there and the guard fails on the fix it is guarding. let extra_clear = after.matches("self.selected.clear()").count() > 1; assert!( !before.contains("self.selected.clear()"), "the split drops the selection before it knows the cut happened, so a \ refused split leaves the user with nothing picked and nothing told" ); assert!( then.contains("self.selected.clear()") && !extra_clear, "the clear does not ride the split's own success branch: a split that \ happened leaves the mark naming a different clip across the seam, and a \ refused one must leave it naming the clip it named" ); } /// The other half: with nothing on screen to claim the key, bare escape falls /// all the way through to `Player::act`, whose `ActionId::Deselect` arm is /// the one place `self.selected` is emptied by a bare stroke rather than by /// picking something else. #[test] fn escape_with_nothing_open_empties_the_selection() { let actions_rs = src_text("player/actions.rs"); let view_rs = src_text("player/view.rs"); assert!( actions_rs.contains("ActionId::Deselect => self.clear_picks(cx),") && view_rs.contains("self.selected = Selection::new();"), "the Deselect arm no longer clears the selection through clear_picks" ); let k = keymap::Keymap::defaults(); assert_eq!( k.lookup("escape", false, false, false), Some(ActionId::Deselect), "bare escape must still route to Deselect for that arm to ever run" ); } /// The gate that keeps "option C" honest. The spine rail is gone -- nothing on /// screen lists these verbs any more -- so every verb it used to carry has to /// be a row on the menu of the thing it acts on, or it is a verb only a person /// who already knows its chord can reach. Listed by action id rather than by /// label, so a reworded row cannot make this pass while the door is gone. /// /// And the rule line's own half of DESIGN §9: the destructive rows come last /// in every list here, which is what lets the render draw one seam before the /// first of them instead of scattering seams through the plate. #[test] fn every_verb_the_spine_carried_is_a_right_click_row() { use keymap::ActionId; // The heads a project can have, so the removes are checked on the lane // each of them belongs to. let heads: Vec = [Lane::V1, Lane::A1, Lane::S1] .into_iter() .flat_map(lane_items) .collect(); for (action, menu) in [ // EDIT (ActionId::Cut, "clip"), (ActionId::Lift, "clip"), (ActionId::Undo, "bench"), (ActionId::Redo, "bench"), // CUT (ActionId::WalkCutPrev, "bench"), (ActionId::WalkCutNext, "bench"), (ActionId::WalkCutPrev10, "bench"), (ActionId::WalkCutNext10, "bench"), (ActionId::TrimIn, "clip"), (ActionId::TrimOut, "clip"), // The trim-to-playhead pair is *not* in this list: `^[` and `^]` are // the keyboard's version of dragging a clip edge to a spot, a gesture // the pointer already has, so the clip menu leaves them out (DESIGN §9, // "Never a junk drawer"). They keep their chords and their KEYS rows, // which is what the layout sweep's exemption for them names. (ActionId::LoopTrim, "clip"), // VIEW (ActionId::ZoomOut, "bench"), (ActionId::ZoomIn, "bench"), (ActionId::ZoomFit, "bench"), (ActionId::ToggleSnap, "bench"), // TRACK (ActionId::AddVideoLane, "lane head"), (ActionId::AddAudioLane, "lane head"), (ActionId::AddSubtitleLane, "lane head"), (ActionId::RemoveVideoLane, "lane head"), (ActionId::RemoveAudioLane, "lane head"), (ActionId::RemoveSubtitleLane, "lane head"), ] { assert!( MENU_ITEMS.contains(&action) || BENCH_ITEMS.contains(&action) || heads.contains(&action), "{action:?} reaches no menu: the spine listed it and the {menu} menu does not" ); } // Every menu is a list of actions the keyboard already reaches, so every // row can wear its chord (DESIGN §4): a row built here out of an id the // registry never files would print an empty column. for action in MENU_ITEMS .into_iter() .chain(BENCH_ITEMS) .chain(heads.iter().copied()) { assert!( ActionId::ALL.contains(&action), "{action:?} is a menu row and not a registered action" ); } for list in [ MENU_ITEMS.to_vec(), BENCH_ITEMS.to_vec(), lane_items(Lane::A1), ] { let first = list.iter().position(|&a| destructive(a)); if let Some(first) = first { assert!( list[first..].iter().all(|&a| destructive(a)), "a safe row sits below the rule line: {list:?}" ); } } } /// The first import into an empty timeline is placed on it, and that placement /// is one undo step: the library line that stands behind it is not. What /// `take_import` does for a file that lands on an empty timeline, minus the /// window (DESIGN §7). #[test] fn a_first_import_placed_on_an_empty_timeline_is_one_undo_step() { let mut session = PlaybackSession::open_library(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); assert!( session.is_empty(), "the library holds the file, the lanes do not" ); let path = session.sources()[0].path.clone(); assert!( session .place_stream_at(0.0, &path, 0, None) .expect("the file is on this timeline") ); assert!(!session.is_empty()); assert_eq!(session.timeline_duration(), 5.0); assert!(session.undo(), "the placement is an undo step"); assert!(session.is_empty(), "undo takes the placement back"); assert!(!session.undo(), "the import itself is not an undo step"); } /// DESIGN §7's gap door, below the window: a picked hole is what Delete /// closes, one undo step gives it back, and an undo that takes the hole away /// leaves a pick that no longer names one. #[test] fn a_picked_gap_closes_in_one_undo_step_and_a_stale_pick_is_dropped() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); let path = session.sources()[0].path.clone(); let c0 = session.lane_clips(Lane::V1)[0].clone(); assert!( session .place_stream_at(20.0, &path, 0, None) .expect("test_av.mp4 is on this timeline") ); let c1 = session.lane_clips(Lane::V1)[1].clone(); let (start, frames) = (c0.end(), c1.start - c0.end()); assert!( frames > 0, "the second placement leaves a hole behind the first" ); let pick = GapPick { lane: Lane::V1, start, frames, }; assert_eq!(live_gap(&session, pick), Some(pick)); // Delete's door: the same close a right-click gives, and the ripple moves // the placement after the hole. let scope = session .gap_take_scope(Lane::V1, start, frames) .expect("a scope"); session .cut_regions(&[(start, frames)], &scope) .expect("the hole closes"); assert_eq!(live_gap(&session, pick), None, "a closed hole is no hole"); assert!(session.lane_clips(Lane::V1)[1].start < c1.start); assert!(session.undo(), "the close is one undo step"); assert_eq!(session.lane_clips(Lane::V1)[1].start, c1.start); assert_eq!(live_gap(&session, pick), Some(pick)); // An undo that takes the placement away takes the hole with it. assert!(session.undo(), "the placement is undoable"); assert_eq!(session.lane_clips(Lane::V1).len(), 1); assert_eq!(live_gap(&session, pick), None); } /// Delete over a picked gap is live with nothing marked; the clip-only rows /// beside it stay refused. #[test] fn delete_is_enabled_over_a_picked_gap() { let gap = Ctx { gap: true, timeline: true, ..Ctx::default() }; assert_eq!(enable(ActionId::Delete, gap.clone()), Enable::Yes); let bare = Ctx { timeline: true, ..Ctx::default() }; assert!(matches!(enable(ActionId::Delete, bare), Enable::No(_))); assert!(matches!(enable(ActionId::Copy, gap), Enable::No(_))); } /// The ledger's gap readout: both ends as timecodes and the length in seconds. #[test] fn the_gap_readout_names_both_ends_and_the_length() { assert_eq!( gap_readout(100, 62, 25.0), "Gap · 2.5 s · starts at 0:04" ); } /// The ledger's clip readout (DESIGN §6.9): the source's stem, the clip's /// first and last frame as timecodes and its length in seconds. #[test] fn the_clip_readout_names_the_source_both_ends_and_the_length() { assert_eq!( clip_readout("city_dusk", 0, 285, 30.0), "city_dusk · 9.5 s · starts at 0:00" ); } /// The status bar's frame rate: whole rates lose their decimals, fractional /// ones keep two. #[test] fn the_status_bar_writes_a_frame_rate_without_trailing_zeros() { assert_eq!(fps_label(30.0), "30"); assert_eq!(fps_label(29.97), "29.97"); assert_eq!(fps_label(24.0), "24"); } /// DESIGN §7: a locked lane refuses the edits to its items, and the oracle says /// why in the words the toast uses. Selection, playback and the editor's own /// switches are not edits and stay live. #[test] fn a_locked_lane_refuses_its_edits_with_the_lock_reason() { use keymap::ActionId; let locked = Ctx { timeline: true, locked: true, playable: true, ..Ctx::default() }; for edit in [ ActionId::Cut, ActionId::Delete, ActionId::Lift, ActionId::Paste, ActionId::Crossfade, ActionId::TrimIn, ActionId::Mix, ] { assert_eq!( enable(edit, locked.clone()), Enable::No("The track is locked"), "{edit:?} changes a locked lane's item", ); } assert_eq!(enable(ActionId::Play, locked.clone()), Enable::Yes); assert_eq!(enable(ActionId::ToggleSnap, locked.clone()), Enable::Yes); // Unlocked, the same question is the one it always was: with nothing marked, // Delete says there is nothing to delete, not that a lock is on. let open = Ctx { locked: false, ..locked }; assert_eq!( enable(ActionId::Delete, open), Enable::No("nothing selected") ); } /// An insert onto a locked lane is refused with the lock's own toast before it /// places anything. The auto-pick is the same question: with no lane named the /// insert writes `V1` and `A1` (or `A1` alone for a song), and the lock is asked /// about each of those. Needs a window to run, so the pick and the order of the /// door are pinned here from the source. #[test] fn an_insert_onto_a_locked_lane_is_refused_with_the_lock_reason() { let picture = Path::new("/media/clip.mp4"); let song = Path::new("/media/song.mp3"); let still = Path::new("/media/still.png"); assert_eq!( crate::Player::insert_lanes(picture, None), vec![Lane::V1, Lane::A1], "an unnamed picture is the grouped take on V1 and A1" ); assert_eq!(crate::Player::insert_lanes(song, None), vec![Lane::A1]); assert_eq!(crate::Player::insert_lanes(still, None), vec![Lane::V1]); let v2 = Lane::new(LaneKind::Video, 1); let a2 = Lane::new(LaneKind::Audio, 1); assert_eq!( crate::Player::insert_lanes(picture, Some(v2)), vec![v2, a2], "a picture named onto V2 takes its sound on A2" ); assert_eq!(crate::Player::insert_lanes(song, Some(a2)), vec![a2]); let body = fn_body("place_source"); let door = body .find("lane_locked_refusal(") .expect("insert_source asks the lock"); let place = body .find("session.place_stream_at(") .expect("insert_source places the stream"); assert!( body.contains("Self::insert_lanes(path, onto)") && door < place, "insert_source places the stream before it asks whether the lane is locked" ); assert!( fn_body("lane_locked_refusal").contains("is locked"), "the refusal must say the lane is locked" ); } /// The lock's refusals are the Player's, and they need a window to run, so the /// doors are pinned by their source: each edit entry point asks the one lock /// helper before it touches the timeline, and the toast offers the way out. #[test] fn every_edit_door_asks_the_lock_before_it_touches_the_timeline() { for func in [ "move_clip_now", "move_sub", "place_sub", "lift_sub", "start_trim", "start_pro", "cut", "delete_selected", "lift_selected", "paste", "place_source", ] { assert!( fn_body(func).contains("lane_locked_refusal(") || fn_body(func).contains("marked_locked_lane()"), "{func} edits a lane without asking whether it is locked" ); } for func in ["select", "pick"] { assert!( fn_body(func).contains("lane_locked_refusal(target.0)"), "{func} selects an item on a locked lane" ); } let stance = src_text("ui/stance.rs"); assert!( stance.contains("ToastAction::Unlock(_) => \"Unlock\""), "the locked toast has no Unlock button" ); assert!( src_text("player/actions.rs").contains("ToastAction::Unlock(lane) =>"), "the Unlock button does nothing" ); } /// The inline cue editor ends on a press anywhere outside its plate, as Enter /// does: the root hears the press, and the plate stops its own presses from /// reaching it. Pinned on source, since a window is not available here. #[test] fn a_press_off_the_cue_plate_commits_the_edit_and_a_press_on_it_does_not() { let root = src_text("ui/stance.rs"); assert!( root.contains("cx.listener(Player::cue_edit_press_outside)"), "the root does not commit an open cue edit on a press" ); assert!( src_text("player/timeline_edit.rs") .contains("if self.cue_edit.is_some() {\n self.commit_cue_edit(cx);"), "a press outside the plate does not commit the open edit" ); let plate = src_text("ui/bench_stance/sub.rs"); let start = plate .find("fn cue_edit_plate(") .expect("the cue edit plate"); assert!( plate[start..].contains("cx.stop_propagation()"), "the cue edit plate lets its own presses reach the root" ); } // ---- three-point edits from the library (F9 insert, F10 overwrite) ---- fn ask<'a>(lanes: &'a [(Lane, bool)]) -> crate::SourceEditAsk<'a> { crate::SourceEditAsk { fps: 30.0, lanes, playhead: 60, range: None, marks: (None, None), source: 1, total: 150, picture: true, sound: true, still: false, video_patch: None, audio_patch: None, } } /// The plan reads the marks the way an editor does: the source's own in..out /// when marked, the whole item when not, at the playhead. #[test] fn the_plan_is_the_marked_range_at_the_playhead() { let lanes = [(Lane::V1, false), (Lane::A1, false)]; let (at, items) = crate::plan_source_edit(&ask(&lanes)).expect("plans"); assert_eq!(at, 60); let shape: Vec<_> = items.iter().map(|(l, c)| (*l, c.source, c.in_frame, c.out_frame)).collect(); assert_eq!(shape, vec![(Lane::V1, 1, 0, 150), (Lane::A1, 1, 0, 150)], "no marks: the whole item"); let marked = crate::SourceEditAsk { marks: (Some(1.0), Some(2.5)), ..ask(&lanes) }; let (_, items) = crate::plan_source_edit(&marked).expect("plans"); assert!(items.iter().all(|(_, c)| (c.in_frame, c.out_frame) == (30, 75))); // An out mark past the file is held to its end; an in mark alone runs to the end. let tail = crate::SourceEditAsk { marks: (Some(4.0), None), ..ask(&lanes) }; let (_, items) = crate::plan_source_edit(&tail).expect("plans"); assert!(items.iter().all(|(_, c)| (c.in_frame, c.out_frame) == (120, 150))); let empty = crate::SourceEditAsk { marks: (Some(2.0), Some(2.0)), ..ask(&lanes) }; assert!(crate::plan_source_edit(&empty).is_err()); // The source patch sends each half to its own lane, when that lane is there. let (v2, a2) = (Lane::new(LaneKind::Video, 1), Lane::new(LaneKind::Audio, 1)); let lanes = [(Lane::V1, false), (Lane::A1, false), (v2, false), (a2, false)]; let patched = crate::SourceEditAsk { video_patch: Some(v2), audio_patch: Some(a2), ..ask(&lanes) }; let (_, items) = crate::plan_source_edit(&patched).expect("plans"); let lanes_hit: Vec<_> = items.iter().map(|(l, _)| *l).collect(); assert_eq!(lanes_hit, vec![v2, a2]); } /// Classic three-point: the source's in plus the timeline's in and out. The /// timeline's in mark is where it lands, its length is how long; a source out /// mark wins the length when both are set. #[test] fn the_timeline_range_sets_where_and_how_long_when_the_source_has_no_out() { let lanes = [(Lane::V1, false), (Lane::A1, false)]; let three = crate::SourceEditAsk { range: Some((90, 120)), marks: (Some(1.0), None), ..ask(&lanes) }; let (at, items) = crate::plan_source_edit(&three).expect("plans"); assert_eq!(at, 90); assert!(items.iter().all(|(_, c)| (c.in_frame, c.out_frame) == (30, 60))); let both = crate::SourceEditAsk { range: Some((90, 120)), marks: (Some(1.0), Some(3.0)), ..ask(&lanes) }; let (at, items) = crate::plan_source_edit(&both).expect("plans"); assert_eq!(at, 90); assert!(items.iter().all(|(_, c)| (c.in_frame, c.out_frame) == (30, 90))); } /// The first unlocked lane of each kind takes its half; a sound-only item and a /// still take their one lane; every lane locked refuses by name. #[test] fn the_plan_picks_the_first_unlocked_lanes() { let v2 = Lane::new(LaneKind::Video, 1); let a2 = Lane::new(LaneKind::Audio, 1); let lanes = [(Lane::V1, true), (Lane::A1, false), (v2, false), (a2, false)]; let (_, items) = crate::plan_source_edit(&ask(&lanes)).expect("plans"); assert_eq!(items.iter().map(|(l, _)| *l).collect::>(), vec![v2, Lane::A1]); let song = crate::SourceEditAsk { picture: false, ..ask(&lanes) }; let (_, items) = crate::plan_source_edit(&song).expect("plans"); assert_eq!(items.len(), 1); assert_eq!(items[0].0, Lane::A1); let still = crate::SourceEditAsk { picture: true, sound: false, still: true, total: 1, ..ask(&lanes) }; let (_, items) = crate::plan_source_edit(&still).expect("plans"); assert_eq!((items[0].0, items[0].1.out_frame), (v2, 150), "a still shows five seconds by default"); let locked = [(Lane::V1, true), (Lane::A1, true)]; assert!(crate::plan_source_edit(&ask(&locked)).unwrap_err().contains("locked")); } /// The whole chain minus the keys: plan the marked range, then the engine edit. /// An insert in the middle of the first take cuts and ripples it; an overwrite /// replaces and moves nothing; each is one undo step. #[test] fn insert_and_overwrite_run_the_plan_through_the_engine_and_undo_in_one_step() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); session.import(&asset("test_av2.mp4")).expect("av2 matches"); let lanes: Vec<(Lane, bool)> = [Lane::V1, Lane::A1].into_iter().map(|l| (l, false)).collect(); let before = (session.lane_clips(Lane::V1).to_vec(), session.lane_clips(Lane::A1).to_vec()); let marked = crate::SourceEditAsk { playhead: 60, marks: (Some(1.0), Some(2.0)), total: session.file_frames(&session.sources()[1].path.clone()), ..ask(&lanes) }; let (at, items) = crate::plan_source_edit(&marked).expect("plans"); session .edit_from_source_at(engine::SourceEdit::Insert, f64::from(at) / 30.0, &items) .expect("inserts"); let spans = |lane| { session.lane_clips(lane).iter().map(|c| (c.start, c.end(), c.source)).collect::>() }; assert_eq!(spans(Lane::V1), vec![(0, 60, 0), (60, 90, 1), (90, 180, 0)]); assert_eq!(spans(Lane::A1), spans(Lane::V1), "the sound went in with the picture"); assert!(session.undo()); assert_eq!((session.lane_clips(Lane::V1).to_vec(), session.lane_clips(Lane::A1).to_vec()), before); session .edit_from_source_at(engine::SourceEdit::Overwrite, f64::from(at) / 30.0, &items) .expect("overwrites"); let spans = |lane| { session.lane_clips(lane).iter().map(|c| (c.start, c.end(), c.source)).collect::>() }; assert_eq!(spans(Lane::V1), vec![(0, 60, 0), (60, 90, 1), (90, 150, 0)]); assert!(session.undo()); // A locked lane refuses with its name and costs no undo step. assert!(session.set_lane_locked(Lane::A1, true)); let err = session .edit_from_source_at(engine::SourceEdit::Insert, 2.0, &items) .expect_err("A1 is locked"); assert!(err.to_string().contains("A1 is locked"), "{err}"); } /// F9 and F10 are free (the comma and the period already walk the cuts), `I` /// and `O` mark the previewed item while one is up, and the palette and the /// keys card list both actions by name. #[test] fn the_source_edits_have_keys_marks_and_a_menu() { let keys = keymap::Keymap::defaults(); assert_eq!(keys.lookup("f9", false, false, false), Some(ActionId::InsertSource)); assert_eq!(keys.lookup("f10", false, false, false), Some(ActionId::OverwriteSource)); assert_eq!(keys.lookup(".", false, false, false), Some(ActionId::WalkCutNext)); assert_eq!(keys.lookup(",", false, false, false), Some(ActionId::WalkCutPrev)); assert_eq!(ActionId::InsertSource.label(), "Insert source at playhead"); assert_eq!(ActionId::OverwriteSource.label(), "Overwrite source at playhead"); let act = source_from("pub(crate) fn act("); for arm in [ "ActionId::SetIn if self.preview_session.is_some() => self.mark_source(true, cx)", "ActionId::SetOut if self.preview_session.is_some() => self.mark_source(false, cx)", "ActionId::ClearRange if self.preview_session.is_some() => self.clear_source_marks(cx)", "ActionId::InsertSource => self.source_edit(engine::SourceEdit::Insert, cx)", "ActionId::OverwriteSource => self.source_edit(engine::SourceEdit::Overwrite, cx)", ] { assert!(act.contains(arm), "act() lacks `{arm}`"); } assert!( ui_source().contains("Act(ActionId::InsertSource)") && ui_source().contains("Act(ActionId::OverwriteSource)"), "the Edit menu carries both" ); let rows = keys_rows(); for a in [ActionId::InsertSource, ActionId::OverwriteSource] { assert!(rows.iter().any(|r| matches!(r, KeyRow::Act(x) if *x == a)), "{a:?} is on the keys card"); } assert!(fn_body("source_edit_at").contains("edit_from_source_at(")); } /// The comment markers' doors: every one of the four actions has a stroke that is not a /// taken one (bare `m` is the mute and stays it), a row on the ruler's right-click menu /// and one in the Timeline menu, and the oracle answers them like the rest of the /// timeline's actions -- live with a timeline, refused without. #[test] fn the_marker_actions_have_free_keys_menu_rows_and_an_oracle_answer() { use keymap::ActionId; let keymap = keymap::Keymap::defaults(); assert_eq!(keymap.lookup("m", false, false, false), Some(ActionId::ToggleMute)); assert_eq!(keymap.lookup("m", false, false, true), Some(ActionId::AddMarker)); assert_eq!(keymap.lookup("m", false, true, false), Some(ActionId::NextMarker)); assert_eq!(keymap.lookup("m", true, true, false), Some(ActionId::PrevMarker)); assert_eq!(keymap.lookup("8", false, false, true), Some(ActionId::Markers)); let mut chords: Vec = keymap.entries().iter().map(|b| b.chord.pretty()).collect(); let all = chords.len(); chords.sort(); chords.dedup(); assert_eq!(chords.len(), all, "a default chord is bound twice"); let timeline = Ctx { timeline: true, playable: true, ..Ctx::default() }; assert!(BENCH_ITEMS.contains(&ActionId::MarkerHere), "the ruler menu drops a marker at the frame it names"); for action in [ActionId::NextMarker, ActionId::PrevMarker, ActionId::Markers] { assert!(BENCH_ITEMS.contains(&action), "{action:?} has no ruler menu row"); assert!( crate::ui::menubar::Title::Timeline .entries() .contains(&crate::ui::menubar::Entry::Act(action)), "{action:?} has no Timeline menu row" ); assert_eq!(enable(action, timeline.clone()), Enable::Yes, "{action:?}"); assert!( matches!(enable(action, Ctx::default()), Enable::No(_)), "{action:?} needs a timeline" ); } } /// Roll, slip and slide through the doors the shift-drags and the keys end at /// ([`Player::pro_apply`] calls exactly these): each is one undo step, the /// timeline keeps its length, and a gesture that moves nothing takes no step. #[test] fn roll_slip_and_slide_reach_the_engine_as_one_undoable_edit_each() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); session.set_gain(0.0); assert!(session.cut_at(1.0) && session.cut_at(3.0)); let full = session.timeline_duration(); let spans = |s: &PlaybackSession, lane: Lane| { s.lane_clips(lane) .iter() .map(|c| (c.start, c.end(), c.in_frame)) .collect::>() }; let before = spans(&session, Lane::V1); let depth = session.undo_depth(); // Roll: the cut after clip 0, one detent later; the take rolls with it. assert_eq!(session.roll_clip(Lane::V1, 0, 31), Some(31)); assert_eq!(spans(&session, Lane::V1)[..2], [(0, 31, 0), (31, 90, 31)]); assert_eq!(spans(&session, Lane::A1)[..2], [(0, 31, 0), (31, 90, 31)]); assert_eq!(session.undo_depth(), depth + 1); assert_eq!(session.timeline_duration(), full); // Pulled past the neighbour it is held a frame short of it. let (_, hi) = session.roll_room(Lane::V1, 0).expect("a cut"); assert_eq!(session.roll_clip(Lane::V1, 0, 9_999), Some(hi)); assert!(session.undo() && session.undo()); assert_eq!(spans(&session, Lane::V1), before); // Slip: the window moves, the slot does not. let by = session.slip_source_delta(Lane::V1, 1, 5).expect("a video clip"); assert_eq!(by, 5); assert_eq!(session.slip_clip(Lane::V1, 1, by), Some(5)); assert_eq!(spans(&session, Lane::V1)[1], (30, 90, 35)); assert_eq!(session.slip_clip(Lane::V1, 1, 0), Some(0), "nothing moved"); assert_eq!(session.undo_depth(), depth + 1, "and no step was taken"); assert!(session.undo()); // Slide: the clip moves, its neighbours give and take the frames. assert_eq!(session.slide_clip(Lane::V1, 1, 40), Some(40)); assert_eq!( spans(&session, Lane::V1), [(0, 40, 0), (40, 100, 30), (100, 150, 100)] ); assert_eq!(session.timeline_duration(), full); assert_eq!(session.slide_clip(Lane::V1, 0, 5), None, "no clip before it"); assert!(session.undo()); assert_eq!(spans(&session, Lane::V1), before); } /// The keys and the shift-drags only land inside the engine's room: the /// drag's arithmetic is a clamp, never a wrap or a negative frame. #[test] fn a_pro_trim_target_is_held_inside_the_rooms_the_engine_answered() { assert_eq!(crate::timeline_math::pro_target(30, 5, 1, 89), 35); assert_eq!(crate::timeline_math::pro_target(30, 500, 1, 89), 89); assert_eq!(crate::timeline_math::pro_target(30, -500, 1, 89), 1); assert_eq!(crate::timeline_math::pro_target(0, -3, 0, 10), 0); } /// The oracle's answers for the six keys: a clip is needed, a still has no /// more footage to slip, and a locked lane refuses all of them. #[test] fn the_pro_trim_actions_need_a_clip_refuse_stills_and_obey_locks() { use keymap::ActionId::*; let all = [RollBack, RollForward, SlipBack, SlipForward, SlideBack, SlideForward]; let bare = Ctx { timeline: true, ..Ctx::default() }; for action in all { assert_eq!(enable(action, bare.clone()), Enable::No("no clip is selected"), "{action:?}"); } let session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); let clip = session.lane_clips(Lane::V1)[0].clone(); let on = Ctx { clip: Some((clip, Lane::V1)), ..bare.clone() }; for action in all { assert_eq!(enable(action, on.clone()), Enable::Yes, "{action:?}"); assert_eq!( enable(action, Ctx { locked: true, ..on.clone() }), Enable::No("The track is locked"), "{action:?}" ); } let still = Ctx { image: true, ..on }; assert_eq!(enable(SlipBack, still.clone()), Enable::Hidden("this clip is a still")); assert_eq!(enable(SlideBack, still), Enable::Yes); } /// The default chords reach the six, and the shift-drags are wired where the /// pointer lands: the body and the edge strips route a shift press to /// `start_pro`, the gpui move-drag the body also starts is told to stand /// down, and the root follows and commits the gesture. Source pins, since a /// window is not available here. #[test] fn the_pro_trims_have_chords_and_shift_drags() { use keymap::ActionId::*; let keys = keymap::Keymap::defaults(); for (key, action) in [ ("[", RollBack), ("]", RollForward), (",", SlipBack), (".", SlipForward), ("left", SlideBack), ("right", SlideForward), ] { assert_eq!(keys.lookup(key, false, false, true), Some(action), "alt+{key}"); } let clip = src_text("ui/bench_stance/clip.rs"); assert!(clip.contains("event.modifiers.shift"), "the shift press is not read"); assert!(clip.contains("ProKind::Roll") && clip.contains("ProKind::Slide")); assert!(fn_body("move_clip_now").contains("pro_drag.is_some()")); let edit = src_text("player/timeline_edit.rs"); assert!(edit.contains("self.pro_to(event.position.x, cx)")); assert!(edit.contains("self.commit_pro(cx)")); } /// The J/K/L shuttle: L and J start at 1x and double to 4x on a repeat, the /// other key turns round at 1x, and a stopped transport starts at 1x. #[test] fn the_shuttle_steps_one_two_four_and_turns_round_at_one() { use crate::player::transport::shuttle_rate; assert_eq!(shuttle_rate(true, false, 1.0), 1.0, "L from rest"); assert_eq!(shuttle_rate(false, false, 1.0), -1.0, "J from rest"); assert_eq!(shuttle_rate(true, true, 1.0), 2.0); assert_eq!(shuttle_rate(true, true, 2.0), 4.0); assert_eq!(shuttle_rate(true, true, 4.0), 4.0, "4x is the top"); assert_eq!(shuttle_rate(false, true, -1.0), -2.0); assert_eq!(shuttle_rate(false, true, -2.0), -4.0); assert_eq!(shuttle_rate(false, true, -4.0), -4.0); assert_eq!(shuttle_rate(false, true, 2.0), -1.0, "J while forward turns round at 1x"); assert_eq!(shuttle_rate(true, true, -4.0), 1.0, "L while backward turns round at 1x"); assert_eq!(shuttle_rate(true, false, 2.0), 1.0, "a paused shuttle starts over"); } /// Backward a picture is due once the clock has come down to its frame. #[test] fn a_backward_picture_is_due_when_the_clock_comes_down_to_it() { use crate::player::transport::frame_due; assert!(frame_due(10, 10.5, false) && !frame_due(11, 10.5, false)); assert!(frame_due(10, 10.5, true), "the frame under the clock is shown"); assert!(frame_due(11, 10.5, true), "...and one above it is not held back"); assert!(!frame_due(9, 10.5, true), "one below is still ahead of the clock"); } /// J is a live action wherever L is. #[test] fn j_is_enabled_wherever_l_is() { use keymap::ActionId; let live = Ctx { timeline: true, playable: true, ..Ctx::default() }; assert!(enable(ActionId::ShuttleBack, live.clone()).yes()); assert_eq!( enable( ActionId::ShuttleBack, Ctx { playable: false, ..live.clone() } ), enable( ActionId::ShuttleForward, Ctx { playable: false, ..live } ), ); } #[test] fn sequence_actions_enable_only_where_they_can_work() { let lone = Ctx { sequences: 1, timeline: true, ..Ctx::default() }; assert!(matches!(enable(ActionId::NewSequence, lone.clone()), Enable::Yes)); assert!(matches!(enable(ActionId::DeleteSequence, lone.clone()), Enable::No(_))); assert!(matches!(enable(ActionId::CloseCompound, lone), Enable::No(_))); let two = Ctx { sequences: 2, timeline: true, ..Ctx::default() }; assert!(matches!(enable(ActionId::DeleteSequence, two.clone()), Enable::Yes)); let used = Ctx { sequence_used: true, ..two.clone() }; assert!(matches!(enable(ActionId::DeleteSequence, used), Enable::No(_))); let child = Ctx { parent: true, ..two }; assert!(matches!(enable(ActionId::CloseCompound, child), Enable::Yes)); assert!(matches!(enable(ActionId::NestClips, Ctx::default()), Enable::No(_))); assert!(matches!(enable(ActionId::BreakApart, Ctx::default()), Enable::No(_))); }