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