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