X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcpomatic_time.h;h=62d8a28ccf1ddee397e85ed014e77beb929fae92;hb=a5d004b0773f633401528392fc28e66d70e13ac8;hp=5f00807bdf2c3c4da605e577e3c18f7214d90391;hpb=35e5de23b21a1fc9788fadd9ecd8beae9cfc18e3;p=dcpomatic.git diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 5f00807bd..62d8a28cc 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -28,15 +28,19 @@ #include "frame_rate_change.h" #include "dcpomatic_assert.h" #include -#include #include #include #include #include #include +struct dcpomatic_time_ceil_test; +struct dcpomatic_time_floor_test; + +namespace dcpomatic { + /** A time in seconds, expressed as a number scaled up by Time::HZ. We want two different - * versions of this class, ContentTime and DCPTime, and we want it to be impossible to + * versions of this class, dcpomatic::ContentTime and dcpomatic::DCPTime, and we want it to be impossible to * convert implicitly between the two. Hence there's this template hack. I'm not * sure if it's the best way to do it. * @@ -113,16 +117,24 @@ public: return *this; } + Time operator/ (int o) const { + return Time (_t / o); + } + /** Round up to the nearest sampling interval * at some sampling rate. * @param r Sampling rate. */ - Time ceil (float r) const { - return Time (llrint (HZ * frames_ceil(r) / double(r))); + Time ceil (double r) const { + return Time (llrint (HZ * frames_ceil(r) / r)); + } + + Time floor (double r) const { + return Time (llrint (HZ * frames_floor(r) / r)); } - Time floor (float r) const { - return Time (llrint (HZ * frames_floor(r) / double(r))); + Time round (double r) const { + return Time (llrint (HZ * frames_round(r) / r)); } double seconds () const { @@ -217,12 +229,13 @@ public: return Time (INT64_MAX); } + static const int HZ = 96000; + private: - friend struct dcpomatic_time_ceil_test; - friend struct dcpomatic_time_floor_test; + friend struct ::dcpomatic_time_ceil_test; + friend struct ::dcpomatic_time_floor_test; Type _t; - static const int HZ = 96000; }; class ContentTimeDifferentiator {}; @@ -305,9 +318,9 @@ std::list > subtract (TimePeriod A, std::list > c std::list > result; result.push_back (A); - BOOST_FOREACH (TimePeriod i, B) { + for (auto i: B) { std::list > new_result; - BOOST_FOREACH (TimePeriod j, result) { + for (auto j: result) { boost::optional > ov = i.overlap (j); if (ov) { if (*ov == i) { @@ -348,4 +361,6 @@ std::string to_string (ContentTime t); std::string to_string (DCPTime t); std::string to_string (DCPTimePeriod p); +} + #endif