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