/*
- Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
#include "wx_util.h"
#include "video_panel.h"
#include "audio_panel.h"
-#include "subtitle_panel.h"
+#include "caption_panel.h"
#include "timing_panel.h"
#include "timeline_dialog.h"
#include "image_sequence_dialog.h"
#include "film_viewer.h"
#include "lib/audio_content.h"
-#include "lib/subtitle_content.h"
+#include "lib/caption_content.h"
#include "lib/video_content.h"
#include "lib/ffmpeg_content.h"
#include "lib/content_factory.h"
#include "lib/config.h"
#include "lib/log.h"
#include "lib/compose.hpp"
+#include "lib/text_caption_file_content.h"
+#include "lib/text_caption_file.h"
#include <wx/wx.h>
#include <wx/notebook.h>
#include <wx/listctrl.h>
using std::string;
using std::cout;
using std::vector;
+using std::max;
using std::exception;
using boost::shared_ptr;
using boost::weak_ptr;
ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr<Film> film, FilmViewer* viewer)
: _timeline_dialog (0)
, _parent (n)
+ , _last_selected_tab (0)
, _film (film)
, _film_viewer (viewer)
, _generally_sensitive (true)
_panels.push_back (_video_panel);
_audio_panel = new AudioPanel (this);
_panels.push_back (_audio_panel);
- _subtitle_panel = new SubtitlePanel (this);
- _panels.push_back (_subtitle_panel);
+ for (int i = 0; i < CAPTION_COUNT; ++i) {
+ _caption_panel[i] = new CaptionPanel (this, static_cast<CaptionType>(i));
+ _panels.push_back (_caption_panel[i]);
+ }
_timing_panel = new TimingPanel (this, _film_viewer);
_panels.push_back (_timing_panel);
}
ContentList
-ContentPanel::selected_subtitle ()
+ContentPanel::selected_caption ()
{
ContentList sc;
BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
- if (i->subtitle) {
+ if (!i->caption.empty()) {
sc.push_back (i);
}
}
}
optional<DCPTime> go_to;
- BOOST_FOREACH (shared_ptr<Content> i, selected ()) {
- if (!go_to || i->position() < go_to.get()) {
- go_to = i->position ();
+ BOOST_FOREACH (shared_ptr<Content> i, selected()) {
+ DCPTime p;
+ p = i->position();
+ if (dynamic_pointer_cast<TextCaptionFileContent>(i) && i->paths_valid()) {
+ /* Rather special case; if we select a text subtitle file jump to its
+ first subtitle.
+ */
+ TextCaptionFile ts (dynamic_pointer_cast<TextCaptionFileContent>(i));
+ if (ts.first()) {
+ p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position()));
+ }
+ }
+ if (!go_to || p < go_to.get()) {
+ go_to = p;
}
}
if (go_to && Config::instance()->jump_to_selected ()) {
- _film_viewer->set_position (go_to.get ());
+ _film_viewer->set_position (go_to.get().ceil(_film->video_frame_rate()));
}
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<Content> i, selected()) {
+ if (i->video) {
+ have_video = true;
+ }
+ if (i->audio) {
+ have_audio = true;
+ }
+ BOOST_FOREACH (shared_ptr<CaptionContent> 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 ();
}
void
void
ContentPanel::timeline_clicked ()
{
+ if (!_film) {
+ return;
+ }
+
if (_timeline_dialog) {
_timeline_dialog->Destroy ();
_timeline_dialog = 0;
_video_panel->Enable (_generally_sensitive && video_selection.size() > 0);
_audio_panel->Enable (_generally_sensitive && audio_selection.size() > 0);
- _subtitle_panel->Enable (_generally_sensitive && selection.size() == 1 && selection.front()->subtitle);
+ 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);
}