Accessor for ClosedCaptionsDialog.
[dcpomatic.git] / src / lib / dcpomatic_time.h
index cc31755cb6c3e2f84d79ef62f7c20cb9640c8f3c..897b725bd3e63587ba9390f194234847e01aedd1 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 #include <iomanip>
 #include <cstdio>
 
-class dcpomatic_round_up_test;
+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.
  *
@@ -115,16 +118,24 @@ public:
                return *this;
        }
 
+       Time<S, O> operator/ (int o) const {
+               return Time<S, O> (_t / o);
+       }
+
        /** Round up to the nearest sampling interval
         *  at some sampling rate.
         *  @param r Sampling rate.
         */
-       Time<S, O> ceil (float r) const {
-               return Time<S, O> (llrint (HZ * frames_ceil(r) / double(r)));
+       Time<S, O> ceil (double r) const {
+               return Time<S, O> (llrint (HZ * frames_ceil(r) / r));
        }
 
-       Time<S, O> floor (float r) const {
-               return Time<S, O> (llrint (HZ * frames_floor(r) / double(r)));
+       Time<S, O> floor (double r) const {
+               return Time<S, O> (llrint (HZ * frames_floor(r) / r));
+       }
+
+       Time<S, O> round (double r) const {
+               return Time<S, O> (llrint (HZ * frames_round(r) / r));
        }
 
        double seconds () const {
@@ -158,7 +169,13 @@ public:
                return ::ceil (_t * double(r) / HZ);
        }
 
-       /** @param r Frames per second */
+       /** Split a time into hours, minutes, seconds and frames.
+        *  @param r Frames per second.
+        *  @param h Returned hours.
+        *  @param m Returned minutes.
+        *  @param s Returned seconds.
+        *  @param f Returned frames.
+        */
        template <typename T>
        void split (T r, int& h, int& m, int& s, int& f) const
        {
@@ -213,12 +230,13 @@ public:
                return Time<S, O> (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 {};
@@ -292,7 +310,9 @@ public:
        }
 };
 
-/** @param B Periods to subtract from `A', must be in ascending order of start time and must not overlap */
+/** @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 <class T>
 std::list<TimePeriod<T> > subtract (TimePeriod<T> A, std::list<TimePeriod<T> > const & B)
 {
@@ -342,4 +362,6 @@ std::string to_string (ContentTime t);
 std::string to_string (DCPTime t);
 std::string to_string (DCPTimePeriod p);
 
+}
+
 #endif