Support subs and tidy up a few things.
[dcpomatic.git] / src / wx / dcp_panel.cc
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 #include "audio_dialog.h"
23 #include "check_box.h"
24 #include "check_box.h"
25 #include "dcp_panel.h"
26 #include "dcpomatic_button.h"
27 #include "dcpomatic_spin_ctrl.h"
28 #include "focus_manager.h"
29 #include "interop_metadata_dialog.h"
30 #include "language_tag_dialog.h"
31 #include "markers_dialog.h"
32 #include "smpte_metadata_dialog.h"
33 #include "static_text.h"
34 #include "wx_util.h"
35 #include "lib/ratio.h"
36 #include "lib/config.h"
37 #include "lib/dcp_content_type.h"
38 #include "lib/util.h"
39 #include "lib/film.h"
40 #include "lib/ffmpeg_content.h"
41 #include "lib/audio_processor.h"
42 #include "lib/video_content.h"
43 #include "lib/text_content.h"
44 #include "lib/dcp_content.h"
45 #include "lib/audio_content.h"
46 #include <dcp/locale_convert.h>
47 #include <wx/wx.h>
48 #include <wx/notebook.h>
49 #include <wx/gbsizer.h>
50 #include <wx/spinctrl.h>
51 #include <boost/lexical_cast.hpp>
52 #include <iostream>
53
54
55 using std::cout;
56 using std::list;
57 using std::string;
58 using std::vector;
59 using std::pair;
60 using std::max;
61 using std::make_pair;
62 using boost::lexical_cast;
63 using std::shared_ptr;
64 using std::weak_ptr;
65 #if BOOST_VERSION >= 106100
66 using namespace boost::placeholders;
67 #endif
68 using dcp::locale_convert;
69
70
71 DCPPanel::DCPPanel (wxNotebook* n, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer)
72         : _film (film)
73         , _viewer (viewer)
74         , _generally_sensitive (true)
75 {
76         _panel = new wxPanel (n);
77         _sizer = new wxBoxSizer (wxVERTICAL);
78         _panel->SetSizer (_sizer);
79
80         _grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
81         _sizer->Add (_grid, 0, wxEXPAND | wxALL, 8);
82
83         _name_label = create_label (_panel, _("Name"), true);
84         _name = new wxTextCtrl (_panel, wxID_ANY);
85         FocusManager::instance()->add(_name);
86
87         _use_isdcf_name = new CheckBox (_panel, _("Use ISDCF name"));
88         _copy_isdcf_name_button = new Button (_panel, _("Copy as name"));
89
90         /* wxST_ELLIPSIZE_MIDDLE works around a bug in GTK2 and/or wxWidgets, see
91            http://trac.wxwidgets.org/ticket/12539
92         */
93         _dcp_name = new StaticText (
94                 _panel, wxT (""), wxDefaultPosition, wxDefaultSize,
95                 wxALIGN_CENTRE_HORIZONTAL | wxST_NO_AUTORESIZE | wxST_ELLIPSIZE_MIDDLE
96                 );
97
98         _enable_audio_language = new wxCheckBox (_panel, wxID_ANY, _("Audio language"));
99         _audio_language = new wxStaticText (_panel, wxID_ANY, wxT(""));
100         _edit_audio_language = new Button (_panel, _("Edit..."));
101
102         _dcp_content_type_label = create_label (_panel, _("Content Type"), true);
103         _dcp_content_type = new wxChoice (_panel, wxID_ANY);
104
105         _encrypted = new CheckBox (_panel, _("Encrypted"));
106
107         wxClientDC dc (_panel);
108         auto size = dc.GetTextExtent (wxT ("GGGGGGGG..."));
109         size.SetHeight (-1);
110
111         _reels_label = create_label (_panel, _("Reels"), true);
112         _reel_type = new wxChoice (_panel, wxID_ANY);
113
114         _reel_length_label = create_label (_panel, _("Reel length"), true);
115         _reel_length = new SpinCtrl (_panel, DCPOMATIC_SPIN_CTRL_WIDTH);
116         _reel_length_gb_label = create_label (_panel, _("GB"), false);
117
118         _standard_label = create_label (_panel, _("Standard"), true);
119         _standard = new wxChoice (_panel, wxID_ANY);
120
121         _markers = new Button (_panel, _("Markers..."));
122         _metadata = new Button (_panel, _("Metadata..."));
123
124         _notebook = new wxNotebook (_panel, wxID_ANY);
125         _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
126
127         _notebook->AddPage (make_video_panel (), _("Video"), false);
128         _notebook->AddPage (make_audio_panel (), _("Audio"), false);
129
130         _name->Bind                  (wxEVT_TEXT,     boost::bind(&DCPPanel::name_changed, this));
131         _use_isdcf_name->Bind        (wxEVT_CHECKBOX, boost::bind(&DCPPanel::use_isdcf_name_toggled, this));
132         _copy_isdcf_name_button->Bind(wxEVT_BUTTON,   boost::bind(&DCPPanel::copy_isdcf_name_button_clicked, this));
133         _dcp_content_type->Bind      (wxEVT_CHOICE,   boost::bind(&DCPPanel::dcp_content_type_changed, this));
134         _encrypted->Bind             (wxEVT_CHECKBOX, boost::bind(&DCPPanel::encrypted_toggled, this));
135         _reel_type->Bind             (wxEVT_CHOICE,   boost::bind(&DCPPanel::reel_type_changed, this));
136         _reel_length->Bind           (wxEVT_SPINCTRL, boost::bind(&DCPPanel::reel_length_changed, this));
137         _standard->Bind              (wxEVT_CHOICE,   boost::bind(&DCPPanel::standard_changed, this));
138         _markers->Bind               (wxEVT_BUTTON,   boost::bind(&DCPPanel::markers_clicked, this));
139         _metadata->Bind              (wxEVT_BUTTON,   boost::bind(&DCPPanel::metadata_clicked, this));
140         _enable_audio_language->Bind (wxEVT_CHECKBOX, boost::bind(&DCPPanel::enable_audio_language_toggled, this));
141         _edit_audio_language->Bind   (wxEVT_BUTTON,   boost::bind(&DCPPanel::edit_audio_language_clicked, this));
142
143         for (auto i: DCPContentType::all()) {
144                 _dcp_content_type->Append (std_to_wx(i->pretty_name()));
145         }
146
147         _reel_type->Append (_("Single reel"));
148         _reel_type->Append (_("Split by video content"));
149         /// TRANSLATORS: translate the word "Custom" here; do not include the "Reel|" prefix
150         _reel_type->Append (S_("Reel|Custom"));
151
152         _reel_length->SetRange (1, 64);
153
154         _standard->Append (_("SMPTE"));
155         _standard->Append (_("Interop"));
156
157         Config::instance()->Changed.connect (boost::bind(&DCPPanel::config_changed, this, _1));
158
159         add_to_grid ();
160 }
161
162 void
163 DCPPanel::add_to_grid ()
164 {
165         int r = 0;
166
167         auto name_sizer = new wxBoxSizer (wxHORIZONTAL);
168         name_sizer->Add (_name_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
169         name_sizer->Add (_name, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
170         _grid->Add (name_sizer, wxGBPosition(r, 0), wxGBSpan(1, 2), wxRIGHT | wxEXPAND, DCPOMATIC_DIALOG_BORDER);
171         ++r;
172
173         int flags = wxALIGN_CENTER_VERTICAL;
174 #ifdef __WXOSX__
175         flags |= wxALIGN_RIGHT;
176 #endif
177
178         _grid->Add (_use_isdcf_name, wxGBPosition(r, 0), wxDefaultSpan, flags);
179         {
180                 auto s = new wxBoxSizer (wxHORIZONTAL);
181                 s->Add (_copy_isdcf_name_button, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
182                 _grid->Add (s, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxBOTTOM, DCPOMATIC_CHECKBOX_BOTTOM_PAD);
183         }
184         ++r;
185
186         _grid->Add (_dcp_name, wxGBPosition(r, 0), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL | wxEXPAND);
187         ++r;
188
189         {
190                 auto s = new wxBoxSizer (wxHORIZONTAL);
191                 s->Add (_enable_audio_language, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_SIZER_GAP);
192                 s->Add (_audio_language, 1, wxALIGN_CENTER_VERTICAL | wxBOTTOM, DCPOMATIC_CHECKBOX_BOTTOM_PAD);
193                 s->Add (_edit_audio_language, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM, DCPOMATIC_CHECKBOX_BOTTOM_PAD);
194                 _grid->Add (s, wxGBPosition(r, 0), wxGBSpan(1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL);
195         }
196         ++r;
197
198         add_label_to_sizer (_grid, _dcp_content_type_label, true, wxGBPosition(r, 0));
199         _grid->Add (_dcp_content_type, wxGBPosition(r, 1));
200         ++r;
201
202         _grid->Add (_encrypted, wxGBPosition(r, 0), wxGBSpan(1, 2));
203         ++r;
204
205         add_label_to_sizer (_grid, _reels_label, true, wxGBPosition(r, 0));
206         _grid->Add (_reel_type, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
207         ++r;
208
209         add_label_to_sizer (_grid, _reel_length_label, true, wxGBPosition(r, 0));
210         {
211                 auto s = new wxBoxSizer (wxHORIZONTAL);
212                 s->Add (_reel_length);
213                 add_label_to_sizer (s, _reel_length_gb_label, false, 0, wxLEFT | wxALIGN_CENTER_VERTICAL);
214                 _grid->Add (s, wxGBPosition(r, 1));
215         }
216         ++r;
217
218         add_label_to_sizer (_grid, _standard_label, true, wxGBPosition(r, 0));
219         _grid->Add (_standard, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
220         ++r;
221
222         auto extra = new wxBoxSizer (wxHORIZONTAL);
223         extra->Add (_markers, 1, wxRIGHT, DCPOMATIC_SIZER_X_GAP);
224         extra->Add (_metadata, 1, wxRIGHT, DCPOMATIC_SIZER_X_GAP);
225         _grid->Add (extra, wxGBPosition(r, 0), wxGBSpan(1, 2));
226         ++r;
227 }
228
229
230 void
231 DCPPanel::name_changed ()
232 {
233         if (!_film) {
234                 return;
235         }
236
237         _film->set_name (string(_name->GetValue().mb_str()));
238 }
239
240
241 void
242 DCPPanel::j2k_bandwidth_changed ()
243 {
244         if (!_film) {
245                 return;
246         }
247
248         _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
249 }
250
251
252 void
253 DCPPanel::encrypted_toggled ()
254 {
255         if (!_film) {
256                 return;
257         }
258
259         _film->set_encrypted (_encrypted->GetValue());
260 }
261
262
263 /** Called when the frame rate choice widget has been changed */
264 void
265 DCPPanel::frame_rate_choice_changed ()
266 {
267         if (!_film) {
268                 return;
269         }
270
271         _film->set_video_frame_rate (
272                 boost::lexical_cast<int>(
273                         wx_to_std(_frame_rate_choice->GetString(_frame_rate_choice->GetSelection()))
274                         ),
275                 true
276                 );
277 }
278
279
280 /** Called when the frame rate spin widget has been changed */
281 void
282 DCPPanel::frame_rate_spin_changed ()
283 {
284         if (!_film) {
285                 return;
286         }
287
288         _film->set_video_frame_rate (_frame_rate_spin->GetValue());
289 }
290
291
292 void
293 DCPPanel::audio_channels_changed ()
294 {
295         if (!_film) {
296                 return;
297         }
298
299         _film->set_audio_channels (locale_convert<int>(string_client_data(_audio_channels->GetClientObject(_audio_channels->GetSelection()))));
300 }
301
302
303 void
304 DCPPanel::resolution_changed ()
305 {
306         if (!_film) {
307                 return;
308         }
309
310         _film->set_resolution (_resolution->GetSelection() == 0 ? Resolution::TWO_K : Resolution::FOUR_K);
311 }
312
313
314 void
315 DCPPanel::standard_changed ()
316 {
317         if (!_film) {
318                 return;
319         }
320
321         _film->set_interop (_standard->GetSelection() == 1);
322
323 }
324
325 void
326 DCPPanel::markers_clicked ()
327 {
328         if (_markers_dialog) {
329                 _markers_dialog->Destroy ();
330                 _markers_dialog = nullptr;
331         }
332
333         _markers_dialog = new MarkersDialog (_panel, _film, _viewer);
334         _markers_dialog->Show();
335 }
336
337
338 void
339 DCPPanel::metadata_clicked ()
340 {
341         if (_film->interop()) {
342                 if (_interop_metadata_dialog) {
343                         _interop_metadata_dialog->Destroy ();
344                         _interop_metadata_dialog = nullptr;
345                 }
346
347                 _interop_metadata_dialog = new InteropMetadataDialog (_panel, _film);
348                 _interop_metadata_dialog->setup ();
349                 _interop_metadata_dialog->Show ();
350         } else {
351                 if (_smpte_metadata_dialog) {
352                         _smpte_metadata_dialog->Destroy ();
353                         _smpte_metadata_dialog = nullptr;
354                 }
355
356                 _smpte_metadata_dialog = new SMPTEMetadataDialog (_panel, _film);
357                 _smpte_metadata_dialog->setup ();
358                 _smpte_metadata_dialog->Show ();
359         }
360 }
361
362
363 void
364 DCPPanel::film_changed (Film::Property p)
365 {
366         switch (p) {
367         case Film::Property::NONE:
368                 break;
369         case Film::Property::CONTAINER:
370                 setup_container ();
371                 break;
372         case Film::Property::NAME:
373                 checked_set (_name, _film->name());
374                 setup_dcp_name ();
375                 break;
376         case Film::Property::DCP_CONTENT_TYPE:
377         {
378                 auto index = DCPContentType::as_index(_film->dcp_content_type());
379                 DCPOMATIC_ASSERT (index);
380                 checked_set (_dcp_content_type, *index);
381                 setup_dcp_name ();
382                 break;
383         }
384         case Film::Property::ENCRYPTED:
385                 checked_set (_encrypted, _film->encrypted ());
386                 break;
387         case Film::Property::RESOLUTION:
388                 checked_set (_resolution, _film->resolution() == Resolution::TWO_K ? 0 : 1);
389                 setup_container ();
390                 setup_dcp_name ();
391                 break;
392         case Film::Property::J2K_BANDWIDTH:
393                 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
394                 break;
395         case Film::Property::USE_ISDCF_NAME:
396         {
397                 checked_set (_use_isdcf_name, _film->use_isdcf_name());
398                 if (_film->use_isdcf_name()) {
399                         /* We are going back to using an ISDCF name.  Remove anything after a _ in the current name,
400                            in case the user has clicked 'Copy as name' then re-ticked 'Use ISDCF name' (#1513).
401                         */
402                         string const name = _film->name ();
403                         string::size_type const u = name.find("_");
404                         if (u != string::npos) {
405                                 _film->set_name (name.substr(0, u));
406                         }
407                 }
408                 setup_dcp_name ();
409                 break;
410         }
411         case Film::Property::VIDEO_FRAME_RATE:
412         {
413                 bool done = false;
414                 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
415                         if (wx_to_std(_frame_rate_choice->GetString(i)) == boost::lexical_cast<string>(_film->video_frame_rate())) {
416                                 checked_set (_frame_rate_choice, i);
417                                 done = true;
418                                 break;
419                         }
420                 }
421
422                 if (!done) {
423                         checked_set (_frame_rate_choice, -1);
424                 }
425
426                 checked_set (_frame_rate_spin, _film->video_frame_rate ());
427
428                 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
429                 setup_dcp_name ();
430                 break;
431         }
432         case Film::Property::AUDIO_CHANNELS:
433                 if (_film->audio_channels() < minimum_allowed_audio_channels()) {
434                         _film->set_audio_channels (minimum_allowed_audio_channels());
435                 } else {
436                         checked_set (_audio_channels, locale_convert<string>(max(minimum_allowed_audio_channels(), _film->audio_channels())));
437                         setup_dcp_name ();
438                 }
439                 break;
440         case Film::Property::THREE_D:
441                 checked_set (_three_d, _film->three_d());
442                 setup_dcp_name ();
443                 break;
444         case Film::Property::REENCODE_J2K:
445                 checked_set (_reencode_j2k, _film->reencode_j2k());
446                 break;
447         case Film::Property::INTEROP:
448                 checked_set (_standard, _film->interop() ? 1 : 0);
449                 setup_dcp_name ();
450                 _markers->Enable (!_film->interop());
451                 break;
452         case Film::Property::AUDIO_PROCESSOR:
453                 if (_film->audio_processor()) {
454                         checked_set (_audio_processor, _film->audio_processor()->id());
455                 } else {
456                         checked_set (_audio_processor, 0);
457                 }
458                 setup_audio_channels_choice (_audio_channels, minimum_allowed_audio_channels());
459                 film_changed (Film::Property::AUDIO_CHANNELS);
460                 break;
461         case Film::Property::REEL_TYPE:
462                 checked_set (_reel_type, static_cast<int>(_film->reel_type()));
463                 _reel_length->Enable (_film->reel_type() == ReelType::BY_LENGTH);
464                 break;
465         case Film::Property::REEL_LENGTH:
466                 checked_set (_reel_length, _film->reel_length() / 1000000000LL);
467                 break;
468         case Film::Property::CONTENT:
469                 setup_dcp_name ();
470                 setup_sensitivity ();
471                 break;
472         case Film::Property::AUDIO_LANGUAGE:
473         {
474                 auto al = _film->audio_language();
475                 checked_set (_enable_audio_language, static_cast<bool>(al));
476                 checked_set (_audio_language, al ? std_to_wx(al->to_string()) : wxT(""));
477                 setup_dcp_name ();
478                 setup_sensitivity ();
479                 break;
480         }
481         case Film::Property::CONTENT_VERSIONS:
482         case Film::Property::VERSION_NUMBER:
483         case Film::Property::RELEASE_TERRITORY:
484         case Film::Property::RATINGS:
485         case Film::Property::FACILITY:
486         case Film::Property::STUDIO:
487         case Film::Property::TEMP_VERSION:
488         case Film::Property::PRE_RELEASE:
489         case Film::Property::RED_BAND:
490         case Film::Property::TWO_D_VERSION_OF_THREE_D:
491         case Film::Property::CHAIN:
492         case Film::Property::LUMINANCE:
493                 setup_dcp_name ();
494                 break;
495         default:
496                 break;
497         }
498 }
499
500
501 void
502 DCPPanel::film_content_changed (int property)
503 {
504         if (property == AudioContentProperty::STREAMS ||
505             property == TextContentProperty::USE ||
506             property == TextContentProperty::BURN ||
507             property == TextContentProperty::LANGUAGE ||
508             property == TextContentProperty::LANGUAGE_IS_ADDITIONAL ||
509             property == VideoContentProperty::CUSTOM_RATIO ||
510             property == VideoContentProperty::CUSTOM_SIZE ||
511             property == VideoContentProperty::BURNT_SUBTITLE_LANGUAGE ||
512             property == VideoContentProperty::CROP ||
513             property == DCPContentProperty::REFERENCE_VIDEO ||
514             property == DCPContentProperty::REFERENCE_AUDIO ||
515             property == DCPContentProperty::REFERENCE_TEXT) {
516                 setup_dcp_name ();
517                 setup_sensitivity ();
518         }
519 }
520
521
522 void
523 DCPPanel::setup_container ()
524 {
525         int n = 0;
526         auto ratios = Ratio::containers ();
527         auto i = ratios.begin ();
528         while (i != ratios.end() && *i != _film->container()) {
529                 ++i;
530                 ++n;
531         }
532
533         if (i == ratios.end()) {
534                 checked_set (_container, -1);
535                 checked_set (_container_size, wxT(""));
536         } else {
537                 checked_set (_container, n);
538                 auto const size = fit_ratio_within (_film->container()->ratio(), _film->full_frame ());
539                 checked_set (_container_size, wxString::Format("%dx%d", size.width, size.height));
540         }
541
542         setup_dcp_name ();
543 }
544
545
546 /** Called when the container widget has been changed */
547 void
548 DCPPanel::container_changed ()
549 {
550         if (!_film) {
551                 return;
552         }
553
554         int const n = _container->GetSelection ();
555         if (n >= 0) {
556                 auto ratios = Ratio::containers ();
557                 DCPOMATIC_ASSERT (n < int(ratios.size()));
558                 _film->set_container (ratios[n]);
559         }
560 }
561
562
563 /** Called when the DCP content type widget has been changed */
564 void
565 DCPPanel::dcp_content_type_changed ()
566 {
567         if (!_film) {
568                 return;
569         }
570
571         int const n = _dcp_content_type->GetSelection ();
572         if (n != wxNOT_FOUND) {
573                 _film->set_dcp_content_type (DCPContentType::from_index(n));
574         }
575 }
576
577
578 void
579 DCPPanel::set_film (shared_ptr<Film> film)
580 {
581         /* We are changing film, so destroy any dialogs for the old one */
582         if (_audio_dialog) {
583                 _audio_dialog->Destroy ();
584                 _audio_dialog = nullptr;
585         }
586         if (_markers_dialog) {
587                 _markers_dialog->Destroy ();
588                 _markers_dialog = nullptr;
589         }
590         if (_interop_metadata_dialog) {
591                 _interop_metadata_dialog->Destroy ();
592                 _interop_metadata_dialog = nullptr;
593         }
594         if (_smpte_metadata_dialog) {
595                 _smpte_metadata_dialog->Destroy ();
596                 _smpte_metadata_dialog = nullptr;
597         }
598
599         _film = film;
600
601         if (!_film) {
602                 /* Really should all the film_changed below but this might be enough */
603                 checked_set (_dcp_name, wxT(""));
604                 set_general_sensitivity (false);
605                 return;
606         }
607
608         film_changed (Film::Property::NAME);
609         film_changed (Film::Property::USE_ISDCF_NAME);
610         film_changed (Film::Property::CONTENT);
611         film_changed (Film::Property::DCP_CONTENT_TYPE);
612         film_changed (Film::Property::CONTAINER);
613         film_changed (Film::Property::RESOLUTION);
614         film_changed (Film::Property::ENCRYPTED);
615         film_changed (Film::Property::J2K_BANDWIDTH);
616         film_changed (Film::Property::VIDEO_FRAME_RATE);
617         film_changed (Film::Property::AUDIO_CHANNELS);
618         film_changed (Film::Property::SEQUENCE);
619         film_changed (Film::Property::THREE_D);
620         film_changed (Film::Property::INTEROP);
621         film_changed (Film::Property::AUDIO_PROCESSOR);
622         film_changed (Film::Property::REEL_TYPE);
623         film_changed (Film::Property::REEL_LENGTH);
624         film_changed (Film::Property::REENCODE_J2K);
625         film_changed (Film::Property::AUDIO_LANGUAGE);
626
627         set_general_sensitivity(static_cast<bool>(_film));
628 }
629
630
631 void
632 DCPPanel::set_general_sensitivity (bool s)
633 {
634         _generally_sensitive = s;
635         setup_sensitivity ();
636 }
637
638
639 void
640 DCPPanel::setup_sensitivity ()
641 {
642         _name->Enable                   (_generally_sensitive);
643         _use_isdcf_name->Enable         (_generally_sensitive);
644         _dcp_content_type->Enable       (_generally_sensitive);
645         _copy_isdcf_name_button->Enable (_generally_sensitive);
646         _enable_audio_language->Enable  (_generally_sensitive);
647         _audio_language->Enable         (_enable_audio_language->GetValue());
648         _edit_audio_language->Enable    (_enable_audio_language->GetValue());
649         _encrypted->Enable              (_generally_sensitive);
650         _reel_type->Enable              (_generally_sensitive && _film && !_film->references_dcp_video() && !_film->references_dcp_audio());
651         _reel_length->Enable            (_generally_sensitive && _film && _film->reel_type() == ReelType::BY_LENGTH);
652         _markers->Enable                (_generally_sensitive && _film && !_film->interop());
653         _metadata->Enable               (_generally_sensitive);
654         _frame_rate_choice->Enable      (_generally_sensitive && _film && !_film->references_dcp_video() && !_film->contains_atmos_content());
655         _frame_rate_spin->Enable        (_generally_sensitive && _film && !_film->references_dcp_video() && !_film->contains_atmos_content());
656         _audio_channels->Enable         (_generally_sensitive && _film && !_film->references_dcp_audio() && !_film->contains_atmos_content());
657         _audio_processor->Enable        (_generally_sensitive && _film && !_film->references_dcp_audio());
658         _j2k_bandwidth->Enable          (_generally_sensitive && _film && !_film->references_dcp_video());
659         _container->Enable              (_generally_sensitive && _film && !_film->references_dcp_video());
660         _best_frame_rate->Enable (
661                 _generally_sensitive &&
662                 _film &&
663                 _film->best_video_frame_rate () != _film->video_frame_rate() &&
664                 !_film->references_dcp_video() &&
665                 !_film->contains_atmos_content()
666                 );
667         _resolution->Enable             (_generally_sensitive && _film && !_film->references_dcp_video());
668         _three_d->Enable                (_generally_sensitive && _film && !_film->references_dcp_video());
669
670         _standard->Enable (
671                 _generally_sensitive &&
672                 _film &&
673                 !_film->references_dcp_video() &&
674                 !_film->references_dcp_audio() &&
675                 !_film->contains_atmos_content()
676                 );
677
678         _reencode_j2k->Enable           (_generally_sensitive && _film);
679         _show_audio->Enable             (_generally_sensitive && _film);
680 }
681
682
683 void
684 DCPPanel::use_isdcf_name_toggled ()
685 {
686         if (!_film) {
687                 return;
688         }
689
690         _film->set_use_isdcf_name (_use_isdcf_name->GetValue());
691 }
692
693 void
694 DCPPanel::setup_dcp_name ()
695 {
696         _dcp_name->SetLabel (std_to_wx(_film->dcp_name(true)));
697         _dcp_name->SetToolTip (std_to_wx(_film->dcp_name(true)));
698 }
699
700
701 void
702 DCPPanel::best_frame_rate_clicked ()
703 {
704         if (!_film) {
705                 return;
706         }
707
708         _film->set_video_frame_rate (_film->best_video_frame_rate());
709 }
710
711
712 void
713 DCPPanel::three_d_changed ()
714 {
715         if (!_film) {
716                 return;
717         }
718
719         _film->set_three_d (_three_d->GetValue());
720 }
721
722
723 void
724 DCPPanel::reencode_j2k_changed ()
725 {
726         if (!_film) {
727                 return;
728         }
729
730         _film->set_reencode_j2k (_reencode_j2k->GetValue());
731 }
732
733
734 void
735 DCPPanel::config_changed (Config::Property p)
736 {
737         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
738         setup_frame_rate_widget ();
739
740         if (p == Config::SHOW_EXPERIMENTAL_AUDIO_PROCESSORS) {
741                 _audio_processor->Clear ();
742                 add_audio_processors ();
743                 if (_film) {
744                         film_changed (Film::Property::AUDIO_PROCESSOR);
745                 }
746         }
747 }
748
749
750 void
751 DCPPanel::setup_frame_rate_widget ()
752 {
753         if (Config::instance()->allow_any_dcp_frame_rate()) {
754                 _frame_rate_choice->Hide ();
755                 _frame_rate_spin->Show ();
756         } else {
757                 _frame_rate_choice->Show ();
758                 _frame_rate_spin->Hide ();
759         }
760 }
761
762
763 wxPanel *
764 DCPPanel::make_video_panel ()
765 {
766         auto panel = new wxPanel (_notebook);
767         auto sizer = new wxBoxSizer (wxVERTICAL);
768         _video_grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
769         sizer->Add (_video_grid, 0, wxALL, 8);
770         panel->SetSizer (sizer);
771
772         _container_label = create_label (panel, _("Container"), true);
773         _container = new wxChoice (panel, wxID_ANY);
774         _container_size = new StaticText (panel, wxT (""));
775
776         _resolution_label = create_label (panel, _("Resolution"), true);
777         _resolution = new wxChoice (panel, wxID_ANY);
778
779         _frame_rate_label = create_label (panel, _("Frame Rate"), true);
780         _frame_rate_choice = new wxChoice (panel, wxID_ANY);
781         _frame_rate_spin = new SpinCtrl (panel, DCPOMATIC_SPIN_CTRL_WIDTH);
782         setup_frame_rate_widget ();
783         _best_frame_rate = new Button (panel, _("Use best"));
784
785         _three_d = new CheckBox (panel, _("3D"));
786
787         _j2k_bandwidth_label = create_label (panel, _("JPEG2000 bandwidth\nfor newly-encoded data"), true);
788         _j2k_bandwidth = new SpinCtrl (panel, DCPOMATIC_SPIN_CTRL_WIDTH);
789         _mbits_label = create_label (panel, _("Mbit/s"), false);
790
791         _reencode_j2k = new CheckBox (panel, _("Re-encode JPEG2000 data from input"));
792
793         _container->Bind         (wxEVT_CHOICE,   boost::bind(&DCPPanel::container_changed, this));
794         _frame_rate_choice->Bind (wxEVT_CHOICE,   boost::bind(&DCPPanel::frame_rate_choice_changed, this));
795         _frame_rate_spin->Bind   (wxEVT_SPINCTRL, boost::bind(&DCPPanel::frame_rate_spin_changed, this));
796         _best_frame_rate->Bind   (wxEVT_BUTTON,   boost::bind(&DCPPanel::best_frame_rate_clicked, this));
797         _j2k_bandwidth->Bind     (wxEVT_SPINCTRL, boost::bind(&DCPPanel::j2k_bandwidth_changed, this));
798         /* Also listen to wxEVT_TEXT so that typing numbers directly in is always noticed */
799         _j2k_bandwidth->Bind     (wxEVT_TEXT,     boost::bind(&DCPPanel::j2k_bandwidth_changed, this));
800         _resolution->Bind        (wxEVT_CHOICE,   boost::bind(&DCPPanel::resolution_changed, this));
801         _three_d->Bind           (wxEVT_CHECKBOX, boost::bind(&DCPPanel::three_d_changed, this));
802         _reencode_j2k->Bind      (wxEVT_CHECKBOX, boost::bind(&DCPPanel::reencode_j2k_changed, this));
803
804         for (auto i: Ratio::containers()) {
805                 _container->Append (std_to_wx(i->container_nickname()));
806         }
807
808         for (auto i: Config::instance()->allowed_dcp_frame_rates()) {
809                 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (i)));
810         }
811
812         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
813         _frame_rate_spin->SetRange (1, 480);
814
815         _resolution->Append (_("2K"));
816         _resolution->Append (_("4K"));
817
818         add_video_panel_to_grid ();
819
820         return panel;
821 }
822
823
824 void
825 DCPPanel::add_video_panel_to_grid ()
826 {
827         int r = 0;
828
829         add_label_to_sizer (_video_grid, _container_label, true, wxGBPosition (r, 0));
830         {
831                 auto s = new wxBoxSizer (wxHORIZONTAL);
832                 s->Add (_container, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
833                 s->Add (_container_size, 1, wxLEFT | wxALIGN_CENTER_VERTICAL);
834                 _video_grid->Add (s, wxGBPosition(r, 1));
835                 ++r;
836         }
837
838         add_label_to_sizer (_video_grid, _resolution_label, true, wxGBPosition (r, 0));
839         _video_grid->Add (_resolution, wxGBPosition (r, 1));
840         ++r;
841
842         add_label_to_sizer (_video_grid, _frame_rate_label, true, wxGBPosition (r, 0));
843         {
844                 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
845                 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
846                 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
847                 _frame_rate_sizer->Add (_best_frame_rate, 1, wxLEFT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
848                 _video_grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
849                 ++r;
850         }
851
852         _video_grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
853         ++r;
854
855         add_label_to_sizer (_video_grid, _j2k_bandwidth_label, true, wxGBPosition (r, 0));
856         auto s = new wxBoxSizer (wxHORIZONTAL);
857         s->Add (_j2k_bandwidth, 0, wxALIGN_CENTER_VERTICAL);
858         add_label_to_sizer (s, _mbits_label, false, 0, wxLEFT | wxALIGN_CENTER_VERTICAL);
859         _video_grid->Add (s, wxGBPosition(r, 1), wxDefaultSpan);
860         ++r;
861         _video_grid->Add (_reencode_j2k, wxGBPosition(r, 0), wxGBSpan(1, 2));
862 }
863
864
865 int
866 DCPPanel::minimum_allowed_audio_channels () const
867 {
868         int min = 2;
869         if (_film && _film->audio_processor ()) {
870                 min = _film->audio_processor()->out_channels ();
871         }
872
873         if (min % 2 == 1) {
874                 ++min;
875         }
876
877         return min;
878 }
879
880
881 wxPanel *
882 DCPPanel::make_audio_panel ()
883 {
884         auto panel = new wxPanel (_notebook);
885         _audio_panel_sizer = new wxBoxSizer (wxVERTICAL);
886         _audio_grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
887         _audio_panel_sizer->Add (_audio_grid, 0, wxALL, 8);
888         panel->SetSizer (_audio_panel_sizer);
889
890         _channels_label = create_label (panel, _("Channels"), true);
891         _audio_channels = new wxChoice (panel, wxID_ANY);
892         setup_audio_channels_choice (_audio_channels, minimum_allowed_audio_channels ());
893
894         _processor_label = create_label (panel, _("Processor"), true);
895         _audio_processor = new wxChoice (panel, wxID_ANY);
896         add_audio_processors ();
897
898         _show_audio = new Button (panel, _("Show graph of audio levels..."));
899
900         _audio_channels->Bind (wxEVT_CHOICE, boost::bind (&DCPPanel::audio_channels_changed, this));
901         _audio_processor->Bind (wxEVT_CHOICE, boost::bind (&DCPPanel::audio_processor_changed, this));
902         _show_audio->Bind (wxEVT_BUTTON, boost::bind (&DCPPanel::show_audio_clicked, this));
903
904         add_audio_panel_to_grid ();
905
906         return panel;
907 }
908
909
910 void
911 DCPPanel::add_audio_panel_to_grid ()
912 {
913         int r = 0;
914
915         add_label_to_sizer (_audio_grid, _channels_label, true, wxGBPosition (r, 0));
916         _audio_grid->Add (_audio_channels, wxGBPosition (r, 1));
917         ++r;
918
919         add_label_to_sizer (_audio_grid, _processor_label, true, wxGBPosition (r, 0));
920         _audio_grid->Add (_audio_processor, wxGBPosition (r, 1));
921         ++r;
922
923         _audio_grid->Add (_show_audio, wxGBPosition (r, 0), wxGBSpan (1, 2));
924         ++r;
925 }
926
927
928 void
929 DCPPanel::copy_isdcf_name_button_clicked ()
930 {
931         _film->set_name (_film->isdcf_name (true));
932         _film->set_use_isdcf_name (false);
933 }
934
935
936 void
937 DCPPanel::audio_processor_changed ()
938 {
939         if (!_film) {
940                 return;
941         }
942
943         auto const s = string_client_data (_audio_processor->GetClientObject (_audio_processor->GetSelection ()));
944         _film->set_audio_processor (AudioProcessor::from_id (s));
945 }
946
947
948 void
949 DCPPanel::show_audio_clicked ()
950 {
951         if (!_film) {
952                 return;
953         }
954
955         if (_audio_dialog) {
956                 _audio_dialog->Destroy ();
957                 _audio_dialog = nullptr;
958         }
959
960         auto d = new AudioDialog (_panel, _film, _viewer);
961         d->Show ();
962 }
963
964
965 void
966 DCPPanel::reel_type_changed ()
967 {
968         if (!_film) {
969                 return;
970         }
971
972         _film->set_reel_type (static_cast<ReelType>(_reel_type->GetSelection()));
973 }
974
975
976 void
977 DCPPanel::reel_length_changed ()
978 {
979         if (!_film) {
980                 return;
981         }
982
983         _film->set_reel_length (_reel_length->GetValue() * 1000000000LL);
984 }
985
986
987 void
988 DCPPanel::add_audio_processors ()
989 {
990         _audio_processor->Append (_("None"), new wxStringClientData(N_("none")));
991         for (auto ap: AudioProcessor::visible()) {
992                 _audio_processor->Append (std_to_wx(ap->name()), new wxStringClientData(std_to_wx(ap->id())));
993         }
994         _audio_panel_sizer->Layout();
995 }
996
997
998 void
999 DCPPanel::enable_audio_language_toggled ()
1000 {
1001         setup_sensitivity ();
1002         if (_enable_audio_language->GetValue()) {
1003                 auto al = wx_to_std (_audio_language->GetLabel());
1004                 _film->set_audio_language (al.empty() ? dcp::LanguageTag("en-US") : dcp::LanguageTag(al));
1005         } else {
1006                 _film->set_audio_language (boost::none);
1007         }
1008 }
1009
1010
1011 void
1012 DCPPanel::edit_audio_language_clicked ()
1013 {
1014        DCPOMATIC_ASSERT (_film->audio_language());
1015        auto d = new LanguageTagDialog (_panel, *_film->audio_language());
1016        d->ShowModal ();
1017        _film->set_audio_language(d->get());
1018        d->Destroy ();
1019 }
1020