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