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, CaptionType t)
47 : ContentSubPanel (p, std_to_wx(caption_type_to_name(t)))
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 shared_ptr<CaptionContent> caption;
207 caption = scs->caption_of_original_type(_original_type);
210 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
213 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
214 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
215 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
218 if (fcs->subtitle_stream()) {
219 checked_set (_stream, fcs->subtitle_stream()->identifier ());
221 _stream->SetSelection (wxNOT_FOUND);
224 setup_sensitivity ();
225 } else if (property == CaptionContentProperty::USE) {
226 checked_set (_use, caption ? caption->use() : false);
227 setup_sensitivity ();
228 } else if (property == CaptionContentProperty::TYPE) {
230 switch (caption->type()) {
232 _type->SetSelection (0);
235 _type->SetSelection (1);
238 DCPOMATIC_ASSERT (false);
241 _type->SetSelection (0);
243 setup_sensitivity ();
244 } else if (property == CaptionContentProperty::BURN) {
245 checked_set (_burn, caption ? caption->burn() : false);
246 } else if (property == CaptionContentProperty::X_OFFSET) {
247 checked_set (_x_offset, caption ? lrint (caption->x_offset() * 100) : 0);
248 } else if (property == CaptionContentProperty::Y_OFFSET) {
249 checked_set (_y_offset, caption ? lrint (caption->y_offset() * 100) : 0);
250 } else if (property == CaptionContentProperty::X_SCALE) {
251 checked_set (_x_scale, caption ? lrint (caption->x_scale() * 100) : 100);
252 } else if (property == CaptionContentProperty::Y_SCALE) {
253 checked_set (_y_scale, caption ? lrint (caption->y_scale() * 100) : 100);
254 } else if (property == CaptionContentProperty::LINE_SPACING) {
255 checked_set (_line_spacing, caption ? lrint (caption->line_spacing() * 100) : 100);
256 } else if (property == CaptionContentProperty::LANGUAGE) {
257 checked_set (_language, caption ? caption->language() : "");
258 } else if (property == DCPContentProperty::REFERENCE_CAPTION) {
260 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
261 checked_set (_reference, dcp ? dcp->reference_caption(_original_type) : false);
263 checked_set (_reference, false);
266 setup_sensitivity ();
267 } else if (property == DCPContentProperty::CAPTIONS) {
268 setup_sensitivity ();
273 CaptionPanel::use_toggled ()
275 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption()) {
276 i->caption_of_original_type(_original_type)->set_use (_use->GetValue());
281 CaptionPanel::type_changed ()
283 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption()) {
284 switch (_type->GetSelection()) {
286 i->caption_of_original_type(_original_type)->set_type (CAPTION_OPEN);
289 i->caption_of_original_type(_original_type)->set_type (CAPTION_CLOSED);
296 CaptionPanel::burn_toggled ()
298 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
299 i->caption_of_original_type(_original_type)->set_burn (_burn->GetValue());
304 CaptionPanel::setup_sensitivity ()
308 ContentList sel = _parent->selected_caption ();
309 BOOST_FOREACH (shared_ptr<Content> i, sel) {
310 /* These are the content types that could include subtitles */
311 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
312 shared_ptr<const TextCaptionFileContent> sc = boost::dynamic_pointer_cast<const TextCaptionFileContent> (i);
313 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
314 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
316 if (!fc->caption.empty()) {
320 } else if (sc || dc || dsc) {
321 /* XXX: in the future there could be bitmap subs from DCPs */
326 /* Decide whether we can reference these subs */
328 shared_ptr<DCPContent> dcp;
329 if (sel.size() == 1) {
330 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
334 bool const can_reference = dcp && dcp->can_reference_caption (_original_type, why_not);
335 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
337 bool const reference = _reference->GetValue ();
339 /* Set up sensitivity */
340 _use->Enable (!reference && any_subs > 0);
341 bool const use = _use->GetValue ();
342 _type->Enable (!reference && any_subs > 0 && use);
343 _burn->Enable (!reference && any_subs > 0 && use && _type->GetSelection() == 0);
344 _x_offset->Enable (!reference && any_subs > 0 && use);
345 _y_offset->Enable (!reference && any_subs > 0 && use);
346 _x_scale->Enable (!reference && any_subs > 0 && use);
347 _y_scale->Enable (!reference && any_subs > 0 && use);
348 _line_spacing->Enable (!reference && use);
349 _language->Enable (!reference && any_subs > 0 && use);
350 _stream->Enable (!reference && ffmpeg_subs == 1);
351 _caption_view_button->Enable (!reference);
352 _fonts_dialog_button->Enable (!reference);
353 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use);
357 CaptionPanel::stream_changed ()
359 FFmpegContentList fc = _parent->selected_ffmpeg ();
360 if (fc.size() != 1) {
364 shared_ptr<FFmpegContent> fcs = fc.front ();
366 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
367 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
368 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
369 while (i != a.end() && (*i)->identifier () != s) {
374 fcs->set_subtitle_stream (*i);
379 CaptionPanel::x_offset_changed ()
381 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
382 i->caption_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
387 CaptionPanel::y_offset_changed ()
389 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
390 i->caption_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
395 CaptionPanel::x_scale_changed ()
397 ContentList c = _parent->selected_caption ();
399 c.front()->caption_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
404 CaptionPanel::y_scale_changed ()
406 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
407 i->caption_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
412 CaptionPanel::line_spacing_changed ()
414 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
415 i->caption_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
420 CaptionPanel::language_changed ()
422 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
423 i->caption_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
428 CaptionPanel::content_selection_changed ()
430 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
431 film_content_changed (CaptionContentProperty::USE);
432 film_content_changed (CaptionContentProperty::BURN);
433 film_content_changed (CaptionContentProperty::X_OFFSET);
434 film_content_changed (CaptionContentProperty::Y_OFFSET);
435 film_content_changed (CaptionContentProperty::X_SCALE);
436 film_content_changed (CaptionContentProperty::Y_SCALE);
437 film_content_changed (CaptionContentProperty::LINE_SPACING);
438 film_content_changed (CaptionContentProperty::LANGUAGE);
439 film_content_changed (CaptionContentProperty::FONTS);
440 film_content_changed (CaptionContentProperty::TYPE);
441 film_content_changed (DCPContentProperty::REFERENCE_CAPTION);
445 CaptionPanel::caption_view_clicked ()
448 _caption_view->Destroy ();
452 ContentList c = _parent->selected_caption ();
453 DCPOMATIC_ASSERT (c.size() == 1);
455 shared_ptr<Decoder> decoder = decoder_factory (c.front(), _parent->film()->log(), false);
458 _caption_view = new CaptionView (this, _parent->film(), c.front(), c.front()->caption_of_original_type(_original_type), decoder, _parent->film_viewer());
459 _caption_view->Show ();
464 CaptionPanel::fonts_dialog_clicked ()
467 _fonts_dialog->Destroy ();
471 ContentList c = _parent->selected_caption ();
472 DCPOMATIC_ASSERT (c.size() == 1);
474 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->caption_of_original_type(_original_type));
475 _fonts_dialog->Show ();
479 CaptionPanel::reference_clicked ()
481 ContentList c = _parent->selected ();
486 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
491 d->set_reference_caption (_original_type, _reference->GetValue ());
495 CaptionPanel::appearance_dialog_clicked ()
497 ContentList c = _parent->selected_caption ();
498 DCPOMATIC_ASSERT (c.size() == 1);
500 CaptionAppearanceDialog* d = new CaptionAppearanceDialog (this, c.front(), c.front()->caption_of_original_type(_original_type));
501 if (d->ShowModal () == wxID_OK) {