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