Round up in Time::as_editable_units.
authorCarl Hetherington <cth@carlh.net>
Mon, 20 Jul 2015 20:48:40 +0000 (21:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 20 Jul 2015 20:48:40 +0000 (21:48 +0100)
src/dcp_time.cc
test/write_subtitle_test.cc

index 8101bed1e38b164983a19afa3a987bb53aa7e259..5e2e3121e741af24f52fac305583ecb829567c5c 100644 (file)
@@ -263,13 +263,13 @@ Time::as_string () const
 }
 
 /** @param tcr_ Timecode rate with which the return value should be counted.
- *  @return the total number of editable units that this time consists of at the specified timecode rate.
- *  For example, as_editable_units (24) returns the total time in frames at 24fps.
+ *  @return the total number of editable units that this time consists of at the specified timecode rate, rounded up
+ *  to the nearest editable unit. For example, as_editable_units (24) returns the total time in frames at 24fps.
  */
 int64_t
 Time::as_editable_units (int tcr_) const
 {
-       return (int64_t(e) * float (tcr_ / tcr)) + int64_t(s) * tcr_ + int64_t(m) * 60 * tcr_ + int64_t(h) * 60 * 60 * tcr_;
+       return ceil (int64_t(e) * double (tcr_) / tcr) + int64_t(s) * tcr_ + int64_t(m) * 60 * tcr_ + int64_t(h) * 60 * 60 * tcr_;
 }
 
 /** @return the total number of seconds that this time consists of */
index d2402262a35b053b6d87a67b918ef2179ba7c40a..faf5cee28b2f5fbbb481fa7dba8b1205859fd26f 100644 (file)
@@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE (write_subtitle_test)
                "    </Subtitle>\n"
                "  </Font>\n"
                "  <Font Italic=\"yes\" Color=\"FF800040\" Size=\"91\" Effect=\"border\" EffectColor=\"FF010203\" Script=\"normal\" Underlined=\"no\" Weight=\"normal\">\n"
-               "    <Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:219\" TimeOut=\"06:12:15:219\" FadeUpTime=\"930790\" FadeDownTime=\"4591830\">\n"
+               "    <Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:219\" TimeOut=\"06:12:15:219\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">\n"
                "      <Text VAlign=\"bottom\" VPosition=\"40\">What's going on</Text>\n"
                "    </Subtitle>\n"
                "  </Font>\n"
@@ -99,4 +99,3 @@ BOOST_AUTO_TEST_CASE (write_subtitle_test)
                list<string> ()
                );
 }
-