X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fdcp_time.cc;h=9ce367645c29e6654bb7471c6246d4743c9434ca;hb=5aa66b7fd3e5256cd20eedde287a2124522610a0;hp=df753efd348364fc7be2a703fd1393a3e996139e;hpb=3941ebc04432fdbb92e1c2b25bbbd10d4fcecd51;p=libdcp.git diff --git a/src/dcp_time.cc b/src/dcp_time.cc index df753efd..9ce36764 100644 --- a/src/dcp_time.cc +++ b/src/dcp_time.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,20 +18,20 @@ */ /** @file src/dcp_time.cc - * @brief A representation of time within a DCP. + * @brief Time class. */ +#include "raw_convert.h" +#include "dcp_time.h" +#include "exceptions.h" +#include #include #include -#include -#include #include -#include "dcp_time.h" -#include "exceptions.h" using namespace std; using namespace boost; -using namespace libdcp; +using namespace dcp; Time::Time (int frame, int frames_per_second) : h (0) @@ -51,22 +51,20 @@ Time::Time (int64_t ticks) s = ticks / 250; ticks -= int64_t (s) * 250; t = ticks; - - std::cout << "Hello: " << h << " " << m << " " << s << " " << t << "\n"; } void Time::set (double ss) { - t = (int (round (ss * 1000)) % 1000) / 4; s = floor (ss); + t = int (round (1000 * (ss - s) / 4)); - if (s > 60) { + if (s >= 60) { m = s / 60; s -= m * 60; } - if (m > 60) { + if (m >= 60) { h = m / 60; m -= h * 60; } @@ -80,26 +78,26 @@ Time::Time (string time) boost::throw_exception (DCPReadError ("unrecognised time specification")); } - h = lexical_cast (b[0]); - m = lexical_cast (b[1]); - s = lexical_cast (b[2]); - t = lexical_cast (b[3]); + h = raw_convert (b[0]); + m = raw_convert (b[1]); + s = raw_convert (b[2]); + t = raw_convert (b[3]); } bool -libdcp::operator== (Time const & a, Time const & b) +dcp::operator== (Time const & a, Time const & b) { 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) +dcp::operator!= (Time const & a, Time const & b) { return !(a == b); } bool -libdcp::operator<= (Time const & a, Time const & b) +dcp::operator<= (Time const & a, Time const & b) { if (a.h != b.h) { return a.h <= b.h; @@ -121,7 +119,7 @@ libdcp::operator<= (Time const & a, Time const & b) } bool -libdcp::operator< (Time const & a, Time const & b) +dcp::operator< (Time const & a, Time const & b) { if (a.h != b.h) { return a.h < b.h; @@ -143,7 +141,7 @@ libdcp::operator< (Time const & a, Time const & b) } bool -libdcp::operator> (Time const & a, Time const & b) +dcp::operator> (Time const & a, Time const & b) { if (a.h != b.h) { return a.h > b.h; @@ -165,14 +163,14 @@ libdcp::operator> (Time const & a, Time const & b) } ostream & -libdcp::operator<< (ostream& s, Time const & t) +dcp::operator<< (ostream& s, Time const & t) { s << t.h << ":" << t.m << ":" << t.s << "." << t.t; return s; } -libdcp::Time -libdcp::operator+ (Time a, Time const & b) +dcp::Time +dcp::operator+ (Time a, Time const & b) { Time r; @@ -199,8 +197,8 @@ libdcp::operator+ (Time a, Time const & b) return r; } -libdcp::Time -libdcp::operator- (Time a, Time const & b) +dcp::Time +dcp::operator- (Time a, Time const & b) { Time r; @@ -228,7 +226,7 @@ libdcp::operator- (Time a, Time const & b) } float -libdcp::operator/ (Time a, Time const & b) +dcp::operator/ (Time a, Time const & b) { int64_t const at = a.h * 3600 * 250 + a.m * 60 * 250 + a.s * 250 + a.t; int64_t const bt = b.h * 3600 * 250 + b.m * 60 * 250 + b.s * 250 + b.t; @@ -251,3 +249,8 @@ Time::to_ticks () const return int64_t(t) + int64_t(s) * 250 + int64_t(m) * 60 * 250 + int64_t(h) * 60 * 60 * 250; } +double +Time::to_seconds () const +{ + return double (to_ticks ()) / 250; +}