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