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