diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 2d8bb7b..df7f593 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -67,8 +67,22 @@ impl Player { | ActionId::AddSubtitleLane | ActionId::RemoveSubtitleLane | ActionId::ImportSubtitles - | ActionId::Crossfade - | ActionId::Dissolve + // `Crossfade` and `Dissolve` are NOT here, and that is the + // rule rather than an omission: their doors answer for + // themselves ([`Player::crossfade_selected`], + // [`Player::dissolve_selected`]) and the clip-menu row reaches + // `dissolve_selected` directly, never through this table, so a + // list entry armed the key path and left the menu path armed by + // nothing. + // + // The three `Remove*Lane` entries ARE still here and are still + // wrong in the same way -- `remove_lane` refuses a track that + // holds clips and the last of its kind, and it now carries its + // own arm ([`Player::remove_lane`]) -- but taking them off is + // a wider pass over this list than this change makes, so they + // stay until it does. Until then each of those removals arms + // twice over, which is the lesser fault beside arming once for + // a removal that did not happen. | ActionId::Visualizer ) { self.mark_dirty(); @@ -251,10 +265,12 @@ impl Player { } match action { ActionId::Mix => self.open_mix(Some(lane), cx), - ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => { - self.mark_dirty(); - self.remove_lane(lane, cx); - } + // The arm rides the door's own answer, like every arm in this + // window: `remove_lane` refuses a track that still holds clips or + // captions, and the last track of its kind, and arming before the + // ask lit the ledger's `unsaved` ghost, wrote a sidecar and put the + // close prompt up over a project whose bytes had not moved. + ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => self.remove_lane(lane, cx), _ => unreachable!("only lane-header actions reach act_lane"), } } diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 5b42d90..19e03db 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -1,8 +1,8 @@ //! The cards the window opens over itself: the pickers, colour, speed, //! silence, the mixer and the equalizer. -use crate::*; use crate::ui::settings_stance::SettingsTab; +use crate::*; impl Player { /// Cycles the *project's* resolution through [`RESOLUTIONS`], starting from @@ -279,10 +279,7 @@ impl Player { match caption_media_half(session, (lane, idx), LaneKind::Video) { Some(half) => Some(half), None => { - self.notify_user( - "NOTHING TO GRADE — a caption has no picture" - .into(), - ); + self.notify_user("NOTHING TO GRADE — a caption has no picture".into()); cx.notify(); return; } @@ -426,10 +423,7 @@ impl Player { match caption_media_half(session, (lane, idx), LaneKind::Video) { Some(half) => Some(half), None => { - self.notify_user( - "NOTHING TO PLACE — a caption has no picture" - .into(), - ); + self.notify_user("NOTHING TO PLACE — a caption has no picture".into()); cx.notify(); return; } @@ -567,8 +561,7 @@ impl Player { Some(half) => Some(half), None => { self.notify_user( - "NOTHING TO RE-TIME — a caption has no speed of its own" - .into(), + "NOTHING TO RE-TIME — a caption has no speed of its own".into(), ); cx.notify(); return; @@ -734,8 +727,7 @@ impl Player { Some(half) => Some(half), None => { self.notify_user( - "NOTHING TO SCAN — a caption has no sound of its own" - .into(), + "NOTHING TO SCAN — a caption has no sound of its own".into(), ); cx.notify(); return; @@ -856,14 +848,20 @@ impl Player { if self.session.is_none() { return; } - self.mark_dirty(); let Some(session) = self.session.as_mut() else { return; }; - match lanes.get(self.mix_field) { + // The arm rides the door's answer, not the press: a fader already + // against its wall, a ceiling already at its clamp and a limiter + // switch that did not move are *not* edits, and `set_lane_gain_db` / + // `set_limiter` each answer `false` for exactly those (an unchanged + // value). Arming before the ask lit the ledger's `unsaved` ghost, + // wrote an autosave sidecar and put the close prompt up over a + // project whose bytes had not moved. + let took = match lanes.get(self.mix_field) { Some(&lane) => { let at = session.lane_gain_db(lane) + steps as f32 * MIX_DB_STEP; - session.set_lane_gain_db(lane, at); + session.set_lane_gain_db(lane, at) } None => { let limiter = session.limiter(); @@ -878,8 +876,11 @@ impl Player { ..limiter }, }; - session.set_limiter(at); + session.set_limiter(at) } + }; + if took { + self.mark_dirty(); } cx.notify(); } @@ -1246,17 +1247,15 @@ impl Player { /// nothing. pub(crate) fn previewed(&mut self) -> Option<(Vec<(u32, u32)>, Vec)> { if self.silence_marks.is_empty() { - self.notify_user( - if self.silence_keep_only { - "NO SPEECH TO CUT — keep-only-silence needs silence and speech".into() - } else { - format!( - "NO SILENCE — under {:.0} dBFS lasting {:.2} s", - self.silence.threshold_db, self.silence.min_silence - ) - .into() - }, - ); + self.notify_user(if self.silence_keep_only { + "NO SPEECH TO CUT — keep-only-silence needs silence and speech".into() + } else { + format!( + "NO SILENCE — under {:.0} dBFS lasting {:.2} s", + self.silence.threshold_db, self.silence.min_silence + ) + .into() + }); return None; } Some((self.silence_marks.clone(), self.silence_lanes())) @@ -1302,7 +1301,11 @@ impl Player { // moves indexes (a delete, a paste, an undo). self.selected.clear(); self.reset_after_reseek(); - let what = if self.silence_keep_only { "SPEECH" } else { "SILENCES" }; + let what = if self.silence_keep_only { + "SPEECH" + } else { + "SILENCES" + }; self.notify_user( format!( "{count} {what} CUT {reach} — {} shorter · undo {}", @@ -1342,7 +1345,11 @@ impl Player { // goes with them. self.selected.clear(); self.reset_after_reseek(); - let what = if self.silence_keep_only { "SPEECH" } else { "SILENCES" }; + let what = if self.silence_keep_only { + "SPEECH" + } else { + "SILENCES" + }; self.notify_user( format!( "{count} {what} AT {rate} {reach} · undo {}", @@ -1494,9 +1501,9 @@ impl Player { "NOTHING SELECTED · select all {}", self.keymap.display(ActionId::Select) )), - (Some((lane, _)), _) if lane.kind != LaneKind::Audio => Some( - "NOT AN AUDIO CLIP — the equalizer works on sound".to_string(), - ), + (Some((lane, _)), _) if lane.kind != LaneKind::Audio => { + Some("NOT AN AUDIO CLIP — the equalizer works on sound".to_string()) + } _ => None, }; if let Some(refusal) = refusal { @@ -1535,12 +1542,23 @@ impl Player { }; let params = (!self.eq_params.is_identity()).then(|| self.eq_params.clone()); if let Some(session) = &mut self.session { - session.set_eq(lane, idx, params); - self.mark_dirty(); + // `set_eq` answers "the index was there and the curve is finite" + // -- it snapshots and rewrites the very slot it already holds for + // a curve that is already in force -- so on its own bool a + // re-commit of the same curve armed autosave, the ledger's + // `unsaved` ghost and the close prompt over a project whose bytes + // had not moved. The arm rides the curve having moved, the + // comparison `apply_fit` reads for `set_fit` + // ([`Player::apply_fit`]), and then the door's own answer. + let moved = session.eq_of(lane, idx).cloned() != params; + if moved && session.set_eq(lane, idx, params) { + self.mark_dirty(); + // `set_eq` reseeks inside the engine -- that is what makes the + // change audible at once -- and a reseek is what these flags + // are about. Nothing was written, so nothing was reseeked. + self.reset_after_reseek(); + } } - // `set_eq` reseeks inside the engine -- that is what makes the change - // audible at once -- and a reseek is what these flags are about. - self.reset_after_reseek(); cx.notify(); } @@ -1590,12 +1608,7 @@ impl Player { /// band that was just made. Refused rather than silently ignored at the cap. pub(crate) fn add_band(&mut self, cx: &mut Context) { if self.eq_params.bands.len() >= EQ_BANDS_MAX { - self.notify_user( - format!( - "EQUALIZER FULL — {EQ_BANDS_MAX} bands" - ) - .into(), - ); + self.notify_user(format!("EQUALIZER FULL — {EQ_BANDS_MAX} bands").into()); cx.notify(); return; } diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 6a5de06..55f147f 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -177,9 +177,7 @@ impl Player { self.reset_after_reseek(); } Err(e) => self.notify_user(format!("NO VISUALIZER — {e}").into()), - Ok(false) => { - self.notify_user("NO VISUALIZER — that clip could not be placed".into()) - } + Ok(false) => self.notify_user("NO VISUALIZER — that clip could not be placed".into()), } cx.notify(); } @@ -453,10 +451,7 @@ impl Player { { true => { self.close_session(); - format!( - "REMOVED {} — the library is empty", - file_name(path) - ) + format!("REMOVED {} — the library is empty", file_name(path)) } // The undo stack goes with it (`Project::remove_source`): // said here, because a `z` that does nothing afterwards @@ -1196,9 +1191,7 @@ impl Player { .count(); let text = match (on, ready, making) { (false, ..) => "PROXIES OFF — the films themselves are what play".to_string(), - (true, 0, 0) => { - "PROXIES ON — no film here has one".to_string() - } + (true, 0, 0) => "PROXIES ON — no film here has one".to_string(), (true, 0, n) => format!("PROXIES ON — {n} still being made"), (true, n, 0) => format!("PROXIES ON — cutting on {n}"), (true, n, m) => format!("PROXIES ON — cutting on {n}, {m} still being made"), @@ -2156,6 +2149,11 @@ impl Player { .map(|session| session.remove_lane(lane)); let text = match removed { Some(Ok(())) => { + // The arm lives here, on the one answer that means the track + // went: `remove_lane` refuses a track still holding clips or + // captions, and the last of its kind, and both used to arrive + // with the `unsaved` ghost already lit behind them. + self.mark_dirty(); self.selected.clear(); self.context_menu = None; self.eq_open = None; diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 3f22151..3cb0903 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1783,12 +1783,25 @@ impl Player { return; }; let frames = self.fps.round().max(1.) as u32; - if let Some(session) = &mut self.session { - if !session.crossfade(lane, idx, frames) { - self.notify_user("NOTHING TO CROSSFADE — no neighbour end to end".into()); - } + if self.session.is_none() { + return; + } + // The arm rides the write, and rides the join's own edges as well as + // the door's answer: `Project::crossfade` answers true for any two + // adjacent clips, so a crossfade already at the room the two clips + // offer writes the value the join already carried and still says yes. + // This door carries its own arm rather than leaning on the action + // table's list, which fires before any door is asked. + let before = self.transition_edges(lane, idx); + let took = match &mut self.session { + Some(session) => session.crossfade(lane, idx, frames), + None => false, + }; + if took && self.transition_edges(lane, idx) != before { + self.mark_dirty(); + } else if !took { + self.notify_user("NOTHING TO CROSSFADE — no neighbour end to end".into()); } - cx.notify(); } /// Dissolves the join the selection names, into or back out of it: two @@ -1809,24 +1822,48 @@ impl Player { cx.notify(); return; }; - let Some(session) = &mut self.session else { + if self.session.is_none() { cx.notify(); return; - }; - let removing = session.transition_out_of(lane, idx) > 0; + } + let removing = self.transition_out_of_selected(lane, idx); let frames = if removing { 0 } else { self.fps.round().max(1.) as u32 }; - if !session.set_transition_out(lane, idx, frames) { + // The arm rides the write, and the join's own edges as well as the + // door's answer -- `set_transition_out`'s own rule + // ([`Player::crossfade_selected`]'s). This door carries its own arm + // rather than leaning on the action table's list, which fires before + // any door is asked: the clip-menu row + // ([`crate::ui::bench_stance`]) reaches this door directly, never + // through the table at all, and was armed by nothing. + let before = self.transition_edges(lane, idx); + let took = match &mut self.session { + Some(session) => session.set_transition_out(lane, idx, frames), + None => false, + }; + if took && self.transition_edges(lane, idx) != before { + self.mark_dirty(); + if removing { + self.notify_user("DISSOLVE REMOVED — the clips cut again".into()); + } + } else if !took { self.notify_user("NOTHING TO DISSOLVE — no neighbour end to end".into()); - } else if removing { - self.notify_user("DISSOLVE REMOVED — the clips cut again".into()); } cx.notify(); } + /// The dissolve the join at `idx` of `lane` already carries, read before + /// the session is borrowed mutably: `0` for a lane, index or join that has + /// none, and `false` if there is no session to ask. + fn transition_out_of_selected(&self, lane: Lane, idx: usize) -> bool { + self.session + .as_ref() + .is_some_and(|session| session.transition_out_of(lane, idx) > 0) + } + /// Widens or narrows the transition the anchor already carries, one /// frame at a step, from the inspector's duration row -- ctrl+f/ctrl+x /// stay the toggle that seeds a fresh one at one second; this is what @@ -1869,17 +1906,44 @@ impl Player { if self.exporting().is_some() { return; } - let Some(session) = &mut self.session else { + if self.session.is_none() { return; + } + // The engine's bool answers "the two clips are adjacent" -- both + // setters snapshot and clamp, and a `frames` already in force (a step + // past the cap, a number retyped in the field) writes the value the + // clip already carried and still says true. The arm therefore rides + // the join's own edges read back, the same before/after comparison + // `move_sub` and `commit_fade` make. + let before = self.transition_edges(lane, idx); + let ok = match &mut self.session { + Some(session) => match lane.kind { + LaneKind::Video => session.set_transition_out(lane, idx, frames), + LaneKind::Audio => session.crossfade(lane, idx, frames), + _ => false, + }, + None => false, }; - let ok = match lane.kind { - LaneKind::Video => session.set_transition_out(lane, idx, frames), - LaneKind::Audio => session.crossfade(lane, idx, frames), - _ => false, - }; - if ok { + if ok && self.transition_edges(lane, idx) != before { self.mark_dirty(); - cx.notify(); + } + cx.notify(); + } + + /// What the join at `idx` of `lane` carries on both sides, for the doors + /// that only the *pair* can answer for: a crossfade writes `idx`'s + /// `fade_out` and its neighbour's `fade_in`, so a comparison of the + /// anchor's own field alone would miss a neighbour-side no-op. `None` + /// for a lane with no such pair, which is a value no write can equal. + fn transition_edges(&self, lane: Lane, idx: usize) -> Option<(u32, u32)> { + let session = self.session.as_ref()?; + match lane.kind { + LaneKind::Video => Some((session.transition_out_of(lane, idx), 0)), + LaneKind::Audio => { + let clips = session.lane_clips(lane); + Some((clips.get(idx)?.fade_out, clips.get(idx + 1)?.fade_in)) + } + _ => None, } } diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index db43f74..eb15650 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -1172,7 +1172,7 @@ 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::{next_picture, PICTURE_CYCLE}; + use crate::ui::settings_stance::{PICTURE_CYCLE, next_picture}; // 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]; @@ -1710,6 +1710,201 @@ fn every_click_door_that_writes_the_project_arms_autosave() { one for the same step" ); } + // The mix card's own doors. Both answer "the value moved" -- a fader + // already against its wall, a ceiling already at its clamp, a limiter + // switch whose value is the one in force are each `false` -- so the arm + // rides the bool, and `nudge_mix` does not arm before the ask the way it + // did: a held arrow key at the top of the fader lit `unsaved`, wrote a + // sidecar and put the close prompt up over a project whose bytes had not + // moved. + let body = fn_body("nudge_mix"); + for door in ["set_lane_gain_db", "set_limiter"] { + assert!( + body.contains(door), + "nudge_mix no longer goes through {door}" + ); + } + let arm = body + .split_once("if took {") + .expect("the mix arm no longer rides the door's own answer") + .1; + assert!( + arm.contains("mark_dirty()"), + "nudge_mix arms outside its gate, so a fader held against its wall \ + would dirty the project" + ); + let before = body.split_once("if took {").unwrap().0; + assert!( + !before.contains("mark_dirty()"), + "nudge_mix still arms ahead of the door, so a clamped no-op nudge \ + leaves the project looking edited" + ); + // The equalizer card's commit, the same rule against a door whose bool is + // the WEAKER of the two shapes: `set_eq` answers "the index was there and + // the curve is finite" and rewrites the very slot it already holds for a + // curve already in force, so the arm needs the comparison too -- the same + // pair of conditions `apply_fit` rides. + let body = fn_body("commit_eq"); + let arm = body + .split_once("if moved && session.set_eq(lane, idx, params) {") + .expect("the EQ commit no longer rides the curve having moved and then the door") + .1; + assert!( + arm.contains("mark_dirty()"), + "commit_eq arms outside its gate, so re-committing the curve already \ + in force would dirty the project" + ); + assert!( + body.contains("session.eq_of(lane, idx).cloned() != params"), + "commit_eq rides the engine's bool alone, which is true for a \ + re-commit of the curve already in force" + ); + // ...and the reseek bookkeeping rides with the arm, not instead of it. + assert!( + arm.contains("reset_after_reseek()"), + "commit_eq's reseek flags no longer clear on a write that took" + ); + let before = body + .split_once("if moved && session.set_eq(lane, idx, params) {") + .unwrap() + .0; + assert!( + !before.contains("mark_dirty()"), + "commit_eq still arms ahead of the door" + ); +} + +/// The transition doors, which are the class's other shape: both engine +/// setters ([`engine::project::Project::set_transition_out`], +/// [`engine::project::Project::crossfade`]) answer `true` for any two +/// adjacent clips, snapshot and clamp included -- so a step past the +/// successor's length, or a number retyped into the field, wrote the value the +/// join already carried and still said yes. [`Player::set_transition_frames`] +/// reads the join's own edges back and rides those, and the crossfade side +/// compares *both* edges: it writes the anchor's `fade_out` and the +/// neighbour's `fade_in`, and a comparison of the anchor alone would miss a +/// neighbour-side no-op. +#[test] +fn a_transition_step_or_a_retyped_number_arms_only_what_moved() { + let body = fn_body("set_transition_frames"); + for door in ["set_transition_out", "crossfade"] { + assert!( + body.contains(door), + "the duration doors no longer include {door}" + ); + } + let gate = "if ok && self.transition_edges(lane, idx) != before {"; + let arm = body + .split_once(gate) + .unwrap_or_else(|| panic!("the transition arm no longer rides the join's own edges")) + .1; + assert!( + arm.contains("mark_dirty()"), + "the transition arm is outside its gate, so a step past the cap or a \ + retyped number would dirty an unchanged project" + ); + let before = body.split_once(gate).unwrap().0; + assert!( + !before.contains("mark_dirty()"), + "the transition arm is still ahead of the comparison" + ); + assert!( + body.contains("let before = self.transition_edges(lane, idx);"), + "the join's edges are no longer read before the write" + ); + // The helper both sides call, and the pair it must compare: an anchor-only + // comparison cannot see the neighbour's `fade_in` not moving. + let helper = fn_body("transition_edges"); + assert!( + helper.contains("clips.get(idx)?.fade_out") + && helper.contains("clips.get(idx + 1)?.fade_in"), + "the edge reader no longer reads both sides of the join, so a \ + crossfade that only moves the neighbour is invisible" + ); +} + +/// The three doors the action table used to arm on their behalf. The table +/// fires *before* any door is asked, so an entry for a door that can refuse +/// dirties an untouched project -- and the dissolve is the sharpest case, +/// because the clip-menu row reaches [`Player::dissolve_selected`] directly +/// ([`crate::ui::bench_stance`]) and so was armed by nothing at all while the +/// key chord beside it armed on every press, refused or not. +/// +/// The engine half of the premise is not a scan but a run: see +/// `engine::project::tests::a_transition_door_says_yes_to_a_write_that_moved_nothing`, +/// which drives `set_transition_out` and `crossfade` and shows they answer +/// `true` for a write that changed nothing. That is why these three need a +/// before/after comparison and not just the door's own answer. +#[test] +fn the_action_table_arms_nothing_a_door_answers_for_itself() { + // The two transition doors, in the same shape as the duration row's. + for (name, door) in [ + ("crossfade_selected", "session.crossfade(lane, idx, frames)"), + ( + "dissolve_selected", + "session.set_transition_out(lane, idx, frames)", + ), + ] { + let body = fn_body(name); + assert!(body.contains(door), "{name} no longer goes through {door}"); + let gate = "if took && self.transition_edges(lane, idx) != before {"; + let arm = body + .split_once(gate) + .unwrap_or_else(|| panic!("{name} no longer arms on the write that took")) + .1; + assert!( + arm.contains("mark_dirty()"), + "{name} arms outside its gate, so a crossfade already at the room \ + the two clips offer would dirty an unchanged project" + ); + let before = body.split_once(gate).unwrap().0; + assert!( + !before.contains("mark_dirty()"), + "{name} still arms ahead of the comparison" + ); + } + // ...and the two actions are out of the table's list, or the key path is + // armed twice over and the menu path not at all. + let act = fn_body("act"); + let listed = act + .split_once("if matches!(") + .unwrap() + .1 + .split_once(") {") + .unwrap() + .0; + for gone in ["ActionId::Crossfade", "ActionId::Dissolve"] { + assert!( + !listed.contains(gone), + "{gone} is back in the pre-arm list, so the key path arms before \ + the door is asked while the clip-menu row arms by nothing" + ); + } + // The track removal, whose two callers are a key and a header button. + let body = fn_body("remove_lane"); + let arm = body + .split_once("Some(Ok(())) => {") + .expect("the track door no longer answers which arm means the track went") + .1; + assert!( + arm.contains("mark_dirty()"), + "a track that went arms nothing, so the removal is invisible to \ + autosave, the unsaved ghost and the close question" + ); + // ...and the header door no longer arms on its own before asking, which + // would be a second arm for the same step. + let lane_act = fn_body("act_lane"); + assert!( + !lane_act.contains("mark_dirty"), + "act_lane arms before remove_lane, so a track still holding clips \ + refuses with the unsaved ghost already lit" + ); + assert!( + lane_act.contains( + "ActionId::RemoveVideoLane | ActionId::RemoveAudioLane => self.remove_lane(lane, cx)" + ), + "act_lane no longer routes the header's remove to the one armed door" + ); } /// [`crate::ui::dock_stance::transition_of`]: the dock's duration row @@ -1928,9 +2123,11 @@ 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]); @@ -2387,8 +2584,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 @@ -2435,7 +2632,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::{below_picture_floor, LEDGER_H, TIME_BAND_H}; + use crate::ui::stance::{LEDGER_H, TIME_BAND_H, below_picture_floor}; let viewport_h = 1080.; for bench_h in [140., 200., 400.] { assert_eq!( diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index cdeb0f9..2a8e096 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -77,11 +77,11 @@ use crate::map::TimelineMap; use std::path::{Path, PathBuf}; use crate::color::ColorParams; -use crate::transform::TransformParams; use crate::eq::EqParams; use crate::limiter::{Limiter, db_to_linear}; use crate::scale::FitPolicy; use crate::subtitle::{Cue as SubtitleCue, SubtitleTrack}; +use crate::transform::TransformParams; /// How far down a lane's own volume goes ([`Project::set_lane_gain_db`]). /// -60 dB is a thousandth of the amplitude -- a track that is out of the mix @@ -1083,7 +1083,9 @@ impl Project { return Err(format!("color {bad} holds a value that is not a finite number").into()); } if let Some(bad) = transform.iter().position(|p| !transform_finite(p)) { - return Err(format!("transform {bad} holds a value that is not a finite number").into()); + return Err( + format!("transform {bad} holds a value that is not a finite number").into(), + ); } if lanes.is_empty() { return Err("no lanes at all: that is not a project".into()); @@ -1148,7 +1150,9 @@ impl Project { ) .into()); } - if c.transform.is_some_and(|i| usize::from(i) >= transform.len()) { + if c.transform + .is_some_and(|i| usize::from(i) >= transform.len()) + { return Err(format!( "{name} clip at {} names transform {} of {}", c.start, @@ -1483,13 +1487,13 @@ impl Project { let used: Vec = handles(&self.lanes) .into_iter() .zip(&self.lanes) - .filter_map( - |(lane, data)| match data.clips.iter().filter(|c| c.source == idx).count() { + .filter_map(|(lane, data)| { + match data.clips.iter().filter(|c| c.source == idx).count() { 0 => None, 1 => Some(format!("{} (1 clip)", lane.label())), n => Some(format!("{} ({n} clips)", lane.label())), - }, - ) + } + }) .collect(); if !used.is_empty() { return Err(format!("{name} still plays on {}", used.join(", ")).into()); @@ -1982,7 +1986,9 @@ impl Project { ..sub }; if at.checked_add(sub.frames).is_none() { - return Err(format!("a placement at frame {at} runs past the last frame there is").into()); + return Err( + format!("a placement at frame {at} runs past the last frame there is").into(), + ); } if let Some(other) = self.lanes[i] .subs @@ -2093,10 +2099,12 @@ impl Project { let at = subs.partition_point(|o| o.start < moved.start); subs.insert(at, moved); debug_assert!(subs_sorted_disjoint(subs)); - debug_assert!(members - .clips - .iter() - .all(|&(l, _)| sorted_disjoint(&self.lanes[l].clips))); + debug_assert!( + members + .clips + .iter() + .all(|&(l, _)| sorted_disjoint(&self.lanes[l].clips)) + ); return Ok(()); } let moved = SubClip { start, ..sub }; @@ -2209,7 +2217,13 @@ impl Project { // clip's trim does: one delta, each member clamped to its own room. // No source table to grow by, which only tightens how far a member may // follow -- never whether it may. - self.follow_group(&members, &(i, idx), edge, i64::from(to) - i64::from(at), &[]); + self.follow_group( + &members, + &(i, idx), + edge, + i64::from(to) - i64::from(at), + &[], + ); Ok(()) } @@ -2230,7 +2244,10 @@ impl Project { // what turns its two walls -- its own start, and its last cue -- into // frames. A rate that is not a rate leaves the window where it is. let frames_of = |us: i64| match fps.is_finite() && fps > 0.0 { - true => ((us as f64) * fps / 1e6).round().max(0.0).min(f64::from(u32::MAX)) as u32, + true => ((us as f64) * fps / 1e6) + .round() + .max(0.0) + .min(f64::from(u32::MAX)) as u32, false => 0, }; Some(match edge { @@ -2360,18 +2377,6 @@ impl Project { true } - - - - - - - - - - - - /// What the clip at `idx` of `lane` plays through, or `None` for one that /// plays flat (and for an index that is not there) -- what a feeder and an /// export ask before they build an [`crate::eq::EqState`]. @@ -2489,7 +2494,12 @@ impl Project { /// [`set_color`](Self::set_color)'s twin for [`Clip::transform`]: one undo /// step, `false` (and no history) for an index that is not there or a /// value that is not finite, and equal settings share a table entry. - pub fn set_transform(&mut self, lane: Lane, idx: usize, params: Option) -> bool { + pub fn set_transform( + &mut self, + lane: Lane, + idx: usize, + params: Option, + ) -> bool { self.write_transform(lane, idx, params, true) } @@ -2608,7 +2618,11 @@ impl Project { let map = TimelineMap::piece((s.start, s.end()), (scale(s.start), scale(s.end()))); let start = map.apply(s.start); let end = map.apply(s.end()).max(start.saturating_add(1)); - SubClip { start, frames: end - start, ..s } + SubClip { + start, + frames: end - start, + ..s + } }; for &(l, i) in &members.clips { let clips = &self.lanes[l].clips; @@ -2686,8 +2700,7 @@ impl Project { let held = self.lane(lane).get(idx).copied()?; let (held_old, new) = (held.speed.as_f64(), speed.as_f64()); for &(l, i) in members.clips.iter().chain(&members.subs) { - let (span, map) = match self - .lanes[l] + let (span, map) = match self.lanes[l] .clips .get(i) .filter(|_| members.clips.contains(&(l, i))) @@ -2700,10 +2713,7 @@ impl Project { (c.start, c.start + c.frames()), TimelineMap::piece( (c.start, c.start + c.frames()), - ( - c.start, - c.start + (c.len() as f64 / new).round() as u32, - ), + (c.start, c.start + (c.len() as f64 / new).round() as u32), ), ), // The caption's span, scaled about the held clip's head by @@ -3235,7 +3245,10 @@ impl Project { .iter() .enumerate() .map(|(i, l)| { - on.contains(&i) && l.subs.iter().any(|s| s.start < timeline_frame && timeline_frame < s.end()) + on.contains(&i) + && l.subs + .iter() + .any(|s| s.start < timeline_frame && timeline_frame < s.end()) }) .collect(); // The links the captions carry, read before the room is opened below @@ -3288,8 +3301,10 @@ impl Project { } } let fresh: Vec = (0..distinct.len()).map(|_| self.new_link()).collect(); - let right_of = - |link: Option| link.and_then(|id| distinct.iter().position(|&d| d == id)).map(|at| fresh[at]); + let right_of = |link: Option| { + link.and_then(|id| distinct.iter().position(|&d| d == id)) + .map(|at| fresh[at]) + }; for (l, data) in self.lanes.iter_mut().enumerate() { if !cut_subs[l] { continue; @@ -3299,7 +3314,11 @@ impl Project { .subs .iter() .position(|s| s.end() == timeline_frame) - .filter(|&idx| data.subs.get(idx + 1).is_some_and(|n| n.start == timeline_frame)) + .filter(|&idx| { + data.subs + .get(idx + 1) + .is_some_and(|n| n.start == timeline_frame) + }) { data.subs[idx].link = sub_orig[l]; data.subs[idx + 1].link = right_of(sub_orig[l]); @@ -3308,7 +3327,9 @@ impl Project { for (data_i, data) in self.lanes.iter_mut().enumerate() { // The lanes this call was not scoped to are not cut, whatever their // own clips would allow. - let Some(idx) = splittable(&data.clips, timeline_frame).filter(|_| cut[data_i].is_some()) else { + let Some(idx) = + splittable(&data.clips, timeline_frame).filter(|_| cut[data_i].is_some()) + else { continue; }; let mut tail = data.clips[idx]; @@ -3547,9 +3568,7 @@ impl Project { } else { "clip" }; - return Err( - format!("there is no {what} {idx} on {}", lane.label()).into() - ); + return Err(format!("there is no {what} {idx} on {}", lane.label()).into()); } } let links: Vec> = picks @@ -3573,8 +3592,16 @@ impl Project { let labels = handles(&self.lanes); let mut per_lane: std::collections::HashMap = std::collections::HashMap::new(); for (li, data) in self.lanes.iter().enumerate() { - let n = data.clips.iter().filter(|c| c.link.is_some() && links.contains(&c.link)).count() - + data.subs.iter().filter(|s| s.link.is_some() && links.contains(&s.link)).count(); + let n = data + .clips + .iter() + .filter(|c| c.link.is_some() && links.contains(&c.link)) + .count() + + data + .subs + .iter() + .filter(|s| s.link.is_some() && links.contains(&s.link)) + .count(); if n > 0 { per_lane.insert(li, n as u32); } @@ -3866,13 +3893,9 @@ impl Project { clips.insert(at, clip); } debug_assert!(sorted_disjoint(&self.lanes[dest].clips)); - debug_assert!(members - .clips - .iter() - .chain(&members.subs) - .all(|&(l, _)| { - sorted_disjoint(&self.lanes[l].clips) && subs_sorted_disjoint(&self.lanes[l].subs) - })); + debug_assert!(members.clips.iter().chain(&members.subs).all(|&(l, _)| { + sorted_disjoint(&self.lanes[l].clips) && subs_sorted_disjoint(&self.lanes[l].subs) + })); true } @@ -4048,7 +4071,13 @@ impl Project { Edge::End => c.out_frame = c.in_frame + keep, } debug_assert!(sorted_disjoint(&self.lanes[held].clips)); - self.follow_group(&members, &(held, idx), edge, i64::from(to) - i64::from(at), source_frames); + self.follow_group( + &members, + &(held, idx), + edge, + i64::from(to) - i64::from(at), + source_frames, + ); true } @@ -4144,13 +4173,7 @@ impl Project { /// [`trim_room`](Project::trim_room) for a clip the caller already holds by /// its lane's storage index: the one wall computation, asked for the clip /// itself and for each member a group trim carries. - fn clip_room( - &self, - l: usize, - i: usize, - edge: Edge, - source_frames: &[u32], - ) -> (u32, u32) { + fn clip_room(&self, l: usize, i: usize, edge: Edge, source_frames: &[u32]) -> (u32, u32) { let clips = &self.lanes[l].clips; let c = clips[i]; let (lo, hi) = match edge { @@ -4606,13 +4629,11 @@ impl Project { let mut report = GapSweep::default(); let mut snapshot = false; for (start, frames) in gaps(self.lane(lane)).into_iter().rev() { - match self - .gap_take_scope(lane, start, frames) - .and_then(|scope| { - let on = self.scoped(&scope)?; - self.scope_holds_takes_whole(&on, start)?; - Ok(on) - }) { + match self.gap_take_scope(lane, start, frames).and_then(|scope| { + let on = self.scoped(&scope)?; + self.scope_holds_takes_whole(&on, start)?; + Ok(on) + }) { Ok(on) => { if !snapshot { self.snapshot(); @@ -5085,7 +5106,10 @@ impl Project { pub(crate) fn parts(&self) -> SweepParts { SweepParts( self.sources.len(), - self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(), + self.lanes + .iter() + .map(|l| (l.kind, l.clips.clone())) + .collect(), self.lanes.iter().map(|l| l.subs.clone()).collect(), self.subtitles.clone(), self.settings.clone(), @@ -5373,7 +5397,6 @@ impl Project { self.next_link = self.next_link.saturating_add(1); id } - } /// The handle of every lane, in storage order -- the one definition of what @@ -5451,7 +5474,9 @@ impl GapPlacement for SubClip { /// Index of the placement covering `frame`, or `None` for a gap or past the /// end. Binary search: the sorted-disjoint invariant is what makes it legal. fn at(items: &[T], frame: u32) -> Option { - let idx = items.partition_point(|item| item.start_frame() <= frame).checked_sub(1)?; + let idx = items + .partition_point(|item| item.start_frame() <= frame) + .checked_sub(1)?; (frame < items[idx].end_frame()).then_some(idx) } @@ -5667,10 +5692,7 @@ fn sub_joinable(subs: &[SubClip], frame: u32) -> Option { fn sub_edge_room(subs: &[SubClip], idx: usize, edge: Edge) -> (u32, u32) { let s = &subs[idx]; match edge { - Edge::Start => ( - idx.checked_sub(1).map_or(0, |p| subs[p].end()), - s.end() - 1, - ), + Edge::Start => (idx.checked_sub(1).map_or(0, |p| subs[p].end()), s.end() - 1), Edge::End => (s.start + 1, subs.get(idx + 1).map_or(u32::MAX, |n| n.start)), } } @@ -5737,11 +5759,9 @@ fn links_are_consistent(lanes: &[LaneData]) -> crate::Result<()> { for (i, s) in data.subs.iter().enumerate() { let Some(id) = s.link else { continue }; if data.subs[..i].iter().any(|prev| prev.link == Some(id)) { - return Err(format!( - "link {id} names two captions in the {} lane", - lane.label() - ) - .into()); + return Err( + format!("link {id} names two captions in the {} lane", lane.label()).into(), + ); } } } @@ -6090,7 +6110,11 @@ mod tests { (f.gain_at(5) - midpoint.sin()).abs() < 1e-6, "equal-power midpoint is sin(pi/4)" ); - assert_eq!(f.gain_at(20), 1.0, "unchanged in the body, past either ramp"); + assert_eq!( + f.gain_at(20), + 1.0, + "unchanged in the body, past either ramp" + ); // The fade-out is the same curve, mirrored, counting down from the // clip's end: unity at the frame the ramp starts, the same // equal-power midpoint, and -- since `total` itself is one past the @@ -6114,14 +6138,8 @@ mod tests { fn crossfade_only_joins_adjacent_audio_clips() { let mut p = Project::single(FILE, 20); assert!(p.split(10)); - assert!( - !p.crossfade(Lane::V1, 0, 5), - "video is not an audio lane" - ); - assert!( - !p.crossfade(Lane::A1, 1, 5), - "there is no clip after idx 1" - ); + assert!(!p.crossfade(Lane::V1, 0, 5), "video is not an audio lane"); + assert!(!p.crossfade(Lane::A1, 1, 5), "there is no clip after idx 1"); assert!(p.crossfade(Lane::A1, 0, 5), "the two halves are adjacent"); let a = p.lane(Lane::A1); assert_eq!(a[0].fade_out, 5); @@ -6148,10 +6166,16 @@ mod tests { assert!(p.set_fade_out(Lane::V1, 0, 15)); assert!(p.split(5)); let v = p.lane(Lane::V1); - assert_eq!(v[0].fade_in, 5, "the left half's kept fade-in, clamped to 5 frames"); + assert_eq!( + v[0].fade_in, 5, + "the left half's kept fade-in, clamped to 5 frames" + ); assert_eq!(v[0].fade_out, 0, "the cut edge it made starts flat"); assert_eq!(v[1].fade_in, 0, "the cut edge it made starts flat"); - assert_eq!(v[1].fade_out, 15, "the right half's kept fade-out, unclamped: 15 frames fit in 15"); + assert_eq!( + v[1].fade_out, 15, + "the right half's kept fade-out, unclamped: 15 frames fit in 15" + ); } /// [`Project::set_transition_out`] refuses a non-video lane, a clip with @@ -6187,6 +6211,55 @@ mod tests { assert!(!p2.set_transition_out(v2, 0, 5), "a gap is not adjacent"); } + /// The two transition doors' bool is the WEAK shape, stated here as + /// behaviour rather than left as something a front-end has to know: both + /// answer "these two clips are adjacent", and both snapshot and clamp -- + /// so a write that lands the value the join already carries is still + /// reported as a write, and still spends an undo step. This is the fact + /// `Player::transition_edges`'s before/after comparison exists to cover, + /// and the fact a UI test can only reach through a source scan: driving + /// the front-end needs a window this crate has no harness for, so the + /// door's own answer is pinned here, where it can be run. + #[test] + fn a_transition_door_says_yes_to_a_write_that_moved_nothing() { + let mut p = Project::single(FILE, 20); + assert!(p.split(10), "two halves to join"); + assert!(p.set_transition_out(Lane::V1, 0, 5), "the dissolve lands"); + assert!(p.crossfade(Lane::A1, 0, 5), "the crossfade lands"); + let history = p.history.len(); + + // The very same numbers again: nothing moved, and both doors report a + // write anyway. + assert!( + p.set_transition_out(Lane::V1, 0, 5), + "set_transition_out answers 'the clips are adjacent', not 'the \ + dissolve moved', so a no-op reads as a write" + ); + assert!( + p.crossfade(Lane::A1, 0, 5), + "crossfade answers the same way for the same reason" + ); + assert_eq!( + p.history.len(), + history + 2, + "and each spent an undo step saying so, which is why the \ + front-end compares the join's own edges before it arms" + ); + + // What did not move -- the comparison the front-end makes: both edges + // a crossfade writes, and the dissolve itself. + let a = p.lane(Lane::A1); + assert_eq!((a[0].fade_out, a[1].fade_in), (5, 5), "unchanged"); + assert_eq!(p.transition_out_of(Lane::V1, 0), 5, "unchanged"); + + // And a refusal still answers no, so the arm is not simply always on: + // the last clip has no successor to dissolve into. + assert!( + !p.set_transition_out(Lane::V1, 1, 5), + "no neighbour end to end" + ); + } + /// The rule [`Project::write_split`] follows for [`Clip::transition_out`], /// same shape as [`a_split_clamps_the_kept_fade_and_zeroes_the_cut_edge`]: /// only the half that kept the clip's original *end* keeps the dissolve, @@ -6203,7 +6276,10 @@ mod tests { p.lane_mut(Lane::V1).unwrap()[0].transition_out = 15; assert!(p.split(5)); let v = p.lane(Lane::V1); - assert_eq!(v[0].transition_out, 0, "the cut edge it made has no successor"); + assert_eq!( + v[0].transition_out, 0, + "the cut edge it made has no successor" + ); assert_eq!( v[1].transition_out, 15, "the tail's kept dissolve, unclamped: 15 frames fit in 15" @@ -6451,11 +6527,7 @@ mod tests { p.group_all(&[(Lane::V1, 0), (v2, 0)]) .expect("the clips group"); let minted = p.lane(Lane::V1)[0].link.expect("grouped"); - assert_ne!( - minted, - 1, - "the caption's id is not re-issued to clips" - ); + assert_ne!(minted, 1, "the caption's id is not re-issued to clips"); assert_eq!( p.sub_lane(Lane::new(LaneKind::Subtitle, 0))[0].link, Some(1), @@ -6501,8 +6573,16 @@ mod tests { .expect("room for it"); assert_eq!(p.lane(Lane::V1)[0].frames(), 45); let s = p.sub_lane(s1)[0]; - assert_eq!((s.start, s.frames), (0, 45), "same words, half the timeline"); - assert_eq!((s.in_us, s.out_us), (0, 90_000_000), "the window is untouched"); + assert_eq!( + (s.start, s.frames), + (0, 45), + "same words, half the timeline" + ); + assert_eq!( + (s.in_us, s.out_us), + (0, 90_000_000), + "the window is untouched" + ); assert!(links_are_consistent(&p.lanes).is_ok()); assert!(p.undo()); assert_eq!(p.sub_lane(s1)[0].frames, 90, "one undo puts it back"); @@ -6518,8 +6598,16 @@ mod tests { .expect("room for it"); assert_eq!(p.lane(Lane::V1)[0].frames(), 180); let s = p.sub_lane(s1)[0]; - assert_eq!((s.start, s.frames), (60, 120), "the offset doubles with the clip"); - assert_eq!(s.end(), p.lane(Lane::V1)[0].end(), "still ends with the clip"); + assert_eq!( + (s.start, s.frames), + (60, 120), + "the offset doubles with the clip" + ); + assert_eq!( + s.end(), + p.lane(Lane::V1)[0].end(), + "still ends with the clip" + ); // A stretch that runs the caption into its neighbour is refused, by // lane and frame, and costs no undo step. @@ -6534,7 +6622,9 @@ mod tests { .unwrap_err() .to_string(); assert!( - err.contains("the S1 caption at frame 0 would run to frame 180 and the next starts at 95"), + err.contains( + "the S1 caption at frame 0 would run to frame 180 and the next starts at 95" + ), "{err}" ); assert_eq!(p.history.len(), history, "a refusal costs no undo step"); @@ -6669,7 +6759,8 @@ mod tests { // An odd-length caption straddling the clip's tail edge: its // own last frame lands past the held clip. let c_start = len.saturating_sub(3); - p.place_sub(s1, c_start, caption(c_start, 7)).expect("placed"); + p.place_sub(s1, c_start, caption(c_start, 7)) + .expect("placed"); p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped"); let speed = Speed::from_permille(permille); let last = c_start + 7 - 1; @@ -6804,8 +6895,7 @@ mod tests { refused: None, }; // A timeline of words alone: 60 frames of caption, no media clips. - let mut p = Project::single(FILE, 60) - .with_subtitles(vec![track()]); + let mut p = Project::single(FILE, 60).with_subtitles(vec![track()]); for l in [Lane::V1, Lane::A1] { while !p.lane(l).is_empty() { p.lift(l, 0); @@ -6871,16 +6961,31 @@ mod tests { .expect("the region speeds up"); // Adjacent one-frame cues: both map to frame 5, and are forced apart. let spans = |p: &Project, lane: Lane| -> Vec<(u32, u32)> { - p.sub_lane(lane).iter().map(|s| (s.start, s.frames)).collect() + p.sub_lane(lane) + .iter() + .map(|s| (s.start, s.frames)) + .collect() }; - assert_eq!(spans(&p, lanes[0]), [(5, 1), (6, 1)], "one frame each, in order"); + assert_eq!( + spans(&p, lanes[0]), + [(5, 1), (6, 1)], + "one frame each, in order" + ); // The three-frame pair: [5, 8) and [8, 11) map to [3, 5) and [4, 6), // and the walk pushes the second to where the first ends. - assert_eq!(spans(&p, lanes[1]), [(3, 1), (4, 2)], "forced apart, kept in order"); + assert_eq!( + spans(&p, lanes[1]), + [(3, 1), (4, 2)], + "forced apart, kept in order" + ); // The last cue of the region ends exactly where the region now does // (frame 15), and the caption behind it lands on that same frame: // touching, never overlapping. - assert_eq!(spans(&p, lanes[2]), [(14, 1), (15, 15)], "the cue ends with the region"); + assert_eq!( + spans(&p, lanes[2]), + [(14, 1), (15, 15)], + "the cue ends with the region" + ); for &lane in &lanes { assert!(subs_sorted_disjoint(&p.lanes[p.index(lane).unwrap()].subs)); } @@ -6968,17 +7073,24 @@ mod tests { // Too few, one lane twice, and an index that is not there: words, no // snapshot. let history = p.history.len(); - assert!(p.group_all(&[]).unwrap_err().to_string().contains("two placements or more")); - assert!(p - .group_all(&[(Lane::V1, 0), (Lane::V1, 0)]) - .unwrap_err() - .to_string() - .contains("V1 is picked twice")); - assert!(p - .group_all(&[(Lane::V1, 0), (s1, 9)]) - .unwrap_err() - .to_string() - .contains("no subtitle 9")); + assert!( + p.group_all(&[]) + .unwrap_err() + .to_string() + .contains("two placements or more") + ); + assert!( + p.group_all(&[(Lane::V1, 0), (Lane::V1, 0)]) + .unwrap_err() + .to_string() + .contains("V1 is picked twice") + ); + assert!( + p.group_all(&[(Lane::V1, 0), (s1, 9)]) + .unwrap_err() + .to_string() + .contains("no subtitle 9") + ); assert_eq!(p.history.len(), history, "refusals cost no undo step"); // The group: the picture, the layer, and the caption -- and the sound @@ -6987,7 +7099,12 @@ mod tests { .expect("three picks, three lanes"); let id = p.lane(Lane::V1)[0].link.expect("grouped"); for lane in [Lane::V1, Lane::A1, v2] { - assert_eq!(p.lane(lane)[0].link, Some(id), "{} rides along", lane.label()); + assert_eq!( + p.lane(lane)[0].link, + Some(id), + "{} rides along", + lane.label() + ); } assert_eq!(p.sub_lane(s1)[0].link, Some(id), "the caption is a member"); assert_eq!(p.sub_lane(s1)[0].frames, 6, "its own span, kept"); @@ -7053,7 +7170,11 @@ mod tests { .to_string(); assert!(err.contains("one placement per lane"), "{err}"); assert_eq!(p.history.len(), history, "the refusal costs no undo step"); - assert_eq!(p.lane(Lane::V1)[0].link, v1_link, "the first group untouched"); + assert_eq!( + p.lane(Lane::V1)[0].link, + v1_link, + "the first group untouched" + ); assert_eq!(p.lane(v2)[0].link, v2_link, "the second group untouched"); assert!(links_are_consistent(&p.lanes).is_ok()); } @@ -7138,8 +7259,15 @@ mod tests { // By the picture or by the caption, the same whole-group delete. assert!(p.delete_sub_in(s1, 0)); assert!(p.lane(Lane::V1).is_empty(), "the take's span left V1"); - assert!(p.sub_lane(s1).is_empty(), "the caption's span left its lane"); - assert_eq!(p.lane(v2)[0].start, 10, "a lane the group does not touch stays"); + assert!( + p.sub_lane(s1).is_empty(), + "the caption's span left its lane" + ); + assert_eq!( + p.lane(v2)[0].start, + 10, + "a lane the group does not touch stays" + ); assert!(links_are_consistent(&p.lanes).is_ok()); assert!(p.undo(), "one step puts the group back"); assert_eq!(p.sub_lane(s1)[0].start, 2, "offsets and all"); @@ -7175,8 +7303,10 @@ mod tests { let group = || { let mut p = Project::single(FILE, 90).with_subtitles(vec![track()]); let s1 = p.add_lane(LaneKind::Subtitle); - p.place_sub(s1, 30, caption(30, 30)).expect("the group's caption"); - p.place_sub(s1, 90, caption(90, 30)).expect("the caption behind"); + p.place_sub(s1, 30, caption(30, 30)) + .expect("the group's caption"); + p.place_sub(s1, 90, caption(90, 30)) + .expect("the caption behind"); p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped"); (p, s1) }; @@ -7192,7 +7322,11 @@ mod tests { "the caption's lane closed by its own span: the follower slid up" ); assert!(p.undo(), "one step"); - assert_eq!(p.sub_lane(s1).len(), 2, "both captions back, offsets and all"); + assert_eq!( + p.sub_lane(s1).len(), + 2, + "both captions back, offsets and all" + ); // By the sound: the same whole-group delete. let (mut p, s1) = group(); @@ -7204,7 +7338,11 @@ mod tests { let (mut p, s1) = group(); assert!(p.delete_sub_in(s1, 0)); assert!(p.lane(Lane::V1).is_empty() && p.lane(Lane::A1).is_empty()); - assert_eq!(p.sub_lane(s1)[0].start, 60, "closed from the caption's own door"); + assert_eq!( + p.sub_lane(s1)[0].start, + 60, + "closed from the caption's own door" + ); assert!(links_are_consistent(&p.lanes).is_ok()); // A caption lifted ALONE still leaves its gap: the ungrouped law, @@ -7213,7 +7351,8 @@ mod tests { assert!(p.ungroup(s1, 0), "the caption stands alone"); assert!(p.lift_sub(s1, 0)); assert_eq!( - p.sub_lane(s1)[0].start, 90, + p.sub_lane(s1)[0].start, + 90, "the follower stayed put: a lone caption's lift is a gap" ); } @@ -7248,7 +7387,11 @@ mod tests { // Same lane, further along: everyone moves by the same eight frames. p.move_sub(s1, 0, s1, 10).expect("room for all of it"); assert_eq!(p.sub_lane(s1)[0].start, 10); - assert_eq!(p.lane(Lane::V1)[0].start, 8, "the clip follows by the delta"); + assert_eq!( + p.lane(Lane::V1)[0].start, + 8, + "the clip follows by the delta" + ); assert!(links_are_consistent(&p.lanes).is_ok()); // ...and an ungrouped caption is the caption it always was. @@ -7257,11 +7400,12 @@ mod tests { let s1 = q.add_lane(LaneKind::Subtitle); q.place_sub(s1, 0, caption(0, 4)).expect("placed"); q.place_sub(s1, 5, caption(5, 4)).expect("placed"); - assert!(q - .move_sub(s1, 0, s1, 3) - .unwrap_err() - .to_string() - .contains("already covers")); + assert!( + q.move_sub(s1, 0, s1, 3) + .unwrap_err() + .to_string() + .contains("already covers") + ); } /// A trim carries a group's caption by the same delta as its clips, clamped @@ -7478,8 +7622,14 @@ mod tests { // The clipboard's clamp lives in `PlaybackSession::paste_at`. assert!(p.paste(1_000, PASTED)); assert_eq!(p.timeline_frames(), 1_002); - assert_eq!(p.lane(Lane::V1).last().expect("the pasted clip").start, 1_000); - assert_eq!(p.lane(Lane::A1).last().expect("its other half").start, 1_000); + assert_eq!( + p.lane(Lane::V1).last().expect("the pasted clip").start, + 1_000 + ); + assert_eq!( + p.lane(Lane::A1).last().expect("its other half").start, + 1_000 + ); // An empty clip is the one thing refused, and it pushes no history. let mut p = three(); @@ -7681,7 +7831,8 @@ mod tests { assert!(p.lift(Lane::V1, 0)); let (sources, lanes, eq, color, _transform) = p.without_orphan_sources(); assert_eq!(sources.len(), 1, "source 0 survives an emptied timeline"); - let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("an empty project loads"); + let back = Project::from_parts(sources, lanes, eq, color, Vec::new()) + .expect("an empty project loads"); assert_eq!(back.timeline_frames(), 0); assert_eq!(back.lanes().len(), 2, "and it kept its lanes"); } @@ -7789,7 +7940,10 @@ mod tests { assert!(p.lane(v2).is_empty()); // Refusals cost nothing: sound placed alone is `place`'s door. - assert!(!p.place_take(Lane::A1, 0, clip(0, 100, 102, 0)), "audio lane"); + assert!( + !p.place_take(Lane::A1, 0, clip(0, 100, 102, 0)), + "audio lane" + ); assert!(!p.place_take(v2, 0, clip(0, 7, 7, 0)), "empty clip"); assert!( !p.place_take(Lane::new(LaneKind::Video, 9), 0, clip(0, 1, 2, 0)), @@ -7855,7 +8009,8 @@ mod tests { (LaneKind::Video, vec![clip(0, 0, 3, 0), clip(10, 3, 6, 0)]), (LaneKind::Audio, vec![clip(0, 0, 3, 0)]), ]; - let mut p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts"); + let mut p = + Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts"); let before = shape(&p); // Into the gap, exactly where it was let go -- nothing else moves. @@ -8167,7 +8322,10 @@ mod tests { assert_eq!(p.gap_at(v, 8), None); assert_eq!(p.gap_at(v, 100), None); - assert!(p.place(v, 12, clip(12, 0, 2, 0)), "a second clip at [12,14)"); + assert!( + p.place(v, 12, clip(12, 0, 2, 0)), + "a second clip at [12,14)" + ); // Between the two: the gap [8,12). assert_eq!(p.gap_at(v, 8), Some((8, 4))); assert_eq!(p.gap_at(v, 11), Some((8, 4))); @@ -8177,7 +8335,11 @@ mod tests { p.place(v, 8, clip(8, 0, 4, 0)), "fills [8,12) exactly, meeting both neighbours" ); - assert_eq!(p.gap_at(v, 8), None, "adjacent clips leave no frame to name a gap"); + assert_eq!( + p.gap_at(v, 8), + None, + "adjacent clips leave no frame to name a gap" + ); assert_eq!(p.gap_at(v, 11), None); } @@ -8200,7 +8362,11 @@ mod tests { assert_eq!((start, len), (0, 5)); assert!(p.cut_regions(&[(start, len)], &[v]).is_ok()); assert_eq!(p.lane(v)[0].start, 0, "the clip slid back to close the gap"); - assert_eq!(p.lane(a)[0].start, 0, "the untouched lane's clip did not move"); + assert_eq!( + p.lane(a)[0].start, + 0, + "the untouched lane's clip did not move" + ); assert!(p.undo(), "one press undoes the whole close"); assert_eq!(shape(&p), before, "back to exactly where it was"); } @@ -8238,11 +8404,21 @@ mod tests { let sources = vec![Source::new(FILE, 0)]; let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; let audio = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; - let mut p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) - .expect("valid parts"); + let mut p = Project::from_parts( + sources, + two(video, audio), + Vec::new(), + Vec::new(), + Vec::new(), + ) + .expect("valid parts"); let before = shape(&p); assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); - assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 2)), "the same stretch is empty on A1 too"); + assert_eq!( + p.gap_at(Lane::A1, 3), + Some((3, 2)), + "the same stretch is empty on A1 too" + ); let scope = p .gap_take_scope(Lane::V1, 3, 2) @@ -8252,7 +8428,11 @@ mod tests { assert!(p.cut_regions(&[(3, 2)], &scope).is_ok()); assert_eq!(p.lane(Lane::V1)[1].start, 3, "V1's far half slid back"); - assert_eq!(p.lane(Lane::A1)[1].start, 3, "A1's far half rode along, in sync"); + assert_eq!( + p.lane(Lane::A1)[1].start, + 3, + "A1's far half rode along, in sync" + ); assert!(p.undo(), "one press undoes the whole close"); assert_eq!(shape(&p), before, "back to exactly where it was"); } @@ -8270,8 +8450,14 @@ mod tests { // shorter than V1's [3,5) -- a legal offset-preserving group, and // still one take. let audio = vec![linked(0, 0, 3, 1), linked(4, 5, 9, 3)]; - let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) - .expect("valid parts"); + let p = Project::from_parts( + sources, + two(video, audio), + Vec::new(), + Vec::new(), + Vec::new(), + ) + .expect("valid parts"); assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 1)), "a shorter gap on A1"); @@ -8293,10 +8479,20 @@ mod tests { // A1 plays through the whole span as one continuous clip, sharing // V1's first-half link: nothing empty at frame 3 there at all. let audio = vec![linked(0, 0, 9, 1)]; - let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) - .expect("valid parts"); + let p = Project::from_parts( + sources, + two(video, audio), + Vec::new(), + Vec::new(), + Vec::new(), + ) + .expect("valid parts"); assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); - assert_eq!(p.gap_at(Lane::A1, 3), None, "A1 plays through, no gap there"); + assert_eq!( + p.gap_at(Lane::A1, 3), + None, + "A1 plays through, no gap there" + ); let err = p .gap_take_scope(Lane::V1, 3, 2) @@ -8306,7 +8502,6 @@ mod tests { assert!(err.contains("detach"), "{err}"); } - /// The sweep is the single-gap close repeated on one lane, but measured once /// and applied from the right. The differing gap lengths here expose a /// front-to-back bug: the last clip would be cut against a stale frame after @@ -8342,14 +8537,20 @@ mod tests { let v = p.add_lane(LaneKind::Video); let history = p.history.len(); let report = p.close_all_gaps_on_lane(v).expect("empty lane exists"); - assert_eq!(report, GapSweep::default(), "an empty lane has no bounded gap"); + assert_eq!( + report, + GapSweep::default(), + "an empty lane has no bounded gap" + ); assert_eq!(p.history.len(), history, "no undo step for a no-op"); let mut p = Project::single(FILE, 9); let v = p.add_lane(LaneKind::Video); assert!(p.place(v, 5, clip(5, 0, 3, 0))); let before = shape(&p); - let report = p.close_all_gaps_on_lane(v).expect("single clip lane exists"); + let report = p + .close_all_gaps_on_lane(v) + .expect("single clip lane exists"); assert_eq!(report.closed, 1, "the head gap closes"); assert_eq!(p.lane(v), &[clip(0, 0, 3, 0)]); assert!(p.undo()); @@ -8366,7 +8567,11 @@ mod tests { assert!(p.place(v, 0, clip(0, 0, 3, 0))); let history = p.history.len(); let report = p.close_all_gaps_on_lane(v).expect("tail-only lane exists"); - assert_eq!(report, GapSweep::default(), "the open-ended tail is not closed"); + assert_eq!( + report, + GapSweep::default(), + "the open-ended tail is not closed" + ); assert_eq!(p.lane(v), &[clip(0, 0, 3, 0)]); assert_eq!(p.history.len(), history); } @@ -8377,19 +8582,16 @@ mod tests { #[test] fn close_all_gaps_on_one_lane_partially_closes_linked_takes_and_reports_skips() { let sources = vec![Source::new(FILE, 0)]; - let video = vec![ - linked(0, 0, 2, 1), - linked(4, 4, 6, 2), - clip(9, 9, 11, 0), - ]; - let audio = vec![ - linked(0, 0, 2, 1), - linked(4, 4, 6, 2), - clip(8, 8, 11, 0), - ]; - let mut p = - Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) - .expect("valid parts"); + let video = vec![linked(0, 0, 2, 1), linked(4, 4, 6, 2), clip(9, 9, 11, 0)]; + let audio = vec![linked(0, 0, 2, 1), linked(4, 4, 6, 2), clip(8, 8, 11, 0)]; + let mut p = Project::from_parts( + sources, + two(video, audio), + Vec::new(), + Vec::new(), + Vec::new(), + ) + .expect("valid parts"); let before = shape(&p); let report = p.close_all_gaps_on_lane(Lane::V1).expect("V1 exists"); @@ -8397,12 +8599,27 @@ mod tests { assert_eq!(report.skipped.len(), 1); assert_eq!(report.skipped[0].start, 6); assert!(report.skipped[0].reason.contains("A1"), "{report:?}"); - assert!(report.skipped[0].reason.contains("out of sync"), "{report:?}"); + assert!( + report.skipped[0].reason.contains("out of sync"), + "{report:?}" + ); assert_eq!(p.lane(Lane::V1)[1].start, 2, "the matched take moved"); - assert_eq!(p.lane(Lane::A1)[1].start, 2, "and its other half stayed in sync"); - assert_eq!(p.lane(Lane::V1)[2].start, 7, "the skipped later gap remains"); - assert_eq!(p.lane(Lane::A1)[2].start, 6, "A1's shorter gap remains shorter"); + assert_eq!( + p.lane(Lane::A1)[1].start, + 2, + "and its other half stayed in sync" + ); + assert_eq!( + p.lane(Lane::V1)[2].start, + 7, + "the skipped later gap remains" + ); + assert_eq!( + p.lane(Lane::A1)[2].start, + 6, + "A1's shorter gap remains shorter" + ); links_are_consistent(&p.lanes).expect("every linked take that moved stayed whole"); assert!(p.undo(), "one undo restores every closed gap"); assert_eq!(shape(&p), before); @@ -8415,18 +8632,28 @@ mod tests { fn gap_at_finds_the_hole_a_caption_frame_sits_in() { let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]); let s = p.add_lane(LaneKind::Subtitle); - assert_eq!(p.gap_at(s, 0), None, "an empty subtitle lane has nothing to close"); + assert_eq!( + p.gap_at(s, 0), + None, + "an empty subtitle lane has nothing to close" + ); - p.place_sub(s, 5, caption(0, 3)).expect("single cue at [5,8)"); + p.place_sub(s, 5, caption(0, 3)) + .expect("single cue at [5,8)"); assert_eq!(p.gap_at(s, 0), Some((0, 5)), "head gap before first cue"); assert_eq!(p.gap_at(s, 4), Some((0, 5))); assert_eq!(p.gap_at(s, 5), None, "inside the cue"); assert_eq!(p.gap_at(s, 8), None, "tail after a single cue is not a gap"); - p.place_sub(s, 12, caption(0, 2)).expect("second cue at [12,14)"); + p.place_sub(s, 12, caption(0, 2)) + .expect("second cue at [12,14)"); assert_eq!(p.gap_at(s, 8), Some((8, 4)), "gap between cues"); assert_eq!(p.gap_at(s, 11), Some((8, 4))); - assert_eq!(p.gap_at(s, 14), None, "tail after the last cue is still open-ended"); + assert_eq!( + p.gap_at(s, 14), + None, + "tail after the last cue is still open-ended" + ); } /// Closing a caption gap ripples the subtitle lane only. It is not a media @@ -8435,13 +8662,15 @@ mod tests { fn closing_a_caption_gap_ripples_no_video_or_audio_clips() { let mut p = Project::single(FILE, 20).with_subtitles(vec![subtitle_track()]); let s = p.add_lane(LaneKind::Subtitle); - p.place_sub(s, 5, caption(0, 3)).expect("single cue at [5,8)"); + p.place_sub(s, 5, caption(0, 3)) + .expect("single cue at [5,8)"); let before_clips = shape(&p); let before_subs = p.sub_lane(s).to_vec(); let (start, len) = p.gap_at(s, 0).expect("gap before the caption"); assert_eq!((start, len), (0, 5)); - p.cut_regions(&[(start, len)], &[s]).expect("caption lane gap closes"); + p.cut_regions(&[(start, len)], &[s]) + .expect("caption lane gap closes"); assert_eq!(shape(&p), before_clips, "media lanes did not move"); assert_eq!(p.sub_lane(s), &[caption(0, 3)], "caption slid left"); @@ -8458,13 +8687,20 @@ mod tests { let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]); let s = p.add_lane(LaneKind::Subtitle); let history = p.history.len(); - let report = p.close_all_gaps_on_lane(s).expect("empty subtitle lane exists"); - assert_eq!(report, GapSweep::default(), "empty subtitle lane has no bounded gap"); + let report = p + .close_all_gaps_on_lane(s) + .expect("empty subtitle lane exists"); + assert_eq!( + report, + GapSweep::default(), + "empty subtitle lane has no bounded gap" + ); assert_eq!(p.history.len(), history, "empty sweep is not an undo step"); p.place_sub(s, 2, caption(0, 2)).expect("head gap [0,2)"); p.place_sub(s, 7, caption(0, 2)).expect("middle gap [4,7)"); - p.place_sub(s, 14, caption(0, 1)).expect("middle gap [9,14), tail after 15"); + p.place_sub(s, 14, caption(0, 1)) + .expect("middle gap [9,14), tail after 15"); let before = p.sub_lane(s).to_vec(); assert_eq!(p.gap_count(s), 3); @@ -8481,7 +8717,8 @@ mod tests { let mut p = Project::single(FILE, 30).with_subtitles(vec![subtitle_track()]); let s = p.add_lane(LaneKind::Subtitle); - p.place_sub(s, 0, caption(0, 3)).expect("contiguous at the head"); + p.place_sub(s, 0, caption(0, 3)) + .expect("contiguous at the head"); let history = p.history.len(); let report = p.close_all_gaps_on_lane(s).expect("subtitle lane exists"); assert_eq!(report, GapSweep::default(), "the open tail is not closed"); @@ -8789,7 +9026,8 @@ mod tests { [0, 1] ); // ...and what comes out is loadable, with the same timeline. - let reloaded = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("from_parts"); + let reloaded = + Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("from_parts"); assert_eq!(reloaded.timeline_frames(), p.timeline_frames()); assert_eq!(reloaded.sources().len(), 2); } @@ -9279,8 +9517,14 @@ mod tests { fn from_parts_has_no_history_and_checks_the_invariants() { let (sources, lanes, eq, color, _transform) = three().without_orphan_sources(); let (video, audio) = (lanes[0].1.clone(), lanes[1].1.clone()); - let mut p = Project::from_parts(sources.clone(), lanes.clone(), eq.clone(), color.clone(), Vec::new()) - .expect("valid parts"); + let mut p = Project::from_parts( + sources.clone(), + lanes.clone(), + eq.clone(), + color.clone(), + Vec::new(), + ) + .expect("valid parts"); assert_eq!(p.clips(), three().clips()); assert!(!p.undo(), "a loaded project has nothing to undo"); assert!(p.split(4), "...and is editable from there"); @@ -9308,7 +9552,16 @@ mod tests { ) .is_ok() ); - assert!(Project::from_parts(sources.clone(), Vec::new(), Vec::new(), Vec::new(), Vec::new()).is_err()); + assert!( + Project::from_parts( + sources.clone(), + Vec::new(), + Vec::new(), + Vec::new(), + Vec::new() + ) + .is_err() + ); let bad: [Vec; 5] = [ vec![clip(0, 0, 3, 1)], // source that is not there vec![clip(0, 3, 3, 0)], // empty clip @@ -9449,7 +9702,8 @@ mod tests { assert_eq!(loaded.color_of(Lane::V1, 0), Some(&grade_at(1))); // Group ids survive a load, and the next split gets a fresh one. - let mut p = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("valid parts"); + let mut p = + Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("valid parts"); assert!(p.split(4)); assert!(p.clips().iter().all(|c| c.link.is_some())); } @@ -9487,9 +9741,15 @@ mod tests { // The door: a doubled id inside one lane, refused by name. let err = |video: Vec, audio: Vec| { - Project::from_parts(sources.clone(), two(video, audio), Vec::new(), Vec::new(), Vec::new()) - .expect_err("refused") - .to_string() + Project::from_parts( + sources.clone(), + two(video, audio), + Vec::new(), + Vec::new(), + Vec::new(), + ) + .expect_err("refused") + .to_string() }; assert!( err(vec![linked(0, 0, 3, 7), linked(3, 3, 5, 7)], Vec::new()) @@ -10197,7 +10457,8 @@ mod tests { lanes.iter().map(|(k, _)| *k).collect::>(), [LaneKind::Video, LaneKind::Video, LaneKind::Audio] ); - let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("three lanes load"); + let back = + Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("three lanes load"); assert_eq!(back.lanes(), p.lanes()); assert_eq!(shape(&back), shape(&p), "the same lane is still on top"); @@ -10215,7 +10476,10 @@ mod tests { let mut p = Project::single(FILE, 9); let take = p.clips()[0].link.expect("a fresh project is one take"); let v2 = p.add_lane(LaneKind::Video); - assert!(p.place(v2, 0, clip(0, 0, 9, 0)), "a placement joins no group"); + assert!( + p.place(v2, 0, clip(0, 0, 9, 0)), + "a placement joins no group" + ); assert!(p.split(4)); let side = |p: &Project, i: usize| -> Vec> { p.lanes().into_iter().map(|l| p.lane(l)[i].link).collect() @@ -10345,7 +10609,8 @@ mod tests { assert_eq!(lanes[2].1, p.lane(v2), "V2's clips are written"); assert!(lanes[3].1.is_empty(), "and the empty A2 is still a lane"); // ...and all four load again as the same four. - let back = Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("four lanes load"); + let back = + Project::from_parts(sources, lanes, eq, color, Vec::new()).expect("four lanes load"); assert_eq!(back.lanes(), p.lanes()); assert_eq!(back.lane(a2), p.lane(a2)); @@ -10438,7 +10703,8 @@ mod tests { (LaneKind::Video, vec![clip(10, 5, 15, 1)]), (LaneKind::Audio, vec![clip(0, 0, 30, 0)]), ]; - let p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts"); + let p = + Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts"); assert_eq!( p.composite_spans_from(0), vec![ @@ -10483,7 +10749,8 @@ mod tests { (LaneKind::Video, vec![clip(10, 0, 10, 1)]), (LaneKind::Audio, vec![clip(0, 0, 30, 0)]), ]; - let p = Project::from_parts(sources, holed, vec![], vec![], Vec::new()).expect("valid parts"); + let p = + Project::from_parts(sources, holed, vec![], vec![], Vec::new()).expect("valid parts"); assert_eq!( p.composite_spans_from(0), vec![ @@ -10531,7 +10798,8 @@ mod tests { (LaneKind::Audio, vec![clip(15, 0, 15, 1)]), (LaneKind::Audio, Vec::new()), ]; - let p = Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts"); + let p = + Project::from_parts(sources, lanes, vec![], vec![], Vec::new()).expect("valid parts"); let lists = p.audio_segments_from(0, FPS); assert_eq!(lists.len(), 2, "the empty lane is not mixed in"); assert_eq!(lists[0], p.segments_from(0, FPS), "A1 is unchanged"); @@ -10554,41 +10822,47 @@ mod tests { assert_eq!(p.audio_segments_from(0, FPS), vec![vec![(None, 0.0, 1.0)]]); } -/// D4: removing a subtitle column used to clear the whole undo history, -/// because a placement names its track by index into the palette and the -/// reindex left every later entry naming the wrong one. The entry holds the -/// palette beside the lanes now, so the reindex undoes with it. -#[test] -fn removing_a_subtitle_column_undoes_with_its_reindex() { - let track = |label: &str| SubtitleTrack { - path: FILE.into(), - track: None, - language: "eng".into(), - name: String::new(), - label: label.into(), - cues: Vec::new(), - bitmap: false, - refused: None, - }; - let mut p = Project::single(FILE, 300) - .with_subtitles(vec![track("one"), track("two"), track("three")]); - assert_eq!(p.subtitles().len(), 3); - let before = p.parts(); - let palette = p.subtitles().to_vec(); - // Column 0 goes, which renumbers the two behind it. - p.remove_subtitles(0).expect("a column with nothing on it"); - assert_eq!(p.subtitles().len(), 2); - assert_eq!(p.subtitles()[0].label, "two"); - assert!(p.undo(), "the removal is a step like any other cut"); - // The palette itself, and not only what `parts` happens to compare: this - // is the assertion that cannot go vacuous if the restore below it ever - // leaves a field of it behind. - assert_eq!(p.subtitles(), palette.as_slice(), "the palette itself, back"); - assert_eq!(p.parts(), before, "the palette and the lanes, both back"); - assert!(p.redo(), "and forward again"); - assert_eq!(p.subtitles().len(), 2, "the column goes again"); - assert_eq!(p.subtitles()[0].label, "two"); - assert_ne!(p.subtitles(), palette.as_slice(), "and it is not back"); -} - + /// D4: removing a subtitle column used to clear the whole undo history, + /// because a placement names its track by index into the palette and the + /// reindex left every later entry naming the wrong one. The entry holds the + /// palette beside the lanes now, so the reindex undoes with it. + #[test] + fn removing_a_subtitle_column_undoes_with_its_reindex() { + let track = |label: &str| SubtitleTrack { + path: FILE.into(), + track: None, + language: "eng".into(), + name: String::new(), + label: label.into(), + cues: Vec::new(), + bitmap: false, + refused: None, + }; + let mut p = Project::single(FILE, 300).with_subtitles(vec![ + track("one"), + track("two"), + track("three"), + ]); + assert_eq!(p.subtitles().len(), 3); + let before = p.parts(); + let palette = p.subtitles().to_vec(); + // Column 0 goes, which renumbers the two behind it. + p.remove_subtitles(0).expect("a column with nothing on it"); + assert_eq!(p.subtitles().len(), 2); + assert_eq!(p.subtitles()[0].label, "two"); + assert!(p.undo(), "the removal is a step like any other cut"); + // The palette itself, and not only what `parts` happens to compare: this + // is the assertion that cannot go vacuous if the restore below it ever + // leaves a field of it behind. + assert_eq!( + p.subtitles(), + palette.as_slice(), + "the palette itself, back" + ); + assert_eq!(p.parts(), before, "the palette and the lanes, both back"); + assert!(p.redo(), "and forward again"); + assert_eq!(p.subtitles().len(), 2, "the column goes again"); + assert_eq!(p.subtitles()[0].label, "two"); + assert_ne!(p.subtitles(), palette.as_slice(), "and it is not back"); + } } diff --git a/crates/engine/src/proxy.rs b/crates/engine/src/proxy.rs index 6ae8b54..8a2c792 100644 --- a/crates/engine/src/proxy.rs +++ b/crates/engine/src/proxy.rs @@ -32,8 +32,8 @@ //! cancel a file export has ([`Job`]). use std::path::{Path, PathBuf}; -use std::sync::atomic::AtomicBool; use std::sync::Arc; +use std::sync::atomic::AtomicBool; use std::time::UNIX_EPOCH; use crate::demux::{Codec, Demuxer, NoVideoTrack, VideoMeta}; @@ -93,8 +93,20 @@ const BITS_PER_PIXEL: f64 = 0.3; /// Whether this is a file worth standing in for: bigger than 1080p, or coded in /// something this machine decodes slowly even at 1080p. H.264 at or under 1080p /// plays natively and a proxy of it would cost time and buy nothing. +/// +/// The size test reads the **coded** pair, not the displayed one +/// ([`VideoMeta::coded_width`]): those differ wherever the file carries a +/// display matrix or a non-square pixel, and a 1920x1080 H.264 phone clip with +/// a 90-degree turn *displays* as 1080x1920 -- so judging the displayed pair +/// called a clip that plays natively proxy-worthy and put a whole film through +/// a decoder and an encoder to stand in for something already at speed. What a +/// decoder is asked to chew through is the stored raster, so the stored raster +/// is what this is about; the codec test is not a size question and is +/// unchanged. pub fn wanted(meta: &VideoMeta) -> bool { - meta.width > 1920 || meta.height > 1080 || matches!(meta.codec, Codec::Hevc | Codec::Av1) + meta.coded_width > 1920 + || meta.coded_height > 1080 + || matches!(meta.codec, Codec::Hevc | Codec::Av1) } /// The picture a proxy of `meta` is coded at: aspect kept, long edge at most @@ -628,7 +640,27 @@ mod tests { Arc::new(AtomicBool::new(false)) } - fn meta(width: u32, height: u32, codec: Codec) -> VideoMeta { + /// A meta as no container wrote it: square pixels, no turn, the displayed + /// pair the same pair the samples are stored at. + fn meta(coded_width: u32, coded_height: u32, codec: Codec) -> VideoMeta { + turned_meta(coded_width, coded_height, Rotation::None, codec) + } + + /// The same, but with the display pair built the way `demux` builds it for + /// a file carrying a display matrix: the stored pair with its axes swapped + /// where the turn says they are. A phone clip shot 1920x1080 and turned to + /// portrait is the case that matters -- it *displays* 1080x1920, and a + /// predicate that reads the displayed pair calls it a tall 1080p film. + fn turned_meta( + coded_width: u32, + coded_height: u32, + rotation: Rotation, + codec: Codec, + ) -> VideoMeta { + let (width, height) = match rotation.swaps_axes() { + true => (coded_height, coded_width), + false => (coded_width, coded_height), + }; VideoMeta { width, height, @@ -636,11 +668,9 @@ mod tests { frame_count: 240, codec, color: ColorDescription::default(), - rotation: Rotation::None, - // Square pixels, coded where they are declared: a meta no - // container wrote, so nothing was read to disagree with it. - coded_width: width, - coded_height: height, + rotation, + coded_width, + coded_height, pixel_aspect: crate::demux::PixelAspect::SQUARE, } } @@ -657,6 +687,39 @@ mod tests { "1080p H.264 plays natively" ); assert!(!wanted(&meta(1280, 720, Codec::H264)), "720p H.264"); + + // A turn must not turn a native file into a proxy job. What a decoder + // is handed is the stored raster -- 1920x1080 of H.264 -- and that is + // what plays at speed; the 1080x1920 the file *displays* is a metadata + // turn, not a bigger picture. Judged on the displayed pair this file + // was handed to a background decoder and an encoder to be stood in for, + // which is a whole film of CPU and cache for a clip already at rate. + let phone = turned_meta(1920, 1080, Rotation::Cw90, Codec::H264); + assert_eq!( + (phone.coded_width, phone.coded_height), + (1920, 1080), + "the samples are stored landscape" + ); + assert_eq!( + (phone.width, phone.height), + (1080, 1920), + "and the file only claims to display portrait" + ); + assert!( + !wanted(&phone), + "a rotated 1080p H.264 clip plays natively: the turn is not height" + ); + // ...while the same turn on a codec this machine decodes slowly is + // still wanted, and so is a genuinely tall stored raster: the two + // tests are about the stored pair, not about `rotation` itself. + assert!( + wanted(&turned_meta(1920, 1080, Rotation::Cw90, Codec::Hevc)), + "1080p HEVC is wanted whatever turn it carries" + ); + assert!( + wanted(&turned_meta(1080, 1920, Rotation::None, Codec::H264)), + "a stored 1080x1920 raster is a big one, turn or not" + ); } /// Aspect kept, long edge capped, both axes even -- and a small source left