Some allowances for video/audio/subtitle possibly being null.
[dcpomatic.git] / src / lib / text_subtitle_content.cc
1 /*
2     Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "text_subtitle_content.h"
21 #include "util.h"
22 #include "text_subtitle.h"
23 #include "film.h"
24 #include "font.h"
25 #include "raw_convert.h"
26 #include "subtitle_content.h"
27 #include <libxml++/libxml++.h>
28 #include <iostream>
29
30 #include "i18n.h"
31
32 using std::string;
33 using std::cout;
34 using boost::shared_ptr;
35
36 std::string const TextSubtitleContent::font_id = "font";
37
38 TextSubtitleContent::TextSubtitleContent (shared_ptr<const Film> film, boost::filesystem::path path)
39         : Content (film, path)
40 {
41         subtitle.reset (new SubtitleContent (this, film));
42 }
43
44 TextSubtitleContent::TextSubtitleContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
45         : Content (film, node)
46         , _length (node->number_child<ContentTime::Type> ("Length"))
47 {
48         subtitle = SubtitleContent::from_xml (this, film, node, version);
49 }
50
51 void
52 TextSubtitleContent::examine (boost::shared_ptr<Job> job)
53 {
54         Content::examine (job);
55         TextSubtitle s (shared_from_this ());
56
57         /* Default to turning these subtitles on */
58         subtitle->set_use (true);
59
60         boost::mutex::scoped_lock lm (_mutex);
61         _length = s.length ();
62         subtitle->add_font (shared_ptr<Font> (new Font (font_id)));
63 }
64
65 string
66 TextSubtitleContent::summary () const
67 {
68         return path_summary() + " " + _("[subtitles]");
69 }
70
71 string
72 TextSubtitleContent::technical_summary () const
73 {
74         return Content::technical_summary() + " - " + _("Text subtitles");
75 }
76
77 void
78 TextSubtitleContent::as_xml (xmlpp::Node* node) const
79 {
80         node->add_child("Type")->add_child_text ("TextSubtitle");
81         Content::as_xml (node);
82
83         if (subtitle) {
84                 subtitle->as_xml (node);
85         }
86
87         node->add_child("Length")->add_child_text (raw_convert<string> (_length.get ()));
88 }
89
90 DCPTime
91 TextSubtitleContent::full_length () const
92 {
93         FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate ());
94         return DCPTime (_length, frc);
95 }