2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "frame_time.h"
21 #include "compose.hpp"
29 sub::operator== (FrameTime const & a, FrameTime const & b)
31 return a.hours() == b.hours() && a.minutes() == b.minutes() && a.seconds() == b.seconds() && a.frames() == b.frames();
35 sub::operator< (FrameTime const & a, FrameTime const & b)
37 if (a.hours() != b.hours()) {
38 return a.hours() < b.hours();
41 if (a.minutes() != b.minutes()) {
42 return a.minutes() < b.minutes();
45 if (a.seconds() != b.seconds()) {
46 return a.seconds() < b.seconds();
49 return a.frames() < b.frames();
53 sub::operator<< (ostream& s, FrameTime const & t)
55 s << t.hours() << ":" << t.minutes() << ":" << t.seconds() << ":" << t.frames();
60 FrameTime::timecode () const
62 return String::compose ("%1:%2:%3:%4", _hours, _minutes, _seconds, _frames);
65 FrameTime::FrameTime (int64_t f, float fps)
67 set_from_frames (f, fps);
71 FrameTime::set_from_frames (int64_t f, float fps)
73 _hours = f / (60 * 60 * fps);
74 f -= _hours * 60 * 60 * fps;
75 _minutes = f / (60 * fps);
76 f -= _minutes * 60 * fps;
83 FrameTime::add (FrameTime t, float fps)
85 _frames += t.frames ();
91 _seconds += t.seconds ();
97 _minutes += t.minutes ();
103 _hours += t.hours ();
107 FrameTime::scale (float f, float frames_per_second)
110 (((_hours * 3600 + _minutes * 60 + _seconds) * frames_per_second) + _frames) * f,