X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcpomatic_time.h;h=9e7191b1eb7dc239a890aebc2d6efa5fe81d3f75;hb=89c0fc8bf6893ecde5e220dca96444afd069bf7f;hp=00a31a7a7057ab5ece9f7ba4b26984bf0735f91d;hpb=ef31a94cd00dcc88fc83093cbc709b5b79acc4b6;p=dcpomatic.git diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 00a31a7a7..9e7191b1e 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2018 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,13 +18,16 @@ */ + /** @file src/lib/dcpomatic_time.h * @brief Types to describe time. */ + #ifndef DCPOMATIC_TIME_H #define DCPOMATIC_TIME_H + #include "frame_rate_change.h" #include "dcpomatic_assert.h" #include @@ -34,9 +37,11 @@ #include #include + struct dcpomatic_time_ceil_test; struct dcpomatic_time_floor_test; + namespace dcpomatic { @@ -156,15 +161,15 @@ public: * @param r Sampling rate. */ Time ceil (double r) const { - return Time (llrint (HZ * frames_ceil(r) / r)); + return Time (llrint(HZ * frames_ceil(r) / r)); } Time floor (double r) const { - return Time (llrint (HZ * frames_floor(r) / r)); + return Time (llrint(HZ * frames_floor(r) / r)); } Time round (double r) const { - return Time (llrint (HZ * frames_round(r) / r)); + return Time (llrint(HZ * frames_round(r) / r)); } double seconds () const { @@ -172,7 +177,7 @@ public: } Time abs () const { - return Time (std::abs (_t)); + return Time (std::abs(_t)); } template @@ -231,7 +236,6 @@ public: return buffer; } - static Time from_seconds (double s) { return Time (llrint (s * HZ)); } @@ -263,9 +267,11 @@ private: Type _t; }; + class ContentTimeDifferentiator {}; class DCPTimeDifferentiator {}; + /* Specializations for the two allowed explicit conversions */ template<> @@ -274,6 +280,7 @@ Time::Time (Time Time::Time (Time d, FrameRateChange f); + /** Time relative to the start or position of a piece of content in its native frame rate */ typedef Time ContentTime; /** Time relative to the start of the output DCP in its frame rate */ @@ -303,12 +310,12 @@ public: return TimePeriod (from + o, to + o); } - boost::optional > overlap (TimePeriod const & other) const { + boost::optional> overlap (TimePeriod const & other) const { T const max_from = std::max (from, other.from); T const min_to = std::min (to, other.to); if (max_from >= min_to) { - return boost::optional > (); + return {}; } return TimePeriod (max_from, min_to); @@ -334,36 +341,37 @@ public: } }; + /** @param A Period which is subtracted from. * @param B Periods to subtract from `A', must be in ascending order of start time and must not overlap. */ template -std::list > subtract (TimePeriod A, std::list > const & B) +std::list> subtract (TimePeriod A, std::list> const & B) { - std::list > result; + std::list> result; result.push_back (A); for (auto i: B) { - std::list > new_result; + std::list> new_result; for (auto j: result) { - boost::optional > ov = i.overlap (j); + auto ov = i.overlap (j); if (ov) { if (*ov == i) { /* A contains all of B */ if (i.from != j.from) { - new_result.push_back (TimePeriod (j.from, i.from)); + new_result.push_back (TimePeriod(j.from, i.from)); } if (i.to != j.to) { - new_result.push_back (TimePeriod (i.to, j.to)); + new_result.push_back (TimePeriod(i.to, j.to)); } } else if (*ov == j) { /* B contains all of A */ } else if (i.from < j.from) { /* B overlaps start of A */ - new_result.push_back (TimePeriod (i.to, j.to)); + new_result.push_back (TimePeriod(i.to, j.to)); } else if (i.to > j.to) { /* B overlaps end of A */ - new_result.push_back (TimePeriod (j.from, i.from)); + new_result.push_back (TimePeriod(j.from, i.from)); } } else { new_result.push_back (j); @@ -375,9 +383,11 @@ std::list > subtract (TimePeriod A, std::list > c return result; } + typedef TimePeriod ContentTimePeriod; typedef TimePeriod DCPTimePeriod; + DCPTime min (DCPTime a, DCPTime b); DCPTime max (DCPTime a, DCPTime b); ContentTime min (ContentTime a, ContentTime b); @@ -386,6 +396,8 @@ std::string to_string (ContentTime t); std::string to_string (DCPTime t); std::string to_string (DCPTimePeriod p); + } + #endif