2 Copyright (C) 2014-2015 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 #ifndef LIBSUB_SUB_TIME_H
21 #define LIBSUB_SUB_TIME_H
23 #include <boost/optional.hpp>
30 Rational (int numerator_, int denominator_)
31 : numerator (numerator_)
32 , denominator (denominator_)
38 double fraction () const {
39 return double (numerator) / denominator;
55 int frames_at (Rational rate) const;
56 int milliseconds () const;
58 static Time from_hmsf (int h, int m, int s, int f, boost::optional<Rational> rate = boost::optional<Rational> ());
59 static Time from_hms (int h, int m, int s, int ms);
62 friend bool operator< (Time const & a, Time const & b);
63 friend bool operator> (Time const & a, Time const & b);
64 friend bool operator== (Time const & a, Time const & b);
65 friend std::ostream& operator<< (std::ostream& s, Time const & t);
67 Time (int seconds, int frames, boost::optional<Rational> rate)
75 boost::optional<Rational> _rate;
78 bool operator< (Time const & a, Time const & b);
79 bool operator> (Time const & a, Time const & b);
80 bool operator== (Time const & a, Time const & b);
81 bool operator!= (Time const & a, Time const & b);
82 std::ostream& operator<< (std::ostream& s, Time const & t);