More licence fixups.
[libdcp.git] / src / reel_asset.h
1 /*
2     Copyright (C) 2014-2015 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
20 /** @file  src/reel_asset.h
21  *  @brief ReelAsset class.
22  */
23
24 #ifndef LIBDCP_REEL_ASSET_H
25 #define LIBDCP_REEL_ASSET_H
26
27 #include "object.h"
28 #include "util.h"
29 #include "ref.h"
30 #include <boost/shared_ptr.hpp>
31
32 namespace cxml {
33         class Node;
34 }
35
36 namespace xmlpp {
37         class Node;
38 }
39
40 namespace dcp {
41
42 class Asset;
43
44 /** @class ReelAsset
45  *  @brief An entry in a &lt;Reel&gt; which refers to a use of a piece of content.
46  *
47  *  This class encapsulates the XML that exists in a &lt;Reel&gt; to say
48  *  that a piece of content is used in this reel.  It does not
49  *  describe the content itself (but links to an Asset object which does).
50  */
51 class ReelAsset : public Object
52 {
53 public:
54         ReelAsset ();
55         ReelAsset (boost::shared_ptr<Asset> asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point);
56         ReelAsset (boost::shared_ptr<const cxml::Node>);
57
58         virtual void write_to_cpl (xmlpp::Node* node, Standard standard) const;
59         virtual bool equals (boost::shared_ptr<const ReelAsset>, EqualityOptions, NoteHandler) const;
60
61         /** @return a Ref to our actual asset */
62         Ref const & asset_ref () const {
63                 return _asset_ref;
64         }
65
66         /** @return a Ref to our actual asset */
67         Ref & asset_ref () {
68                 return _asset_ref;
69         }
70
71         Fraction edit_rate () const {
72                 return _edit_rate;
73         }
74
75         int64_t intrinsic_duration () const {
76                 return _intrinsic_duration;
77         }
78
79         int64_t entry_point () const {
80                 return _entry_point;
81         }
82
83         int64_t duration () const {
84                 return _duration;
85         }
86
87 protected:
88
89         template <class T>
90         boost::shared_ptr<T> asset_of_type () const {
91                 return boost::dynamic_pointer_cast<T> (_asset_ref.asset ());
92         }
93
94         template <class T>
95         boost::shared_ptr<T> asset_of_type () {
96                 return boost::dynamic_pointer_cast<T> (_asset_ref.asset ());
97         }
98
99         /** @return the node name that this asset uses in the CPL's &lt;Reel&gt; node
100          *  e.g. MainPicture, MainSound etc.
101          */
102         virtual std::string cpl_node_name () const = 0;
103
104         /** @return Any attribute that should be used on the asset's node in the
105          *  CPL.
106          */
107         virtual std::pair<std::string, std::string> cpl_node_attribute (Standard) const;
108
109         /** Reference to the asset (MXF or XML file) that this reel entry
110          *  applies to.
111          */
112         Ref _asset_ref;
113
114 private:
115         std::string _annotation_text; ///< The &lt;AnnotationText&gt; from the reel's entry for this asset
116         Fraction _edit_rate;          ///< The &lt;EditRate&gt; from the reel's entry for this asset
117         int64_t _intrinsic_duration;  ///< The &lt;IntrinsicDuration&gt; from the reel's entry for this asset
118         int64_t _entry_point;         ///< The &lt;EntryPoint&gt; from the reel's entry for this asset
119         int64_t _duration;            ///< The &lt;Duration&gt; from the reel's entry for this asset
120         std::string _hash;            ///< The &lt;Hash&gt; from the reel's entry for this asset
121 };
122
123 }
124
125 #endif