From de49deb8b65bad47fda93a04fab2e97b10d48a75 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 21 Jun 2014 15:44:46 +0100 Subject: Add FrameTime constructor from frames and fps. --- src/frame_time.cc | 11 +++++++++++ src/frame_time.h | 6 ++++++ test/time_test.cc | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/src/frame_time.cc b/src/frame_time.cc index 726c552..e9b72b7 100644 --- a/src/frame_time.cc +++ b/src/frame_time.cc @@ -61,3 +61,14 @@ FrameTime::timecode () const { return String::compose ("%1:%2:%3:%4", _hours, _minutes, _seconds, _frames); } + +FrameTime::FrameTime (int64_t f, int fps) +{ + _hours = f / (60 * 60 * fps); + f -= _hours * 60 * 60 * fps; + _minutes = f / (60 * fps); + f -= _minutes * 60 * fps; + _seconds = f / fps; + f -= _seconds * fps; + _frames = int (f); +} diff --git a/src/frame_time.h b/src/frame_time.h index 1a97e63..e721a29 100644 --- a/src/frame_time.h +++ b/src/frame_time.h @@ -21,6 +21,7 @@ #define LIBSUB_FRAME_TIME_H #include +#include namespace sub { @@ -36,6 +37,11 @@ public: , _seconds (0) , _frames (0) {} + + /** @param f Number of frames. + * @param fps Frames per second. + */ + FrameTime (int64_t f, int fps); FrameTime (int h, int m, int s, int f) : _hours (h) diff --git a/test/time_test.cc b/test/time_test.cc index 977ebd2..fc852b1 100644 --- a/test/time_test.cc +++ b/test/time_test.cc @@ -40,6 +40,14 @@ BOOST_AUTO_TEST_CASE (time_construction_test) BOOST_CHECK_EQUAL (t.seconds(), 2); BOOST_CHECK_EQUAL (t.milliseconds(), 3); } + + { + sub::FrameTime t (3 * 60 * 60 * 24 + 31 * 60 * 24 + 4 * 24 + 11, 24); + BOOST_CHECK_EQUAL (t.hours(), 3); + BOOST_CHECK_EQUAL (t.minutes(), 31); + BOOST_CHECK_EQUAL (t.seconds(), 4); + BOOST_CHECK_EQUAL (t.frames(), 11); + } } /* Check time conversions */ -- cgit v1.2.3