Use boost starts/ends with methods.
[libdcp.git] / src / dcp.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 /** @file  src/dcp.h
21  *  @brief A class to create a DCP.
22  */
23
24 #ifndef LIBDCP_DCP_H
25 #define LIBDCP_DCP_H
26
27 #include <string>
28 #include <vector>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/signals2.hpp>
31 #include "types.h"
32
33 namespace xmlpp {
34         class Node;
35 }
36
37 /** @brief Namespace for everything in libdcp */
38 namespace libdcp
39 {
40
41 class Asset;    
42 class PictureAsset;
43 class SoundAsset;
44 class SubtitleAsset;
45 class Reel;
46 class AssetMap;
47
48 /** @brief A CPL within a DCP */
49 class CPL
50 {
51 public:
52         CPL (std::string directory, std::string name, ContentKind content_kind, int length, int frames_per_second);
53         CPL (std::string directory, std::string file, boost::shared_ptr<const AssetMap> asset_map, bool require_mxfs = true);
54
55         void add_reel (boost::shared_ptr<const Reel> reel);
56         
57         /** @return the length in frames */
58         int length () const {
59                 return _length;
60         }
61
62         /** @return the type of the content, used by media servers
63          *  to categorise things (e.g. feature, trailer, etc.)
64          */
65         ContentKind content_kind () const {
66                 return _content_kind;
67         }
68
69         std::list<boost::shared_ptr<const Reel> > reels () const {
70                 return _reels;
71         }
72
73         /** @return the CPL's name, as will be presented on projector
74          *  media servers and theatre management systems.
75          */
76         std::string name () const {
77                 return _name;
78         }
79
80         /** @return the number of frames per second */
81         int frames_per_second () const {
82                 return _fps;
83         }
84
85         std::list<boost::shared_ptr<const Asset> > assets () const;
86         
87         bool equals (CPL const & other, EqualityOptions options, std::list<std::string>& notes) const;
88         
89         void write_xml () const;
90         void write_to_assetmap (std::ostream& s) const;
91         void write_to_pkl (std::ostream& s) const;
92         
93 private:
94         std::string _directory;
95         /** the name of the DCP */
96         std::string _name;
97         /** the content kind of the CPL */
98         ContentKind _content_kind;
99         /** length in frames */
100         mutable int _length;
101         /** frames per second */
102         int _fps;
103         /** reels */
104         std::list<boost::shared_ptr<const Reel> > _reels;
105
106         /** our UUID */
107         std::string _uuid;
108         /** a SHA1 digest of our XML */
109         mutable std::string _digest;
110 };
111
112 /** @class DCP dcp.h libdcp/dcp.h
113  *  @brief A class to create or read a DCP.
114  */
115         
116 class DCP
117 {
118 public:
119         /** Construct a DCP.  You can pass an existing DCP's directory
120          *  as the parameter, or a non-existant folder to create a new
121          *  DCP in.
122          *
123          *  @param directory Directory containing the DCP's files.
124          */
125         DCP (std::string directory);
126
127         /** Read an existing DCP's data.
128          *
129          *  The DCP's XML metadata will be examined, and you can then look at the contents
130          *  of the DCP.
131          *
132          *  @param require_mxfs true to throw an exception if MXF files are missing; setting to false
133          *  can be useful for testing, but normally it should be set to true.
134          */
135         void read (bool require_mxfs = true);
136
137         /** Write the required XML files to the directory that was
138          *  passed into the constructor.
139          */
140         void write_xml () const;
141
142         /** Compare this DCP with another, according to various options.
143          *  @param other DCP to compare this one to.
144          *  @param options Options to define just what "equality" means.
145          *  @param notes Filled in with notes about differences.
146          *  @return true if the DCPs are equal according to EqualityOptions, otherwise false.
147          */
148         bool equals (DCP const & other, EqualityOptions options, std::list<std::string>& notes) const;
149
150         /** Add a CPL to this DCP.
151          *  @param cpl CPL to add.
152          */
153         void add_cpl (boost::shared_ptr<CPL> cpl);
154
155         /** @return The list of CPLs in this DCP */
156         std::list<boost::shared_ptr<const CPL> > cpls () const {
157                 return _cpls;
158         }
159
160         /** Emitted with a parameter between 0 and 1 to indicate progress
161          *  for long jobs.
162          */
163         boost::signals2::signal<void (float)> Progress;
164
165 private:
166
167         /** Write the PKL file.
168          *  @param pkl_uuid UUID to use.
169          */
170         std::string write_pkl (std::string pkl_uuid) const;
171         
172         /** Write the VOLINDEX file */
173         void write_volindex () const;
174
175         /** Write the ASSETMAP file.
176          *  @param pkl_uuid UUID of our PKL.
177          *  @param pkl_length Length of our PKL in bytes.
178          */
179         void write_assetmap (std::string pkl_uuid, int pkl_length) const;
180
181         /** @return Assets in all this CPLs in this DCP */
182         std::list<boost::shared_ptr<const Asset> > assets () const;
183
184         struct Files {
185                 std::list<std::string> cpls;
186                 std::string pkl;
187                 std::string asset_map;
188         };
189
190         /** the directory that we are writing to */
191         std::string _directory;
192         /** our CPLs */
193         std::list<boost::shared_ptr<const CPL> > _cpls;
194 };
195
196 }
197
198 #endif