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 add_label_to_grid_bag_sizer (grid, _panel, _("DCP Name"), true, wxGBPosition (r, 0));
62 _dcp_name = new wxStaticText (_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
63 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxEXPAND);
66 int flags = wxALIGN_CENTER_VERTICAL;
68 flags |= wxALIGN_RIGHT;
71 _use_isdcf_name = new wxCheckBox (_panel, wxID_ANY, _("Use ISDCF name"));
72 grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
73 _edit_isdcf_button = new wxButton (_panel, wxID_ANY, _("Details..."));
74 grid->Add (_edit_isdcf_button, wxGBPosition (r, 1));
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:
269 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
272 case Film::ISDCF_METADATA:
275 case Film::VIDEO_FRAME_RATE:
278 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
279 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
280 checked_set (_frame_rate_choice, i);
287 checked_set (_frame_rate_choice, -1);
290 _frame_rate_spin->SetValue (_film->video_frame_rate ());
292 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
295 case Film::AUDIO_CHANNELS:
296 checked_set (_audio_channels, _film->audio_channels ());
300 checked_set (_three_d, _film->three_d ());
304 checked_set (_standard, _film->interop() ? 1 : 0);
312 DCPPanel::film_content_changed (int property)
314 if (property == FFmpegContentProperty::AUDIO_STREAM || property == SubtitleContentProperty::USE_SUBTITLES) {
321 DCPPanel::setup_container ()
324 vector<Ratio const *> ratios = Ratio::all ();
325 vector<Ratio const *>::iterator i = ratios.begin ();
326 while (i != ratios.end() && *i != _film->container ()) {
331 if (i == ratios.end()) {
332 checked_set (_container, -1);
334 checked_set (_container, n);
340 /** Called when the container widget has been changed */
342 DCPPanel::container_changed ()
348 int const n = _container->GetSelection ();
350 vector<Ratio const *> ratios = Ratio::all ();
351 assert (n < int (ratios.size()));
352 _film->set_container (ratios[n]);
356 /** Called when the DCP content type widget has been changed */
358 DCPPanel::dcp_content_type_changed ()
364 int const n = _dcp_content_type->GetSelection ();
365 if (n != wxNOT_FOUND) {
366 _film->set_dcp_content_type (DCPContentType::from_index (n));
371 DCPPanel::set_film (shared_ptr<Film> film)
375 film_changed (Film::NAME);
376 film_changed (Film::USE_ISDCF_NAME);
377 film_changed (Film::CONTENT);
378 film_changed (Film::DCP_CONTENT_TYPE);
379 film_changed (Film::CONTAINER);
380 film_changed (Film::RESOLUTION);
381 film_changed (Film::SCALER);
382 film_changed (Film::SIGNED);
383 film_changed (Film::BURN_SUBTITLES);
384 film_changed (Film::ENCRYPTED);
385 film_changed (Film::J2K_BANDWIDTH);
386 film_changed (Film::ISDCF_METADATA);
387 film_changed (Film::VIDEO_FRAME_RATE);
388 film_changed (Film::AUDIO_CHANNELS);
389 film_changed (Film::SEQUENCE_VIDEO);
390 film_changed (Film::THREE_D);
391 film_changed (Film::INTEROP);
395 DCPPanel::set_general_sensitivity (bool s)
398 _use_isdcf_name->Enable (s);
399 _edit_isdcf_button->Enable (s);
400 _dcp_content_type->Enable (s);
403 if (_film && _film->encrypted ()) {
406 _burn_subtitles->Enable (s);
407 _signed->Enable (si);
409 _encrypted->Enable (s);
410 _frame_rate_choice->Enable (s);
411 _frame_rate_spin->Enable (s);
412 _audio_channels->Enable (s);
413 _j2k_bandwidth->Enable (s);
414 _container->Enable (s);
415 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
416 _resolution->Enable (s);
418 _three_d->Enable (s);
419 _standard->Enable (s);
422 /** Called when the scaler widget has been changed */
424 DCPPanel::scaler_changed ()
430 int const n = _scaler->GetSelection ();
432 _film->set_scaler (Scaler::from_index (n));
437 DCPPanel::use_isdcf_name_toggled ()
443 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
447 DCPPanel::edit_isdcf_button_clicked ()
453 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
455 _film->set_isdcf_metadata (d->isdcf_metadata ());
460 DCPPanel::setup_dcp_name ()
462 string s = _film->dcp_name (true);
463 if (s.length() > 28) {
464 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
465 _dcp_name->SetToolTip (std_to_wx (s));
467 _dcp_name->SetLabel (std_to_wx (s));
472 DCPPanel::best_frame_rate_clicked ()
478 _film->set_video_frame_rate (_film->best_video_frame_rate ());
482 DCPPanel::three_d_changed ()
488 _film->set_three_d (_three_d->GetValue ());
492 DCPPanel::config_changed ()
494 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
495 setup_frame_rate_widget ();
499 DCPPanel::setup_frame_rate_widget ()
501 if (Config::instance()->allow_any_dcp_frame_rate ()) {
502 _frame_rate_choice->Hide ();
503 _frame_rate_spin->Show ();
505 _frame_rate_choice->Show ();
506 _frame_rate_spin->Hide ();
509 _frame_rate_sizer->Layout ();
513 DCPPanel::make_video_panel ()
515 wxPanel* panel = new wxPanel (_notebook);
516 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
517 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
518 sizer->Add (grid, 0, wxALL, 8);
519 panel->SetSizer (sizer);
523 add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
524 _container = new wxChoice (panel, wxID_ANY);
525 grid->Add (_container, wxGBPosition (r, 1));
529 add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
530 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
531 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
532 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
533 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
534 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
535 setup_frame_rate_widget ();
536 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
537 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
538 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
542 _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
543 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
546 _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
547 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
550 add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
551 _resolution = new wxChoice (panel, wxID_ANY);
552 grid->Add (_resolution, wxGBPosition (r, 1));
556 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
557 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
558 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
559 s->Add (_j2k_bandwidth, 1);
560 add_label_to_sizer (s, panel, _("Mbit/s"), false);
561 grid->Add (s, wxGBPosition (r, 1));
565 add_label_to_grid_bag_sizer (grid, panel, _("Scaler"), true, wxGBPosition (r, 0));
566 _scaler = new wxChoice (panel, wxID_ANY);
567 grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
570 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::container_changed, this));
571 _scaler->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::scaler_changed, this));
572 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::frame_rate_choice_changed, this));
573 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::frame_rate_spin_changed, this));
574 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::best_frame_rate_clicked, this));
575 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::burn_subtitles_toggled, this));
576 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
577 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::resolution_changed, this));
578 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::three_d_changed, this));
580 vector<Scaler const *> const sc = Scaler::all ();
581 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
582 _scaler->Append (std_to_wx ((*i)->name()));
585 vector<Ratio const *> const ratio = Ratio::all ();
586 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
587 _container->Append (std_to_wx ((*i)->nickname ()));
590 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
591 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
592 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
595 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
596 _frame_rate_spin->SetRange (1, 480);
598 _resolution->Append (_("2K"));
599 _resolution->Append (_("4K"));
605 DCPPanel::make_audio_panel ()
607 wxPanel* panel = new wxPanel (_notebook);
608 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
609 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
610 sizer->Add (grid, 0, wxALL, 8);
611 panel->SetSizer (sizer);
614 add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
615 _audio_channels = new wxSpinCtrl (panel, wxID_ANY);
616 grid->Add (_audio_channels, wxGBPosition (r, 1));
619 _audio_channels->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::audio_channels_changed, this));
621 _audio_channels->SetRange (0, MAX_DCP_AUDIO_CHANNELS);