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