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 /** @file src/film_editor.cc
21 * @brief A wx widget to edit a film's metadata, and perform various functions.
27 #include <wx/notebook.h>
28 #include <wx/listctrl.h>
29 #include <boost/thread.hpp>
30 #include <boost/filesystem.hpp>
31 #include <boost/lexical_cast.hpp>
33 #include "lib/transcode_job.h"
34 #include "lib/exceptions.h"
35 #include "lib/job_manager.h"
36 #include "lib/filter.h"
37 #include "lib/ratio.h"
38 #include "lib/config.h"
39 #include "lib/image_content.h"
40 #include "lib/ffmpeg_content.h"
41 #include "lib/sndfile_content.h"
42 #include "lib/dcp_content_type.h"
43 #include "lib/scaler.h"
44 #include "lib/playlist.h"
45 #include "lib/content.h"
46 #include "lib/content_factory.h"
47 #include "lib/dcp_content.h"
50 #include "film_editor.h"
51 #include "isdcf_metadata_dialog.h"
52 #include "timeline_dialog.h"
53 #include "timing_panel.h"
54 #include "subtitle_panel.h"
55 #include "audio_panel.h"
56 #include "video_panel.h"
60 using std::stringstream;
63 using std::setprecision;
67 using boost::shared_ptr;
68 using boost::weak_ptr;
69 using boost::dynamic_pointer_cast;
70 using boost::lexical_cast;
72 /** @param f Film to edit */
73 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
75 , _generally_sensitive (true)
77 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
79 _main_notebook = new wxNotebook (this, wxID_ANY);
80 s->Add (_main_notebook, 1);
82 _content_panel = new ContentPanel (_main_notebook, _film);
83 _main_notebook->AddPage (_content_panel->panel (), _("Content"), true);
85 _main_notebook->AddPage (_dcp_panel, _("DCP"), false);
88 connect_to_widgets ();
90 JobManager::instance()->ActiveJobsChanged.connect (
91 bind (&FilmEditor::active_jobs_changed, this, _1)
94 Config::instance()->Changed.connect (boost::bind (&FilmEditor::config_changed, this));
100 FilmEditor::make_dcp_panel ()
102 _dcp_panel = new wxPanel (_main_notebook);
103 _dcp_sizer = new wxBoxSizer (wxVERTICAL);
104 _dcp_panel->SetSizer (_dcp_sizer);
106 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
107 _dcp_sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
111 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Name"), true, wxGBPosition (r, 0));
112 _name = new wxTextCtrl (_dcp_panel, wxID_ANY);
113 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
116 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), true, wxGBPosition (r, 0));
117 _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
118 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
121 int flags = wxALIGN_CENTER_VERTICAL;
123 flags |= wxALIGN_RIGHT;
126 _use_isdcf_name = new wxCheckBox (_dcp_panel, wxID_ANY, _("Use ISDCF name"));
127 grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
128 _edit_isdcf_button = new wxButton (_dcp_panel, wxID_ANY, _("Details..."));
129 grid->Add (_edit_isdcf_button, wxGBPosition (r, 1), wxDefaultSpan);
132 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), true, wxGBPosition (r, 0));
133 _container = new wxChoice (_dcp_panel, wxID_ANY);
134 grid->Add (_container, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
137 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Content Type"), true, wxGBPosition (r, 0));
138 _dcp_content_type = new wxChoice (_dcp_panel, wxID_ANY);
139 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
143 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Frame Rate"), true, wxGBPosition (r, 0));
144 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
145 _frame_rate_choice = new wxChoice (_dcp_panel, wxID_ANY);
146 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
147 _frame_rate_spin = new wxSpinCtrl (_dcp_panel, wxID_ANY);
148 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
149 setup_frame_rate_widget ();
150 _best_frame_rate = new wxButton (_dcp_panel, wxID_ANY, _("Use best"));
151 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
152 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
156 _burn_subtitles = new wxCheckBox (_dcp_panel, wxID_ANY, _("Burn subtitles into image"));
157 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
160 _signed = new wxCheckBox (_dcp_panel, wxID_ANY, _("Signed"));
161 grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
164 _encrypted = new wxCheckBox (_dcp_panel, wxID_ANY, _("Encrypted"));
165 grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
168 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Audio channels"), true, wxGBPosition (r, 0));
169 _audio_channels = new wxSpinCtrl (_dcp_panel, wxID_ANY);
170 grid->Add (_audio_channels, wxGBPosition (r, 1));
173 _three_d = new wxCheckBox (_dcp_panel, wxID_ANY, _("3D"));
174 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
177 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Resolution"), true, wxGBPosition (r, 0));
178 _resolution = new wxChoice (_dcp_panel, wxID_ANY);
179 grid->Add (_resolution, wxGBPosition (r, 1));
183 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
184 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
185 _j2k_bandwidth = new wxSpinCtrl (_dcp_panel, wxID_ANY);
186 s->Add (_j2k_bandwidth, 1);
187 add_label_to_sizer (s, _dcp_panel, _("Mbit/s"), false);
188 grid->Add (s, wxGBPosition (r, 1));
192 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Standard"), true, wxGBPosition (r, 0));
193 _standard = new wxChoice (_dcp_panel, wxID_ANY);
194 grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
197 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Scaler"), true, wxGBPosition (r, 0));
198 _scaler = new wxChoice (_dcp_panel, wxID_ANY);
199 grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
202 vector<Scaler const *> const sc = Scaler::all ();
203 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
204 _scaler->Append (std_to_wx ((*i)->name()));
207 vector<Ratio const *> const ratio = Ratio::all ();
208 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
209 _container->Append (std_to_wx ((*i)->nickname ()));
212 vector<DCPContentType const *> const ct = DCPContentType::all ();
213 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
214 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
217 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
218 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
219 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
222 _audio_channels->SetRange (0, MAX_DCP_AUDIO_CHANNELS);
223 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
224 _frame_rate_spin->SetRange (1, 480);
226 _resolution->Append (_("2K"));
227 _resolution->Append (_("4K"));
229 _standard->Append (_("SMPTE"));
230 _standard->Append (_("Interop"));
234 FilmEditor::connect_to_widgets ()
236 _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&FilmEditor::name_changed, this));
237 _use_isdcf_name->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::use_isdcf_name_toggled, this));
238 _edit_isdcf_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FilmEditor::edit_isdcf_button_clicked, this));
239 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::container_changed, this));
240 _scaler->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::scaler_changed, this));
241 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::dcp_content_type_changed, this));
242 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::frame_rate_choice_changed, this));
243 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&FilmEditor::frame_rate_spin_changed, this));
244 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FilmEditor::best_frame_rate_clicked, this));
245 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::burn_subtitles_toggled, this));
246 _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::signed_toggled, this));
247 _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::encrypted_toggled, this));
248 _audio_channels->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&FilmEditor::audio_channels_changed, this));
249 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&FilmEditor::j2k_bandwidth_changed, this));
250 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::resolution_changed, this));
251 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::three_d_changed, this));
252 _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::standard_changed, this));
255 /** Called when the name widget has been changed */
257 FilmEditor::name_changed ()
263 _film->set_name (string (_name->GetValue().mb_str()));
267 FilmEditor::j2k_bandwidth_changed ()
273 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
277 FilmEditor::signed_toggled ()
283 _film->set_signed (_signed->GetValue ());
287 FilmEditor::burn_subtitles_toggled ()
293 _film->set_burn_subtitles (_burn_subtitles->GetValue ());
297 FilmEditor::encrypted_toggled ()
303 _film->set_encrypted (_encrypted->GetValue ());
306 /** Called when the frame rate choice widget has been changed */
308 FilmEditor::frame_rate_choice_changed ()
314 _film->set_video_frame_rate (
315 boost::lexical_cast<int> (
316 wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
321 /** Called when the frame rate spin widget has been changed */
323 FilmEditor::frame_rate_spin_changed ()
329 _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
333 FilmEditor::audio_channels_changed ()
339 _film->set_audio_channels (_audio_channels->GetValue ());
343 FilmEditor::resolution_changed ()
349 _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
353 FilmEditor::standard_changed ()
359 _film->set_interop (_standard->GetSelection() == 1);
362 /** Called when the metadata stored in the Film object has changed;
363 * so that we can update the GUI.
364 * @param p Property of the Film that has changed.
367 FilmEditor::film_changed (Film::Property p)
377 _content_panel->film_changed (p);
382 case Film::CONTAINER:
386 checked_set (_name, _film->name());
389 case Film::DCP_CONTENT_TYPE:
390 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
394 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
396 case Film::BURN_SUBTITLES:
397 checked_set (_burn_subtitles, _film->burn_subtitles ());
400 checked_set (_signed, _film->is_signed ());
402 case Film::ENCRYPTED:
403 checked_set (_encrypted, _film->encrypted ());
404 if (_film->encrypted ()) {
405 _film->set_signed (true);
406 _signed->Enable (false);
408 _signed->Enable (_generally_sensitive);
411 case Film::RESOLUTION:
412 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
415 case Film::J2K_BANDWIDTH:
416 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
418 case Film::USE_ISDCF_NAME:
419 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
422 case Film::ISDCF_METADATA:
425 case Film::VIDEO_FRAME_RATE:
428 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
429 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
430 checked_set (_frame_rate_choice, i);
437 checked_set (_frame_rate_choice, -1);
440 _frame_rate_spin->SetValue (_film->video_frame_rate ());
442 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
445 case Film::AUDIO_CHANNELS:
446 checked_set (_audio_channels, _film->audio_channels ());
450 checked_set (_three_d, _film->three_d ());
454 checked_set (_standard, _film->interop() ? 1 : 0);
462 FilmEditor::film_content_changed (int property)
467 /* We call this method ourselves (as well as using it as a signal handler)
473 _content_panel->film_content_changed (property);
475 if (property == FFmpegContentProperty::AUDIO_STREAM || property == SubtitleContentProperty::USE_SUBTITLES) {
481 FilmEditor::setup_container ()
484 vector<Ratio const *> ratios = Ratio::all ();
485 vector<Ratio const *>::iterator i = ratios.begin ();
486 while (i != ratios.end() && *i != _film->container ()) {
491 if (i == ratios.end()) {
492 checked_set (_container, -1);
494 checked_set (_container, n);
500 /** Called when the container widget has been changed */
502 FilmEditor::container_changed ()
508 int const n = _container->GetSelection ();
510 vector<Ratio const *> ratios = Ratio::all ();
511 assert (n < int (ratios.size()));
512 _film->set_container (ratios[n]);
516 /** Called when the DCP content type widget has been changed */
518 FilmEditor::dcp_content_type_changed ()
524 int const n = _dcp_content_type->GetSelection ();
525 if (n != wxNOT_FOUND) {
526 _film->set_dcp_content_type (DCPContentType::from_index (n));
530 /** Sets the Film that we are editing */
532 FilmEditor::set_film (shared_ptr<Film> f)
534 set_general_sensitivity (f != 0);
542 _content_panel->set_film (_film);
545 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
546 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _2));
550 FileChanged (_film->directory ());
555 film_changed (Film::NAME);
556 film_changed (Film::USE_ISDCF_NAME);
557 film_changed (Film::CONTENT);
558 film_changed (Film::DCP_CONTENT_TYPE);
559 film_changed (Film::CONTAINER);
560 film_changed (Film::RESOLUTION);
561 film_changed (Film::SCALER);
562 film_changed (Film::SIGNED);
563 film_changed (Film::BURN_SUBTITLES);
564 film_changed (Film::ENCRYPTED);
565 film_changed (Film::J2K_BANDWIDTH);
566 film_changed (Film::ISDCF_METADATA);
567 film_changed (Film::VIDEO_FRAME_RATE);
568 film_changed (Film::AUDIO_CHANNELS);
569 film_changed (Film::SEQUENCE_VIDEO);
570 film_changed (Film::THREE_D);
571 film_changed (Film::INTEROP);
573 if (!_film->content().empty ()) {
574 _content_panel->set_selection (_film->content().front ());
579 FilmEditor::set_general_sensitivity (bool s)
581 _generally_sensitive = s;
583 _content_panel->set_general_sensitivity (s);
585 /* Stuff in the Content / DCP tabs */
587 _use_isdcf_name->Enable (s);
588 _edit_isdcf_button->Enable (s);
589 _dcp_content_type->Enable (s);
592 if (_film && _film->encrypted ()) {
595 _burn_subtitles->Enable (s);
596 _signed->Enable (si);
598 _encrypted->Enable (s);
599 _frame_rate_choice->Enable (s);
600 _frame_rate_spin->Enable (s);
601 _audio_channels->Enable (s);
602 _j2k_bandwidth->Enable (s);
603 _container->Enable (s);
604 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
605 _resolution->Enable (s);
607 _three_d->Enable (s);
608 _standard->Enable (s);
611 /** Called when the scaler widget has been changed */
613 FilmEditor::scaler_changed ()
619 int const n = _scaler->GetSelection ();
621 _film->set_scaler (Scaler::from_index (n));
626 FilmEditor::use_isdcf_name_toggled ()
632 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
636 FilmEditor::edit_isdcf_button_clicked ()
642 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (this, _film->isdcf_metadata ());
644 _film->set_isdcf_metadata (d->isdcf_metadata ());
649 FilmEditor::active_jobs_changed (bool a)
651 set_general_sensitivity (!a);
655 FilmEditor::setup_dcp_name ()
657 string s = _film->dcp_name (true);
658 if (s.length() > 28) {
659 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
660 _dcp_name->SetToolTip (std_to_wx (s));
662 _dcp_name->SetLabel (std_to_wx (s));
667 FilmEditor::best_frame_rate_clicked ()
673 _film->set_video_frame_rate (_film->best_video_frame_rate ());
677 FilmEditor::three_d_changed ()
683 _film->set_three_d (_three_d->GetValue ());
687 FilmEditor::config_changed ()
689 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
690 setup_frame_rate_widget ();
694 FilmEditor::setup_frame_rate_widget ()
696 if (Config::instance()->allow_any_dcp_frame_rate ()) {
697 _frame_rate_choice->Hide ();
698 _frame_rate_spin->Show ();
700 _frame_rate_choice->Show ();
701 _frame_rate_spin->Hide ();
704 _frame_rate_sizer->Layout ();