From dea824f6ff41384a5e17e23de5434cf84eccff29 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 22 Jul 2018 00:41:03 +0100 Subject: [PATCH] Display only required tabs, including subs / ccap. --- src/lib/caption_content.cc | 4 +- src/lib/caption_content.h | 2 +- src/lib/dcp_content.cc | 6 +- src/lib/dcp_examiner.cc | 9 ++- src/lib/dcp_examiner.h | 10 +-- src/lib/dcp_subtitle_content.cc | 2 +- src/lib/ffmpeg_content.cc | 2 +- src/lib/text_caption_file_content.cc | 2 +- src/lib/types.cc | 17 +++- src/lib/types.h | 1 + src/wx/caption_panel.cc | 31 +++++--- src/wx/caption_panel.h | 2 +- src/wx/content_panel.cc | 115 +++++++++++++++++++++++++-- src/wx/content_panel.h | 6 +- src/wx/content_sub_panel.cc | 3 +- src/wx/content_sub_panel.h | 5 ++ 16 files changed, 178 insertions(+), 39 deletions(-) diff --git a/src/lib/caption_content.cc b/src/lib/caption_content.cc index 4fa8b678f..37a3e7c70 100644 --- a/src/lib/caption_content.cc +++ b/src/lib/caption_content.cc @@ -57,7 +57,7 @@ int const CaptionContentProperty::FADE_OUT = 513; int const CaptionContentProperty::OUTLINE_WIDTH = 514; int const CaptionContentProperty::TYPE = 515; -CaptionContent::CaptionContent (Content* parent) +CaptionContent::CaptionContent (Content* parent, CaptionType original_type) : ContentPart (parent) , _use (false) , _burn (false) @@ -68,7 +68,7 @@ CaptionContent::CaptionContent (Content* parent) , _line_spacing (1) , _outline_width (2) , _type (CAPTION_OPEN) - , _original_type (CAPTION_OPEN) + , _original_type (original_type) { } diff --git a/src/lib/caption_content.h b/src/lib/caption_content.h index 767fc7234..4f5780d23 100644 --- a/src/lib/caption_content.h +++ b/src/lib/caption_content.h @@ -58,7 +58,7 @@ public: class CaptionContent : public ContentPart { public: - explicit CaptionContent (Content* parent); + CaptionContent (Content* parent, CaptionType original_type); CaptionContent (Content* parent, std::vector >); void as_xml (xmlpp::Node *) const; diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index e56ad9e21..414a22256 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -191,8 +191,10 @@ DCPContent::examine (shared_ptr job) { boost::mutex::scoped_lock lm (_mutex); _name = examiner->name (); - for (int i = 0; i < examiner->captions(); ++i) { - caption.push_back (shared_ptr (new CaptionContent (this))); + for (int i = 0; i < CAPTION_COUNT; ++i) { + if (examiner->has_caption(static_cast(i))) { + caption.push_back (shared_ptr(new CaptionContent(this, static_cast(i)))); + } } captions = caption.size (); _encrypted = examiner->encrypted (); diff --git a/src/lib/dcp_examiner.cc b/src/lib/dcp_examiner.cc index 8ce4aee00..6b4f854f8 100644 --- a/src/lib/dcp_examiner.cc +++ b/src/lib/dcp_examiner.cc @@ -58,7 +58,6 @@ DCPExaminer::DCPExaminer (shared_ptr content) , _audio_length (0) , _has_video (false) , _has_audio (false) - , _captions (0) , _encrypted (false) , _needs_assets (false) , _kdm_valid (false) @@ -66,6 +65,10 @@ DCPExaminer::DCPExaminer (shared_ptr content) { shared_ptr cpl; + for (int i = 0; i < CAPTION_COUNT; ++i) { + _has_caption[i] = false; + } + if (content->cpl ()) { /* Use the CPL that the content was using before */ BOOST_FOREACH (shared_ptr i, cpls()) { @@ -166,7 +169,7 @@ DCPExaminer::DCPExaminer (shared_ptr content) return; } - ++_captions; + _has_caption[CAPTION_OPEN] = true; } if (i->closed_caption ()) { @@ -176,7 +179,7 @@ DCPExaminer::DCPExaminer (shared_ptr content) return; } - ++_captions; + _has_caption[CAPTION_CLOSED] = true; } if (i->main_picture()) { diff --git a/src/lib/dcp_examiner.h b/src/lib/dcp_examiner.h index 0d55d4643..16385e07a 100644 --- a/src/lib/dcp_examiner.h +++ b/src/lib/dcp_examiner.h @@ -59,10 +59,6 @@ public: return _name; } - int captions () const { - return _captions; - } - bool encrypted () const { return _encrypted; } @@ -87,6 +83,10 @@ public: return _audio_frame_rate.get_value_or (48000); } + bool has_caption (CaptionType type) const { + return _has_caption[type]; + } + bool kdm_valid () const { return _kdm_valid; } @@ -119,7 +119,7 @@ private: bool _has_video; /** true if this DCP has audio content (but false if it has unresolved references to audio content) */ bool _has_audio; - int _captions; + bool _has_caption[CAPTION_COUNT]; bool _encrypted; bool _needs_assets; bool _kdm_valid; diff --git a/src/lib/dcp_subtitle_content.cc b/src/lib/dcp_subtitle_content.cc index 78e81328a..779361f63 100644 --- a/src/lib/dcp_subtitle_content.cc +++ b/src/lib/dcp_subtitle_content.cc @@ -40,7 +40,7 @@ using dcp::raw_convert; DCPSubtitleContent::DCPSubtitleContent (shared_ptr film, boost::filesystem::path path) : Content (film, path) { - caption.push_back (shared_ptr (new CaptionContent (this))); + caption.push_back (shared_ptr (new CaptionContent (this, CAPTION_OPEN))); } DCPSubtitleContent::DCPSubtitleContent (shared_ptr film, cxml::ConstNodePtr node, int version) diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 4300dc970..3f0a692cd 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -304,7 +304,7 @@ FFmpegContent::examine (shared_ptr job) _subtitle_streams = examiner->subtitle_streams (); if (!_subtitle_streams.empty ()) { caption.clear (); - caption.push_back (shared_ptr (new CaptionContent (this))); + caption.push_back (shared_ptr (new CaptionContent (this, CAPTION_OPEN))); _subtitle_stream = _subtitle_streams.front (); } diff --git a/src/lib/text_caption_file_content.cc b/src/lib/text_caption_file_content.cc index c8eb2390a..aa64ca572 100644 --- a/src/lib/text_caption_file_content.cc +++ b/src/lib/text_caption_file_content.cc @@ -38,7 +38,7 @@ using dcp::raw_convert; TextCaptionFileContent::TextCaptionFileContent (shared_ptr film, boost::filesystem::path path) : Content (film, path) { - caption.push_back (shared_ptr (new CaptionContent (this))); + caption.push_back (shared_ptr (new CaptionContent (this, CAPTION_OPEN))); } TextCaptionFileContent::TextCaptionFileContent (shared_ptr film, cxml::ConstNodePtr node, int version) diff --git a/src/lib/types.cc b/src/lib/types.cc index 97373b24e..5474b609a 100644 --- a/src/lib/types.cc +++ b/src/lib/types.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -25,6 +25,8 @@ #include #include +#include "i18n.h" + using std::max; using std::min; using std::string; @@ -116,6 +118,19 @@ caption_type_to_string (CaptionType t) } } +string +caption_type_to_name (CaptionType t) +{ + switch (t) { + case CAPTION_OPEN: + return _("Subtitles"); + case CAPTION_CLOSED: + return _("Closed captions"); + default: + DCPOMATIC_ASSERT (false); + } +} + string video_frame_type_to_string (VideoFrameType t) { diff --git a/src/lib/types.h b/src/lib/types.h index b2bff78fa..6a05f66c9 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -147,6 +147,7 @@ enum CaptionType }; extern std::string caption_type_to_string (CaptionType t); +extern std::string caption_type_to_name (CaptionType t); extern CaptionType string_to_caption_type (std::string s); /** @struct Crop diff --git a/src/wx/caption_panel.cc b/src/wx/caption_panel.cc index 5a3ac39ed..3957c2a45 100644 --- a/src/wx/caption_panel.cc +++ b/src/wx/caption_panel.cc @@ -43,11 +43,11 @@ using std::list; using boost::shared_ptr; using boost::dynamic_pointer_cast; -CaptionPanel::CaptionPanel (ContentPanel* p) - : ContentSubPanel (p, _("Captions")) +CaptionPanel::CaptionPanel (ContentPanel* p, CaptionType t) + : ContentSubPanel (p, std_to_wx(caption_type_to_name(t))) , _caption_view (0) , _fonts_dialog (0) - , _original_type (CAPTION_OPEN) + , _original_type (t) { wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL); @@ -202,6 +202,11 @@ CaptionPanel::film_content_changed (int property) scs = sc.front (); } + shared_ptr caption; + if (scs) { + caption = scs->caption_of_original_type(_original_type); + } + if (property == FFmpegContentProperty::SUBTITLE_STREAMS) { _stream->Clear (); if (fcs) { @@ -218,11 +223,11 @@ CaptionPanel::film_content_changed (int property) } setup_sensitivity (); } else if (property == CaptionContentProperty::USE) { - checked_set (_use, scs ? scs->caption_of_original_type(_original_type)->use() : false); + checked_set (_use, caption ? caption->use() : false); setup_sensitivity (); } else if (property == CaptionContentProperty::TYPE) { - if (scs) { - switch (scs->caption_of_original_type(_original_type)->type()) { + if (caption) { + switch (caption->type()) { case CAPTION_OPEN: _type->SetSelection (0); break; @@ -237,19 +242,19 @@ CaptionPanel::film_content_changed (int property) } setup_sensitivity (); } else if (property == CaptionContentProperty::BURN) { - checked_set (_burn, scs ? scs->caption_of_original_type(_original_type)->burn() : false); + checked_set (_burn, caption ? caption->burn() : false); } else if (property == CaptionContentProperty::X_OFFSET) { - checked_set (_x_offset, scs ? lrint (scs->caption_of_original_type(_original_type)->x_offset() * 100) : 0); + checked_set (_x_offset, caption ? lrint (caption->x_offset() * 100) : 0); } else if (property == CaptionContentProperty::Y_OFFSET) { - checked_set (_y_offset, scs ? lrint (scs->caption_of_original_type(_original_type)->y_offset() * 100) : 0); + checked_set (_y_offset, caption ? lrint (caption->y_offset() * 100) : 0); } else if (property == CaptionContentProperty::X_SCALE) { - checked_set (_x_scale, scs ? lrint (scs->caption_of_original_type(_original_type)->x_scale() * 100) : 100); + checked_set (_x_scale, caption ? lrint (caption->x_scale() * 100) : 100); } else if (property == CaptionContentProperty::Y_SCALE) { - checked_set (_y_scale, scs ? lrint (scs->caption_of_original_type(_original_type)->y_scale() * 100) : 100); + checked_set (_y_scale, caption ? lrint (caption->y_scale() * 100) : 100); } else if (property == CaptionContentProperty::LINE_SPACING) { - checked_set (_line_spacing, scs ? lrint (scs->caption_of_original_type(_original_type)->line_spacing() * 100) : 100); + checked_set (_line_spacing, caption ? lrint (caption->line_spacing() * 100) : 100); } else if (property == CaptionContentProperty::LANGUAGE) { - checked_set (_language, scs ? scs->caption_of_original_type(_original_type)->language() : ""); + checked_set (_language, caption ? caption->language() : ""); } else if (property == DCPContentProperty::REFERENCE_CAPTION) { if (scs) { shared_ptr dcp = dynamic_pointer_cast (scs); diff --git a/src/wx/caption_panel.h b/src/wx/caption_panel.h index 8adb85e15..20af29d7e 100644 --- a/src/wx/caption_panel.h +++ b/src/wx/caption_panel.h @@ -28,7 +28,7 @@ class FontsDialog; class CaptionPanel : public ContentSubPanel { public: - explicit CaptionPanel (ContentPanel *); + CaptionPanel (ContentPanel *, CaptionType t); void film_changed (Film::Property); void film_content_changed (int); diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 40501f717..ce9c66a3e 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -52,6 +52,7 @@ using std::list; using std::string; using std::cout; using std::vector; +using std::max; using std::exception; using boost::shared_ptr; using boost::weak_ptr; @@ -63,6 +64,7 @@ using boost::optional; ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr film, FilmViewer* viewer) : _timeline_dialog (0) , _parent (n) + , _last_selected_tab (0) , _film (film) , _film_viewer (viewer) , _generally_sensitive (true) @@ -125,8 +127,10 @@ ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr film, FilmVie _panels.push_back (_video_panel); _audio_panel = new AudioPanel (this); _panels.push_back (_audio_panel); - _caption_panel = new CaptionPanel (this); - _panels.push_back (_caption_panel); + for (int i = 0; i < CAPTION_COUNT; ++i) { + _caption_panel[i] = new CaptionPanel (this, static_cast(i)); + _panels.push_back (_caption_panel[i]); + } _timing_panel = new TimingPanel (this, _film_viewer); _panels.push_back (_timing_panel); @@ -255,7 +259,7 @@ ContentPanel::selection_changed () } optional go_to; - BOOST_FOREACH (shared_ptr i, selected ()) { + BOOST_FOREACH (shared_ptr i, selected()) { DCPTime p; p = i->position(); if (dynamic_pointer_cast(i) && i->paths_valid()) { @@ -277,7 +281,106 @@ ContentPanel::selection_changed () } if (_timeline_dialog) { - _timeline_dialog->set_selection (selected ()); + _timeline_dialog->set_selection (selected()); + } + + /* Make required tabs visible */ + + if (_notebook->GetPageCount() > 1) { + /* There's more than one tab in the notebook so the current selection could be meaningful + to the user; store it so that we can try to restore it later. + */ + _last_selected_tab = 0; + if (_notebook->GetSelection() != wxNOT_FOUND) { + _last_selected_tab = _notebook->GetPage(_notebook->GetSelection()); + } + } + + bool have_video = false; + bool have_audio = false; + bool have_caption[CAPTION_COUNT] = { false, false }; + BOOST_FOREACH (shared_ptr i, selected()) { + if (i->video) { + have_video = true; + } + if (i->audio) { + have_audio = true; + } + BOOST_FOREACH (shared_ptr j, i->caption) { + have_caption[j->original_type()] = true; + } + } + + bool video_panel = false; + bool audio_panel = false; + bool caption_panel[CAPTION_COUNT] = { false, false }; + for (size_t i = 0; i < _notebook->GetPageCount(); ++i) { + if (_notebook->GetPage(i) == _video_panel) { + video_panel = true; + } else if (_notebook->GetPage(i) == _audio_panel) { + audio_panel = true; + } + for (int j = 0; j < CAPTION_COUNT; ++j) { + if (_notebook->GetPage(i) == _caption_panel[j]) { + caption_panel[j] = true; + } + } + } + + int off = 0; + + if (have_video != video_panel) { + if (video_panel) { + _notebook->RemovePage (off); + } + if (have_video) { + _notebook->InsertPage (off, _video_panel, _video_panel->name()); + } + } + + if (have_video) { + ++off; + } + + if (have_audio != audio_panel) { + if (audio_panel) { + _notebook->RemovePage (off); + } + if (have_audio) { + _notebook->InsertPage (off, _audio_panel, _audio_panel->name()); + } + } + + if (have_audio) { + ++off; + } + + for (int i = 0; i < CAPTION_COUNT; ++i) { + if (have_caption[i] != caption_panel[i]) { + if (caption_panel[i]) { + _notebook->RemovePage (off); + } + if (have_caption[i]) { + _notebook->InsertPage (off, _caption_panel[i], _caption_panel[i]->name()); + } + } + if (have_caption[i]) { + ++off; + } + } + + /* Set up the tab selection */ + + bool done = false; + for (size_t i = 0; i < _notebook->GetPageCount(); ++i) { + if (_notebook->GetPage(i) == _last_selected_tab) { + _notebook->SetSelection (i); + done = true; + } + } + + if (!done) { + _notebook->SetSelection (0); } SelectionChanged (); @@ -447,7 +550,9 @@ ContentPanel::setup_sensitivity () _video_panel->Enable (_generally_sensitive && video_selection.size() > 0); _audio_panel->Enable (_generally_sensitive && audio_selection.size() > 0); - _caption_panel->Enable (_generally_sensitive && selection.size() == 1 && !selection.front()->caption.empty()); + for (int i = 0; i < CAPTION_COUNT; ++i) { + _caption_panel[i]->Enable (_generally_sensitive && selection.size() == 1 && !selection.front()->caption.empty()); + } _timing_panel->Enable (_generally_sensitive); } diff --git a/src/wx/content_panel.h b/src/wx/content_panel.h index e7d9c95b3..3f0fb17a5 100644 --- a/src/wx/content_panel.h +++ b/src/wx/content_panel.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -32,6 +32,7 @@ class wxListEvent; class TimelineDialog; class FilmEditor; class ContentSubPanel; +class CaptionPanel; class AudioPanel; class Film; class FilmViewer; @@ -104,13 +105,14 @@ private: wxButton* _timeline; ContentSubPanel* _video_panel; AudioPanel* _audio_panel; - ContentSubPanel* _caption_panel; + CaptionPanel* _caption_panel[CAPTION_COUNT]; ContentSubPanel* _timing_panel; std::list _panels; ContentMenu* _menu; TimelineDialog* _timeline_dialog; wxNotebook* _parent; ContentList _last_selected; + wxWindow* _last_selected_tab; boost::shared_ptr _film; FilmViewer* _film_viewer; diff --git a/src/wx/content_sub_panel.cc b/src/wx/content_sub_panel.cc index 93296d5b9..a60a65707 100644 --- a/src/wx/content_sub_panel.cc +++ b/src/wx/content_sub_panel.cc @@ -35,8 +35,9 @@ ContentSubPanel::ContentSubPanel (ContentPanel* p, wxString name) : wxScrolledWindow (p->notebook(), wxID_ANY) , _parent (p) , _sizer (new wxBoxSizer (wxVERTICAL)) + , _name (name) { - p->notebook()->AddPage (this, name, false); + p->notebook()->AddPage (this, _name, false); SetScrollRate (-1, 8); SetSizer (_sizer); } diff --git a/src/wx/content_sub_panel.h b/src/wx/content_sub_panel.h index 9afd50d40..8c7854af2 100644 --- a/src/wx/content_sub_panel.h +++ b/src/wx/content_sub_panel.h @@ -40,12 +40,17 @@ public: /** Called when the list of selected Contents changes */ virtual void content_selection_changed () = 0; + wxString name () const { + return _name; + } + protected: void setup_refer_button (wxCheckBox* button, wxStaticText* note, boost::shared_ptr dcp, bool can_reference, std::string why_not) const; ContentPanel* _parent; wxSizer* _sizer; + wxString _name; }; #endif -- 2.30.2