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"
57 #include "content_panel.h"
61 using std::stringstream;
64 using std::setprecision;
68 using boost::shared_ptr;
69 using boost::weak_ptr;
70 using boost::dynamic_pointer_cast;
71 using boost::lexical_cast;
73 /** @param f Film to edit */
74 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
76 , _generally_sensitive (true)
78 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
80 _main_notebook = new wxNotebook (this, wxID_ANY);
81 s->Add (_main_notebook, 1);
83 _content_panel = new ContentPanel (_main_notebook, _film);
84 _main_notebook->AddPage (_content_panel->panel (), _("Content"), true);
86 _main_notebook->AddPage (_dcp_panel, _("DCP"), false);
89 connect_to_widgets ();
91 JobManager::instance()->ActiveJobsChanged.connect (
92 bind (&FilmEditor::active_jobs_changed, this, _1)
95 Config::instance()->Changed.connect (boost::bind (&FilmEditor::config_changed, this));
101 FilmEditor::make_dcp_panel ()
103 _dcp_panel = new wxPanel (_main_notebook);
104 _dcp_sizer = new wxBoxSizer (wxVERTICAL);
105 _dcp_panel->SetSizer (_dcp_sizer);
107 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
108 _dcp_sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
112 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Name"), true, wxGBPosition (r, 0));
113 _name = new wxTextCtrl (_dcp_panel, wxID_ANY);
114 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
117 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), true, wxGBPosition (r, 0));
118 _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
119 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
122 int flags = wxALIGN_CENTER_VERTICAL;
124 flags |= wxALIGN_RIGHT;
127 _use_isdcf_name = new wxCheckBox (_dcp_panel, wxID_ANY, _("Use ISDCF name"));
128 grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
129 _edit_isdcf_button = new wxButton (_dcp_panel, wxID_ANY, _("Details..."));
130 grid->Add (_edit_isdcf_button, wxGBPosition (r, 1), wxDefaultSpan);
133 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), true, wxGBPosition (r, 0));
134 _container = new wxChoice (_dcp_panel, wxID_ANY);
135 grid->Add (_container, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
138 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Content Type"), true, wxGBPosition (r, 0));
139 _dcp_content_type = new wxChoice (_dcp_panel, wxID_ANY);
140 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
144 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Frame Rate"), true, wxGBPosition (r, 0));
145 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
146 _frame_rate_choice = new wxChoice (_dcp_panel, wxID_ANY);
147 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
148 _frame_rate_spin = new wxSpinCtrl (_dcp_panel, wxID_ANY);
149 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
150 setup_frame_rate_widget ();
151 _best_frame_rate = new wxButton (_dcp_panel, wxID_ANY, _("Use best"));
152 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
153 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
157 _burn_subtitles = new wxCheckBox (_dcp_panel, wxID_ANY, _("Burn subtitles into image"));
158 grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
161 _signed = new wxCheckBox (_dcp_panel, wxID_ANY, _("Signed"));
162 grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
165 _encrypted = new wxCheckBox (_dcp_panel, wxID_ANY, _("Encrypted"));
166 grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
169 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Audio channels"), true, wxGBPosition (r, 0));
170 _audio_channels = new wxSpinCtrl (_dcp_panel, wxID_ANY);
171 grid->Add (_audio_channels, wxGBPosition (r, 1));
174 _three_d = new wxCheckBox (_dcp_panel, wxID_ANY, _("3D"));
175 grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
178 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Resolution"), true, wxGBPosition (r, 0));
179 _resolution = new wxChoice (_dcp_panel, wxID_ANY);
180 grid->Add (_resolution, wxGBPosition (r, 1));
184 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
185 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
186 _j2k_bandwidth = new wxSpinCtrl (_dcp_panel, wxID_ANY);
187 s->Add (_j2k_bandwidth, 1);
188 add_label_to_sizer (s, _dcp_panel, _("Mbit/s"), false);
189 grid->Add (s, wxGBPosition (r, 1));
193 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Standard"), true, wxGBPosition (r, 0));
194 _standard = new wxChoice (_dcp_panel, wxID_ANY);
195 grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
198 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Scaler"), true, wxGBPosition (r, 0));
199 _scaler = new wxChoice (_dcp_panel, wxID_ANY);
200 grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
203 vector<Scaler const *> const sc = Scaler::all ();
204 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
205 _scaler->Append (std_to_wx ((*i)->name()));
208 vector<Ratio const *> const ratio = Ratio::all ();
209 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
210 _container->Append (std_to_wx ((*i)->nickname ()));
213 vector<DCPContentType const *> const ct = DCPContentType::all ();
214 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
215 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
218 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
219 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
220 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
223 _audio_channels->SetRange (0, MAX_DCP_AUDIO_CHANNELS);
224 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
225 _frame_rate_spin->SetRange (1, 480);
227 _resolution->Append (_("2K"));
228 _resolution->Append (_("4K"));
230 _standard->Append (_("SMPTE"));
231 _standard->Append (_("Interop"));
235 FilmEditor::connect_to_widgets ()
237 _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&FilmEditor::name_changed, this));
238 _use_isdcf_name->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::use_isdcf_name_toggled, this));
239 _edit_isdcf_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FilmEditor::edit_isdcf_button_clicked, this));
240 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::container_changed, this));
241 _scaler->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::scaler_changed, this));
242 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::dcp_content_type_changed, this));
243 _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::frame_rate_choice_changed, this));
244 _frame_rate_spin->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&FilmEditor::frame_rate_spin_changed, this));
245 _best_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FilmEditor::best_frame_rate_clicked, this));
246 _burn_subtitles->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::burn_subtitles_toggled, this));
247 _signed->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::signed_toggled, this));
248 _encrypted->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::encrypted_toggled, this));
249 _audio_channels->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&FilmEditor::audio_channels_changed, this));
250 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&FilmEditor::j2k_bandwidth_changed, this));
251 _resolution->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::resolution_changed, this));
252 _three_d->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&FilmEditor::three_d_changed, this));
253 _standard->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&FilmEditor::standard_changed, this));
256 /** Called when the name widget has been changed */
258 FilmEditor::name_changed ()
264 _film->set_name (string (_name->GetValue().mb_str()));
268 FilmEditor::j2k_bandwidth_changed ()
274 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
278 FilmEditor::signed_toggled ()
284 _film->set_signed (_signed->GetValue ());
288 FilmEditor::burn_subtitles_toggled ()
294 _film->set_burn_subtitles (_burn_subtitles->GetValue ());
298 FilmEditor::encrypted_toggled ()
304 _film->set_encrypted (_encrypted->GetValue ());
307 /** Called when the frame rate choice widget has been changed */
309 FilmEditor::frame_rate_choice_changed ()
315 _film->set_video_frame_rate (
316 boost::lexical_cast<int> (
317 wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
322 /** Called when the frame rate spin widget has been changed */
324 FilmEditor::frame_rate_spin_changed ()
330 _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
334 FilmEditor::audio_channels_changed ()
340 _film->set_audio_channels (_audio_channels->GetValue ());
344 FilmEditor::resolution_changed ()
350 _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
354 FilmEditor::standard_changed ()
360 _film->set_interop (_standard->GetSelection() == 1);
363 /** Called when the metadata stored in the Film object has changed;
364 * so that we can update the GUI.
365 * @param p Property of the Film that has changed.
368 FilmEditor::film_changed (Film::Property p)
378 _content_panel->film_changed (p);
383 case Film::CONTAINER:
387 checked_set (_name, _film->name());
390 case Film::DCP_CONTENT_TYPE:
391 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
395 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
397 case Film::BURN_SUBTITLES:
398 checked_set (_burn_subtitles, _film->burn_subtitles ());
401 checked_set (_signed, _film->is_signed ());
403 case Film::ENCRYPTED:
404 checked_set (_encrypted, _film->encrypted ());
405 if (_film->encrypted ()) {
406 _film->set_signed (true);
407 _signed->Enable (false);
409 _signed->Enable (_generally_sensitive);
412 case Film::RESOLUTION:
413 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
416 case Film::J2K_BANDWIDTH:
417 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
419 case Film::USE_ISDCF_NAME:
420 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
423 case Film::ISDCF_METADATA:
426 case Film::VIDEO_FRAME_RATE:
429 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
430 if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
431 checked_set (_frame_rate_choice, i);
438 checked_set (_frame_rate_choice, -1);
441 _frame_rate_spin->SetValue (_film->video_frame_rate ());
443 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
446 case Film::AUDIO_CHANNELS:
447 checked_set (_audio_channels, _film->audio_channels ());
451 checked_set (_three_d, _film->three_d ());
455 checked_set (_standard, _film->interop() ? 1 : 0);
463 FilmEditor::film_content_changed (int property)
468 /* We call this method ourselves (as well as using it as a signal handler)
474 _content_panel->film_content_changed (property);
476 if (property == FFmpegContentProperty::AUDIO_STREAM || property == SubtitleContentProperty::USE_SUBTITLES) {
482 FilmEditor::setup_container ()
485 vector<Ratio const *> ratios = Ratio::all ();
486 vector<Ratio const *>::iterator i = ratios.begin ();
487 while (i != ratios.end() && *i != _film->container ()) {
492 if (i == ratios.end()) {
493 checked_set (_container, -1);
495 checked_set (_container, n);
501 /** Called when the container widget has been changed */
503 FilmEditor::container_changed ()
509 int const n = _container->GetSelection ();
511 vector<Ratio const *> ratios = Ratio::all ();
512 assert (n < int (ratios.size()));
513 _film->set_container (ratios[n]);
517 /** Called when the DCP content type widget has been changed */
519 FilmEditor::dcp_content_type_changed ()
525 int const n = _dcp_content_type->GetSelection ();
526 if (n != wxNOT_FOUND) {
527 _film->set_dcp_content_type (DCPContentType::from_index (n));
531 /** Sets the Film that we are editing */
533 FilmEditor::set_film (shared_ptr<Film> f)
535 set_general_sensitivity (f != 0);
543 _content_panel->set_film (_film);
546 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
547 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _2));
551 FileChanged (_film->directory ());
556 film_changed (Film::NAME);
557 film_changed (Film::USE_ISDCF_NAME);
558 film_changed (Film::CONTENT);
559 film_changed (Film::DCP_CONTENT_TYPE);
560 film_changed (Film::CONTAINER);
561 film_changed (Film::RESOLUTION);
562 film_changed (Film::SCALER);
563 film_changed (Film::SIGNED);
564 film_changed (Film::BURN_SUBTITLES);
565 film_changed (Film::ENCRYPTED);
566 film_changed (Film::J2K_BANDWIDTH);
567 film_changed (Film::ISDCF_METADATA);
568 film_changed (Film::VIDEO_FRAME_RATE);
569 film_changed (Film::AUDIO_CHANNELS);
570 film_changed (Film::SEQUENCE_VIDEO);
571 film_changed (Film::THREE_D);
572 film_changed (Film::INTEROP);
574 if (!_film->content().empty ()) {
575 _content_panel->set_selection (_film->content().front ());
580 FilmEditor::set_general_sensitivity (bool s)
582 _generally_sensitive = s;
584 _content_panel->set_general_sensitivity (s);
586 /* Stuff in the Content / DCP tabs */
588 _use_isdcf_name->Enable (s);
589 _edit_isdcf_button->Enable (s);
590 _dcp_content_type->Enable (s);
593 if (_film && _film->encrypted ()) {
596 _burn_subtitles->Enable (s);
597 _signed->Enable (si);
599 _encrypted->Enable (s);
600 _frame_rate_choice->Enable (s);
601 _frame_rate_spin->Enable (s);
602 _audio_channels->Enable (s);
603 _j2k_bandwidth->Enable (s);
604 _container->Enable (s);
605 _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
606 _resolution->Enable (s);
608 _three_d->Enable (s);
609 _standard->Enable (s);
612 /** Called when the scaler widget has been changed */
614 FilmEditor::scaler_changed ()
620 int const n = _scaler->GetSelection ();
622 _film->set_scaler (Scaler::from_index (n));
627 FilmEditor::use_isdcf_name_toggled ()
633 _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
637 FilmEditor::edit_isdcf_button_clicked ()
643 ISDCFMetadataDialog* d = new ISDCFMetadataDialog (this, _film->isdcf_metadata ());
645 _film->set_isdcf_metadata (d->isdcf_metadata ());
650 FilmEditor::active_jobs_changed (bool a)
652 set_general_sensitivity (!a);
656 FilmEditor::setup_dcp_name ()
658 string s = _film->dcp_name (true);
659 if (s.length() > 28) {
660 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
661 _dcp_name->SetToolTip (std_to_wx (s));
663 _dcp_name->SetLabel (std_to_wx (s));
668 FilmEditor::best_frame_rate_clicked ()
674 _film->set_video_frame_rate (_film->best_video_frame_rate ());
678 FilmEditor::three_d_changed ()
684 _film->set_three_d (_three_d->GetValue ());
688 FilmEditor::config_changed ()
690 _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
691 setup_frame_rate_widget ();
695 FilmEditor::setup_frame_rate_widget ()
697 if (Config::instance()->allow_any_dcp_frame_rate ()) {
698 _frame_rate_choice->Hide ();
699 _frame_rate_spin->Show ();
701 _frame_rate_choice->Show ();
702 _frame_rate_spin->Hide ();
705 _frame_rate_sizer->Layout ();