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