Add Subtitle::set_text()
[libdcp.git] / src / cpl.cc
index dcb730ff91cc2287a09378c5b9b6bfdb2e8d59ff..6fc52be536d4499ec372f56c806c7e63ee43eb30 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@
 #include "signer.h"
 #include "exceptions.h"
 #include "compose.hpp"
+#include "raw_convert.h"
 
 using std::string;
 using std::stringstream;
@@ -177,6 +178,7 @@ CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> ass
                        subtitle.reset (new SubtitleAsset (asset.first, asset.second->chunks.front()->path));
 
                        subtitle->set_entry_point ((*i)->asset_list->main_subtitle->entry_point);
+                       subtitle->set_edit_rate (_fps);
                        subtitle->set_duration ((*i)->asset_list->main_subtitle->duration);
                }
                        
@@ -190,14 +192,16 @@ CPL::add_reel (shared_ptr<Reel> reel)
        _reels.push_back (reel);
 }
 
+boost::filesystem::path
+CPL::filename () const
+{
+       return _directory / String::compose ("%1_cpl.xml", _id);
+}
+
 void
 CPL::write_xml (bool interop, XMLMetadata const & metadata, shared_ptr<const Signer> signer) const
 {
-       boost::filesystem::path p;
-       p /= _directory;
-       stringstream s;
-       s << _id << "_cpl.xml";
-       p /= s.str();
+       boost::filesystem::path p = filename ();
 
        xmlpp::Document doc;
        xmlpp::Element* root;
@@ -243,13 +247,17 @@ CPL::write_xml (bool interop, XMLMetadata const & metadata, shared_ptr<const Sig
 }
 
 void
-CPL::write_to_pkl (xmlpp::Node* node) const
+CPL::write_to_pkl (xmlpp::Node* node, bool interop) const
 {
        xmlpp::Node* asset = node->add_child ("Asset");
        asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
        asset->add_child("Hash")->add_child_text (_digest);
-       asset->add_child("Size")->add_child_text (lexical_cast<string> (_length));
-       asset->add_child("Type")->add_child_text ("text/xml");
+       asset->add_child("Size")->add_child_text (raw_convert<string> (_length));
+       if (interop) {
+               asset->add_child("Type")->add_child_text ("text/xml;asdcpKind=CPL");
+       } else {
+               asset->add_child("Type")->add_child_text ("text/xml");
+       }
 }
 
 list<shared_ptr<const Asset> >
@@ -281,7 +289,7 @@ CPL::write_to_assetmap (xmlpp::Node* node) const
        chunk->add_child("Path")->add_child_text (_id + "_cpl.xml");
        chunk->add_child("VolumeIndex")->add_child_text ("1");
        chunk->add_child("Offset")->add_child_text("0");
-       chunk->add_child("Length")->add_child_text(lexical_cast<string> (_length));
+       chunk->add_child("Length")->add_child_text (raw_convert<string> (_length));
 }