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