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