FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Fix AudioSamples time display for negative times
NetterSilver9a93d175a4af
diff --git a/crates/time/src/lib.rs b/crates/time/src/lib.rsindex 23f328bf5..685b91a06 100644--- a/crates/time/src/lib.rs+++ b/crates/time/src/lib.rs@@ -416,9 +416,12 @@ pub fn format_time(t: Tick, rate: FrameRate, drop_frame: bool, display: TimeDispformat!("{}{}+{: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()),}@@ -507,6 +510,14 @@ mod tests {use super::*;use proptest::prelude::*;+ #[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).