CENTRE_OF_SCREEN -> VERTICAL_CENTRE_OF_SCREEN.
[libsub.git] / src / sub_time.cc
index c4e00bab233479e5862d216f5748386b6d742948..763b4e44aba4e1389f118ba401fd3a0670bf3031 100644 (file)
@@ -169,27 +169,18 @@ Time::from_frames (int f, Rational rate)
 double
 Time::all_as_seconds () const
 {
-       return _seconds + double(milliseconds ()) / 1000;
+       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
@@ -199,10 +190,7 @@ Time::scale (float f)
        SUB_ASSERT (_rate->denominator != 0);
        SUB_ASSERT (_rate->integer ());
 
-       _seconds = rint (_seconds * f);
-       _frames = rint (_frames * f);
-       if (_frames >= _rate->integer_fraction()) {
-               _frames -= _rate->integer_fraction ();
-               ++_seconds;
-       }
+       double const s = Time::all_as_seconds() * f;
+       _seconds = floor (s);
+       _frames = rint ((s - _seconds) * _rate->fraction());
 }