2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "subtitle_panel.h"
21 #include "film_editor.h"
23 #include "subtitle_view.h"
24 #include "content_panel.h"
25 #include "fonts_dialog.h"
26 #include "text_subtitle_appearance_dialog.h"
27 #include "image_subtitle_colour_dialog.h"
28 #include "lib/ffmpeg_content.h"
29 #include "lib/text_subtitle_content.h"
30 #include "lib/ffmpeg_subtitle_stream.h"
31 #include "lib/dcp_subtitle_content.h"
32 #include "lib/text_subtitle_decoder.h"
33 #include "lib/dcp_subtitle_decoder.h"
34 #include "lib/dcp_content.h"
35 #include <wx/spinctrl.h>
36 #include <boost/foreach.hpp>
41 using boost::shared_ptr;
42 using boost::dynamic_pointer_cast;
44 SubtitlePanel::SubtitlePanel (ContentPanel* p)
45 : ContentSubPanel (p, _("Subtitles"))
49 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
50 _sizer->Add (grid, 0, wxALL, 8);
53 _reference = new wxCheckBox (this, wxID_ANY, _("Refer to existing DCP"));
54 grid->Add (_reference, wxGBPosition (r, 0), wxGBSpan (1, 2));
57 _use = new wxCheckBox (this, wxID_ANY, _("Use subtitles"));
58 grid->Add (_use, wxGBPosition (r, 0), wxGBSpan (1, 2));
61 _burn = new wxCheckBox (this, wxID_ANY, _("Burn subtitles into image"));
62 grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
66 add_label_to_sizer (grid, this, _("X Offset"), true, wxGBPosition (r, 0));
67 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
68 _x_offset = new wxSpinCtrl (this);
70 add_label_to_sizer (s, this, _("%"), false);
71 grid->Add (s, wxGBPosition (r, 1));
76 add_label_to_sizer (grid, this, _("Y Offset"), true, wxGBPosition (r, 0));
77 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
78 _y_offset = new wxSpinCtrl (this);
80 add_label_to_sizer (s, this, _("%"), false);
81 grid->Add (s, wxGBPosition (r, 1));
86 add_label_to_sizer (grid, this, _("X Scale"), true, wxGBPosition (r, 0));
87 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
88 _x_scale = new wxSpinCtrl (this);
90 add_label_to_sizer (s, this, _("%"), false);
91 grid->Add (s, wxGBPosition (r, 1));
96 add_label_to_sizer (grid, this, _("Y Scale"), true, wxGBPosition (r, 0));
97 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
98 _y_scale = new wxSpinCtrl (this);
100 add_label_to_sizer (s, this, _("%"), false);
101 grid->Add (s, wxGBPosition (r, 1));
105 add_label_to_sizer (grid, this, _("Language"), true, wxGBPosition (r, 0));
106 _language = new wxTextCtrl (this, wxID_ANY);
107 grid->Add (_language, wxGBPosition (r, 1));
110 add_label_to_sizer (grid, this, _("Stream"), true, wxGBPosition (r, 0));
111 _stream = new wxChoice (this, wxID_ANY);
112 grid->Add (_stream, wxGBPosition (r, 1));
116 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
118 _subtitle_view_button = new wxButton (this, wxID_ANY, _("View..."));
119 s->Add (_subtitle_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
120 _fonts_dialog_button = new wxButton (this, wxID_ANY, _("Fonts..."));
121 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
122 _appearance_dialog_button = new wxButton (this, wxID_ANY, _("Appearance..."));
123 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
125 grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
129 _x_offset->SetRange (-100, 100);
130 _y_offset->SetRange (-100, 100);
131 _x_scale->SetRange (10, 1000);
132 _y_scale->SetRange (10, 1000);
134 _reference->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&SubtitlePanel::reference_clicked, this));
135 _use->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&SubtitlePanel::use_toggled, this));
136 _burn->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&SubtitlePanel::burn_toggled, this));
137 _x_offset->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::x_offset_changed, this));
138 _y_offset->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::y_offset_changed, this));
139 _x_scale->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::x_scale_changed, this));
140 _y_scale->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&SubtitlePanel::y_scale_changed, this));
141 _language->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&SubtitlePanel::language_changed, this));
142 _stream->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&SubtitlePanel::stream_changed, this));
143 _subtitle_view_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&SubtitlePanel::subtitle_view_clicked, this));
144 _fonts_dialog_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&SubtitlePanel::fonts_dialog_clicked, this));
145 _appearance_dialog_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&SubtitlePanel::appearance_dialog_clicked, this));
149 SubtitlePanel::film_changed (Film::Property property)
151 if (property == Film::CONTENT || property == Film::REEL_TYPE) {
152 setup_sensitivity ();
157 SubtitlePanel::film_content_changed (int property)
159 FFmpegContentList fc = _parent->selected_ffmpeg ();
160 SubtitleContentList sc = _parent->selected_subtitle ();
162 shared_ptr<FFmpegContent> fcs;
163 if (fc.size() == 1) {
167 shared_ptr<SubtitleContent> scs;
168 if (sc.size() == 1) {
172 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
175 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
176 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
177 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
180 if (fcs->subtitle_stream()) {
181 checked_set (_stream, fcs->subtitle_stream()->identifier ());
183 _stream->SetSelection (wxNOT_FOUND);
186 setup_sensitivity ();
187 } else if (property == SubtitleContentProperty::USE_SUBTITLES) {
188 checked_set (_use, scs ? scs->use_subtitles() : false);
189 setup_sensitivity ();
190 } else if (property == SubtitleContentProperty::BURN_SUBTITLES) {
191 checked_set (_burn, scs ? scs->burn_subtitles() : false);
192 } else if (property == SubtitleContentProperty::SUBTITLE_X_OFFSET) {
193 checked_set (_x_offset, scs ? lrint (scs->subtitle_x_offset() * 100) : 0);
194 } else if (property == SubtitleContentProperty::SUBTITLE_Y_OFFSET) {
195 checked_set (_y_offset, scs ? lrint (scs->subtitle_y_offset() * 100) : 0);
196 } else if (property == SubtitleContentProperty::SUBTITLE_X_SCALE) {
197 checked_set (_x_scale, scs ? lrint (scs->subtitle_x_scale() * 100) : 100);
198 } else if (property == SubtitleContentProperty::SUBTITLE_Y_SCALE) {
199 checked_set (_y_scale, scs ? lrint (scs->subtitle_y_scale() * 100) : 100);
200 } else if (property == SubtitleContentProperty::SUBTITLE_LANGUAGE) {
201 checked_set (_language, scs ? scs->subtitle_language() : "");
202 } else if (property == DCPContentProperty::REFERENCE_SUBTITLE) {
204 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
205 checked_set (_reference, dcp ? dcp->reference_subtitle () : false);
207 checked_set (_reference, false);
210 setup_sensitivity ();
215 SubtitlePanel::use_toggled ()
217 BOOST_FOREACH (shared_ptr<SubtitleContent> i, _parent->selected_subtitle ()) {
218 i->set_use_subtitles (_use->GetValue());
223 SubtitlePanel::burn_toggled ()
225 BOOST_FOREACH (shared_ptr<SubtitleContent> i, _parent->selected_subtitle ()) {
226 i->set_burn_subtitles (_burn->GetValue());
231 SubtitlePanel::setup_sensitivity ()
238 SubtitleContentList sel = _parent->selected_subtitle ();
239 BOOST_FOREACH (shared_ptr<SubtitleContent> i, sel) {
240 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
241 shared_ptr<const TextSubtitleContent> sc = boost::dynamic_pointer_cast<const TextSubtitleContent> (i);
242 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
244 if (fc->has_subtitles ()) {
258 if (i->has_image_subtitles ()) {
260 /* We must burn image subtitles at the moment */
261 i->set_burn_subtitles (true);
265 shared_ptr<DCPContent> dcp;
266 if (sel.size() == 1) {
267 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
270 list<string> why_not;
271 bool const can_reference = dcp && dcp->can_reference_subtitle (why_not);
272 setup_refer_button (_reference, dcp, can_reference, why_not);
274 bool const reference = _reference->GetValue ();
276 _use->Enable (!reference && any_subs > 0);
277 bool const use = _use->GetValue ();
278 _burn->Enable (!reference && any_subs > 0 && use && image_subs == 0);
279 _x_offset->Enable (!reference && any_subs > 0 && use);
280 _y_offset->Enable (!reference && any_subs > 0 && use);
281 _x_scale->Enable (!reference && any_subs > 0 && use);
282 _y_scale->Enable (!reference && any_subs > 0 && use);
283 _language->Enable (!reference && any_subs > 0 && use);
284 _stream->Enable (!reference && ffmpeg_subs == 1);
285 _subtitle_view_button->Enable (!reference && (text_subs == 1 || dcp_subs == 1));
286 _fonts_dialog_button->Enable (!reference && (text_subs == 1 || dcp_subs == 1));
287 _appearance_dialog_button->Enable (!reference && (ffmpeg_subs == 1 || text_subs == 1));
291 SubtitlePanel::stream_changed ()
293 FFmpegContentList fc = _parent->selected_ffmpeg ();
294 if (fc.size() != 1) {
298 shared_ptr<FFmpegContent> fcs = fc.front ();
300 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
301 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
302 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
303 while (i != a.end() && (*i)->identifier () != s) {
308 fcs->set_subtitle_stream (*i);
313 SubtitlePanel::x_offset_changed ()
315 BOOST_FOREACH (shared_ptr<SubtitleContent> i, _parent->selected_subtitle ()) {
316 i->set_subtitle_x_offset (_x_offset->GetValue() / 100.0);
321 SubtitlePanel::y_offset_changed ()
323 BOOST_FOREACH (shared_ptr<SubtitleContent> i, _parent->selected_subtitle ()) {
324 i->set_subtitle_y_offset (_y_offset->GetValue() / 100.0);
329 SubtitlePanel::x_scale_changed ()
331 SubtitleContentList c = _parent->selected_subtitle ();
333 c.front()->set_subtitle_x_scale (_x_scale->GetValue() / 100.0);
338 SubtitlePanel::y_scale_changed ()
340 BOOST_FOREACH (shared_ptr<SubtitleContent> i, _parent->selected_subtitle ()) {
341 i->set_subtitle_y_scale (_y_scale->GetValue() / 100.0);
346 SubtitlePanel::language_changed ()
348 BOOST_FOREACH (shared_ptr<SubtitleContent> i, _parent->selected_subtitle ()) {
349 i->set_subtitle_language (wx_to_std (_language->GetValue()));
354 SubtitlePanel::content_selection_changed ()
356 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
357 film_content_changed (SubtitleContentProperty::USE_SUBTITLES);
358 film_content_changed (SubtitleContentProperty::BURN_SUBTITLES);
359 film_content_changed (SubtitleContentProperty::SUBTITLE_X_OFFSET);
360 film_content_changed (SubtitleContentProperty::SUBTITLE_Y_OFFSET);
361 film_content_changed (SubtitleContentProperty::SUBTITLE_X_SCALE);
362 film_content_changed (SubtitleContentProperty::SUBTITLE_Y_SCALE);
363 film_content_changed (SubtitleContentProperty::SUBTITLE_LANGUAGE);
364 film_content_changed (SubtitleContentProperty::FONTS);
365 film_content_changed (DCPContentProperty::REFERENCE_SUBTITLE);
369 SubtitlePanel::subtitle_view_clicked ()
371 if (_subtitle_view) {
372 _subtitle_view->Destroy ();
376 SubtitleContentList c = _parent->selected_subtitle ();
377 DCPOMATIC_ASSERT (c.size() == 1);
379 shared_ptr<SubtitleDecoder> decoder;
381 shared_ptr<TextSubtitleContent> sr = dynamic_pointer_cast<TextSubtitleContent> (c.front ());
383 decoder.reset (new TextSubtitleDecoder (sr));
386 shared_ptr<DCPSubtitleContent> dc = dynamic_pointer_cast<DCPSubtitleContent> (c.front ());
388 decoder.reset (new DCPSubtitleDecoder (dc));
392 _subtitle_view = new SubtitleView (this, _parent->film(), decoder, c.front()->position ());
393 _subtitle_view->Show ();
398 SubtitlePanel::fonts_dialog_clicked ()
401 _fonts_dialog->Destroy ();
405 SubtitleContentList c = _parent->selected_subtitle ();
406 DCPOMATIC_ASSERT (c.size() == 1);
408 _fonts_dialog = new FontsDialog (this, c.front ());
409 _fonts_dialog->Show ();
413 SubtitlePanel::reference_clicked ()
415 ContentList c = _parent->selected ();
420 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
425 d->set_reference_subtitle (_reference->GetValue ());
429 SubtitlePanel::appearance_dialog_clicked ()
431 SubtitleContentList c = _parent->selected_subtitle ();
432 DCPOMATIC_ASSERT (c.size() == 1);
434 shared_ptr<TextSubtitleContent> sr = dynamic_pointer_cast<TextSubtitleContent> (c.front ());
436 TextSubtitleAppearanceDialog* d = new TextSubtitleAppearanceDialog (this, sr);
437 if (d->ShowModal () == wxID_OK) {
442 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c.front ());
443 DCPOMATIC_ASSERT (fc);
444 ImageSubtitleColourDialog* d = new ImageSubtitleColourDialog (this, fc, fc->subtitle_stream ());
445 if (d->ShowModal() == wxID_OK) {