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 "text_panel.h"
22 #include "film_editor.h"
24 #include "text_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/string_text_file_content.h"
30 #include "lib/ffmpeg_subtitle_stream.h"
31 #include "lib/dcp_subtitle_content.h"
32 #include "lib/string_text_file_decoder.h"
33 #include "lib/dcp_subtitle_decoder.h"
34 #include "lib/dcp_content.h"
35 #include "lib/text_content.h"
36 #include "lib/decoder_factory.h"
37 #include <wx/spinctrl.h>
38 #include <boost/foreach.hpp>
44 using boost::shared_ptr;
45 using boost::dynamic_pointer_cast;
47 TextPanel::TextPanel (ContentPanel* p, TextType t)
48 : ContentSubPanel (p, std_to_wx(caption_type_to_name(t)))
53 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
55 _reference = new wxCheckBox (this, wxID_ANY, _("Use this DCP's subtitle as OV and make VF"));
56 reference_sizer->Add (_reference, 0, wxLEFT | wxRIGHT | wxTOP, DCPOMATIC_SIZER_GAP);
58 _reference_note = new wxStaticText (this, wxID_ANY, _(""));
59 _reference_note->Wrap (200);
60 reference_sizer->Add (_reference_note, 0, wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
61 wxFont font = _reference_note->GetFont();
62 font.SetStyle(wxFONTSTYLE_ITALIC);
63 font.SetPointSize(font.GetPointSize() - 1);
64 _reference_note->SetFont(font);
66 _sizer->Add (reference_sizer);
68 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
69 _sizer->Add (grid, 0, wxALL, 8);
72 wxBoxSizer* use = new wxBoxSizer (wxHORIZONTAL);
73 _use = new wxCheckBox (this, wxID_ANY, _("Use as"));
74 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
75 _type = new wxChoice (this, wxID_ANY);
76 _type->Append (_("subtitles (open captions)"));
77 _type->Append (_("closed captions"));
78 use->Add (_type, 1, wxEXPAND, 0);
79 grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
82 _burn = new wxCheckBox (this, wxID_ANY, _("Burn subtitles into image"));
83 grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
87 add_label_to_sizer (grid, this, _("X Offset"), true, wxGBPosition (r, 0));
88 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
89 _x_offset = new wxSpinCtrl (this);
91 add_label_to_sizer (s, this, _("%"), false);
92 grid->Add (s, wxGBPosition (r, 1));
97 add_label_to_sizer (grid, this, _("Y Offset"), true, wxGBPosition (r, 0));
98 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
99 _y_offset = new wxSpinCtrl (this);
101 add_label_to_sizer (s, this, _("%"), false);
102 grid->Add (s, wxGBPosition (r, 1));
107 add_label_to_sizer (grid, this, _("X Scale"), true, wxGBPosition (r, 0));
108 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
109 _x_scale = new wxSpinCtrl (this);
111 add_label_to_sizer (s, this, _("%"), false);
112 grid->Add (s, wxGBPosition (r, 1));
117 add_label_to_sizer (grid, this, _("Y Scale"), true, wxGBPosition (r, 0));
118 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
119 _y_scale = new wxSpinCtrl (this);
121 add_label_to_sizer (s, this, _("%"), false);
122 grid->Add (s, wxGBPosition (r, 1));
127 add_label_to_sizer (grid, this, _("Line spacing"), true, wxGBPosition (r, 0));
128 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
129 _line_spacing = new wxSpinCtrl (this);
130 s->Add (_line_spacing);
131 add_label_to_sizer (s, this, _("%"), false);
132 grid->Add (s, wxGBPosition (r, 1));
136 add_label_to_sizer (grid, this, _("Language"), true, wxGBPosition (r, 0));
137 _language = new wxTextCtrl (this, wxID_ANY);
138 grid->Add (_language, wxGBPosition (r, 1));
141 add_label_to_sizer (grid, this, _("Stream"), true, wxGBPosition (r, 0));
142 _stream = new wxChoice (this, wxID_ANY);
143 grid->Add (_stream, wxGBPosition (r, 1));
147 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
149 _caption_view_button = new wxButton (this, wxID_ANY, _("View..."));
150 s->Add (_caption_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
151 _fonts_dialog_button = new wxButton (this, wxID_ANY, _("Fonts..."));
152 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
153 _appearance_dialog_button = new wxButton (this, wxID_ANY, _("Appearance..."));
154 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
156 grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
160 _x_offset->SetRange (-100, 100);
161 _y_offset->SetRange (-100, 100);
162 _x_scale->SetRange (10, 1000);
163 _y_scale->SetRange (10, 1000);
164 _line_spacing->SetRange (10, 1000);
166 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
167 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
168 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
169 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
170 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
171 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
172 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
173 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
174 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
175 _language->Bind (wxEVT_TEXT, boost::bind (&TextPanel::language_changed, this));
176 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
177 _caption_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::caption_view_clicked, this));
178 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
179 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
183 TextPanel::film_changed (Film::Property property)
185 if (property == Film::CONTENT || property == Film::REEL_TYPE) {
186 setup_sensitivity ();
191 TextPanel::film_content_changed (int property)
193 FFmpegContentList fc = _parent->selected_ffmpeg ();
194 ContentList sc = _parent->selected_caption ();
196 shared_ptr<FFmpegContent> fcs;
197 if (fc.size() == 1) {
201 shared_ptr<Content> scs;
202 if (sc.size() == 1) {
206 shared_ptr<TextContent> caption;
208 caption = scs->caption_of_original_type(_original_type);
211 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
214 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
215 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
216 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
219 if (fcs->subtitle_stream()) {
220 checked_set (_stream, fcs->subtitle_stream()->identifier ());
222 _stream->SetSelection (wxNOT_FOUND);
225 setup_sensitivity ();
226 } else if (property == TextContentProperty::USE) {
227 checked_set (_use, caption ? caption->use() : false);
228 setup_sensitivity ();
229 } else if (property == TextContentProperty::TYPE) {
231 switch (caption->type()) {
233 _type->SetSelection (0);
236 _type->SetSelection (1);
239 DCPOMATIC_ASSERT (false);
242 _type->SetSelection (0);
244 setup_sensitivity ();
245 } else if (property == TextContentProperty::BURN) {
246 checked_set (_burn, caption ? caption->burn() : false);
247 } else if (property == TextContentProperty::X_OFFSET) {
248 checked_set (_x_offset, caption ? lrint (caption->x_offset() * 100) : 0);
249 } else if (property == TextContentProperty::Y_OFFSET) {
250 checked_set (_y_offset, caption ? lrint (caption->y_offset() * 100) : 0);
251 } else if (property == TextContentProperty::X_SCALE) {
252 checked_set (_x_scale, caption ? lrint (caption->x_scale() * 100) : 100);
253 } else if (property == TextContentProperty::Y_SCALE) {
254 checked_set (_y_scale, caption ? lrint (caption->y_scale() * 100) : 100);
255 } else if (property == TextContentProperty::LINE_SPACING) {
256 checked_set (_line_spacing, caption ? lrint (caption->line_spacing() * 100) : 100);
257 } else if (property == TextContentProperty::LANGUAGE) {
258 checked_set (_language, caption ? caption->language() : "");
259 } else if (property == DCPContentProperty::REFERENCE_CAPTION) {
261 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
262 checked_set (_reference, dcp ? dcp->reference_caption(_original_type) : false);
264 checked_set (_reference, false);
267 setup_sensitivity ();
268 } else if (property == DCPContentProperty::CAPTIONS) {
269 setup_sensitivity ();
274 TextPanel::use_toggled ()
276 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption()) {
277 i->caption_of_original_type(_original_type)->set_use (_use->GetValue());
282 TextPanel::type_changed ()
284 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption()) {
285 switch (_type->GetSelection()) {
287 i->caption_of_original_type(_original_type)->set_type (CAPTION_OPEN);
290 i->caption_of_original_type(_original_type)->set_type (CAPTION_CLOSED);
297 TextPanel::burn_toggled ()
299 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
300 i->caption_of_original_type(_original_type)->set_burn (_burn->GetValue());
305 TextPanel::setup_sensitivity ()
309 ContentList sel = _parent->selected_caption ();
310 BOOST_FOREACH (shared_ptr<Content> i, sel) {
311 /* These are the content types that could include subtitles */
312 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
313 shared_ptr<const StringTextFileContent> sc = boost::dynamic_pointer_cast<const StringTextFileContent> (i);
314 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
315 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
317 if (!fc->caption.empty()) {
321 } else if (sc || dc || dsc) {
322 /* XXX: in the future there could be bitmap subs from DCPs */
327 /* Decide whether we can reference these subs */
329 shared_ptr<DCPContent> dcp;
330 if (sel.size() == 1) {
331 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
335 bool const can_reference = dcp && dcp->can_reference_caption (_original_type, why_not);
336 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
338 bool const reference = _reference->GetValue ();
340 /* Set up sensitivity */
341 _use->Enable (!reference && any_subs > 0);
342 bool const use = _use->GetValue ();
343 _type->Enable (!reference && any_subs > 0 && use);
344 _burn->Enable (!reference && any_subs > 0 && use && _type->GetSelection() == 0);
345 _x_offset->Enable (!reference && any_subs > 0 && use);
346 _y_offset->Enable (!reference && any_subs > 0 && use);
347 _x_scale->Enable (!reference && any_subs > 0 && use);
348 _y_scale->Enable (!reference && any_subs > 0 && use);
349 _line_spacing->Enable (!reference && use);
350 _language->Enable (!reference && any_subs > 0 && use);
351 _stream->Enable (!reference && ffmpeg_subs == 1);
352 _caption_view_button->Enable (!reference);
353 _fonts_dialog_button->Enable (!reference);
354 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use);
358 TextPanel::stream_changed ()
360 FFmpegContentList fc = _parent->selected_ffmpeg ();
361 if (fc.size() != 1) {
365 shared_ptr<FFmpegContent> fcs = fc.front ();
367 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
368 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
369 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
370 while (i != a.end() && (*i)->identifier () != s) {
375 fcs->set_subtitle_stream (*i);
380 TextPanel::x_offset_changed ()
382 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
383 i->caption_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
388 TextPanel::y_offset_changed ()
390 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
391 i->caption_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
396 TextPanel::x_scale_changed ()
398 ContentList c = _parent->selected_caption ();
400 c.front()->caption_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
405 TextPanel::y_scale_changed ()
407 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
408 i->caption_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
413 TextPanel::line_spacing_changed ()
415 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
416 i->caption_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
421 TextPanel::language_changed ()
423 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_caption ()) {
424 i->caption_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
429 TextPanel::content_selection_changed ()
431 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
432 film_content_changed (TextContentProperty::USE);
433 film_content_changed (TextContentProperty::BURN);
434 film_content_changed (TextContentProperty::X_OFFSET);
435 film_content_changed (TextContentProperty::Y_OFFSET);
436 film_content_changed (TextContentProperty::X_SCALE);
437 film_content_changed (TextContentProperty::Y_SCALE);
438 film_content_changed (TextContentProperty::LINE_SPACING);
439 film_content_changed (TextContentProperty::LANGUAGE);
440 film_content_changed (TextContentProperty::FONTS);
441 film_content_changed (TextContentProperty::TYPE);
442 film_content_changed (DCPContentProperty::REFERENCE_CAPTION);
446 TextPanel::caption_view_clicked ()
449 _caption_view->Destroy ();
453 ContentList c = _parent->selected_caption ();
454 DCPOMATIC_ASSERT (c.size() == 1);
456 shared_ptr<Decoder> decoder = decoder_factory (c.front(), _parent->film()->log(), false);
459 _caption_view = new TextView (this, _parent->film(), c.front(), c.front()->caption_of_original_type(_original_type), decoder, _parent->film_viewer());
460 _caption_view->Show ();
465 TextPanel::fonts_dialog_clicked ()
468 _fonts_dialog->Destroy ();
472 ContentList c = _parent->selected_caption ();
473 DCPOMATIC_ASSERT (c.size() == 1);
475 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->caption_of_original_type(_original_type));
476 _fonts_dialog->Show ();
480 TextPanel::reference_clicked ()
482 ContentList c = _parent->selected ();
487 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
492 d->set_reference_caption (_original_type, _reference->GetValue ());
496 TextPanel::appearance_dialog_clicked ()
498 ContentList c = _parent->selected_caption ();
499 DCPOMATIC_ASSERT (c.size() == 1);
501 SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, c.front(), c.front()->caption_of_original_type(_original_type));
502 if (d->ShowModal () == wxID_OK) {