summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-08-13 14:44:22 +0100
committerCarl Hetherington <cth@carlh.net>2012-08-13 14:44:22 +0100
commit5130dd409e92a7cdb868b2af85797afd286d8afa (patch)
tree205c49ef4e1610bff85a9bc1bfb3882e0dcd23a8 /src
parentcadec42b9547665ac03a7180af374ebb40df7c78 (diff)
Time from frame.
Diffstat (limited to 'src')
-rw-r--r--src/dcp_time.cc19
-rw-r--r--src/dcp_time.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/src/dcp_time.cc b/src/dcp_time.cc
index 5e8bf801..6af653ad 100644
--- a/src/dcp_time.cc
+++ b/src/dcp_time.cc
@@ -18,9 +18,28 @@
*/
#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)
diff --git a/src/dcp_time.h b/src/dcp_time.h
index 48560596..22dcec0f 100644
--- a/src/dcp_time.h
+++ b/src/dcp_time.h
@@ -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_)