projects
/
libdcp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Express colour conversions as chromaticities and adjust so that
[libdcp.git]
/
src
/
dcp_time.cc
diff --git
a/src/dcp_time.cc
b/src/dcp_time.cc
index 5376b9724e08a9f7ddef6907ec7fd05cd4edf0c4..c3c60f662e59890bdba810f0210659f1fa837622 100644
(file)
--- a/
src/dcp_time.cc
+++ b/
src/dcp_time.cc
@@
-1,5
+1,5
@@
/*
/*
- Copyright (C) 2012-201
4
Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-201
5
Carl Hetherington <cth@carlh.net>
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
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
@@
-21,10
+21,10
@@
* @brief Time class.
*/
* @brief Time class.
*/
+#include "raw_convert.h"
#include "dcp_time.h"
#include "exceptions.h"
#include <boost/algorithm/string.hpp>
#include "dcp_time.h"
#include "exceptions.h"
#include <boost/algorithm/string.hpp>
-#include <boost/lexical_cast.hpp>
#include <iostream>
#include <vector>
#include <cmath>
#include <iostream>
#include <vector>
#include <cmath>
@@
-33,44
+33,41
@@
using namespace std;
using namespace boost;
using namespace dcp;
using namespace boost;
using namespace dcp;
-Time::Time (int frame, int frames_per_second)
- : h (0)
- , m (0)
- , s (0)
- , t (0)
+Time::Time (int frame, int frames_per_second, int tcr_)
{
{
- set (double (frame) / frames_per_second);
+ set (double (frame) / frames_per_second
, tcr_
);
}
}
-Time::Time (
int64_t tick
s)
+Time::Time (
double second
s)
{
{
- h = ticks / (60 * 60 * 250);
- ticks -= int64_t (h) * 60 * 60 * 250;
- m = ticks / (60 * 250);
- ticks -= int64_t (m) * 60 * 250;
- s = ticks / 250;
- ticks -= int64_t (s) * 250;
- t = ticks;
+ set (seconds, 24);
}
void
}
void
-Time::set (double s
s
)
+Time::set (double s
econds, int tcr_
)
{
{
- t = (int (round (ss * 1000)) % 1000) / 4;
- s = floor (ss);
+ s = floor (seconds);
+ tcr = tcr_;
+
+ e = int (round ((seconds - s) * tcr));
- if (s > 60) {
+ if (s >
=
60) {
m = s / 60;
s -= m * 60;
m = s / 60;
s -= m * 60;
+ } else {
+ m = 0;
}
}
- if (m > 60) {
+ if (m >
=
60) {
h = m / 60;
m -= h * 60;
h = m / 60;
m -= h * 60;
+ } else {
+ h = 0;
}
}
}
}
-Time::Time (string time)
+Time::Time (string time, int tcr_)
+ : tcr (tcr_)
{
vector<string> b;
split (b, time, is_any_of (":"));
{
vector<string> b;
split (b, time, is_any_of (":"));
@@
-78,16
+75,16
@@
Time::Time (string time)
boost::throw_exception (DCPReadError ("unrecognised time specification"));
}
boost::throw_exception (DCPReadError ("unrecognised time specification"));
}
- h =
lexical_cas
t<int> (b[0]);
- m =
lexical_cas
t<int> (b[1]);
- s =
lexical_cas
t<int> (b[2]);
-
t = lexical_cas
t<int> (b[3]);
+ h =
raw_conver
t<int> (b[0]);
+ m =
raw_conver
t<int> (b[1]);
+ s =
raw_conver
t<int> (b[2]);
+
e = raw_conver
t<int> (b[3]);
}
bool
dcp::operator== (Time const & a, Time const & b)
{
}
bool
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
);
+ return (a.h == b.h && a.m == b.m && a.s == b.s &&
(a.e * b.tcr) == (b.e * a.tcr)
);
}
bool
}
bool
@@
-99,23
+96,13
@@
dcp::operator!= (Time const & a, Time const & b)
bool
dcp::operator<= (Time const & a, Time const & b)
{
bool
dcp::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 a < b || a == b;
+}
- return true;
+bool
+dcp::operator>= (Time const & a, Time const & b)
+{
+ return a > b || a == b;
}
bool
}
bool
@@
-133,8
+120,8
@@
dcp::operator< (Time const & a, Time const & b)
return a.s < b.s;
}
return a.s < b.s;
}
- if (
a.t != b.t
) {
- return
a.t < b.t
;
+ if (
(a.e * b.tcr) != (b.e * a.tcr)
) {
+ return
(a.e * b.tcr) < (b.e * a.tcr)
;
}
return true;
}
return true;
@@
-155,8
+142,8
@@
dcp::operator> (Time const & a, Time const & b)
return a.s > b.s;
}
return a.s > b.s;
}
- if (
a.t != b.t
) {
- return
a.t > b.t
;
+ if (
(a.e * b.tcr) != (b.e * a.tcr)
) {
+ return
(a.e * b.tcr) > (b.e * a.tcr)
;
}
return true;
}
return true;
@@
-165,18
+152,27
@@
dcp::operator> (Time const & a, Time const & b)
ostream &
dcp::operator<< (ostream& s, Time const & t)
{
ostream &
dcp::operator<< (ostream& s, Time const & t)
{
- s << t.h << ":" << t.m << ":" << t.s << "." << t.
t
;
+ s << t.h << ":" << t.m << ":" << t.s << "." << t.
e
;
return s;
}
dcp::Time
return s;
}
dcp::Time
-dcp::operator+ (Time a, Time
const &
b)
+dcp::operator+ (Time a, Time b)
{
Time r;
{
Time r;
- r.t = a.t + b.t;
- if (r.t >= 250) {
- r.t -= 250;
+ /* Make sure we have a common tcr */
+ if (a.tcr != b.tcr) {
+ a.e *= b.tcr;
+ b.e *= a.tcr;
+ r.tcr = a.tcr * b.tcr;
+ } else {
+ r.tcr = a.tcr;
+ }
+
+ r.e = a.e + b.e;
+ if (r.e >= r.tcr) {
+ r.e -= r.tcr;
r.s++;
}
r.s++;
}
@@
-198,13
+194,22
@@
dcp::operator+ (Time a, Time const & b)
}
dcp::Time
}
dcp::Time
-dcp::operator- (Time a, Time
const &
b)
+dcp::operator- (Time a, Time b)
{
Time r;
{
Time r;
- r.t = a.t - b.t;
- if (r.t < 0) {
- r.t += 250;
+ /* Make sure we have a common tcr */
+ if (a.tcr != b.tcr) {
+ a.e *= b.tcr;
+ b.e *= a.tcr;
+ r.tcr = a.tcr * b.tcr;
+ } else {
+ r.tcr = a.tcr;
+ }
+
+ r.e = a.e - b.e;
+ if (r.e < 0) {
+ r.e += r.tcr;
r.s--;
}
r.s--;
}
@@
-228,24
+233,28
@@
dcp::operator- (Time a, Time const & b)
float
dcp::operator/ (Time a, Time const & b)
{
float
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
;
+ int64_t const at = a.h * 3600
+ a.m * 60 + a.s * float (a.e) / a.tcr
;
+ int64_t const bt = b.h * 3600
+ b.m * 60 + b.s * float (b.e) / b.tcr
;
return float (at) / bt;
}
return float (at) / bt;
}
-/** @return A string of the form h:m:s:
t
*/
+/** @return A string of the form h:m:s:
e
*/
string
Time::to_string () const
{
stringstream str;
string
Time::to_string () const
{
stringstream str;
- str << h << ":" << m << ":" << s << ":" <<
t
;
+ str << h << ":" << m << ":" << s << ":" <<
e
;
return str.str ();
}
return str.str ();
}
-/** @return This time in ticks */
int64_t
int64_t
-Time::to_
ticks (
) const
+Time::to_
editable_units (int tcr_
) const
{
{
- return
int64_t(t) + int64_t(s) * 250 + int64_t(m) * 60 * 250 + int64_t(h) * 60 * 60 * 250
;
+ return
(int64_t(e) * float (tcr_ / tcr)) + int64_t(s) * tcr_ + int64_t(m) * 60 * tcr_ + int64_t(h) * 60 * 60 * tcr_
;
}
}
+double
+Time::to_seconds () const
+{
+ return h * 3600 + m * 60 + s + double(e) / tcr;
+}