libdcp
reel_markers_asset.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2019-2021 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 
40 #include "dcp_assert.h"
41 #include "raw_convert.h"
42 #include "reel_markers_asset.h"
43 #include "warnings.h"
44 LIBDCP_DISABLE_WARNINGS
45 #include <libxml++/libxml++.h>
46 LIBDCP_ENABLE_WARNINGS
47 
48 
49 using std::string;
50 using std::map;
51 using std::max;
52 using boost::optional;
53 using std::shared_ptr;
54 using namespace dcp;
55 
56 
57 ReelMarkersAsset::ReelMarkersAsset (Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
58  : ReelAsset (make_uuid(), edit_rate, intrinsic_duration, entry_point)
59 {
60 
61 }
62 
63 
64 ReelMarkersAsset::ReelMarkersAsset (cxml::ConstNodePtr node)
65  : ReelAsset (node)
66 {
67  auto list = node->node_child ("MarkerList");
68  DCP_ASSERT (list);
69  for (auto i: list->node_children("Marker")) {
70  set (marker_from_string(i->string_child("Label")), dcp::Time(i->number_child<int64_t>("Offset"), edit_rate().as_float(), edit_rate().numerator));
71  }
72 }
73 
74 
75 string
76 ReelMarkersAsset::cpl_node_name (Standard) const
77 {
78  return "MainMarkers";
79 }
80 
81 
82 void
83 ReelMarkersAsset::set (Marker m, Time t)
84 {
85  _markers[m] = t;
86 }
87 
88 
89 void
90 ReelMarkersAsset::unset (Marker m)
91 {
92  _markers.erase (m);
93 }
94 
95 
96 optional<Time>
97 ReelMarkersAsset::get (Marker m) const
98 {
99  auto i = _markers.find (m);
100  if (i == _markers.end ()) {
101  return {};
102  }
103  return i->second;
104 }
105 
106 
107 xmlpp::Node*
108 ReelMarkersAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
109 {
110  int const tcr = edit_rate().numerator / edit_rate().denominator;
111  auto asset = ReelAsset::write_to_cpl (node, standard);
112  auto ml = asset->add_child("MarkerList");
113  for (auto const& i: _markers) {
114  auto m = ml->add_child("Marker");
115  m->add_child("Label")->add_child_text(marker_to_string(i.first));
116  m->add_child("Offset")->add_child_text(raw_convert<string>(i.second.as_editable_units_ceil(tcr)));
117  }
118 
119  return asset;
120 }
121 
122 bool
123 ReelMarkersAsset::equals (shared_ptr<const ReelMarkersAsset> other, EqualityOptions opt, NoteHandler note) const
124 {
125  if (!asset_equals(other, opt, note)) {
126  return false;
127  }
128 
129  if (get(Marker::FFOC) != other->get(Marker::FFOC) ||
130  get(Marker::LFOC) != other->get(Marker::LFOC) ||
131  get(Marker::FFTC) != other->get(Marker::FFTC) ||
132  get(Marker::LFTC) != other->get(Marker::LFTC) ||
133  get(Marker::FFOI) != other->get(Marker::FFOI) ||
134  get(Marker::LFOI) != other->get(Marker::LFOI) ||
135  get(Marker::FFEC) != other->get(Marker::FFEC) ||
136  get(Marker::LFEC) != other->get(Marker::LFEC) ||
137  get(Marker::FFMC) != other->get(Marker::FFMC) ||
138  get(Marker::LFMC) != other->get(Marker::LFMC)) {
139  return false;
140  }
141 
142  return true;
143 }
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Definition: types.h:214
An entry in a <Reel> which refers to a use of a piece of content.
Definition: reel_asset.h:74
A representation of time within a DCP.
Definition: dcp_time.h:73
DCP_ASSERT macro.
Namespace for everything in libdcp.
Definition: array_data.h:50
Marker
Definition: types.h:358
@ FFOI
first frame of intermission
@ FFEC
first frame of end credits
@ LFMC
last frame of moving credits
@ LFOI
last frame of intermission
@ FFMC
first frame of moving credits
@ FFTC
first frame of title credits
@ LFOC
last frame of composition
@ FFOC
first frame of composition
@ LFEC
last frame of end credits
@ LFTC
last frame of title credits
Methods for conversion to/from string.
A class to describe what "equality" means for a particular test.
Definition: types.h:249