Try doing frames calculation with int where possible.
[dcpomatic.git] / src / lib / dcpomatic_time.h
index b308e82b42baec709200c80cf29ccf2fc8b9dbc7..494aebba73c32583d902608a55d5184a9523af1c 100644 (file)
@@ -62,7 +62,7 @@ public:
 
        /* Explicit conversion from type O */
        Time (Time<O, S> d, FrameRateChange f);
-       
+
        Type get () const {
                return _t;
        }
@@ -133,7 +133,7 @@ public:
 
        template <typename T>
        int64_t frames (T r) const {
-               return rint (double (_t) * r / HZ);
+               return floor (_t * r / HZ);
        }
 
        /** @param r Frames per second */
@@ -144,7 +144,7 @@ public:
                   to a frame boundary at the start rather than the end.
                */
                int64_t ff = frames (r);
-               
+
                h = ff / (3600 * r);
                ff -= h * 3600 * r;
                m = ff / (60 * r);
@@ -173,9 +173,9 @@ public:
                return o.str ();
        }
 
-       
+
        static Time<S, O> from_seconds (double s) {
-               return Time<S, O> (s * HZ);
+               return Time<S, O> (rint (s * HZ));
        }
 
        template <class T>
@@ -188,13 +188,17 @@ public:
                return Time<S, O> (1);
        }
 
+       static Time<S, O> min () {
+               return Time<S, O> (-INT64_MAX);
+       }
+
        static Time<S, O> max () {
                return Time<S, O> (INT64_MAX);
        }
-       
+
 private:
        friend struct dcptime_round_up_test;
-       
+
        Type _t;
        static const int HZ = 96000;
 };
@@ -219,7 +223,7 @@ class ContentTimePeriod
 {
 public:
        ContentTimePeriod () {}
-       
+
        ContentTimePeriod (ContentTime f, ContentTime t)
                : from (f)
                , to (t)
@@ -237,6 +241,9 @@ public:
 };
 
 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);