2 Copyright (C) 2012-2018 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 "caption_panel.h"
22 #include "film_editor.h"
24 #include "caption_view.h"
25 #include "content_panel.h"
26 #include "fonts_dialog.h"
27 #include "caption_appearance_dialog.h"
28 #include "lib/ffmpeg_content.h"
29 #include "lib/text_caption_file_content.h"
30 #include "lib/ffmpeg_subtitle_stream.h"
31 #include "lib/dcp_subtitle_content.h"
32 #include "lib/text_caption_file_decoder.h"
33 #include "lib/dcp_subtitle_decoder.h"
34 #include "lib/dcp_content.h"
35 #include "lib/caption_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 CaptionPanel::CaptionPanel (ContentPanel* p)
47 : ContentSubPanel (p, _("Captions"))
50 , _original_type (CAPTION_OPEN)
52 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
54 _reference = new wxCheckBox (this, wxID_ANY, _("Use this DCP's subtitle as OV and make VF"));
55 reference_sizer->Add (_reference, 0, wxLEFT | wxRIGHT | wxTOP, DCPOMATIC_SIZER_GAP);
57 _reference_note = new wxStaticText (this, wxID_ANY, _(""));
58 _reference_note->Wrap (200);
59 reference_sizer->Add (_reference_note, 0, wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
60 wxFont font = _reference_note->GetFont();
61 font.SetStyle(wxFONTSTYLE_ITALIC);
62 font.SetPointSize(font.GetPointSize() - 1);
63 _reference_note->SetFont(font);
65 _sizer->Add (reference_sizer);
67 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
68 _sizer->Add (grid, 0, wxALL, 8);
71 wxBoxSizer* use = new wxBoxSizer (wxHORIZONTAL);
72 _use = new wxCheckBox (this, wxID_ANY, _("Use as"));
73 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
74 _type = new wxChoice (this, wxID_ANY);
75 _type->Append (_("subtitles (open captions)"));
76 _type->Append (_("closed captions"));
77 use->Add (_type, 1, wxEXPAND, 0);
78 grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
81 _burn = new wxCheckBox (this, wxID_ANY, _("Burn subtitles into image"));
82 grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
86 add_label_to_sizer (grid, this, _("X Offset"), true, wxGBPosition (r, 0));
87 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
88 _x_offset = 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 Offset"), true, wxGBPosition (r, 0));
97 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
98 _y_offset = new wxSpinCtrl (this);
100 add_label_to_sizer (s, this, _("%"), false);
101 grid->Add (s, wxGBPosition (r, 1));
106 add_label_to_sizer (grid, this, _("X Scale"), true, wxGBPosition (r, 0));
107 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
108 _x_scale = new wxSpinCtrl (this);
110 add_label_to_sizer (s, this, _("%"), false);
111 grid->Add (s, wxGBPosition (r, 1));
116 add_label_to_sizer (grid, this, _("Y Scale"), true, wxGBPosition (r, 0));
117 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
118 _y_scale = new wxSpinCtrl (this);
120 add_label_to_sizer (s, this, _("%"), false);
121 grid->Add (s, wxGBPosition (r, 1));
126 add_label_to_sizer (grid, this, _("Line spacing"), true, wxGBPosition (r, 0));
127 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
128 _line_spacing = new wxSpinCtrl (this);
129 s->Add (_line_spacing);
130 add_label_to_sizer (s, this, _("%"), false);
131 grid->Add (s, wxGBPosition (r, 1));
135 add_label_to_sizer (grid, this, _("Language"), true, wxGBPosition (r, 0));
136 _language = new wxTextCtrl (this, wxID_ANY);
137 grid->Add (_language, wxGBPosition (r, 1));
140 add_label_to_sizer (grid, this, _("Stream"), true, wxGBPosition (r, 0));
141 _stream = new wxChoice (this, wxID_ANY);
142 grid->Add (_stream, wxGBPosition (r, 1));
146 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
148 _caption_view_button = new wxButton (this, wxID_ANY, _("View..."));
149 s->Add (_caption_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
150 _fonts_dialog_button = new wxButton (this, wxID_ANY, _("Fonts..."));
151 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
152 _appearance_dialog_button = new wxButton (this, wxID_ANY, _("Appearance..."));
153 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
155 grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
159 _x_offset->SetRange (-100, 100);
160 _y_offset->SetRange (-100, 100);
161 _x_scale->SetRange (10, 1000);
162 _y_scale->SetRange (10, 1000);
163 _line_spacing->SetRange (10, 1000);
165 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&CaptionPanel::reference_clicked, this));
166 _use->Bind (wxEVT_CHECKBOX, boost::bind (&CaptionPanel::use_toggled, this));
167 _type->Bind (wxEVT_CHOICE, boost::bind (&CaptionPanel::type_changed, this));
168 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&CaptionPanel::burn_toggled, this));
169 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&CaptionPanel::x_offset_changed, this));
170 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&CaptionPanel::y_offset_changed, this));
171 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&CaptionPanel::x_scale_changed, this));
172 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&CaptionPanel::y_scale_changed, this));
173 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&CaptionPanel::line_spacing_changed, this));
174 _language->Bind (wxEVT_TEXT, boost::bind (&CaptionPanel::language_changed, this));
175 _stream->Bind (wxEVT_CHOICE, boost::bind (&CaptionPanel::stream_changed, this));
176 _caption_view_button->Bind (wxEVT_BUTTON, boost::bind (&CaptionPanel::caption_view_clicked, this));
177 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&CaptionPanel::fonts_dialog_clicked, this));
178 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&CaptionPanel::appearance_dialog_clicked, this));
182 CaptionPanel::film_changed (Film::Property property)
184 if (property == Film::CONTENT || property == Film::REEL_TYPE) {
185 setup_sensitivity ();
190 CaptionPanel::film_content_changed (int property)
192 FFmpegContentList fc = _parent->selected_ffmpeg ();
193 ContentList sc = _parent->selected_caption ();
195 shared_ptr<FFmpegContent> fcs;
196 if (fc.size() == 1) {
200 shared_ptr<Content> scs;
201 if (sc.size() == 1) {
205 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
208 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
209 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
210 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
213 if (fcs->subtitle_stream()) {
214 checked_set (_stream, fcs->subtitle_stream()->identifier ());
216 _stream->SetSelection (wxNOT_FOUND);
219 setup_sensitivity ();
220 } else if (property == CaptionContentProperty::USE) {
221 checked_set (_use, scs ? scs->caption_of_original_type(_original_type)->use() : false);
222 setup_sensitivity ();
223 } else if (property == CaptionContentProperty::TYPE) {
225 switch (scs->caption_of_original_type(_original_type)->type()) {
227 _type->SetSelection (0);
230 _type->SetSelection (1);
233 DCPOMATIC_ASSERT (false);
236 _type->SetSelection (0);
238 setup_sensitivity ();
239 } else if (property == CaptionContentProperty::BURN) {
240 checked_set (_burn, scs ? scs->caption_of_original_type(_original_type)->burn() : false);
241 } else if (property == CaptionContentProperty::X_OFFSET) {
242 checked_set (_x_offset, scs ? lrint (scs->caption_of_original_type(_original_type)->x_offset() * 100) : 0);
243 } else if (property == CaptionContentProperty::Y_OFFSET) {
244 checked_set (_y_offset, scs ? lrint (scs->caption_of_original_type(_original_type)->y_offset() * 100) : 0);
245 } else if (property == CaptionContentProperty::X_SCALE) {
246 checked_set (_x_scale, scs ? lrint (scs->caption_of_original_type(_original_type)->x_scale() * 100) : 100);
247 } else if (property == CaptionContentProperty::Y_SCALE) {
248 checked_set (_y_scale, scs ? lrint (scs->caption_of_original_type(_original_type)->y_scale() * 100) : 100);
249 } else if (property == CaptionContentProperty::LINE_SPACING) {
250 checked_set (_line_spacing, scs ? lrint (scs->caption_of_original_type(_original_type)->line_spacing() * 100) : 100);
251 } else if (property == CaptionContentProperty::LANGUAGE) {
252 checked_set (_language, scs ? scs->caption_of_original_type(_original_type)->language() : "");
253 } else if (property == DCPContentProperty::REFERENCE_CAPTION) {
255 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
256 checked_set (_reference, dcp ? dcp->reference_caption(_original_type) : false);
258 checked_set (_reference, false);
261 setup_sensitivity ();
262 } else if (property == DCPContentProperty::CAPTIONS) {
263 setup_sensitivity ();
268 CaptionPanel::use_toggled ()
270 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption()) {
271 i->caption_of_original_type(_original_type)->set_use (_use->GetValue());
276 CaptionPanel::type_changed ()
278 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption()) {
279 switch (_type->GetSelection()) {
281 i->caption_of_original_type(_original_type)->set_type (CAPTION_OPEN);
284 i->caption_of_original_type(_original_type)->set_type (CAPTION_CLOSED);
291 CaptionPanel::burn_toggled ()
293 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
294 i->caption_of_original_type(_original_type)->set_burn (_burn->GetValue());
299 CaptionPanel::setup_sensitivity ()
303 ContentList sel = _parent->selected_caption ();
304 BOOST_FOREACH (shared_ptr<Content> i, sel) {
305 /* These are the content types that could include subtitles */
306 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
307 shared_ptr<const TextCaptionFileContent> sc = boost::dynamic_pointer_cast<const TextCaptionFileContent> (i);
308 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
309 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
311 if (!fc->caption.empty()) {
315 } else if (sc || dc || dsc) {
316 /* XXX: in the future there could be bitmap subs from DCPs */
321 /* Decide whether we can reference these subs */
323 shared_ptr<DCPContent> dcp;
324 if (sel.size() == 1) {
325 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
329 bool const can_reference = dcp && dcp->can_reference_caption (_original_type, why_not);
330 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
332 bool const reference = _reference->GetValue ();
334 /* Set up sensitivity */
335 _use->Enable (!reference && any_subs > 0);
336 bool const use = _use->GetValue ();
337 _type->Enable (!reference && any_subs > 0 && use);
338 _burn->Enable (!reference && any_subs > 0 && use && _type->GetSelection() == 0);
339 _x_offset->Enable (!reference && any_subs > 0 && use);
340 _y_offset->Enable (!reference && any_subs > 0 && use);
341 _x_scale->Enable (!reference && any_subs > 0 && use);
342 _y_scale->Enable (!reference && any_subs > 0 && use);
343 _line_spacing->Enable (!reference && use);
344 _language->Enable (!reference && any_subs > 0 && use);
345 _stream->Enable (!reference && ffmpeg_subs == 1);
346 _caption_view_button->Enable (!reference);
347 _fonts_dialog_button->Enable (!reference);
348 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use);
352 CaptionPanel::stream_changed ()
354 FFmpegContentList fc = _parent->selected_ffmpeg ();
355 if (fc.size() != 1) {
359 shared_ptr<FFmpegContent> fcs = fc.front ();
361 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
362 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
363 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
364 while (i != a.end() && (*i)->identifier () != s) {
369 fcs->set_subtitle_stream (*i);
374 CaptionPanel::x_offset_changed ()
376 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
377 i->caption_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
382 CaptionPanel::y_offset_changed ()
384 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
385 i->caption_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
390 CaptionPanel::x_scale_changed ()
392 ContentList c = _parent->selected_caption ();
394 c.front()->caption_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
399 CaptionPanel::y_scale_changed ()
401 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
402 i->caption_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
407 CaptionPanel::line_spacing_changed ()
409 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
410 i->caption_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
415 CaptionPanel::language_changed ()
417 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
418 i->caption_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
423 CaptionPanel::content_selection_changed ()
425 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
426 film_content_changed (CaptionContentProperty::USE);
427 film_content_changed (CaptionContentProperty::BURN);
428 film_content_changed (CaptionContentProperty::X_OFFSET);
429 film_content_changed (CaptionContentProperty::Y_OFFSET);
430 film_content_changed (CaptionContentProperty::X_SCALE);
431 film_content_changed (CaptionContentProperty::Y_SCALE);
432 film_content_changed (CaptionContentProperty::LINE_SPACING);
433 film_content_changed (CaptionContentProperty::LANGUAGE);
434 film_content_changed (CaptionContentProperty::FONTS);
435 film_content_changed (CaptionContentProperty::TYPE);
436 film_content_changed (DCPContentProperty::REFERENCE_CAPTION);
440 CaptionPanel::caption_view_clicked ()
443 _caption_view->Destroy ();
447 ContentList c = _parent->selected_caption ();
448 DCPOMATIC_ASSERT (c.size() == 1);
450 shared_ptr<Decoder> decoder = decoder_factory (c.front(), _parent->film()->log(), false);
453 _caption_view = new CaptionView (this, _parent->film(), c.front(), c.front()->caption_of_original_type(_original_type), decoder, _parent->film_viewer());
454 _caption_view->Show ();
459 CaptionPanel::fonts_dialog_clicked ()
462 _fonts_dialog->Destroy ();
466 ContentList c = _parent->selected_caption ();
467 DCPOMATIC_ASSERT (c.size() == 1);
469 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->caption_of_original_type(_original_type));
470 _fonts_dialog->Show ();
474 CaptionPanel::reference_clicked ()
476 ContentList c = _parent->selected ();
481 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
486 d->set_reference_caption (_original_type, _reference->GetValue ());
490 CaptionPanel::appearance_dialog_clicked ()
492 ContentList c = _parent->selected_caption ();
493 DCPOMATIC_ASSERT (c.size() == 1);
495 CaptionAppearanceDialog* d = new CaptionAppearanceDialog (this, c.front(), c.front()->caption_of_original_type(_original_type));
496 if (d->ShowModal () == wxID_OK) {