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