summaryrefslogtreecommitdiff
path: root/src/sub_time.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-07-18 10:37:51 +0100
committerCarl Hetherington <cth@carlh.net>2017-07-18 10:38:17 +0100
commita25cc3fda26e2bbc6b1c3786cc7f2ed7141a29f0 (patch)
tree763e292124b43b8c652bb4d34eaae5e14e8236f6 /src/sub_time.cc
parent4f6f03dc72d9cd24f3e4b2d856c5ccb66bda3930 (diff)
Fix Time::add which was broken when adding times with different rates.
Diffstat (limited to 'src/sub_time.cc')
-rw-r--r--src/sub_time.cc17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/sub_time.cc b/src/sub_time.cc
index c4e00ba..adaab31 100644
--- a/src/sub_time.cc
+++ b/src/sub_time.cc
@@ -172,24 +172,15 @@ Time::all_as_seconds () const
return _seconds + double(milliseconds ()) / 1000;
}
-/** Add a time to this one. This time must have an integer _rate
- * and t must have the same rate.
- */
+/** Add a time to this one. Both *this and t must have a specified _rate */
void
Time::add (Time t)
{
SUB_ASSERT (_rate);
+ SUB_ASSERT (t._rate);
- _seconds += t._seconds;
- _frames += t._frames;
-
- SUB_ASSERT (_rate.get().denominator != 0);
- SUB_ASSERT (_rate.get().integer ());
-
- if (_frames >= _rate.get().integer_fraction()) {
- _frames -= _rate.get().integer_fraction();
- ++_seconds;
- }
+ Rational result_rate = max (*_rate, *t._rate);
+ *this = Time::from_frames((all_as_seconds() + t.all_as_seconds()) * result_rate.fraction(), result_rate);
}
void