Split ReelSubtitleAsset into Interop and SMPTE classes.
[libdcp.git] / src / cpl.cc
index b18197559324b58a0d3bbdf1561c0262e65988da..3b5497576b5cef71808af84f3399420e93c4e738 100644 (file)
 #include <boost/algorithm/string.hpp>
 
 
-using std::string;
+using std::cout;
+using std::dynamic_pointer_cast;
 using std::list;
-using std::pair;
 using std::make_pair;
-using std::cout;
+using std::make_shared;
+using std::pair;
 using std::set;
-using std::vector;
 using std::shared_ptr;
+using std::string;
+using std::vector;
 using boost::optional;
-using std::dynamic_pointer_cast;
 using namespace dcp;
 
 
@@ -136,7 +137,10 @@ CPL::CPL (boost::filesystem::path file)
                        _ratings.push_back (Rating(i));
                }
        }
-       _reels = type_grand_children<Reel> (f, "ReelList", "Reel");
+
+       for (auto i: f.node_child("ReelList")->node_children("Reel")) {
+               _reels.push_back (make_shared<Reel>(i, *_standard));
+       }
 
        auto reel_list = f.node_child ("ReelList");
        if (reel_list) {
@@ -291,9 +295,9 @@ CPL::read_composition_metadata_asset (cxml::ConstNodePtr node)
                /* If the first language on SubtitleLanguageList is the same as the language of the first subtitle we'll ignore it */
                size_t first = 0;
                if (!_reels.empty()) {
-                       shared_ptr<dcp::ReelSubtitleAsset> sub = _reels.front()->main_subtitle();
+                       auto sub = _reels.front()->main_subtitle();
                        if (sub) {
-                               optional<string> lang = sub->language();
+                               auto lang = sub->language();
                                if (lang && lang == sll_split[0]) {
                                        first = 1;
                                }
@@ -515,23 +519,68 @@ add_file_assets (vector<shared_ptr<T>>& assets, vector<shared_ptr<Reel>> reels)
 }
 
 
-vector<shared_ptr<ReelEncryptableAsset>>
+vector<shared_ptr<ReelFileAsset>>
 CPL::reel_file_assets ()
 {
-       vector<shared_ptr<ReelEncryptableAsset>> c;
+       vector<shared_ptr<ReelFileAsset>> c;
        add_file_assets (c, _reels);
        return c;
 }
 
-vector<shared_ptr<const ReelEncryptableAsset>>
+
+vector<shared_ptr<const ReelFileAsset>>
 CPL::reel_file_assets () const
 {
-       vector<shared_ptr<const ReelEncryptableAsset>> c;
+       vector<shared_ptr<const ReelFileAsset>> c;
        add_file_assets (c, _reels);
        return c;
 }
 
 
+template <class T>
+void
+add_encryptable_assets (vector<shared_ptr<T>>& assets, vector<shared_ptr<Reel>> reels)
+{
+       for (auto i: reels) {
+               if (i->main_picture ()) {
+                       assets.push_back (i->main_picture());
+               }
+               if (i->main_sound ()) {
+                       assets.push_back (i->main_sound());
+               }
+               if (i->main_subtitle ()) {
+                       if (auto enc = dynamic_pointer_cast<ReelEncryptableAsset>(i->main_subtitle())) {
+                               assets.push_back (enc);
+                       }
+               }
+               for (auto j: i->closed_captions()) {
+                       assets.push_back (j);
+               }
+               if (i->atmos ()) {
+                       assets.push_back (i->atmos());
+               }
+       }
+}
+
+
+vector<shared_ptr<ReelEncryptableAsset>>
+CPL::reel_encryptable_assets ()
+{
+       vector<shared_ptr<ReelEncryptableAsset>> c;
+       add_encryptable_assets (c, _reels);
+       return c;
+}
+
+
+vector<shared_ptr<const ReelEncryptableAsset>>
+CPL::reel_encryptable_assets () const
+{
+       vector<shared_ptr<const ReelEncryptableAsset>> c;
+       add_encryptable_assets (c, _reels);
+       return c;
+}
+
+
 bool
 CPL::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
 {