Merge branch 'master' into cxml
[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 CPL;
47 class XMLMetadata;
48
49 /** @class DCP
50  *  @brief A class to create or read a DCP.
51  */
52         
53 class DCP
54 {
55 public:
56         /** Construct a DCP.  You can pass an existing DCP's directory
57          *  as the parameter, or a non-existant folder to create a new
58          *  DCP in.
59          *
60          *  @param directory Directory containing the DCP's files.
61          */
62         DCP (std::string directory);
63
64         /** Read an existing DCP's data.
65          *
66          *  The DCP's XML metadata will be examined, and you can then look at the contents
67          *  of the DCP.
68          *
69          *  @param require_mxfs true to throw an exception if MXF files are missing; setting to false
70          *  can be useful for testing, but normally it should be set to true.
71          */
72         void read (bool require_mxfs = true);
73
74         /** Write the required XML files to the directory that was
75          *  passed into the constructor.
76          */
77         void write_xml (XMLMetadata const &) const;
78
79         /** Compare this DCP with another, according to various options.
80          *  @param other DCP to compare this one to.
81          *  @param options Options to define what "equality" means.
82          *  @return true if the DCPs are equal according to EqualityOptions, otherwise false.
83          */
84         bool equals (DCP const & other, EqualityOptions options, boost::function<void (NoteType, std::string)> note) const;
85
86         /** Add a CPL to this DCP.
87          *  @param cpl CPL to add.
88          */
89         void add_cpl (boost::shared_ptr<CPL> cpl);
90
91         /** @return The list of CPLs in this DCP */
92         std::list<boost::shared_ptr<const CPL> > cpls () const {
93                 return _cpls;
94         }
95
96         /** Emitted with a parameter between 0 and 1 to indicate progress
97          *  for long jobs.
98          */
99         boost::signals2::signal<void (float)> Progress;
100
101 private:
102
103         /** Write the PKL file.
104          *  @param pkl_uuid UUID to use.
105          */
106         std::string write_pkl (std::string pkl_uuid, XMLMetadata const &) const;
107         
108         /** Write the VOLINDEX file */
109         void write_volindex () const;
110
111         /** Write the ASSETMAP file.
112          *  @param pkl_uuid UUID of our PKL.
113          *  @param pkl_length Length of our PKL in bytes.
114          */
115         void write_assetmap (std::string pkl_uuid, int pkl_length, XMLMetadata const &) const;
116
117         /** @return Assets in all this CPLs in this DCP */
118         std::list<boost::shared_ptr<const Asset> > assets () const;
119
120         struct Files {
121                 std::list<std::string> cpls;
122                 std::string pkl;
123                 std::string asset_map;
124         };
125
126         /** the directory that we are writing to */
127         std::string _directory;
128         /** our CPLs */
129         std::list<boost::shared_ptr<const CPL> > _cpls;
130 };
131
132 }
133
134 #endif