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