2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "dcp_panel.h"
22 #include "key_dialog.h"
23 #include "isdcf_metadata_dialog.h"
24 #include "audio_dialog.h"
25 #include "lib/ratio.h"
26 #include "lib/config.h"
27 #include "lib/dcp_content_type.h"
30 #include "lib/ffmpeg_content.h"
31 #include "lib/audio_processor.h"
34 #include <wx/notebook.h>
35 #include <wx/gbsizer.h>
36 #include <wx/spinctrl.h>
37 #include <boost/lexical_cast.hpp>
38 #include <boost/foreach.hpp>
44 using boost::lexical_cast;
45 using boost::shared_ptr;
47 DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr<Film> f)
50 , _generally_sensitive (true)
52 _panel = new wxPanel (n);
53 _sizer = new wxBoxSizer (wxVERTICAL);
54 _panel->SetSizer (_sizer);
56 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
57 _sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
61 add_label_to_grid_bag_sizer (grid, _panel, _("Name"), true, wxGBPosition (r, 0));
62 _name = new wxTextCtrl (_panel, wxID_ANY);
63 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
66 int flags = wxALIGN_CENTER_VERTICAL;
68 flags |= wxALIGN_RIGHT;
71 _use_isdcf_name = new wxCheckBox (_panel, wxID_ANY, _("Use ISDCF name"));
72 grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
75 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
76 _edit_isdcf_button = new wxButton (_panel, wxID_ANY, _("Details..."));
77 s->Add (_edit_isdcf_button, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
78 _copy_isdcf_name_button = new wxButton (_panel, wxID_ANY, _("Copy as name"));
79 s->Add (_copy_isdcf_name_button, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_X_GAP);
80 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
84 /* wxST_ELLIPSIZE_MIDDLE works around a bug in GTK2 and/or wxWidgets, see
85 http://trac.wxwidgets.org/ticket/12539
87 _dcp_name = new wxStaticText (
88 _panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize,
89 wxALIGN_CENTRE_HORIZONTAL | wxST_NO_AUTORESIZE | wxST_ELLIPSIZE_MIDDLE
92 grid->Add (_dcp_name, wxGBPosition(r, 0), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL | wxEXPAND);
95 add_label_to_grid_bag_sizer (grid, _panel, _("Content Type"), true, wxGBPosition (r, 0));
96 _dcp_content_type = new wxChoice (_panel, wxID_ANY);
97 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
100 _notebook = new wxNotebook (_panel, wxID_ANY);
101 _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
103 _notebook->AddPage (make_video_panel (), _("Video"), false);
104 _notebook->AddPage (make_audio_panel (), _("Audio"), false);
106 _signed = new wxCheckBox (_panel, wxID_ANY, _("Signed"));
107 grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
110 _encrypted = new wxCheckBox (_panel, wxID_ANY, _("Encrypted"));
111 grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
114 wxClientDC dc (_panel);
115 wxSize size = dc.GetTextExtent (wxT ("GGGGGGGG..."));
119 add_label_to_grid_bag_sizer (grid, _panel, _("Key"), true, wxGBPosition (r, 0));
120 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
121 _key = new wxStaticText (_panel, wxID_ANY, "", wxDefaultPosition, size);
122 s->Add (_key, 1, wxALIGN_CENTER_VERTICAL);
123 _edit_key = new wxButton (_panel, wxID_ANY, _("Edit..."));
125 grid->Add (s, wxGBPosition (r, 1));
129 add_label_to_grid_bag_sizer (grid, _panel, _("Standard"), true, wxGBPosition (r, 0));
130 _standard = new wxChoice (_panel, wxID_ANY);
131 grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
134 _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::name_changed, this));
135 _use_isdcf_name->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::use_isdcf_name_toggled, this));
136 _edit_isdcf_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_isdcf_button_clicked, this));
137 _copy_isdcf_name_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::copy_isdcf_name_button_clicked, this));
138 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::dcp_content_type_changed, this));
139 _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::signed_toggled, this));
140 _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::encrypted_toggled, this));
141 _edit_key->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_key_clicked, this));
142 _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::standard_changed, this));
144 vector<DCPContentType const *> const ct = DCPContentType::all ();
145 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
146 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
149 _standard->Append (_("SMPTE"));
150 _standard->Append (_("Interop"));
152 Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this));
156 DCPPanel::edit_key_clicked ()
158 KeyDialog* d = new KeyDialog (_panel, _film->key ());
159 if (d->ShowModal () == wxID_OK) {
160 _film->set_key (d->key ());
166 DCPPanel::name_changed ()
172 _film->set_name (string (_name->GetValue().mb_str()));
176 DCPPanel::j2k_bandwidth_changed ()
182 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
186 DCPPanel::signed_toggled ()
192 _film->set_signed (_signed->GetValue ());
196 DCPPanel::burn_subtitles_toggled ()
202 _film->set_burn_subtitles (_burn_subtitles->GetValue ());
206 DCPPanel::encrypted_toggled ()
212 _film->set_encrypted (_encrypted->GetValue ());
215 /** Called when the frame rate choice widget has been changed */
217 DCPPanel::frame_rate_choice_changed ()
223 _film->set_video_frame_rate (
224 boost::lexical_cast<int> (
225 wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
230 /** Called when the frame rate spin widget has been changed */
232 DCPPanel::frame_rate_spin_changed ()
238 _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
242 DCPPanel::audio_channels_changed ()
248 _film->set_audio_channels ((_audio_channels->GetSelection () + 1) * 2);
252 DCPPanel::resolution_changed ()
258 _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
262 DCPPanel::standard_changed ()
268 _film->set_interop (_standard->GetSelection() == 1);
272 DCPPanel::film_changed (int p)
277 case Film::CONTAINER:
281 checked_set (_name, _film->name());
284 case Film::DCP_CONTENT_TYPE:
285 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
288 case Film::BURN_SUBTITLES:
289 checked_set (_burn_subtitles, _film->burn_subtitles ());
292 checked_set (_signed, _film->is_signed ());
294 case Film::ENCRYPTED:
295 checked_set (_encrypted, _film->encrypted ());
296 if (_film->encrypted ()) {
297 _film->set_signed (true);
298 _signed->Enable (false);
299 _key->Enable (_generally_sensitive);
300 _edit_key->Enable (_generally_sensitive);
302 _signed->Enable (_generally_sensitive);
303 _key->Enable (false);
304 _edit_key->Enable (false);
308 checked_set (_key, _film->key().hex().substr (0, 8) + "...");
310 case Film::RESOLUTION:
311 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
315 case Film::J2K_BANDWIDTH:
316 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
318 case Film::USE_ISDCF_NAME:
320 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
322 _edit_isdcf_button->Enable (_film->use_isdcf_name ());
325 case Film::ISDCF_METADATA:
328 case Film::VIDEO_FRAME_RATE:
331 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
332 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
333 checked_set (_frame_rate_choice, i);
340 checked_set (_frame_rate_choice, -1);
343 _frame_rate_spin->SetValue (_film->video_frame_rate ());
345 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
348 case Film::AUDIO_CHANNELS:
349 checked_set (_audio_channels, (_film->audio_channels () / 2) - 1);
353 checked_set (_three_d, _film->three_d ());
357 checked_set (_standard, _film->interop() ? 1 : 0);
360 case Film::AUDIO_PROCESSOR:
361 if (_film->audio_processor ()) {
362 checked_set (_audio_processor, _film->audio_processor()->id());
364 checked_set (_audio_processor, 0);
373 DCPPanel::film_content_changed (int property)
375 if (property == AudioContentProperty::AUDIO_STREAMS ||
376 property == SubtitleContentProperty::USE_SUBTITLES ||
377 property == VideoContentProperty::VIDEO_SCALE) {
384 DCPPanel::setup_container ()
387 vector<Ratio const *> ratios = Ratio::all ();
388 vector<Ratio const *>::iterator i = ratios.begin ();
389 while (i != ratios.end() && *i != _film->container ()) {
394 if (i == ratios.end()) {
395 checked_set (_container, -1);
396 checked_set (_container_size, wxT (""));
398 checked_set (_container, n);
399 dcp::Size const size = fit_ratio_within (_film->container()->ratio(), _film->full_frame ());
400 checked_set (_container_size, wxString::Format ("%dx%d", size.width, size.height));
406 /** Called when the container widget has been changed */
408 DCPPanel::container_changed ()
414 int const n = _container->GetSelection ();
416 vector<Ratio const *> ratios = Ratio::all ();
417 DCPOMATIC_ASSERT (n < int (ratios.size()));
418 _film->set_container (ratios[n]);
422 /** Called when the DCP content type widget has been changed */
424 DCPPanel::dcp_content_type_changed ()
430 int const n = _dcp_content_type->GetSelection ();
431 if (n != wxNOT_FOUND) {
432 _film->set_dcp_content_type (DCPContentType::from_index (n));
437 DCPPanel::set_film (shared_ptr<Film> film)
441 film_changed (Film::NAME);
442 film_changed (Film::USE_ISDCF_NAME);
443 film_changed (Film::CONTENT);
444 film_changed (Film::DCP_CONTENT_TYPE);
445 film_changed (Film::CONTAINER);
446 film_changed (Film::RESOLUTION);
447 film_changed (Film::SIGNED);
448 film_changed (Film::BURN_SUBTITLES);
449 film_changed (Film::ENCRYPTED);
450 film_changed (Film::KEY);
451 film_changed (Film::J2K_BANDWIDTH);
452 film_changed (Film::ISDCF_METADATA);
453 film_changed (Film::VIDEO_FRAME_RATE);
454 film_changed (Film::AUDIO_CHANNELS);
455 film_changed (Film::SEQUENCE_VIDEO);
456 film_changed (Film::THREE_D);
457 film_changed (Film::INTEROP);
458 film_changed (Film::AUDIO_PROCESSOR);
462 DCPPanel::set_general_sensitivity (bool s)
465 _use_isdcf_name->Enable (s);
466 _edit_isdcf_button->Enable (s);
467 _dcp_content_type->Enable (s);
468 _copy_isdcf_name_button->Enable (s);
471 if (_film && _film->encrypted ()) {
474 _burn_subtitles->Enable (s);
475 _signed->Enable (si);
477 _encrypted->Enable (s);
478 _key->Enable (s && _film && _film->encrypted ());
479 _edit_key->Enable (s && _film && _film->encrypted ());
480 _frame_rate_choice->Enable (s);
481 _frame_rate_spin->Enable (s);
482 _audio_channels->Enable (s);
483 _audio_processor->Enable (s);
484 _j2k_bandwidth->Enable (s);
485 _container->Enable (s);
486 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
487 _resolution->Enable (s);
488 _three_d->Enable (s);
489 _standard->Enable (s);
493 DCPPanel::use_isdcf_name_toggled ()
499 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
503 DCPPanel::edit_isdcf_button_clicked ()
509 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
511 _film->set_isdcf_metadata (d->isdcf_metadata ());
516 DCPPanel::setup_dcp_name ()
518 _dcp_name->SetLabel (std_to_wx (_film->dcp_name (true)));
522 DCPPanel::best_frame_rate_clicked ()
528 _film->set_video_frame_rate (_film->best_video_frame_rate ());
532 DCPPanel::three_d_changed ()
538 _film->set_three_d (_three_d->GetValue ());
542 DCPPanel::config_changed ()
544 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
545 setup_frame_rate_widget ();
549 DCPPanel::setup_frame_rate_widget ()
551 if (Config::instance()->allow_any_dcp_frame_rate ()) {
552 _frame_rate_choice->Hide ();
553 _frame_rate_spin->Show ();
555 _frame_rate_choice->Show ();
556 _frame_rate_spin->Hide ();
559 _frame_rate_sizer->Layout ();
563 DCPPanel::make_video_panel ()
565 wxPanel* panel = new wxPanel (_notebook);
566 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
567 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
568 sizer->Add (grid, 0, wxALL, 8);
569 panel->SetSizer (sizer);
573 add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
575 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
576 _container = new wxChoice (panel, wxID_ANY);
577 s->Add (_container, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
578 _container_size = new wxStaticText (panel, wxID_ANY, wxT (""));
579 s->Add (_container_size, 1, wxLEFT | wxALIGN_CENTER_VERTICAL);
580 grid->Add (s, wxGBPosition (r,1 ), wxDefaultSpan, wxEXPAND);
584 add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
586 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
587 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
588 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
589 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
590 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
591 setup_frame_rate_widget ();
592 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
593 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
594 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
598 _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
599 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
602 _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
603 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
606 add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
607 _resolution = new wxChoice (panel, wxID_ANY);
608 grid->Add (_resolution, wxGBPosition (r, 1));
612 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
613 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
614 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
615 s->Add (_j2k_bandwidth, 1);
616 add_label_to_sizer (s, panel, _("Mbit/s"), false);
617 grid->Add (s, wxGBPosition (r, 1));
621 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::container_changed, this));
622 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::frame_rate_choice_changed, this));
623 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::frame_rate_spin_changed, this));
624 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::best_frame_rate_clicked, this));
625 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::burn_subtitles_toggled, this));
626 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
627 /* Also listen to wxEVT_COMMAND_TEXT_UPDATED so that typing numbers directly in is always noticed */
628 _j2k_bandwidth->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
629 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::resolution_changed, this));
630 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::three_d_changed, this));
632 vector<Ratio const *> const ratio = Ratio::all ();
633 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
634 _container->Append (std_to_wx ((*i)->nickname ()));
637 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
638 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
639 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
642 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
643 _frame_rate_spin->SetRange (1, 480);
645 _resolution->Append (_("2K"));
646 _resolution->Append (_("4K"));
652 DCPPanel::make_audio_panel ()
654 wxPanel* panel = new wxPanel (_notebook);
655 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
656 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
657 sizer->Add (grid, 0, wxALL, 8);
658 panel->SetSizer (sizer);
662 add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
663 _audio_channels = new wxChoice (panel, wxID_ANY);
664 for (int i = 2; i <= 12; i += 2) {
665 _audio_channels->Append (wxString::Format ("%d", i));
667 grid->Add (_audio_channels, wxGBPosition (r, 1));
670 add_label_to_grid_bag_sizer (grid, panel, _("Processor"), true, wxGBPosition (r, 0));
671 _audio_processor = new wxChoice (panel, wxID_ANY);
672 _audio_processor->Append (_("None"), new wxStringClientData (N_("none")));
673 BOOST_FOREACH (AudioProcessor const * ap, AudioProcessor::all ()) {
674 _audio_processor->Append (std_to_wx (ap->name ()), new wxStringClientData (std_to_wx (ap->id ())));
676 grid->Add (_audio_processor, wxGBPosition (r, 1));
679 _show_audio = new wxButton (panel, wxID_ANY, _("Show audio..."));
680 grid->Add (_show_audio, wxGBPosition (r, 0), wxGBSpan (1, 2));
683 _audio_channels->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_channels_changed, this));
684 _audio_processor->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_processor_changed, this));
685 _show_audio->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::show_audio_clicked, this));
691 DCPPanel::copy_isdcf_name_button_clicked ()
693 _film->set_name (_film->isdcf_name (false));
694 _film->set_use_isdcf_name (false);
698 DCPPanel::audio_processor_changed ()
704 string const s = string_client_data (_audio_processor->GetClientObject (_audio_processor->GetSelection ()));
705 _film->set_audio_processor (AudioProcessor::from_id (s));
709 DCPPanel::show_audio_clicked ()
716 _audio_dialog->Destroy ();
720 AudioDialog* d = new AudioDialog (_panel, _film);
722 d->set_playlist (_film->playlist ());