Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Merge main into #2472 (resolve append conflicts)

Brandon Thomasd90538d094c1
diff --cc crates/time/src/lib.rs
index 685b91a06,b4df8d1c1..2cb8004a8
--- a/crates/time/src/lib.rs
+++ b/crates/time/src/lib.rs
@@@ -416,14 -416,15 +416,18 @@@ pub fn format_time(t: Tick, rate: Frame
format!("{}{}+{:02}", if neg { "-" } else { "" }, a / per_ft, a % per_ft)
}
TimeDisplay::AudioSamples => {
- let secs = t.0.div_euclid(TICKS_PER_SECOND);
- let rem = Tick(t.0.rem_euclid(TICKS_PER_SECOND)).to_units_floor(sample_rate);
- format!("{:02}:{:02}:{:02}:{rem:05}", secs / 3600, (secs / 60) % 60, secs % 60)
+ let neg = t.0 < 0;
+ let a = t.0.unsigned_abs();
+ let tps = TICKS_PER_SECOND.unsigned_abs();
+ let secs = a / tps;
+ let rem = Tick((a % tps) as i64).to_units_floor(sample_rate);
+ format!("{}{:02}:{:02}:{:02}:{rem:05}", if neg { "-" } else { "" }, secs / 3600, (secs / 60) % 60, secs % 60)
}
- TimeDisplay::Seconds => format!("{:.3}", t.seconds()),
+ TimeDisplay::Seconds => {
+ let s = format!("{:.3}", t.seconds());
+ // A tiny negative time rounds to zero but keeps its sign: drop it.
+ if s == "-0.000" { "0.000".to_string() } else { s }
+ }
}
}
@@@ -510,14 -511,16 +514,24 @@@ mod tests
use super::*;
use proptest::prelude::*;
+ #[test]
+ fn seconds_display_has_no_negative_zero() {
+ let f = |t: i64| format_time(Tick(t), FrameRate::default(), false, TimeDisplay::Seconds, 48000);
+ assert_eq!(f(-1), "0.000");
+ assert_eq!(f(-2), "0.000");
+ assert_eq!(f(-(TICKS_PER_SECOND / 2500)), "0.000");
+ assert_eq!(f(-TICKS_PER_SECOND), "-1.000");
+ assert_eq!(f(-TICKS_PER_SECOND / 1000), "-0.001");
+ }
+
+ #[test]
+ fn audio_samples_negative_time_has_leading_minus() {
+ let r = FrameRate::new(30000, 1001);
+ let f = |t| format_time(Tick(t), r, false, TimeDisplay::AudioSamples, 48000);
+ assert_eq!(f(-TICKS_PER_SECOND), "-00:00:01:00000");
+ assert_eq!(f(-(TICKS_PER_SECOND + TICKS_PER_SECOND / 2)), "-00:00:01:24000");
+ }
+
/// Damaged files and projects can carry zero / negative rates and timebases, and users or
/// agents can type huge timecodes: these used to panic (division by zero, overflow,
/// crossed `clamp` bounds).