Rest of DCP panel.
[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
210         if (interface == Config::INTERFACE_FULL) {
211                 add_label_to_sizer (_grid, _key_label, true, wxGBPosition (r, 0));
212                 {
213                         wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
214                         s->Add (_key, 1, wxALIGN_CENTER_VERTICAL);
215                         s->Add (_edit_key);
216                         _grid->Add (s, wxGBPosition (r, 1));
217                 }
218                 ++r;
219
220                 add_label_to_sizer (_grid, _reels_label, true, wxGBPosition (r, 0));
221                 _grid->Add (_reel_type, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
222                 ++r;
223
224                 add_label_to_sizer (_grid, _reel_length_label, true, wxGBPosition (r, 0));
225                 {
226                         wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
227                         s->Add (_reel_length);
228                         add_label_to_sizer (s, _reel_length_gb_label, false);
229                         _grid->Add (s, wxGBPosition (r, 1));
230                 }
231                 ++r;
232
233                 add_label_to_sizer (_grid, _standard_label, true, wxGBPosition (r, 0));
234                 _grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
235                 ++r;
236
237                 _grid->Add (_upload_after_make_dcp, wxGBPosition (r, 0), wxGBSpan (1, 2));
238                 ++r;
239         }
240 }
241
242 void
243 DCPPanel::edit_key_clicked ()
244 {
245         KeyDialog* d = new KeyDialog (_panel, _film->key ());
246         if (d->ShowModal () == wxID_OK) {
247                 _film->set_key (d->key ());
248         }
249         d->Destroy ();
250 }
251
252 void
253 DCPPanel::name_changed ()
254 {
255         if (!_film) {
256                 return;
257         }
258
259         _film->set_name (string (_name->GetValue().mb_str()));
260 }
261
262 void
263 DCPPanel::j2k_bandwidth_changed ()
264 {
265         if (!_film) {
266                 return;
267         }
268
269         _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
270 }
271
272 void
273 DCPPanel::signed_toggled ()
274 {
275         if (!_film) {
276                 return;
277         }
278
279         _film->set_signed (_signed->GetValue ());
280 }
281
282 void
283 DCPPanel::encrypted_toggled ()
284 {
285         if (!_film) {
286                 return;
287         }
288
289         _film->set_encrypted (_encrypted->GetValue ());
290 }
291
292 /** Called when the frame rate choice widget has been changed */
293 void
294 DCPPanel::frame_rate_choice_changed ()
295 {
296         if (!_film) {
297                 return;
298         }
299
300         _film->set_video_frame_rate (
301                 boost::lexical_cast<int> (
302                         wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
303                         )
304                 );
305 }
306
307 /** Called when the frame rate spin widget has been changed */
308 void
309 DCPPanel::frame_rate_spin_changed ()
310 {
311         if (!_film) {
312                 return;
313         }
314
315         _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
316 }
317
318 void
319 DCPPanel::audio_channels_changed ()
320 {
321         if (!_film) {
322                 return;
323         }
324
325         _film->set_audio_channels (locale_convert<int> (string_client_data (_audio_channels->GetClientObject (_audio_channels->GetSelection ()))));
326 }
327
328 void
329 DCPPanel::resolution_changed ()
330 {
331         if (!_film) {
332                 return;
333         }
334
335         _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
336 }
337
338 void
339 DCPPanel::standard_changed ()
340 {
341         if (!_film) {
342                 return;
343         }
344
345         _film->set_interop (_standard->GetSelection() == 1);
346 }
347
348 void
349 DCPPanel::upload_after_make_dcp_changed ()
350 {
351         if (!_film) {
352                 return;
353         }
354
355         _film->set_upload_after_make_dcp (_upload_after_make_dcp->GetValue ());
356 }
357
358 void
359 DCPPanel::film_changed (int p)
360 {
361         switch (p) {
362         case Film::NONE:
363                 break;
364         case Film::CONTAINER:
365                 setup_container ();
366                 break;
367         case Film::NAME:
368                 checked_set (_name, _film->name());
369                 setup_dcp_name ();
370                 break;
371         case Film::DCP_CONTENT_TYPE:
372                 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
373                 setup_dcp_name ();
374                 break;
375         case Film::SIGNED:
376                 checked_set (_signed, _film->is_signed ());
377                 break;
378         case Film::ENCRYPTED:
379                 checked_set (_encrypted, _film->encrypted ());
380                 if (_film->encrypted ()) {
381                         _film->set_signed (true);
382                         _signed->Enable (false);
383                         _key->Enable (_generally_sensitive);
384                         _edit_key->Enable (_generally_sensitive);
385                 } else {
386                         _signed->Enable (_generally_sensitive);
387                         _key->Enable (false);
388                         _edit_key->Enable (false);
389                 }
390                 break;
391         case Film::KEY:
392                 checked_set (_key, _film->key().hex().substr (0, 8) + "...");
393                 break;
394         case Film::RESOLUTION:
395                 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
396                 setup_container ();
397                 setup_dcp_name ();
398                 break;
399         case Film::J2K_BANDWIDTH:
400                 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
401                 break;
402         case Film::USE_ISDCF_NAME:
403         {
404                 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
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::INTEROP:
446                 checked_set (_standard, _film->interop() ? 1 : 0);
447                 setup_dcp_name ();
448                 break;
449         case Film::AUDIO_PROCESSOR:
450                 if (_film->audio_processor ()) {
451                         checked_set (_audio_processor, _film->audio_processor()->id());
452                 } else {
453                         checked_set (_audio_processor, 0);
454                 }
455                 setup_audio_channels_choice (_audio_channels, minimum_allowed_audio_channels ());
456                 film_changed (Film::AUDIO_CHANNELS);
457                 break;
458         case Film::REEL_TYPE:
459                 checked_set (_reel_type, _film->reel_type ());
460                 _reel_length->Enable (_film->reel_type() == REELTYPE_BY_LENGTH);
461                 break;
462         case Film::REEL_LENGTH:
463                 checked_set (_reel_length, _film->reel_length() / 1000000000LL);
464                 break;
465         case Film::UPLOAD_AFTER_MAKE_DCP:
466                 checked_set (_upload_after_make_dcp, _film->upload_after_make_dcp ());
467                 break;
468         case Film::CONTENT:
469                 setup_dcp_name ();
470                 break;
471         default:
472                 break;
473         }
474 }
475
476 void
477 DCPPanel::film_content_changed (int property)
478 {
479         if (property == AudioContentProperty::STREAMS ||
480             property == TextContentProperty::USE ||
481             property == TextContentProperty::BURN ||
482             property == VideoContentProperty::SCALE ||
483             property == DCPContentProperty::REFERENCE_VIDEO ||
484             property == DCPContentProperty::REFERENCE_AUDIO ||
485             property == DCPContentProperty::REFERENCE_TEXT) {
486                 setup_dcp_name ();
487                 setup_sensitivity ();
488         }
489 }
490
491
492 void
493 DCPPanel::setup_container ()
494 {
495         int n = 0;
496         vector<Ratio const *> ratios = Ratio::containers ();
497         vector<Ratio const *>::iterator i = ratios.begin ();
498         while (i != ratios.end() && *i != _film->container ()) {
499                 ++i;
500                 ++n;
501         }
502
503         if (i == ratios.end()) {
504                 checked_set (_container, -1);
505                 checked_set (_container_size, wxT (""));
506         } else {
507                 checked_set (_container, n);
508                 dcp::Size const size = fit_ratio_within (_film->container()->ratio(), _film->full_frame ());
509                 checked_set (_container_size, wxString::Format ("%dx%d", size.width, size.height));
510         }
511
512         setup_dcp_name ();
513 }
514
515 /** Called when the container widget has been changed */
516 void
517 DCPPanel::container_changed ()
518 {
519         if (!_film) {
520                 return;
521         }
522
523         int const n = _container->GetSelection ();
524         if (n >= 0) {
525                 vector<Ratio const *> ratios = Ratio::containers ();
526                 DCPOMATIC_ASSERT (n < int (ratios.size()));
527                 _film->set_container (ratios[n]);
528         }
529 }
530
531 /** Called when the DCP content type widget has been changed */
532 void
533 DCPPanel::dcp_content_type_changed ()
534 {
535         if (!_film) {
536                 return;
537         }
538
539         int const n = _dcp_content_type->GetSelection ();
540         if (n != wxNOT_FOUND) {
541                 _film->set_dcp_content_type (DCPContentType::from_index (n));
542         }
543 }
544
545 void
546 DCPPanel::set_film (shared_ptr<Film> film)
547 {
548         /* We are changing film, so destroy any audio dialog for the old one */
549         if (_audio_dialog) {
550                 _audio_dialog->Destroy ();
551                 _audio_dialog = 0;
552         }
553
554         _film = film;
555
556         film_changed (Film::NAME);
557         film_changed (Film::USE_ISDCF_NAME);
558         film_changed (Film::CONTENT);
559         film_changed (Film::DCP_CONTENT_TYPE);
560         film_changed (Film::CONTAINER);
561         film_changed (Film::RESOLUTION);
562         film_changed (Film::SIGNED);
563         film_changed (Film::ENCRYPTED);
564         film_changed (Film::KEY);
565         film_changed (Film::J2K_BANDWIDTH);
566         film_changed (Film::ISDCF_METADATA);
567         film_changed (Film::VIDEO_FRAME_RATE);
568         film_changed (Film::AUDIO_CHANNELS);
569         film_changed (Film::SEQUENCE);
570         film_changed (Film::THREE_D);
571         film_changed (Film::INTEROP);
572         film_changed (Film::AUDIO_PROCESSOR);
573         film_changed (Film::REEL_TYPE);
574         film_changed (Film::REEL_LENGTH);
575         film_changed (Film::UPLOAD_AFTER_MAKE_DCP);
576
577         set_general_sensitivity(static_cast<bool>(_film));
578 }
579
580 void
581 DCPPanel::set_general_sensitivity (bool s)
582 {
583         _generally_sensitive = s;
584         setup_sensitivity ();
585 }
586
587 void
588 DCPPanel::setup_sensitivity ()
589 {
590         _name->Enable                   (_generally_sensitive);
591         _use_isdcf_name->Enable         (_generally_sensitive);
592         _edit_isdcf_button->Enable      (_generally_sensitive);
593         _dcp_content_type->Enable       (_generally_sensitive);
594         _copy_isdcf_name_button->Enable (_generally_sensitive);
595
596         bool si = _generally_sensitive;
597         if (_film && _film->encrypted ()) {
598                 si = false;
599         }
600         _signed->Enable (si);
601
602         _encrypted->Enable              (_generally_sensitive);
603         _key->Enable                    (_generally_sensitive && _film && _film->encrypted ());
604         _edit_key->Enable               (_generally_sensitive && _film && _film->encrypted ());
605         _reel_type->Enable              (_generally_sensitive && _film && !_film->references_dcp_video() && !_film->references_dcp_audio());
606         _reel_length->Enable            (_generally_sensitive && _film && _film->reel_type() == REELTYPE_BY_LENGTH);
607         _upload_after_make_dcp->Enable  (_generally_sensitive);
608         _frame_rate_choice->Enable      (_generally_sensitive && _film && !_film->references_dcp_video());
609         _frame_rate_spin->Enable        (_generally_sensitive && _film && !_film->references_dcp_video());
610         _audio_channels->Enable         (_generally_sensitive && _film && !_film->references_dcp_audio());
611         _audio_processor->Enable        (_generally_sensitive && _film && !_film->references_dcp_audio());
612         _j2k_bandwidth->Enable          (_generally_sensitive && _film && !_film->references_dcp_video());
613         _container->Enable              (_generally_sensitive && _film && !_film->references_dcp_video());
614         _best_frame_rate->Enable        (_generally_sensitive && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
615         _resolution->Enable             (_generally_sensitive && _film && !_film->references_dcp_video());
616         _three_d->Enable                (_generally_sensitive && _film && !_film->references_dcp_video());
617         _standard->Enable               (_generally_sensitive && _film && !_film->references_dcp_video() && !_film->references_dcp_audio());
618 }
619
620 void
621 DCPPanel::use_isdcf_name_toggled ()
622 {
623         if (!_film) {
624                 return;
625         }
626
627         _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
628 }
629
630 void
631 DCPPanel::edit_isdcf_button_clicked ()
632 {
633         if (!_film) {
634                 return;
635         }
636
637         ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata (), _film->three_d ());
638         d->ShowModal ();
639         _film->set_isdcf_metadata (d->isdcf_metadata ());
640         d->Destroy ();
641 }
642
643 void
644 DCPPanel::setup_dcp_name ()
645 {
646         _dcp_name->SetLabel (std_to_wx (_film->dcp_name (true)));
647         _dcp_name->SetToolTip (std_to_wx (_film->dcp_name (true)));
648 }
649
650 void
651 DCPPanel::best_frame_rate_clicked ()
652 {
653         if (!_film) {
654                 return;
655         }
656
657         _film->set_video_frame_rate (_film->best_video_frame_rate ());
658 }
659
660 void
661 DCPPanel::three_d_changed ()
662 {
663         if (!_film) {
664                 return;
665         }
666
667         _film->set_three_d (_three_d->GetValue ());
668 }
669
670 void
671 DCPPanel::config_changed (Config::Property p)
672 {
673         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
674         setup_frame_rate_widget ();
675
676         if (p == Config::INTERFACE_COMPLEXITY) {
677                 _grid->Clear ();
678                 add_to_grid ();
679                 _sizer->Layout ();
680                 _grid->Layout ();
681
682                 _video_grid->Clear ();
683                 add_video_panel_to_grid ();
684                 _video_grid->Layout ();
685
686                 _audio_grid->Clear ();
687                 add_audio_panel_to_grid ();
688                 _audio_grid->Layout ();
689         }
690 }
691
692 void
693 DCPPanel::setup_frame_rate_widget ()
694 {
695         if (Config::instance()->allow_any_dcp_frame_rate ()) {
696                 _frame_rate_choice->Hide ();
697                 _frame_rate_spin->Show ();
698         } else {
699                 _frame_rate_choice->Show ();
700                 _frame_rate_spin->Hide ();
701         }
702
703         _frame_rate_sizer->Layout ();
704 }
705
706 wxPanel *
707 DCPPanel::make_video_panel ()
708 {
709         wxPanel* panel = new wxPanel (_notebook);
710         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
711         _video_grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
712         sizer->Add (_video_grid, 0, wxALL, 8);
713         panel->SetSizer (sizer);
714
715         int r = 0;
716
717         _container_label = create_label (panel, _("Container"), true);
718         _container = new wxChoice (panel, wxID_ANY);
719         _container_size = new wxStaticText (panel, wxID_ANY, wxT (""));
720
721         _resolution_label = create_label (panel, _("Resolution"), true);
722         _resolution = new wxChoice (panel, wxID_ANY);
723
724         _frame_rate_label = create_label (panel, _("Frame Rate"), true);
725         _frame_rate_choice = new wxChoice (panel, wxID_ANY);
726         _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
727         _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
728         _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
729         _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
730         setup_frame_rate_widget ();
731         _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
732         _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
733
734         _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
735         ++r;
736
737         _j2k_bandwidth_label = create_label (panel, _("JPEG2000 bandwidth\nfor newly-encoded data"), true);
738         _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
739         _mbits_label = create_label (panel, _("Mbit/s"), false);
740
741         _container->Bind        (wxEVT_CHOICE,        boost::bind (&DCPPanel::container_changed, this));
742         _frame_rate_choice->Bind(wxEVT_CHOICE,        boost::bind (&DCPPanel::frame_rate_choice_changed, this));
743         _frame_rate_spin->Bind  (wxEVT_SPINCTRL,      boost::bind (&DCPPanel::frame_rate_spin_changed, this));
744         _best_frame_rate->Bind  (wxEVT_BUTTON,        boost::bind (&DCPPanel::best_frame_rate_clicked, this));
745         _j2k_bandwidth->Bind    (wxEVT_SPINCTRL,      boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
746         /* Also listen to wxEVT_TEXT so that typing numbers directly in is always noticed */
747         _j2k_bandwidth->Bind    (wxEVT_TEXT,          boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
748         _resolution->Bind       (wxEVT_CHOICE,        boost::bind (&DCPPanel::resolution_changed, this));
749         _three_d->Bind          (wxEVT_CHECKBOX,      boost::bind (&DCPPanel::three_d_changed, this));
750
751         BOOST_FOREACH (Ratio const * i, Ratio::containers()) {
752                 _container->Append (std_to_wx(i->container_nickname()));
753         }
754
755         BOOST_FOREACH (int i, Config::instance()->allowed_dcp_frame_rates()) {
756                 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (i)));
757         }
758
759         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
760         _frame_rate_spin->SetRange (1, 480);
761
762         _resolution->Append (_("2K"));
763         _resolution->Append (_("4K"));
764
765         add_video_panel_to_grid ();
766
767         return panel;
768 }
769
770 void
771 DCPPanel::add_video_panel_to_grid ()
772 {
773         bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
774
775         int r = 0;
776
777         add_label_to_sizer (_video_grid, _container_label, true, wxGBPosition (r, 0));
778         {
779                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
780                 s->Add (_container, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
781                 s->Add (_container_size, 1, wxLEFT | wxALIGN_CENTER_VERTICAL);
782                 _video_grid->Add (s, wxGBPosition(r, 1));
783                 ++r;
784         }
785
786         add_label_to_sizer (_video_grid, _resolution_label, true, wxGBPosition (r, 0));
787         _video_grid->Add (_resolution, wxGBPosition (r, 1));
788         ++r;
789
790         add_label_to_sizer (_video_grid, _frame_rate_label, true, wxGBPosition (r, 0));
791         {
792                 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
793                 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
794                 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
795                 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
796                 _video_grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
797                 ++r;
798         }
799
800         _video_grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
801         ++r;
802
803         _j2k_bandwidth_label->Show (full);
804         _j2k_bandwidth->Show (full);
805         _mbits_label->Show (full);
806
807         if (full) {
808                 add_label_to_sizer (_video_grid, _j2k_bandwidth_label, true, wxGBPosition (r, 0));
809                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
810                 s->Add (_j2k_bandwidth, 1);
811                 add_label_to_sizer (s, _mbits_label, false);
812                 _video_grid->Add (s, wxGBPosition (r, 1));
813                 ++r;
814         }
815 }
816
817 int
818 DCPPanel::minimum_allowed_audio_channels () const
819 {
820         int min = 2;
821         if (_film && _film->audio_processor ()) {
822                 min = _film->audio_processor()->out_channels ();
823         }
824
825         if (min % 2 == 1) {
826                 ++min;
827         }
828
829         return min;
830 }
831
832 wxPanel *
833 DCPPanel::make_audio_panel ()
834 {
835         wxPanel* panel = new wxPanel (_notebook);
836         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
837         _audio_grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
838         sizer->Add (_audio_grid, 0, wxALL, 8);
839         panel->SetSizer (sizer);
840
841         _channels_label = create_label (panel, _("Channels"), true);
842         _audio_channels = new wxChoice (panel, wxID_ANY);
843         setup_audio_channels_choice (_audio_channels, minimum_allowed_audio_channels ());
844
845         _processor_label = create_label (panel, _("Processor"), true);
846         _audio_processor = new wxChoice (panel, wxID_ANY);
847         _audio_processor->Append (_("None"), new wxStringClientData (N_("none")));
848         BOOST_FOREACH (AudioProcessor const * ap, AudioProcessor::all ()) {
849                 _audio_processor->Append (std_to_wx (ap->name ()), new wxStringClientData (std_to_wx (ap->id ())));
850         }
851
852         _show_audio = new wxButton (panel, wxID_ANY, _("Show audio..."));
853
854         _audio_channels->Bind (wxEVT_CHOICE, boost::bind (&DCPPanel::audio_channels_changed, this));
855         _audio_processor->Bind (wxEVT_CHOICE, boost::bind (&DCPPanel::audio_processor_changed, this));
856         _show_audio->Bind (wxEVT_BUTTON, boost::bind (&DCPPanel::show_audio_clicked, this));
857
858         add_audio_panel_to_grid ();
859
860         return panel;
861 }
862
863 void
864 DCPPanel::add_audio_panel_to_grid ()
865 {
866         bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
867
868         int r = 0;
869
870         add_label_to_sizer (_audio_grid, _channels_label, true, wxGBPosition (r, 0));
871         _audio_grid->Add (_audio_channels, wxGBPosition (r, 1));
872         ++r;
873
874         _processor_label->Show (full);
875         _audio_processor->Show (full);
876
877         if (full) {
878                 add_label_to_sizer (_audio_grid, _processor_label, true, wxGBPosition (r, 0));
879                 _audio_grid->Add (_audio_processor, wxGBPosition (r, 1));
880                 ++r;
881         }
882
883         _audio_grid->Add (_show_audio, wxGBPosition (r, 0), wxGBSpan (1, 2));
884         ++r;
885 }
886
887 void
888 DCPPanel::copy_isdcf_name_button_clicked ()
889 {
890         _film->set_name (_film->isdcf_name (true));
891         _film->set_use_isdcf_name (false);
892 }
893
894 void
895 DCPPanel::audio_processor_changed ()
896 {
897         if (!_film) {
898                 return;
899         }
900
901         string const s = string_client_data (_audio_processor->GetClientObject (_audio_processor->GetSelection ()));
902         _film->set_audio_processor (AudioProcessor::from_id (s));
903 }
904
905 void
906 DCPPanel::show_audio_clicked ()
907 {
908         if (!_film) {
909                 return;
910         }
911
912         if (_audio_dialog) {
913                 _audio_dialog->Destroy ();
914                 _audio_dialog = 0;
915         }
916
917         AudioDialog* d = new AudioDialog (_panel, _film);
918         d->Show ();
919 }
920
921 void
922 DCPPanel::reel_type_changed ()
923 {
924         if (!_film) {
925                 return;
926         }
927
928         _film->set_reel_type (static_cast<ReelType> (_reel_type->GetSelection ()));
929 }
930
931 void
932 DCPPanel::reel_length_changed ()
933 {
934         if (!_film) {
935                 return;
936         }
937
938         _film->set_reel_length (_reel_length->GetValue() * 1000000000LL);
939 }