projects
/
libdcp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use an enum class for Marker.
[libdcp.git]
/
src
/
dcp_time.cc
diff --git
a/src/dcp_time.cc
b/src/dcp_time.cc
index 526c784c95b09bff127aba1900d501281972a5d6..025a48590ed51aafcc4ff02c8670e0997a3e4724 100644
(file)
--- a/
src/dcp_time.cc
+++ b/
src/dcp_time.cc
@@
-39,6
+39,7
@@
#include "dcp_time.h"
#include "exceptions.h"
#include "compose.hpp"
#include "dcp_time.h"
#include "exceptions.h"
#include "compose.hpp"
+#include "dcp_assert.h"
#include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>
#include <iostream>
@@
-107,7
+108,7
@@
Time::Time (string time, optional<int> tcr_)
split (b, time, is_any_of (":"));
if (b.size() < 3 || b[0].empty() || b[1].empty() || b[0].length() > 2 || b[1].length() > 2) {
split (b, time, is_any_of (":"));
if (b.size() < 3 || b[0].empty() || b[1].empty() || b[0].length() > 2 || b[1].length() > 2) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1", time)));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1", time)));
}
if (!tcr_) {
}
if (!tcr_) {
@@
-117,17
+118,17
@@
Time::Time (string time, optional<int> tcr_)
vector<string> bs;
split (bs, b[2], is_any_of ("."));
if (bs.size() != 2) {
vector<string> bs;
split (bs, b[2], is_any_of ("."));
if (bs.size() != 2) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1", time)));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1", time)));
}
h = raw_convert<int> (b[0]);
m = raw_convert<int> (b[1]);
if (bs[0].empty() || bs[0].length() > 2) {
}
h = raw_convert<int> (b[0]);
m = raw_convert<int> (b[1]);
if (bs[0].empty() || bs[0].length() > 2) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, bs[0])));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, bs[0])));
}
s = raw_convert<int> (bs[0]);
if (bs[1].empty() || bs[1].length() > 3) {
}
s = raw_convert<int> (bs[0]);
if (bs[1].empty() || bs[1].length() > 3) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, bs[1])));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, bs[1])));
}
e = raw_convert<int> (bs[1]);
tcr = 1000;
}
e = raw_convert<int> (bs[1]);
tcr = 1000;
@@
-136,33
+137,33
@@
Time::Time (string time, optional<int> tcr_)
h = raw_convert<int> (b[0]);
m = raw_convert<int> (b[1]);
if (b[2].empty() || b[2].length() > 2) {
h = raw_convert<int> (b[0]);
m = raw_convert<int> (b[1]);
if (b[2].empty() || b[2].length() > 2) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, b[2])));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, b[2])));
}
s = raw_convert<int> (b[2]);
if (b[3].empty() || b[3].length() > 3) {
}
s = raw_convert<int> (b[2]);
if (b[3].empty() || b[3].length() > 3) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, b[3])));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, b[3])));
}
e = raw_convert<int> (b[3]);
tcr = 250;
} else {
}
e = raw_convert<int> (b[3]);
tcr = 250;
} else {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1", time)));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1", time)));
}
} else {
/* SMPTE: HH:MM:SS:EE */
split (b, time, is_any_of (":"));
if (b.size() != 4) {
}
} else {
/* SMPTE: HH:MM:SS:EE */
split (b, time, is_any_of (":"));
if (b.size() != 4) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1; does not have 4 parts", time)));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1; does not have 4 parts", time)));
}
h = raw_convert<int> (b[0]);
m = raw_convert<int> (b[1]);
if (b[2].empty() || b[2].length() > 2) {
}
h = raw_convert<int> (b[0]);
m = raw_convert<int> (b[1]);
if (b[2].empty() || b[2].length() > 2) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, b[2])));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, b[2])));
}
s = raw_convert<int> (b[2]);
if (b[3].empty() || b[3].length() > 2) {
}
s = raw_convert<int> (b[2]);
if (b[3].empty() || b[3].length() > 2) {
- boost::throw_exception (
DCP
ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, b[3])));
+ boost::throw_exception (ReadError (String::compose ("unrecognised time specification %1; %2 has bad length", time, b[3])));
}
e = raw_convert<int> (b[3]);
tcr = tcr_.get();
}
e = raw_convert<int> (b[3]);
tcr = tcr_.get();
@@
-208,11
+209,7
@@
dcp::operator< (Time const & a, Time const & b)
return a.s < b.s;
}
return a.s < b.s;
}
- if ((a.e * b.tcr) != (b.e * a.tcr)) {
- return (a.e * b.tcr) < (b.e * a.tcr);
- }
-
- return true;
+ return (a.e * b.tcr) < (b.e * a.tcr);
}
bool
}
bool
@@
-230,11
+227,7
@@
dcp::operator> (Time const & a, Time const & b)
return a.s > b.s;
}
return a.s > b.s;
}
- if ((a.e * b.tcr) != (b.e * a.tcr)) {
- return (a.e * b.tcr) > (b.e * a.tcr);
- }
-
- return true;
+ return (a.e * b.tcr) > (b.e * a.tcr);
}
ostream &
}
ostream &
@@
-330,18
+323,15
@@
dcp::operator/ (Time a, Time const & b)
string
Time::as_string (Standard standard) const
{
string
Time::as_string (Standard standard) const
{
- locked_stringstream str;
- str << setw(2) << setfill('0') << h << ":"
- << setw(2) << setfill('0') << m << ":"
- << setw(2) << setfill('0') << s << ":";
+ char buffer[64];
if (standard == SMPTE) {
if (standard == SMPTE) {
- s
tr << setw(2) << setfill('0') << e
;
+ s
nprintf (buffer, sizeof(buffer), "%02d:%02d:%02d:%02d", h, m, s, e)
;
} else {
} else {
- s
tr << setw(3) << setfill('0') << e
;
+ s
nprintf (buffer, sizeof(buffer), "%02d:%02d:%02d:%03d", h, m, s, e)
;
}
}
- return
str.str ()
;
+ return
buffer
;
}
/** @param tcr_ Timecode rate with which the return value should be counted.
}
/** @param tcr_ Timecode rate with which the return value should be counted.
@@
-367,5
+357,22
@@
Time::as_seconds () const
Time
Time::rebase (int tcr_) const
{
Time
Time::rebase (int tcr_) const
{
- return Time (h, m, s, floor (float (e) * tcr_ / tcr), tcr_);
+ long int e_ = lrintf (float (e) * tcr_ / tcr);
+ int s_ = s;
+ if (e_ >= tcr_) {
+ e_ -= tcr_;
+ ++s_;
+ }
+ int m_ = m;
+ if (s_ >= 60) {
+ s_ -= 60;
+ ++m_;
+ }
+ int h_ = h;
+ if (m_ >= 60) {
+ m_ -= 60;
+ ++h_;
+ }
+
+ return Time (h_, m_, s_, e_, tcr_);
}
}