No-op: whitespace.
[libdcp.git] / src / reel.cc
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 <libxml++/nodes/element.h>
21 #include "reel.h"
22 #include "util.h"
23 #include "picture_asset.h"
24 #include "mono_picture_asset.h"
25 #include "stereo_picture_asset.h"
26 #include "sound_asset.h"
27 #include "subtitle_asset.h"
28 #include "kdm.h"
29
30 using std::string;
31 using std::list;
32 using std::cout;
33 using boost::shared_ptr;
34 using boost::dynamic_pointer_cast;
35 using namespace libdcp;
36
37 void
38 Reel::write_to_cpl (xmlpp::Element* node) const
39 {
40         xmlpp::Element* reel = node->add_child ("Reel");
41         reel->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid());
42         xmlpp::Element* asset_list = reel->add_child ("AssetList");
43
44         if (_main_picture && dynamic_pointer_cast<MonoPictureAsset> (_main_picture)) {
45                 /* Mono pictures come before other stuff... */
46                 _main_picture->write_to_cpl (asset_list);
47         }
48
49         if (_main_sound) {
50                 _main_sound->write_to_cpl (asset_list);
51         }
52
53         if (_main_subtitle) {
54                 _main_subtitle->write_to_cpl (asset_list);
55         }
56
57         if (_main_picture && dynamic_pointer_cast<StereoPictureAsset> (_main_picture)) {
58                 /* ... but stereo pictures must come after */
59                 _main_picture->write_to_cpl (asset_list);
60         }
61 }
62
63 bool
64 Reel::equals (boost::shared_ptr<const Reel> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
65 {
66         if ((_main_picture && !other->_main_picture) || (!_main_picture && other->_main_picture)) {
67                 note (ERROR, "reel has different assets");
68                 return false;
69         }
70
71         if (_main_picture && !_main_picture->equals (other->_main_picture, opt, note)) {
72                 return false;
73         }
74
75         if ((_main_sound && !other->_main_sound) || (!_main_sound && other->_main_sound)) {
76                 note (ERROR, "reel has different assets");
77                 return false;
78         }
79
80         if (_main_sound && !_main_sound->equals (other->_main_sound, opt, note)) {
81                 return false;
82         }
83
84         if ((_main_subtitle && !other->_main_subtitle) || (!_main_subtitle && other->_main_subtitle)) {
85                 note (ERROR, "reel has different assets");
86                 return false;
87         }
88
89         if (_main_subtitle && !_main_subtitle->equals (other->_main_subtitle, opt, note)) {
90                 return false;
91         }
92
93         return true;
94 }
95
96 bool
97 Reel::encrypted () const
98 {
99         return ((_main_picture && _main_picture->encrypted ()) || (_main_sound && _main_sound->encrypted ()));
100 }
101
102 void
103 Reel::add_kdm (KDM const & kdm)
104 {
105         list<KDMKey> keys = kdm.keys ();
106
107         for (list<KDMKey>::iterator i = keys.begin(); i != keys.end(); ++i) {
108                 if (i->key_id() == _main_picture->key_id()) {
109                         _main_picture->set_key (i->key ());
110                 }
111                 if (i->key_id() == _main_sound->key_id()) {
112                         _main_sound->set_key (i->key ());
113                 }
114         }
115 }
116
117 void
118 Reel::set_mxf_keys (Key key)
119 {
120         _main_picture->set_key (key);
121         if (_main_sound) {
122                 _main_sound->set_key (key);
123         }
124
125         /* XXX: subtitle asset? */
126 }