Basics of selecting 'tracks' for CCAPs.
[dcpomatic.git] / src / lib / text_content.h
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 #ifndef DCPOMATIC_CAPTION_CONTENT_H
22 #define DCPOMATIC_CAPTION_CONTENT_H
23
24 #include "content_part.h"
25 #include "dcp_text_track.h"
26 #include <libcxml/cxml.h>
27 #include <dcp/types.h>
28 #include <boost/signals2.hpp>
29
30 class Font;
31
32 class TextContentProperty
33 {
34 public:
35         static int const X_OFFSET;
36         static int const Y_OFFSET;
37         static int const X_SCALE;
38         static int const Y_SCALE;
39         static int const USE;
40         static int const BURN;
41         static int const LANGUAGE;
42         static int const FONTS;
43         static int const COLOUR;
44         static int const EFFECT;
45         static int const EFFECT_COLOUR;
46         static int const LINE_SPACING;
47         static int const FADE_IN;
48         static int const FADE_OUT;
49         static int const OUTLINE_WIDTH;
50         static int const TYPE;
51         static int const DCP_TRACK;
52 };
53
54 /** @class TextContent
55  *  @brief Description of how some text content should be presented.
56  *
57  *  There are `bitmap' subtitles and `plain' subtitles (plain text),
58  *  and not all of the settings in this class correspond to both types.
59  */
60 class TextContent : public ContentPart
61 {
62 public:
63         TextContent (Content* parent, TextType type, TextType original_type);
64         TextContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
65
66         void as_xml (xmlpp::Node *) const;
67         std::string identifier () const;
68         void take_settings_from (boost::shared_ptr<const TextContent> c);
69
70         void add_font (boost::shared_ptr<Font> font);
71
72         void set_use (bool);
73         void set_burn (bool);
74         void set_x_offset (double);
75         void set_y_offset (double);
76         void set_x_scale (double);
77         void set_y_scale (double);
78         void set_language (std::string language);
79         void set_colour (dcp::Colour);
80         void unset_colour ();
81         void set_effect (dcp::Effect);
82         void unset_effect ();
83         void set_effect_colour (dcp::Colour);
84         void unset_effect_colour ();
85         void set_line_spacing (double s);
86         void set_fade_in (ContentTime);
87         void unset_fade_in ();
88         void set_fade_out (ContentTime);
89         void set_outline_width (int);
90         void unset_fade_out ();
91         void set_type (TextType type);
92         void set_dcp_track (DCPTextTrack track);
93         void unset_dcp_track ();
94
95         bool use () const {
96                 boost::mutex::scoped_lock lm (_mutex);
97                 return _use;
98         }
99
100         bool burn () const {
101                 boost::mutex::scoped_lock lm (_mutex);
102                 return _burn;
103         }
104
105         double x_offset () const {
106                 boost::mutex::scoped_lock lm (_mutex);
107                 return _x_offset;
108         }
109
110         double y_offset () const {
111                 boost::mutex::scoped_lock lm (_mutex);
112                 return _y_offset;
113         }
114
115         double x_scale () const {
116                 boost::mutex::scoped_lock lm (_mutex);
117                 return _x_scale;
118         }
119
120         double y_scale () const {
121                 boost::mutex::scoped_lock lm (_mutex);
122                 return _y_scale;
123         }
124
125         std::list<boost::shared_ptr<Font> > fonts () const {
126                 boost::mutex::scoped_lock lm (_mutex);
127                 return _fonts;
128         }
129
130         std::string language () const {
131                 boost::mutex::scoped_lock lm (_mutex);
132                 return _language;
133         }
134
135         boost::optional<dcp::Colour> colour () const {
136                 boost::mutex::scoped_lock lm (_mutex);
137                 return _colour;
138         }
139
140         boost::optional<dcp::Effect> effect () const {
141                 boost::mutex::scoped_lock lm (_mutex);
142                 return _effect;
143         }
144
145         boost::optional<dcp::Colour> effect_colour () const {
146                 boost::mutex::scoped_lock lm (_mutex);
147                 return _effect_colour;
148         }
149
150         double line_spacing () const {
151                 boost::mutex::scoped_lock lm (_mutex);
152                 return _line_spacing;
153         }
154
155         boost::optional<ContentTime> fade_in () const {
156                 boost::mutex::scoped_lock lm (_mutex);
157                 return _fade_in;
158         }
159
160         boost::optional<ContentTime> fade_out () const {
161                 boost::mutex::scoped_lock lm (_mutex);
162                 return _fade_out;
163         }
164
165         int outline_width () const {
166                 boost::mutex::scoped_lock lm (_mutex);
167                 return _outline_width;
168         }
169
170         TextType type () const {
171                 boost::mutex::scoped_lock lm (_mutex);
172                 return _type;
173         }
174
175         TextType original_type () const {
176                 boost::mutex::scoped_lock lm (_mutex);
177                 return _original_type;
178         }
179
180         boost::optional<DCPTextTrack> dcp_track () const {
181                 boost::mutex::scoped_lock lm (_mutex);
182                 return _dcp_track;
183         }
184
185         static std::list<boost::shared_ptr<TextContent> > from_xml (Content* parent, cxml::ConstNodePtr, int version);
186
187 protected:
188         /** subtitle language (e.g. "German") or empty if it is not known */
189         std::string _language;
190
191 private:
192         friend struct ffmpeg_pts_offset_test;
193
194         TextContent (Content* parent, cxml::ConstNodePtr, int version);
195         void font_changed ();
196         void connect_to_fonts ();
197
198         std::list<boost::signals2::connection> _font_connections;
199
200         bool _use;
201         bool _burn;
202         /** x offset for placing subtitles, as a proportion of the container width;
203          * +ve is further right, -ve is further left.
204          */
205         double _x_offset;
206         /** y offset for placing subtitles, as a proportion of the container height;
207          *  +ve is further down the frame, -ve is further up.
208          */
209         double _y_offset;
210         /** x scale factor to apply to subtitles */
211         double _x_scale;
212         /** y scale factor to apply to subtitles */
213         double _y_scale;
214         std::list<boost::shared_ptr<Font> > _fonts;
215         boost::optional<dcp::Colour> _colour;
216         boost::optional<dcp::Effect> _effect;
217         boost::optional<dcp::Colour> _effect_colour;
218         /** scaling factor for line spacing; 1 is "standard", < 1 is closer together, > 1 is further apart */
219         double _line_spacing;
220         boost::optional<ContentTime> _fade_in;
221         boost::optional<ContentTime> _fade_out;
222         int _outline_width;
223         /** what these captions will be used for in the output DCP (not necessarily what
224          *  they were originally).
225          */
226         TextType _type;
227         /** the original type of these captions in their content */
228         TextType _original_type;
229         /** the track of closed captions that this content should be put in, or empty to put in the default (only) track */
230         boost::optional<DCPTextTrack> _dcp_track;
231 };
232
233 #endif