Make terminate_threads() less likely to leave _threads containing invalid pointers.
[dcpomatic.git] / src / lib / dcpomatic_time.cc
1 /*
2     Copyright (C) 2014-2016 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 #include "dcpomatic_time.h"
22 #include <inttypes.h>
23
24 using std::string;
25
26 template <>
27 Time<ContentTimeDifferentiator, DCPTimeDifferentiator>::Time (DCPTime d, FrameRateChange f)
28         : _t (llrint (d.get() * f.speed_up))
29 {
30
31 }
32
33 template <>
34 Time<DCPTimeDifferentiator, ContentTimeDifferentiator>::Time (ContentTime d, FrameRateChange f)
35         : _t (llrint (d.get() / f.speed_up))
36 {
37
38 }
39
40 DCPTime
41 min (DCPTime a, DCPTime b)
42 {
43         if (a < b) {
44                 return a;
45         }
46
47         return b;
48 }
49
50 DCPTime
51 max (DCPTime a, DCPTime b)
52 {
53         if (a > b) {
54                 return a;
55         }
56
57         return b;
58 }
59
60 ContentTime
61 min (ContentTime a, ContentTime b)
62 {
63         if (a < b) {
64                 return a;
65         }
66
67         return b;
68 }
69
70 ContentTime
71 max (ContentTime a, ContentTime b)
72 {
73         if (a > b) {
74                 return a;
75         }
76
77         return b;
78 }
79
80 string
81 to_string (ContentTime t)
82 {
83         char buffer[64];
84 #ifdef DCPOMATIC_WINDOWS
85         __mingw_snprintf (buffer, sizeof(buffer), "[CONT %" PRId64 " %fs]", t.get(), t.seconds());
86 #else
87         snprintf (buffer, sizeof(buffer), "[CONT %" PRId64 " %fs]", t.get(), t.seconds());
88 #endif
89         return buffer;
90 }
91
92 string
93 to_string (DCPTime t)
94 {
95         char buffer[64];
96 #ifdef DCPOMATIC_WINDOWS
97         __mingw_snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs]", t.get(), t.seconds());
98 #else
99         snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs]", t.get(), t.seconds());
100 #endif
101         return buffer;
102 }
103
104 string
105 to_string (DCPTimePeriod p)
106 {
107         char buffer[64];
108 #ifdef DCPOMATIC_WINDOWS
109         __mingw_snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs -> %" PRId64 " %fs]", p.from.get(), p.from.seconds(), p.to.get(), p.to.seconds());
110 #else
111         snprintf (buffer, sizeof(buffer), "[DCP %" PRId64 " %fs -> %" PRId64 " %fs]", p.from.get(), p.from.seconds(), p.to.get(), p.to.seconds());
112 #endif
113         return buffer;
114 }