diff options
| author | Carl Hetherington <cth@carlh.net> | 2026-02-28 09:06:44 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2026-02-28 09:08:46 +0100 |
| commit | bcf62b5e4a268554b7960e5f739b24f9eafb38a5 (patch) | |
| tree | 904fb5959dcd2401daba2d42c53d3a0736604bff /src/lib/dcpomatic_time.h | |
| parent | bb04b67f593c1da37b76af9507f3e28e9ab15f74 (diff) | |
WIP: use fraction for DCP frame rate.archive-frame-rates
This will allow archival rates to be expressed precisely.
Diffstat (limited to 'src/lib/dcpomatic_time.h')
| -rw-r--r-- | src/lib/dcpomatic_time.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 0d15028c6..a388b6dc6 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -30,6 +30,7 @@ #include "dcpomatic_assert.h" #include "frame_rate_change.h" +#include <dcp/types.h> #include <boost/optional.hpp> #include <stdint.h> #include <cmath> @@ -178,6 +179,10 @@ public: return Time<S, O>(llrint(HZ * frames_round(r) / r)); } + Time<S, O> round(dcp::Fraction r) const { + return Time<S, O>(llrint(HZ * frames_round(r) * r.denominator / r.numerator)); + } + double seconds() const { return double(_t) / HZ; } @@ -195,11 +200,23 @@ public: return llrint(_t * double(r) / HZ); } + int64_t frames_round(dcp::Fraction r) const { + /* We must cast to double here otherwise if T is integer + the calculation will round down before we get the chance + to llrint(). + */ + return llrint(_t * double(r.numerator) / (HZ * r.denominator)); + } + template <typename T> int64_t frames_floor(T r) const { return ::floor(_t * r / HZ); } + int64_t frames_floor(dcp::Fraction r) const { + return ::floor(_t * r.numerator / (HZ * r.denominator)); + } + template <typename T> int64_t frames_ceil(T r) const { /* We must cast to double here otherwise if T is integer @@ -252,6 +269,11 @@ public: return Time<S, O>(f * HZ / r); } + static Time<S, O> from_frames(int64_t f, dcp::Fraction r) { + DCPOMATIC_ASSERT(r.numerator > 0); + return Time<S, O>(f * HZ * r.denominator / r.numerator); + } + static Time<S, O> delta() { return Time<S, O>(1); } |
