From 564ba30ef23ef839dacc9c55b4cb103808d5cb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 10 Aug 2026 23:29:15 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(timeline):=20a=20silence=20r?= =?UTF-8?q?efusal=20names=20the=20file=20and=20the=20frame=20it=20means?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A still handed to the silence card answered in the mp4 demuxer's words ("a box with a larger size than it"), which is true of a container and useless to a person: a picture has no sound for the same reason a silent video has none, so it is refused in the same sentence, by name. And a rate that cannot be cut at the *end* of a silence said the start instead -- a frame the cut would have been fine at, and the wrong place to send anyone looking. --- crates/app/src/main.rs | 65 ++++++++++++++++++++++++++++------ crates/engine/src/project.rs | 10 +++++- crates/engine/tests/silence.rs | 28 +++++++++++++++ 3 files changed, 92 insertions(+), 11 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 7514dc0..2b64199 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1205,6 +1205,16 @@ impl Player { }) else { return; }; + // A still is asked *before* the decoder is: handing a png to the mp4 + // demuxer answers "a box with a larger size than it", which is a true + // sentence about a container and nothing a person can act on. A picture + // has no sound for the same reason a silent video has none, so it is + // refused in the same words. + if engine::is_image(&source.path) { + self.silence_open = None; + self.notice = Some(unscannable(lane, idx, &source.path).into()); + return; + } let cached = self .silence_levels .as_ref() @@ -1224,15 +1234,7 @@ impl Player { // knows which one it meant. Ok(None) => { self.silence_open = None; - self.notice = Some( - format!( - "{} clip {} has no audio to scan — {} is silent", - lane.label(), - idx + 1, - file_name(&source.path) - ) - .into(), - ); + self.notice = Some(unscannable(lane, idx, &source.path).into()); return; } Err(e) => { @@ -5833,6 +5835,27 @@ enum ColorKey { Reset, } +/// Why the silence card has nothing to scan on that clip, in its own voice: the +/// lane and index the user picked, the file it is of, and which of the two +/// soundless things it is. One place, because a still and a silent video are +/// the same answer to the same question -- "a box with a larger size than it" +/// is what the *demuxer* would say about a png, and it is not an answer. +/// +/// Costs nothing: the scan reads a file and writes marks, so a refusal here +/// leaves the project (and its undo history) exactly where it was. +fn unscannable(lane: Lane, idx: usize, path: &Path) -> String { + let what = match engine::is_image(path) { + true => "is a picture", + false => "is silent", + }; + format!( + "{} clip {} has no audio to scan — {} {what}", + lane.label(), + idx + 1, + file_name(path) + ) +} + /// The half of a take whose *sound* the silence card scans: a link is one span /// on however many lanes, so a card opened on the picture opens on the sound it /// is grouped with. That is the lane the waveform is drawn on, and so the lane @@ -6592,7 +6615,7 @@ mod tests { silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths, unseen_sources, whole_take, width_frac, window_title, }; - use super::{file_name, file_uri, library_rows}; + use super::{LaneKind, file_name, file_uri, library_rows, unscannable}; /// 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. @@ -8078,6 +8101,28 @@ mod tests { assert!(u64::from(push_digit(99, 9)) * 1_000_000 < u64::from(u32::MAX)); } + #[test] + fn a_clip_with_no_sound_is_refused_in_the_same_words_whichever_kind_it_is() { + // A still and a video with no audio track are one answer to one + // question: the lane and index that were picked, the file, and which of + // the two soundless things it is. What must never reach the bar is the + // demuxer's own words -- a png handed to the mp4 reader answers "a box + // with a larger size than it", which is true of a container and useless + // to a person. + assert_eq!( + unscannable(Lane::V1, 1, std::path::Path::new("/tmp/shot.png")), + "V1 clip 2 has no audio to scan — shot.png is a picture" + ); + assert_eq!( + unscannable( + Lane::new(LaneKind::Audio, 1), + 0, + std::path::Path::new("/tmp/test_baseline.mp4") + ), + "A2 clip 1 has no audio to scan — test_baseline.mp4 is silent" + ); + } + #[test] fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() { // The same 640x360 floor, and this card starts below the header: a diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 90cadb7..be98983 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1965,8 +1965,16 @@ impl Project { for (l, data) in self.lanes.iter().enumerate() { for c in data.clips.iter().filter(|c| c.end() > at && c.start < at + len) { if (c.start, c.end()) != (at, at + len) { + // *Which* edge did not come off: a rate that cannot + // address the end of the silence is not a rate that + // cannot address its start, and naming the wrong frame + // sends the user looking in the wrong place. + let edge = match c.start == at { + true => at + len, + false => at, + }; refused = Some(format!( - "the {} clip at frame {} plays at {} and cannot be cut at frame {at}: \ + "the {} clip at frame {} plays at {} and cannot be cut at frame {edge}: \ detach it, or put it back to 1.00x first", labels[l].label(), c.start, diff --git a/crates/engine/tests/silence.rs b/crates/engine/tests/silence.rs index 7712c68..dc40fdf 100644 --- a/crates/engine/tests/silence.rs +++ b/crates/engine/tests/silence.rs @@ -165,6 +165,34 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() { loadable(&p); } +/// A rate that cannot address an edge of a silence is refused naming **that** +/// edge -- not the region's start, which at a slow rate is often the one frame +/// that *was* addressable. A cut at the wrong frame is a user sent to look in +/// the wrong place. +/// +/// At a quarter speed one source frame is four timeline frames, so only every +/// fourth frame is a cut the clip's own arithmetic can make. +#[test] +fn an_unaddressable_edge_is_named_where_it_actually_is() { + let mut p = fixture(); + p.set_speed(Lane::V1, 0, Speed::MIN).expect("nothing after it"); + let before = spans(&p); + // Starts where the clip starts -- no split needed there -- and ends at a + // frame a quarter-speed clip cannot be cut at. + let err = p + .speed_regions(&[(0, 5)], Speed::MAX) + .expect_err("frame 5 is not a cut this rate can make") + .to_string(); + assert!(err.contains("frame 5"), "{err}"); + assert!(!err.contains("frame 0:"), "it named the region's start: {err}"); + // Rolled back whole, and the refusal cost no undo step: the press below is + // the `set_speed` above. + assert_eq!(spans(&p), before); + assert!(p.undo()); + assert_eq!(p.lane(Lane::V1)[0].speed, Speed::NORMAL); + assert!(!p.undo()); +} + /// The whole chain a person presses one key for: the fixture is scanned, its /// silences come back as timeline frames, and cutting them shortens the /// timeline by exactly what was found -- with the scan itself having changed