C++11 tidying.
[dcpomatic.git] / src / lib / dcpomatic_time.cc
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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     DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "dcpomatic_time.h"
23 #include <inttypes.h>
24
25
26 using std::string;
27 using namespace dcpomatic;
28
29
30 template <>
31 Time<ContentTimeDifferentiator, DCPTimeDifferentiator>::Time (DCPTime d, FrameRateChange f)
32         : _t (llrint(d.get() * f.speed_up))
33 {
34
35 }
36
37
38 template <>
39 Time<DCPTimeDifferentiator, ContentTimeDifferentiator>::Time (ContentTime d, FrameRateChange f)
40         : _t (llrint(d.get() / f.speed_up))
41 {
42
43 }
44
45
46 DCPTime
47 dcpomatic::min (DCPTime a, DCPTime b)
48 {
49         if (a < b) {
50                 return a;
51         }
52
53         return b;
54 }
55
56
57 DCPTime
58 dcpomatic::max (DCPTime a, DCPTime b)
59 {
60         if (a > b) {
61                 return a;
62         }
63
64         return b;
65 }
66
67
68 ContentTime
69 dcpomatic::min (ContentTime a, ContentTime b)
70 {
71         if (a < b) {
72                 return a;
73         }
74
75         return b;
76 }
77
78
79 ContentTime
80 dcpomatic::max (ContentTime a, ContentTime b)
81 {
82         if (a > b) {
83                 return a;
84         }
85
86         return b;
87 }
88
89
90 string
91 dcpomatic::to_string (ContentTime t)
92 {
93         char buffer[64];
94 #ifdef DCPOMATIC_WINDOWS
95         __mingw_snprintf (buffer, sizeof(buffer), "[CONT %" PRId64 " %fs]", t.get(), t.seconds());
96 #else
97         snprintf (buffer, sizeof(buffer), "[CONT %" PRId64 " %fs]", t.get(), t.seconds());
98 #endif
99         return buffer;
100 }
101
102
103 string
104 dcpomatic::to_string (DCPTime t)
105 {
106         char buffer[64];
107 #ifdef DCPOMATIC_WINDOWS
108         __mingw_snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs]", t.get(), t.seconds());
109 #else
110         snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs]", t.get(), t.seconds());
111 #endif
112         return buffer;
113 }
114
115
116 string
117 dcpomatic::to_string (DCPTimePeriod p)
118 {
119         char buffer[64];
120 #ifdef DCPOMATIC_WINDOWS
121         __mingw_snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs -> %" PRId64 " %fs]", p.from.get(), p.from.seconds(), p.to.get(), p.to.seconds());
122 #else
123         snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs -> %" PRId64 " %fs]", p.from.get(), p.from.seconds(), p.to.get(), p.to.seconds());
124 #endif
125         return buffer;
126 }