From a8af9a0b57b853b8a8cd8fa35adb3fc967d59ee7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 10 Jul 2014 22:41:48 +0100 Subject: [PATCH] Add has_subtitles method to SubtitleContent; tidy up timeline display a bit. --- src/lib/dcp_content.cc | 13 +++++++++++++ src/lib/dcp_content.h | 4 ++++ src/lib/dcp_examiner.cc | 4 ++++ src/lib/dcp_examiner.h | 5 +++++ src/lib/dcp_subtitle_content.h | 6 ++++++ src/lib/ffmpeg_content.cc | 6 ++++++ src/lib/ffmpeg_content.h | 3 +++ src/lib/subrip_content.h | 6 ++++++ src/lib/subtitle_content.h | 8 ++++++++ src/wx/subtitle_panel.cc | 2 +- src/wx/timeline.cc | 13 ++++++++----- 11 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index b1d0d9a37..0eef075d7 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -34,6 +34,7 @@ DCPContent::DCPContent (shared_ptr f, boost::filesystem::path p) , VideoContent (f) , SingleStreamAudioContent (f) , SubtitleContent (f) + , _has_subtitles (false) , _directory (p) { read_directory (p); @@ -46,6 +47,7 @@ DCPContent::DCPContent (shared_ptr f, cxml::ConstNodePtr node, int v , SubtitleContent (f, node, version) { _name = node->string_child ("Name"); + _has_subtitles = node->bool_child ("HasSubtitles"); _directory = node->string_child ("Directory"); } @@ -66,12 +68,14 @@ DCPContent::examine (shared_ptr job) { job->set_progress_unknown (); Content::examine (job); + shared_ptr examiner (new DCPExaminer (shared_from_this ())); take_from_video_examiner (examiner); take_from_audio_examiner (examiner); boost::mutex::scoped_lock lm (_mutex); _name = examiner->name (); + _has_subtitles = examiner->has_subtitles (); } string @@ -99,7 +103,9 @@ DCPContent::as_xml (xmlpp::Node* node) const SingleStreamAudioContent::as_xml (node); SubtitleContent::as_xml (node); + boost::mutex::scoped_lock lm (_mutex); node->add_child("Name")->add_child_text (_name); + node->add_child("HasSubtitles")->add_child_text (_has_subtitles ? "1" : "0"); node->add_child("Directory")->add_child_text (_directory.string ()); } @@ -116,3 +122,10 @@ DCPContent::identifier () const { return SubtitleContent::identifier (); } + +bool +DCPContent::has_subtitles () const +{ + boost::mutex::scoped_lock lm (_mutex); + return _has_subtitles; +} diff --git a/src/lib/dcp_content.h b/src/lib/dcp_content.h index 7b7e85d9d..60b7142de 100644 --- a/src/lib/dcp_content.h +++ b/src/lib/dcp_content.h @@ -47,6 +47,9 @@ public: void as_xml (xmlpp::Node *) const; std::string identifier () const; + /* SubtitleContent */ + bool has_subtitles () const; + boost::filesystem::path directory () const { boost::mutex::scoped_lock lm (_mutex); return _directory; @@ -56,5 +59,6 @@ private: void read_directory (boost::filesystem::path); std::string _name; + bool _has_subtitles; boost::filesystem::path _directory; }; diff --git a/src/lib/dcp_examiner.cc b/src/lib/dcp_examiner.cc index 39bf2d098..625276e18 100644 --- a/src/lib/dcp_examiner.cc +++ b/src/lib/dcp_examiner.cc @@ -84,5 +84,9 @@ DCPExaminer::DCPExaminer (shared_ptr content) _audio_length += ContentTime::from_frames ((*i)->main_sound()->duration(), _video_frame_rate.get ()); } + + if ((*i)->main_subtitle ()) { + _has_subtitles = true; + } } } diff --git a/src/lib/dcp_examiner.h b/src/lib/dcp_examiner.h index 24a59dd34..5b510743b 100644 --- a/src/lib/dcp_examiner.h +++ b/src/lib/dcp_examiner.h @@ -43,6 +43,10 @@ public: return _name; } + bool has_subtitles () const { + return _has_subtitles; + } + int audio_channels () const { return _audio_channels.get_value_or (0); } @@ -63,4 +67,5 @@ private: boost::optional _audio_frame_rate; ContentTime _audio_length; std::string _name; + bool _has_subtitles; }; diff --git a/src/lib/dcp_subtitle_content.h b/src/lib/dcp_subtitle_content.h index 79338c1af..5794b5951 100644 --- a/src/lib/dcp_subtitle_content.h +++ b/src/lib/dcp_subtitle_content.h @@ -25,6 +25,7 @@ public: DCPSubtitleContent (boost::shared_ptr, boost::filesystem::path); DCPSubtitleContent (boost::shared_ptr, cxml::ConstNodePtr, int); + /* Content */ void examine (boost::shared_ptr); std::string summary () const; std::string technical_summary () const; @@ -32,6 +33,11 @@ public: void as_xml (xmlpp::Node *) const; DCPTime full_length () const; + /* SubtitleContent */ + bool has_subtitles () const { + return true; + } + private: DCPTime _length; }; diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index d2bb329db..9b2bfc606 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -409,3 +409,9 @@ FFmpegContent::subtitles_during (ContentTimePeriod period, bool starting) const return d; } + +bool +FFmpegContent::has_subtitles () const +{ + return !subtitle_streams().empty (); +} diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index 6bf6c0f50..67839794b 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -73,6 +73,9 @@ public: void set_audio_mapping (AudioMapping); boost::filesystem::path audio_analysis_path () const; + /* SubtitleContent */ + bool has_subtitles () const; + void set_filters (std::vector const &); std::vector > subtitle_streams () const { diff --git a/src/lib/subrip_content.h b/src/lib/subrip_content.h index 7da6e71f7..d2dcdee00 100644 --- a/src/lib/subrip_content.h +++ b/src/lib/subrip_content.h @@ -29,6 +29,7 @@ public: return boost::dynamic_pointer_cast (Content::shared_from_this ()); } + /* Content */ void examine (boost::shared_ptr); std::string summary () const; std::string technical_summary () const; @@ -36,6 +37,11 @@ public: void as_xml (xmlpp::Node *) const; DCPTime full_length () const; + /* SubtitleContent */ + bool has_subtitles () const { + return true; + } + private: DCPTime _length; }; diff --git a/src/lib/subtitle_content.h b/src/lib/subtitle_content.h index 1425c33cd..29634f95a 100644 --- a/src/lib/subtitle_content.h +++ b/src/lib/subtitle_content.h @@ -31,6 +31,12 @@ public: static int const SUBTITLE_USE; }; +/** @class SubtitleContent + * @brief Parent for content which has the potential to include subtitles. + * + * Although inheriting from this class indicates that the content could + * have subtitles, it may not. ::has_subtitles() will tell you. + */ class SubtitleContent : public virtual Content { public: @@ -42,6 +48,8 @@ public: void as_xml (xmlpp::Node *) const; std::string identifier () const; + virtual bool has_subtitles () const = 0; + void set_subtitle_use (bool); void set_subtitle_x_offset (double); void set_subtitle_y_offset (double); diff --git a/src/wx/subtitle_panel.cc b/src/wx/subtitle_panel.cc index 5cfd29504..4271b2d92 100644 --- a/src/wx/subtitle_panel.cc +++ b/src/wx/subtitle_panel.cc @@ -166,7 +166,7 @@ SubtitlePanel::setup_sensitivity () shared_ptr sc = boost::dynamic_pointer_cast (*i); shared_ptr dsc = boost::dynamic_pointer_cast (*i); if (fc) { - if (!fc->subtitle_streams().empty ()) { + if (!fc->has_subtitles ()) { ++ffmpeg_subs; ++any_subs; } diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index 534f4eda7..fc3aefdaa 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -22,6 +22,7 @@ #include #include "lib/film.h" #include "lib/playlist.h" +#include "lib/image_content.h" #include "film_editor.h" #include "timeline.h" #include "wx_util.h" @@ -173,7 +174,7 @@ private: gc->StrokePath (path); gc->FillPath (path); - wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->path_summary()).data(), type().data()); + wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->summary()).data(), type().data()); wxDouble name_width; wxDouble name_height; wxDouble name_descent; @@ -241,10 +242,10 @@ private: wxString type () const { - if (dynamic_pointer_cast (content ())) { - return _("video"); - } else { + if (dynamic_pointer_cast (content ()) && content()->number_of_paths() == 1) { return _("still"); + } else { + return _("video"); } } @@ -435,7 +436,9 @@ Timeline::playlist_changed () if (dynamic_pointer_cast (*i)) { _views.push_back (shared_ptr (new AudioContentView (*this, *i))); } - if (dynamic_pointer_cast (*i)) { + + shared_ptr sc = dynamic_pointer_cast (*i); + if (sc && sc->has_subtitles ()) { _views.push_back (shared_ptr (new SubtitleContentView (*this, *i))); } } -- 2.30.2