More licence fixups.
[libdcp.git] / src / smpte_subtitle_asset.h
1 /*
2     Copyright (C) 2012-2015 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
20 /** @file  src/smpte_subtitle_asset.h
21  *  @brief SMPTESubtitleAsset class.
22  */
23
24 #include "subtitle_asset.h"
25 #include "local_time.h"
26 #include "mxf.h"
27 #include <boost/filesystem.hpp>
28
29 namespace ASDCP {
30         namespace TimedText {
31                 class MXFReader;
32         }
33 }
34
35 namespace dcp {
36
37 class SMPTELoadFontNode;
38
39 /** @class SMPTESubtitleAsset
40  *  @brief A set of subtitles to be read and/or written in the SMPTE format.
41  */
42 class SMPTESubtitleAsset : public SubtitleAsset, public MXF
43 {
44 public:
45         SMPTESubtitleAsset ();
46
47         /** @param file File name
48          */
49         SMPTESubtitleAsset (boost::filesystem::path file);
50
51         bool equals (
52                 boost::shared_ptr<const Asset>,
53                 EqualityOptions,
54                 NoteHandler note
55                 ) const;
56
57         std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const;
58
59         std::string xml_as_string () const;
60         void write (boost::filesystem::path path) const;
61         void add (SubtitleString);
62         void add_font (std::string id, boost::filesystem::path file);
63
64         void set_content_title_text (std::string t) {
65                 _content_title_text = t;
66         }
67
68         void set_language (std::string l) {
69                 _language = l;
70         }
71
72         void set_issue_date (LocalTime t) {
73                 _issue_date = t;
74         }
75
76         void set_reel_number (int r) {
77                 _reel_number = r;
78         }
79
80         void set_edit_rate (Fraction e) {
81                 _edit_rate = e;
82         }
83
84         void set_time_code_rate (int t) {
85                 _time_code_rate = t;
86         }
87
88         void set_start_time (Time t) {
89                 _start_time = t;
90         }
91
92         void set_intrinsic_duration (int64_t d) {
93                 _intrinsic_duration = d;
94         }
95
96         /** @return title of the film that these subtitles are for,
97          *  to be presented to the user.
98          */
99         std::string content_title_text () const {
100                 return _content_title_text;
101         }
102
103         /** @return language as a xs:language, if one was specified */
104         boost::optional<std::string> language () const {
105                 return _language;
106         }
107
108         /** @return annotation text, to be presented to the user */
109         boost::optional<std::string> annotation_text () const {
110                 return _annotation_text;
111         }
112
113         /** @return file creation time and date */
114         LocalTime issue_date () const {
115                 return _issue_date;
116         }
117
118         boost::optional<int> reel_number () const {
119                 return _reel_number;
120         }
121
122         Fraction edit_rate () const {
123                 return _edit_rate;
124         }
125
126         /** @return subdivision of 1 second that is used for subtitle times;
127          *  e.g. a time_code_rate of 250 means that a subtitle time of 0:0:0:001
128          *  represents 4ms.
129          */
130         int time_code_rate () const {
131                 return _time_code_rate;
132         }
133
134         boost::optional<Time> start_time () const {
135                 return _start_time;
136         }
137
138         static bool valid_mxf (boost::filesystem::path);
139
140 protected:
141
142         std::string pkl_type (Standard) const {
143                 return "application/mxf";
144         }
145
146 private:
147         void read_fonts (boost::shared_ptr<ASDCP::TimedText::MXFReader>);
148
149         /** The total length of this content in video frames.  The amount of
150          *  content presented may be less than this.
151          */
152         int64_t _intrinsic_duration;
153         std::string _content_title_text;
154         boost::optional<std::string> _language;
155         boost::optional<std::string> _annotation_text;
156         LocalTime _issue_date;
157         boost::optional<int> _reel_number;
158         Fraction _edit_rate;
159         int _time_code_rate;
160         boost::optional<Time> _start_time;
161
162         std::list<boost::shared_ptr<SMPTELoadFontNode> > _load_font_nodes;
163 };
164
165 }