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