X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcpomatic_time.h;h=897b725bd3e63587ba9390f194234847e01aedd1;hb=fa5f3a8bf77209da27acc33cf144e2e4500a2600;hp=ad5b6768edb1140c9ac04570bab6f8a8af1651b2;hpb=bc9bd13a2d9df75057511deca71b943ab1183e19;p=dcpomatic.git diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index ad5b6768e..897b725bd 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2017 Carl Hetherington + Copyright (C) 2014-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -35,8 +35,13 @@ #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 +118,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 +230,13 @@ public: return Time (INT64_MAX); } + static const int HZ = 96000; + private: - friend struct dcptime_ceil_test; - friend struct dcptime_floor_test; + friend struct ::dcpomatic_time_ceil_test; + friend struct ::dcpomatic_time_floor_test; Type _t; - static const int HZ = 96000; }; class ContentTimeDifferentiator {}; @@ -348,4 +362,6 @@ std::string to_string (ContentTime t); std::string to_string (DCPTime t); std::string to_string (DCPTimePeriod p); +} + #endif