Assume burn-in when making ISDCF name unless we definitely have non-burnt subs.
[dcpomatic.git] / src / wx / dcp_panel.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "dcp_panel.h"
21 #include "wx_util.h"
22 #include "key_dialog.h"
23 #include "isdcf_metadata_dialog.h"
24 #include "audio_dialog.h"
25 #include "lib/ratio.h"
26 #include "lib/config.h"
27 #include "lib/dcp_content_type.h"
28 #include "lib/util.h"
29 #include "lib/film.h"
30 #include "lib/ffmpeg_content.h"
31 #include "lib/audio_processor.h"
32 #include "lib/dcp_content.h"
33 #include <dcp/key.h>
34 #include <dcp/raw_convert.h>
35 #include <wx/wx.h>
36 #include <wx/notebook.h>
37 #include <wx/gbsizer.h>
38 #include <wx/spinctrl.h>
39 #include <boost/lexical_cast.hpp>
40 #include <boost/foreach.hpp>
41 #include <iostream>
42
43 using std::cout;
44 using std::list;
45 using std::string;
46 using std::vector;
47 using std::pair;
48 using std::max;
49 using std::make_pair;
50 using boost::lexical_cast;
51 using boost::shared_ptr;
52
53 DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr<Film> film)
54         : _audio_dialog (0)
55         , _film (film)
56         , _generally_sensitive (true)
57 {
58         _panel = new wxPanel (n);
59         _sizer = new wxBoxSizer (wxVERTICAL);
60         _panel->SetSizer (_sizer);
61
62         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
63         _sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
64
65         int r = 0;
66
67         add_label_to_sizer (grid, _panel, _("Name"), true, wxGBPosition (r, 0));
68         _name = new wxTextCtrl (_panel, wxID_ANY);
69         grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
70         ++r;
71
72         int flags = wxALIGN_CENTER_VERTICAL;
73 #ifdef __WXOSX__
74         flags |= wxALIGN_RIGHT;
75 #endif
76
77         _use_isdcf_name = new wxCheckBox (_panel, wxID_ANY, _("Use ISDCF name"));
78         grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
79
80         {
81                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
82                 _edit_isdcf_button = new wxButton (_panel, wxID_ANY, _("Details..."));
83                 s->Add (_edit_isdcf_button, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
84                 _copy_isdcf_name_button = new wxButton (_panel, wxID_ANY, _("Copy as name"));
85                 s->Add (_copy_isdcf_name_button, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_X_GAP);
86                 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
87                 ++r;
88         }
89
90         /* wxST_ELLIPSIZE_MIDDLE works around a bug in GTK2 and/or wxWidgets, see
91            http://trac.wxwidgets.org/ticket/12539
92         */
93         _dcp_name = new wxStaticText (
94                 _panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize,
95                 wxALIGN_CENTRE_HORIZONTAL | wxST_NO_AUTORESIZE | wxST_ELLIPSIZE_MIDDLE
96                 );
97
98         grid->Add (_dcp_name, wxGBPosition(r, 0), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL | wxEXPAND);
99         ++r;
100
101         add_label_to_sizer (grid, _panel, _("Content Type"), true, wxGBPosition (r, 0));
102         _dcp_content_type = new wxChoice (_panel, wxID_ANY);
103         grid->Add (_dcp_content_type, wxGBPosition (r, 1));
104         ++r;
105
106         _notebook = new wxNotebook (_panel, wxID_ANY);
107         _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
108
109         _notebook->AddPage (make_video_panel (), _("Video"), false);
110         _notebook->AddPage (make_audio_panel (), _("Audio"), false);
111
112         _signed = new wxCheckBox (_panel, wxID_ANY, _("Signed"));
113         grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
114         ++r;
115
116         _encrypted = new wxCheckBox (_panel, wxID_ANY, _("Encrypted"));
117         grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
118         ++r;
119
120         wxClientDC dc (_panel);
121         wxSize size = dc.GetTextExtent (wxT ("GGGGGGGG..."));
122         size.SetHeight (-1);
123
124         {
125                add_label_to_sizer (grid, _panel, _("Key"), true, wxGBPosition (r, 0));
126                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
127                _key = new wxStaticText (_panel, wxID_ANY, "", wxDefaultPosition, size);
128                s->Add (_key, 1, wxALIGN_CENTER_VERTICAL);
129                _edit_key = new wxButton (_panel, wxID_ANY, _("Edit..."));
130                s->Add (_edit_key);
131                grid->Add (s, wxGBPosition (r, 1));
132                ++r;
133         }
134
135         add_label_to_sizer (grid, _panel, _("Reels"), true, wxGBPosition (r, 0));
136         _reel_type = new wxChoice (_panel, wxID_ANY);
137         grid->Add (_reel_type, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
138         ++r;
139
140         add_label_to_sizer (grid, _panel, _("Reel length"), true, wxGBPosition (r, 0));
141
142         {
143                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
144                 _reel_length = new wxSpinCtrl (_panel, wxID_ANY);
145                 s->Add (_reel_length);
146                 add_label_to_sizer (s, _panel, _("GB"), false);
147                 grid->Add (s, wxGBPosition (r, 1));
148                 ++r;
149         }
150
151         add_label_to_sizer (grid, _panel, _("Standard"), true, wxGBPosition (r, 0));
152         _standard = new wxChoice (_panel, wxID_ANY);
153         grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
154         ++r;
155
156         _upload_after_make_dcp = new wxCheckBox (_panel, wxID_ANY, _("Upload DCP to TMS after it is made"));
157         grid->Add (_upload_after_make_dcp, wxGBPosition (r, 0), wxGBSpan (1, 2));
158         ++r;
159
160         _name->Bind                  (wxEVT_COMMAND_TEXT_UPDATED,     boost::bind (&DCPPanel::name_changed, this));
161         _use_isdcf_name->Bind        (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::use_isdcf_name_toggled, this));
162         _edit_isdcf_button->Bind     (wxEVT_COMMAND_BUTTON_CLICKED,   boost::bind (&DCPPanel::edit_isdcf_button_clicked, this));
163         _copy_isdcf_name_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED,   boost::bind (&DCPPanel::copy_isdcf_name_button_clicked, this));
164         _dcp_content_type->Bind      (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&DCPPanel::dcp_content_type_changed, this));
165         _signed->Bind                (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::signed_toggled, this));
166         _encrypted->Bind             (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::encrypted_toggled, this));
167         _edit_key->Bind              (wxEVT_COMMAND_BUTTON_CLICKED,   boost::bind (&DCPPanel::edit_key_clicked, this));
168         _reel_type->Bind             (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&DCPPanel::reel_type_changed, this));
169         _reel_length->Bind           (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::reel_length_changed, this));
170         _standard->Bind              (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&DCPPanel::standard_changed, this));
171         _upload_after_make_dcp->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::upload_after_make_dcp_changed, this));
172
173         vector<DCPContentType const *> const ct = DCPContentType::all ();
174         for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
175                 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
176         }
177
178         _reel_type->Append (_("Single reel"));
179         _reel_type->Append (_("Split by video content"));
180         _reel_type->Append (_("Reel|Custom"));
181
182         _reel_length->SetRange (1, 64);
183
184         _standard->Append (_("SMPTE"));
185         _standard->Append (_("Interop"));
186
187         Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this));
188 }
189
190 void
191 DCPPanel::edit_key_clicked ()
192 {
193         KeyDialog* d = new KeyDialog (_panel, _film->key ());
194         if (d->ShowModal () == wxID_OK) {
195                 _film->set_key (d->key ());
196         }
197         d->Destroy ();
198 }
199
200 void
201 DCPPanel::name_changed ()
202 {
203         if (!_film) {
204                 return;
205         }
206
207         _film->set_name (string (_name->GetValue().mb_str()));
208 }
209
210 void
211 DCPPanel::j2k_bandwidth_changed ()
212 {
213         if (!_film) {
214                 return;
215         }
216
217         _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
218 }
219
220 void
221 DCPPanel::signed_toggled ()
222 {
223         if (!_film) {
224                 return;
225         }
226
227         _film->set_signed (_signed->GetValue ());
228 }
229
230 void
231 DCPPanel::encrypted_toggled ()
232 {
233         if (!_film) {
234                 return;
235         }
236
237         _film->set_encrypted (_encrypted->GetValue ());
238 }
239
240 /** Called when the frame rate choice widget has been changed */
241 void
242 DCPPanel::frame_rate_choice_changed ()
243 {
244         if (!_film) {
245                 return;
246         }
247
248         _film->set_video_frame_rate (
249                 boost::lexical_cast<int> (
250                         wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
251                         )
252                 );
253 }
254
255 /** Called when the frame rate spin widget has been changed */
256 void
257 DCPPanel::frame_rate_spin_changed ()
258 {
259         if (!_film) {
260                 return;
261         }
262
263         _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
264 }
265
266 void
267 DCPPanel::audio_channels_changed ()
268 {
269         if (!_film) {
270                 return;
271         }
272
273         _film->set_audio_channels (dcp::raw_convert<int> (string_client_data (_audio_channels->GetClientObject (_audio_channels->GetSelection ()))));
274 }
275
276 void
277 DCPPanel::resolution_changed ()
278 {
279         if (!_film) {
280                 return;
281         }
282
283         _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
284 }
285
286 void
287 DCPPanel::standard_changed ()
288 {
289         if (!_film) {
290                 return;
291         }
292
293         _film->set_interop (_standard->GetSelection() == 1);
294 }
295
296 void
297 DCPPanel::upload_after_make_dcp_changed ()
298 {
299         if (!_film) {
300                 return;
301         }
302
303         _film->set_upload_after_make_dcp (_upload_after_make_dcp->GetValue ());
304 }
305
306 void
307 DCPPanel::film_changed (int p)
308 {
309         switch (p) {
310         case Film::NONE:
311                 break;
312         case Film::CONTAINER:
313                 setup_container ();
314                 break;
315         case Film::NAME:
316                 checked_set (_name, _film->name());
317                 setup_dcp_name ();
318                 break;
319         case Film::DCP_CONTENT_TYPE:
320                 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
321                 setup_dcp_name ();
322                 break;
323         case Film::SIGNED:
324                 checked_set (_signed, _film->is_signed ());
325                 break;
326         case Film::ENCRYPTED:
327                 checked_set (_encrypted, _film->encrypted ());
328                 if (_film->encrypted ()) {
329                         _film->set_signed (true);
330                         _signed->Enable (false);
331                         _key->Enable (_generally_sensitive);
332                         _edit_key->Enable (_generally_sensitive);
333                 } else {
334                         _signed->Enable (_generally_sensitive);
335                         _key->Enable (false);
336                         _edit_key->Enable (false);
337                 }
338                 break;
339         case Film::KEY:
340                 checked_set (_key, _film->key().hex().substr (0, 8) + "...");
341                 break;
342         case Film::RESOLUTION:
343                 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
344                 setup_container ();
345                 setup_dcp_name ();
346                 break;
347         case Film::J2K_BANDWIDTH:
348                 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
349                 break;
350         case Film::USE_ISDCF_NAME:
351         {
352                 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
353                 setup_dcp_name ();
354                 _edit_isdcf_button->Enable (_film->use_isdcf_name ());
355                 break;
356         }
357         case Film::ISDCF_METADATA:
358                 setup_dcp_name ();
359                 break;
360         case Film::VIDEO_FRAME_RATE:
361         {
362                 bool done = false;
363                 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
364                         if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
365                                 checked_set (_frame_rate_choice, i);
366                                 done = true;
367                                 break;
368                         }
369                 }
370
371                 if (!done) {
372                         checked_set (_frame_rate_choice, -1);
373                 }
374
375                 checked_set (_frame_rate_spin, _film->video_frame_rate ());
376
377                 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
378                 break;
379         }
380         case Film::AUDIO_CHANNELS:
381                 if (_film->audio_channels () < minimum_allowed_audio_channels ()) {
382                         _film->set_audio_channels (minimum_allowed_audio_channels ());
383                 } else {
384                         checked_set (_audio_channels, dcp::raw_convert<string> (max (minimum_allowed_audio_channels(), _film->audio_channels ())));
385                         setup_dcp_name ();
386                 }
387                 break;
388         case Film::THREE_D:
389                 checked_set (_three_d, _film->three_d ());
390                 setup_dcp_name ();
391                 break;
392         case Film::INTEROP:
393                 checked_set (_standard, _film->interop() ? 1 : 0);
394                 setup_dcp_name ();
395                 break;
396         case Film::AUDIO_PROCESSOR:
397                 if (_film->audio_processor ()) {
398                         checked_set (_audio_processor, _film->audio_processor()->id());
399                 } else {
400                         checked_set (_audio_processor, 0);
401                 }
402                 setup_audio_channels_choice ();
403                 film_changed (Film::AUDIO_CHANNELS);
404                 break;
405         case Film::REEL_TYPE:
406                 checked_set (_reel_type, _film->reel_type ());
407                 _reel_length->Enable (_film->reel_type() == REELTYPE_BY_LENGTH);
408                 break;
409         case Film::REEL_LENGTH:
410                 checked_set (_reel_length, _film->reel_length() / 1000000000LL);
411                 break;
412         case Film::UPLOAD_AFTER_MAKE_DCP:
413                 checked_set (_upload_after_make_dcp, _film->upload_after_make_dcp ());
414                 break;
415         case Film::CONTENT:
416                 setup_dcp_name ();
417                 break;
418         default:
419                 break;
420         }
421 }
422
423 void
424 DCPPanel::film_content_changed (int property)
425 {
426         if (property == AudioContentProperty::AUDIO_STREAMS ||
427             property == SubtitleContentProperty::USE_SUBTITLES ||
428             property == SubtitleContentProperty::BURN_SUBTITLES ||
429             property == VideoContentProperty::VIDEO_SCALE ||
430             property == DCPContentProperty::REFERENCE_VIDEO ||
431             property == DCPContentProperty::REFERENCE_AUDIO ||
432             property == DCPContentProperty::REFERENCE_SUBTITLE) {
433                 setup_dcp_name ();
434         }
435 }
436
437
438 void
439 DCPPanel::setup_container ()
440 {
441         int n = 0;
442         vector<Ratio const *> ratios = Ratio::all ();
443         vector<Ratio const *>::iterator i = ratios.begin ();
444         while (i != ratios.end() && *i != _film->container ()) {
445                 ++i;
446                 ++n;
447         }
448
449         if (i == ratios.end()) {
450                 checked_set (_container, -1);
451                 checked_set (_container_size, wxT (""));
452         } else {
453                 checked_set (_container, n);
454                 dcp::Size const size = fit_ratio_within (_film->container()->ratio(), _film->full_frame ());
455                 checked_set (_container_size, wxString::Format ("%dx%d", size.width, size.height));
456         }
457
458         setup_dcp_name ();
459 }
460
461 /** Called when the container widget has been changed */
462 void
463 DCPPanel::container_changed ()
464 {
465         if (!_film) {
466                 return;
467         }
468
469         int const n = _container->GetSelection ();
470         if (n >= 0) {
471                 vector<Ratio const *> ratios = Ratio::all ();
472                 DCPOMATIC_ASSERT (n < int (ratios.size()));
473                 _film->set_container (ratios[n]);
474         }
475 }
476
477 /** Called when the DCP content type widget has been changed */
478 void
479 DCPPanel::dcp_content_type_changed ()
480 {
481         if (!_film) {
482                 return;
483         }
484
485         int const n = _dcp_content_type->GetSelection ();
486         if (n != wxNOT_FOUND) {
487                 _film->set_dcp_content_type (DCPContentType::from_index (n));
488         }
489 }
490
491 void
492 DCPPanel::set_film (shared_ptr<Film> film)
493 {
494         _film = film;
495
496         film_changed (Film::NAME);
497         film_changed (Film::USE_ISDCF_NAME);
498         film_changed (Film::CONTENT);
499         film_changed (Film::DCP_CONTENT_TYPE);
500         film_changed (Film::CONTAINER);
501         film_changed (Film::RESOLUTION);
502         film_changed (Film::SIGNED);
503         film_changed (Film::ENCRYPTED);
504         film_changed (Film::KEY);
505         film_changed (Film::J2K_BANDWIDTH);
506         film_changed (Film::ISDCF_METADATA);
507         film_changed (Film::VIDEO_FRAME_RATE);
508         film_changed (Film::AUDIO_CHANNELS);
509         film_changed (Film::SEQUENCE);
510         film_changed (Film::THREE_D);
511         film_changed (Film::INTEROP);
512         film_changed (Film::AUDIO_PROCESSOR);
513         film_changed (Film::REEL_TYPE);
514         film_changed (Film::REEL_LENGTH);
515         film_changed (Film::UPLOAD_AFTER_MAKE_DCP);
516 }
517
518 void
519 DCPPanel::set_general_sensitivity (bool s)
520 {
521         _name->Enable (s);
522         _use_isdcf_name->Enable (s);
523         _edit_isdcf_button->Enable (s);
524         _dcp_content_type->Enable (s);
525         _copy_isdcf_name_button->Enable (s);
526
527         bool si = s;
528         if (_film && _film->encrypted ()) {
529                 si = false;
530         }
531         _signed->Enable (si);
532
533         _encrypted->Enable (s);
534         _key->Enable (s && _film && _film->encrypted ());
535         _edit_key->Enable (s && _film && _film->encrypted ());
536         _reel_type->Enable (s);
537         _reel_length->Enable (s && _film && _film->reel_type() == REELTYPE_BY_LENGTH);
538         _upload_after_make_dcp->Enable (s);
539         _frame_rate_choice->Enable (s);
540         _frame_rate_spin->Enable (s);
541         _audio_channels->Enable (s);
542         _audio_processor->Enable (s);
543         _j2k_bandwidth->Enable (s);
544         _container->Enable (s);
545         _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
546         _resolution->Enable (s);
547         _three_d->Enable (s);
548         _standard->Enable (s);
549 }
550
551 void
552 DCPPanel::use_isdcf_name_toggled ()
553 {
554         if (!_film) {
555                 return;
556         }
557
558         _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
559 }
560
561 void
562 DCPPanel::edit_isdcf_button_clicked ()
563 {
564         if (!_film) {
565                 return;
566         }
567
568         ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata (), _film->three_d ());
569         d->ShowModal ();
570         _film->set_isdcf_metadata (d->isdcf_metadata ());
571         d->Destroy ();
572 }
573
574 void
575 DCPPanel::setup_dcp_name ()
576 {
577         _dcp_name->SetLabel (std_to_wx (_film->dcp_name (true)));
578 }
579
580 void
581 DCPPanel::best_frame_rate_clicked ()
582 {
583         if (!_film) {
584                 return;
585         }
586
587         _film->set_video_frame_rate (_film->best_video_frame_rate ());
588 }
589
590 void
591 DCPPanel::three_d_changed ()
592 {
593         if (!_film) {
594                 return;
595         }
596
597         _film->set_three_d (_three_d->GetValue ());
598 }
599
600 void
601 DCPPanel::config_changed ()
602 {
603         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
604         setup_frame_rate_widget ();
605 }
606
607 void
608 DCPPanel::setup_frame_rate_widget ()
609 {
610         if (Config::instance()->allow_any_dcp_frame_rate ()) {
611                 _frame_rate_choice->Hide ();
612                 _frame_rate_spin->Show ();
613         } else {
614                 _frame_rate_choice->Show ();
615                 _frame_rate_spin->Hide ();
616         }
617
618         _frame_rate_sizer->Layout ();
619 }
620
621 wxPanel *
622 DCPPanel::make_video_panel ()
623 {
624         wxPanel* panel = new wxPanel (_notebook);
625         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
626         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
627         sizer->Add (grid, 0, wxALL, 8);
628         panel->SetSizer (sizer);
629
630         int r = 0;
631
632         add_label_to_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
633         {
634                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
635                 _container = new wxChoice (panel, wxID_ANY);
636                 s->Add (_container, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
637                 _container_size = new wxStaticText (panel, wxID_ANY, wxT (""));
638                 s->Add (_container_size, 1, wxLEFT | wxALIGN_CENTER_VERTICAL);
639                 grid->Add (s, wxGBPosition (r,1 ), wxDefaultSpan, wxEXPAND);
640                 ++r;
641         }
642
643         add_label_to_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
644         {
645                 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
646                 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
647                 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
648                 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
649                 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
650                 setup_frame_rate_widget ();
651                 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
652                 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
653                 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
654                 ++r;
655         }
656
657         _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
658         grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
659         ++r;
660
661         add_label_to_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
662         _resolution = new wxChoice (panel, wxID_ANY);
663         grid->Add (_resolution, wxGBPosition (r, 1));
664         ++r;
665
666         {
667                 add_label_to_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
668                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
669                 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
670                 s->Add (_j2k_bandwidth, 1);
671                 add_label_to_sizer (s, panel, _("Mbit/s"), false);
672                 grid->Add (s, wxGBPosition (r, 1));
673         }
674         ++r;
675
676         _container->Bind        (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&DCPPanel::container_changed, this));
677         _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&DCPPanel::frame_rate_choice_changed, this));
678         _frame_rate_spin->Bind  (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&DCPPanel::frame_rate_spin_changed, this));
679         _best_frame_rate->Bind  (wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&DCPPanel::best_frame_rate_clicked, this));
680         _j2k_bandwidth->Bind    (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
681         /* Also listen to wxEVT_COMMAND_TEXT_UPDATED so that typing numbers directly in is always noticed */
682         _j2k_bandwidth->Bind    (wxEVT_COMMAND_TEXT_UPDATED,          boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
683         _resolution->Bind       (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&DCPPanel::resolution_changed, this));
684         _three_d->Bind          (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&DCPPanel::three_d_changed, this));
685
686         vector<Ratio const *> const ratio = Ratio::all ();
687         for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
688                 _container->Append (std_to_wx ((*i)->nickname ()));
689         }
690
691         list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
692         for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
693                 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
694         }
695
696         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
697         _frame_rate_spin->SetRange (1, 480);
698
699         _resolution->Append (_("2K"));
700         _resolution->Append (_("4K"));
701
702         return panel;
703 }
704
705 int
706 DCPPanel::minimum_allowed_audio_channels () const
707 {
708         int min = 2;
709         if (_film && _film->audio_processor ()) {
710                 min = _film->audio_processor()->out_channels ();
711         }
712
713         if (min % 2 == 1) {
714                 ++min;
715         }
716
717         return min;
718 }
719
720 void
721 DCPPanel::setup_audio_channels_choice ()
722 {
723         vector<pair<string, string> > items;
724         for (int i = minimum_allowed_audio_channels(); i <= 16; i += 2) {
725                 items.push_back (make_pair (dcp::raw_convert<string> (i), dcp::raw_convert<string> (i)));
726         }
727
728         checked_set (_audio_channels, items);
729 }
730
731 wxPanel *
732 DCPPanel::make_audio_panel ()
733 {
734         wxPanel* panel = new wxPanel (_notebook);
735         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
736         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
737         sizer->Add (grid, 0, wxALL, 8);
738         panel->SetSizer (sizer);
739
740         int r = 0;
741
742         add_label_to_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
743         _audio_channels = new wxChoice (panel, wxID_ANY);
744         setup_audio_channels_choice ();
745         grid->Add (_audio_channels, wxGBPosition (r, 1));
746         ++r;
747
748         add_label_to_sizer (grid, panel, _("Processor"), true, wxGBPosition (r, 0));
749         _audio_processor = new wxChoice (panel, wxID_ANY);
750         _audio_processor->Append (_("None"), new wxStringClientData (N_("none")));
751         BOOST_FOREACH (AudioProcessor const * ap, AudioProcessor::all ()) {
752                 _audio_processor->Append (std_to_wx (ap->name ()), new wxStringClientData (std_to_wx (ap->id ())));
753         }
754         grid->Add (_audio_processor, wxGBPosition (r, 1));
755         ++r;
756
757         _show_audio = new wxButton (panel, wxID_ANY, _("Show audio..."));
758         grid->Add (_show_audio, wxGBPosition (r, 0), wxGBSpan (1, 2));
759         ++r;
760
761         _audio_channels->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_channels_changed, this));
762         _audio_processor->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_processor_changed, this));
763         _show_audio->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::show_audio_clicked, this));
764
765         return panel;
766 }
767
768 void
769 DCPPanel::copy_isdcf_name_button_clicked ()
770 {
771         _film->set_name (_film->isdcf_name (false));
772         _film->set_use_isdcf_name (false);
773 }
774
775 void
776 DCPPanel::audio_processor_changed ()
777 {
778         if (!_film) {
779                 return;
780         }
781
782         string const s = string_client_data (_audio_processor->GetClientObject (_audio_processor->GetSelection ()));
783         _film->set_audio_processor (AudioProcessor::from_id (s));
784 }
785
786 void
787 DCPPanel::show_audio_clicked ()
788 {
789         if (!_film) {
790                 return;
791         }
792
793         if (_audio_dialog) {
794                 _audio_dialog->Destroy ();
795                 _audio_dialog = 0;
796         }
797
798         AudioDialog* d = new AudioDialog (_panel, _film);
799         d->Show ();
800 }
801
802 void
803 DCPPanel::reel_type_changed ()
804 {
805         if (!_film) {
806                 return;
807         }
808
809         _film->set_reel_type (static_cast<ReelType> (_reel_type->GetSelection ()));
810 }
811
812 void
813 DCPPanel::reel_length_changed ()
814 {
815         if (!_film) {
816                 return;
817         }
818
819         _film->set_reel_length (_reel_length->GetValue() * 1000000000LL);
820 }