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