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