More automated renaming.
[dcpomatic.git] / src / lib / types.cc
1 /*
2     Copyright (C) 2013-2018 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 "types.h"
22 #include "compose.hpp"
23 #include "dcpomatic_assert.h"
24 #include <dcp/raw_convert.h>
25 #include <libxml++/libxml++.h>
26 #include <libcxml/cxml.h>
27
28 #include "i18n.h"
29
30 using std::max;
31 using std::min;
32 using std::string;
33 using boost::shared_ptr;
34 using dcp::raw_convert;
35
36 bool operator== (Crop const & a, Crop const & b)
37 {
38         return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom);
39 }
40
41 bool operator!= (Crop const & a, Crop const & b)
42 {
43         return !(a == b);
44 }
45
46 /** @param r Resolution.
47  *  @return Untranslated string representation.
48  */
49 string
50 resolution_to_string (Resolution r)
51 {
52         switch (r) {
53         case RESOLUTION_2K:
54                 return "2K";
55         case RESOLUTION_4K:
56                 return "4K";
57         }
58
59         DCPOMATIC_ASSERT (false);
60         return "";
61 }
62
63
64 Resolution
65 string_to_resolution (string s)
66 {
67         if (s == "2K") {
68                 return RESOLUTION_2K;
69         }
70
71         if (s == "4K") {
72                 return RESOLUTION_4K;
73         }
74
75         DCPOMATIC_ASSERT (false);
76         return RESOLUTION_2K;
77 }
78
79 Crop::Crop (shared_ptr<cxml::Node> node)
80 {
81         left = node->number_child<int> ("LeftCrop");
82         right = node->number_child<int> ("RightCrop");
83         top = node->number_child<int> ("TopCrop");
84         bottom = node->number_child<int> ("BottomCrop");
85 }
86
87 void
88 Crop::as_xml (xmlpp::Node* node) const
89 {
90         node->add_child("LeftCrop")->add_child_text (raw_convert<string> (left));
91         node->add_child("RightCrop")->add_child_text (raw_convert<string> (right));
92         node->add_child("TopCrop")->add_child_text (raw_convert<string> (top));
93         node->add_child("BottomCrop")->add_child_text (raw_convert<string> (bottom));
94 }
95
96 TextType
97 string_to_caption_type (string s)
98 {
99         if (s == "open") {
100                 return CAPTION_OPEN;
101         } else if (s == "closed") {
102                 return CAPTION_CLOSED;
103         } else {
104                 throw MetadataError (String::compose ("Unknown caption type %1", s));
105         }
106 }
107
108 string
109 caption_type_to_string (TextType t)
110 {
111         switch (t) {
112         case CAPTION_OPEN:
113                 return "open";
114         case CAPTION_CLOSED:
115                 return "closed";
116         default:
117                 DCPOMATIC_ASSERT (false);
118         }
119 }
120
121 string
122 caption_type_to_name (TextType t)
123 {
124         switch (t) {
125         case CAPTION_OPEN:
126                 return _("Subtitles");
127         case CAPTION_CLOSED:
128                 return _("Closed captions");
129         default:
130                 DCPOMATIC_ASSERT (false);
131         }
132 }
133
134 string
135 video_frame_type_to_string (VideoFrameType t)
136 {
137         switch (t) {
138         case VIDEO_FRAME_TYPE_2D:
139                 return "2d";
140         case VIDEO_FRAME_TYPE_3D:
141                 return "3d";
142         case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT:
143                 return "3d-left-right";
144         case VIDEO_FRAME_TYPE_3D_TOP_BOTTOM:
145                 return "3d-top-bottom";
146         case VIDEO_FRAME_TYPE_3D_ALTERNATE:
147                 return "3d-alternate";
148         case VIDEO_FRAME_TYPE_3D_LEFT:
149                 return "3d-left";
150         case VIDEO_FRAME_TYPE_3D_RIGHT:
151                 return "3d-right";
152         default:
153                 DCPOMATIC_ASSERT (false);
154         }
155
156         DCPOMATIC_ASSERT (false);
157 }
158
159 VideoFrameType
160 string_to_video_frame_type (string s)
161 {
162         if (s == "2d") {
163                 return VIDEO_FRAME_TYPE_2D;
164         } else if (s == "3d") {
165                 return VIDEO_FRAME_TYPE_3D;
166         } else if (s == "3d-left-right") {
167                 return VIDEO_FRAME_TYPE_3D_LEFT_RIGHT;
168         } else if (s == "3d-top-bottom") {
169                 return VIDEO_FRAME_TYPE_3D_TOP_BOTTOM;
170         } else if (s == "3d-alternate") {
171                 return VIDEO_FRAME_TYPE_3D_ALTERNATE;
172         } else if (s == "3d-left") {
173                 return VIDEO_FRAME_TYPE_3D_LEFT;
174         } else if (s == "3d-right") {
175                 return VIDEO_FRAME_TYPE_3D_RIGHT;
176         }
177
178         DCPOMATIC_ASSERT (false);
179 }