forge
Explore
Log in

Don't you dare go Hollow

A silence refusal names the file and the frame it means

Browse files at this commit

564ba30ef23ef839dacc9c55b4cb103808d5cb47Ahmet Kaan GümüşParent: d4ac3fc
  • fix
    • a silence refusal names the file and the frame it means
Show full message
🐛 fix(timeline): a silence refusal names the file and the frame it means

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.rsmodified+55 -10
@@ -1205,6 +1205,16 @@ impl Player {
1205 }) else {1205 }) else {
1206 return;1206 return;
1207 };1207 };
1208+ // A still is asked *before* the decoder is: handing a png to the mp4
1209+ // demuxer answers "a box with a larger size than it", which is a true
1210+ // sentence about a container and nothing a person can act on. A picture
1211+ // has no sound for the same reason a silent video has none, so it is
1212+ // refused in the same words.
1213+ if engine::is_image(&source.path) {
1214+ self.silence_open = None;
1215+ self.notice = Some(unscannable(lane, idx, &source.path).into());
1216+ return;
1217+ }
1208 let cached = self1218 let cached = self
1209 .silence_levels1219 .silence_levels
1210 .as_ref()1220 .as_ref()
@@ -1224,15 +1234,7 @@ impl Player {
1224 // knows which one it meant.1234 // knows which one it meant.
1225 Ok(None) => {1235 Ok(None) => {
1226 self.silence_open = None;1236 self.silence_open = None;
1227- self.notice = Some(1237+ self.notice = Some(unscannable(lane, idx, &source.path).into());
1228- format!(
1229- "{} clip {} has no audio to scan — {} is silent",
1230- lane.label(),
1231- idx + 1,
1232- file_name(&source.path)
1233- )
1234- .into(),
1235- );
1236 return;1238 return;
1237 }1239 }
1238 Err(e) => {1240 Err(e) => {
@@ -5833,6 +5835,27 @@ enum ColorKey {
5833 Reset,5835 Reset,
5834 }5836 }
5835 5837
5838+/// Why the silence card has nothing to scan on that clip, in its own voice: the
5839+/// lane and index the user picked, the file it is of, and which of the two
5840+/// soundless things it is. One place, because a still and a silent video are
5841+/// the same answer to the same question -- "a box with a larger size than it"
5842+/// is what the *demuxer* would say about a png, and it is not an answer.
5843+///
5844+/// Costs nothing: the scan reads a file and writes marks, so a refusal here
5845+/// leaves the project (and its undo history) exactly where it was.
5846+fn unscannable(lane: Lane, idx: usize, path: &Path) -> String {
5847+ let what = match engine::is_image(path) {
5848+ true => "is a picture",
5849+ false => "is silent",
5850+ };
5851+ format!(
5852+ "{} clip {} has no audio to scan — {} {what}",
5853+ lane.label(),
5854+ idx + 1,
5855+ file_name(path)
5856+ )
5857+}
5858+
5836 /// The half of a take whose *sound* the silence card scans: a link is one span5859 /// The half of a take whose *sound* the silence card scans: a link is one span
5837 /// on however many lanes, so a card opened on the picture opens on the sound it5860 /// on however many lanes, so a card opened on the picture opens on the sound it
5838 /// is grouped with. That is the lane the waveform is drawn on, and so the lane5861 /// is grouped with. That is the lane the waveform is drawn on, and so the lane
@@ -6592,7 +6615,7 @@ mod tests {
6592 silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths,6615 silence_rate, source_tint, span_partner, speed_at, start_frac, timecode, unseen_paths,
6593 unseen_sources, whole_take, width_frac, window_title,6616 unseen_sources, whole_take, width_frac, window_title,
6594 };6617 };
6595- use super::{file_name, file_uri, library_rows};6618+ use super::{LaneKind, file_name, file_uri, library_rows, unscannable};
6596 6619
6597 /// What the file manager is handed: the parts a path keeps as they are, and6620 /// What the file manager is handed: the parts a path keeps as they are, and
6598 /// the ones the bus would otherwise read as something else.6621 /// the ones the bus would otherwise read as something else.
@@ -8078,6 +8101,28 @@ mod tests {
8078 assert!(u64::from(push_digit(99, 9)) * 1_000_000 < u64::from(u32::MAX));8101 assert!(u64::from(push_digit(99, 9)) * 1_000_000 < u64::from(u32::MAX));
8079 }8102 }
8080 8103
8104+ #[test]
8105+ fn a_clip_with_no_sound_is_refused_in_the_same_words_whichever_kind_it_is() {
8106+ // A still and a video with no audio track are one answer to one
8107+ // question: the lane and index that were picked, the file, and which of
8108+ // the two soundless things it is. What must never reach the bar is the
8109+ // demuxer's own words -- a png handed to the mp4 reader answers "a box
8110+ // with a larger size than it", which is true of a container and useless
8111+ // to a person.
8112+ assert_eq!(
8113+ unscannable(Lane::V1, 1, std::path::Path::new("/tmp/shot.png")),
8114+ "V1 clip 2 has no audio to scan — shot.png is a picture"
8115+ );
8116+ assert_eq!(
8117+ unscannable(
8118+ Lane::new(LaneKind::Audio, 1),
8119+ 0,
8120+ std::path::Path::new("/tmp/test_baseline.mp4")
8121+ ),
8122+ "A2 clip 1 has no audio to scan — test_baseline.mp4 is silent"
8123+ );
8124+ }
8125+
8081 #[test]8126 #[test]
8082 fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() {8127 fn the_silence_card_fits_the_smallest_window_and_never_slows_a_silence_down() {
8083 // The same 640x360 floor, and this card starts below the header: a8128 // The same 640x360 floor, and this card starts below the header: a
crates/engine/src/project.rsmodified+9 -1
@@ -1965,8 +1965,16 @@ impl Project {
1965 for (l, data) in self.lanes.iter().enumerate() {1965 for (l, data) in self.lanes.iter().enumerate() {
1966 for c in data.clips.iter().filter(|c| c.end() > at && c.start < at + len) {1966 for c in data.clips.iter().filter(|c| c.end() > at && c.start < at + len) {
1967 if (c.start, c.end()) != (at, at + len) {1967 if (c.start, c.end()) != (at, at + len) {
1968+ // *Which* edge did not come off: a rate that cannot
1969+ // address the end of the silence is not a rate that
1970+ // cannot address its start, and naming the wrong frame
1971+ // sends the user looking in the wrong place.
1972+ let edge = match c.start == at {
1973+ true => at + len,
1974+ false => at,
1975+ };
1968 refused = Some(format!(1976 refused = Some(format!(
1969- "the {} clip at frame {} plays at {} and cannot be cut at frame {at}: \1977+ "the {} clip at frame {} plays at {} and cannot be cut at frame {edge}: \
1970 detach it, or put it back to 1.00x first",1978 detach it, or put it back to 1.00x first",
1971 labels[l].label(),1979 labels[l].label(),
1972 c.start,1980 c.start,
crates/engine/tests/silence.rsmodified+28 -0
@@ -165,6 +165,34 @@ fn speed_mode_refuses_a_clip_that_laps_over_a_silence() {
165 loadable(&p);165 loadable(&p);
166 }166 }
167 167
168+/// A rate that cannot address an edge of a silence is refused naming **that**
169+/// edge -- not the region's start, which at a slow rate is often the one frame
170+/// that *was* addressable. A cut at the wrong frame is a user sent to look in
171+/// the wrong place.
172+///
173+/// At a quarter speed one source frame is four timeline frames, so only every
174+/// fourth frame is a cut the clip's own arithmetic can make.
175+#[test]
176+fn an_unaddressable_edge_is_named_where_it_actually_is() {
177+ let mut p = fixture();
178+ p.set_speed(Lane::V1, 0, Speed::MIN).expect("nothing after it");
179+ let before = spans(&p);
180+ // Starts where the clip starts -- no split needed there -- and ends at a
181+ // frame a quarter-speed clip cannot be cut at.
182+ let err = p
183+ .speed_regions(&[(0, 5)], Speed::MAX)
184+ .expect_err("frame 5 is not a cut this rate can make")
185+ .to_string();
186+ assert!(err.contains("frame 5"), "{err}");
187+ assert!(!err.contains("frame 0:"), "it named the region's start: {err}");
188+ // Rolled back whole, and the refusal cost no undo step: the press below is
189+ // the `set_speed` above.
190+ assert_eq!(spans(&p), before);
191+ assert!(p.undo());
192+ assert_eq!(p.lane(Lane::V1)[0].speed, Speed::NORMAL);
193+ assert!(!p.undo());
194+}
195+
168 /// The whole chain a person presses one key for: the fixture is scanned, its196 /// The whole chain a person presses one key for: the fixture is scanned, its
169 /// silences come back as timeline frames, and cutting them shortens the197 /// silences come back as timeline frames, and cutting them shortens the
170 /// timeline by exactly what was found -- with the scan itself having changed198 /// timeline by exactly what was found -- with the scan itself having changed