2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/reel_asset.cc
21 * @brief ReelAsset class.
24 #include "raw_convert.h"
25 #include "reel_asset.h"
27 #include "compose.hpp"
28 #include <libcxml/cxml.h>
29 #include <libxml++/libxml++.h>
35 using std::stringstream;
37 using boost::shared_ptr;
40 ReelAsset::ReelAsset ()
42 , _edit_rate (Fraction (24, 1))
43 , _intrinsic_duration (0)
50 /** Construct a ReelAsset.
51 * @param asset Asset that this ReelAsset refers to.
52 * @param edit_rate Edit rate for the asset.
53 * @param intrinsic_duration Intrinsic duration of this asset.
54 * @param entry_point Entry point to use in that asset.
56 ReelAsset::ReelAsset (shared_ptr<Asset> asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
57 : Object (asset->id ())
59 , _edit_rate (edit_rate)
60 , _intrinsic_duration (intrinsic_duration)
61 , _entry_point (entry_point)
62 , _duration (intrinsic_duration - entry_point)
63 , _hash (asset->hash ())
65 /* default _annotation_text to the leaf name of our file */
66 _annotation_text = asset->file().leaf().string ();
69 ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node)
70 : Object (node->string_child ("Id"))
72 , _annotation_text (node->optional_string_child ("AnnotationText").get_value_or (""))
73 , _edit_rate (Fraction (node->string_child ("EditRate")))
74 , _intrinsic_duration (node->number_child<int64_t> ("IntrinsicDuration"))
75 , _entry_point (node->number_child<int64_t> ("EntryPoint"))
76 , _duration (node->number_child<int64_t> ("Duration"))
77 , _hash (node->optional_string_child ("Hash").get_value_or (""))
79 if (_id.length() > 9) {
81 _asset_ref.set_id (_id);
86 ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
88 pair<string, string> const attr = cpl_node_attribute (standard);
89 xmlpp::Element* a = node->add_child (cpl_node_name ());
90 if (!attr.first.empty ()) {
91 a->set_attribute (attr.first, attr.second);
93 a->add_child("Id")->add_child_text ("urn:uuid:" + _id);
94 a->add_child("AnnotationText")->add_child_text (_annotation_text);
95 a->add_child("EditRate")->add_child_text (String::compose ("%1 %2", _edit_rate.numerator, _edit_rate.denominator));
96 a->add_child("IntrinsicDuration")->add_child_text (raw_convert<string> (_intrinsic_duration));
97 a->add_child("EntryPoint")->add_child_text (raw_convert<string> (_entry_point));
98 a->add_child("Duration")->add_child_text (raw_convert<string> (_duration));
99 a->add_child("Hash")->add_child_text (_asset_ref.asset()->hash ());
103 ReelAsset::cpl_node_attribute (Standard) const
105 return make_pair ("", "");
109 ReelAsset::equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, NoteHandler note) const
111 if (_annotation_text != other->_annotation_text) {
113 s << "Reel: annotation texts differ (" << _annotation_text << " vs " << other->_annotation_text << ")\n";
114 if (!opt.reel_annotation_texts_can_differ) {
115 note (DCP_ERROR, s.str ());
118 note (DCP_NOTE, s.str ());
122 if (_edit_rate != other->_edit_rate) {
123 note (DCP_ERROR, "Reel: edit rates differ");
127 if (_intrinsic_duration != other->_intrinsic_duration) {
128 note (DCP_ERROR, String::compose ("Reel: intrinsic durations differ (%1 vs %2)", _intrinsic_duration, other->_intrinsic_duration));
132 if (_entry_point != other->_entry_point) {
133 note (DCP_ERROR, "Reel: entry points differ");
137 if (_duration != other->_duration) {
138 note (DCP_ERROR, "Reel: durations differ");
142 if (_hash != other->_hash) {
143 if (!opt.reel_hashes_can_differ) {
144 note (DCP_ERROR, "Reel: hashes differ");
147 note (DCP_NOTE, "Reel: hashes differ");
151 if (_asset_ref.resolved () && other->_asset_ref.resolved ()) {
152 return _asset_ref->equals (other->_asset_ref.asset(), opt, note);