summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-08 23:22:05 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-08 23:22:05 +0000
commit7ca029dea19ab0aa1b7e96d363fe6de61350d2e7 (patch)
treed520d2f6597fa4ccbe2a78e3aea4d1d2614d9373 /src/parse
parentbbb3db16cc7e6f2262a89da4bec9fc356d6c3c12 (diff)
Change libdcp::Time to allow sub-second units to be anything, so that
we can support SMPTE subtitles which use TimeCodeRate as the base rather than the arbitrary "ticks" (4ms) of Interop.
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/subtitle.cc65
-rw-r--r--src/parse/subtitle.h8
2 files changed, 49 insertions, 24 deletions
diff --git a/src/parse/subtitle.cc b/src/parse/subtitle.cc
index 831fef59..56222c97 100644
--- a/src/parse/subtitle.cc
+++ b/src/parse/subtitle.cc
@@ -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
@@ -30,7 +30,7 @@ using boost::optional;
using namespace libdcp;
using namespace libdcp::parse;
-Font::Font (shared_ptr<const cxml::Node> node)
+Font::Font (shared_ptr<const cxml::Node> node, optional<int> tcr)
{
text = node->content ();
@@ -49,9 +49,21 @@ Font::Font (shared_ptr<const cxml::Node> node)
if (c) {
effect_color = Color (c.get ());
}
- subtitle_nodes = type_children<Subtitle> (node, "Subtitle");
- font_nodes = type_children<Font> (node, "Font");
- text_nodes = type_children<Text> (node, "Text");
+
+ list<cxml::NodePtr> s = node->node_children ("Subtitle");
+ for (list<cxml::NodePtr>::iterator i = s.begin(); i != s.end(); ++i) {
+ subtitle_nodes.push_back (shared_ptr<Subtitle> (new Subtitle (*i, 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)));
+ }
}
Font::Font (list<shared_ptr<Font> > const & font_nodes)
@@ -93,38 +105,48 @@ LoadFont::LoadFont (shared_ptr<const cxml::Node> node)
uri = node->optional_string_attribute ("URI");
}
-Subtitle::Subtitle (shared_ptr<const cxml::Node> node)
+/** @param tcr A timecode rate, if this subtitle is from a SMPTE file, or empty if it is Interop */
+Subtitle::Subtitle (shared_ptr<const cxml::Node> node, optional<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.get_value_or (250));
+ out = Time (node->string_attribute ("TimeOut"), tcr.get_value_or (250));
+
+ 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, optional<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.get_value_or(250));
} else {
- t = Time (0, 0, 0, raw_convert<int> (u));
+ t = Time (0, 0, 0, raw_convert<int> (u), tcr.get_value_or(250));
}
- 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;
}
-Text::Text (shared_ptr<const cxml::Node> node)
+Text::Text (shared_ptr<const cxml::Node> node, optional<int> tcr)
: v_align (CENTER)
{
/* Vertical position */
@@ -144,6 +166,9 @@ Text::Text (shared_ptr<const cxml::Node> node)
v_align = string_to_valign (v.get ());
}
- font_nodes = type_children<Font> (node, "Font");
+ 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)));
+ }
}
diff --git a/src/parse/subtitle.h b/src/parse/subtitle.h
index 3d99d9bc..867b3f0e 100644
--- a/src/parse/subtitle.h
+++ b/src/parse/subtitle.h
@@ -37,7 +37,7 @@ public:
, v_align (TOP)
{}
- Text (boost::shared_ptr<const cxml::Node> node);
+ Text (boost::shared_ptr<const cxml::Node> node, boost::optional<int> tcr);
float v_position;
VAlign v_align;
@@ -49,7 +49,7 @@ class Subtitle
{
public:
Subtitle () {}
- Subtitle (boost::shared_ptr<const cxml::Node> node);
+ Subtitle (boost::shared_ptr<const cxml::Node> node, boost::optional<int> tcr);
Time in;
Time out;
@@ -59,7 +59,7 @@ public:
std::list<boost::shared_ptr<Text> > text_nodes;
private:
- Time fade_time (boost::shared_ptr<const cxml::Node>, std::string name);
+ Time fade_time (boost::shared_ptr<const cxml::Node>, std::string name, boost::optional<int> tcr);
};
class Font
@@ -69,7 +69,7 @@ public:
: size (0)
{}
- Font (boost::shared_ptr<const cxml::Node> node);
+ Font (boost::shared_ptr<const cxml::Node> node, boost::optional<int> tcr);
Font (std::list<boost::shared_ptr<Font> > const & font_nodes);
std::string text;