Fix handling of timing in SMPTE subtitles.
[libdcp.git] / src / subtitle.cc
index 12714961445eb8ac9077bb379ba9b991b9d40262..6c2ccd7ef8f96328196775b068e237c5181ef7cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 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
 #include <boost/lexical_cast.hpp>
 
 using std::string;
+using std::list;
+using boost::optional;
 using boost::shared_ptr;
 using boost::lexical_cast;
 using namespace dcp;
 
-Subtitle::Subtitle (boost::shared_ptr<const cxml::Node> node)
+Subtitle::Subtitle (boost::shared_ptr<const cxml::Node> node, int tcr)
 {
-       in = Time (node->string_attribute ("TimeIn"));
-       out = Time (node->string_attribute ("TimeOut"));
-       font_nodes = type_children<Font> (node, "Font");
-       text_nodes = type_children<Text> (node, "Text");
-       fade_up_time = fade_time (node, "FadeUpTime");
-       fade_down_time = fade_time (node, "FadeDownTime");
+       in = Time (node->string_attribute ("TimeIn"), tcr);
+       out = Time (node->string_attribute ("TimeOut"), tcr);
+
+       list<cxml::NodePtr> f = node->node_children ("Font");
+       for (list<cxml::NodePtr>::iterator i = f.begin(); i != f.end(); ++i) {
+               font_nodes.push_back (shared_ptr<Font> (new Font (*i, tcr)));
+       }
+
+       list<cxml::NodePtr> t = node->node_children ("Text");
+       for (list<cxml::NodePtr>::iterator i = t.begin(); i != t.end(); ++i) {
+               text_nodes.push_back (shared_ptr<Text> (new Text (*i, tcr)));
+       }
+       
+       fade_up_time = fade_time (node, "FadeUpTime", tcr);
+       fade_down_time = fade_time (node, "FadeDownTime", tcr);
 }
 
 Time
-Subtitle::fade_time (shared_ptr<const cxml::Node> node, string name)
+Subtitle::fade_time (shared_ptr<const cxml::Node> node, string name, int tcr)
 {
        string const u = node->optional_string_attribute (name).get_value_or ("");
        Time t;
        
        if (u.empty ()) {
-               t = Time (0, 0, 0, 20);
+               t = Time (0, 0, 0, 20, 250);
        } else if (u.find (":") != string::npos) {
-               t = Time (u);
+               t = Time (u, tcr);
        } else {
-               t = Time (0, 0, 0, lexical_cast<int> (u));
+               t = Time (0, 0, 0, lexical_cast<int> (u), tcr);
        }
 
-       if (t > Time (0, 0, 8, 0)) {
-               t = Time (0, 0, 8, 0);
+       if (t > Time (0, 0, 8, 0, 250)) {
+               t = Time (0, 0, 8, 0, 250);
        }
 
        return t;