Bump libdcp.
[libsub.git] / src / frame_time.h
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef LIBSUB_FRAME_TIME_H
21 #define LIBSUB_FRAME_TIME_H
22
23 #include <iostream>
24 #include <stdint.h>
25
26 namespace sub {
27
28 /** @class FrameTime
29  *  @brief A time stored in hours, minutes, seconds and frames.
30  */
31 class FrameTime
32 {
33 public:
34         FrameTime ()
35                 : _hours (0)
36                 , _minutes (0)
37                 , _seconds (0)
38                 , _frames (0)
39         {}
40
41         /** @param f Number of frames.
42          *  @param fps Frames per second.
43          */
44         FrameTime (int64_t f, float fps);
45                           
46         FrameTime (int h, int m, int s, int f)
47                 : _hours (h)
48                 , _minutes (m)
49                 , _seconds (s)
50                 , _frames (f)
51         {}
52
53         int hours () const {
54                 return _hours;
55         }
56         
57         int minutes () const {
58                 return _minutes;
59         }
60         
61         int seconds () const {
62                 return _seconds;
63         }
64         
65         int frames () const {
66                 return _frames;
67         }
68
69         std::string timecode () const;
70
71         void add (FrameTime t, float fps);
72         void scale (float f, float fps);
73
74 private:
75         void set_from_frames (int64_t f, float fps);
76         
77         int _hours;
78         int _minutes;
79         int _seconds;
80         int _frames;
81 };
82
83 bool operator== (FrameTime const & a, FrameTime const & b);
84 bool operator< (FrameTime const & a, FrameTime const & b);
85 std::ostream& operator<< (std::ostream&, FrameTime const & t);
86         
87 }
88
89 #endif