Time from frame.
authorCarl Hetherington <cth@carlh.net>
Mon, 13 Aug 2012 13:44:22 +0000 (14:44 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 13 Aug 2012 13:44:22 +0000 (14:44 +0100)
src/dcp_time.cc
src/dcp_time.h
test/tests.cc

index 5e8bf801a02909445ee4174668263fb2c58a7a92..6af653adeabc43be623e9aab56a1745b9c10eb01 100644 (file)
 */
 
 #include <iostream>
+#include <cmath>
 #include "dcp_time.h"
 
 using namespace std;
+using namespace libdcp;
+
+Time::Time (int frame, int frames_per_second)
+{
+       float sec_float = float (frame) / frames_per_second;
+       ms = int (sec_float * 1000) % 1000;
+       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)
index 48560596dece8500e38654f6dafa29af0eb8d919..22dcec0fd73004650787aecc254a476040c6c40e 100644 (file)
@@ -26,6 +26,7 @@ class Time
 {
 public:
        Time () : h (0), m (0), s (0), ms (0) {}
+       Time (int frame, int frames_per_second);
        Time (int h_, int m_, int s_, int ms_)
                : h (h_)
                , m (m_)
index cb180ec0f5c60c2d7b2f7ac16a600d3cb7c5bdbf..ccbf8787895dabb86299d586eee912abc7245cc3 100644 (file)
@@ -129,4 +129,12 @@ BOOST_AUTO_TEST_CASE (subtitles)
        BOOST_CHECK_EQUAL (subs.subtitles_at (libdcp::Time (0, 0, 14, 042)).front()->text(), "And these are Roy Hattersley's jeans");
 }
 
-       
+BOOST_AUTO_TEST_CASE (dcp_time)
+{
+       libdcp::Time t (977143, 24);
+
+       BOOST_CHECK_EQUAL (t.ms, 292);
+       BOOST_CHECK_EQUAL (t.s, 34);
+       BOOST_CHECK_EQUAL (t.m, 18);
+       BOOST_CHECK_EQUAL (t.h, 11);
+}