Add some new channels to the enum.
[libdcp.git] / src / types.h
1 /*
2     Copyright (C) 2012-2019 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 /** @file  src/types.h
35  *  @brief Miscellaneous types.
36  */
37
38 #ifndef LIBDCP_TYPES_H
39 #define LIBDCP_TYPES_H
40
41 #include <libcxml/cxml.h>
42 #include <boost/shared_ptr.hpp>
43 #include <boost/function.hpp>
44 #include <string>
45
46 namespace xmlpp {
47         class Element;
48 }
49
50 namespace dcp
51 {
52
53 /** @struct Size
54  *  @brief The integer, two-dimensional size of something.
55  */
56 struct Size
57 {
58         Size ()
59                 : width (0)
60                 , height (0)
61         {}
62
63         Size (int w, int h)
64                 : width (w)
65                 , height (h)
66         {}
67
68         float ratio () const {
69                 return float (width) / height;
70         }
71
72         int width;
73         int height;
74 };
75
76 extern bool operator== (Size const & a, Size const & b);
77 extern bool operator!= (Size const & a, Size const & b);
78 extern std::ostream& operator<< (std::ostream& s, Size const & a);
79
80 /** Identifier for a sound channel */
81 enum Channel {
82         LEFT = 0,      ///< left
83         RIGHT = 1,     ///< right
84         CENTRE = 2,    ///< centre
85         LFE = 3,       ///< low-frequency effects (sub)
86         LS = 4,        ///< left surround
87         RS = 5,        ///< right surround
88         HI = 6,
89         VI = 7,
90         LC = 8,
91         RC = 9,
92         BSL = 10,
93         BSR = 11,
94         MOTION_DATA = 12,
95         SYNC_SIGNAL = 13,
96         SIGN_LANGUAGE = 14,
97         UNUSED = 15,
98         CHANNEL_COUNT = 16
99 };
100
101 enum ContentKind
102 {
103         FEATURE,
104         SHORT,
105         TRAILER,
106         TEST,
107         TRANSITIONAL,
108         RATING,
109         TEASER,
110         POLICY,
111         PUBLIC_SERVICE_ANNOUNCEMENT,
112         ADVERTISEMENT,
113         EPISODE,
114         PROMO
115 };
116
117 extern std::string content_kind_to_string (ContentKind kind);
118 extern ContentKind content_kind_from_string (std::string kind);
119
120 enum Effect
121 {
122         NONE,
123         BORDER,
124         SHADOW
125 };
126
127 extern std::string effect_to_string (Effect e);
128 extern Effect string_to_effect (std::string s);
129
130 enum HAlign
131 {
132         HALIGN_LEFT,   ///< horizontal position is distance from left of screen to left of subtitle
133         HALIGN_CENTER, ///< horizontal position is distance from centre of screen to centre of subtitle
134         HALIGN_RIGHT,  ///< horizontal position is distance from right of screen to right of subtitle
135 };
136
137 extern std::string halign_to_string (HAlign a);
138 extern HAlign string_to_halign (std::string s);
139
140 enum VAlign
141 {
142         VALIGN_TOP,    ///< vertical position is distance from top of screen to top of subtitle
143         VALIGN_CENTER, ///< vertical position is distance from centre of screen to centre of subtitle
144         VALIGN_BOTTOM  ///< vertical position is distance from bottom of screen to bottom of subtitle
145 };
146
147 extern std::string valign_to_string (VAlign a);
148 extern VAlign string_to_valign (std::string s);
149
150 /** Direction for subtitle test */
151 enum Direction
152 {
153         DIRECTION_LTR, ///< left-to-right
154         DIRECTION_RTL, ///< right-to-left
155         DIRECTION_TTB, ///< top-to-bottom
156         DIRECTION_BTT  ///< bottom-to-top
157 };
158
159 extern std::string direction_to_string (Direction a);
160 extern Direction string_to_direction (std::string s);
161
162 enum Eye
163 {
164         EYE_LEFT,
165         EYE_RIGHT
166 };
167
168 /** @class Fraction
169  *  @brief A fraction (i.e. a thing with an integer numerator and an integer denominator).
170  */
171 class Fraction
172 {
173 public:
174         /** Construct a fraction of 0/0 */
175         Fraction () : numerator (0), denominator (0) {}
176         explicit Fraction (std::string s);
177         /** Construct a fraction with a specified numerator and denominator.
178          *  @param n Numerator.
179          *  @param d Denominator.
180          */
181         Fraction (int n, int d) : numerator (n), denominator (d) {}
182
183         float as_float () const {
184                 return float (numerator) / denominator;
185         }
186
187         std::string as_string () const;
188
189         int numerator;
190         int denominator;
191 };
192
193 extern bool operator== (Fraction const & a, Fraction const & b);
194 extern bool operator!= (Fraction const & a, Fraction const & b);
195 extern std::ostream& operator<< (std::ostream& s, Fraction const & f);
196
197 /** @struct EqualityOptions
198  *  @brief  A class to describe what "equality" means for a particular test.
199  *
200  *  When comparing things, we want to be able to ignore some differences;
201  *  this class expresses those differences.
202  */
203 struct EqualityOptions
204 {
205         /** Construct an EqualityOptions where nothing at all can differ */
206         EqualityOptions ()
207                 : max_mean_pixel_error (0)
208                 , max_std_dev_pixel_error (0)
209                 , max_audio_sample_error (0)
210                 , cpl_annotation_texts_can_differ (false)
211                 , reel_annotation_texts_can_differ (false)
212                 , reel_hashes_can_differ (false)
213                 , issue_dates_can_differ (false)
214                 , load_font_nodes_can_differ (false)
215                 , keep_going (false)
216         {}
217
218         /** The maximum allowable mean difference in pixel value between two images */
219         double max_mean_pixel_error;
220         /** The maximum standard deviation of the differences in pixel value between two images */
221         double max_std_dev_pixel_error;
222         /** The maximum difference in audio sample value between two soundtracks */
223         int max_audio_sample_error;
224         /** true if the &lt;AnnotationText&gt; nodes of CPLs are allowed to differ */
225         bool cpl_annotation_texts_can_differ;
226         /** true if the &lt;AnnotationText&gt; nodes of Reels are allowed to differ */
227         bool reel_annotation_texts_can_differ;
228         /** true if <Hash>es in Reels can differ */
229         bool reel_hashes_can_differ;
230         /** true if IssueDate nodes can differ */
231         bool issue_dates_can_differ;
232         bool load_font_nodes_can_differ;
233         bool keep_going;
234 };
235
236 /* I've been unable to make mingw happy with ERROR as a symbol, so
237    I'm using a DCP_ prefix here.
238 */
239 enum NoteType {
240         DCP_PROGRESS,
241         DCP_ERROR,
242         DCP_NOTE
243 };
244
245 enum Standard {
246         INTEROP,
247         SMPTE
248 };
249
250 enum Formulation {
251         MODIFIED_TRANSITIONAL_1,
252         MULTIPLE_MODIFIED_TRANSITIONAL_1,
253         DCI_ANY,
254         DCI_SPECIFIC,
255         /** For testing: adds no AuthorizedDeviceInfo tag */
256         MODIFIED_TRANSITIONAL_TEST
257 };
258
259 /** @class Colour
260  *  @brief An RGB colour.
261  */
262 class Colour
263 {
264 public:
265         Colour ();
266         Colour (int r_, int g_, int b_);
267         explicit Colour (std::string argb_hex);
268
269         int r; ///< red component, from 0 to 255
270         int g; ///< green component, from 0 to 255
271         int b; ///< blue component, from 0 to 255
272
273         std::string to_rgb_string () const;
274         std::string to_argb_string () const;
275 };
276
277 extern bool operator== (Colour const & a, Colour const & b);
278 extern bool operator!= (Colour const & a, Colour const & b);
279 extern std::ostream & operator<< (std::ostream & s, Colour const & c);
280
281 typedef boost::function<void (NoteType, std::string)> NoteHandler;
282
283 /** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
284  *  are considered equal.
285  */
286 const float ASPECT_ADJUST_EPSILON = 1e-3;
287
288 /** Maximum absolute difference between dcp::SubtitleString alignment values that
289  *  are considered equal.
290  */
291 const float ALIGN_EPSILON = 1e-3;
292
293 enum Marker {
294         FFOC, ///< first frame of composition
295         LFOC, ///< last frame of composition
296         FFTC, ///< first frame of title credits
297         LFTC, ///< last frame of title credits
298         FFOI, ///< first frame of intermission
299         LFOI, ///< last frame of intermission
300         FFEC, ///< first frame of end credits
301         LFEC, ///< last frame of end credits
302         FFMC, ///< first frame of moving credits
303         LFMC  ///< last frame of moving credits
304 };
305
306 std::string marker_to_string (Marker);
307 Marker marker_from_string (std::string);
308
309 class Rating
310 {
311 public:
312         Rating (std::string agency_, std::string label_)
313                 : agency (agency_)
314                 , label (label_)
315         {}
316
317         explicit Rating (cxml::ConstNodePtr node);
318
319         void as_xml (xmlpp::Element* parent) const;
320
321         /** URI of the agency issuing the rating */
322         std::string agency;
323         /** Rating (e.g. PG, PG-13, 12A etc) */
324         std::string label;
325 };
326
327 extern bool operator== (Rating const & a, Rating const & b);
328 extern std::ostream& operator<< (std::ostream& s, Rating const & r);
329
330
331 class ContentVersion
332 {
333 public:
334         ContentVersion () {}
335
336         ContentVersion (std::string id_, std::string label_text_)
337                 : id (id_)
338                 , label_text (label_text_)
339         {}
340
341         void as_xml (xmlpp::Element* parent) const;
342
343         std::string id;
344         std::string label_text;
345 };
346
347 }
348
349 #endif