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