2 Copyright (C) 2012-2014 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/scaler.h"
25 #include "lib/config.h"
26 #include "lib/dcp_content_type.h"
29 #include "lib/ffmpeg_content.h"
31 #include <wx/notebook.h>
32 #include <wx/gbsizer.h>
33 #include <wx/spinctrl.h>
34 #include <boost/lexical_cast.hpp>
40 using boost::lexical_cast;
41 using boost::shared_ptr;
43 DCPPanel::DCPPanel (wxNotebook* n, boost::shared_ptr<Film> f)
45 , _generally_sensitive (true)
47 _panel = new wxPanel (n);
48 _sizer = new wxBoxSizer (wxVERTICAL);
49 _panel->SetSizer (_sizer);
51 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
52 _sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
56 add_label_to_grid_bag_sizer (grid, _panel, _("Name"), true, wxGBPosition (r, 0));
57 _name = new wxTextCtrl (_panel, wxID_ANY);
58 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
61 int flags = wxALIGN_CENTER_VERTICAL;
63 flags |= wxALIGN_RIGHT;
66 _use_isdcf_name = new wxCheckBox (_panel, wxID_ANY, _("Use ISDCF name"));
67 grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
68 _edit_isdcf_button = new wxButton (_panel, wxID_ANY, _("Details..."));
69 grid->Add (_edit_isdcf_button, wxGBPosition (r, 1));
72 add_label_to_grid_bag_sizer (grid, _panel, _("DCP Name"), true, wxGBPosition (r, 0));
73 _dcp_name = new wxStaticText (_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
74 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxEXPAND);
77 add_label_to_grid_bag_sizer (grid, _panel, _("Content Type"), true, wxGBPosition (r, 0));
78 _dcp_content_type = new wxChoice (_panel, wxID_ANY);
79 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
82 _notebook = new wxNotebook (_panel, wxID_ANY);
83 _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
85 _notebook->AddPage (make_video_panel (), _("Video"), false);
86 _notebook->AddPage (make_audio_panel (), _("Audio"), false);
88 _signed = new wxCheckBox (_panel, wxID_ANY, _("Signed"));
89 grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
92 _encrypted = new wxCheckBox (_panel, wxID_ANY, _("Encrypted"));
93 grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
96 add_label_to_grid_bag_sizer (grid, _panel, _("Standard"), true, wxGBPosition (r, 0));
97 _standard = new wxChoice (_panel, wxID_ANY);
98 grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
101 _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::name_changed, this));
102 _use_isdcf_name->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::use_isdcf_name_toggled, this));
103 _edit_isdcf_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_isdcf_button_clicked, this));
104 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::dcp_content_type_changed, this));
105 _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::signed_toggled, this));
106 _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::encrypted_toggled, this));
107 _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::standard_changed, this));
109 vector<DCPContentType const *> const ct = DCPContentType::all ();
110 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
111 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
114 _standard->Append (_("SMPTE"));
115 _standard->Append (_("Interop"));
117 Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this));
121 DCPPanel::name_changed ()
127 _film->set_name (string (_name->GetValue().mb_str()));
131 DCPPanel::j2k_bandwidth_changed ()
137 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
141 DCPPanel::signed_toggled ()
147 _film->set_signed (_signed->GetValue ());
151 DCPPanel::burn_subtitles_toggled ()
157 _film->set_burn_subtitles (_burn_subtitles->GetValue ());
161 DCPPanel::encrypted_toggled ()
167 _film->set_encrypted (_encrypted->GetValue ());
170 /** Called when the frame rate choice widget has been changed */
172 DCPPanel::frame_rate_choice_changed ()
178 _film->set_video_frame_rate (
179 boost::lexical_cast<int> (
180 wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
185 /** Called when the frame rate spin widget has been changed */
187 DCPPanel::frame_rate_spin_changed ()
193 _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
197 DCPPanel::audio_channels_changed ()
203 _film->set_audio_channels (_audio_channels->GetValue ());
207 DCPPanel::resolution_changed ()
213 _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
217 DCPPanel::standard_changed ()
223 _film->set_interop (_standard->GetSelection() == 1);
227 DCPPanel::film_changed (int p)
232 case Film::CONTAINER:
236 checked_set (_name, _film->name());
239 case Film::DCP_CONTENT_TYPE:
240 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
244 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
246 case Film::BURN_SUBTITLES:
247 checked_set (_burn_subtitles, _film->burn_subtitles ());
250 checked_set (_signed, _film->is_signed ());
252 case Film::ENCRYPTED:
253 checked_set (_encrypted, _film->encrypted ());
254 if (_film->encrypted ()) {
255 _film->set_signed (true);
256 _signed->Enable (false);
258 _signed->Enable (_generally_sensitive);
261 case Film::RESOLUTION:
262 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
265 case Film::J2K_BANDWIDTH:
266 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
268 case Film::USE_ISDCF_NAME:
270 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
272 bool const i = _film->use_isdcf_name ();
274 _film->set_name (_film->isdcf_name (true));
276 _edit_isdcf_button->Enable (i);
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 ());
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 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::SCALER);
391 film_changed (Film::SIGNED);
392 film_changed (Film::BURN_SUBTITLES);
393 film_changed (Film::ENCRYPTED);
394 film_changed (Film::J2K_BANDWIDTH);
395 film_changed (Film::ISDCF_METADATA);
396 film_changed (Film::VIDEO_FRAME_RATE);
397 film_changed (Film::AUDIO_CHANNELS);
398 film_changed (Film::SEQUENCE_VIDEO);
399 film_changed (Film::THREE_D);
400 film_changed (Film::INTEROP);
404 DCPPanel::set_general_sensitivity (bool s)
407 _use_isdcf_name->Enable (s);
408 _edit_isdcf_button->Enable (s);
409 _dcp_content_type->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);
427 _three_d->Enable (s);
428 _standard->Enable (s);
431 /** Called when the scaler widget has been changed */
433 DCPPanel::scaler_changed ()
439 int const n = _scaler->GetSelection ();
441 _film->set_scaler (Scaler::from_index (n));
446 DCPPanel::use_isdcf_name_toggled ()
452 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
456 DCPPanel::edit_isdcf_button_clicked ()
462 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
464 _film->set_isdcf_metadata (d->isdcf_metadata ());
469 DCPPanel::setup_dcp_name ()
471 string s = _film->dcp_name (true);
472 if (s.length() > 28) {
473 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
474 _dcp_name->SetToolTip (std_to_wx (s));
476 _dcp_name->SetLabel (std_to_wx (s));
481 DCPPanel::best_frame_rate_clicked ()
487 _film->set_video_frame_rate (_film->best_video_frame_rate ());
491 DCPPanel::three_d_changed ()
497 _film->set_three_d (_three_d->GetValue ());
501 DCPPanel::config_changed ()
503 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
504 setup_frame_rate_widget ();
508 DCPPanel::setup_frame_rate_widget ()
510 if (Config::instance()->allow_any_dcp_frame_rate ()) {
511 _frame_rate_choice->Hide ();
512 _frame_rate_spin->Show ();
514 _frame_rate_choice->Show ();
515 _frame_rate_spin->Hide ();
518 _frame_rate_sizer->Layout ();
522 DCPPanel::make_video_panel ()
524 wxPanel* panel = new wxPanel (_notebook);
525 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
526 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
527 sizer->Add (grid, 0, wxALL, 8);
528 panel->SetSizer (sizer);
532 add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
533 _container = new wxChoice (panel, wxID_ANY);
534 grid->Add (_container, wxGBPosition (r, 1));
538 add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
539 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
540 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
541 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
542 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
543 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
544 setup_frame_rate_widget ();
545 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
546 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
547 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
551 _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
552 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
555 _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
556 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
559 add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
560 _resolution = new wxChoice (panel, wxID_ANY);
561 grid->Add (_resolution, wxGBPosition (r, 1));
565 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
566 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
567 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
568 s->Add (_j2k_bandwidth, 1);
569 add_label_to_sizer (s, panel, _("Mbit/s"), false);
570 grid->Add (s, wxGBPosition (r, 1));
574 add_label_to_grid_bag_sizer (grid, panel, _("Scaler"), true, wxGBPosition (r, 0));
575 _scaler = new wxChoice (panel, wxID_ANY);
576 grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
579 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::container_changed, this));
580 _scaler->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::scaler_changed, this));
581 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::frame_rate_choice_changed, this));
582 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::frame_rate_spin_changed, this));
583 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::best_frame_rate_clicked, this));
584 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::burn_subtitles_toggled, this));
585 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
586 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::resolution_changed, this));
587 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::three_d_changed, this));
589 vector<Scaler const *> const sc = Scaler::all ();
590 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
591 _scaler->Append (std_to_wx ((*i)->name()));
594 vector<Ratio const *> const ratio = Ratio::all ();
595 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
596 _container->Append (std_to_wx ((*i)->nickname ()));
599 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
600 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
601 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
604 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
605 _frame_rate_spin->SetRange (1, 480);
607 _resolution->Append (_("2K"));
608 _resolution->Append (_("4K"));
614 DCPPanel::make_audio_panel ()
616 wxPanel* panel = new wxPanel (_notebook);
617 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
618 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
619 sizer->Add (grid, 0, wxALL, 8);
620 panel->SetSizer (sizer);
623 add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
624 _audio_channels = new wxSpinCtrl (panel, wxID_ANY);
625 grid->Add (_audio_channels, wxGBPosition (r, 1));
628 _audio_channels->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::audio_channels_changed, this));
630 _audio_channels->SetRange (0, MAX_DCP_AUDIO_CHANNELS);