2 Copyright (C) 2012-2020 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 "dcp_text_track_dialog.h"
28 #include "subtitle_appearance_dialog.h"
29 #include "static_text.h"
30 #include "check_box.h"
31 #include "dcpomatic_button.h"
32 #include "film_viewer.h"
33 #include "lib/job_manager.h"
34 #include "lib/ffmpeg_content.h"
35 #include "lib/string_text_file_content.h"
36 #include "lib/ffmpeg_subtitle_stream.h"
37 #include "lib/dcp_subtitle_content.h"
38 #include "lib/string_text_file_decoder.h"
39 #include "lib/dcp_subtitle_decoder.h"
40 #include "lib/dcp_content.h"
41 #include "lib/text_content.h"
42 #include "lib/decoder_factory.h"
43 #include "lib/analyse_subtitles_job.h"
44 #include "lib/subtitle_analysis.h"
45 #include <wx/spinctrl.h>
46 #include <boost/foreach.hpp>
52 using boost::shared_ptr;
53 using boost::optional;
54 using boost::dynamic_pointer_cast;
57 /** @param t Original text type of the content, if known */
58 TextPanel::TextPanel (ContentPanel* p, TextType t)
59 : ContentSubPanel (p, std_to_wx(text_type_to_name(t)))
60 , _outline_subtitles (0)
61 , _dcp_track_label (0)
66 , _loading_analysis (false)
68 wxString refer = _("Use this DCP's subtitle as OV and make VF");
69 if (t == TEXT_CLOSED_CAPTION) {
70 refer = _("Use this DCP's closed caption as OV and make VF");
73 _reference = new CheckBox (this, refer);
74 _reference_note = new StaticText (this, wxT(""));
75 _reference_note->Wrap (200);
76 wxFont font = _reference_note->GetFont();
77 font.SetStyle(wxFONTSTYLE_ITALIC);
78 font.SetPointSize(font.GetPointSize() - 1);
79 _reference_note->SetFont(font);
81 _use = new CheckBox (this, _("Use as"));
82 _type = new wxChoice (this, wxID_ANY);
83 _type->Append (_("open subtitles"));
84 _type->Append (_("closed captions"));
86 _burn = new CheckBox (this, _("Burn subtitles into image"));
89 int const spin_width = 118;
91 int const spin_width = 56;
94 _offset_label = create_label (this, _("Offset"), true);
95 _x_offset_label = create_label (this, _("X"), true);
96 _x_offset = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(spin_width, -1));
97 _x_offset_pc_label = new StaticText (this, _("%"));
98 _y_offset_label = create_label (this, _("Y"), true);
99 _y_offset = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(spin_width, -1));
100 _y_offset_pc_label = new StaticText (this, _("%"));
102 _scale_label = create_label (this, _("Scale"), true);
103 _x_scale_label = create_label (this, _("X"), true);
104 _x_scale = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(spin_width, -1));
105 _x_scale_pc_label = new StaticText (this, _("%"));
106 _y_scale_label = create_label (this, S_("Coord|Y"), true);
107 _y_scale = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(spin_width, -1));
108 _y_scale_pc_label = new StaticText (this, _("%"));
110 _line_spacing_label = create_label (this, _("Line spacing"), true);
111 _line_spacing = new wxSpinCtrl (this);
112 _line_spacing_pc_label = new StaticText (this, _("%"));
114 _stream_label = create_label (this, _("Stream"), true);
115 _stream = new wxChoice (this, wxID_ANY);
117 _text_view_button = new Button (this, _("View..."));
118 _fonts_dialog_button = new Button (this, _("Fonts..."));
119 _appearance_dialog_button = new Button (this, _("Appearance..."));
121 _x_offset->SetRange (-100, 100);
122 _y_offset->SetRange (-100, 100);
123 _x_scale->SetRange (10, 1000);
124 _y_scale->SetRange (10, 1000);
125 _line_spacing->SetRange (10, 1000);
127 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
128 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
129 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
130 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
131 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
132 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
133 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
134 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
135 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
136 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
137 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
138 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
139 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
142 content_selection_changed ();
146 TextPanel::setup_visibility ()
148 switch (current_type()) {
149 case TEXT_OPEN_SUBTITLE:
150 if (_dcp_track_label) {
151 _dcp_track_label->Destroy ();
152 _dcp_track_label = 0;
155 _dcp_track->Destroy ();
158 if (!_outline_subtitles) {
159 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
160 _outline_subtitles->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::outline_subtitles_changed, this));
161 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
165 case TEXT_CLOSED_CAPTION:
166 if (!_dcp_track_label) {
167 _dcp_track_label = create_label (this, _("CCAP track"), true);
168 add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(_ccap_track_row, 0));
171 _dcp_track = new wxChoice (this, wxID_ANY);
172 _dcp_track->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::dcp_track_changed, this));
173 _grid->Add (_dcp_track, wxGBPosition(_ccap_track_row, 1), wxDefaultSpan, wxEXPAND);
174 update_dcp_tracks ();
175 film_content_changed (TextContentProperty::DCP_TRACK);
177 if (_outline_subtitles) {
178 _outline_subtitles->Destroy ();
179 _outline_subtitles = 0;
180 clear_outline_subtitles ();
191 TextPanel::add_to_grid ()
193 Config::Interface const interface = Config::instance()->interface_complexity();
197 _reference->Show (interface == Config::INTERFACE_FULL);
198 _reference_note->Show (interface == Config::INTERFACE_FULL);
200 if (interface == Config::INTERFACE_FULL) {
201 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
202 reference_sizer->Add (_reference, 0);
203 reference_sizer->Add (_reference_note, 0);
204 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
208 wxBoxSizer* use = new wxBoxSizer (wxHORIZONTAL);
209 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
210 use->Add (_type, 1, wxEXPAND, 0);
211 _grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
214 _grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
217 _outline_subtitles_row = r;
220 add_label_to_sizer (_grid, _offset_label, true, wxGBPosition (r, 0));
221 wxBoxSizer* offset = new wxBoxSizer (wxHORIZONTAL);
222 add_label_to_sizer (offset, _x_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
223 offset->Add (_x_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
224 offset->Add (_x_offset_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
226 _grid->Add (offset, wxGBPosition(r, 1));
228 offset = new wxBoxSizer (wxHORIZONTAL);
230 add_label_to_sizer (offset, _y_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
231 offset->Add (_y_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
232 add_label_to_sizer (offset, _y_offset_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
233 _grid->Add (offset, wxGBPosition (r, 1));
236 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
237 wxBoxSizer* scale = new wxBoxSizer (wxHORIZONTAL);
238 add_label_to_sizer (scale, _x_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
239 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
240 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
242 _grid->Add (scale, wxGBPosition(r, 1));
244 scale = new wxBoxSizer (wxHORIZONTAL);
246 add_label_to_sizer (scale, _y_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
247 scale->Add (_y_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
248 add_label_to_sizer (scale, _y_scale_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
249 _grid->Add (scale, wxGBPosition (r, 1));
253 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
254 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
255 s->Add (_line_spacing);
256 add_label_to_sizer (s, _line_spacing_pc_label, false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
257 _grid->Add (s, wxGBPosition (r, 1));
264 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
265 _grid->Add (_stream, wxGBPosition (r, 1));
269 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
271 s->Add (_text_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
272 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
273 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
275 _grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
283 TextPanel::update_dcp_track_selection ()
285 DCPOMATIC_ASSERT (_dcp_track);
287 optional<DCPTextTrack> selected;
289 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
290 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
292 optional<DCPTextTrack> dt = t->dcp_track();
293 if (dt && selected && *dt != *selected) {
295 } else if (!selected) {
302 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
303 if (!many && selected && *selected == i) {
304 _dcp_track->SetSelection (n);
309 if (!selected || many) {
310 _dcp_track->SetSelection (wxNOT_FOUND);
315 TextPanel::update_dcp_tracks ()
317 DCPOMATIC_ASSERT (_dcp_track);
319 _dcp_track->Clear ();
320 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
321 /* XXX: don't display the "magic" track which has empty name and language;
322 this is a nasty hack (see also Film::closed_caption_tracks)
324 if (!i.name.empty() || !i.language.empty()) {
325 _dcp_track->Append (std_to_wx(i.summary()));
329 if (_parent->film()->closed_caption_tracks().size() < 6) {
330 _dcp_track->Append (_("Add new..."));
333 update_dcp_track_selection ();
337 TextPanel::dcp_track_changed ()
339 optional<DCPTextTrack> track;
341 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
342 DCPTextTrackDialog* d = new DCPTextTrackDialog (this);
343 if (d->ShowModal() == wxID_OK) {
348 /* Find the DCPTextTrack that was selected */
349 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
350 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
357 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
358 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
359 if (t && t->type() == TEXT_CLOSED_CAPTION) {
360 t->set_dcp_track(*track);
365 update_dcp_tracks ();
369 TextPanel::film_changed (Film::Property property)
371 if (property == Film::CONTENT || property == Film::REEL_TYPE || property == Film::INTEROP) {
372 setup_sensitivity ();
377 TextPanel::film_content_changed (int property)
379 FFmpegContentList fc = _parent->selected_ffmpeg ();
380 ContentList sc = _parent->selected_text ();
382 shared_ptr<FFmpegContent> fcs;
383 if (fc.size() == 1) {
387 shared_ptr<Content> scs;
388 if (sc.size() == 1) {
392 shared_ptr<TextContent> text;
394 text = scs->text_of_original_type(_original_type);
397 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
400 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
401 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
402 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
405 if (fcs->subtitle_stream()) {
406 checked_set (_stream, fcs->subtitle_stream()->identifier ());
408 _stream->SetSelection (wxNOT_FOUND);
411 setup_sensitivity ();
412 clear_outline_subtitles ();
413 } else if (property == TextContentProperty::USE) {
414 checked_set (_use, text ? text->use() : false);
415 setup_sensitivity ();
416 clear_outline_subtitles ();
417 } else if (property == TextContentProperty::TYPE) {
419 switch (text->type()) {
420 case TEXT_OPEN_SUBTITLE:
421 _type->SetSelection (0);
423 case TEXT_CLOSED_CAPTION:
424 _type->SetSelection (1);
427 DCPOMATIC_ASSERT (false);
430 _type->SetSelection (0);
432 setup_sensitivity ();
434 } else if (property == TextContentProperty::BURN) {
435 checked_set (_burn, text ? text->burn() : false);
436 } else if (property == TextContentProperty::X_OFFSET) {
437 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
438 update_outline_subtitles_in_viewer ();
439 } else if (property == TextContentProperty::Y_OFFSET) {
440 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
441 update_outline_subtitles_in_viewer ();
442 } else if (property == TextContentProperty::X_SCALE) {
443 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
444 clear_outline_subtitles ();
445 } else if (property == TextContentProperty::Y_SCALE) {
446 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
447 clear_outline_subtitles ();
448 } else if (property == TextContentProperty::LINE_SPACING) {
449 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
450 clear_outline_subtitles ();
451 } else if (property == TextContentProperty::DCP_TRACK) {
453 update_dcp_track_selection ();
455 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
457 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
458 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
460 checked_set (_reference, false);
463 setup_sensitivity ();
464 } else if (property == DCPContentProperty::TEXTS) {
465 setup_sensitivity ();
470 TextPanel::use_toggled ()
472 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
473 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
477 /** @return the text type that is currently selected in the drop-down */
479 TextPanel::current_type () const
481 switch (_type->GetSelection()) {
483 return TEXT_OPEN_SUBTITLE;
485 return TEXT_CLOSED_CAPTION;
492 TextPanel::type_changed ()
494 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
495 i->text_of_original_type(_original_type)->set_type (current_type ());
502 TextPanel::burn_toggled ()
504 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
505 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
510 TextPanel::setup_sensitivity ()
513 /* We currently assume that FFmpeg subtitles are bitmapped */
515 /* DCP subs can't have their line spacing changed */
517 ContentList sel = _parent->selected_text ();
518 BOOST_FOREACH (shared_ptr<Content> i, sel) {
519 /* These are the content types that could include subtitles */
520 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
521 shared_ptr<const StringTextFileContent> sc = boost::dynamic_pointer_cast<const StringTextFileContent> (i);
522 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
523 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
525 if (!fc->text.empty()) {
529 } else if (dc || dsc) {
533 /* XXX: in the future there could be bitmap subs from DCPs */
538 /* Decide whether we can reference these subs */
540 shared_ptr<DCPContent> dcp;
541 if (sel.size() == 1) {
542 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
546 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
548 if (why_not.empty()) {
549 cannot = _("Cannot reference this DCP's subtitles or captions.");
551 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
553 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
555 bool const reference = _reference->GetValue ();
557 TextType const type = current_type ();
561 _type->Append (_("open subtitles"));
562 if (ffmpeg_subs == 0) {
563 _type->Append (_("closed captions"));
567 case TEXT_OPEN_SUBTITLE:
568 _type->SetSelection (0);
570 case TEXT_CLOSED_CAPTION:
571 if (_type->GetCount() > 1) {
572 _type->SetSelection (1);
579 /* Set up sensitivity */
580 _use->Enable (!reference && any_subs > 0);
581 bool const use = _use->GetValue ();
582 if (_outline_subtitles) {
583 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TEXT_OPEN_SUBTITLE);
585 _type->Enable (!reference && any_subs > 0 && use);
586 _burn->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
587 _x_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
588 _y_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
589 _x_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
590 _y_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
591 _line_spacing->Enable (!reference && use && type == TEXT_OPEN_SUBTITLE && dcp_subs < any_subs);
592 _stream->Enable (!reference && ffmpeg_subs == 1);
593 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
594 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
595 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TEXT_OPEN_SUBTITLE);
596 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
600 TextPanel::stream_changed ()
602 FFmpegContentList fc = _parent->selected_ffmpeg ();
603 if (fc.size() != 1) {
607 shared_ptr<FFmpegContent> fcs = fc.front ();
609 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
610 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
611 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
612 while (i != a.end() && (*i)->identifier () != s) {
617 fcs->set_subtitle_stream (*i);
622 TextPanel::x_offset_changed ()
624 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
625 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
630 TextPanel::y_offset_changed ()
632 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
633 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
638 TextPanel::x_scale_changed ()
640 ContentList c = _parent->selected_text ();
642 c.front()->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
647 TextPanel::y_scale_changed ()
649 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
650 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
655 TextPanel::line_spacing_changed ()
657 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
658 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
663 TextPanel::content_selection_changed ()
665 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
666 film_content_changed (TextContentProperty::USE);
667 film_content_changed (TextContentProperty::BURN);
668 film_content_changed (TextContentProperty::X_OFFSET);
669 film_content_changed (TextContentProperty::Y_OFFSET);
670 film_content_changed (TextContentProperty::X_SCALE);
671 film_content_changed (TextContentProperty::Y_SCALE);
672 film_content_changed (TextContentProperty::LINE_SPACING);
673 film_content_changed (TextContentProperty::FONTS);
674 film_content_changed (TextContentProperty::TYPE);
675 film_content_changed (TextContentProperty::DCP_TRACK);
676 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
680 TextPanel::text_view_clicked ()
683 _text_view->Destroy ();
687 ContentList c = _parent->selected_text ();
688 DCPOMATIC_ASSERT (c.size() == 1);
690 shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
693 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
699 TextPanel::fonts_dialog_clicked ()
702 _fonts_dialog->Destroy ();
706 ContentList c = _parent->selected_text ();
707 DCPOMATIC_ASSERT (c.size() == 1);
709 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
710 _fonts_dialog->Show ();
714 TextPanel::reference_clicked ()
716 ContentList c = _parent->selected ();
721 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
726 d->set_reference_text (_original_type, _reference->GetValue ());
730 TextPanel::appearance_dialog_clicked ()
732 ContentList c = _parent->selected_text ();
733 DCPOMATIC_ASSERT (c.size() == 1);
735 SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
736 if (d->ShowModal () == wxID_OK) {
744 /** The user has clicked on the outline subtitles check box */
746 TextPanel::outline_subtitles_changed ()
748 if (_outline_subtitles->GetValue()) {
749 _analysis_content = _parent->selected_text().front();
750 try_to_load_analysis ();
752 clear_outline_subtitles ();
758 TextPanel::try_to_load_analysis ()
760 if (_loading_analysis) {
764 _loading_analysis = true;
765 setup_sensitivity ();
768 shared_ptr<Content> content = _analysis_content.lock ();
770 _loading_analysis = false;
771 setup_sensitivity ();
775 boost::filesystem::path const path = _parent->film()->subtitle_analysis_path(content);
777 if (!boost::filesystem::exists(path)) {
778 BOOST_FOREACH (shared_ptr<Job> i, JobManager::instance()->get()) {
779 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
784 JobManager::instance()->analyse_subtitles (
785 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
791 _analysis.reset (new SubtitleAnalysis(path));
792 } catch (OldFormatError& e) {
793 /* An old analysis file: recreate it */
794 JobManager::instance()->analyse_subtitles (
795 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
800 update_outline_subtitles_in_viewer ();
801 _loading_analysis = false;
802 setup_sensitivity ();
807 TextPanel::update_outline_subtitles_in_viewer ()
809 shared_ptr<FilmViewer> fv = _parent->film_viewer().lock();
815 optional<dcpomatic::Rect<double> > rect = _analysis->bounding_box ();
817 shared_ptr<Content> content = _analysis_content.lock ();
818 DCPOMATIC_ASSERT (content);
819 rect->x += content->text.front()->x_offset();
820 rect->y += content->text.front()->y_offset();
822 fv->set_outline_subtitles (rect);
824 fv->set_outline_subtitles (optional<dcpomatic::Rect<double> >());
829 /** Remove any current subtitle outline display */
831 TextPanel::clear_outline_subtitles ()
834 update_outline_subtitles_in_viewer ();
835 if (_outline_subtitles) {
836 _outline_subtitles->SetValue (false);
842 TextPanel::analysis_finished ()
844 shared_ptr<Content> content = _analysis_content.lock ();
846 _loading_analysis = false;
847 setup_sensitivity ();
851 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
852 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
855 error_dialog (_parent->window(), _("Could not analyse subtitles."));
856 clear_outline_subtitles ();
857 _loading_analysis = false;
858 setup_sensitivity ();
862 _loading_analysis = false;
863 try_to_load_analysis ();