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);
70 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
71 _edit_isdcf_button = new wxButton (_panel, wxID_ANY, _("Details..."));
72 s->Add (_edit_isdcf_button, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
73 _copy_isdcf_name_button = new wxButton (_panel, wxID_ANY, _("Copy as name"));
74 s->Add (_copy_isdcf_name_button, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_X_GAP);
75 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
79 add_label_to_grid_bag_sizer (grid, _panel, _("DCP Name"), true, wxGBPosition (r, 0));
80 _dcp_name = new wxStaticText (_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
81 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL | wxEXPAND);
84 add_label_to_grid_bag_sizer (grid, _panel, _("Content Type"), true, wxGBPosition (r, 0));
85 _dcp_content_type = new wxChoice (_panel, wxID_ANY);
86 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
89 _notebook = new wxNotebook (_panel, wxID_ANY);
90 _sizer->Add (_notebook, 1, wxEXPAND | wxTOP, 6);
92 _notebook->AddPage (make_video_panel (), _("Video"), false);
93 _notebook->AddPage (make_audio_panel (), _("Audio"), false);
95 _signed = new wxCheckBox (_panel, wxID_ANY, _("Signed"));
96 grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
99 _encrypted = new wxCheckBox (_panel, wxID_ANY, _("Encrypted"));
100 grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
103 add_label_to_grid_bag_sizer (grid, _panel, _("Standard"), true, wxGBPosition (r, 0));
104 _standard = new wxChoice (_panel, wxID_ANY);
105 grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
108 _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DCPPanel::name_changed, this));
109 _use_isdcf_name->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::use_isdcf_name_toggled, this));
110 _edit_isdcf_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::edit_isdcf_button_clicked, this));
111 _copy_isdcf_name_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::copy_isdcf_name_button_clicked, this));
112 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::dcp_content_type_changed, this));
113 _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::signed_toggled, this));
114 _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::encrypted_toggled, this));
115 _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::standard_changed, this));
117 vector<DCPContentType const *> const ct = DCPContentType::all ();
118 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
119 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
122 _standard->Append (_("SMPTE"));
123 _standard->Append (_("Interop"));
125 Config::instance()->Changed.connect (boost::bind (&DCPPanel::config_changed, this));
129 DCPPanel::name_changed ()
135 _film->set_name (string (_name->GetValue().mb_str()));
139 DCPPanel::j2k_bandwidth_changed ()
145 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
149 DCPPanel::signed_toggled ()
155 _film->set_signed (_signed->GetValue ());
159 DCPPanel::burn_subtitles_toggled ()
165 _film->set_burn_subtitles (_burn_subtitles->GetValue ());
169 DCPPanel::encrypted_toggled ()
175 _film->set_encrypted (_encrypted->GetValue ());
178 /** Called when the frame rate choice widget has been changed */
180 DCPPanel::frame_rate_choice_changed ()
186 _film->set_video_frame_rate (
187 boost::lexical_cast<int> (
188 wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
193 /** Called when the frame rate spin widget has been changed */
195 DCPPanel::frame_rate_spin_changed ()
201 _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
205 DCPPanel::audio_channels_changed ()
211 _film->set_audio_channels (_audio_channels->GetValue ());
215 DCPPanel::resolution_changed ()
221 _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
225 DCPPanel::standard_changed ()
231 _film->set_interop (_standard->GetSelection() == 1);
235 DCPPanel::film_changed (int p)
240 case Film::CONTAINER:
244 checked_set (_name, _film->name());
247 case Film::DCP_CONTENT_TYPE:
248 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
252 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
254 case Film::BURN_SUBTITLES:
255 checked_set (_burn_subtitles, _film->burn_subtitles ());
258 checked_set (_signed, _film->is_signed ());
260 case Film::ENCRYPTED:
261 checked_set (_encrypted, _film->encrypted ());
262 if (_film->encrypted ()) {
263 _film->set_signed (true);
264 _signed->Enable (false);
266 _signed->Enable (_generally_sensitive);
269 case Film::RESOLUTION:
270 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
273 case Film::J2K_BANDWIDTH:
274 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
276 case Film::USE_ISDCF_NAME:
278 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
280 _edit_isdcf_button->Enable (_film->use_isdcf_name ());
283 case Film::ISDCF_METADATA:
286 case Film::VIDEO_FRAME_RATE:
289 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
290 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
291 checked_set (_frame_rate_choice, i);
298 checked_set (_frame_rate_choice, -1);
301 _frame_rate_spin->SetValue (_film->video_frame_rate ());
303 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
306 case Film::AUDIO_CHANNELS:
307 checked_set (_audio_channels, _film->audio_channels ());
311 checked_set (_three_d, _film->three_d ());
315 checked_set (_standard, _film->interop() ? 1 : 0);
323 DCPPanel::film_content_changed (int property)
325 if (property == FFmpegContentProperty::AUDIO_STREAM ||
326 property == SubtitleContentProperty::USE_SUBTITLES ||
327 property == VideoContentProperty::VIDEO_SCALE) {
334 DCPPanel::setup_container ()
337 vector<Ratio const *> ratios = Ratio::all ();
338 vector<Ratio const *>::iterator i = ratios.begin ();
339 while (i != ratios.end() && *i != _film->container ()) {
344 if (i == ratios.end()) {
345 checked_set (_container, -1);
347 checked_set (_container, n);
353 /** Called when the container widget has been changed */
355 DCPPanel::container_changed ()
361 int const n = _container->GetSelection ();
363 vector<Ratio const *> ratios = Ratio::all ();
364 assert (n < int (ratios.size()));
365 _film->set_container (ratios[n]);
369 /** Called when the DCP content type widget has been changed */
371 DCPPanel::dcp_content_type_changed ()
377 int const n = _dcp_content_type->GetSelection ();
378 if (n != wxNOT_FOUND) {
379 _film->set_dcp_content_type (DCPContentType::from_index (n));
384 DCPPanel::set_film (shared_ptr<Film> film)
388 film_changed (Film::NAME);
389 film_changed (Film::USE_ISDCF_NAME);
390 film_changed (Film::CONTENT);
391 film_changed (Film::DCP_CONTENT_TYPE);
392 film_changed (Film::CONTAINER);
393 film_changed (Film::RESOLUTION);
394 film_changed (Film::SCALER);
395 film_changed (Film::SIGNED);
396 film_changed (Film::BURN_SUBTITLES);
397 film_changed (Film::ENCRYPTED);
398 film_changed (Film::J2K_BANDWIDTH);
399 film_changed (Film::ISDCF_METADATA);
400 film_changed (Film::VIDEO_FRAME_RATE);
401 film_changed (Film::AUDIO_CHANNELS);
402 film_changed (Film::SEQUENCE_VIDEO);
403 film_changed (Film::THREE_D);
404 film_changed (Film::INTEROP);
408 DCPPanel::set_general_sensitivity (bool s)
411 _use_isdcf_name->Enable (s);
412 _edit_isdcf_button->Enable (s);
413 _dcp_content_type->Enable (s);
416 if (_film && _film->encrypted ()) {
419 _burn_subtitles->Enable (s);
420 _signed->Enable (si);
422 _encrypted->Enable (s);
423 _frame_rate_choice->Enable (s);
424 _frame_rate_spin->Enable (s);
425 _audio_channels->Enable (s);
426 _j2k_bandwidth->Enable (s);
427 _container->Enable (s);
428 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
429 _resolution->Enable (s);
431 _three_d->Enable (s);
432 _standard->Enable (s);
435 /** Called when the scaler widget has been changed */
437 DCPPanel::scaler_changed ()
443 int const n = _scaler->GetSelection ();
445 _film->set_scaler (Scaler::from_index (n));
450 DCPPanel::use_isdcf_name_toggled ()
456 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
460 DCPPanel::edit_isdcf_button_clicked ()
466 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (_panel, _film->isdcf_metadata ());
468 _film->set_isdcf_metadata (d->isdcf_metadata ());
473 DCPPanel::setup_dcp_name ()
475 string s = _film->dcp_name (true);
476 if (s.length() > 28) {
477 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
478 _dcp_name->SetToolTip (std_to_wx (s));
480 _dcp_name->SetLabel (std_to_wx (s));
485 DCPPanel::best_frame_rate_clicked ()
491 _film->set_video_frame_rate (_film->best_video_frame_rate ());
495 DCPPanel::three_d_changed ()
501 _film->set_three_d (_three_d->GetValue ());
505 DCPPanel::config_changed ()
507 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
508 setup_frame_rate_widget ();
512 DCPPanel::setup_frame_rate_widget ()
514 if (Config::instance()->allow_any_dcp_frame_rate ()) {
515 _frame_rate_choice->Hide ();
516 _frame_rate_spin->Show ();
518 _frame_rate_choice->Show ();
519 _frame_rate_spin->Hide ();
522 _frame_rate_sizer->Layout ();
526 DCPPanel::make_video_panel ()
528 wxPanel* panel = new wxPanel (_notebook);
529 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
530 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
531 sizer->Add (grid, 0, wxALL, 8);
532 panel->SetSizer (sizer);
536 add_label_to_grid_bag_sizer (grid, panel, _("Container"), true, wxGBPosition (r, 0));
537 _container = new wxChoice (panel, wxID_ANY);
538 grid->Add (_container, wxGBPosition (r, 1));
542 add_label_to_grid_bag_sizer (grid, panel, _("Frame Rate"), true, wxGBPosition (r, 0));
543 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
544 _frame_rate_choice = new wxChoice (panel, wxID_ANY);
545 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
546 _frame_rate_spin = new wxSpinCtrl (panel, wxID_ANY);
547 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
548 setup_frame_rate_widget ();
549 _best_frame_rate = new wxButton (panel, wxID_ANY, _("Use best"));
550 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
551 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
555 _burn_subtitles = new wxCheckBox (panel, wxID_ANY, _("Burn subtitles into image"));
556 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
559 _three_d = new wxCheckBox (panel, wxID_ANY, _("3D"));
560 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
563 add_label_to_grid_bag_sizer (grid, panel, _("Resolution"), true, wxGBPosition (r, 0));
564 _resolution = new wxChoice (panel, wxID_ANY);
565 grid->Add (_resolution, wxGBPosition (r, 1));
569 add_label_to_grid_bag_sizer (grid, panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
570 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
571 _j2k_bandwidth = new wxSpinCtrl (panel, wxID_ANY);
572 s->Add (_j2k_bandwidth, 1);
573 add_label_to_sizer (s, panel, _("Mbit/s"), false);
574 grid->Add (s, wxGBPosition (r, 1));
578 add_label_to_grid_bag_sizer (grid, panel, _("Scaler"), true, wxGBPosition (r, 0));
579 _scaler = new wxChoice (panel, wxID_ANY);
580 grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
583 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::container_changed, this));
584 _scaler->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::scaler_changed, this));
585 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::frame_rate_choice_changed, this));
586 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::frame_rate_spin_changed, this));
587 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DCPPanel::best_frame_rate_clicked, this));
588 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::burn_subtitles_toggled, this));
589 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::j2k_bandwidth_changed, this));
590 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DCPPanel::resolution_changed, this));
591 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&DCPPanel::three_d_changed, this));
593 vector<Scaler const *> const sc = Scaler::all ();
594 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
595 _scaler->Append (std_to_wx ((*i)->name()));
598 vector<Ratio const *> const ratio = Ratio::all ();
599 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
600 _container->Append (std_to_wx ((*i)->nickname ()));
603 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
604 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
605 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
608 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
609 _frame_rate_spin->SetRange (1, 480);
611 _resolution->Append (_("2K"));
612 _resolution->Append (_("4K"));
618 DCPPanel::make_audio_panel ()
620 wxPanel* panel = new wxPanel (_notebook);
621 wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
622 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
623 sizer->Add (grid, 0, wxALL, 8);
624 panel->SetSizer (sizer);
627 add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
628 _audio_channels = new wxSpinCtrl (panel, wxID_ANY);
629 grid->Add (_audio_channels, wxGBPosition (r, 1));
632 _audio_channels->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DCPPanel::audio_channels_changed, this));
634 _audio_channels->SetRange (0, MAX_DCP_AUDIO_CHANNELS);
640 DCPPanel::copy_isdcf_name_button_clicked ()
642 _film->set_name (_film->isdcf_name (false));
643 _film->set_use_isdcf_name (false);