std::shared_ptr
[dcpomatic.git] / src / lib / atmos_content.cc
1 /*
2     Copyright (C) 2020 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
22 #include "atmos_content.h"
23 #include "warnings.h"
24 #include <dcp/raw_convert.h>
25 DCPOMATIC_DISABLE_WARNINGS
26 #include <libxml++/libxml++.h>
27 DCPOMATIC_ENABLE_WARNINGS
28
29
30 using std::string;
31 using std::shared_ptr;
32
33
34 int const AtmosContentProperty::EDIT_RATE = 700;
35
36
37 AtmosContent::AtmosContent (Content* parent)
38         : ContentPart (parent)
39         , _length (0)
40 {
41
42 }
43
44
45 AtmosContent::AtmosContent (Content* parent, cxml::ConstNodePtr node)
46         : ContentPart (parent)
47 {
48         _length = node->number_child<Frame>("AtmosLength");
49         _edit_rate = dcp::Fraction (node->string_child("AtmosEditRate"));
50 }
51
52
53 shared_ptr<AtmosContent>
54 AtmosContent::from_xml (Content* parent, cxml::ConstNodePtr node)
55 {
56         if (!node->optional_node_child("AtmosLength")) {
57                 return shared_ptr<AtmosContent>();
58         }
59
60         return shared_ptr<AtmosContent> (new AtmosContent(parent, node));
61 }
62
63
64 void
65 AtmosContent::as_xml (xmlpp::Node* node) const
66 {
67         node->add_child("AtmosLength")->add_child_text(dcp::raw_convert<string>(_length));
68         node->add_child("AtmosEditRate")->add_child_text(_edit_rate.as_string());
69 }
70
71
72 void
73 AtmosContent::set_length (Frame len)
74 {
75         maybe_set (_length, len, ContentProperty::LENGTH);
76 }
77
78
79 void
80 AtmosContent::set_edit_rate (dcp::Fraction rate)
81 {
82         maybe_set (_edit_rate, rate, AtmosContentProperty::EDIT_RATE);
83 }
84