From 6c55e8d2c3b0129a19fc40dca344219021ad12ef Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 4 Jun 2015 16:48:08 +0100 Subject: Rename some stuff Content -> Asset. --- src/dcp.cc | 8 +- src/interop_subtitle_asset.cc | 239 ++++++++++++++++++++++++++++++++++++++++ src/interop_subtitle_asset.h | 50 +++++++++ src/interop_subtitle_content.cc | 239 ---------------------------------------- src/interop_subtitle_content.h | 50 --------- src/reel.cc | 2 +- src/reel_sound_asset.cc | 4 +- src/reel_subtitle_asset.cc | 6 +- src/reel_subtitle_asset.h | 12 +- src/smpte_subtitle_asset.cc | 94 ++++++++++++++++ src/smpte_subtitle_asset.h | 43 ++++++++ src/smpte_subtitle_content.cc | 94 ---------------- src/smpte_subtitle_content.h | 43 -------- src/subtitle_asset.cc | 228 ++++++++++++++++++++++++++++++++++++++ src/subtitle_asset.h | 114 +++++++++++++++++++ src/subtitle_content.cc | 228 -------------------------------------- src/subtitle_content.h | 114 ------------------- src/wscript | 12 +- 18 files changed, 790 insertions(+), 790 deletions(-) create mode 100644 src/interop_subtitle_asset.cc create mode 100644 src/interop_subtitle_asset.h delete mode 100644 src/interop_subtitle_content.cc delete mode 100644 src/interop_subtitle_content.h create mode 100644 src/smpte_subtitle_asset.cc create mode 100644 src/smpte_subtitle_asset.h delete mode 100644 src/smpte_subtitle_content.cc delete mode 100644 src/smpte_subtitle_content.h create mode 100644 src/subtitle_asset.cc create mode 100644 src/subtitle_asset.h delete mode 100644 src/subtitle_content.cc delete mode 100644 src/subtitle_content.h (limited to 'src') diff --git a/src/dcp.cc b/src/dcp.cc index 638ed707..e1b632c6 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -25,8 +25,8 @@ #include "dcp.h" #include "sound_mxf.h" #include "picture_mxf.h" -#include "interop_subtitle_content.h" -#include "smpte_subtitle_content.h" +#include "interop_subtitle_asset.h" +#include "smpte_subtitle_asset.h" #include "mono_picture_mxf.h" #include "stereo_picture_mxf.h" #include "util.h" @@ -137,7 +137,7 @@ DCP::read (bool keep_going, ReadErrors* errors) if (root == "CompositionPlaylist") { _assets.push_back (shared_ptr (new CPL (path))); } else if (root == "DCSubtitle") { - _assets.push_back (shared_ptr (new InteropSubtitleContent (path))); + _assets.push_back (shared_ptr (new InteropSubtitleAsset (path))); } } else if (boost::algorithm::ends_with (path.string(), ".mxf")) { ASDCP::EssenceType_t type; @@ -159,7 +159,7 @@ DCP::read (bool keep_going, ReadErrors* errors) _assets.push_back (shared_ptr (new StereoPictureMXF (path))); break; case ASDCP::ESS_TIMED_TEXT: - _assets.push_back (shared_ptr (new SMPTESubtitleContent (path))); + _assets.push_back (shared_ptr (new SMPTESubtitleAsset (path))); break; default: throw DCPReadError ("Unknown MXF essence type"); diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc new file mode 100644 index 00000000..a6bdfcaf --- /dev/null +++ b/src/interop_subtitle_asset.cc @@ -0,0 +1,239 @@ +/* + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "interop_subtitle_asset.h" +#include "interop_load_font_node.h" +#include "xml.h" +#include "raw_convert.h" +#include "font_node.h" +#include +#include +#include + +using std::list; +using std::string; +using std::cout; +using boost::shared_ptr; +using boost::optional; +using boost::dynamic_pointer_cast; +using namespace dcp; + +InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file) + : SubtitleAsset (file) +{ + shared_ptr xml (new cxml::Document ("DCSubtitle")); + xml->read_file (file); + _id = xml->string_child ("SubtitleID"); + + _movie_title = xml->string_child ("MovieTitle"); + _load_font_nodes = type_children (xml, "LoadFont"); + + list f = xml->node_children ("Font"); + list > font_nodes; + BOOST_FOREACH (cxml::NodePtr& i, f) { + font_nodes.push_back (shared_ptr (new FontNode (i, 250))); + } + + parse_common (xml, font_nodes); +} + +InteropSubtitleAsset::InteropSubtitleAsset (string movie_title, string language) + : _movie_title (movie_title) +{ + _language = language; +} + +struct SubtitleSorter { + bool operator() (SubtitleString const & a, SubtitleString const & b) { + if (a.in() != b.in()) { + return a.in() < b.in(); + } + return a.v_position() < b.v_position(); + } +}; + +Glib::ustring +InteropSubtitleAsset::xml_as_string () const +{ + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("DCSubtitle"); + root->set_attribute ("Version", "1.0"); + + root->add_child("SubtitleID")->add_child_text (_id); + root->add_child("MovieTitle")->add_child_text (_movie_title); + root->add_child("ReelNumber")->add_child_text (raw_convert (_reel_number)); + root->add_child("Language")->add_child_text (_language); + + for (list >::const_iterator i = _load_font_nodes.begin(); i != _load_font_nodes.end(); ++i) { + xmlpp::Element* load_font = root->add_child("LoadFont"); + load_font->set_attribute ("Id", (*i)->id); + load_font->set_attribute ("URI", (*i)->uri); + } + + list sorted = _subtitles; + sorted.sort (SubtitleSorter ()); + + /* XXX: script, underlined, weight not supported */ + + optional font; + bool italic = false; + Colour colour; + int size = 0; + float aspect_adjust = 1.0; + Effect effect = NONE; + Colour effect_colour; + int spot_number = 1; + Time last_in; + Time last_out; + Time last_fade_up_time; + Time last_fade_down_time; + + xmlpp::Element* font_element = 0; + xmlpp::Element* subtitle_element = 0; + + for (list::iterator i = sorted.begin(); i != sorted.end(); ++i) { + + /* We will start a new ... whenever some font property changes. + I suppose we should really make an optimal hierarchy of tags, but + that seems hard. + */ + + bool const font_changed = + font != i->font() || + italic != i->italic() || + colour != i->colour() || + size != i->size() || + fabs (aspect_adjust - i->aspect_adjust()) > ASPECT_ADJUST_EPSILON || + effect != i->effect() || + effect_colour != i->effect_colour(); + + if (font_changed) { + font = i->font (); + italic = i->italic (); + colour = i->colour (); + size = i->size (); + aspect_adjust = i->aspect_adjust (); + effect = i->effect (); + effect_colour = i->effect_colour (); + } + + if (!font_element || font_changed) { + font_element = root->add_child ("Font"); + if (font) { + font_element->set_attribute ("Id", font.get ()); + } + font_element->set_attribute ("Italic", italic ? "yes" : "no"); + font_element->set_attribute ("Color", colour.to_argb_string()); + font_element->set_attribute ("Size", raw_convert (size)); + if (fabs (aspect_adjust - 1.0) > ASPECT_ADJUST_EPSILON) { + font_element->set_attribute ("AspectAdjust", raw_convert (aspect_adjust)); + } + font_element->set_attribute ("Effect", effect_to_string (effect)); + font_element->set_attribute ("EffectColor", effect_colour.to_argb_string()); + font_element->set_attribute ("Script", "normal"); + font_element->set_attribute ("Underlined", "no"); + font_element->set_attribute ("Weight", "normal"); + } + + if (!subtitle_element || font_changed || + (last_in != i->in() || + last_out != i->out() || + last_fade_up_time != i->fade_up_time() || + last_fade_down_time != i->fade_down_time() + )) { + + subtitle_element = font_element->add_child ("Subtitle"); + subtitle_element->set_attribute ("SpotNumber", raw_convert (spot_number++)); + subtitle_element->set_attribute ("TimeIn", i->in().as_string()); + subtitle_element->set_attribute ("TimeOut", i->out().as_string()); + subtitle_element->set_attribute ("FadeUpTime", raw_convert (i->fade_up_time().as_editable_units(250))); + subtitle_element->set_attribute ("FadeDownTime", raw_convert (i->fade_down_time().as_editable_units(250))); + + last_in = i->in (); + last_out = i->out (); + last_fade_up_time = i->fade_up_time (); + last_fade_down_time = i->fade_down_time (); + } + + xmlpp::Element* text = subtitle_element->add_child ("Text"); + if (i->h_align() != HALIGN_CENTER) { + text->set_attribute ("HAlign", halign_to_string (i->h_align ())); + } + if (i->h_position() > ALIGN_EPSILON) { + text->set_attribute ("HPosition", raw_convert (i->h_position() * 100, 6)); + } + text->set_attribute ("VAlign", valign_to_string (i->v_align())); + text->set_attribute ("VPosition", raw_convert (i->v_position() * 100, 6)); + text->add_child_text (i->text()); + } + + return doc.write_to_string_formatted ("UTF-8"); +} + +void +InteropSubtitleAsset::add_font (string id, string uri) +{ + _load_font_nodes.push_back (shared_ptr (new InteropLoadFontNode (id, uri))); +} + +bool +InteropSubtitleAsset::equals (shared_ptr other_asset, EqualityOptions options, NoteHandler note) const +{ + if (!SubtitleAsset::equals (other_asset, options, note)) { + return false; + } + + shared_ptr other = dynamic_pointer_cast (other_asset); + if (!other) { + return false; + } + + list >::const_iterator i = _load_font_nodes.begin (); + list >::const_iterator j = other->_load_font_nodes.begin (); + + while (i != _load_font_nodes.end ()) { + if (j == other->_load_font_nodes.end ()) { + note (DCP_ERROR, " nodes differ"); + return false; + } + + if (**i != **j) { + note (DCP_ERROR, " nodes differ"); + return false; + } + + ++i; + ++j; + } + + if (_movie_title != other->_movie_title) { + note (DCP_ERROR, "Subtitle movie titles differ"); + return false; + } + + return true; +} + +list > +InteropSubtitleAsset::load_font_nodes () const +{ + list > lf; + copy (_load_font_nodes.begin(), _load_font_nodes.end(), back_inserter (lf)); + return lf; +} diff --git a/src/interop_subtitle_asset.h b/src/interop_subtitle_asset.h new file mode 100644 index 00000000..586bb67c --- /dev/null +++ b/src/interop_subtitle_asset.h @@ -0,0 +1,50 @@ +/* + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "subtitle_asset.h" +#include + +namespace dcp { + +class InteropLoadFontNode; + +class InteropSubtitleAsset : public SubtitleAsset +{ +public: + InteropSubtitleAsset (std::string movie_title, std::string language); + InteropSubtitleAsset (boost::filesystem::path file); + + bool equals ( + boost::shared_ptr, + EqualityOptions, + NoteHandler note + ) const; + + std::list > load_font_nodes () const; + + void add_font (std::string id, std::string uri); + + Glib::ustring xml_as_string () const; + +private: + std::string _movie_title; + std::list > _load_font_nodes; +}; + +} diff --git a/src/interop_subtitle_content.cc b/src/interop_subtitle_content.cc deleted file mode 100644 index 29da0b21..00000000 --- a/src/interop_subtitle_content.cc +++ /dev/null @@ -1,239 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "interop_subtitle_content.h" -#include "interop_load_font_node.h" -#include "xml.h" -#include "raw_convert.h" -#include "font_node.h" -#include -#include -#include - -using std::list; -using std::string; -using std::cout; -using boost::shared_ptr; -using boost::optional; -using boost::dynamic_pointer_cast; -using namespace dcp; - -InteropSubtitleContent::InteropSubtitleContent (boost::filesystem::path file) - : SubtitleContent (file) -{ - shared_ptr xml (new cxml::Document ("DCSubtitle")); - xml->read_file (file); - _id = xml->string_child ("SubtitleID"); - - _movie_title = xml->string_child ("MovieTitle"); - _load_font_nodes = type_children (xml, "LoadFont"); - - list f = xml->node_children ("Font"); - list > font_nodes; - BOOST_FOREACH (cxml::NodePtr& i, f) { - font_nodes.push_back (shared_ptr (new FontNode (i, 250))); - } - - parse_common (xml, font_nodes); -} - -InteropSubtitleContent::InteropSubtitleContent (string movie_title, string language) - : _movie_title (movie_title) -{ - _language = language; -} - -struct SubtitleSorter { - bool operator() (SubtitleString const & a, SubtitleString const & b) { - if (a.in() != b.in()) { - return a.in() < b.in(); - } - return a.v_position() < b.v_position(); - } -}; - -Glib::ustring -InteropSubtitleContent::xml_as_string () const -{ - xmlpp::Document doc; - xmlpp::Element* root = doc.create_root_node ("DCSubtitle"); - root->set_attribute ("Version", "1.0"); - - root->add_child("SubtitleID")->add_child_text (_id); - root->add_child("MovieTitle")->add_child_text (_movie_title); - root->add_child("ReelNumber")->add_child_text (raw_convert (_reel_number)); - root->add_child("Language")->add_child_text (_language); - - for (list >::const_iterator i = _load_font_nodes.begin(); i != _load_font_nodes.end(); ++i) { - xmlpp::Element* load_font = root->add_child("LoadFont"); - load_font->set_attribute ("Id", (*i)->id); - load_font->set_attribute ("URI", (*i)->uri); - } - - list sorted = _subtitles; - sorted.sort (SubtitleSorter ()); - - /* XXX: script, underlined, weight not supported */ - - optional font; - bool italic = false; - Colour colour; - int size = 0; - float aspect_adjust = 1.0; - Effect effect = NONE; - Colour effect_colour; - int spot_number = 1; - Time last_in; - Time last_out; - Time last_fade_up_time; - Time last_fade_down_time; - - xmlpp::Element* font_element = 0; - xmlpp::Element* subtitle_element = 0; - - for (list::iterator i = sorted.begin(); i != sorted.end(); ++i) { - - /* We will start a new ... whenever some font property changes. - I suppose we should really make an optimal hierarchy of tags, but - that seems hard. - */ - - bool const font_changed = - font != i->font() || - italic != i->italic() || - colour != i->colour() || - size != i->size() || - fabs (aspect_adjust - i->aspect_adjust()) > ASPECT_ADJUST_EPSILON || - effect != i->effect() || - effect_colour != i->effect_colour(); - - if (font_changed) { - font = i->font (); - italic = i->italic (); - colour = i->colour (); - size = i->size (); - aspect_adjust = i->aspect_adjust (); - effect = i->effect (); - effect_colour = i->effect_colour (); - } - - if (!font_element || font_changed) { - font_element = root->add_child ("Font"); - if (font) { - font_element->set_attribute ("Id", font.get ()); - } - font_element->set_attribute ("Italic", italic ? "yes" : "no"); - font_element->set_attribute ("Color", colour.to_argb_string()); - font_element->set_attribute ("Size", raw_convert (size)); - if (fabs (aspect_adjust - 1.0) > ASPECT_ADJUST_EPSILON) { - font_element->set_attribute ("AspectAdjust", raw_convert (aspect_adjust)); - } - font_element->set_attribute ("Effect", effect_to_string (effect)); - font_element->set_attribute ("EffectColor", effect_colour.to_argb_string()); - font_element->set_attribute ("Script", "normal"); - font_element->set_attribute ("Underlined", "no"); - font_element->set_attribute ("Weight", "normal"); - } - - if (!subtitle_element || font_changed || - (last_in != i->in() || - last_out != i->out() || - last_fade_up_time != i->fade_up_time() || - last_fade_down_time != i->fade_down_time() - )) { - - subtitle_element = font_element->add_child ("Subtitle"); - subtitle_element->set_attribute ("SpotNumber", raw_convert (spot_number++)); - subtitle_element->set_attribute ("TimeIn", i->in().as_string()); - subtitle_element->set_attribute ("TimeOut", i->out().as_string()); - subtitle_element->set_attribute ("FadeUpTime", raw_convert (i->fade_up_time().as_editable_units(250))); - subtitle_element->set_attribute ("FadeDownTime", raw_convert (i->fade_down_time().as_editable_units(250))); - - last_in = i->in (); - last_out = i->out (); - last_fade_up_time = i->fade_up_time (); - last_fade_down_time = i->fade_down_time (); - } - - xmlpp::Element* text = subtitle_element->add_child ("Text"); - if (i->h_align() != HALIGN_CENTER) { - text->set_attribute ("HAlign", halign_to_string (i->h_align ())); - } - if (i->h_position() > ALIGN_EPSILON) { - text->set_attribute ("HPosition", raw_convert (i->h_position() * 100, 6)); - } - text->set_attribute ("VAlign", valign_to_string (i->v_align())); - text->set_attribute ("VPosition", raw_convert (i->v_position() * 100, 6)); - text->add_child_text (i->text()); - } - - return doc.write_to_string_formatted ("UTF-8"); -} - -void -InteropSubtitleContent::add_font (string id, string uri) -{ - _load_font_nodes.push_back (shared_ptr (new InteropLoadFontNode (id, uri))); -} - -bool -InteropSubtitleContent::equals (shared_ptr other_asset, EqualityOptions options, NoteHandler note) const -{ - if (!SubtitleContent::equals (other_asset, options, note)) { - return false; - } - - shared_ptr other = dynamic_pointer_cast (other_asset); - if (!other) { - return false; - } - - list >::const_iterator i = _load_font_nodes.begin (); - list >::const_iterator j = other->_load_font_nodes.begin (); - - while (i != _load_font_nodes.end ()) { - if (j == other->_load_font_nodes.end ()) { - note (DCP_ERROR, " nodes differ"); - return false; - } - - if (**i != **j) { - note (DCP_ERROR, " nodes differ"); - return false; - } - - ++i; - ++j; - } - - if (_movie_title != other->_movie_title) { - note (DCP_ERROR, "Subtitle movie titles differ"); - return false; - } - - return true; -} - -list > -InteropSubtitleContent::load_font_nodes () const -{ - list > lf; - copy (_load_font_nodes.begin(), _load_font_nodes.end(), back_inserter (lf)); - return lf; -} diff --git a/src/interop_subtitle_content.h b/src/interop_subtitle_content.h deleted file mode 100644 index cb7c52d5..00000000 --- a/src/interop_subtitle_content.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "subtitle_content.h" -#include - -namespace dcp { - -class InteropLoadFontNode; - -class InteropSubtitleContent : public SubtitleContent -{ -public: - InteropSubtitleContent (std::string movie_title, std::string language); - InteropSubtitleContent (boost::filesystem::path file); - - bool equals ( - boost::shared_ptr, - EqualityOptions, - NoteHandler note - ) const; - - std::list > load_font_nodes () const; - - void add_font (std::string id, std::string uri); - - Glib::ustring xml_as_string () const; - -private: - std::string _movie_title; - std::list > _load_font_nodes; -}; - -} diff --git a/src/reel.cc b/src/reel.cc index eb682aea..3a046297 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -23,7 +23,7 @@ #include "mono_picture_mxf.h" #include "stereo_picture_mxf.h" #include "sound_mxf.h" -#include "subtitle_content.h" +#include "subtitle_asset.h" #include "reel_mono_picture_asset.h" #include "reel_stereo_picture_asset.h" #include "reel_sound_asset.h" diff --git a/src/reel_sound_asset.cc b/src/reel_sound_asset.cc index a5e32b02..9d3e00d7 100644 --- a/src/reel_sound_asset.cc +++ b/src/reel_sound_asset.cc @@ -29,8 +29,8 @@ using std::string; using boost::shared_ptr; using namespace dcp; -ReelSoundAsset::ReelSoundAsset (shared_ptr content, int64_t entry_point) - : ReelMXFAsset (content, content->edit_rate(), content->intrinsic_duration(), entry_point) +ReelSoundAsset::ReelSoundAsset (shared_ptr asset, int64_t entry_point) + : ReelMXFAsset (asset, asset->edit_rate(), asset->intrinsic_duration(), entry_point) { } diff --git a/src/reel_subtitle_asset.cc b/src/reel_subtitle_asset.cc index 139e3a39..ed0376ed 100644 --- a/src/reel_subtitle_asset.cc +++ b/src/reel_subtitle_asset.cc @@ -21,15 +21,15 @@ * @brief ReelSubtitleAsset class. */ -#include "subtitle_content.h" +#include "subtitle_asset.h" #include "reel_subtitle_asset.h" using std::string; using boost::shared_ptr; using namespace dcp; -ReelSubtitleAsset::ReelSubtitleAsset (boost::shared_ptr content, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point) - : ReelAsset (content, edit_rate, intrinsic_duration, entry_point) +ReelSubtitleAsset::ReelSubtitleAsset (boost::shared_ptr asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point) + : ReelAsset (asset, edit_rate, intrinsic_duration, entry_point) { } diff --git a/src/reel_subtitle_asset.h b/src/reel_subtitle_asset.h index bc00b4c3..f296fdc6 100644 --- a/src/reel_subtitle_asset.h +++ b/src/reel_subtitle_asset.h @@ -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 @@ -25,11 +25,11 @@ #define LIBDCP_REEL_SUBTITLE_ASSET_H #include "reel_asset.h" -#include "subtitle_content.h" +#include "subtitle_asset.h" namespace dcp { -class SubtitleContent; +class SubtitleAsset; /** @class ReelSubtitleAsset * @brief Part of a Reel's description which refers to a subtitle XML file. @@ -37,11 +37,11 @@ class SubtitleContent; class ReelSubtitleAsset : public ReelAsset { public: - ReelSubtitleAsset (boost::shared_ptr content, Fraction edit_rate, int64_t instrinsic_duration, int64_t entry_point); + ReelSubtitleAsset (boost::shared_ptr asset, Fraction edit_rate, int64_t instrinsic_duration, int64_t entry_point); ReelSubtitleAsset (boost::shared_ptr); - boost::shared_ptr subtitle_content () const { - return boost::dynamic_pointer_cast (_asset.object ()); + boost::shared_ptr subtitle_asset () const { + return boost::dynamic_pointer_cast (_asset.object ()); } private: diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc new file mode 100644 index 00000000..e5a083b1 --- /dev/null +++ b/src/smpte_subtitle_asset.cc @@ -0,0 +1,94 @@ +/* + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "smpte_subtitle_asset.h" +#include "smpte_load_font_node.h" +#include "font_node.h" +#include "exceptions.h" +#include "xml.h" +#include "AS_DCP.h" +#include "KM_util.h" +#include + +using std::string; +using std::list; +using std::stringstream; +using std::cout; +using boost::shared_ptr; +using namespace dcp; + +SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file, bool mxf) + : SubtitleAsset (file) +{ + shared_ptr xml (new cxml::Document ("SubtitleReel")); + + if (mxf) { + ASDCP::TimedText::MXFReader reader; + Kumu::Result_t r = reader.OpenRead (file.string().c_str ()); + if (ASDCP_FAILURE (r)) { + boost::throw_exception (MXFFileError ("could not open MXF file for reading", file, r)); + } + + string s; + reader.ReadTimedTextResource (s, 0, 0); + stringstream t; + t << s; + xml->read_stream (t); + + ASDCP::WriterInfo info; + reader.FillWriterInfo (info); + + char buffer[64]; + Kumu::bin2UUIDhex (info.AssetUUID, ASDCP::UUIDlen, buffer, sizeof (buffer)); + _id = buffer; + } else { + xml->read_file (file); + _id = xml->string_child("Id").substr (9); + } + + _load_font_nodes = type_children (xml, "LoadFont"); + + int tcr = xml->number_child ("TimeCodeRate"); + + shared_ptr subtitle_list = xml->optional_node_child ("SubtitleList"); + + list f = subtitle_list->node_children ("Font"); + list > font_nodes; + BOOST_FOREACH (cxml::NodePtr& i, f) { + font_nodes.push_back (shared_ptr (new FontNode (i, tcr))); + } + + parse_common (xml, font_nodes); +} + +list > +SMPTESubtitleAsset::load_font_nodes () const +{ + list > lf; + copy (_load_font_nodes.begin(), _load_font_nodes.end(), back_inserter (lf)); + return lf; +} + +bool +SMPTESubtitleAsset::valid_mxf (boost::filesystem::path file) +{ + ASDCP::TimedText::MXFReader reader; + Kumu::Result_t r = reader.OpenRead (file.string().c_str ()); + return !ASDCP_FAILURE (r); +} diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h new file mode 100644 index 00000000..639c8eb7 --- /dev/null +++ b/src/smpte_subtitle_asset.h @@ -0,0 +1,43 @@ +/* + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "subtitle_asset.h" +#include + +namespace dcp { + +class SMPTELoadFontNode; + +class SMPTESubtitleAsset : public SubtitleAsset +{ +public: + /** @param file File name + * @param mxf true if `file' is a MXF, or false if it is an XML file. + */ + SMPTESubtitleAsset (boost::filesystem::path file, bool mxf = true); + + std::list > load_font_nodes () const; + + static bool valid_mxf (boost::filesystem::path); + +private: + std::list > _load_font_nodes; +}; + +} diff --git a/src/smpte_subtitle_content.cc b/src/smpte_subtitle_content.cc deleted file mode 100644 index e95a64fc..00000000 --- a/src/smpte_subtitle_content.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "smpte_subtitle_content.h" -#include "smpte_load_font_node.h" -#include "font_node.h" -#include "exceptions.h" -#include "xml.h" -#include "AS_DCP.h" -#include "KM_util.h" -#include - -using std::string; -using std::list; -using std::stringstream; -using std::cout; -using boost::shared_ptr; -using namespace dcp; - -SMPTESubtitleContent::SMPTESubtitleContent (boost::filesystem::path file, bool mxf) - : SubtitleContent (file) -{ - shared_ptr xml (new cxml::Document ("SubtitleReel")); - - if (mxf) { - ASDCP::TimedText::MXFReader reader; - Kumu::Result_t r = reader.OpenRead (file.string().c_str ()); - if (ASDCP_FAILURE (r)) { - boost::throw_exception (MXFFileError ("could not open MXF file for reading", file, r)); - } - - string s; - reader.ReadTimedTextResource (s, 0, 0); - stringstream t; - t << s; - xml->read_stream (t); - - ASDCP::WriterInfo info; - reader.FillWriterInfo (info); - - char buffer[64]; - Kumu::bin2UUIDhex (info.AssetUUID, ASDCP::UUIDlen, buffer, sizeof (buffer)); - _id = buffer; - } else { - xml->read_file (file); - _id = xml->string_child("Id").substr (9); - } - - _load_font_nodes = type_children (xml, "LoadFont"); - - int tcr = xml->number_child ("TimeCodeRate"); - - shared_ptr subtitle_list = xml->optional_node_child ("SubtitleList"); - - list f = subtitle_list->node_children ("Font"); - list > font_nodes; - BOOST_FOREACH (cxml::NodePtr& i, f) { - font_nodes.push_back (shared_ptr (new FontNode (i, tcr))); - } - - parse_common (xml, font_nodes); -} - -list > -SMPTESubtitleContent::load_font_nodes () const -{ - list > lf; - copy (_load_font_nodes.begin(), _load_font_nodes.end(), back_inserter (lf)); - return lf; -} - -bool -SMPTESubtitleContent::valid_mxf (boost::filesystem::path file) -{ - ASDCP::TimedText::MXFReader reader; - Kumu::Result_t r = reader.OpenRead (file.string().c_str ()); - return !ASDCP_FAILURE (r); -} diff --git a/src/smpte_subtitle_content.h b/src/smpte_subtitle_content.h deleted file mode 100644 index 8526e0ec..00000000 --- a/src/smpte_subtitle_content.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "subtitle_content.h" -#include - -namespace dcp { - -class SMPTELoadFontNode; - -class SMPTESubtitleContent : public SubtitleContent -{ -public: - /** @param file File name - * @param mxf true if `file' is a MXF, or false if it is an XML file. - */ - SMPTESubtitleContent (boost::filesystem::path file, bool mxf = true); - - std::list > load_font_nodes () const; - - static bool valid_mxf (boost::filesystem::path); - -private: - std::list > _load_font_nodes; -}; - -} diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc new file mode 100644 index 00000000..f1ecc939 --- /dev/null +++ b/src/subtitle_asset.cc @@ -0,0 +1,228 @@ +/* + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "raw_convert.h" +#include "subtitle_asset.h" +#include "util.h" +#include "xml.h" +#include "font_node.h" +#include "text_node.h" +#include "subtitle_string.h" +#include "dcp_assert.h" +#include "AS_DCP.h" +#include "KM_util.h" +#include +#include +#include + +using std::string; +using std::list; +using std::ostream; +using std::ofstream; +using std::stringstream; +using std::cout; +using boost::shared_ptr; +using boost::optional; +using boost::dynamic_pointer_cast; +using namespace dcp; + +SubtitleAsset::SubtitleAsset () + : _reel_number ("1") +{ + +} + +SubtitleAsset::SubtitleAsset (boost::filesystem::path file) + : Asset (file) + , _reel_number ("1") +{ + +} + +void +SubtitleAsset::parse_common (shared_ptr xml, list > font_nodes) +{ + _reel_number = xml->string_child ("ReelNumber"); + _language = xml->string_child ("Language"); + + /* Now make Subtitle objects to represent the raw XML nodes + in a sane way. + */ + + ParseState parse_state; + examine_font_nodes (xml, font_nodes, parse_state); +} + +void +SubtitleAsset::examine_font_nodes ( + shared_ptr xml, + list > const & font_nodes, + ParseState& parse_state + ) +{ + for (list >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { + + parse_state.font_nodes.push_back (*i); + maybe_add_subtitle ((*i)->text, parse_state); + + for (list >::iterator j = (*i)->subtitle_nodes.begin(); j != (*i)->subtitle_nodes.end(); ++j) { + parse_state.subtitle_nodes.push_back (*j); + examine_text_nodes (xml, (*j)->text_nodes, parse_state); + examine_font_nodes (xml, (*j)->font_nodes, parse_state); + parse_state.subtitle_nodes.pop_back (); + } + + examine_font_nodes (xml, (*i)->font_nodes, parse_state); + examine_text_nodes (xml, (*i)->text_nodes, parse_state); + + parse_state.font_nodes.pop_back (); + } +} + +void +SubtitleAsset::examine_text_nodes ( + shared_ptr xml, + list > const & text_nodes, + ParseState& parse_state + ) +{ + for (list >::const_iterator i = text_nodes.begin(); i != text_nodes.end(); ++i) { + parse_state.text_nodes.push_back (*i); + maybe_add_subtitle ((*i)->text, parse_state); + examine_font_nodes (xml, (*i)->font_nodes, parse_state); + parse_state.text_nodes.pop_back (); + } +} + +void +SubtitleAsset::maybe_add_subtitle (string text, ParseState const & parse_state) +{ + if (empty_or_white_space (text)) { + return; + } + + if (parse_state.text_nodes.empty() || parse_state.subtitle_nodes.empty ()) { + return; + } + + DCP_ASSERT (!parse_state.text_nodes.empty ()); + DCP_ASSERT (!parse_state.subtitle_nodes.empty ()); + + dcp::FontNode effective_font (parse_state.font_nodes); + dcp::TextNode effective_text (*parse_state.text_nodes.back ()); + dcp::SubtitleNode effective_subtitle (*parse_state.subtitle_nodes.back ()); + + _subtitles.push_back ( + SubtitleString ( + effective_font.id, + effective_font.italic.get_value_or (false), + effective_font.colour.get_value_or (dcp::Colour (255, 255, 255)), + effective_font.size, + effective_font.aspect_adjust.get_value_or (1.0), + effective_subtitle.in, + effective_subtitle.out, + effective_text.h_position, + effective_text.h_align, + effective_text.v_position, + effective_text.v_align, + text, + effective_font.effect.get_value_or (NONE), + effective_font.effect_colour.get_value_or (dcp::Colour (0, 0, 0)), + effective_subtitle.fade_up_time, + effective_subtitle.fade_down_time + ) + ); +} + +list +SubtitleAsset::subtitles_during (Time from, Time to) const +{ + list s; + for (list::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { + if (i->out() >= from && i->in() <= to) { + s.push_back (*i); + } + } + + return s; +} + +void +SubtitleAsset::add (SubtitleString s) +{ + _subtitles.push_back (s); +} + +void +SubtitleAsset::write_xml (boost::filesystem::path p) const +{ + FILE* f = fopen_boost (p, "w"); + if (!f) { + throw FileError ("Could not open file for writing", p, -1); + } + + Glib::ustring const s = xml_as_string (); + fwrite (s.c_str(), 1, s.bytes(), f); + fclose (f); + + _file = p; +} + +Time +SubtitleAsset::latest_subtitle_out () const +{ + Time t; + for (list::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { + if (i->out() > t) { + t = i->out (); + } + } + + return t; +} + +bool +SubtitleAsset::equals (shared_ptr other_asset, EqualityOptions options, NoteHandler note) const +{ + if (!Asset::equals (other_asset, options, note)) { + return false; + } + + shared_ptr other = dynamic_pointer_cast (other_asset); + if (!other) { + return false; + } + + if (_reel_number != other->_reel_number) { + note (DCP_ERROR, "subtitle reel numbers differ"); + return false; + } + + if (_language != other->_language) { + note (DCP_ERROR, "subtitle languages differ"); + return false; + } + + if (_subtitles != other->_subtitles) { + note (DCP_ERROR, "subtitles differ"); + return false; + } + + return true; +} diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h new file mode 100644 index 00000000..deb72ece --- /dev/null +++ b/src/subtitle_asset.h @@ -0,0 +1,114 @@ +/* + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef LIBDCP_SUBTITLE_ASSET_H +#define LIBDCP_SUBTITLE_ASSET_H + +#include "asset.h" +#include "dcp_time.h" +#include "subtitle_string.h" +#include + +namespace dcp +{ + +class SubtitleString; +class FontNode; +class TextNode; +class SubtitleNode; +class LoadFontNode; + +/** @class SubtitleAsset + * @brief A parent for classes representing a file containing subtitles. + */ +class SubtitleAsset : public Asset +{ +public: + SubtitleAsset (); + SubtitleAsset (boost::filesystem::path file); + + bool equals ( + boost::shared_ptr, + EqualityOptions, + NoteHandler note + ) const; + + std::string language () const { + return _language; + } + + std::list subtitles_during (Time from, Time to) const; + std::list const & subtitles () const { + return _subtitles; + } + + void add (SubtitleString); + + void write_xml (boost::filesystem::path) const; + virtual Glib::ustring xml_as_string () const { + /* XXX: this should be pure virtual when SMPTE writing is implemented */ + return ""; + } + + Time latest_subtitle_out () const; + + virtual std::list > load_font_nodes () const = 0; + +protected: + void parse_common (boost::shared_ptr xml, std::list > font_nodes); + + std::string pkl_type (Standard) const { + return "text/xml"; + } + + std::string asdcp_kind () const { + return "Subtitle"; + } + + /* strangely, this is sometimes a string */ + std::string _reel_number; + std::string _language; + + std::list _subtitles; + +private: + struct ParseState { + std::list > font_nodes; + std::list > text_nodes; + std::list > subtitle_nodes; + }; + + void maybe_add_subtitle (std::string text, ParseState const & parse_state); + + void examine_font_nodes ( + boost::shared_ptr xml, + std::list > const & font_nodes, + ParseState& parse_state + ); + + void examine_text_nodes ( + boost::shared_ptr xml, + std::list > const & text_nodes, + ParseState& parse_state + ); +}; + +} + +#endif diff --git a/src/subtitle_content.cc b/src/subtitle_content.cc deleted file mode 100644 index d2be6fe0..00000000 --- a/src/subtitle_content.cc +++ /dev/null @@ -1,228 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "raw_convert.h" -#include "subtitle_content.h" -#include "util.h" -#include "xml.h" -#include "font_node.h" -#include "text_node.h" -#include "subtitle_string.h" -#include "dcp_assert.h" -#include "AS_DCP.h" -#include "KM_util.h" -#include -#include -#include - -using std::string; -using std::list; -using std::ostream; -using std::ofstream; -using std::stringstream; -using std::cout; -using boost::shared_ptr; -using boost::optional; -using boost::dynamic_pointer_cast; -using namespace dcp; - -SubtitleContent::SubtitleContent () - : _reel_number ("1") -{ - -} - -SubtitleContent::SubtitleContent (boost::filesystem::path file) - : Asset (file) - , _reel_number ("1") -{ - -} - -void -SubtitleContent::parse_common (shared_ptr xml, list > font_nodes) -{ - _reel_number = xml->string_child ("ReelNumber"); - _language = xml->string_child ("Language"); - - /* Now make Subtitle objects to represent the raw XML nodes - in a sane way. - */ - - ParseState parse_state; - examine_font_nodes (xml, font_nodes, parse_state); -} - -void -SubtitleContent::examine_font_nodes ( - shared_ptr xml, - list > const & font_nodes, - ParseState& parse_state - ) -{ - for (list >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { - - parse_state.font_nodes.push_back (*i); - maybe_add_subtitle ((*i)->text, parse_state); - - for (list >::iterator j = (*i)->subtitle_nodes.begin(); j != (*i)->subtitle_nodes.end(); ++j) { - parse_state.subtitle_nodes.push_back (*j); - examine_text_nodes (xml, (*j)->text_nodes, parse_state); - examine_font_nodes (xml, (*j)->font_nodes, parse_state); - parse_state.subtitle_nodes.pop_back (); - } - - examine_font_nodes (xml, (*i)->font_nodes, parse_state); - examine_text_nodes (xml, (*i)->text_nodes, parse_state); - - parse_state.font_nodes.pop_back (); - } -} - -void -SubtitleContent::examine_text_nodes ( - shared_ptr xml, - list > const & text_nodes, - ParseState& parse_state - ) -{ - for (list >::const_iterator i = text_nodes.begin(); i != text_nodes.end(); ++i) { - parse_state.text_nodes.push_back (*i); - maybe_add_subtitle ((*i)->text, parse_state); - examine_font_nodes (xml, (*i)->font_nodes, parse_state); - parse_state.text_nodes.pop_back (); - } -} - -void -SubtitleContent::maybe_add_subtitle (string text, ParseState const & parse_state) -{ - if (empty_or_white_space (text)) { - return; - } - - if (parse_state.text_nodes.empty() || parse_state.subtitle_nodes.empty ()) { - return; - } - - DCP_ASSERT (!parse_state.text_nodes.empty ()); - DCP_ASSERT (!parse_state.subtitle_nodes.empty ()); - - dcp::FontNode effective_font (parse_state.font_nodes); - dcp::TextNode effective_text (*parse_state.text_nodes.back ()); - dcp::SubtitleNode effective_subtitle (*parse_state.subtitle_nodes.back ()); - - _subtitles.push_back ( - SubtitleString ( - effective_font.id, - effective_font.italic.get_value_or (false), - effective_font.colour.get_value_or (dcp::Colour (255, 255, 255)), - effective_font.size, - effective_font.aspect_adjust.get_value_or (1.0), - effective_subtitle.in, - effective_subtitle.out, - effective_text.h_position, - effective_text.h_align, - effective_text.v_position, - effective_text.v_align, - text, - effective_font.effect.get_value_or (NONE), - effective_font.effect_colour.get_value_or (dcp::Colour (0, 0, 0)), - effective_subtitle.fade_up_time, - effective_subtitle.fade_down_time - ) - ); -} - -list -SubtitleContent::subtitles_during (Time from, Time to) const -{ - list s; - for (list::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { - if (i->out() >= from && i->in() <= to) { - s.push_back (*i); - } - } - - return s; -} - -void -SubtitleContent::add (SubtitleString s) -{ - _subtitles.push_back (s); -} - -void -SubtitleContent::write_xml (boost::filesystem::path p) const -{ - FILE* f = fopen_boost (p, "w"); - if (!f) { - throw FileError ("Could not open file for writing", p, -1); - } - - Glib::ustring const s = xml_as_string (); - fwrite (s.c_str(), 1, s.bytes(), f); - fclose (f); - - _file = p; -} - -Time -SubtitleContent::latest_subtitle_out () const -{ - Time t; - for (list::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { - if (i->out() > t) { - t = i->out (); - } - } - - return t; -} - -bool -SubtitleContent::equals (shared_ptr other_asset, EqualityOptions options, NoteHandler note) const -{ - if (!Asset::equals (other_asset, options, note)) { - return false; - } - - shared_ptr other = dynamic_pointer_cast (other_asset); - if (!other) { - return false; - } - - if (_reel_number != other->_reel_number) { - note (DCP_ERROR, "subtitle reel numbers differ"); - return false; - } - - if (_language != other->_language) { - note (DCP_ERROR, "subtitle languages differ"); - return false; - } - - if (_subtitles != other->_subtitles) { - note (DCP_ERROR, "subtitles differ"); - return false; - } - - return true; -} diff --git a/src/subtitle_content.h b/src/subtitle_content.h deleted file mode 100644 index d80d631c..00000000 --- a/src/subtitle_content.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef LIBDCP_SUBTITLE_CONTENT_H -#define LIBDCP_SUBTITLE_CONTENT_H - -#include "asset.h" -#include "dcp_time.h" -#include "subtitle_string.h" -#include - -namespace dcp -{ - -class SubtitleString; -class FontNode; -class TextNode; -class SubtitleNode; -class LoadFontNode; - -/** @class SubtitleContent - * @brief A parent for classes representing a file containing subtitles. - */ -class SubtitleContent : public Asset -{ -public: - SubtitleContent (); - SubtitleContent (boost::filesystem::path file); - - bool equals ( - boost::shared_ptr, - EqualityOptions, - NoteHandler note - ) const; - - std::string language () const { - return _language; - } - - std::list subtitles_during (Time from, Time to) const; - std::list const & subtitles () const { - return _subtitles; - } - - void add (SubtitleString); - - void write_xml (boost::filesystem::path) const; - virtual Glib::ustring xml_as_string () const { - /* XXX: this should be pure virtual when SMPTE writing is implemented */ - return ""; - } - - Time latest_subtitle_out () const; - - virtual std::list > load_font_nodes () const = 0; - -protected: - void parse_common (boost::shared_ptr xml, std::list > font_nodes); - - std::string pkl_type (Standard) const { - return "text/xml"; - } - - std::string asdcp_kind () const { - return "Subtitle"; - } - - /* strangely, this is sometimes a string */ - std::string _reel_number; - std::string _language; - - std::list _subtitles; - -private: - struct ParseState { - std::list > font_nodes; - std::list > text_nodes; - std::list > subtitle_nodes; - }; - - void maybe_add_subtitle (std::string text, ParseState const & parse_state); - - void examine_font_nodes ( - boost::shared_ptr xml, - std::list > const & font_nodes, - ParseState& parse_state - ); - - void examine_text_nodes ( - boost::shared_ptr xml, - std::list > const & text_nodes, - ParseState& parse_state - ); -}; - -} - -#endif diff --git a/src/wscript b/src/wscript index 7328178b..54f3a03b 100644 --- a/src/wscript +++ b/src/wscript @@ -19,7 +19,7 @@ def build(bld): font_node.cc gamma_transfer_function.cc interop_load_font_node.cc - interop_subtitle_content.cc + interop_subtitle_asset.cc key.cc local_time.cc metadata.cc @@ -43,7 +43,7 @@ def build(bld): rgb_xyz.cc signer.cc smpte_load_font_node.cc - smpte_subtitle_content.cc + smpte_subtitle_asset.cc sound_mxf.cc sound_mxf_writer.cc sound_frame.cc @@ -51,7 +51,7 @@ def build(bld): stereo_picture_mxf_writer.cc stereo_picture_frame.cc subtitle_node.cc - subtitle_content.cc + subtitle_asset.cc subtitle_string.cc text_node.cc transfer_function.cc @@ -78,7 +78,7 @@ def build(bld): font.h gamma_transfer_function.h interop_load_font_node.h - interop_subtitle_content.h + interop_subtitle_asset.h key.h load_font_node.h local_time.h @@ -104,14 +104,14 @@ def build(bld): ref.h signer.h smpte_load_font_node.h - smpte_subtitle_content.h + smpte_subtitle_asset.h sound_frame.h sound_mxf.h sound_mxf_writer.h stereo_picture_mxf.h stereo_picture_frame.h subtitle_node.h - subtitle_content.h + subtitle_asset.h subtitle_string.h transfer_function.h types.h -- cgit v1.2.3