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 "lib/ratio.h"
25 #include "lib/config.h"
26 #include "lib/dcp_content_type.h"
29 #include "lib/ffmpeg_content.h"
30 #include "lib/audio_processor.h"
33 #include <wx/notebook.h>
34 #include <wx/gbsizer.h>
35 #include <wx/spinctrl.h>
36 #include <boost/lexical_cast.hpp>
37 #include <boost/foreach.hpp>
43 using boost::lexical_cast;
44 using boost::shared_ptr;
46 DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr<Film> f)
48 , _generally_sensitive (true)
50 _panel = new wxPanel (n);
51 _sizer = new wxBoxSizer (wxVERTICAL);
52 _panel->SetSizer (_sizer);
54 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
55 _sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
59 add_label_to_grid_bag_sizer (grid, _panel, _("Name"), true, wxGBPosition (r, 0));
60 _name = new wxTextCtrl (_panel, wxID_ANY);
61 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
64 int flags = wxALIGN_CENTER_VERTICAL;
66 flags |= wxALIGN_RIGHT;
69 _use_isdcf_name = new wxCheckBox (_panel, wxID_ANY, _("Use ISDCF name"));
70 grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
73 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
74 _edit_isdcf_button = new wxButton (_panel, wxID_ANY, _("Details..."));
75 s->Add (_edit_isdcf_button, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
76 _copy_isdcf_name_button = new wxButton (_panel, wxID_ANY, _("Copy as name"));
77 s->Add (_copy_isdcf_name_button, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_X_GAP);
78 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
82 /* wxST_ELLIPSIZE_MIDDLE works around a bug in GTK2 and/or wxWidgets, see
83 http://trac.wxwidgets.org/ticket/12539
85 _dcp_name = new wxStaticText (
86 _panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize,
87 wxALIGN_CENTRE_HORIZONTAL | wxST_NO_AUTORESIZE | wxST_ELLIPSIZE_MIDDLE
90 grid->Add (_dcp_name, wxGBPosition(r, 0), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL | wxEXPAND);
93 add_label_to_grid_bag_sizer (grid, _panel, _("Content Type"), true, wxGBPosition (r, 0));
94 _dcp_content_type = new wxChoice (_panel, wxID_ANY);
95 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
98 _notebook = new wxNotebook (_panel, wxID_ANY);
99 _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
101 _notebook->AddPage (make_video_panel (), _("Video"), false);
102 _notebook->AddPage (make_audio_panel (), _("Audio"), false);
104 _signed = new wxCheckBox (_panel, wxID_ANY, _("Signed"));
105 grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
108 _encrypted = new wxCheckBox (_panel, wxID_ANY, _("Encrypted"));
109 grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
112 wxClientDC dc (_panel);
113 wxSize size = dc.GetTextExtent (wxT ("GGGGGGGG..."));
117 add_label_to_grid_bag_sizer (grid, _panel, _("Key"), true, wxGBPosition (r, 0));
118 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
119 _key = new wxStaticText (_panel, wxID_ANY, "", wxDefaultPosition, size);
120 s->Add (_key, 1, wxALIGN_CENTER_VERTICAL);
121 _edit_key = new wxButton (_panel, wxID_ANY, _("Edit..."));
123 grid->Add (s, wxGBPosition (r, 1));
127 add_label_to_grid_bag_sizer (grid, _panel, _("Standard"), true, wxGBPosition (r, 0));
128 _standard = new wxChoice (_panel, wxID_ANY);
129 grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
132 _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::name_changed, this));
133 _use_isdcf_name->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::use_isdcf_name_toggled, this));
134 _edit_isdcf_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_isdcf_button_clicked, this));
135 _copy_isdcf_name_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::copy_isdcf_name_button_clicked, this));
136 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::dcp_content_type_changed, this));
137 _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::signed_toggled, this));
138 _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::encrypted_toggled, this));
139 _edit_key->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_key_clicked, this));
140 _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::standard_changed, this));
142 vector<DCPContentType const *> const ct = DCPContentType::all ();
143 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
144 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
147 _standard->Append (_("SMPTE"));
148 _standard->Append (_("Interop"));
150 Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this));
154 DCPPanel::edit_key_clicked ()
156 KeyDialog* d = new KeyDialog (_panel, _film->key ());
157 if (d->ShowModal () == wxID_OK) {
158 _film->set_key (d->key ());
164 DCPPanel::name_changed ()
170 _film->set_name (string (_name->GetValue().mb_str()));
174 DCPPanel::j2k_bandwidth_changed ()
180 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
184 DCPPanel::signed_toggled ()
190 _film->set_signed (_signed->GetValue ());
194 DCPPanel::burn_subtitles_toggled ()
200 _film->set_burn_subtitles (_burn_subtitles->GetValue ());
204 DCPPanel::encrypted_toggled ()
210 _film->set_encrypted (_encrypted->GetValue ());
213 /** Called when the frame rate choice widget has been changed */
215 DCPPanel::frame_rate_choice_changed ()
221 _film->set_video_frame_rate (
222 boost::lexical_cast<int> (
223 wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
228 /** Called when the frame rate spin widget has been changed */
230 DCPPanel::frame_rate_spin_changed ()
236 _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
240 DCPPanel::audio_channels_changed ()
246 _film->set_audio_channels ((_audio_channels->GetSelection () + 1) * 2);
250 DCPPanel::resolution_changed ()
256 _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
260 DCPPanel::standard_changed ()
266 _film->set_interop (_standard->GetSelection() == 1);
270 DCPPanel::film_changed (int p)
275 case Film::CONTAINER:
279 checked_set (_name, _film->name());
282 case Film::DCP_CONTENT_TYPE:
283 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
286 case Film::BURN_SUBTITLES:
287 checked_set (_burn_subtitles, _film->burn_subtitles ());
290 checked_set (_signed, _film->is_signed ());
292 case Film::ENCRYPTED:
293 checked_set (_encrypted, _film->encrypted ());
294 if (_film->encrypted ()) {
295 _film->set_signed (true);
296 _signed->Enable (false);
297 _key->Enable (_generally_sensitive);
298 _edit_key->Enable (_generally_sensitive);
300 _signed->Enable (_generally_sensitive);
301 _key->Enable (false);
302 _edit_key->Enable (false);
306 checked_set (_key, _film->key().hex().substr (0, 8) + "...");
308 case Film::RESOLUTION:
309 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
313 case Film::J2K_BANDWIDTH:
314 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
316 case Film::USE_ISDCF_NAME:
318 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
320 _edit_isdcf_button->Enable (_film->use_isdcf_name ());
323 case Film::ISDCF_METADATA:
326 case Film::VIDEO_FRAME_RATE:
329 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
330 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
331 checked_set (_frame_rate_choice, i);
338 checked_set (_frame_rate_choice, -1);
341 _frame_rate_spin->SetValue (_film->video_frame_rate ());
343 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
346 case Film::AUDIO_CHANNELS:
347 checked_set (_audio_channels, (_film->audio_channels () / 2) - 1);
351 checked_set (_three_d, _film->three_d ());
355 checked_set (_standard, _film->interop() ? 1 : 0);
364 DCPPanel::film_content_changed (int property)
366 if (property == FFmpegContentProperty::AUDIO_STREAMS ||
367 property == SubtitleContentProperty::USE_SUBTITLES ||
368 property == VideoContentProperty::VIDEO_SCALE) {
375 DCPPanel::setup_container ()
378 vector<Ratio const *> ratios = Ratio::all ();
379 vector<Ratio const *>::iterator i = ratios.begin ();
380 while (i != ratios.end() && *i != _film->container ()) {
385 if (i == ratios.end()) {
386 checked_set (_container, -1);
387 checked_set (_container_size, wxT (""));
389 checked_set (_container, n);
390 dcp::Size const size = fit_ratio_within (_film->container()->ratio(), _film->full_frame ());
391 checked_set (_container_size, wxString::Format ("%dx%d", size.width, size.height));
397 /** Called when the container widget has been changed */
399 DCPPanel::container_changed ()
405 int const n = _container->GetSelection ();
407 vector<Ratio const *> ratios = Ratio::all ();
408 DCPOMATIC_ASSERT (n < int (ratios.size()));
409 _film->set_container (ratios[n]);
413 /** Called when the DCP content type widget has been changed */
415 DCPPanel::dcp_content_type_changed ()
421 int const n = _dcp_content_type->GetSelection ();
422 if (n != wxNOT_FOUND) {
423 _film->set_dcp_content_type (DCPContentType::from_index (n));
428 DCPPanel::set_film (shared_ptr<Film> film)
432 film_changed (Film::NAME);
433 film_changed (Film::USE_ISDCF_NAME);
434 film_changed (Film::CONTENT);
435 film_changed (Film::DCP_CONTENT_TYPE);
436 film_changed (Film::CONTAINER);
437 film_changed (Film::RESOLUTION);
438 film_changed (Film::SIGNED);
439 film_changed (Film::BURN_SUBTITLES);
440 film_changed (Film::ENCRYPTED);
441 film_changed (Film::KEY);
442 film_changed (Film::J2K_BANDWIDTH);
443 film_changed (Film::ISDCF_METADATA);
444 film_changed (Film::VIDEO_FRAME_RATE);
445 film_changed (Film::AUDIO_CHANNELS);
446 film_changed (Film::SEQUENCE_VIDEO);
447 film_changed (Film::THREE_D);
448 film_changed (Film::INTEROP);
452 DCPPanel::set_general_sensitivity (bool s)
455 _use_isdcf_name->Enable (s);
456 _edit_isdcf_button->Enable (s);
457 _dcp_content_type->Enable (s);
458 _copy_isdcf_name_button->Enable (s);
461 if (_film && _film->encrypted ()) {
464 _burn_subtitles->Enable (s);
465 _signed->Enable (si);
467 _encrypted->Enable (s);
468 _key->Enable (s && _film && _film->encrypted ());
469 _edit_key->Enable (s && _film && _film->encrypted ());
470 _frame_rate_choice->Enable (s);
471 _frame_rate_spin->Enable (s);
472 _audio_channels->Enable (s);
473 _audio_processor->Enable (s);
474 _j2k_bandwidth->Enable (s);
475 _container->Enable (s);
476 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
477 _resolution->Enable (s);
478 _three_d->Enable (s);
479 _standard->Enable (s);
483 DCPPanel::use_isdcf_name_toggled ()
489 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
493 DCPPanel::edit_isdcf_button_clicked ()
499 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
501 _film->set_isdcf_metadata (d->isdcf_metadata ());
506 DCPPanel::setup_dcp_name ()
508 _dcp_name->SetLabel (std_to_wx (_film->dcp_name (true)));
512 DCPPanel::best_frame_rate_clicked ()
518 _film->set_video_frame_rate (_film->best_video_frame_rate ());
522 DCPPanel::three_d_changed ()
528 _film->set_three_d (_three_d->GetValue ());
532 DCPPanel::config_changed ()
534 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
535 setup_frame_rate_widget ();
539 DCPPanel::setup_frame_rate_widget ()
541 if (Config::instance()->allow_any_dcp_frame_rate ()) {
542 _frame_rate_choice->Hide ();
543 _frame_rate_spin->Show ();
545 _frame_rate_choice->Show ();
546 _frame_rate_spin->Hide ();
549 _frame_rate_sizer->Layout ();
553 DCPPanel::make_video_panel ()
555 wxPanel* panel = new wxPanel (_notebook);
556 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
557 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
558 sizer->Add (grid, 0, wxALL, 8);
559 panel->SetSizer (sizer);
563 add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
565 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
566 _container = new wxChoice (panel, wxID_ANY);
567 s->Add (_container, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
568 _container_size = new wxStaticText (panel, wxID_ANY, wxT (""));
569 s->Add (_container_size, 1, wxLEFT | wxALIGN_CENTER_VERTICAL);
570 grid->Add (s, wxGBPosition (r,1 ), wxDefaultSpan, wxEXPAND);
575 add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
576 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
577 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
578 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
579 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
580 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
581 setup_frame_rate_widget ();
582 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
583 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
584 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
588 _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
589 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
592 _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
593 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
596 add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
597 _resolution = new wxChoice (panel, wxID_ANY);
598 grid->Add (_resolution, wxGBPosition (r, 1));
602 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
603 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
604 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
605 s->Add (_j2k_bandwidth, 1);
606 add_label_to_sizer (s, panel, _("Mbit/s"), false);
607 grid->Add (s, wxGBPosition (r, 1));
611 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::container_changed, this));
612 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::frame_rate_choice_changed, this));
613 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::frame_rate_spin_changed, this));
614 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::best_frame_rate_clicked, this));
615 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::burn_subtitles_toggled, this));
616 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
617 /* Also listen to wxEVT_COMMAND_TEXT_UPDATED so that typing numbers directly in is always noticed */
618 _j2k_bandwidth->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
619 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::resolution_changed, this));
620 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::three_d_changed, this));
622 vector<Ratio const *> const ratio = Ratio::all ();
623 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
624 _container->Append (std_to_wx ((*i)->nickname ()));
627 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
628 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
629 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
632 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
633 _frame_rate_spin->SetRange (1, 480);
635 _resolution->Append (_("2K"));
636 _resolution->Append (_("4K"));
642 DCPPanel::make_audio_panel ()
644 wxPanel* panel = new wxPanel (_notebook);
645 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
646 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
647 sizer->Add (grid, 0, wxALL, 8);
648 panel->SetSizer (sizer);
652 add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
653 _audio_channels = new wxChoice (panel, wxID_ANY);
654 for (int i = 2; i <= 12; i += 2) {
655 _audio_channels->Append (wxString::Format ("%d", i));
657 grid->Add (_audio_channels, wxGBPosition (r, 1));
659 add_label_to_grid_bag_sizer (grid, panel, _("Processor"), true, wxGBPosition (r, 0));
660 _audio_processor = new wxChoice (panel, wxID_ANY);
661 _audio_processor->Append (_("None"), new wxStringClientData (N_("none")));
662 BOOST_FOREACH (AudioProcessor const * ap, AudioProcessor::all ()) {
663 _audio_processor->Append (std_to_wx (ap->name ()), new wxStringClientData (std_to_wx (ap->id ())));
665 grid->Add (_audio_processor, wxGBPosition (r, 1));
669 _audio_channels->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_channels_changed, this));
670 _audio_processor->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_processor_changed, this));
676 DCPPanel::copy_isdcf_name_button_clicked ()
678 _film->set_name (_film->isdcf_name (false));
679 _film->set_use_isdcf_name (false);
683 DCPPanel::audio_processor_changed ()
689 string const s = string_client_data (_audio_processor->GetClientObject (_audio_processor->GetSelection ()));
691 _film->set_audio_processor (AudioProcessor::from_id (s));