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