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