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