2 Copyright (C) 2012-2021 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/>.
22 #include "check_box.h"
23 #include "content_panel.h"
24 #include "dcp_text_track_dialog.h"
25 #include "dcpomatic_button.h"
26 #include "dcpomatic_spin_ctrl.h"
27 #include "film_editor.h"
28 #include "film_viewer.h"
29 #include "fonts_dialog.h"
30 #include "language_tag_widget.h"
31 #include "static_text.h"
32 #include "subtitle_appearance_dialog.h"
33 #include "text_panel.h"
34 #include "text_view.h"
36 #include "lib/analyse_subtitles_job.h"
37 #include "lib/dcp_content.h"
38 #include "lib/dcp_subtitle_content.h"
39 #include "lib/dcp_subtitle_decoder.h"
40 #include "lib/decoder_factory.h"
41 #include "lib/ffmpeg_content.h"
42 #include "lib/ffmpeg_subtitle_stream.h"
43 #include "lib/job_manager.h"
44 #include "lib/string_text_file_content.h"
45 #include "lib/string_text_file_decoder.h"
46 #include "lib/subtitle_analysis.h"
47 #include "lib/text_content.h"
48 #include <dcp/warnings.h>
49 LIBDCP_DISABLE_WARNINGS
50 #include <wx/spinctrl.h>
51 LIBDCP_ENABLE_WARNINGS
55 using std::dynamic_pointer_cast;
57 using std::shared_ptr;
61 using boost::optional;
64 /** @param t Original text type of the content, if known */
65 TextPanel::TextPanel (ContentPanel* p, TextType t)
66 : ContentSubPanel (p, std_to_wx(text_type_to_name(t)))
76 wxString refer = _("Use this DCP's subtitle as OV and make VF");
77 if (_original_type == TextType::CLOSED_CAPTION) {
78 refer = _("Use this DCP's closed caption as OV and make VF");
81 _reference = new CheckBox (this, refer);
82 _reference_note = new StaticText (this, wxT(""));
83 _reference_note->Wrap (200);
84 auto font = _reference_note->GetFont();
85 font.SetStyle(wxFONTSTYLE_ITALIC);
86 font.SetPointSize(font.GetPointSize() - 1);
87 _reference_note->SetFont(font);
89 _use = new CheckBox (this, _("Use as"));
90 _type = new wxChoice (this, wxID_ANY);
91 _type->Append (_("open subtitles"));
92 _type->Append (_("closed captions"));
94 _burn = new CheckBox (this, _("Burn subtitles into image"));
96 _offset_label = create_label (this, _("Offset"), true);
97 _x_offset_label = create_label (this, _("X"), true);
98 _x_offset = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
99 _x_offset_pc_label = new StaticText (this, _("%"));
100 _y_offset_label = create_label (this, _("Y"), true);
101 _y_offset = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
102 _y_offset_pc_label = new StaticText (this, _("%"));
104 _scale_label = create_label (this, _("Scale"), true);
105 _x_scale_label = create_label (this, _("X"), true);
106 _x_scale = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
107 _x_scale_pc_label = new StaticText (this, _("%"));
108 _y_scale_label = create_label (this, S_("Coord|Y"), true);
109 _y_scale = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
110 _y_scale_pc_label = new StaticText (this, _("%"));
112 _line_spacing_label = create_label (this, _("Line spacing"), true);
113 _line_spacing = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
114 _line_spacing_pc_label = new StaticText (this, _("%"));
116 _z_position_label = create_label (this, _("Z position"), true);
117 _z_position = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
119 _stream_label = create_label (this, _("Stream"), true);
120 _stream = new wxChoice (this, wxID_ANY);
122 _text_view_button = new Button (this, _("View..."));
123 _fonts_dialog_button = new Button (this, _("Fonts..."));
124 _appearance_dialog_button = new Button (this, _("Appearance..."));
126 _x_offset->SetRange (-100, 100);
127 _y_offset->SetRange (-100, 100);
128 _x_scale->SetRange (0, 1000);
129 _y_scale->SetRange (0, 1000);
130 _line_spacing->SetRange (0, 1000);
131 _z_position->SetRange (-100, 100);
133 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
134 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
135 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
136 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
137 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
138 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
139 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
140 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
141 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
142 _z_position->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::z_position_changed, this));
143 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
144 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
145 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
146 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
149 content_selection_changed ();
156 TextPanel::setup_visibility ()
158 switch (current_type()) {
159 case TextType::OPEN_SUBTITLE:
160 if (_dcp_track_label) {
161 _dcp_track_label->Destroy ();
162 _dcp_track_label = nullptr;
165 _dcp_track->Destroy ();
166 _dcp_track = nullptr;
168 if (!_outline_subtitles) {
169 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
170 _outline_subtitles->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::outline_subtitles_changed, this));
171 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
174 _language_label = create_label (this, _("Language"), true);
175 add_label_to_sizer (_grid, _language_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
176 _language_sizer = new wxBoxSizer (wxHORIZONTAL);
177 _language = new LanguageTagWidget (this, _("Language of these subtitles"), boost::none, wxString("en-US-"));
178 _language->Changed.connect (boost::bind(&TextPanel::language_changed, this));
179 _language_sizer->Add (_language->sizer(), 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
180 _language_type = new wxChoice (this, wxID_ANY);
181 /// TRANSLATORS: Main and Additional here are a choice for whether a set of subtitles is in the "main" language of the
182 /// film or an "additional" language.
183 _language_type->Append (_("Main"));
184 _language_type->Append (_("Additional"));
185 _language_type->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::language_is_additional_changed, this));
186 _language_sizer->Add (_language_type, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_CHOICE_TOP_PAD);
187 _grid->Add (_language_sizer, wxGBPosition(_ccap_track_or_language_row, 1), wxGBSpan(1, 2));
188 film_content_changed (TextContentProperty::LANGUAGE);
189 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
192 case TextType::CLOSED_CAPTION:
193 if (_language_label) {
194 _language_label->Destroy ();
195 _language_label = nullptr;
196 _grid->Remove (_language->sizer());
198 _grid->Remove (_language_sizer);
199 _language_sizer = nullptr;
201 _language_type->Destroy ();
202 _language_type = nullptr;
204 if (!_dcp_track_label) {
205 _dcp_track_label = create_label (this, _("CCAP track"), true);
206 add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
209 _dcp_track = new wxChoice (this, wxID_ANY);
210 _dcp_track->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::dcp_track_changed, this));
211 _grid->Add (_dcp_track, wxGBPosition(_ccap_track_or_language_row, 1), wxDefaultSpan, wxEXPAND);
212 update_dcp_tracks ();
213 film_content_changed (TextContentProperty::DCP_TRACK);
215 if (_outline_subtitles) {
216 _outline_subtitles->Destroy ();
217 _outline_subtitles = nullptr;
218 clear_outline_subtitles ();
230 TextPanel::add_to_grid ()
234 auto reference_sizer = new wxBoxSizer (wxVERTICAL);
235 reference_sizer->Add (_reference, 0);
236 reference_sizer->Add (_reference_note, 0);
237 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
240 auto use = new wxBoxSizer (wxHORIZONTAL);
241 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
242 use->Add (_type, 1, wxEXPAND, 0);
243 _grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
246 _grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
249 _outline_subtitles_row = r;
252 add_label_to_sizer (_grid, _offset_label, true, wxGBPosition (r, 0));
253 auto offset = new wxBoxSizer (wxHORIZONTAL);
254 add_label_to_sizer (offset, _x_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
255 offset->Add (_x_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
256 offset->Add (_x_offset_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
258 _grid->Add (offset, wxGBPosition(r, 1));
260 offset = new wxBoxSizer (wxHORIZONTAL);
262 add_label_to_sizer (offset, _y_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
263 offset->Add (_y_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
264 add_label_to_sizer (offset, _y_offset_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
265 _grid->Add (offset, wxGBPosition (r, 1));
268 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
269 auto scale = new wxBoxSizer (wxHORIZONTAL);
270 add_label_to_sizer (scale, _x_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
271 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
272 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
274 _grid->Add (scale, wxGBPosition(r, 1));
276 scale = new wxBoxSizer (wxHORIZONTAL);
278 add_label_to_sizer (scale, _y_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
279 scale->Add (_y_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
280 add_label_to_sizer (scale, _y_scale_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
281 _grid->Add (scale, wxGBPosition (r, 1));
285 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
286 auto s = new wxBoxSizer (wxHORIZONTAL);
287 s->Add (_line_spacing);
288 add_label_to_sizer (s, _line_spacing_pc_label, false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
289 _grid->Add (s, wxGBPosition (r, 1));
293 add_label_to_sizer (_grid, _z_position_label, true, wxGBPosition(r, 0));
294 _grid->Add (_z_position, wxGBPosition(r, 1));
297 _ccap_track_or_language_row = r;
300 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
301 _grid->Add (_stream, wxGBPosition (r, 1));
305 auto s = new wxBoxSizer (wxHORIZONTAL);
307 s->Add (_text_view_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
308 s->Add (_fonts_dialog_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
309 s->Add (_appearance_dialog_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
311 _grid->Add (s, wxGBPosition(r, 0), wxGBSpan(1, 2));
320 TextPanel::update_dcp_track_selection ()
322 DCPOMATIC_ASSERT (_dcp_track);
324 optional<DCPTextTrack> selected;
326 for (auto i: _parent->selected_text()) {
327 auto t = i->text_of_original_type(_original_type);
329 auto dt = t->dcp_track();
330 if (dt && selected && *dt != *selected) {
332 } else if (!selected) {
339 for (auto i: _parent->film()->closed_caption_tracks()) {
340 if (!many && selected && *selected == i) {
341 _dcp_track->SetSelection (n);
346 if (!selected || many) {
347 _dcp_track->SetSelection (wxNOT_FOUND);
353 TextPanel::update_dcp_tracks ()
355 DCPOMATIC_ASSERT (_dcp_track);
357 _dcp_track->Clear ();
358 for (auto i: _parent->film()->closed_caption_tracks()) {
359 /* XXX: don't display the "magic" track which has empty name and language;
360 this is a nasty hack (see also Film::closed_caption_tracks)
362 if (!i.name.empty() || i.language) {
363 _dcp_track->Append (std_to_wx(i.summary()));
367 if (_parent->film()->closed_caption_tracks().size() < 6) {
368 _dcp_track->Append (_("Add new..."));
371 update_dcp_track_selection ();
376 TextPanel::dcp_track_changed ()
378 optional<DCPTextTrack> track;
380 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
381 auto d = new DCPTextTrackDialog (this);
382 if (d->ShowModal() == wxID_OK) {
387 /* Find the DCPTextTrack that was selected */
388 for (auto i: _parent->film()->closed_caption_tracks()) {
389 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
396 for (auto i: _parent->selected_text()) {
397 auto t = i->text_of_original_type(_original_type);
398 if (t && t->type() == TextType::CLOSED_CAPTION) {
399 t->set_dcp_track(*track);
404 update_dcp_tracks ();
409 TextPanel::film_changed (Film::Property property)
411 if (property == Film::Property::CONTENT || property == Film::Property::REEL_TYPE || property == Film::Property::INTEROP) {
412 setup_sensitivity ();
418 TextPanel::film_content_changed (int property)
420 auto fc = _parent->selected_ffmpeg ();
421 auto sc = _parent->selected_text ();
423 shared_ptr<FFmpegContent> fcs;
424 if (fc.size() == 1) {
428 shared_ptr<Content> scs;
429 if (sc.size() == 1) {
433 shared_ptr<TextContent> text;
435 text = scs->text_of_original_type(_original_type);
438 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
441 for (auto i: fcs->subtitle_streams()) {
442 _stream->Append (std_to_wx(i->name), new wxStringClientData(std_to_wx(i->identifier())));
445 if (fcs->subtitle_stream()) {
446 checked_set (_stream, fcs->subtitle_stream()->identifier ());
448 _stream->SetSelection (wxNOT_FOUND);
451 setup_sensitivity ();
452 clear_outline_subtitles ();
453 } else if (property == TextContentProperty::USE) {
454 checked_set (_use, text ? text->use() : false);
455 setup_sensitivity ();
456 clear_outline_subtitles ();
457 } else if (property == TextContentProperty::TYPE) {
459 switch (text->type()) {
460 case TextType::OPEN_SUBTITLE:
461 _type->SetSelection (0);
463 case TextType::CLOSED_CAPTION:
464 _type->SetSelection (1);
467 DCPOMATIC_ASSERT (false);
470 _type->SetSelection (0);
472 setup_sensitivity ();
474 } else if (property == TextContentProperty::BURN) {
475 checked_set (_burn, text ? text->burn() : false);
476 } else if (property == TextContentProperty::X_OFFSET) {
477 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
478 update_outline_subtitles_in_viewer ();
479 } else if (property == TextContentProperty::Y_OFFSET) {
480 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
481 update_outline_subtitles_in_viewer ();
482 } else if (property == TextContentProperty::X_SCALE) {
483 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
484 clear_outline_subtitles ();
485 } else if (property == TextContentProperty::Y_SCALE) {
486 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
487 clear_outline_subtitles ();
488 } else if (property == TextContentProperty::LINE_SPACING) {
489 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
490 clear_outline_subtitles ();
491 } else if (property == TextContentProperty::Z_POSITION) {
492 checked_set (_z_position, text ? text->z_position() : 0);
493 } else if (property == TextContentProperty::DCP_TRACK) {
495 update_dcp_track_selection ();
497 } else if (property == TextContentProperty::LANGUAGE) {
499 _language->set (text ? text->language() : boost::none);
501 } else if (property == TextContentProperty::LANGUAGE_IS_ADDITIONAL) {
502 if (_language_type) {
503 _language_type->SetSelection (text ? (text->language_is_additional() ? 1 : 0) : 0);
505 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
507 auto dcp = dynamic_pointer_cast<DCPContent> (scs);
508 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
510 checked_set (_reference, false);
513 setup_sensitivity ();
514 } else if (property == DCPContentProperty::TEXTS) {
515 setup_sensitivity ();
516 } else if (property == ContentProperty::TRIM_START) {
517 setup_sensitivity ();
523 TextPanel::use_toggled ()
525 for (auto i: _parent->selected_text()) {
526 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
531 /** @return the text type that is currently selected in the drop-down */
533 TextPanel::current_type () const
535 switch (_type->GetSelection()) {
537 return TextType::OPEN_SUBTITLE;
539 return TextType::CLOSED_CAPTION;
542 return TextType::UNKNOWN;
547 TextPanel::type_changed ()
549 for (auto i: _parent->selected_text()) {
550 i->text_of_original_type(_original_type)->set_type (current_type ());
558 TextPanel::burn_toggled ()
560 for (auto i: _parent->selected_text ()) {
561 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
567 TextPanel::setup_sensitivity ()
570 /* We currently assume that FFmpeg subtitles are bitmapped */
572 /* DCP subs can't have their line spacing changed */
574 auto sel = _parent->selected_text ();
576 /* These are the content types that could include subtitles */
577 auto fc = std::dynamic_pointer_cast<const FFmpegContent>(i);
578 auto sc = std::dynamic_pointer_cast<const StringTextFileContent>(i);
579 auto dc = std::dynamic_pointer_cast<const DCPContent>(i);
580 auto dsc = std::dynamic_pointer_cast<const DCPSubtitleContent>(i);
582 if (!fc->text.empty()) {
586 } else if (dc || dsc) {
590 /* XXX: in the future there could be bitmap subs from DCPs */
595 /* Decide whether we can reference these subs */
597 shared_ptr<DCPContent> dcp;
598 if (sel.size() == 1) {
599 dcp = dynamic_pointer_cast<DCPContent>(sel.front());
603 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
605 if (why_not.empty()) {
606 cannot = _("Cannot reference this DCP's subtitles or captions.");
608 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
610 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
612 bool const reference = _reference->GetValue ();
614 auto const type = current_type ();
618 _type->Append (_("open subtitles"));
619 if (ffmpeg_subs == 0) {
620 _type->Append (_("closed captions"));
624 case TextType::OPEN_SUBTITLE:
625 _type->SetSelection (0);
627 case TextType::CLOSED_CAPTION:
628 if (_type->GetCount() > 1) {
629 _type->SetSelection (1);
636 /* Set up sensitivity */
637 _use->Enable (!reference && any_subs > 0);
638 bool const use = _use->GetValue ();
639 if (_outline_subtitles) {
640 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TextType::OPEN_SUBTITLE);
642 _type->Enable (!reference && any_subs > 0 && use);
643 _burn->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
644 _x_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
645 _y_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
646 _x_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
647 _y_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
648 _line_spacing->Enable (!reference && use && type == TextType::OPEN_SUBTITLE && dcp_subs < any_subs);
649 _z_position->Enable (!reference && use && type == TextType::OPEN_SUBTITLE);
650 _stream->Enable (!reference && ffmpeg_subs == 1);
651 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
652 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
653 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TextType::OPEN_SUBTITLE);
654 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
659 TextPanel::stream_changed ()
661 auto fc = _parent->selected_ffmpeg ();
662 if (fc.size() != 1) {
666 auto fcs = fc.front ();
668 auto a = fcs->subtitle_streams ();
670 auto const s = string_client_data (_stream->GetClientObject(_stream->GetSelection()));
671 while (i != a.end() && (*i)->identifier () != s) {
676 fcs->set_subtitle_stream (*i);
682 TextPanel::x_offset_changed ()
684 for (auto i: _parent->selected_text ()) {
685 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
691 TextPanel::y_offset_changed ()
693 for (auto i: _parent->selected_text ()) {
694 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
700 TextPanel::x_scale_changed ()
702 for (auto i: _parent->selected_text ()) {
703 i->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
709 TextPanel::y_scale_changed ()
711 for (auto i: _parent->selected_text ()) {
712 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
718 TextPanel::line_spacing_changed ()
720 for (auto i: _parent->selected_text ()) {
721 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
727 TextPanel::z_position_changed ()
729 for (auto i: _parent->selected_text()) {
730 i->text_of_original_type(_original_type)->set_z_position (_z_position->GetValue());
736 TextPanel::content_selection_changed ()
738 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
739 film_content_changed (TextContentProperty::USE);
740 film_content_changed (TextContentProperty::BURN);
741 film_content_changed (TextContentProperty::X_OFFSET);
742 film_content_changed (TextContentProperty::Y_OFFSET);
743 film_content_changed (TextContentProperty::X_SCALE);
744 film_content_changed (TextContentProperty::Y_SCALE);
745 film_content_changed (TextContentProperty::LINE_SPACING);
746 film_content_changed (TextContentProperty::Z_POSITION);
747 film_content_changed (TextContentProperty::FONTS);
748 film_content_changed (TextContentProperty::TYPE);
749 film_content_changed (TextContentProperty::DCP_TRACK);
750 film_content_changed (TextContentProperty::LANGUAGE);
751 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
752 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
757 TextPanel::text_view_clicked ()
760 _text_view->Destroy ();
761 _text_view = nullptr;
764 auto c = _parent->selected_text ();
765 DCPOMATIC_ASSERT (c.size() == 1);
767 auto decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
770 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
777 TextPanel::fonts_dialog_clicked ()
780 _fonts_dialog->Destroy ();
781 _fonts_dialog = nullptr;
784 auto c = _parent->selected_text ();
785 DCPOMATIC_ASSERT (c.size() == 1);
787 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
788 _fonts_dialog->Show ();
793 TextPanel::reference_clicked ()
795 auto c = _parent->selected ();
800 auto d = dynamic_pointer_cast<DCPContent> (c.front ());
805 d->set_reference_text (_original_type, _reference->GetValue ());
810 TextPanel::appearance_dialog_clicked ()
812 auto c = _parent->selected_text ();
813 DCPOMATIC_ASSERT (c.size() == 1);
815 auto d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
816 if (d->ShowModal () == wxID_OK) {
823 /** The user has clicked on the outline subtitles check box */
825 TextPanel::outline_subtitles_changed ()
827 if (_outline_subtitles->GetValue()) {
828 _analysis_content = _parent->selected_text().front();
829 try_to_load_analysis ();
831 clear_outline_subtitles ();
837 TextPanel::try_to_load_analysis ()
839 if (_loading_analysis) {
843 _loading_analysis = true;
844 setup_sensitivity ();
847 auto content = _analysis_content.lock ();
849 _loading_analysis = false;
850 setup_sensitivity ();
854 auto const path = _parent->film()->subtitle_analysis_path(content);
856 if (!boost::filesystem::exists(path)) {
857 for (auto i: JobManager::instance()->get()) {
858 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
863 JobManager::instance()->analyse_subtitles (
864 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
870 _analysis.reset (new SubtitleAnalysis(path));
871 } catch (OldFormatError& e) {
872 /* An old analysis file: recreate it */
873 JobManager::instance()->analyse_subtitles (
874 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
879 update_outline_subtitles_in_viewer ();
880 _loading_analysis = false;
881 setup_sensitivity ();
886 TextPanel::update_outline_subtitles_in_viewer ()
888 auto fv = _parent->film_viewer().lock();
894 auto rect = _analysis->bounding_box ();
896 auto content = _analysis_content.lock ();
897 DCPOMATIC_ASSERT (content);
898 rect->x += content->text.front()->x_offset();
899 rect->y += content->text.front()->y_offset();
901 fv->set_outline_subtitles (rect);
903 fv->set_outline_subtitles ({});
908 /** Remove any current subtitle outline display */
910 TextPanel::clear_outline_subtitles ()
913 update_outline_subtitles_in_viewer ();
914 if (_outline_subtitles) {
915 _outline_subtitles->SetValue (false);
921 TextPanel::analysis_finished ()
923 auto content = _analysis_content.lock ();
925 _loading_analysis = false;
926 setup_sensitivity ();
930 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
931 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
934 error_dialog (_parent->window(), _("Could not analyse subtitles."));
935 clear_outline_subtitles ();
936 _loading_analysis = false;
937 setup_sensitivity ();
941 _loading_analysis = false;
942 try_to_load_analysis ();
947 TextPanel::language_changed ()
949 for (auto i: _parent->selected_text()) {
950 auto t = i->text_of_original_type(_original_type);
952 t->set_language (_language->get());
959 TextPanel::language_is_additional_changed ()
961 for (auto i: _parent->selected_text()) {
962 auto t = i->text_of_original_type(_original_type);
964 t->set_language_is_additional (_language_type->GetSelection() == 1);