summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-05-02 22:16:03 +0100
committerCarl Hetherington <cth@carlh.net>2018-05-14 23:14:50 +0100
commit743acc9bc88f543257355d40c320992ab72d8abe (patch)
tree19c4796f999af10d25ba3bee7ba8212c138dded1 /src
parentb43b16605df0980f3bb43d969cc0c3c18360812d (diff)
rebase() would round up and so it was possible for ticks to go out of range.
Now it still rounds up but then copes with overflow.
Diffstat (limited to 'src')
-rw-r--r--src/dcp_time.cc20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/dcp_time.cc b/src/dcp_time.cc
index f0b7e231..acc9723f 100644
--- 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_assert.h"
#include <boost/algorithm/string.hpp>
#include <boost/optional.hpp>
#include <iostream>
@@ -356,5 +357,22 @@ Time::as_seconds () const
Time
Time::rebase (int tcr_) const
{
- return Time (h, m, s, lrintf (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_);
}