From 7ca029dea19ab0aa1b7e96d363fe6de61350d2e7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 8 Jan 2015 23:22:05 +0000 Subject: 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. --- src/parse/subtitle.cc | 65 +++++++++++++++++++++++++++++++++++---------------- src/parse/subtitle.h | 8 +++---- 2 files changed, 49 insertions(+), 24 deletions(-) (limited to 'src/parse') 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 + Copyright (C) 2012-2015 Carl Hetherington 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 node) +Font::Font (shared_ptr node, optional tcr) { text = node->content (); @@ -49,9 +49,21 @@ Font::Font (shared_ptr node) if (c) { effect_color = Color (c.get ()); } - subtitle_nodes = type_children (node, "Subtitle"); - font_nodes = type_children (node, "Font"); - text_nodes = type_children (node, "Text"); + + list s = node->node_children ("Subtitle"); + for (list::iterator i = s.begin(); i != s.end(); ++i) { + subtitle_nodes.push_back (shared_ptr (new Subtitle (*i, tcr))); + } + + list f = node->node_children ("Font"); + for (list::iterator i = f.begin(); i != f.end(); ++i) { + font_nodes.push_back (shared_ptr (new Font (*i, tcr))); + } + + list t = node->node_children ("Text"); + for (list::iterator i = t.begin(); i != t.end(); ++i) { + text_nodes.push_back (shared_ptr (new Text (*i, tcr))); + } } Font::Font (list > const & font_nodes) @@ -93,38 +105,48 @@ LoadFont::LoadFont (shared_ptr node) uri = node->optional_string_attribute ("URI"); } -Subtitle::Subtitle (shared_ptr node) +/** @param tcr A timecode rate, if this subtitle is from a SMPTE file, or empty if it is Interop */ +Subtitle::Subtitle (shared_ptr node, optional tcr) { - in = Time (node->string_attribute ("TimeIn")); - out = Time (node->string_attribute ("TimeOut")); - font_nodes = type_children (node, "Font"); - text_nodes = type_children (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 f = node->node_children ("Font"); + for (list::iterator i = f.begin(); i != f.end(); ++i) { + font_nodes.push_back (shared_ptr (new Font (*i, tcr))); + } + + list t = node->node_children ("Text"); + for (list::iterator i = t.begin(); i != t.end(); ++i) { + text_nodes.push_back (shared_ptr (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 node, string name) +Subtitle::fade_time (shared_ptr node, string name, optional 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 (u)); + t = Time (0, 0, 0, raw_convert (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 node) +Text::Text (shared_ptr node, optional tcr) : v_align (CENTER) { /* Vertical position */ @@ -144,6 +166,9 @@ Text::Text (shared_ptr node) v_align = string_to_valign (v.get ()); } - font_nodes = type_children (node, "Font"); + list f = node->node_children ("Font"); + for (list::iterator i = f.begin(); i != f.end(); ++i) { + font_nodes.push_back (shared_ptr (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 node); + Text (boost::shared_ptr node, boost::optional tcr); float v_position; VAlign v_align; @@ -49,7 +49,7 @@ class Subtitle { public: Subtitle () {} - Subtitle (boost::shared_ptr node); + Subtitle (boost::shared_ptr node, boost::optional tcr); Time in; Time out; @@ -59,7 +59,7 @@ public: std::list > text_nodes; private: - Time fade_time (boost::shared_ptr, std::string name); + Time fade_time (boost::shared_ptr, std::string name, boost::optional tcr); }; class Font @@ -69,7 +69,7 @@ public: : size (0) {} - Font (boost::shared_ptr node); + Font (boost::shared_ptr node, boost::optional tcr); Font (std::list > const & font_nodes); std::string text; -- cgit v1.2.3