2 Copyright (C) 2012 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>
32 #include "lib/format.h"
34 #include "lib/transcode_job.h"
35 #include "lib/exceptions.h"
36 #include "lib/ab_transcode_job.h"
37 #include "lib/job_manager.h"
38 #include "lib/filter.h"
39 #include "lib/config.h"
40 #include "lib/ffmpeg_decoder.h"
41 #include "lib/imagemagick_content.h"
42 #include "lib/sndfile_content.h"
43 #include "lib/dcp_content_type.h"
44 #include "filter_dialog.h"
46 #include "film_editor.h"
47 #include "gain_calculator_dialog.h"
48 #include "sound_processor.h"
49 #include "dci_metadata_dialog.h"
51 #include "audio_dialog.h"
55 using std::stringstream;
58 using std::setprecision;
61 using boost::shared_ptr;
62 using boost::weak_ptr;
63 using boost::dynamic_pointer_cast;
64 using boost::lexical_cast;
66 /** @param f Film to edit */
67 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
69 , _generally_sensitive (true)
72 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
73 _notebook = new wxNotebook (this, wxID_ANY);
74 s->Add (_notebook, 1);
77 _notebook->AddPage (_film_panel, _("Film"), true);
78 make_content_panel ();
79 _notebook->AddPage (_content_panel, _("Content"), false);
81 _notebook->AddPage (_video_panel, _("Video"), false);
83 _notebook->AddPage (_audio_panel, _("Audio"), false);
84 make_subtitle_panel ();
85 _notebook->AddPage (_subtitle_panel, _("Subtitles"), false);
88 connect_to_widgets ();
90 JobManager::instance()->ActiveJobsChanged.connect (
91 bind (&FilmEditor::active_jobs_changed, this, _1)
100 FilmEditor::make_film_panel ()
102 _film_panel = new wxPanel (_notebook);
103 _film_sizer = new wxBoxSizer (wxVERTICAL);
104 _film_panel->SetSizer (_film_sizer);
106 wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
107 _film_sizer->Add (grid, 0, wxALL, 8);
111 add_label_to_grid_bag_sizer (grid, _film_panel, _("Name"), wxGBPosition (r, 0));
112 _name = new wxTextCtrl (_film_panel, wxID_ANY);
113 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
116 add_label_to_grid_bag_sizer (grid, _film_panel, _("DCP Name"), wxGBPosition (r, 0));
117 _dcp_name = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
118 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
121 _use_dci_name = new wxCheckBox (_film_panel, wxID_ANY, _("Use DCI name"));
122 grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
123 _edit_dci_button = new wxButton (_film_panel, wxID_ANY, _("Details..."));
124 grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
127 _trust_content_headers = new wxCheckBox (_film_panel, wxID_ANY, _("Trust content's header"));
128 grid->Add (_trust_content_headers, wxGBPosition (r, 0), wxGBSpan(1, 2));
131 add_label_to_grid_bag_sizer (grid, _film_panel, _("Content Type"), wxGBPosition (r, 0));
132 _dcp_content_type = new wxChoice (_film_panel, wxID_ANY);
133 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
137 add_label_to_grid_bag_sizer (grid, _film_panel, _("DCP Frame Rate"), wxGBPosition (r, 0));
138 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
139 _dcp_frame_rate = new wxChoice (_film_panel, wxID_ANY);
140 s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
141 _best_dcp_frame_rate = new wxButton (_film_panel, wxID_ANY, _("Use best"));
142 s->Add (_best_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 6);
143 grid->Add (s, wxGBPosition (r, 1));
147 _frame_rate_description = new wxStaticText (_film_panel, wxID_ANY, wxT (" \n "), wxDefaultPosition, wxDefaultSize);
148 grid->Add (_frame_rate_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
149 wxFont font = _frame_rate_description->GetFont();
150 font.SetStyle(wxFONTSTYLE_ITALIC);
151 font.SetPointSize(font.GetPointSize() - 1);
152 _frame_rate_description->SetFont(font);
155 add_label_to_grid_bag_sizer (grid, _film_panel, _("Length"), wxGBPosition (r, 0));
156 _length = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
157 grid->Add (_length, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
162 add_label_to_grid_bag_sizer (grid, _film_panel, _("Trim frames"), wxGBPosition (r, 0));
163 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
164 add_label_to_sizer (s, _film_panel, _("Start"));
165 _trim_start = new wxSpinCtrl (_film_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
166 s->Add (_trim_start);
167 add_label_to_sizer (s, _film_panel, _("End"));
168 _trim_end = new wxSpinCtrl (_film_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
171 grid->Add (s, wxGBPosition (r, 1));
175 _ab = new wxCheckBox (_film_panel, wxID_ANY, _("A/B"));
176 grid->Add (_ab, wxGBPosition (r, 0));
179 vector<DCPContentType const *> const ct = DCPContentType::all ();
180 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
181 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
184 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
185 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
186 _dcp_frame_rate->Append (std_to_wx (boost::lexical_cast<string> (*i)));
191 FilmEditor::connect_to_widgets ()
193 _name->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (FilmEditor::name_changed), 0, this);
194 _use_dci_name->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::use_dci_name_toggled), 0, this);
195 _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
196 _format->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this);
197 _trust_content_headers->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::trust_content_headers_changed), 0, this);
198 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_item_selected), 0, this);
199 _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
200 _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
201 _content_earlier->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_earlier_clicked), 0, this);
202 _content_later->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_later_clicked), 0, this);
203 _imagemagick_video_length->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::imagemagick_video_length_changed), 0, this);
204 _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
205 _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
206 _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
207 _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
208 _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
209 _scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
210 _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
211 _dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
212 _best_dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
213 _ab->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::ab_toggled), 0, this);
214 _trim_start->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::trim_start_changed), 0, this);
215 _trim_end->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::trim_end_changed), 0, this);
216 _with_subtitles->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
217 _subtitle_offset->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_offset_changed), 0, this);
218 _subtitle_scale->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this);
219 _colour_lut->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::colour_lut_changed), 0, this);
220 _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_changed), 0, this);
221 _ffmpeg_subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ffmpeg_subtitle_stream_changed), 0, this);
222 _ffmpeg_audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ffmpeg_audio_stream_changed), 0, this);
223 _audio_gain->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_gain_changed), 0, this);
224 _audio_gain_calculate_button->Connect (
225 wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::audio_gain_calculate_button_clicked), 0, this
227 _show_audio->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::show_audio_clicked), 0, this);
228 _audio_delay->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
232 FilmEditor::make_video_panel ()
234 _video_panel = new wxPanel (_notebook);
235 _video_sizer = new wxBoxSizer (wxVERTICAL);
236 _video_panel->SetSizer (_video_sizer);
238 wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
239 _video_sizer->Add (grid, 0, wxALL, 8);
242 add_label_to_grid_bag_sizer (grid, _video_panel, _("Format"), wxGBPosition (r, 0));
243 _format = new wxChoice (_video_panel, wxID_ANY);
244 grid->Add (_format, wxGBPosition (r, 1));
247 _format_description = new wxStaticText (_video_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize);
248 grid->Add (_format_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
249 wxFont font = _format_description->GetFont();
250 font.SetStyle(wxFONTSTYLE_ITALIC);
251 font.SetPointSize(font.GetPointSize() - 1);
252 _format_description->SetFont(font);
255 add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0));
256 _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
257 grid->Add (_left_crop, wxGBPosition (r, 1));
260 add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), wxGBPosition (r, 0));
261 _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
262 grid->Add (_right_crop, wxGBPosition (r, 1));
265 add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), wxGBPosition (r, 0));
266 _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
267 grid->Add (_top_crop, wxGBPosition (r, 1));
270 add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), wxGBPosition (r, 0));
271 _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
272 grid->Add (_bottom_crop, wxGBPosition (r, 1));
275 /* VIDEO-only stuff */
277 add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), wxGBPosition (r, 0));
278 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
279 _filters = new wxStaticText (_video_panel, wxID_ANY, _("None"));
280 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
281 _filters_button = new wxButton (_video_panel, wxID_ANY, _("Edit..."));
282 s->Add (_filters_button, 0);
283 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
287 add_label_to_grid_bag_sizer (grid, _video_panel, _("Scaler"), wxGBPosition (r, 0));
288 _scaler = new wxChoice (_video_panel, wxID_ANY);
289 grid->Add (_scaler, wxGBPosition (r, 1));
292 vector<Scaler const *> const sc = Scaler::all ();
293 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
294 _scaler->Append (std_to_wx ((*i)->name()));
297 add_label_to_grid_bag_sizer (grid, _video_panel, _("Colour look-up table"), wxGBPosition (r, 0));
298 _colour_lut = new wxChoice (_video_panel, wxID_ANY);
299 for (int i = 0; i < 2; ++i) {
300 _colour_lut->Append (std_to_wx (colour_lut_index_to_name (i)));
302 _colour_lut->SetSelection (0);
303 grid->Add (_colour_lut, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
307 add_label_to_grid_bag_sizer (grid, _video_panel, _("JPEG2000 bandwidth"), wxGBPosition (r, 0));
308 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
309 _j2k_bandwidth = new wxSpinCtrl (_video_panel, wxID_ANY);
310 s->Add (_j2k_bandwidth, 1);
311 add_label_to_sizer (s, _video_panel, _("MBps"));
312 grid->Add (s, wxGBPosition (r, 1));
316 _left_crop->SetRange (0, 1024);
317 _top_crop->SetRange (0, 1024);
318 _right_crop->SetRange (0, 1024);
319 _bottom_crop->SetRange (0, 1024);
320 _trim_start->SetRange (0, 100);
321 _trim_end->SetRange (0, 100);
322 _j2k_bandwidth->SetRange (50, 250);
326 FilmEditor::make_content_panel ()
328 _content_panel = new wxPanel (_notebook);
329 _content_sizer = new wxBoxSizer (wxVERTICAL);
330 _content_panel->SetSizer (_content_sizer);
333 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
335 _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
336 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
338 _content->InsertColumn (0, wxT(""));
339 _content->SetColumnWidth (0, 512);
341 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
342 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
343 b->Add (_content_add);
344 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
345 b->Add (_content_remove);
346 _content_earlier = new wxButton (_content_panel, wxID_ANY, _("Earlier"));
347 b->Add (_content_earlier);
348 _content_later = new wxButton (_content_panel, wxID_ANY, _("Later"));
349 b->Add (_content_later);
351 s->Add (b, 0, wxALL, 4);
353 _content_sizer->Add (s, 1, wxEXPAND | wxALL, 6);
356 _content_information = new wxTextCtrl (_content_panel, wxID_ANY, wxT ("\n\n\n\n"), wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxTE_MULTILINE);
357 _content_sizer->Add (_content_information, 1, wxEXPAND | wxALL, 6);
359 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
360 _content_sizer->Add (grid, 0, wxEXPAND | wxALL, 6);
363 add_label_to_sizer (grid, _content_panel, (_("Duration")));
364 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
365 _imagemagick_video_length = new wxSpinCtrl (_content_panel);
366 s->Add (_imagemagick_video_length);
367 /// TRANSLATORS: this is an abbreviation for seconds, the unit of time
368 add_label_to_sizer (s, _content_panel, _("s"));
372 _imagemagick_video_length->SetRange (1, 3600);
376 FilmEditor::make_audio_panel ()
378 _audio_panel = new wxPanel (_notebook);
379 _audio_sizer = new wxBoxSizer (wxVERTICAL);
380 _audio_panel->SetSizer (_audio_sizer);
382 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
383 _audio_sizer->Add (grid, 0, wxALL, 8);
385 _show_audio = new wxButton (_audio_panel, wxID_ANY, _("Show Audio..."));
386 grid->Add (_show_audio, 1);
390 add_label_to_sizer (grid, _audio_panel, _("Audio Gain"));
391 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
392 _audio_gain = new wxSpinCtrl (_audio_panel);
393 s->Add (_audio_gain, 1);
394 add_label_to_sizer (s, _audio_panel, _("dB"));
395 _audio_gain_calculate_button = new wxButton (_audio_panel, wxID_ANY, _("Calculate..."));
396 s->Add (_audio_gain_calculate_button, 1, wxEXPAND);
401 add_label_to_sizer (grid, _audio_panel, _("Audio Delay"));
402 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
403 _audio_delay = new wxSpinCtrl (_audio_panel);
404 s->Add (_audio_delay, 1);
405 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
406 add_label_to_sizer (s, _audio_panel, _("ms"));
411 add_label_to_sizer (grid, _audio_panel, _("Audio Stream"));
412 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
413 _ffmpeg_audio_stream = new wxChoice (_audio_panel, wxID_ANY);
414 s->Add (_ffmpeg_audio_stream, 1);
415 _audio = new wxStaticText (_audio_panel, wxID_ANY, wxT (""));
416 s->Add (_audio, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
417 grid->Add (s, 1, wxEXPAND);
420 _audio_gain->SetRange (-60, 60);
421 _audio_delay->SetRange (-1000, 1000);
425 FilmEditor::make_subtitle_panel ()
427 _subtitle_panel = new wxPanel (_notebook);
428 _subtitle_sizer = new wxBoxSizer (wxVERTICAL);
429 _subtitle_panel->SetSizer (_subtitle_sizer);
430 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
431 _subtitle_sizer->Add (grid, 0, wxALL, 8);
433 _with_subtitles = new wxCheckBox (_subtitle_panel, wxID_ANY, _("With Subtitles"));
434 grid->Add (_with_subtitles, 1);
436 _ffmpeg_subtitle_stream = new wxChoice (_subtitle_panel, wxID_ANY);
437 grid->Add (_ffmpeg_subtitle_stream);
439 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset"));
440 _subtitle_offset = new wxSpinCtrl (_subtitle_panel);
441 grid->Add (_subtitle_offset, 1);
444 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Scale"));
445 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
446 _subtitle_scale = new wxSpinCtrl (_subtitle_panel);
447 s->Add (_subtitle_scale);
448 add_label_to_sizer (s, _subtitle_panel, _("%"));
452 _subtitle_offset->SetRange (-1024, 1024);
453 _subtitle_scale->SetRange (1, 1000);
456 /** Called when the left crop widget has been changed */
458 FilmEditor::left_crop_changed (wxCommandEvent &)
464 _film->set_left_crop (_left_crop->GetValue ());
467 /** Called when the right crop widget has been changed */
469 FilmEditor::right_crop_changed (wxCommandEvent &)
475 _film->set_right_crop (_right_crop->GetValue ());
478 /** Called when the top crop widget has been changed */
480 FilmEditor::top_crop_changed (wxCommandEvent &)
486 _film->set_top_crop (_top_crop->GetValue ());
489 /** Called when the bottom crop value has been changed */
491 FilmEditor::bottom_crop_changed (wxCommandEvent &)
497 _film->set_bottom_crop (_bottom_crop->GetValue ());
501 FilmEditor::trust_content_headers_changed (wxCommandEvent &)
507 _film->set_trust_content_headers (_trust_content_headers->GetValue ());
510 /** Called when the DCP A/B switch has been toggled */
512 FilmEditor::ab_toggled (wxCommandEvent &)
518 _film->set_ab (_ab->GetValue ());
521 /** Called when the name widget has been changed */
523 FilmEditor::name_changed (wxCommandEvent &)
529 _film->set_name (string (_name->GetValue().mb_str()));
533 FilmEditor::subtitle_offset_changed (wxCommandEvent &)
539 _film->set_subtitle_offset (_subtitle_offset->GetValue ());
543 FilmEditor::subtitle_scale_changed (wxCommandEvent &)
549 _film->set_subtitle_scale (_subtitle_scale->GetValue() / 100.0);
553 FilmEditor::colour_lut_changed (wxCommandEvent &)
559 _film->set_colour_lut (_colour_lut->GetSelection ());
563 FilmEditor::j2k_bandwidth_changed (wxCommandEvent &)
569 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
573 FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
579 _film->set_dcp_frame_rate (
580 boost::lexical_cast<int> (
581 wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
587 /** Called when the metadata stored in the Film object has changed;
588 * so that we can update the GUI.
589 * @param p Property of the Film that has changed.
592 FilmEditor::film_changed (Film::Property p)
609 setup_subtitle_control_sensitivity ();
611 setup_show_audio_sensitivity ();
614 case Film::TRUST_CONTENT_HEADERS:
615 checked_set (_trust_content_headers, _film->trust_content_headers ());
621 checked_set (_left_crop, _film->crop().left);
622 checked_set (_right_crop, _film->crop().right);
623 checked_set (_top_crop, _film->crop().top);
624 checked_set (_bottom_crop, _film->crop().bottom);
628 pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
629 if (p.first.empty () && p.second.empty ()) {
630 _filters->SetLabel (_("None"));
632 string const b = p.first + " " + p.second;
633 _filters->SetLabel (std_to_wx (b));
635 _film_sizer->Layout ();
639 checked_set (_name, _film->name());
642 case Film::DCP_CONTENT_TYPE:
643 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
647 checked_set (_ab, _film->ab ());
650 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
652 case Film::TRIM_START:
653 checked_set (_trim_start, _film->trim_start());
656 checked_set (_trim_end, _film->trim_end());
658 case Film::AUDIO_GAIN:
659 checked_set (_audio_gain, _film->audio_gain ());
661 case Film::AUDIO_DELAY:
662 checked_set (_audio_delay, _film->audio_delay ());
664 case Film::WITH_SUBTITLES:
665 checked_set (_with_subtitles, _film->with_subtitles ());
666 setup_subtitle_control_sensitivity ();
669 case Film::SUBTITLE_OFFSET:
670 checked_set (_subtitle_offset, _film->subtitle_offset ());
672 case Film::SUBTITLE_SCALE:
673 checked_set (_subtitle_scale, _film->subtitle_scale() * 100);
675 case Film::COLOUR_LUT:
676 checked_set (_colour_lut, _film->colour_lut ());
678 case Film::J2K_BANDWIDTH:
679 checked_set (_j2k_bandwidth, double (_film->j2k_bandwidth()) / 1e6);
681 case Film::USE_DCI_NAME:
682 checked_set (_use_dci_name, _film->use_dci_name ());
685 case Film::DCI_METADATA:
688 case Film::DCP_FRAME_RATE:
689 for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
690 if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_frame_rate())) {
691 if (_dcp_frame_rate->GetSelection() != int(i)) {
692 _dcp_frame_rate->SetSelection (i);
698 if (_film->video_frame_rate()) {
699 _frame_rate_description->SetLabel (std_to_wx (FrameRateConversion (_film->video_frame_rate(), _film->dcp_frame_rate()).description));
700 _best_dcp_frame_rate->Enable (best_dcp_frame_rate (_film->video_frame_rate ()) != _film->dcp_frame_rate ());
702 _frame_rate_description->SetLabel (wxT (""));
703 _best_dcp_frame_rate->Disable ();
709 FilmEditor::film_content_changed (weak_ptr<Content> content, int property)
712 /* We call this method ourselves (as well as using it as a signal handler)
718 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
719 setup_subtitle_control_sensitivity ();
721 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
723 setup_show_audio_sensitivity ();
724 } else if (property == VideoContentProperty::VIDEO_LENGTH) {
727 boost::shared_ptr<Content> c = content.lock ();
728 if (c && c == selected_content()) {
729 setup_content_information ();
730 shared_ptr<ImageMagickContent> im = dynamic_pointer_cast<ImageMagickContent> (c);
732 checked_set (_imagemagick_video_length, im->video_length() / 24);
735 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
736 if (_film->ffmpeg_audio_stream()) {
737 checked_set (_ffmpeg_audio_stream, boost::lexical_cast<string> (_film->ffmpeg_audio_stream()->id));
740 setup_audio_details ();
741 setup_show_audio_sensitivity ();
742 } else if (property == FFmpegContentProperty::SUBTITLE_STREAM) {
743 if (_film->ffmpeg_subtitle_stream()) {
744 checked_set (_ffmpeg_subtitle_stream, boost::lexical_cast<string> (_film->ffmpeg_subtitle_stream()->id));
750 FilmEditor::setup_format ()
753 vector<Format const *>::iterator i = _formats.begin ();
754 while (i != _formats.end() && *i != _film->format ()) {
758 if (i == _formats.end()) {
759 checked_set (_format, -1);
761 checked_set (_format, n);
765 if (_film->format ()) {
766 _format_description->SetLabel (std_to_wx (_film->format()->description ()));
768 _format_description->SetLabel (wxT (""));
773 FilmEditor::setup_length ()
776 if (_film->video_frame_rate() > 0 && _film->video_length()) {
777 s << _film->video_length() << " "
778 << wx_to_std (_("frames")) << "; " << seconds_to_hms (_film->video_length() / _film->video_frame_rate());
779 } else if (_film->video_length()) {
780 s << _film->video_length() << " "
781 << wx_to_std (_("frames"));
783 _length->SetLabel (std_to_wx (s.str ()));
784 if (_film->video_length()) {
785 _trim_start->SetRange (0, _film->video_length());
786 _trim_end->SetRange (0, _film->video_length());
791 /** Called when the format widget has been changed */
793 FilmEditor::format_changed (wxCommandEvent &)
799 int const n = _format->GetSelection ();
801 assert (n < int (_formats.size()));
802 _film->set_format (_formats[n]);
806 /** Called when the DCP content type widget has been changed */
808 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
814 int const n = _dcp_content_type->GetSelection ();
815 if (n != wxNOT_FOUND) {
816 _film->set_dcp_content_type (DCPContentType::from_index (n));
820 /** Sets the Film that we are editing */
822 FilmEditor::set_film (shared_ptr<Film> f)
830 set_things_sensitive (_film != 0);
833 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
834 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1, _2));
838 FileChanged (_film->directory ());
844 _audio_dialog->set_film (_film);
847 film_changed (Film::NAME);
848 film_changed (Film::USE_DCI_NAME);
849 film_changed (Film::CONTENT);
850 film_changed (Film::TRUST_CONTENT_HEADERS);
851 film_changed (Film::DCP_CONTENT_TYPE);
852 film_changed (Film::FORMAT);
853 film_changed (Film::CROP);
854 film_changed (Film::FILTERS);
855 film_changed (Film::SCALER);
856 film_changed (Film::TRIM_START);
857 film_changed (Film::TRIM_END);
858 film_changed (Film::AB);
859 film_changed (Film::AUDIO_GAIN);
860 film_changed (Film::AUDIO_DELAY);
861 film_changed (Film::WITH_SUBTITLES);
862 film_changed (Film::SUBTITLE_OFFSET);
863 film_changed (Film::SUBTITLE_SCALE);
864 film_changed (Film::COLOUR_LUT);
865 film_changed (Film::J2K_BANDWIDTH);
866 film_changed (Film::DCI_METADATA);
867 film_changed (Film::DCP_FRAME_RATE);
869 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAMS);
870 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM);
871 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAMS);
872 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAM);
875 /** Updates the sensitivity of lots of widgets to a given value.
876 * @param s true to make sensitive, false to make insensitive.
879 FilmEditor::set_things_sensitive (bool s)
881 _generally_sensitive = s;
884 _use_dci_name->Enable (s);
885 _edit_dci_button->Enable (s);
887 _content->Enable (s);
888 _trust_content_headers->Enable (s);
889 _content->Enable (s);
890 _left_crop->Enable (s);
891 _right_crop->Enable (s);
892 _top_crop->Enable (s);
893 _bottom_crop->Enable (s);
894 _filters_button->Enable (s);
896 _ffmpeg_audio_stream->Enable (s);
897 _dcp_content_type->Enable (s);
898 _dcp_frame_rate->Enable (s);
899 _trim_start->Enable (s);
900 _trim_end->Enable (s);
902 _colour_lut->Enable (s);
903 _j2k_bandwidth->Enable (s);
904 _audio_gain->Enable (s);
905 _audio_gain_calculate_button->Enable (s);
906 _show_audio->Enable (s);
907 _audio_delay->Enable (s);
909 setup_subtitle_control_sensitivity ();
910 setup_show_audio_sensitivity ();
911 setup_content_button_sensitivity ();
914 /** Called when the `Edit filters' button has been clicked */
916 FilmEditor::edit_filters_clicked (wxCommandEvent &)
918 FilterDialog* d = new FilterDialog (this, _film->filters());
919 d->ActiveChanged.connect (bind (&Film::set_filters, _film, _1));
924 /** Called when the scaler widget has been changed */
926 FilmEditor::scaler_changed (wxCommandEvent &)
932 int const n = _scaler->GetSelection ();
934 _film->set_scaler (Scaler::from_index (n));
939 FilmEditor::audio_gain_changed (wxCommandEvent &)
945 _film->set_audio_gain (_audio_gain->GetValue ());
949 FilmEditor::audio_delay_changed (wxCommandEvent &)
955 _film->set_audio_delay (_audio_delay->GetValue ());
959 FilmEditor::trim_start_changed (wxCommandEvent &)
965 _film->set_trim_start (_trim_start->GetValue ());
969 FilmEditor::trim_end_changed (wxCommandEvent &)
975 _film->set_trim_end (_trim_end->GetValue ());
979 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
981 GainCalculatorDialog* d = new GainCalculatorDialog (this);
984 if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
989 _audio_gain->SetValue (
990 Config::instance()->sound_processor()->db_for_fader_change (
996 /* This appears to be necessary, as the change is not signalled,
999 wxCommandEvent dummy;
1000 audio_gain_changed (dummy);
1006 FilmEditor::setup_formats ()
1008 _formats = Format::all ();
1011 for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
1012 _format->Append (std_to_wx ((*i)->name ()));
1015 _film_sizer->Layout ();
1019 FilmEditor::with_subtitles_toggled (wxCommandEvent &)
1025 _film->set_with_subtitles (_with_subtitles->GetValue ());
1029 FilmEditor::setup_subtitle_control_sensitivity ()
1032 if (_generally_sensitive && _film) {
1033 h = !_film->ffmpeg_subtitle_streams().empty();
1036 _with_subtitles->Enable (h);
1040 j = _film->with_subtitles ();
1043 _ffmpeg_subtitle_stream->Enable (j);
1044 _subtitle_offset->Enable (j);
1045 _subtitle_scale->Enable (j);
1049 FilmEditor::use_dci_name_toggled (wxCommandEvent &)
1055 _film->set_use_dci_name (_use_dci_name->GetValue ());
1059 FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
1065 DCIMetadataDialog* d = new DCIMetadataDialog (this, _film->dci_metadata ());
1067 _film->set_dci_metadata (d->dci_metadata ());
1072 FilmEditor::setup_streams ()
1078 _ffmpeg_audio_stream->Clear ();
1079 vector<FFmpegAudioStream> a = _film->ffmpeg_audio_streams ();
1080 for (vector<FFmpegAudioStream>::iterator i = a.begin(); i != a.end(); ++i) {
1081 _ffmpeg_audio_stream->Append (std_to_wx (i->name), new wxStringClientData (std_to_wx (boost::lexical_cast<string> (i->id))));
1084 if (_film->ffmpeg_audio_stream()) {
1085 checked_set (_ffmpeg_audio_stream, boost::lexical_cast<string> (_film->ffmpeg_audio_stream()->id));
1088 _ffmpeg_subtitle_stream->Clear ();
1089 vector<FFmpegSubtitleStream> s = _film->ffmpeg_subtitle_streams ();
1090 for (vector<FFmpegSubtitleStream>::iterator i = s.begin(); i != s.end(); ++i) {
1091 _ffmpeg_subtitle_stream->Append (std_to_wx (i->name), new wxStringClientData (std_to_wx (boost::lexical_cast<string> (i->id))));
1094 if (_film->ffmpeg_subtitle_stream()) {
1095 checked_set (_ffmpeg_subtitle_stream, boost::lexical_cast<string> (_film->ffmpeg_subtitle_stream()->id));
1097 _ffmpeg_subtitle_stream->SetSelection (wxNOT_FOUND);
1102 FilmEditor::ffmpeg_audio_stream_changed (wxCommandEvent &)
1108 vector<FFmpegAudioStream> a = _film->ffmpeg_audio_streams ();
1109 vector<FFmpegAudioStream>::iterator i = a.begin ();
1110 string const s = string_client_data (_ffmpeg_audio_stream->GetClientObject (_ffmpeg_audio_stream->GetSelection ()));
1111 while (i != a.end() && lexical_cast<string> (i->id) != s) {
1115 if (i != a.end ()) {
1116 _film->set_ffmpeg_audio_stream (*i);
1121 FilmEditor::ffmpeg_subtitle_stream_changed (wxCommandEvent &)
1127 vector<FFmpegSubtitleStream> a = _film->ffmpeg_subtitle_streams ();
1128 vector<FFmpegSubtitleStream>::iterator i = a.begin ();
1129 string const s = string_client_data (_ffmpeg_subtitle_stream->GetClientObject (_ffmpeg_subtitle_stream->GetSelection ()));
1130 while (i != a.end() && lexical_cast<string> (i->id) != s) {
1134 if (i != a.end ()) {
1135 _film->set_ffmpeg_subtitle_stream (*i);
1140 FilmEditor::setup_audio_details ()
1142 if (!_film->ffmpeg_audio_stream()) {
1143 _audio->SetLabel (wxT (""));
1146 if (_film->audio_channels() == 1) {
1147 s << wx_to_std (_("1 channel"));
1149 s << _film->audio_channels() << " " << wx_to_std (_("channels"));
1151 s << ", " << _film->audio_frame_rate() << wx_to_std (_("Hz"));
1152 _audio->SetLabel (std_to_wx (s.str ()));
1157 FilmEditor::active_jobs_changed (bool a)
1159 set_things_sensitive (!a);
1163 FilmEditor::setup_dcp_name ()
1165 string s = _film->dcp_name (true);
1166 if (s.length() > 28) {
1167 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
1168 _dcp_name->SetToolTip (std_to_wx (s));
1170 _dcp_name->SetLabel (std_to_wx (s));
1175 FilmEditor::show_audio_clicked (wxCommandEvent &)
1177 if (_audio_dialog) {
1178 _audio_dialog->Destroy ();
1182 _audio_dialog = new AudioDialog (this);
1183 _audio_dialog->Show ();
1184 _audio_dialog->set_film (_film);
1188 FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
1194 _film->set_dcp_frame_rate (best_dcp_frame_rate (_film->video_frame_rate ()));
1198 FilmEditor::setup_show_audio_sensitivity ()
1200 _show_audio->Enable (_film && _film->has_audio ());
1204 FilmEditor::setup_content ()
1206 string selected_summary;
1207 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1209 selected_summary = wx_to_std (_content->GetItemText (s));
1212 _content->DeleteAllItems ();
1214 ContentList content = _film->content ();
1215 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
1216 int const t = _content->GetItemCount ();
1217 _content->InsertItem (t, std_to_wx ((*i)->summary ()));
1218 if ((*i)->summary() == selected_summary) {
1219 _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1223 if (selected_summary.empty () && !content.empty ()) {
1224 /* Select the first item of content if non was selected before */
1225 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1230 FilmEditor::content_add_clicked (wxCommandEvent &)
1232 wxFileDialog* d = new wxFileDialog (this);
1233 int const r = d->ShowModal ();
1240 boost::filesystem::path p (wx_to_std (d->GetPath()));
1242 if (ImageMagickContent::valid_file (p)) {
1243 _film->add_content (shared_ptr<ImageMagickContent> (new ImageMagickContent (p)));
1244 } else if (SndfileContent::valid_file (p)) {
1245 _film->add_content (shared_ptr<SndfileContent> (new SndfileContent (p)));
1247 _film->add_content (shared_ptr<FFmpegContent> (new FFmpegContent (p)));
1253 FilmEditor::content_remove_clicked (wxCommandEvent &)
1255 shared_ptr<Content> c = selected_content ();
1257 _film->remove_content (c);
1262 FilmEditor::content_earlier_clicked (wxCommandEvent &)
1264 shared_ptr<Content> c = selected_content ();
1266 _film->move_content_earlier (c);
1271 FilmEditor::content_later_clicked (wxCommandEvent &)
1273 shared_ptr<Content> c = selected_content ();
1275 _film->move_content_later (c);
1280 FilmEditor::content_item_selected (wxListEvent &)
1282 setup_content_button_sensitivity ();
1283 setup_content_information ();
1285 shared_ptr<Content> c = selected_content ();
1287 shared_ptr<ImageMagickContent> im = dynamic_pointer_cast<ImageMagickContent> (c);
1288 _imagemagick_video_length->Enable (im);
1290 checked_set (_imagemagick_video_length, im->video_length() / 24);
1296 FilmEditor::setup_content_information ()
1298 shared_ptr<Content> c = selected_content ();
1300 _content_information->SetValue (wxT (""));
1304 _content_information->SetValue (std_to_wx (c->information ()));
1308 FilmEditor::setup_content_button_sensitivity ()
1310 _content_add->Enable (_generally_sensitive);
1312 bool const have_selection = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1;
1313 _content_remove->Enable (have_selection && _generally_sensitive);
1314 _content_earlier->Enable (have_selection && _generally_sensitive);
1315 _content_later->Enable (have_selection && _generally_sensitive);
1319 FilmEditor::imagemagick_video_length_changed (wxCommandEvent &)
1321 shared_ptr<Content> c = selected_content ();
1326 shared_ptr<ImageMagickContent> im = dynamic_pointer_cast<ImageMagickContent> (c);
1331 im->set_video_length (_imagemagick_video_length->GetValue() * 24);
1335 FilmEditor::selected_content ()
1337 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1339 return shared_ptr<Content> ();
1342 ContentList c = _film->content ();
1343 assert (s >= 0 && size_t (s) < c.size ());