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 "isdcf_metadata_dialog.h"
23 #include "lib/ratio.h"
24 #include "lib/config.h"
25 #include "lib/dcp_content_type.h"
28 #include "lib/ffmpeg_content.h"
30 #include <wx/notebook.h>
31 #include <wx/gbsizer.h>
32 #include <wx/spinctrl.h>
33 #include <boost/lexical_cast.hpp>
39 using boost::lexical_cast;
40 using boost::shared_ptr;
42 DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr<Film> f)
44 , _generally_sensitive (true)
46 _panel = new wxPanel (n);
47 _sizer = new wxBoxSizer (wxVERTICAL);
48 _panel->SetSizer (_sizer);
50 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
51 _sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
55 add_label_to_grid_bag_sizer (grid, _panel, _("Name"), true, wxGBPosition (r, 0));
56 _name = new wxTextCtrl (_panel, wxID_ANY);
57 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
60 int flags = wxALIGN_CENTER_VERTICAL;
62 flags |= wxALIGN_RIGHT;
65 _use_isdcf_name = new wxCheckBox (_panel, wxID_ANY, _("Use ISDCF name"));
66 grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
69 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
70 _edit_isdcf_button = new wxButton (_panel, wxID_ANY, _("Details..."));
71 s->Add (_edit_isdcf_button, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
72 _copy_isdcf_name_button = new wxButton (_panel, wxID_ANY, _("Copy as name"));
73 s->Add (_copy_isdcf_name_button, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_X_GAP);
74 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
78 add_label_to_grid_bag_sizer (grid, _panel, _("DCP Name"), true, wxGBPosition (r, 0));
79 _dcp_name = new wxStaticText (_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
80 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxEXPAND);
83 add_label_to_grid_bag_sizer (grid, _panel, _("Content Type"), true, wxGBPosition (r, 0));
84 _dcp_content_type = new wxChoice (_panel, wxID_ANY);
85 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
88 _notebook = new wxNotebook (_panel, wxID_ANY);
89 _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
91 _notebook->AddPage (make_video_panel (), _("Video"), false);
92 _notebook->AddPage (make_audio_panel (), _("Audio"), false);
94 _signed = new wxCheckBox (_panel, wxID_ANY, _("Signed"));
95 grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
98 _encrypted = new wxCheckBox (_panel, wxID_ANY, _("Encrypted"));
99 grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
102 add_label_to_grid_bag_sizer (grid, _panel, _("Standard"), true, wxGBPosition (r, 0));
103 _standard = new wxChoice (_panel, wxID_ANY);
104 grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
107 _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::name_changed, this));
108 _use_isdcf_name->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::use_isdcf_name_toggled, this));
109 _edit_isdcf_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_isdcf_button_clicked, this));
110 _copy_isdcf_name_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::copy_isdcf_name_button_clicked, this));
111 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::dcp_content_type_changed, this));
112 _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::signed_toggled, this));
113 _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::encrypted_toggled, this));
114 _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::standard_changed, this));
116 vector<DCPContentType const *> const ct = DCPContentType::all ();
117 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
118 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
121 _standard->Append (_("SMPTE"));
122 _standard->Append (_("Interop"));
124 Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this));
128 DCPPanel::name_changed ()
134 _film->set_name (string (_name->GetValue().mb_str()));
138 DCPPanel::j2k_bandwidth_changed ()
144 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
148 DCPPanel::signed_toggled ()
154 _film->set_signed (_signed->GetValue ());
158 DCPPanel::burn_subtitles_toggled ()
164 _film->set_burn_subtitles (_burn_subtitles->GetValue ());
168 DCPPanel::encrypted_toggled ()
174 _film->set_encrypted (_encrypted->GetValue ());
177 /** Called when the frame rate choice widget has been changed */
179 DCPPanel::frame_rate_choice_changed ()
185 _film->set_video_frame_rate (
186 boost::lexical_cast<int> (
187 wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
192 /** Called when the frame rate spin widget has been changed */
194 DCPPanel::frame_rate_spin_changed ()
200 _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
204 DCPPanel::audio_channels_changed ()
210 _film->set_audio_channels ((_audio_channels->GetSelection () + 1) * 2);
214 DCPPanel::resolution_changed ()
220 _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
224 DCPPanel::standard_changed ()
230 _film->set_interop (_standard->GetSelection() == 1);
234 DCPPanel::film_changed (int p)
239 case Film::CONTAINER:
243 checked_set (_name, _film->name());
246 case Film::DCP_CONTENT_TYPE:
247 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
250 case Film::BURN_SUBTITLES:
251 checked_set (_burn_subtitles, _film->burn_subtitles ());
254 checked_set (_signed, _film->is_signed ());
256 case Film::ENCRYPTED:
257 checked_set (_encrypted, _film->encrypted ());
258 if (_film->encrypted ()) {
259 _film->set_signed (true);
260 _signed->Enable (false);
262 _signed->Enable (_generally_sensitive);
265 case Film::RESOLUTION:
266 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
269 case Film::J2K_BANDWIDTH:
270 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
272 case Film::USE_ISDCF_NAME:
274 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
276 _edit_isdcf_button->Enable (_film->use_isdcf_name ());
279 case Film::ISDCF_METADATA:
282 case Film::VIDEO_FRAME_RATE:
285 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
286 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
287 checked_set (_frame_rate_choice, i);
294 checked_set (_frame_rate_choice, -1);
297 _frame_rate_spin->SetValue (_film->video_frame_rate ());
299 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
302 case Film::AUDIO_CHANNELS:
303 checked_set (_audio_channels, (_film->audio_channels () / 2) - 1);
307 checked_set (_three_d, _film->three_d ());
311 checked_set (_standard, _film->interop() ? 1 : 0);
319 DCPPanel::film_content_changed (int property)
321 if (property == FFmpegContentProperty::AUDIO_STREAM ||
322 property == SubtitleContentProperty::USE_SUBTITLES ||
323 property == VideoContentProperty::VIDEO_SCALE) {
330 DCPPanel::setup_container ()
333 vector<Ratio const *> ratios = Ratio::all ();
334 vector<Ratio const *>::iterator i = ratios.begin ();
335 while (i != ratios.end() && *i != _film->container ()) {
340 if (i == ratios.end()) {
341 checked_set (_container, -1);
343 checked_set (_container, n);
349 /** Called when the container widget has been changed */
351 DCPPanel::container_changed ()
357 int const n = _container->GetSelection ();
359 vector<Ratio const *> ratios = Ratio::all ();
360 DCPOMATIC_ASSERT (n < int (ratios.size()));
361 _film->set_container (ratios[n]);
365 /** Called when the DCP content type widget has been changed */
367 DCPPanel::dcp_content_type_changed ()
373 int const n = _dcp_content_type->GetSelection ();
374 if (n != wxNOT_FOUND) {
375 _film->set_dcp_content_type (DCPContentType::from_index (n));
380 DCPPanel::set_film (shared_ptr<Film> film)
384 film_changed (Film::NAME);
385 film_changed (Film::USE_ISDCF_NAME);
386 film_changed (Film::CONTENT);
387 film_changed (Film::DCP_CONTENT_TYPE);
388 film_changed (Film::CONTAINER);
389 film_changed (Film::RESOLUTION);
390 film_changed (Film::SIGNED);
391 film_changed (Film::BURN_SUBTITLES);
392 film_changed (Film::ENCRYPTED);
393 film_changed (Film::J2K_BANDWIDTH);
394 film_changed (Film::ISDCF_METADATA);
395 film_changed (Film::VIDEO_FRAME_RATE);
396 film_changed (Film::AUDIO_CHANNELS);
397 film_changed (Film::SEQUENCE_VIDEO);
398 film_changed (Film::THREE_D);
399 film_changed (Film::INTEROP);
403 DCPPanel::set_general_sensitivity (bool s)
406 _use_isdcf_name->Enable (s);
407 _edit_isdcf_button->Enable (s);
408 _dcp_content_type->Enable (s);
409 _copy_isdcf_name_button->Enable (s);
412 if (_film && _film->encrypted ()) {
415 _burn_subtitles->Enable (s);
416 _signed->Enable (si);
418 _encrypted->Enable (s);
419 _frame_rate_choice->Enable (s);
420 _frame_rate_spin->Enable (s);
421 _audio_channels->Enable (s);
422 _j2k_bandwidth->Enable (s);
423 _container->Enable (s);
424 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
425 _resolution->Enable (s);
426 _three_d->Enable (s);
427 _standard->Enable (s);
431 DCPPanel::use_isdcf_name_toggled ()
437 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
441 DCPPanel::edit_isdcf_button_clicked ()
447 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
449 _film->set_isdcf_metadata (d->isdcf_metadata ());
454 DCPPanel::setup_dcp_name ()
456 string s = _film->dcp_name (true);
457 if (s.length() > 28) {
458 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
459 _dcp_name->SetToolTip (std_to_wx (s));
461 _dcp_name->SetLabel (std_to_wx (s));
466 DCPPanel::best_frame_rate_clicked ()
472 _film->set_video_frame_rate (_film->best_video_frame_rate ());
476 DCPPanel::three_d_changed ()
482 _film->set_three_d (_three_d->GetValue ());
486 DCPPanel::config_changed ()
488 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
489 setup_frame_rate_widget ();
493 DCPPanel::setup_frame_rate_widget ()
495 if (Config::instance()->allow_any_dcp_frame_rate ()) {
496 _frame_rate_choice->Hide ();
497 _frame_rate_spin->Show ();
499 _frame_rate_choice->Show ();
500 _frame_rate_spin->Hide ();
503 _frame_rate_sizer->Layout ();
507 DCPPanel::make_video_panel ()
509 wxPanel* panel = new wxPanel (_notebook);
510 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
511 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
512 sizer->Add (grid, 0, wxALL, 8);
513 panel->SetSizer (sizer);
517 add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
518 _container = new wxChoice (panel, wxID_ANY);
519 grid->Add (_container, wxGBPosition (r, 1));
523 add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
524 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
525 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
526 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
527 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
528 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
529 setup_frame_rate_widget ();
530 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
531 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
532 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
536 _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
537 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
540 _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
541 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
544 add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
545 _resolution = new wxChoice (panel, wxID_ANY);
546 grid->Add (_resolution, wxGBPosition (r, 1));
550 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
551 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
552 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
553 s->Add (_j2k_bandwidth, 1);
554 add_label_to_sizer (s, panel, _("Mbit/s"), false);
555 grid->Add (s, wxGBPosition (r, 1));
559 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::container_changed, this));
560 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::frame_rate_choice_changed, this));
561 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::frame_rate_spin_changed, this));
562 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::best_frame_rate_clicked, this));
563 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::burn_subtitles_toggled, this));
564 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
565 /* Also listen to wxEVT_COMMAND_TEXT_UPDATED so that typing numbers directly in is always noticed */
566 _j2k_bandwidth->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
567 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::resolution_changed, this));
568 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::three_d_changed, this));
570 vector<Ratio const *> const ratio = Ratio::all ();
571 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
572 _container->Append (std_to_wx ((*i)->nickname ()));
575 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
576 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
577 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
580 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
581 _frame_rate_spin->SetRange (1, 480);
583 _resolution->Append (_("2K"));
584 _resolution->Append (_("4K"));
590 DCPPanel::make_audio_panel ()
592 wxPanel* panel = new wxPanel (_notebook);
593 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
594 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
595 sizer->Add (grid, 0, wxALL, 8);
596 panel->SetSizer (sizer);
599 add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
600 _audio_channels = new wxChoice (panel, wxID_ANY);
601 for (int i = 2; i <= 16; i += 2) {
602 _audio_channels->Append (wxString::Format ("%d", i));
604 grid->Add (_audio_channels, wxGBPosition (r, 1));
607 _audio_channels->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::audio_channels_changed, this));
613 DCPPanel::copy_isdcf_name_button_clicked ()
615 _film->set_name (_film->isdcf_name (false));
616 _film->set_use_isdcf_name (false);