More licence fixups.
[libdcp.git] / src / dcp_time.h
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /** @file  src/dcp_time.h
21  *  @brief Time class.
22  */
23
24 #ifndef LIBDCP_TIME_H
25 #define LIBDCP_TIME_H
26
27 #include "types.h"
28 #include <stdint.h>
29 #include <string>
30 #include <iostream>
31
32 namespace dcp {
33
34 /** @class Time
35  *  @brief A representation of time within a DCP.
36  */
37 class Time
38 {
39 public:
40         /** Construct a zero Time */
41         Time () : h (0), m (0), s (0), e (0), tcr (1) {}
42
43         /** Construct a Time.
44          *  @param Frame index (starting from 0).
45          *  @param frames_per_second Frames per second.
46          *  @param tcr Timecode rate.
47          */
48         Time (int frame, double frames_per_second, int tcr);
49
50         /** Construct a Time from hours, minutes, seconds, editable units and a timecode rate.
51          *  @param h_ Hours.
52          *  @param m_ Minutes.
53          *  @param s_ Seconds.
54          *  @param e_ Editable units (where 1 editable unit is 1 / tcr_ seconds)
55          *  @param tcr_ Timecode rate; i.e. number of editable units per second.
56          */
57         Time (int h_, int m_, int s_, int e_, int tcr_)
58                 : h (h_)
59                 , m (m_)
60                 , s (s_)
61                 , e (e_)
62                 , tcr (tcr_)
63         {}
64
65         Time (double seconds, int tcr);
66
67         Time (std::string time, int tcr);
68
69         int h; ///<   hours
70         int m; ///<   minutes
71         int s; ///<   seconds
72         int e; ///<   editable units (where 1 editable unit is 1 / tcr_ seconds)
73         int tcr; ///< timecode rate: the number of editable units per second.
74
75         std::string as_string (Standard standard) const;
76         double as_seconds () const;
77         int64_t as_editable_units (int tcr_) const;
78         Time rebase (int tcr_) const;
79
80 private:
81         void set (double seconds, int tcr);
82 };
83
84 extern bool operator== (Time const & a, Time const & b);
85 extern bool operator!= (Time const & a, Time const & b);
86 extern bool operator<= (Time const & a, Time const & b);
87 extern bool operator< (Time const & a, Time const & b);
88 extern bool operator> (Time const & a, Time const & b);
89 extern bool operator>= (Time const & a, Time const & b);
90 extern std::ostream & operator<< (std::ostream & s, Time const & t);
91 extern Time operator+ (Time a, Time b);
92 extern Time operator- (Time a, Time b);
93 extern float operator/ (Time a, Time const & b);
94
95 }
96
97 #endif