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 /* We just chose to use the ISDCF name. The user has probably unticked and re-ticked the box,
275 so it's fairly likey that the film's name will now be a full ISDCF one. Based on this guess,
276 remove anything after the first _ in the film's name here.
278 string const n = _film->name ();
279 if (n.find ("_") != string::npos) {
280 _film->set_name (n.substr (0, n.find ("_")));
283 /* Otherwise set the name to the full ISDCF name */
284 _film->set_name (_film->isdcf_name (true));
286 _edit_isdcf_button->Enable (i);
289 case Film::ISDCF_METADATA:
292 case Film::VIDEO_FRAME_RATE:
295 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
296 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
297 checked_set (_frame_rate_choice, i);
304 checked_set (_frame_rate_choice, -1);
307 _frame_rate_spin->SetValue (_film->video_frame_rate ());
309 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
312 case Film::AUDIO_CHANNELS:
313 checked_set (_audio_channels, _film->audio_channels ());
317 checked_set (_three_d, _film->three_d ());
321 checked_set (_standard, _film->interop() ? 1 : 0);
329 DCPPanel::film_content_changed (int property)
331 if (property == FFmpegContentProperty::AUDIO_STREAM ||
332 property == SubtitleContentProperty::USE_SUBTITLES ||
333 property == VideoContentProperty::VIDEO_SCALE) {
340 DCPPanel::setup_container ()
343 vector<Ratio const *> ratios = Ratio::all ();
344 vector<Ratio const *>::iterator i = ratios.begin ();
345 while (i != ratios.end() && *i != _film->container ()) {
350 if (i == ratios.end()) {
351 checked_set (_container, -1);
353 checked_set (_container, n);
359 /** Called when the container widget has been changed */
361 DCPPanel::container_changed ()
367 int const n = _container->GetSelection ();
369 vector<Ratio const *> ratios = Ratio::all ();
370 assert (n < int (ratios.size()));
371 _film->set_container (ratios[n]);
375 /** Called when the DCP content type widget has been changed */
377 DCPPanel::dcp_content_type_changed ()
383 int const n = _dcp_content_type->GetSelection ();
384 if (n != wxNOT_FOUND) {
385 _film->set_dcp_content_type (DCPContentType::from_index (n));
390 DCPPanel::set_film (shared_ptr<Film> film)
394 film_changed (Film::NAME);
395 film_changed (Film::USE_ISDCF_NAME);
396 film_changed (Film::CONTENT);
397 film_changed (Film::DCP_CONTENT_TYPE);
398 film_changed (Film::CONTAINER);
399 film_changed (Film::RESOLUTION);
400 film_changed (Film::SCALER);
401 film_changed (Film::SIGNED);
402 film_changed (Film::BURN_SUBTITLES);
403 film_changed (Film::ENCRYPTED);
404 film_changed (Film::J2K_BANDWIDTH);
405 film_changed (Film::ISDCF_METADATA);
406 film_changed (Film::VIDEO_FRAME_RATE);
407 film_changed (Film::AUDIO_CHANNELS);
408 film_changed (Film::SEQUENCE_VIDEO);
409 film_changed (Film::THREE_D);
410 film_changed (Film::INTEROP);
414 DCPPanel::set_general_sensitivity (bool s)
417 _use_isdcf_name->Enable (s);
418 _edit_isdcf_button->Enable (s);
419 _dcp_content_type->Enable (s);
422 if (_film && _film->encrypted ()) {
425 _burn_subtitles->Enable (s);
426 _signed->Enable (si);
428 _encrypted->Enable (s);
429 _frame_rate_choice->Enable (s);
430 _frame_rate_spin->Enable (s);
431 _audio_channels->Enable (s);
432 _j2k_bandwidth->Enable (s);
433 _container->Enable (s);
434 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
435 _resolution->Enable (s);
437 _three_d->Enable (s);
438 _standard->Enable (s);
441 /** Called when the scaler widget has been changed */
443 DCPPanel::scaler_changed ()
449 int const n = _scaler->GetSelection ();
451 _film->set_scaler (Scaler::from_index (n));
456 DCPPanel::use_isdcf_name_toggled ()
462 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
466 DCPPanel::edit_isdcf_button_clicked ()
472 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
474 _film->set_isdcf_metadata (d->isdcf_metadata ());
479 DCPPanel::setup_dcp_name ()
481 string s = _film->dcp_name (true);
482 if (s.length() > 28) {
483 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
484 _dcp_name->SetToolTip (std_to_wx (s));
486 _dcp_name->SetLabel (std_to_wx (s));
491 DCPPanel::best_frame_rate_clicked ()
497 _film->set_video_frame_rate (_film->best_video_frame_rate ());
501 DCPPanel::three_d_changed ()
507 _film->set_three_d (_three_d->GetValue ());
511 DCPPanel::config_changed ()
513 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
514 setup_frame_rate_widget ();
518 DCPPanel::setup_frame_rate_widget ()
520 if (Config::instance()->allow_any_dcp_frame_rate ()) {
521 _frame_rate_choice->Hide ();
522 _frame_rate_spin->Show ();
524 _frame_rate_choice->Show ();
525 _frame_rate_spin->Hide ();
528 _frame_rate_sizer->Layout ();
532 DCPPanel::make_video_panel ()
534 wxPanel* panel = new wxPanel (_notebook);
535 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
536 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
537 sizer->Add (grid, 0, wxALL, 8);
538 panel->SetSizer (sizer);
542 add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
543 _container = new wxChoice (panel, wxID_ANY);
544 grid->Add (_container, wxGBPosition (r, 1));
548 add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
549 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
550 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
551 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
552 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
553 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
554 setup_frame_rate_widget ();
555 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
556 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
557 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
561 _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
562 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
565 _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
566 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
569 add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
570 _resolution = new wxChoice (panel, wxID_ANY);
571 grid->Add (_resolution, wxGBPosition (r, 1));
575 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
576 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
577 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
578 s->Add (_j2k_bandwidth, 1);
579 add_label_to_sizer (s, panel, _("Mbit/s"), false);
580 grid->Add (s, wxGBPosition (r, 1));
584 add_label_to_grid_bag_sizer (grid, panel, _("Scaler"), true, wxGBPosition (r, 0));
585 _scaler = new wxChoice (panel, wxID_ANY);
586 grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
589 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::container_changed, this));
590 _scaler->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::scaler_changed, this));
591 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::frame_rate_choice_changed, this));
592 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::frame_rate_spin_changed, this));
593 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::best_frame_rate_clicked, this));
594 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::burn_subtitles_toggled, this));
595 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
596 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::resolution_changed, this));
597 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::three_d_changed, this));
599 vector<Scaler const *> const sc = Scaler::all ();
600 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
601 _scaler->Append (std_to_wx ((*i)->name()));
604 vector<Ratio const *> const ratio = Ratio::all ();
605 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
606 _container->Append (std_to_wx ((*i)->nickname ()));
609 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
610 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
611 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
614 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
615 _frame_rate_spin->SetRange (1, 480);
617 _resolution->Append (_("2K"));
618 _resolution->Append (_("4K"));
624 DCPPanel::make_audio_panel ()
626 wxPanel* panel = new wxPanel (_notebook);
627 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
628 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
629 sizer->Add (grid, 0, wxALL, 8);
630 panel->SetSizer (sizer);
633 add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
634 _audio_channels = new wxSpinCtrl (panel, wxID_ANY);
635 grid->Add (_audio_channels, wxGBPosition (r, 1));
638 _audio_channels->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::audio_channels_changed, this));
640 _audio_channels->SetRange (0, MAX_DCP_AUDIO_CHANNELS);