summaryrefslogtreecommitdiff
path: root/src/lib/dcpomatic_time.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-12-22 00:09:57 +0100
committerCarl Hetherington <cth@carlh.net>2025-09-02 22:40:13 +0200
commit33b0928b20618da5bc295711bfdf3d638863afa5 (patch)
tree24af21c6a7b863d914991ae837c36b6b9b50bcce /src/lib/dcpomatic_time.h
parent6784eb8de2451afd2dedc15c05eac043011b5afb (diff)
Untested conversion to num/den DCPTime.arbitrary-hz
Summary of required changes: Replace ::from_frames with a constructor that takes num/den. Provide and use member to_debug_string() instead of to_string(). Provide and use member to_serializable_string() and string constructor instead of fmt::to_string on .get() and number constructor. Provide and use content_time() member instead of ContentTime constructor from DCPTime. Use frames_round(96000) instead of get() when comparing times to see if they are "close enough". Provide and use DCPTime(x, FrameRateChange) constructor when converting from ContentTime. Use .seconds() when calculating proportions or sometimes when dividing by HZ. Provide and use operator bool(). Pass explicit 96000 denominator in a lot of places. Add member max() and use it instead of static max() Change BOOST_CHECK_EQUAL to BOOST_CHECK Provide operator/ and use it instead of .get() / 2.
Diffstat (limited to 'src/lib/dcpomatic_time.h')
-rw-r--r--src/lib/dcpomatic_time.h70
1 files changed, 64 insertions, 6 deletions
diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h
index 6de576246..685da778a 100644
--- a/src/lib/dcpomatic_time.h
+++ b/src/lib/dcpomatic_time.h
@@ -216,7 +216,7 @@ public:
* @return Split time.
*/
template <typename T>
- HMSF split (T r) const
+ HMSF splitX(T r) const
{
/* Do this calculation with frames so that we can round
to a frame boundary at the start rather than the end.
@@ -236,8 +236,8 @@ public:
}
template <typename T>
- std::string timecode (T r) const {
- auto hmsf = split (r);
+ std::string timecodeX(T r) const {
+ auto hmsf = splitX(r);
char buffer[128];
snprintf (buffer, sizeof(buffer), "%02d:%02d:%02d:%02d", hmsf.h, hmsf.m, hmsf.s, hmsf.f);
@@ -291,8 +291,7 @@ Time<DCPTimeDifferentiator, ContentTimeDifferentiator>::Time (Time<ContentTimeDi
/** Time relative to the start or position of a piece of content in its native frame rate */
typedef Time<ContentTimeDifferentiator, DCPTimeDifferentiator> ContentTime;
-/** Time relative to the start of the output DCP in its frame rate */
-typedef Time<DCPTimeDifferentiator, ContentTimeDifferentiator> DCPTime;
+
template <class T>
class TimePeriod
@@ -392,6 +391,66 @@ std::list<TimePeriod<T>> subtract (TimePeriod<T> A, std::list<TimePeriod<T>> con
}
+class DCPTime
+{
+private:
+ using Type = int64_t;
+
+public:
+ DCPTime() = default;
+ explicit DCPTime(Type num);
+ DCPTime(Type num, Type den);
+ DCPTime(ContentTime time, FrameRateChange frc);
+ DCPTime(std::string const& serializable_string);
+ DCPTime(HMSF const& hmsf, float fps);
+
+ static DCPTime from_seconds(double s);
+
+ std::string to_serialisable_string() const;
+ std::string to_debug_string() const;
+
+ double seconds() const;
+
+ int64_t frames_floor(int r) const;
+ int64_t frames_round(int r) const;
+ int64_t frames_ceil(int r) const;
+ DCPTime floor(int r) const;
+ DCPTime round(int r) const;
+ DCPTime ceil(int r) const;
+
+ DCPTime abs() const;
+
+ bool operator<(DCPTime const& o) const;
+ bool operator<=(DCPTime const& o) const;
+ bool operator==(DCPTime const& o) const;
+ bool operator!=(DCPTime const& o) const;
+ bool operator>=(DCPTime const& o) const;
+ bool operator>(DCPTime const& o) const;
+
+ DCPTime operator+(DCPTime const& o) const;
+ DCPTime& operator+=(DCPTime const& o);
+ DCPTime operator-() const;
+ DCPTime operator-(DCPTime const& o) const;
+ DCPTime& operator-=(DCPTime const& o);
+ DCPTime operator*(int o) const;
+ DCPTime operator/(int o) const;
+
+ DCPTime max() const;
+
+ explicit operator bool() const;
+
+ HMSF splitX(int r) const;
+ std::string timecodeX(int r) const;
+
+ ContentTime content_time(FrameRateChange frc) const;
+
+private:
+ Type _num = 0;
+ Type _den = 1;
+};
+
+
+
typedef TimePeriod<ContentTime> ContentTimePeriod;
typedef TimePeriod<DCPTime> DCPTimePeriod;
@@ -401,7 +460,6 @@ DCPTime max (DCPTime a, DCPTime b);
ContentTime min (ContentTime a, ContentTime b);
ContentTime max (ContentTime a, ContentTime b);
std::string to_string (ContentTime t);
-std::string to_string (DCPTime t);
std::string to_string (DCPTimePeriod p);