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