Pick up effect and effect color.
[libdcp.git] / src / dcp_time.cc
index 2e79e74293fe6e61f8c84724a57e6bc64d912fd0..0cc6b264894c00be6c11b257ddbe73084c523f17 100644 (file)
 
 */
 
+/** @file  src/dcp_time.cc
+ *  @brief A representation of time within a DCP.
+ */
+
 #include <iostream>
+#include <cmath>
 #include "dcp_time.h"
 
 using namespace std;
+using namespace libdcp;
+
+Time::Time (int frame, int frames_per_second)
+       : h (0)
+       , m (0)
+       , s (0)
+       , t (0)
+{
+       float sec_float = float (frame) / frames_per_second;
+       t = (int (floor (sec_float * 1000)) % 1000) / 4;
+       s = floor (sec_float);
+
+       if (s > 60) {
+               m = s / 60;
+               s -= m * 60;
+       }
+
+       if (m > 60) {
+               h = m / 60;
+               m -= h * 60;
+       }
+}
 
 bool
 libdcp::operator== (Time const & a, Time const & b)
 {
-       return (a.h == b.h && a.m == b.m && a.s == b.s && a.ms == b.ms);
+       return (a.h == b.h && a.m == b.m && a.s == b.s && a.t == b.t);
+}
+
+bool
+libdcp::operator<= (Time const & a, Time const & b)
+{
+       if (a.h != b.h) {
+               return a.h <= b.h;
+       }
+
+       if (a.m != b.m) {
+               return a.m <= b.m;
+       }
+
+       if (a.s != b.s) {
+               return a.s <= b.s;
+       }
+
+       if (a.t != b.t) {
+               return a.t <= b.t;
+       }
+
+       return true;
 }
 
 ostream &
 libdcp::operator<< (ostream& s, Time const & t)
 {
-       s << t.h << ":" << t.m << ":" << t.s << "." << t.ms;
+       s << t.h << ":" << t.m << ":" << t.s << "." << t.t;
        return s;
 }