diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index e7da37e..9772a0e 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -914,7 +914,10 @@ fn the_budget_is_the_one_number_the_engine_gets() { // put on screen. assert_eq!(auto_bps(1920, 1080, 30.), 6_220_800); assert_eq!(auto_bps(160, 120, 15.), BPS_MIN, "a tiny picture floors"); - assert!(auto_bps(7680, 4320, 60.) <= 20_000_000, "and a huge one caps"); + assert!( + auto_bps(7680, 4320, 60.) <= 20_000_000, + "and a huge one caps" + ); for bps in [auto_bps(1920, 1080, 30.), auto_bps(320, 240, 24.)] { assert!((BPS_MIN..=BPS_MAX).contains(&bps)); } @@ -1067,11 +1070,25 @@ fn a_chord_the_export_moment_answers_never_reaches_the_room() { let (typing, closed) = rest .split_once("return true;") .expect("the typing branch returns before the chords below it"); - assert!(typing.contains("self.budget_edit = None"), "esc leaves the field"); - assert!(closed.contains("self.close_card()"), "then esc closes the moment"); + assert!( + typing.contains("self.budget_edit = None"), + "esc leaves the field" + ); + assert!( + closed.contains("self.close_card()"), + "then esc closes the moment" + ); // Its chords, all of them consumed here rather than by the keymap. for chord in [ - "\"d\"", "\"n\"", "\"e\"", "\"enter\"", "\"up\"", "\"down\"", "\"c\"", "\"b\"", "\"g\"", + "\"d\"", + "\"n\"", + "\"e\"", + "\"enter\"", + "\"up\"", + "\"down\"", + "\"c\"", + "\"b\"", + "\"g\"", "\",\"", ] { assert!(closed.contains(chord), "{chord} is not the moment's own"); @@ -1086,7 +1103,11 @@ fn a_chord_the_export_moment_answers_never_reaches_the_room() { fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { let cards = src_text("ui/cards.rs"); let start = cards.find("fn export_card(").expect("the moment"); - let body = &cards[start..start + cards[start..].find("\n /// ").unwrap_or(cards.len() - start)]; + let body = &cards[start + ..start + + cards[start..] + .find("\n /// ") + .unwrap_or(cards.len() - start)]; // A segment is the setter it names, not a readout of it. for (id, chord, setter) in [ ("moment-picture", "\"c\"", "cycle_export_picture"), @@ -1098,7 +1119,10 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { assert!(body.contains(setter), "the {id} segment changes nothing"); } // The door, wearing the room's own chord rather than a hand-typed one. - assert!(body.contains("moment-settings"), "row 3 has no settings door"); + assert!( + body.contains("moment-settings"), + "row 3 has no settings door" + ); assert!( body.contains("self.keymap.chord(ActionId::Settings)"), "the door's chord is not read from the keymap" @@ -1113,7 +1137,10 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { .map(|at| &cards[at..at + 1900]) .expect("the segment atom"); assert!(seg.contains("INK3()") && seg.contains("INK4()")); - assert!(seg.contains("DARK_RAISED()"), "a segment does not answer hover"); + assert!( + seg.contains("DARK_RAISED()"), + "a segment does not answer hover" + ); // The readouts worth seeing: the project's picture size and rate, and // a sound rate that is on the line whether or not it is pressable. assert!( @@ -1126,13 +1153,18 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { ); // The picture segment is a child, not a `has_video` maybe: hidden on the // sound-only formats it left `c` pressing nothing and no way back. - let at = body.find("\"moment-picture\"").expect("the picture segment"); + let at = body + .find("\"moment-picture\"") + .expect("the picture segment"); assert!( !body[at - 240..at].contains("has_video"), "the picture segment is gated on has_video again -- the dead end" ); // Wrapped, never cut: the readouts made row 3 longer than 1280 wide. - assert!(body.contains(".flex_wrap()"), "row 3 truncates instead of wrapping"); + assert!( + body.contains(".flex_wrap()"), + "row 3 truncates instead of wrapping" + ); } /// The dead end the user hit: the cycle walked into the sound-only formats @@ -1140,15 +1172,22 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { /// and can't turn it back to video"). One cycle, and it wraps. #[test] fn the_picture_cycle_wraps_out_of_the_sound_only_formats() { - use crate::ui::settings_stance::{PICTURE_CYCLE, next_picture}; + use crate::ui::settings_stance::{next_picture, PICTURE_CYCLE}; // Nothing refused: every stop is the next one, and the last wraps to the // first -- OGG, the tail of the list, back to MP4. let mut at = PICTURE_CYCLE[0]; - for &want in PICTURE_CYCLE.iter().skip(1).chain(std::iter::once(&PICTURE_CYCLE[0])) { + for &want in PICTURE_CYCLE + .iter() + .skip(1) + .chain(std::iter::once(&PICTURE_CYCLE[0])) + { at = next_picture(at, |_| false); assert_eq!(at, want, "the cycle stopped walking"); } - assert_eq!(at, PICTURE_CYCLE[0], "a full walk is a wrap, not a dead end"); + assert_eq!( + at, PICTURE_CYCLE[0], + "a full walk is a wrap, not a dead end" + ); assert_eq!(next_picture(Format::Ogg, |_| false), Format::Mp4); // A timeline with no picture refuses every video format, and the cycle // still moves: the sound-only stops are what is left of it. @@ -1278,12 +1317,33 @@ fn the_moment_and_the_settings_room_wear_the_same_export_chords() { assert!(settings.contains(chord), "the EXPORT rows lost {chord}"); assert!(moment.contains(chord), "row 3 lost {chord}"); assert!(handler.contains(chord), "the moment answers no {chord}"); - assert!(player.contains(chord), "the settings page answers no {chord}"); + assert!( + player.contains(chord), + "the settings page answers no {chord}" + ); } + // The Encoder row is the picture's own -- the engine opens no seat for a + // song -- so the settings room gates it on the format exactly as the + // moment does, and neither mounts a row for an audio-only format. + assert_eq!(Format::Mp4.has_video(), true); + for audio_only in [Format::Wav, Format::Flac, Format::Mp3, Format::Ogg] { + assert_eq!(audio_only.has_video(), false, "{audio_only:?}"); + } + let at = settings + .find("settings-export-encoder") + .expect("the Encoder row"); + let mount = &settings[at.saturating_sub(260)..at]; + assert!( + mount.contains("has_video()"), + "the Encoder row is mounted for a song, where pressing it does nothing" + ); // `e` stays the Export press: the encoder seat took `g` rather than a // shifted letter, which no ghost wears. assert!(handler.contains("\"e\" | \"enter\" => self.start_export")); - assert!(!settings.contains("\n \"e\","), "the Encoder row took `e` back"); + assert!( + !settings.contains("\n \"e\","), + "the Encoder row took `e` back" + ); } /// The Sound row: what it offers, and that the pick travels to the engine @@ -1401,9 +1461,15 @@ fn a_typed_colour_is_read_in_every_spelling_and_anything_else_is_refused() { edit.typed('z'); assert_eq!(edit.commit(), None); let why = edit.refusal.clone().expect("a refusal, not a silence"); - assert!(why.contains("#RRGGBB"), "the refusal says what a colour is: {why}"); + assert!( + why.contains("#RRGGBB"), + "the refusal says what a colour is: {why}" + ); assert_eq!(edit.text, "zz", "the refusal keeps the text it refused"); - assert!(edit.detail().contains("zz▏"), "the caret stays in the buffer"); + assert!( + edit.detail().contains("zz▏"), + "the caret stays in the buffer" + ); // ...and the next stroke clears it: that reason described the text that is // no longer there. edit.typed('0'); @@ -1780,11 +1846,9 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() { assert!(native_detail.ends_with(" source"), "{native_detail}"); // A project at a size nobody listed still gets the whole list, with // nothing marked rather than a wrong row marked. - assert!( - resolution_choices((1000, 1000), native) - .iter() - .all(|(.., picked)| !picked) - ); + assert!(resolution_choices((1000, 1000), native) + .iter() + .all(|(.., picked)| !picked)); // Picking a row means that row, and stepping means the next one: the // list and the stroke read the same ladder. assert_eq!(next_resolution(ladder[1], native), ladder[2]); @@ -1883,7 +1947,10 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() { assert!(tall <= 360., "the list is taller than the floor"); assert_eq!( menu_at(point(px(600.), px(340.)), size(px(640.), px(360.)), tall), - (640. - crate::layout::MENU_EDGE - MENU_W, 360. - crate::layout::MENU_EDGE - tall), + ( + 640. - crate::layout::MENU_EDGE - MENU_W, + 360. - crate::layout::MENU_EDGE - tall + ), "the list would hang off the smallest window" ); } @@ -2238,8 +2305,8 @@ fn maximizing_a_card_grows_its_box_without_moving_where_a_value_sits_in_it() { /// inside the dock, or hands it the dock's width again, fails this. #[test] fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() { + use crate::layout::{split_size, Split}; use crate::SPLIT_W; - use crate::layout::{Split, split_size}; // `layout::SPLIT_W` is the one divider between `stance-centre` and the // dock; the 56px rail that used to eat the centre's left edge is gone @@ -2286,7 +2353,7 @@ fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() { /// assumption. #[test] fn a_maximized_card_can_never_rise_above_the_picture_no_matter_the_bench_height() { - use crate::ui::stance::{LEDGER_H, TIME_BAND_H, below_picture_floor}; + use crate::ui::stance::{below_picture_floor, LEDGER_H, TIME_BAND_H}; let viewport_h = 1080.; for bench_h in [140., 200., 400.] { assert_eq!( @@ -2531,3 +2598,58 @@ fn picker_row_tails_are_state_words_and_settings_values_carry_no_ellipsis() { ); } } + +/// D1: the project's own settings are the project's -- the resolution, the +/// rate, the encoder seat, the mix rate and the two proxy switches ride in +/// the same history entry the lanes do, so every one of those picks is a +/// single `ctrl+z`. Before this, pressing `z` after any of them did nothing. +#[test] +fn a_settings_pick_undoes_and_redoes_like_a_cut() { + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); + let (w, h) = session.resolution(); + + assert!(session.set_resolution(w / 2, h / 2)); + assert_eq!(session.resolution(), (w / 2, h / 2)); + assert!(session.undo(), "the resolution pick is one step"); + assert_eq!(session.resolution(), (w, h), "and the canvas comes back"); + assert!(session.redo(), "redo walks the same branch"); + assert_eq!(session.resolution(), (w / 2, h / 2)); + assert!(session.undo(), "back to where the test started"); + + // The encoder seat, which nothing reseeks and nothing shows until an + // export starts. + let seat = session.encoder_seat(); + assert_ne!(seat, EncoderSeat::Software); + session.set_encoder_seat(EncoderSeat::Software); + assert_eq!(session.encoder_seat(), EncoderSeat::Software); + assert!(session.undo(), "the encoder pick is one step"); + assert_eq!(session.encoder_seat(), seat, "and the seat comes back"); + assert!(session.redo()); + assert_eq!(session.encoder_seat(), EncoderSeat::Software); + assert!(session.undo()); + + // The mix rate, and the switches beside it. + session.set_sample_rate(Some(44_100)); + assert_eq!(session.sample_rate(), Some(44_100)); + assert!(session.undo(), "the mix rate is one step"); + assert_eq!(session.sample_rate(), None, "back to the derived rate"); + let proxies = session.proxies(); + session.set_proxies(!proxies); + assert_eq!(session.proxies(), !proxies); + assert!(session.undo(), "the proxy switch is one step"); + assert_eq!(session.proxies(), proxies, "and the switch comes back"); + let auto = session.auto_proxies(); + session.set_auto_proxies(!auto); + assert_eq!(session.auto_proxies(), !auto); + assert!(session.undo(), "and so is the auto switch"); + assert_eq!(session.auto_proxies(), auto, "which comes back too"); + + // ...and a lane edit still undoes the way it always did, settings and all + // in the same stack. + let clips = session.lane_clips(Lane::V1).len(); + assert_eq!(clips, 1, "one take to start with"); + assert!(session.delete_clip(Lane::V1, 0)); + assert_eq!(session.lane_clips(Lane::V1).len(), 0); + assert!(session.undo(), "the delete is one step"); + assert_eq!(session.lane_clips(Lane::V1).len(), clips); +} diff --git a/crates/app/src/ui/settings_stance.rs b/crates/app/src/ui/settings_stance.rs index 0a7bea4..6127830 100644 --- a/crates/app/src/ui/settings_stance.rs +++ b/crates/app/src/ui/settings_stance.rs @@ -684,7 +684,11 @@ fn export_section(player: &Player, cx: &mut Context) -> impl IntoElement .as_ref() .and_then(|session| format_refusal(session, format)) .map(|why| (short_reason(&why).into(), INK4())); - let picture_ink = if refused_now.is_some() { INK4() } else { INK1() }; + let picture_ink = if refused_now.is_some() { + INK4() + } else { + INK1() + }; let (codec, rated) = sound_codec(format); let seat = player.encoder_seat(); let av1_gpu = seat == EncoderSeat::Hardware && matches!(format, Format::Av1 | Format::Av1Mp4); @@ -745,18 +749,25 @@ fn export_section(player: &Player, cx: &mut Context) -> impl IntoElement ) .into_any_element() })) - .child(row_chord( - "settings-export-encoder", - "Encoder", - encoder_word(seat), - "which encoder writes the picture: the GPU where this machine has a seat, or the CPU", - "g", - av1_gpu.then(|| (AV1_GPU_NOTICE.into(), NOTICE_LOOK())), - player, - cx.listener(|this, _: &ClickEvent, _, cx| { - this.cycle_encoder(cx); - }), - )) + // The encoder writes the *picture*, and the engine opens no seat for a + // song: with WAV/FLAC/MP3/Ogg picked the row would be a button that + // does nothing when pressed. The export moment mounts no row there + // either (`Format::has_video`), so this is that same rule rather than a + // third treatment. + .children(format.has_video().then(|| { + row_chord( + "settings-export-encoder", + "Encoder", + encoder_word(seat), + "which encoder writes the picture: the GPU where this machine has a seat, or the CPU", + "g", + av1_gpu.then(|| (AV1_GPU_NOTICE.into(), NOTICE_LOOK())), + player, + cx.listener(|this, _: &ClickEvent, _, cx| { + this.cycle_encoder(cx); + }), + ) + })) // Read-only: the range is set on the timeline with the marks // themselves ([`keymap::ActionId::SetIn`]/`SetOut`), which is where a // person can see what they are marking.