Merge branch 'master' into cxml
[libdcp.git] / src / cpl.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <list>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/function.hpp>
23 #include <libxml++/libxml++.h>
24 #include "types.h"
25
26 namespace libdcp {
27
28 namespace parse {
29         class AssetMap;
30 }
31         
32 class Asset;
33 class Reel;
34 class XMLMetadata;
35
36 /** @brief A CPL within a DCP */
37 class CPL
38 {
39 public:
40         CPL (std::string directory, std::string name, ContentKind content_kind, int length, int frames_per_second);
41         CPL (std::string directory, std::string file, boost::shared_ptr<const parse::AssetMap> asset_map, bool require_mxfs = true);
42
43         void add_reel (boost::shared_ptr<const Reel> reel);
44         
45         /** @return the length in frames */
46         int length () const {
47                 return _length;
48         }
49
50         /** @return the type of the content, used by media servers
51          *  to categorise things (e.g. feature, trailer, etc.)
52          */
53         ContentKind content_kind () const {
54                 return _content_kind;
55         }
56
57         std::list<boost::shared_ptr<const Reel> > reels () const {
58                 return _reels;
59         }
60
61         /** @return the CPL's name, as will be presented on projector
62          *  media servers and theatre management systems.
63          */
64         std::string name () const {
65                 return _name;
66         }
67
68         /** @return the number of frames per second */
69         int frames_per_second () const {
70                 return _fps;
71         }
72
73         std::list<boost::shared_ptr<const Asset> > assets () const;
74         
75         bool equals (CPL const & other, EqualityOptions options, boost::function<void (NoteType, std::string)> note) const;
76         
77         void write_xml (XMLMetadata const &) const;
78         void write_to_assetmap (xmlpp::Node *) const;
79         void write_to_pkl (xmlpp::Node *) const;
80         
81 private:
82         std::string _directory;
83         /** the name of the DCP */
84         std::string _name;
85         /** the content kind of the CPL */
86         ContentKind _content_kind;
87         /** length in frames */
88         mutable int _length;
89         /** frames per second */
90         int _fps;
91         /** reels */
92         std::list<boost::shared_ptr<const Reel> > _reels;
93
94         /** our UUID */
95         std::string _uuid;
96         /** a SHA1 digest of our XML */
97         mutable std::string _digest;
98 };
99
100 }