diff options
Diffstat (limited to 'src/lib/dcpomatic_time.h')
| -rw-r--r-- | src/lib/dcpomatic_time.h | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 05b4e1a5d..b19a94ad7 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -21,6 +21,7 @@ #define DCPOMATIC_TIME_H #include <cmath> +#include <ostream> #include <stdint.h> #include "frame_rate_change.h" @@ -55,10 +56,6 @@ public: return rint (_t * r / HZ); } - operator bool () const { - return _t != 0; - } - protected: friend class dcptime_round_up_test; @@ -109,6 +106,10 @@ public: return *this; } + ContentTime operator- () const { + return ContentTime (-_t); + } + ContentTime operator- (ContentTime const & o) const { return ContentTime (_t - o._t); } @@ -118,6 +119,17 @@ public: return *this; } + /** Round up to the nearest sampling interval + * at some sampling rate. + * @param r Sampling rate. + */ + ContentTime round_up (int r) { + int64_t const n = HZ / r; + int64_t const a = _t + n - 1; + return ContentTime (a - (a % n)); + } + + static ContentTime from_seconds (double s) { return ContentTime (s * HZ); } @@ -128,6 +140,8 @@ public: } }; +std::ostream& operator<< (std::ostream& s, ContentTime t); + class DCPTime : public Time { public: @@ -210,5 +224,6 @@ public: }; DCPTime min (DCPTime a, DCPTime b); +std::ostream& operator<< (std::ostream& s, DCPTime t); #endif |
