mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
fix: correct timecode drift at non-25fps frame rates
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
parent
ee3bbbe29f
commit
60d57f74d8
2 changed files with 12 additions and 11 deletions
|
|
@ -32,6 +32,7 @@ impl LtcFrame {
|
||||||
/// Compare just HH:MM:SS against local time.
|
/// Compare just HH:MM:SS against local time.
|
||||||
pub fn matches_system_time(&self) -> bool {
|
pub fn matches_system_time(&self) -> bool {
|
||||||
let local = Local::now();
|
let local = Local::now();
|
||||||
|
// We only compare hours, minutes and seconds - frames are not considered in this comparison
|
||||||
local.hour() == self.hours
|
local.hour() == self.hours
|
||||||
&& local.minute() == self.minutes
|
&& local.minute() == self.minutes
|
||||||
&& local.second() == self.seconds
|
&& local.second() == self.seconds
|
||||||
|
|
|
||||||
|
|
@ -101,22 +101,22 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
let s = parseInt(tcParts[2], 10);
|
let s = parseInt(tcParts[2], 10);
|
||||||
let f = parseInt(tcParts[3], 10);
|
let f = parseInt(tcParts[3], 10);
|
||||||
|
|
||||||
|
const frameRateInt = Math.round(frameRate);
|
||||||
const msPerFrame = 1000.0 / frameRate;
|
const msPerFrame = 1000.0 / frameRate;
|
||||||
const elapsedFrames = Math.floor(elapsedMs / msPerFrame);
|
const elapsedFrames = Math.floor(elapsedMs / msPerFrame);
|
||||||
|
|
||||||
f += elapsedFrames;
|
// Compute total seconds including fractional part
|
||||||
|
let totalSeconds = h * 3600 + m * 60 + s + f / frameRateInt;
|
||||||
|
totalSeconds += elapsedMs / 1000.0;
|
||||||
|
|
||||||
const frameRateInt = Math.round(frameRate);
|
// Convert back to components
|
||||||
|
let newSeconds = Math.floor(totalSeconds);
|
||||||
s += Math.floor(f / frameRateInt);
|
f = Math.round((totalSeconds - newSeconds) * frameRateInt) % frameRateInt;
|
||||||
f %= frameRateInt;
|
|
||||||
|
|
||||||
m += Math.floor(s / 60);
|
|
||||||
s %= 60;
|
|
||||||
|
|
||||||
h += Math.floor(m / 60);
|
|
||||||
m %= 60;
|
|
||||||
|
|
||||||
|
h = Math.floor(newSeconds / 3600);
|
||||||
|
newSeconds %= 3600;
|
||||||
|
m = Math.floor(newSeconds / 60);
|
||||||
|
s = Math.floor(newSeconds % 60);
|
||||||
h %= 24;
|
h %= 24;
|
||||||
|
|
||||||
statusElements.ltcTimecode.textContent =
|
statusElements.ltcTimecode.textContent =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue