2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "subtitle_panel.h"
22 #include "film_editor.h"
24 #include "subtitle_view.h"
25 #include "content_panel.h"
26 #include "fonts_dialog.h"
27 #include "subtitle_appearance_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 "lib/subtitle_content.h"
36 #include "lib/decoder_factory.h"
37 #include <wx/spinctrl.h>
38 #include <boost/foreach.hpp>
43 using boost::shared_ptr;
44 using boost::dynamic_pointer_cast;
46 SubtitlePanel::SubtitlePanel (ContentPanel* p)
47 : ContentSubPanel (p, _("Subtitles"))
51 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
53 _reference = new wxCheckBox (this, wxID_ANY, _("Use this DCP's subtitle as OV and make VF"));
54 reference_sizer->Add (_reference, 0, wxLEFT | wxRIGHT | wxTOP, DCPOMATIC_SIZER_GAP);
56 _reference_note = new wxStaticText (this, wxID_ANY, _(""));
57 _reference_note->Wrap (200);
58 reference_sizer->Add (_reference_note, 0, wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
59 wxFont font = _reference_note->GetFont();
60 font.SetStyle(wxFONTSTYLE_ITALIC);
61 font.SetPointSize(font.GetPointSize() - 1);
62 _reference_note->SetFont(font);
64 _sizer->Add (reference_sizer);
66 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
67 _sizer->Add (grid, 0, wxALL, 8);
70 _use = new wxCheckBox (this, wxID_ANY, _("Use subtitles"));
71 grid->Add (_use, wxGBPosition (r, 0), wxGBSpan (1, 2));
74 _burn = new wxCheckBox (this, wxID_ANY, _("Burn subtitles into image"));
75 grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
79 add_label_to_sizer (grid, this, _("X Offset"), true, wxGBPosition (r, 0));
80 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
81 _x_offset = new wxSpinCtrl (this);
83 add_label_to_sizer (s, this, _("%"), false);
84 grid->Add (s, wxGBPosition (r, 1));
89 add_label_to_sizer (grid, this, _("Y Offset"), true, wxGBPosition (r, 0));
90 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
91 _y_offset = new wxSpinCtrl (this);
93 add_label_to_sizer (s, this, _("%"), false);
94 grid->Add (s, wxGBPosition (r, 1));
99 add_label_to_sizer (grid, this, _("X Scale"), true, wxGBPosition (r, 0));
100 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
101 _x_scale = new wxSpinCtrl (this);
103 add_label_to_sizer (s, this, _("%"), false);
104 grid->Add (s, wxGBPosition (r, 1));
109 add_label_to_sizer (grid, this, _("Y Scale"), true, wxGBPosition (r, 0));
110 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
111 _y_scale = new wxSpinCtrl (this);
113 add_label_to_sizer (s, this, _("%"), false);
114 grid->Add (s, wxGBPosition (r, 1));
119 add_label_to_sizer (grid, this, _("Line spacing"), true, wxGBPosition (r, 0));
120 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
121 _line_spacing = new wxSpinCtrl (this);
122 s->Add (_line_spacing);
123 add_label_to_sizer (s, this, _("%"), false);
124 grid->Add (s, wxGBPosition (r, 1));
128 add_label_to_sizer (grid, this, _("Language"), true, wxGBPosition (r, 0));
129 _language = new wxTextCtrl (this, wxID_ANY);
130 grid->Add (_language, wxGBPosition (r, 1));
133 add_label_to_sizer (grid, this, _("Stream"), true, wxGBPosition (r, 0));
134 _stream = new wxChoice (this, wxID_ANY);
135 grid->Add (_stream, wxGBPosition (r, 1));
139 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
141 _subtitle_view_button = new wxButton (this, wxID_ANY, _("View..."));
142 s->Add (_subtitle_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
143 _fonts_dialog_button = new wxButton (this, wxID_ANY, _("Fonts..."));
144 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
145 _appearance_dialog_button = new wxButton (this, wxID_ANY, _("Appearance..."));
146 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
148 grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
152 _x_offset->SetRange (-100, 100);
153 _y_offset->SetRange (-100, 100);
154 _x_scale->SetRange (10, 1000);
155 _y_scale->SetRange (10, 1000);
156 _line_spacing->SetRange (10, 1000);
158 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&SubtitlePanel::reference_clicked, this));
159 _use->Bind (wxEVT_CHECKBOX, boost::bind (&SubtitlePanel::use_toggled, this));
160 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&SubtitlePanel::burn_toggled, this));
161 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&SubtitlePanel::x_offset_changed, this));
162 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&SubtitlePanel::y_offset_changed, this));
163 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&SubtitlePanel::x_scale_changed, this));
164 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&SubtitlePanel::y_scale_changed, this));
165 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&SubtitlePanel::line_spacing_changed, this));
166 _language->Bind (wxEVT_TEXT, boost::bind (&SubtitlePanel::language_changed, this));
167 _stream->Bind (wxEVT_CHOICE, boost::bind (&SubtitlePanel::stream_changed, this));
168 _subtitle_view_button->Bind (wxEVT_BUTTON, boost::bind (&SubtitlePanel::subtitle_view_clicked, this));
169 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&SubtitlePanel::fonts_dialog_clicked, this));
170 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&SubtitlePanel::appearance_dialog_clicked, this));
174 SubtitlePanel::film_changed (Film::Property property)
176 if (property == Film::CONTENT || property == Film::REEL_TYPE) {
177 setup_sensitivity ();
182 SubtitlePanel::film_content_changed (int property)
184 FFmpegContentList fc = _parent->selected_ffmpeg ();
185 ContentList sc = _parent->selected_subtitle ();
187 shared_ptr<FFmpegContent> fcs;
188 if (fc.size() == 1) {
192 shared_ptr<Content> scs;
193 if (sc.size() == 1) {
197 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
200 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
201 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
202 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
205 if (fcs->subtitle_stream()) {
206 checked_set (_stream, fcs->subtitle_stream()->identifier ());
208 _stream->SetSelection (wxNOT_FOUND);
211 setup_sensitivity ();
212 } else if (property == SubtitleContentProperty::USE) {
213 checked_set (_use, scs ? scs->subtitle->use() : false);
214 setup_sensitivity ();
215 } else if (property == SubtitleContentProperty::BURN) {
216 checked_set (_burn, scs ? scs->subtitle->burn() : false);
217 } else if (property == SubtitleContentProperty::X_OFFSET) {
218 checked_set (_x_offset, scs ? lrint (scs->subtitle->x_offset() * 100) : 0);
219 } else if (property == SubtitleContentProperty::Y_OFFSET) {
220 checked_set (_y_offset, scs ? lrint (scs->subtitle->y_offset() * 100) : 0);
221 } else if (property == SubtitleContentProperty::X_SCALE) {
222 checked_set (_x_scale, scs ? lrint (scs->subtitle->x_scale() * 100) : 100);
223 } else if (property == SubtitleContentProperty::Y_SCALE) {
224 checked_set (_y_scale, scs ? lrint (scs->subtitle->y_scale() * 100) : 100);
225 } else if (property == SubtitleContentProperty::LINE_SPACING) {
226 checked_set (_line_spacing, scs ? lrint (scs->subtitle->line_spacing() * 100) : 100);
227 } else if (property == SubtitleContentProperty::LANGUAGE) {
228 checked_set (_language, scs ? scs->subtitle->language() : "");
229 } else if (property == DCPContentProperty::REFERENCE_SUBTITLE) {
231 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
232 checked_set (_reference, dcp ? dcp->reference_subtitle () : false);
234 checked_set (_reference, false);
237 setup_sensitivity ();
238 } else if (property == DCPContentProperty::HAS_SUBTITLES) {
239 setup_sensitivity ();
244 SubtitlePanel::use_toggled ()
246 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_subtitle ()) {
247 i->subtitle->set_use (_use->GetValue());
252 SubtitlePanel::burn_toggled ()
254 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_subtitle ()) {
255 i->subtitle->set_burn (_burn->GetValue());
260 SubtitlePanel::setup_sensitivity ()
264 ContentList sel = _parent->selected_subtitle ();
265 BOOST_FOREACH (shared_ptr<Content> i, sel) {
266 /* These are the content types that could include subtitles */
267 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
268 shared_ptr<const TextSubtitleContent> sc = boost::dynamic_pointer_cast<const TextSubtitleContent> (i);
269 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
270 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
276 } else if (sc || dc || dsc) {
277 /* XXX: in the future there could be bitmap subs from DCPs */
282 /* Decide whether we can reference these subs */
284 shared_ptr<DCPContent> dcp;
285 if (sel.size() == 1) {
286 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
290 bool const can_reference = dcp && dcp->can_reference_subtitle (why_not);
291 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
293 bool const reference = _reference->GetValue ();
295 /* Set up sensitivity */
296 _use->Enable (!reference && any_subs > 0);
297 bool const use = _use->GetValue ();
298 _burn->Enable (!reference && any_subs > 0 && use);
299 _x_offset->Enable (!reference && any_subs > 0 && use);
300 _y_offset->Enable (!reference && any_subs > 0 && use);
301 _x_scale->Enable (!reference && any_subs > 0 && use);
302 _y_scale->Enable (!reference && any_subs > 0 && use);
303 _line_spacing->Enable (!reference && use);
304 _language->Enable (!reference && any_subs > 0 && use);
305 _stream->Enable (!reference && ffmpeg_subs == 1);
306 _subtitle_view_button->Enable (!reference);
307 _fonts_dialog_button->Enable (!reference);
308 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use);
312 SubtitlePanel::stream_changed ()
314 FFmpegContentList fc = _parent->selected_ffmpeg ();
315 if (fc.size() != 1) {
319 shared_ptr<FFmpegContent> fcs = fc.front ();
321 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
322 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
323 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
324 while (i != a.end() && (*i)->identifier () != s) {
329 fcs->set_subtitle_stream (*i);
334 SubtitlePanel::x_offset_changed ()
336 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_subtitle ()) {
337 i->subtitle->set_x_offset (_x_offset->GetValue() / 100.0);
342 SubtitlePanel::y_offset_changed ()
344 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_subtitle ()) {
345 i->subtitle->set_y_offset (_y_offset->GetValue() / 100.0);
350 SubtitlePanel::x_scale_changed ()
352 ContentList c = _parent->selected_subtitle ();
354 c.front()->subtitle->set_x_scale (_x_scale->GetValue() / 100.0);
359 SubtitlePanel::y_scale_changed ()
361 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_subtitle ()) {
362 i->subtitle->set_y_scale (_y_scale->GetValue() / 100.0);
367 SubtitlePanel::line_spacing_changed ()
369 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_subtitle ()) {
370 i->subtitle->set_line_spacing (_line_spacing->GetValue() / 100.0);
375 SubtitlePanel::language_changed ()
377 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_subtitle ()) {
378 i->subtitle->set_language (wx_to_std (_language->GetValue()));
383 SubtitlePanel::content_selection_changed ()
385 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
386 film_content_changed (SubtitleContentProperty::USE);
387 film_content_changed (SubtitleContentProperty::BURN);
388 film_content_changed (SubtitleContentProperty::X_OFFSET);
389 film_content_changed (SubtitleContentProperty::Y_OFFSET);
390 film_content_changed (SubtitleContentProperty::X_SCALE);
391 film_content_changed (SubtitleContentProperty::Y_SCALE);
392 film_content_changed (SubtitleContentProperty::LINE_SPACING);
393 film_content_changed (SubtitleContentProperty::LANGUAGE);
394 film_content_changed (SubtitleContentProperty::FONTS);
395 film_content_changed (DCPContentProperty::REFERENCE_SUBTITLE);
399 SubtitlePanel::subtitle_view_clicked ()
401 if (_subtitle_view) {
402 _subtitle_view->Destroy ();
406 ContentList c = _parent->selected_subtitle ();
407 DCPOMATIC_ASSERT (c.size() == 1);
409 shared_ptr<Decoder> decoder = decoder_factory (c.front(), _parent->film()->log(), false);
412 _subtitle_view = new SubtitleView (this, _parent->film(), decoder, c.front()->position ());
413 _subtitle_view->Show ();
418 SubtitlePanel::fonts_dialog_clicked ()
421 _fonts_dialog->Destroy ();
425 ContentList c = _parent->selected_subtitle ();
426 DCPOMATIC_ASSERT (c.size() == 1);
428 _fonts_dialog = new FontsDialog (this, c.front ());
429 _fonts_dialog->Show ();
433 SubtitlePanel::reference_clicked ()
435 ContentList c = _parent->selected ();
440 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
445 d->set_reference_subtitle (_reference->GetValue ());
449 SubtitlePanel::appearance_dialog_clicked ()
451 ContentList c = _parent->selected_subtitle ();
452 DCPOMATIC_ASSERT (c.size() == 1);
454 SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, c.front());
455 if (d->ShowModal () == wxID_OK) {