In-line run of subs_in_out so that it gets the environment more easily.
[libdcp.git] / src / types.h
1 /*
2     Copyright (C) 2012-2021 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     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 /** @file  src/types.h
36  *  @brief Miscellaneous types
37  */
38
39
40 #ifndef LIBDCP_TYPES_H
41 #define LIBDCP_TYPES_H
42
43
44 #include "warnings.h"
45 #include <libcxml/cxml.h>
46 LIBDCP_DISABLE_WARNINGS
47 #include <asdcp/KLV.h>
48 LIBDCP_ENABLE_WARNINGS
49 #include <memory>
50 #include <boost/function.hpp>
51 #include <string>
52
53
54 /* windows.h defines this but we want to use it */
55 #undef ERROR
56
57
58 namespace xmlpp {
59         class Element;
60 }
61
62
63 namespace dcp
64 {
65
66
67 /** @struct Size
68  *  @brief The integer, two-dimensional size of something.
69  */
70 struct Size
71 {
72         Size() = default;
73
74         Size (int w, int h)
75                 : width (w)
76                 , height (h)
77         {}
78
79         float ratio () const {
80                 return float (width) / height;
81         }
82
83         int width = 0;
84         int height = 0;
85 };
86
87
88 extern bool operator== (Size const & a, Size const & b);
89 extern bool operator!= (Size const & a, Size const & b);
90
91
92 /** Identifier for a sound channel */
93 enum class Channel {
94         LEFT = 0,      ///< left
95         RIGHT = 1,     ///< right
96         CENTRE = 2,    ///< centre
97         LFE = 3,       ///< low-frequency effects (sub)
98         LS = 4,        ///< left surround
99         RS = 5,        ///< right surround
100         HI = 6,
101         VI = 7,
102         LC = 8,        ///< not used, but referred to in MainSoundConfiguration in some CPLs
103         RC = 9,        ///< not used, but referred to in MainSoundConfiguration in some CPLs
104         BSL = 10,
105         BSR = 11,
106         MOTION_DATA = 12,
107         SYNC_SIGNAL = 13,
108         SIGN_LANGUAGE = 14,
109         /* 15 is not used */
110         CHANNEL_COUNT = 16
111 };
112
113
114 std::vector<dcp::Channel> used_audio_channels ();
115
116
117 enum class MCASoundField
118 {
119         FIVE_POINT_ONE,
120         SEVEN_POINT_ONE,
121         OTHER
122 };
123
124
125 extern std::string channel_to_mca_id (Channel c, MCASoundField field);
126 extern Channel mca_id_to_channel (std::string);
127 extern std::string channel_to_mca_name (Channel c, MCASoundField field);
128 extern ASDCP::UL channel_to_mca_universal_label (Channel c, MCASoundField field, ASDCP::Dictionary const* dict);
129
130
131 enum class Effect
132 {
133         NONE,
134         BORDER,
135         SHADOW
136 };
137
138
139 extern std::string effect_to_string (Effect e);
140 extern Effect string_to_effect (std::string s);
141
142
143 /** Direction for subtitle test */
144 enum class Direction
145 {
146         LTR, ///< left-to-right
147         RTL, ///< right-to-left
148         TTB, ///< top-to-bottom
149         BTT  ///< bottom-to-top
150 };
151
152
153 extern std::string direction_to_string (Direction a);
154 extern Direction string_to_direction (std::string s);
155
156
157 enum class Eye
158 {
159         LEFT,
160         RIGHT
161 };
162
163
164 /** @class Fraction
165  *  @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
166  */
167 class Fraction
168 {
169 public:
170         /** Construct a fraction of 0/0 */
171         Fraction() = default;
172
173         explicit Fraction (std::string s);
174         /** Construct a fraction with a specified numerator and denominator.
175          *  @param n Numerator.
176          *  @param d Denominator.
177          */
178         Fraction (int n, int d) : numerator (n), denominator (d) {}
179
180         float as_float () const {
181                 return float (numerator) / denominator;
182         }
183
184         std::string as_string () const;
185
186         int numerator = 0;
187         int denominator = 0;
188 };
189
190
191 extern bool operator== (Fraction const & a, Fraction const & b);
192 extern bool operator!= (Fraction const & a, Fraction const & b);
193
194
195 enum class NoteType {
196         PROGRESS,
197         ERROR,
198         NOTE
199 };
200
201
202 enum class Standard {
203         INTEROP,
204         SMPTE
205 };
206
207
208 enum class Formulation {
209         MODIFIED_TRANSITIONAL_1,
210         MULTIPLE_MODIFIED_TRANSITIONAL_1,
211         DCI_ANY,
212         DCI_SPECIFIC,
213 };
214
215
216 std::string formulation_to_string (dcp::Formulation formulation);
217 dcp::Formulation string_to_formulation (std::string forumulation);
218
219
220 /** @class Colour
221  *  @brief An RGB colour
222  */
223 class Colour
224 {
225 public:
226         /** Construct a Colour, initialising it to black */
227         Colour() = default;
228
229         /** Construct a Colour from R, G and B.  The values run between
230          *  0 and 255.
231          */
232         Colour (int r_, int g_, int b_);
233
234         /** Construct a Colour from an ARGB hex string; the alpha value is ignored.
235          *  @param argb_hex A string of the form AARRGGBB, where e.g. RR is a two-character
236          *  hex value.
237          */
238         explicit Colour (std::string argb_hex);
239
240         int r = 0; ///< red component, from 0 to 255
241         int g = 0; ///< green component, from 0 to 255
242         int b = 0; ///< blue component, from 0 to 255
243
244         /** @return An RGB string of the form RRGGBB, where e.g. RR is a two-character
245          *  hex value.
246          */
247         std::string to_rgb_string () const;
248
249         /** @return An ARGB string of the form AARRGGBB, where e.g. RR is a two-character
250          *  hex value.  The alpha value will always be FF (ie 255; maximum alpha).
251          */
252         std::string to_argb_string () const;
253 };
254
255
256 extern bool operator== (Colour const & a, Colour const & b);
257 extern bool operator!= (Colour const & a, Colour const & b);
258
259
260 typedef boost::function<void (NoteType, std::string)> NoteHandler;
261
262
263 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
264  *  are considered equal
265  */
266 constexpr float ASPECT_ADJUST_EPSILON = 1e-3;
267
268
269 /** Maximum absolute difference between dcp::SubtitleString alignment values that
270  *  are considered equal.
271  */
272 constexpr float ALIGN_EPSILON = 1e-3;
273
274
275 /** Maximum absolute difference between dcp::SubtitleString space_before values that
276  *  are considered equal.
277  */
278 constexpr float SPACE_BEFORE_EPSILON = 1e-3;
279
280
281 constexpr float SIZE_EPSILON = 1e-3;
282 constexpr float OFFSET_EPSILON = 1e-3;
283 constexpr float SPACING_EPSILON = 1e-3;
284
285
286 enum class Marker {
287         FFOC, ///< first frame of composition
288         LFOC, ///< last frame of composition
289         FFTC, ///< first frame of title credits
290         LFTC, ///< last frame of title credits
291         FFOI, ///< first frame of intermission
292         LFOI, ///< last frame of intermission
293         FFEC, ///< first frame of end credits
294         LFEC, ///< last frame of end credits
295         FFMC, ///< first frame of moving credits
296         LFMC  ///< last frame of moving credits
297 };
298
299
300 std::string marker_to_string (Marker);
301 Marker marker_from_string (std::string);
302
303
304 enum class Status
305 {
306         FINAL, ///< final version
307         TEMP,  ///< temporary version (picture/sound unfinished)
308         PRE    ///< pre-release (picture/sound finished)
309 };
310
311
312 extern std::string status_to_string (Status s);
313 extern Status string_to_status (std::string s);
314
315
316 class ContentVersion
317 {
318 public:
319         ContentVersion ();
320
321         explicit ContentVersion (cxml::ConstNodePtr node);
322
323         explicit ContentVersion (std::string label_text_);
324
325         ContentVersion (std::string id_, std::string label_text_)
326                 : id (id_)
327                 , label_text (label_text_)
328         {}
329
330         void as_xml (xmlpp::Element* parent) const;
331
332         std::string id;
333         std::string label_text;
334 };
335
336
337 class Luminance
338 {
339 public:
340         enum class Unit {
341                 CANDELA_PER_SQUARE_METRE,
342                 FOOT_LAMBERT
343         };
344
345         Luminance (cxml::ConstNodePtr node);
346
347         Luminance (float value, Unit unit);
348
349         void set_value (float v);
350         void set_unit (Unit u) {
351                 _unit = u;
352         }
353
354         float value () const {
355                 return _value;
356         }
357
358         Unit unit () const {
359                 return _unit;
360         }
361
362         float value_in_foot_lamberts () const;
363
364         void as_xml (xmlpp::Element* parent, std::string ns) const;
365
366         static std::string unit_to_string (Unit u);
367         static Unit string_to_unit (std::string u);
368
369 private:
370         float _value;
371         Unit _unit;
372 };
373
374
375 bool operator== (Luminance const& a, Luminance const& b);
376
377
378 class MainSoundConfiguration
379 {
380 public:
381         explicit MainSoundConfiguration(std::string);
382         MainSoundConfiguration (MCASoundField field_, int channels);
383
384         MCASoundField field () const {
385                 return _field;
386         }
387
388         int channels () const {
389                 return _channels.size();
390         }
391
392         boost::optional<Channel> mapping (int index) const;
393         void set_mapping (int index, Channel channel);
394
395         std::string to_string () const;
396
397 private:
398         MCASoundField _field;
399         std::vector<boost::optional<Channel>> _channels;
400 };
401
402
403 }
404
405
406 #endif