Add EqualityOptions option to ignore differences in LoadFont nodes.
[libdcp.git] / src / reel_markers_asset.cc
1 /*
2     Copyright (C) 2019 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     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 #include "reel_markers_asset.h"
35 #include "raw_convert.h"
36 #include "dcp_assert.h"
37 #include <libxml++/libxml++.h>
38 #include <boost/foreach.hpp>
39
40 using std::string;
41 using std::map;
42 using std::max;
43 using boost::optional;
44 using boost::shared_ptr;
45 using namespace dcp;
46
47 ReelMarkersAsset::ReelMarkersAsset (Fraction edit_rate, int64_t entry_point)
48         : ReelAsset (make_uuid(), edit_rate, 0, entry_point)
49 {
50
51 }
52
53 ReelMarkersAsset::ReelMarkersAsset (cxml::ConstNodePtr node)
54         : ReelAsset (node)
55 {
56         cxml::ConstNodePtr list = node->node_child ("MarkerList");
57         DCP_ASSERT (list);
58         BOOST_FOREACH (cxml::ConstNodePtr i, list->node_children("Marker")) {
59                 set (marker_from_string(i->string_child("Label")), dcp::Time(i->number_child<int64_t>("Offset"), edit_rate().as_float(), edit_rate().numerator));
60         }
61 }
62
63 string
64 ReelMarkersAsset::cpl_node_name (Standard) const
65 {
66         return "MainMarkers";
67 }
68
69 void
70 ReelMarkersAsset::set (Marker m, Time t)
71 {
72         _markers[m] = t;
73         update_duration ();
74 }
75
76 void
77 ReelMarkersAsset::unset (Marker m)
78 {
79         _markers.erase (m);
80         update_duration ();
81 }
82
83 optional<Time>
84 ReelMarkersAsset::get (Marker m) const
85 {
86         map<Marker, Time>::const_iterator i = _markers.find (m);
87         if (i == _markers.end ()) {
88                 return optional<Time>();
89         }
90         return i->second;
91 }
92
93 void
94 ReelMarkersAsset::update_duration ()
95 {
96         int const tcr = edit_rate().numerator / edit_rate().denominator;
97         _intrinsic_duration = 0;
98         for (map<Marker, Time>::const_iterator i = _markers.begin(); i != _markers.end(); ++i) {
99                 _intrinsic_duration = max(_intrinsic_duration, i->second.as_editable_units(tcr));
100         }
101         _duration = _intrinsic_duration;
102 }
103
104 xmlpp::Node*
105 ReelMarkersAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
106 {
107         int const tcr = edit_rate().numerator / edit_rate().denominator;
108         xmlpp::Node* asset = write_to_cpl_asset (node, standard, optional<string>());
109         xmlpp::Node* ml = asset->add_child("MarkerList");
110         for (map<Marker, Time>::const_iterator i = _markers.begin(); i != _markers.end(); ++i) {
111                 xmlpp::Node* m = ml->add_child("Marker");
112                 m->add_child("Label")->add_child_text (marker_to_string(i->first));
113                 m->add_child("Offset")->add_child_text (raw_convert<string>(i->second.as_editable_units(tcr)));
114         }
115
116         return asset;
117 }
118
119 bool
120 ReelMarkersAsset::equals (shared_ptr<const ReelMarkersAsset> other, EqualityOptions opt, NoteHandler note) const
121 {
122         if (!asset_equals(other, opt, note)) {
123                 return false;
124         }
125
126         if (get(FFOC) != other->get(FFOC) ||
127             get(LFOC) != other->get(LFOC) ||
128             get(FFTC) != other->get(FFTC) ||
129             get(LFTC) != other->get(LFTC) ||
130             get(FFOI) != other->get(FFOI) ||
131             get(LFOI) != other->get(LFOI) ||
132             get(FFEC) != other->get(FFEC) ||
133             get(LFEC) != other->get(LFEC) ||
134             get(FFMC) != other->get(FFMC) ||
135             get(LFMC) != other->get(LFMC)) {
136                 return false;
137         }
138
139         return true;
140 }