From c1f98c84cdf3829b31929453b8a89fdcbdcd0c42 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 18 Jul 2018 23:40:25 +0100 Subject: More renaming; text -> plain. sed -i "s/TextTextContent/PlainText/g" src/lib/*.cc src/lib/*.h src/wx/*.cc src/wx/*.h src/tools/*.cc test/*.cc sed -i "s/text_text/plain_text/g" src/lib/*.cc src/lib/*.h src/wx/*.cc src/wx/*.h src/tools/*.cc test/*.cc src/lib/wscript mv src/lib/text_text_content.cc src/lib/plain_text_content.cc mv src/lib/text_text_content.h src/lib/plain_text_content.h mv src/lib/text_text_decoder.cc src/lib/plain_text_decoder.cc mv src/lib/text_text_decoder.h src/lib/plain_text_decoder.h --- src/lib/content_factory.cc | 6 +-- src/lib/decoder_factory.cc | 6 +-- src/lib/plain_text_content.cc | 95 +++++++++++++++++++++++++++++++++++++++++++ src/lib/plain_text_content.h | 46 +++++++++++++++++++++ src/lib/plain_text_decoder.cc | 88 +++++++++++++++++++++++++++++++++++++++ src/lib/plain_text_decoder.h | 43 ++++++++++++++++++++ src/lib/text_file.h | 2 +- src/lib/text_subtitle.cc | 4 +- src/lib/text_subtitle.h | 6 +-- src/lib/text_text_content.cc | 95 ------------------------------------------- src/lib/text_text_content.h | 46 --------------------- src/lib/text_text_decoder.cc | 88 --------------------------------------- src/lib/text_text_decoder.h | 43 -------------------- src/lib/wscript | 4 +- 14 files changed, 286 insertions(+), 286 deletions(-) create mode 100644 src/lib/plain_text_content.cc create mode 100644 src/lib/plain_text_content.h create mode 100644 src/lib/plain_text_decoder.cc create mode 100644 src/lib/plain_text_decoder.h delete mode 100644 src/lib/text_text_content.cc delete mode 100644 src/lib/text_text_content.h delete mode 100644 src/lib/text_text_decoder.cc delete mode 100644 src/lib/text_text_decoder.h (limited to 'src/lib') diff --git a/src/lib/content_factory.cc b/src/lib/content_factory.cc index 14ca579e9..24ad95578 100644 --- a/src/lib/content_factory.cc +++ b/src/lib/content_factory.cc @@ -26,7 +26,7 @@ #include "audio_content.h" #include "image_content.h" #include "atmos_mxf_content.h" -#include "text_text_content.h" +#include "plain_text_content.h" #include "dcp_content.h" #include "dcp_text_content.h" #include "util.h" @@ -88,7 +88,7 @@ content_factory (shared_ptr film, cxml::NodePtr node, int version, l ); } else if (type == "SubRip" || type == "TextSubtitle") { - content.reset (new TextTextContent (film, node, version)); + content.reset (new PlainText (film, node, version)); } else if (type == "DCP") { content.reset (new DCPContent (film, node, version)); } else if (type == "DCPSubtitle") { @@ -210,7 +210,7 @@ content_factory (shared_ptr film, boost::filesystem::path path) if (valid_image_file (path)) { single.reset (new ImageContent (film, path)); } else if (ext == ".srt" || ext == ".ssa" || ext == ".ass") { - single.reset (new TextTextContent (film, path)); + single.reset (new PlainText (film, path)); } else if (ext == ".xml") { cxml::Document doc; doc.read_file (path); diff --git a/src/lib/decoder_factory.cc b/src/lib/decoder_factory.cc index 1a0af1b2c..4301edd17 100644 --- a/src/lib/decoder_factory.cc +++ b/src/lib/decoder_factory.cc @@ -24,8 +24,8 @@ #include "dcp_decoder.h" #include "image_content.h" #include "image_decoder.h" -#include "text_text_content.h" -#include "text_text_decoder.h" +#include "plain_text_content.h" +#include "plain_text_decoder.h" #include "dcp_text_content.h" #include "dcp_text_decoder.h" #include "video_mxf_content.h" @@ -54,7 +54,7 @@ decoder_factory (shared_ptr content, shared_ptr log, bool fa return shared_ptr (new ImageDecoder (ic, log)); } - shared_ptr rc = dynamic_pointer_cast (content); + shared_ptr rc = dynamic_pointer_cast (content); if (rc) { return shared_ptr (new TextTextDecoder (rc, log)); } diff --git a/src/lib/plain_text_content.cc b/src/lib/plain_text_content.cc new file mode 100644 index 000000000..6ca783c16 --- /dev/null +++ b/src/lib/plain_text_content.cc @@ -0,0 +1,95 @@ +/* + Copyright (C) 2014-2016 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see . + +*/ + +#include "plain_text_content.h" +#include "util.h" +#include "text_subtitle.h" +#include "film.h" +#include "font.h" +#include "text_content.h" +#include +#include +#include + +#include "i18n.h" + +using std::string; +using std::cout; +using boost::shared_ptr; +using dcp::raw_convert; + +PlainText::PlainText (shared_ptr film, boost::filesystem::path path) + : Content (film, path) +{ + subtitle.reset (new TextContent (this)); +} + +PlainText::PlainText (shared_ptr film, cxml::ConstNodePtr node, int version) + : Content (film, node) + , _length (node->number_child ("Length")) +{ + subtitle = TextContent::from_xml (this, node, version); +} + +void +PlainText::examine (boost::shared_ptr job) +{ + Content::examine (job); + TextSubtitle s (shared_from_this ()); + + /* Default to turning these subtitles on */ + subtitle->set_use (true); + + boost::mutex::scoped_lock lm (_mutex); + _length = s.length (); + subtitle->add_font (shared_ptr (new Font (TEXT_FONT_ID))); +} + +string +PlainText::summary () const +{ + return path_summary() + " " + _("[subtitles]"); +} + +string +PlainText::technical_summary () const +{ + return Content::technical_summary() + " - " + _("Text subtitles"); +} + +void +PlainText::as_xml (xmlpp::Node* node, bool with_paths) const +{ + node->add_child("Type")->add_child_text ("TextSubtitle"); + Content::as_xml (node, with_paths); + + if (subtitle) { + subtitle->as_xml (node); + } + + node->add_child("Length")->add_child_text (raw_convert (_length.get ())); +} + +DCPTime +PlainText::full_length () const +{ + FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate ()); + return DCPTime (_length, frc); +} diff --git a/src/lib/plain_text_content.h b/src/lib/plain_text_content.h new file mode 100644 index 000000000..7a7ef66ea --- /dev/null +++ b/src/lib/plain_text_content.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2014-2016 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see . + +*/ + +#include "content.h" + +class Job; + +/** @class PlainText + * @brief SubRip or SSA subtitles. + */ +class PlainText : public Content +{ +public: + PlainText (boost::shared_ptr, boost::filesystem::path); + PlainText (boost::shared_ptr, cxml::ConstNodePtr, int); + + boost::shared_ptr shared_from_this () { + return boost::dynamic_pointer_cast<PlainText> (Content::shared_from_this ()); + } + + void examine (boost::shared_ptr<Job>); + std::string summary () const; + std::string technical_summary () const; + void as_xml (xmlpp::Node *, bool with_paths) const; + DCPTime full_length () const; + +private: + ContentTime _length; +}; diff --git a/src/lib/plain_text_decoder.cc b/src/lib/plain_text_decoder.cc new file mode 100644 index 000000000..71f7bed42 --- /dev/null +++ b/src/lib/plain_text_decoder.cc @@ -0,0 +1,88 @@ +/* + Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "plain_text_decoder.h" +#include "plain_text_content.h" +#include "text_content.h" +#include <dcp/subtitle_string.h> +#include <boost/foreach.hpp> +#include <iostream> + +using std::list; +using std::vector; +using std::string; +using std::cout; +using std::max; +using boost::shared_ptr; +using boost::optional; +using boost::dynamic_pointer_cast; + +TextTextDecoder::TextTextDecoder (shared_ptr<const PlainText> content, shared_ptr<Log> log) + : TextSubtitle (content) + , _next (0) +{ + ContentTime first; + if (!_subtitles.empty()) { + first = content_time_period(_subtitles[0]).from; + } + subtitle.reset (new TextDecoder (this, content->subtitle, log, first)); +} + +void +TextTextDecoder::seek (ContentTime time, bool accurate) +{ + /* It's worth back-tracking a little here as decoding is cheap and it's nice if we don't miss + too many subtitles when seeking. + */ + time -= ContentTime::from_seconds (5); + if (time < ContentTime()) { + time = ContentTime(); + } + + Decoder::seek (time, accurate); + + _next = 0; + while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) { + ++_next; + } +} + +bool +TextTextDecoder::pass () +{ + if (_next >= _subtitles.size ()) { + return true; + } + + ContentTimePeriod const p = content_time_period (_subtitles[_next]); + subtitle->emit_text (p, _subtitles[_next]); + + ++_next; + return false; +} + +ContentTimePeriod +TextTextDecoder::content_time_period (sub::Subtitle s) const +{ + return ContentTimePeriod ( + ContentTime::from_seconds (s.from.all_as_seconds()), + ContentTime::from_seconds (s.to.all_as_seconds()) + ); +} diff --git a/src/lib/plain_text_decoder.h b/src/lib/plain_text_decoder.h new file mode 100644 index 000000000..4bdedf58d --- /dev/null +++ b/src/lib/plain_text_decoder.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#ifndef DCPOMATIC_TEXT_SUBTITLE_DECODER_H +#define DCPOMATIC_TEXT_SUBTITLE_DECODER_H + +#include "text_decoder.h" +#include "text_subtitle.h" + +class PlainText; + +class TextTextDecoder : public Decoder, public TextSubtitle +{ +public: + TextTextDecoder (boost::shared_ptr<const PlainText>, boost::shared_ptr<Log> log); + + void seek (ContentTime time, bool accurate); + bool pass (); + +private: + ContentTimePeriod content_time_period (sub::Subtitle s) const; + + size_t _next; +}; + +#endif diff --git a/src/lib/text_file.h b/src/lib/text_file.h index 346571fc1..8cf0d3eae 100644 --- a/src/lib/text_file.h +++ b/src/lib/text_file.h @@ -29,7 +29,7 @@ class TextFileContent; class text_file_time_test; class text_file_coordinate_test; -class text_text_content_test; +class plain_text_content_test; class text_file_parse_test; class TextFile diff --git a/src/lib/text_subtitle.cc b/src/lib/text_subtitle.cc index 35acb9022..35801e160 100644 --- a/src/lib/text_subtitle.cc +++ b/src/lib/text_subtitle.cc @@ -21,7 +21,7 @@ #include "text_subtitle.h" #include "cross.h" #include "exceptions.h" -#include "text_text_content.h" +#include "plain_text_content.h" #include <sub/subrip_reader.h> #include <sub/ssa_reader.h> #include <sub/collect.h> @@ -39,7 +39,7 @@ using boost::scoped_array; using boost::optional; using dcp::Data; -TextSubtitle::TextSubtitle (shared_ptr<const TextTextContent> content) +TextSubtitle::TextSubtitle (shared_ptr<const PlainText> content) { Data in (content->path (0)); diff --git a/src/lib/text_subtitle.h b/src/lib/text_subtitle.h index 0cd33c9fb..60571a439 100644 --- a/src/lib/text_subtitle.h +++ b/src/lib/text_subtitle.h @@ -26,16 +26,16 @@ #include <boost/shared_ptr.hpp> #include <vector> -class TextTextContent; +class PlainText; class text_subtitle_time_test; class text_subtitle_coordinate_test; -class text_text_content_test; +class plain_text_content_test; class text_subtitle_parse_test; class TextSubtitle { public: - explicit TextSubtitle (boost::shared_ptr<const TextTextContent>); + explicit TextSubtitle (boost::shared_ptr<const PlainText>); boost::optional<ContentTime> first () const; ContentTime length () const; diff --git a/src/lib/text_text_content.cc b/src/lib/text_text_content.cc deleted file mode 100644 index 1ff66c490..000000000 --- a/src/lib/text_text_content.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> - - This file is part of DCP-o-matic. - - DCP-o-matic 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. - - DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "text_text_content.h" -#include "util.h" -#include "text_subtitle.h" -#include "film.h" -#include "font.h" -#include "text_content.h" -#include <dcp/raw_convert.h> -#include <libxml++/libxml++.h> -#include <iostream> - -#include "i18n.h" - -using std::string; -using std::cout; -using boost::shared_ptr; -using dcp::raw_convert; - -TextTextContent::TextTextContent (shared_ptr<const Film> film, boost::filesystem::path path) - : Content (film, path) -{ - subtitle.reset (new TextContent (this)); -} - -TextTextContent::TextTextContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version) - : Content (film, node) - , _length (node->number_child<ContentTime::Type> ("Length")) -{ - subtitle = TextContent::from_xml (this, node, version); -} - -void -TextTextContent::examine (boost::shared_ptr<Job> job) -{ - Content::examine (job); - TextSubtitle s (shared_from_this ()); - - /* Default to turning these subtitles on */ - subtitle->set_use (true); - - boost::mutex::scoped_lock lm (_mutex); - _length = s.length (); - subtitle->add_font (shared_ptr<Font> (new Font (TEXT_FONT_ID))); -} - -string -TextTextContent::summary () const -{ - return path_summary() + " " + _("[subtitles]"); -} - -string -TextTextContent::technical_summary () const -{ - return Content::technical_summary() + " - " + _("Text subtitles"); -} - -void -TextTextContent::as_xml (xmlpp::Node* node, bool with_paths) const -{ - node->add_child("Type")->add_child_text ("TextSubtitle"); - Content::as_xml (node, with_paths); - - if (subtitle) { - subtitle->as_xml (node); - } - - node->add_child("Length")->add_child_text (raw_convert<string> (_length.get ())); -} - -DCPTime -TextTextContent::full_length () const -{ - FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate ()); - return DCPTime (_length, frc); -} diff --git a/src/lib/text_text_content.h b/src/lib/text_text_content.h deleted file mode 100644 index ccc86fbbf..000000000 --- a/src/lib/text_text_content.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> - - This file is part of DCP-o-matic. - - DCP-o-matic 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. - - DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "content.h" - -class Job; - -/** @class TextTextContent - * @brief SubRip or SSA subtitles. - */ -class TextTextContent : public Content -{ -public: - TextTextContent (boost::shared_ptr<const Film>, boost::filesystem::path); - TextTextContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int); - - boost::shared_ptr<TextTextContent> shared_from_this () { - return boost::dynamic_pointer_cast<TextTextContent> (Content::shared_from_this ()); - } - - void examine (boost::shared_ptr<Job>); - std::string summary () const; - std::string technical_summary () const; - void as_xml (xmlpp::Node *, bool with_paths) const; - DCPTime full_length () const; - -private: - ContentTime _length; -}; diff --git a/src/lib/text_text_decoder.cc b/src/lib/text_text_decoder.cc deleted file mode 100644 index 2ae5cd38e..000000000 --- a/src/lib/text_text_decoder.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> - - This file is part of DCP-o-matic. - - DCP-o-matic 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. - - DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "text_text_decoder.h" -#include "text_text_content.h" -#include "text_content.h" -#include <dcp/subtitle_string.h> -#include <boost/foreach.hpp> -#include <iostream> - -using std::list; -using std::vector; -using std::string; -using std::cout; -using std::max; -using boost::shared_ptr; -using boost::optional; -using boost::dynamic_pointer_cast; - -TextTextDecoder::TextTextDecoder (shared_ptr<const TextTextContent> content, shared_ptr<Log> log) - : TextSubtitle (content) - , _next (0) -{ - ContentTime first; - if (!_subtitles.empty()) { - first = content_time_period(_subtitles[0]).from; - } - subtitle.reset (new TextDecoder (this, content->subtitle, log, first)); -} - -void -TextTextDecoder::seek (ContentTime time, bool accurate) -{ - /* It's worth back-tracking a little here as decoding is cheap and it's nice if we don't miss - too many subtitles when seeking. - */ - time -= ContentTime::from_seconds (5); - if (time < ContentTime()) { - time = ContentTime(); - } - - Decoder::seek (time, accurate); - - _next = 0; - while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) { - ++_next; - } -} - -bool -TextTextDecoder::pass () -{ - if (_next >= _subtitles.size ()) { - return true; - } - - ContentTimePeriod const p = content_time_period (_subtitles[_next]); - subtitle->emit_text (p, _subtitles[_next]); - - ++_next; - return false; -} - -ContentTimePeriod -TextTextDecoder::content_time_period (sub::Subtitle s) const -{ - return ContentTimePeriod ( - ContentTime::from_seconds (s.from.all_as_seconds()), - ContentTime::from_seconds (s.to.all_as_seconds()) - ); -} diff --git a/src/lib/text_text_decoder.h b/src/lib/text_text_decoder.h deleted file mode 100644 index daaf2fcfe..000000000 --- a/src/lib/text_text_decoder.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> - - This file is part of DCP-o-matic. - - DCP-o-matic 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. - - DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. - -*/ - -#ifndef DCPOMATIC_TEXT_SUBTITLE_DECODER_H -#define DCPOMATIC_TEXT_SUBTITLE_DECODER_H - -#include "text_decoder.h" -#include "text_subtitle.h" - -class TextTextContent; - -class TextTextDecoder : public Decoder, public TextSubtitle -{ -public: - TextTextDecoder (boost::shared_ptr<const TextTextContent>, boost::shared_ptr<Log> log); - - void seek (ContentTime time, bool accurate); - bool pass (); - -private: - ContentTimePeriod content_time_period (sub::Subtitle s) const; - - size_t _next; -}; - -#endif diff --git a/src/lib/wscript b/src/lib/wscript index 4a7132e48..b3e04e28b 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -135,8 +135,8 @@ sources = """ text_content.cc text_decoder.cc text_subtitle.cc - text_text_content.cc - text_text_decoder.cc + plain_text_content.cc + plain_text_decoder.cc timer.cc transcode_job.cc types.cc -- cgit v1.2.3