Add has_subtitles method to SubtitleContent; tidy up timeline display a bit.
authorCarl Hetherington <cth@carlh.net>
Thu, 10 Jul 2014 21:41:48 +0000 (22:41 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 10 Jul 2014 21:41:48 +0000 (22:41 +0100)
src/lib/dcp_content.cc
src/lib/dcp_content.h
src/lib/dcp_examiner.cc
src/lib/dcp_examiner.h
src/lib/dcp_subtitle_content.h
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
src/lib/subrip_content.h
src/lib/subtitle_content.h
src/wx/subtitle_panel.cc
src/wx/timeline.cc

index b1d0d9a378b855b97893e5635d6d11d3cf5b56b5..0eef075d7c0b9eddcb58c7dfd544af212e90b21c 100644 (file)
@@ -34,6 +34,7 @@ DCPContent::DCPContent (shared_ptr<const Film> 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<const Film> 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)
 {
        job->set_progress_unknown ();
        Content::examine (job);
+       
        shared_ptr<DCPExaminer> 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;
+}
index 7b7e85d9df745220e334207cb8ebe6ffd9c1d29e..60b7142de1fe655dc0a6e4826a2841fb3d611334 100644 (file)
@@ -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;
 };
index 39bf2d0983c3c59c1eb6b1c6ddf63fa102ba0896..625276e180de13f54a92a05b16f5e453f27e8d08 100644 (file)
@@ -84,5 +84,9 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content)
 
                        _audio_length += ContentTime::from_frames ((*i)->main_sound()->duration(), _video_frame_rate.get ());
                }
+
+               if ((*i)->main_subtitle ()) {
+                       _has_subtitles = true;
+               }
        }
 }
index 24a59dd342ebcbdd9bd4b142f7a9e6eddc8946fc..5b510743b73c8ce8ba2a876c84e8fe5ae4d71b11 100644 (file)
@@ -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<int> _audio_frame_rate;
        ContentTime _audio_length;
        std::string _name;
+       bool _has_subtitles;
 };
index 79338c1af6d7e4137001a5c8c35765aa6d0c7c61..5794b59516e6767f586cc5d0a33663b2ed9ef376 100644 (file)
@@ -25,6 +25,7 @@ public:
        DCPSubtitleContent (boost::shared_ptr<const Film>, boost::filesystem::path);
        DCPSubtitleContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
 
+       /* Content */
        void examine (boost::shared_ptr<Job>);
        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;
 };
index d2bb329db346bc3ca34988f95a8425a3727dcded..9b2bfc60649c6b9e58b11905ed3216063e6148df 100644 (file)
@@ -409,3 +409,9 @@ FFmpegContent::subtitles_during (ContentTimePeriod period, bool starting) const
 
        return d;
 }
+
+bool
+FFmpegContent::has_subtitles () const
+{
+       return !subtitle_streams().empty ();
+}
index 6bf6c0f502c6562e7fd5ba7b3b19bd0c96315cab..67839794b97945496f4158f7379349794273fa66 100644 (file)
@@ -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<Filter const *> const &);
        
        std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
index 7da6e71f7b49e262e0cb741f72bb6fcfcc897116..d2dcdee00b09cce5e1b014dba924fd0b09bea8ff 100644 (file)
@@ -29,6 +29,7 @@ public:
                return boost::dynamic_pointer_cast<SubRipContent> (Content::shared_from_this ());
        }
        
+       /* Content */
        void examine (boost::shared_ptr<Job>);
        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;
 };
index 1425c33cd695ff5a06941e11db27cd5386c7000b..29634f95a9e3921419e9e5b0f7eed21c9d4034bc 100644 (file)
@@ -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);
index 5cfd295042e6bfdc407511a6f2171ca2a041b306..4271b2d92cfe3a0ba9e546a432f47f7fe84464f9 100644 (file)
@@ -166,7 +166,7 @@ SubtitlePanel::setup_sensitivity ()
                shared_ptr<const SubRipContent> sc = boost::dynamic_pointer_cast<const SubRipContent> (*i);
                shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (*i);
                if (fc) {
-                       if (!fc->subtitle_streams().empty ()) {
+                       if (!fc->has_subtitles ()) {
                                ++ffmpeg_subs;
                                ++any_subs;
                        }
index 534f4eda752ad4078c9d6afbc982a138de4586d9..fc3aefdaac21b2f6252225ae557872d70d12e7cf 100644 (file)
@@ -22,6 +22,7 @@
 #include <boost/weak_ptr.hpp>
 #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<FFmpegContent> (content ())) {
-                       return _("video");
-               } else {
+               if (dynamic_pointer_cast<ImageContent> (content ()) && content()->number_of_paths() == 1) {
                        return _("still");
+               } else {
+                       return _("video");
                }
        }
 
@@ -435,7 +436,9 @@ Timeline::playlist_changed ()
                if (dynamic_pointer_cast<AudioContent> (*i)) {
                        _views.push_back (shared_ptr<View> (new AudioContentView (*this, *i)));
                }
-               if (dynamic_pointer_cast<SubtitleContent> (*i)) {
+
+               shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (*i);
+               if (sc && sc->has_subtitles ()) {
                        _views.push_back (shared_ptr<View> (new SubtitleContentView (*this, *i)));
                }
        }