X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fdcpomatic_time.h;h=90e79de0a7b4cec45cee0a495d63554f2a6fa2c6;hb=e0adfd85dd7987ee2b77eea7f6d3c13885729a38;hp=7d755a46cf1a7e53a826f3f7ddd1f596b35ccc81;hpb=924dd6e5356f401c325a42ccb43607b79027bb59;p=dcpomatic.git diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 7d755a46c..90e79de0a 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -140,6 +140,11 @@ public: return floor (_t * r / HZ); } + template + int64_t frames_ceil (T r) const { + return ceil (_t * r / HZ); + } + /** @param r Frames per second */ template void split (T r, int& h, int& m, int& s, int& f) const @@ -223,36 +228,50 @@ typedef Time ContentTime; /** Time relative to the start of the output DCP in its frame rate */ typedef Time DCPTime; -class ContentTimePeriod +template +class TimePeriod { public: - ContentTimePeriod () {} + TimePeriod () {} - ContentTimePeriod (ContentTime f, ContentTime t) + TimePeriod (T f, T t) : from (f) , to (t) {} - ContentTime from; - ContentTime to; + T from; + T to; - ContentTimePeriod operator+ (ContentTime const & o) const { - return ContentTimePeriod (from + o, to + o); + T duration () const { + return to - from; } - bool overlaps (ContentTimePeriod const & o) const; - bool contains (ContentTime const & o) const; + TimePeriod operator+ (T const & o) const { + return TimePeriod (from + o, to + o); + } - bool operator== (ContentTimePeriod const & o) const { - return from == o.from && to == o.to; + bool overlaps (TimePeriod const & other) const { + return (from < other.to && to > other.from); + } + + bool contains (T const & other) const { + return (from <= other && other < to); + } + + bool operator== (TimePeriod const & other) const { + return from == other.from && to == other.to; } }; +typedef TimePeriod ContentTimePeriod; +typedef TimePeriod DCPTimePeriod; + DCPTime min (DCPTime a, DCPTime b); DCPTime max (DCPTime a, DCPTime b); ContentTime min (ContentTime a, ContentTime b); ContentTime max (ContentTime a, ContentTime b); std::ostream& operator<< (std::ostream& s, ContentTime t); std::ostream& operator<< (std::ostream& s, DCPTime t); +std::ostream& operator<< (std::ostream& s, DCPTimePeriod p); #endif