mirror of
https://github.com/storytold/soundcraft.git
synced 2026-10-30 05:26:52 -06:00
Merge pull request #260 from Silvertree2010/fix/timecode-overflow
Compute timecode frame counts in i128 and clamp (#248)
This commit is contained in:
@@ -122,6 +122,7 @@ mutated and truncated movies. Field reports from the first public week are track
|
||||
|
||||
## Progress log
|
||||
|
||||
- **2026-10-12:** Timecode labels with huge fields no longer overflow: frame counts are computed in 128 bits and clamp, so `setup.current_timecode` and `session.format_time` saturate instead of failing (#248)
|
||||
- **2026-10-10 (UI docking):** Tracks and Groups, Clips, MIDI Editor, Memory Locations, and Undo History use movable panels. Edit and Mix retain separate arrangements; Clips and MIDI Editor belong to Edit. Transport, plug-in, and specialist utility windows retain their existing hosts. Panel moves and reset are available as UI commands, and saved UI preferences retain arrangements. Common toolbar and track record-enable buttons share interaction, accessible labels and keyboard focus through `craft-ui`, retaining blue tool selection and red record-arm states. No readiness percentage change.
|
||||
- **2026-10-10** — Stage re-normalized to **pre-alpha** by the core-workflow gate (interface recording, MIDI recording and session interchange fail). Full re-measure against Pro Tools Ultimate 2026.4.1 and the standard
|
||||
progress-docs set (this page, target-app parity, gaps, roadmap, UI/format/hardware/plugin/
|
||||
@@ -143,6 +144,7 @@ mutated and truncated movies. Field reports from the first public week are track
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-12 | trivial | Progress log: timecode overflow (#248) |
|
||||
| 2026-10-10 | minor | Readiness-by-audience table with hours: full 950–1,450 h, mainstream 380–600 h, essentials 110–200 h |
|
||||
| 2026-10-10 | minor | Added mainstream practitioner ~36 % and essentials user ~57 % to the headline numbers |
|
||||
| 2026-10-10 | minor | Stage alpha → pre-alpha: the core-workflow gate fails on interface recording, MIDI recording and session interchange; alpha distance added |
|
||||
|
||||
@@ -109,7 +109,7 @@ impl FrameRate {
|
||||
return 0;
|
||||
}
|
||||
let v = (i128::from(f) * i128::from(sr.hz()) * i128::from(d) + i128::from(n) / 2) / i128::from(n);
|
||||
i64::try_from(v).unwrap_or(0)
|
||||
i64::try_from(v).unwrap_or(if v < 0 { i64::MIN } else { i64::MAX })
|
||||
}
|
||||
|
||||
/// Samples per frame (fractional).
|
||||
@@ -153,13 +153,14 @@ impl Timecode {
|
||||
/// Absolute frame count of this label.
|
||||
pub fn to_frames(&self, rate: FrameRate) -> i64 {
|
||||
let base = rate.nominal().max(1);
|
||||
let total_min = self.hours * 60 + self.minutes;
|
||||
let mut f = (total_min * 60 + self.seconds) * base + self.frames;
|
||||
let total_min = i128::from(self.hours) * 60 + i128::from(self.minutes);
|
||||
let mut f = (total_min * 60 + i128::from(self.seconds)) * i128::from(base) + i128::from(self.frames);
|
||||
if rate.is_drop() {
|
||||
let drop = if base >= 60 { 4 } else { 2 };
|
||||
f -= drop * (total_min - total_min / 10);
|
||||
}
|
||||
if self.negative { -f } else { f }
|
||||
let f = if self.negative { -f } else { f };
|
||||
i64::try_from(f).unwrap_or(if f < 0 { i64::MIN } else { i64::MAX })
|
||||
}
|
||||
|
||||
pub fn from_samples(s: Samples, rate: FrameRate, sr: SampleRate) -> Timecode {
|
||||
@@ -233,6 +234,19 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn huge_timecode_saturates_instead_of_overflowing() {
|
||||
let sr = SampleRate::HZ_48000;
|
||||
for r in [FrameRate::Fps30, FrameRate::Fps29_97Drop] {
|
||||
let tc = Timecode::parse("9223372036854775807:00:00:00").unwrap();
|
||||
assert_eq!(tc.to_samples(r, sr), i64::MAX);
|
||||
let tc = Timecode::parse("-9223372036854775807:00:00:00").unwrap();
|
||||
assert_eq!(tc.to_samples(r, sr), i64::MIN);
|
||||
}
|
||||
let tc = Timecode::parse("01:02:03:04").unwrap();
|
||||
assert_eq!(tc.to_samples(FrameRate::Fps30, sr), 178_710_400);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_variants() {
|
||||
let tc = Timecode::parse("01:02:03:04").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user