Layout tweak.
[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         default:
359                 break;
360         }
361 }
362
363 void
364 DCPPanel::film_content_changed (int property)
365 {
366         if (property == FFmpegContentProperty::AUDIO_STREAMS ||
367             property == SubtitleContentProperty::USE_SUBTITLES ||
368             property == VideoContentProperty::VIDEO_SCALE) {
369                 setup_dcp_name ();
370         }
371 }
372
373
374 void
375 DCPPanel::setup_container ()
376 {
377         int n = 0;
378         vector<Ratio const *> ratios = Ratio::all ();
379         vector<Ratio const *>::iterator i = ratios.begin ();
380         while (i != ratios.end() && *i != _film->container ()) {
381                 ++i;
382                 ++n;
383         }
384         
385         if (i == ratios.end()) {
386                 checked_set (_container, -1);
387                 checked_set (_container_size, wxT (""));
388         } else {
389                 checked_set (_container, n);
390                 dcp::Size const size = fit_ratio_within (_film->container()->ratio(), _film->full_frame ());
391                 checked_set (_container_size, wxString::Format ("%dx%d", size.width, size.height));
392         }
393         
394         setup_dcp_name ();
395 }       
396
397 /** Called when the container widget has been changed */
398 void
399 DCPPanel::container_changed ()
400 {
401         if (!_film) {
402                 return;
403         }
404
405         int const n = _container->GetSelection ();
406         if (n >= 0) {
407                 vector<Ratio const *> ratios = Ratio::all ();
408                 DCPOMATIC_ASSERT (n < int (ratios.size()));
409                 _film->set_container (ratios[n]);
410         }
411 }
412
413 /** Called when the DCP content type widget has been changed */
414 void
415 DCPPanel::dcp_content_type_changed ()
416 {
417         if (!_film) {
418                 return;
419         }
420
421         int const n = _dcp_content_type->GetSelection ();
422         if (n != wxNOT_FOUND) {
423                 _film->set_dcp_content_type (DCPContentType::from_index (n));
424         }
425 }
426
427 void
428 DCPPanel::set_film (shared_ptr<Film> film)
429 {
430         _film = film;
431         
432         film_changed (Film::NAME);
433         film_changed (Film::USE_ISDCF_NAME);
434         film_changed (Film::CONTENT);
435         film_changed (Film::DCP_CONTENT_TYPE);
436         film_changed (Film::CONTAINER);
437         film_changed (Film::RESOLUTION);
438         film_changed (Film::SIGNED);
439         film_changed (Film::BURN_SUBTITLES);
440         film_changed (Film::ENCRYPTED);
441         film_changed (Film::KEY);
442         film_changed (Film::J2K_BANDWIDTH);
443         film_changed (Film::ISDCF_METADATA);
444         film_changed (Film::VIDEO_FRAME_RATE);
445         film_changed (Film::AUDIO_CHANNELS);
446         film_changed (Film::SEQUENCE_VIDEO);
447         film_changed (Film::THREE_D);
448         film_changed (Film::INTEROP);
449 }
450
451 void
452 DCPPanel::set_general_sensitivity (bool s)
453 {
454         _name->Enable (s);
455         _use_isdcf_name->Enable (s);
456         _edit_isdcf_button->Enable (s);
457         _dcp_content_type->Enable (s);
458         _copy_isdcf_name_button->Enable (s);
459
460         bool si = s;
461         if (_film && _film->encrypted ()) {
462                 si = false;
463         }
464         _burn_subtitles->Enable (s);
465         _signed->Enable (si);
466         
467         _encrypted->Enable (s);
468         _key->Enable (s && _film && _film->encrypted ());
469         _edit_key->Enable (s && _film && _film->encrypted ());
470         _frame_rate_choice->Enable (s);
471         _frame_rate_spin->Enable (s);
472         _audio_channels->Enable (s);
473         _audio_processor->Enable (s);
474         _j2k_bandwidth->Enable (s);
475         _container->Enable (s);
476         _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
477         _resolution->Enable (s);
478         _three_d->Enable (s);
479         _standard->Enable (s);
480 }
481
482 void
483 DCPPanel::use_isdcf_name_toggled ()
484 {
485         if (!_film) {
486                 return;
487         }
488
489         _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
490 }
491
492 void
493 DCPPanel::edit_isdcf_button_clicked ()
494 {
495         if (!_film) {
496                 return;
497         }
498
499         ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
500         d->ShowModal ();
501         _film->set_isdcf_metadata (d->isdcf_metadata ());
502         d->Destroy ();
503 }
504
505 void
506 DCPPanel::setup_dcp_name ()
507 {
508         _dcp_name->SetLabel (std_to_wx (_film->dcp_name (true)));
509 }
510
511 void
512 DCPPanel::best_frame_rate_clicked ()
513 {
514         if (!_film) {
515                 return;
516         }
517         
518         _film->set_video_frame_rate (_film->best_video_frame_rate ());
519 }
520
521 void
522 DCPPanel::three_d_changed ()
523 {
524         if (!_film) {
525                 return;
526         }
527
528         _film->set_three_d (_three_d->GetValue ());
529 }
530
531 void
532 DCPPanel::config_changed ()
533 {
534         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
535         setup_frame_rate_widget ();
536 }
537
538 void
539 DCPPanel::setup_frame_rate_widget ()
540 {
541         if (Config::instance()->allow_any_dcp_frame_rate ()) {
542                 _frame_rate_choice->Hide ();
543                 _frame_rate_spin->Show ();
544         } else {
545                 _frame_rate_choice->Show ();
546                 _frame_rate_spin->Hide ();
547         }
548
549         _frame_rate_sizer->Layout ();
550 }
551
552 wxPanel *
553 DCPPanel::make_video_panel ()
554 {
555         wxPanel* panel = new wxPanel (_notebook);
556         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
557         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
558         sizer->Add (grid, 0, wxALL, 8);
559         panel->SetSizer (sizer);
560
561         int r = 0;
562         
563         add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
564         {
565                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
566                 _container = new wxChoice (panel, wxID_ANY);
567                 s->Add (_container, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
568                 _container_size = new wxStaticText (panel, wxID_ANY, wxT (""));
569                 s->Add (_container_size, 1, wxLEFT | wxALIGN_CENTER_VERTICAL);
570                 grid->Add (s, wxGBPosition (r,1 ), wxDefaultSpan, wxEXPAND);
571                 ++r;
572         }
573
574         add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
575         {
576                 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
577                 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
578                 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
579                 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
580                 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
581                 setup_frame_rate_widget ();
582                 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
583                 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
584                 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
585                 ++r;
586         }
587
588         _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
589         grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
590         ++r;
591
592         _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
593         grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
594         ++r;
595
596         add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
597         _resolution = new wxChoice (panel, wxID_ANY);
598         grid->Add (_resolution, wxGBPosition (r, 1));
599         ++r;
600
601         {
602                 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
603                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
604                 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
605                 s->Add (_j2k_bandwidth, 1);
606                 add_label_to_sizer (s, panel, _("Mbit/s"), false);
607                 grid->Add (s, wxGBPosition (r, 1));
608         }
609         ++r;
610
611         _container->Bind        (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&DCPPanel::container_changed, this));
612         _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&DCPPanel::frame_rate_choice_changed, this));
613         _frame_rate_spin->Bind  (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&DCPPanel::frame_rate_spin_changed, this));
614         _best_frame_rate->Bind  (wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&DCPPanel::best_frame_rate_clicked, this));
615         _burn_subtitles->Bind   (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&DCPPanel::burn_subtitles_toggled, this));
616         _j2k_bandwidth->Bind    (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
617         /* Also listen to wxEVT_COMMAND_TEXT_UPDATED so that typing numbers directly in is always noticed */
618         _j2k_bandwidth->Bind    (wxEVT_COMMAND_TEXT_UPDATED,          boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
619         _resolution->Bind       (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&DCPPanel::resolution_changed, this));
620         _three_d->Bind          (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&DCPPanel::three_d_changed, this));
621
622         vector<Ratio const *> const ratio = Ratio::all ();
623         for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
624                 _container->Append (std_to_wx ((*i)->nickname ()));
625         }
626
627         list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
628         for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
629                 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
630         }
631
632         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
633         _frame_rate_spin->SetRange (1, 480);
634
635         _resolution->Append (_("2K"));
636         _resolution->Append (_("4K"));
637
638         return panel;
639 }
640
641 wxPanel *
642 DCPPanel::make_audio_panel ()
643 {
644         wxPanel* panel = new wxPanel (_notebook);
645         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
646         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
647         sizer->Add (grid, 0, wxALL, 8);
648         panel->SetSizer (sizer);
649
650         int r = 0;
651         
652         add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
653         _audio_channels = new wxChoice (panel, wxID_ANY);
654         for (int i = 2; i <= 12; i += 2) {
655                 _audio_channels->Append (wxString::Format ("%d", i));
656         }
657         grid->Add (_audio_channels, wxGBPosition (r, 1));
658
659         add_label_to_grid_bag_sizer (grid, panel, _("Processor"), true, wxGBPosition (r, 0));
660         _audio_processor = new wxChoice (panel, wxID_ANY);
661         _audio_processor->Append (_("None"), new wxStringClientData (N_("none")));
662         BOOST_FOREACH (AudioProcessor const * ap, AudioProcessor::all ()) {
663                 _audio_processor->Append (std_to_wx (ap->name ()), new wxStringClientData (std_to_wx (ap->id ())));
664         }
665         grid->Add (_audio_processor, wxGBPosition (r, 1));
666         
667         ++r;
668
669         _audio_channels->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_channels_changed, this));
670         _audio_processor->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_processor_changed, this));
671
672         return panel;
673 }
674
675 void
676 DCPPanel::copy_isdcf_name_button_clicked ()
677 {
678         _film->set_name (_film->isdcf_name (false));
679         _film->set_use_isdcf_name (false);
680 }
681
682 void
683 DCPPanel::audio_processor_changed ()
684 {
685         if (!_film) {
686                 return;
687         }
688
689         string const s = string_client_data (_audio_processor->GetClientObject (_audio_processor->GetSelection ()));
690         if (s != "none") {
691                 _film->set_audio_processor (AudioProcessor::from_id (s));
692         }
693 }