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