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