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