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"
32 #include <wx/notebook.h>
33 #include <wx/gbsizer.h>
34 #include <wx/spinctrl.h>
35 #include <boost/lexical_cast.hpp>
41 using boost::lexical_cast;
42 using boost::shared_ptr;
44 DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr<Film> f)
46 , _generally_sensitive (true)
48 _panel = new wxPanel (n);
49 _sizer = new wxBoxSizer (wxVERTICAL);
50 _panel->SetSizer (_sizer);
52 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
53 _sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
57 add_label_to_grid_bag_sizer (grid, _panel, _("Name"), true, wxGBPosition (r, 0));
58 _name = new wxTextCtrl (_panel, wxID_ANY);
59 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
62 int flags = wxALIGN_CENTER_VERTICAL;
64 flags |= wxALIGN_RIGHT;
67 _use_isdcf_name = new wxCheckBox (_panel, wxID_ANY, _("Use ISDCF name"));
68 grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
71 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
72 _edit_isdcf_button = new wxButton (_panel, wxID_ANY, _("Details..."));
73 s->Add (_edit_isdcf_button, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
74 _copy_isdcf_name_button = new wxButton (_panel, wxID_ANY, _("Copy as name"));
75 s->Add (_copy_isdcf_name_button, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_X_GAP);
76 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
80 add_label_to_grid_bag_sizer (grid, _panel, _("DCP Name"), true, wxGBPosition (r, 0));
81 _dcp_name = new wxStaticText (_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
82 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxEXPAND);
85 add_label_to_grid_bag_sizer (grid, _panel, _("Content Type"), true, wxGBPosition (r, 0));
86 _dcp_content_type = new wxChoice (_panel, wxID_ANY);
87 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
90 _notebook = new wxNotebook (_panel, wxID_ANY);
91 _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
93 _notebook->AddPage (make_video_panel (), _("Video"), false);
94 _notebook->AddPage (make_audio_panel (), _("Audio"), false);
96 _signed = new wxCheckBox (_panel, wxID_ANY, _("Signed"));
97 grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
100 _encrypted = new wxCheckBox (_panel, wxID_ANY, _("Encrypted"));
101 grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
104 wxClientDC dc (_panel);
105 wxSize size = dc.GetTextExtent (wxT ("GGGGGGGG..."));
109 add_label_to_grid_bag_sizer (grid, _panel, _("Key"), true, wxGBPosition (r, 0));
110 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
111 _key = new wxStaticText (_panel, wxID_ANY, "", wxDefaultPosition, size);
112 s->Add (_key, 1, wxALIGN_CENTER_VERTICAL);
113 _edit_key = new wxButton (_panel, wxID_ANY, _("Edit..."));
115 grid->Add (s, wxGBPosition (r, 1));
119 add_label_to_grid_bag_sizer (grid, _panel, _("Standard"), true, wxGBPosition (r, 0));
120 _standard = new wxChoice (_panel, wxID_ANY);
121 grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
124 _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::name_changed, this));
125 _use_isdcf_name->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::use_isdcf_name_toggled, this));
126 _edit_isdcf_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_isdcf_button_clicked, this));
127 _copy_isdcf_name_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::copy_isdcf_name_button_clicked, this));
128 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::dcp_content_type_changed, this));
129 _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::signed_toggled, this));
130 _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::encrypted_toggled, this));
131 _edit_key->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_key_clicked, this));
132 _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::standard_changed, this));
134 vector<DCPContentType const *> const ct = DCPContentType::all ();
135 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
136 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
139 _standard->Append (_("SMPTE"));
140 _standard->Append (_("Interop"));
142 Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this));
146 DCPPanel::edit_key_clicked ()
148 KeyDialog* d = new KeyDialog (_panel, _film->key ());
149 if (d->ShowModal () == wxID_OK) {
150 _film->set_key (d->key ());
156 DCPPanel::name_changed ()
162 _film->set_name (string (_name->GetValue().mb_str()));
166 DCPPanel::j2k_bandwidth_changed ()
172 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
176 DCPPanel::signed_toggled ()
182 _film->set_signed (_signed->GetValue ());
186 DCPPanel::burn_subtitles_toggled ()
192 _film->set_burn_subtitles (_burn_subtitles->GetValue ());
196 DCPPanel::encrypted_toggled ()
202 _film->set_encrypted (_encrypted->GetValue ());
205 /** Called when the frame rate choice widget has been changed */
207 DCPPanel::frame_rate_choice_changed ()
213 _film->set_video_frame_rate (
214 boost::lexical_cast<int> (
215 wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
220 /** Called when the frame rate spin widget has been changed */
222 DCPPanel::frame_rate_spin_changed ()
228 _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
232 DCPPanel::audio_channels_changed ()
238 _film->set_audio_channels ((_audio_channels->GetSelection () + 1) * 2);
242 DCPPanel::resolution_changed ()
248 _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
252 DCPPanel::standard_changed ()
258 _film->set_interop (_standard->GetSelection() == 1);
262 DCPPanel::film_changed (int p)
267 case Film::CONTAINER:
271 checked_set (_name, _film->name());
274 case Film::DCP_CONTENT_TYPE:
275 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
278 case Film::BURN_SUBTITLES:
279 checked_set (_burn_subtitles, _film->burn_subtitles ());
282 checked_set (_signed, _film->is_signed ());
284 case Film::ENCRYPTED:
285 checked_set (_encrypted, _film->encrypted ());
286 if (_film->encrypted ()) {
287 _film->set_signed (true);
288 _signed->Enable (false);
289 _key->Enable (_generally_sensitive);
290 _edit_key->Enable (_generally_sensitive);
292 _signed->Enable (_generally_sensitive);
293 _key->Enable (false);
294 _edit_key->Enable (false);
298 checked_set (_key, _film->key().hex().substr (0, 8) + "...");
300 case Film::RESOLUTION:
301 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
304 case Film::J2K_BANDWIDTH:
305 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
307 case Film::USE_ISDCF_NAME:
309 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
311 _edit_isdcf_button->Enable (_film->use_isdcf_name ());
314 case Film::ISDCF_METADATA:
317 case Film::VIDEO_FRAME_RATE:
320 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
321 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
322 checked_set (_frame_rate_choice, i);
329 checked_set (_frame_rate_choice, -1);
332 _frame_rate_spin->SetValue (_film->video_frame_rate ());
334 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
337 case Film::AUDIO_CHANNELS:
338 checked_set (_audio_channels, (_film->audio_channels () / 2) - 1);
342 checked_set (_three_d, _film->three_d ());
346 checked_set (_standard, _film->interop() ? 1 : 0);
354 DCPPanel::film_content_changed (int property)
356 if (property == FFmpegContentProperty::AUDIO_STREAM ||
357 property == SubtitleContentProperty::USE_SUBTITLES ||
358 property == VideoContentProperty::VIDEO_SCALE) {
365 DCPPanel::setup_container ()
368 vector<Ratio const *> ratios = Ratio::all ();
369 vector<Ratio const *>::iterator i = ratios.begin ();
370 while (i != ratios.end() && *i != _film->container ()) {
375 if (i == ratios.end()) {
376 checked_set (_container, -1);
378 checked_set (_container, n);
384 /** Called when the container widget has been changed */
386 DCPPanel::container_changed ()
392 int const n = _container->GetSelection ();
394 vector<Ratio const *> ratios = Ratio::all ();
395 DCPOMATIC_ASSERT (n < int (ratios.size()));
396 _film->set_container (ratios[n]);
400 /** Called when the DCP content type widget has been changed */
402 DCPPanel::dcp_content_type_changed ()
408 int const n = _dcp_content_type->GetSelection ();
409 if (n != wxNOT_FOUND) {
410 _film->set_dcp_content_type (DCPContentType::from_index (n));
415 DCPPanel::set_film (shared_ptr<Film> film)
419 film_changed (Film::NAME);
420 film_changed (Film::USE_ISDCF_NAME);
421 film_changed (Film::CONTENT);
422 film_changed (Film::DCP_CONTENT_TYPE);
423 film_changed (Film::CONTAINER);
424 film_changed (Film::RESOLUTION);
425 film_changed (Film::SIGNED);
426 film_changed (Film::BURN_SUBTITLES);
427 film_changed (Film::ENCRYPTED);
428 film_changed (Film::KEY);
429 film_changed (Film::J2K_BANDWIDTH);
430 film_changed (Film::ISDCF_METADATA);
431 film_changed (Film::VIDEO_FRAME_RATE);
432 film_changed (Film::AUDIO_CHANNELS);
433 film_changed (Film::SEQUENCE_VIDEO);
434 film_changed (Film::THREE_D);
435 film_changed (Film::INTEROP);
439 DCPPanel::set_general_sensitivity (bool s)
442 _use_isdcf_name->Enable (s);
443 _edit_isdcf_button->Enable (s);
444 _dcp_content_type->Enable (s);
445 _copy_isdcf_name_button->Enable (s);
448 if (_film && _film->encrypted ()) {
451 _burn_subtitles->Enable (s);
452 _signed->Enable (si);
454 _encrypted->Enable (s);
455 _key->Enable (s && _film && _film->encrypted ());
456 _edit_key->Enable (s && _film && _film->encrypted ());
457 _frame_rate_choice->Enable (s);
458 _frame_rate_spin->Enable (s);
459 _audio_channels->Enable (s);
460 _j2k_bandwidth->Enable (s);
461 _container->Enable (s);
462 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
463 _resolution->Enable (s);
464 _three_d->Enable (s);
465 _standard->Enable (s);
469 DCPPanel::use_isdcf_name_toggled ()
475 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
479 DCPPanel::edit_isdcf_button_clicked ()
485 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
487 _film->set_isdcf_metadata (d->isdcf_metadata ());
492 DCPPanel::setup_dcp_name ()
494 string s = _film->dcp_name (true);
495 if (s.length() > 28) {
496 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
497 _dcp_name->SetToolTip (std_to_wx (s));
499 _dcp_name->SetLabel (std_to_wx (s));
504 DCPPanel::best_frame_rate_clicked ()
510 _film->set_video_frame_rate (_film->best_video_frame_rate ());
514 DCPPanel::three_d_changed ()
520 _film->set_three_d (_three_d->GetValue ());
524 DCPPanel::config_changed ()
526 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
527 setup_frame_rate_widget ();
531 DCPPanel::setup_frame_rate_widget ()
533 if (Config::instance()->allow_any_dcp_frame_rate ()) {
534 _frame_rate_choice->Hide ();
535 _frame_rate_spin->Show ();
537 _frame_rate_choice->Show ();
538 _frame_rate_spin->Hide ();
541 _frame_rate_sizer->Layout ();
545 DCPPanel::make_video_panel ()
547 wxPanel* panel = new wxPanel (_notebook);
548 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
549 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
550 sizer->Add (grid, 0, wxALL, 8);
551 panel->SetSizer (sizer);
555 add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
556 _container = new wxChoice (panel, wxID_ANY);
557 grid->Add (_container, wxGBPosition (r, 1));
561 add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
562 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
563 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
564 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
565 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
566 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
567 setup_frame_rate_widget ();
568 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
569 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
570 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
574 _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
575 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
578 _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
579 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
582 add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
583 _resolution = new wxChoice (panel, wxID_ANY);
584 grid->Add (_resolution, wxGBPosition (r, 1));
588 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
589 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
590 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
591 s->Add (_j2k_bandwidth, 1);
592 add_label_to_sizer (s, panel, _("Mbit/s"), false);
593 grid->Add (s, wxGBPosition (r, 1));
597 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::container_changed, this));
598 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::frame_rate_choice_changed, this));
599 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::frame_rate_spin_changed, this));
600 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::best_frame_rate_clicked, this));
601 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::burn_subtitles_toggled, this));
602 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
603 /* Also listen to wxEVT_COMMAND_TEXT_UPDATED so that typing numbers directly in is always noticed */
604 _j2k_bandwidth->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
605 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::resolution_changed, this));
606 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::three_d_changed, this));
608 vector<Ratio const *> const ratio = Ratio::all ();
609 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
610 _container->Append (std_to_wx ((*i)->nickname ()));
613 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
614 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
615 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
618 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
619 _frame_rate_spin->SetRange (1, 480);
621 _resolution->Append (_("2K"));
622 _resolution->Append (_("4K"));
628 DCPPanel::make_audio_panel ()
630 wxPanel* panel = new wxPanel (_notebook);
631 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
632 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
633 sizer->Add (grid, 0, wxALL, 8);
634 panel->SetSizer (sizer);
637 add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
638 _audio_channels = new wxChoice (panel, wxID_ANY);
639 for (int i = 2; i <= 16; i += 2) {
640 _audio_channels->Append (wxString::Format ("%d", i));
642 grid->Add (_audio_channels, wxGBPosition (r, 1));
645 _audio_channels->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_channels_changed, this));
651 DCPPanel::copy_isdcf_name_button_clicked ()
653 _film->set_name (_film->isdcf_name (false));
654 _film->set_use_isdcf_name (false);