Purge rint() and use llrint and friends.
[dcpomatic.git] / src / lib / dcpomatic_time.cc
index 98888646d0a841e26bcb077a426be8ac66e1e8e4..6f8f5efa2d4eb01b8b7249447c271ac79dc33bc4 100644 (file)
 
 using std::ostream;
 
-ContentTime::ContentTime (DCPTime d, FrameRateChange f)
-       : Time (rint (d.get() * f.speed_up))
+template <>
+Time<ContentTimeDifferentiator, DCPTimeDifferentiator>::Time (DCPTime d, FrameRateChange f)
+       : _t (llrint (d.get() * f.speed_up))
 {
 
 }
 
-DCPTime min (DCPTime a, DCPTime b)
+template <>
+Time<DCPTimeDifferentiator, ContentTimeDifferentiator>::Time (ContentTime d, FrameRateChange f)
+       : _t (llrint (d.get() / f.speed_up))
+{
+
+}
+
+DCPTime
+min (DCPTime a, DCPTime b)
+{
+       if (a < b) {
+               return a;
+       }
+
+       return b;
+}
+
+DCPTime
+max (DCPTime a, DCPTime b)
+{
+       if (a > b) {
+               return a;
+       }
+
+       return b;
+}
+
+ContentTime
+min (ContentTime a, ContentTime b)
 {
        if (a < b) {
                return a;
@@ -36,6 +65,16 @@ DCPTime min (DCPTime a, DCPTime b)
        return b;
 }
 
+ContentTime
+max (ContentTime a, ContentTime b)
+{
+       if (a > b) {
+               return a;
+       }
+
+       return b;
+}
+
 ostream &
 operator<< (ostream& s, ContentTime t)
 {
@@ -49,3 +88,15 @@ operator<< (ostream& s, DCPTime t)
        s << "[DCP " << t.get() << " " << t.seconds() << "s]";
        return s;
 }
+
+bool
+ContentTimePeriod::overlaps (ContentTimePeriod const & other) const
+{
+       return (from < other.to && to >= other.from);
+}
+
+bool
+ContentTimePeriod::contains (ContentTime const & other) const
+{
+       return (from <= other && other < to);
+}