Improve implementation of ContentTime/DCPTime.
[dcpomatic.git] / src / lib / dcpomatic_time.cc
index 98888646d0a841e26bcb077a426be8ac66e1e8e4..4541ced7dc504db73621e9db29e23bbe4b2750d5 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 (rint (d.get() * f.speed_up))
 {
 
 }
 
-DCPTime min (DCPTime a, DCPTime b)
+template <>
+Time<DCPTimeDifferentiator, ContentTimeDifferentiator>::Time (ContentTime d, FrameRateChange f)
+       : _t (rint (d.get() / f.speed_up))
+{
+
+}
+
+DCPTime
+min (DCPTime a, DCPTime b)
 {
        if (a < b) {
                return a;
@@ -49,3 +58,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);
+}