1 /* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
4 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 /** @file src/film_editor.cc
23 * @brief A wx widget to edit a film's metadata, and perform various functions.
29 #include <wx/notebook.h>
30 #include <wx/listctrl.h>
31 #include <boost/thread.hpp>
32 #include <boost/filesystem.hpp>
33 #include <boost/lexical_cast.hpp>
34 #include "lib/format.h"
36 #include "lib/transcode_job.h"
37 #include "lib/exceptions.h"
38 #include "lib/ab_transcode_job.h"
39 #include "lib/job_manager.h"
40 #include "lib/filter.h"
41 #include "lib/config.h"
42 #include "lib/ffmpeg_decoder.h"
43 #include "lib/imagemagick_content.h"
44 #include "lib/sndfile_content.h"
45 #include "lib/dcp_content_type.h"
46 #include "filter_dialog.h"
48 #include "film_editor.h"
49 #include "gain_calculator_dialog.h"
50 #include "sound_processor.h"
51 #include "dci_metadata_dialog.h"
53 #include "audio_dialog.h"
54 #include "imagemagick_content_dialog.h"
55 #include "ffmpeg_content_dialog.h"
56 #include "audio_mapping_view.h"
57 #include "timeline_dialog.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 , _timeline_dialog (0)
80 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
81 _notebook = new wxNotebook (this, wxID_ANY);
82 s->Add (_notebook, 1);
85 _notebook->AddPage (_film_panel, _("Film"), true);
86 make_content_panel ();
87 _notebook->AddPage (_content_panel, _("Content"), false);
89 _notebook->AddPage (_video_panel, _("Video"), false);
91 _notebook->AddPage (_audio_panel, _("Audio"), false);
92 make_subtitle_panel ();
93 _notebook->AddPage (_subtitle_panel, _("Subtitles"), false);
98 connect_to_widgets ();
100 JobManager::instance()->ActiveJobsChanged.connect (
101 bind (&FilmEditor::active_jobs_changed, this, _1)
108 FilmEditor::make_film_panel ()
110 _film_panel = new wxPanel (_notebook);
111 _film_sizer = new wxBoxSizer (wxVERTICAL);
112 _film_panel->SetSizer (_film_sizer);
114 wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
115 _film_sizer->Add (grid, 0, wxALL, 8);
119 add_label_to_grid_bag_sizer (grid, _film_panel, _("Name"), wxGBPosition (r, 0));
120 _name = new wxTextCtrl (_film_panel, wxID_ANY);
121 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
124 add_label_to_grid_bag_sizer (grid, _film_panel, _("DCP Name"), wxGBPosition (r, 0));
125 _dcp_name = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
126 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
129 _use_dci_name = new wxCheckBox (_film_panel, wxID_ANY, _("Use DCI name"));
130 grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
131 _edit_dci_button = new wxButton (_film_panel, wxID_ANY, _("Details..."));
132 grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
135 _trust_content_headers = new wxCheckBox (_film_panel, wxID_ANY, _("Trust content headers"));
136 grid->Add (_trust_content_headers, wxGBPosition (r, 0), wxGBSpan(1, 2));
139 add_label_to_grid_bag_sizer (grid, _film_panel, _("Content Type"), wxGBPosition (r, 0));
140 _dcp_content_type = new wxChoice (_film_panel, wxID_ANY);
141 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
145 add_label_to_grid_bag_sizer (grid, _film_panel, _("DCP Frame Rate"), wxGBPosition (r, 0));
146 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
147 _dcp_frame_rate = new wxChoice (_film_panel, wxID_ANY);
148 s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
149 _best_dcp_frame_rate = new wxButton (_film_panel, wxID_ANY, _("Use best"));
150 s->Add (_best_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 6);
151 grid->Add (s, wxGBPosition (r, 1));
155 _frame_rate_description = new wxStaticText (_film_panel, wxID_ANY, wxT ("\n \n "), wxDefaultPosition, wxDefaultSize);
156 grid->Add (_frame_rate_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
157 wxFont font = _frame_rate_description->GetFont();
158 font.SetStyle(wxFONTSTYLE_ITALIC);
159 font.SetPointSize(font.GetPointSize() - 1);
160 _frame_rate_description->SetFont(font);
163 add_label_to_grid_bag_sizer (grid, _film_panel, _("Length"), wxGBPosition (r, 0));
164 _length = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
165 grid->Add (_length, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
168 add_label_to_grid_bag_sizer (grid, _film_panel, _("Trim method"), wxGBPosition (r, 0));
169 _trim_type = new wxChoice (_film_panel, wxID_ANY);
170 grid->Add (_trim_type, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
173 _ab = new wxCheckBox (_film_panel, wxID_ANY, _("A/B"));
174 grid->Add (_ab, wxGBPosition (r, 0));
177 vector<DCPContentType const *> const ct = DCPContentType::all ();
178 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
179 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
182 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
183 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
184 _dcp_frame_rate->Append (std_to_wx (boost::lexical_cast<string> (*i)));
187 _trim_type->Append (_("encode all frames and play the subset"));
188 _trim_type->Append (_("encode only the subset"));
192 FilmEditor::connect_to_widgets ()
194 _name->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (FilmEditor::name_changed), 0, this);
195 _use_dci_name->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::use_dci_name_toggled), 0, this);
196 _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
197 _format->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this);
198 _trust_content_headers->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::trust_content_headers_changed), 0, this);
199 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
200 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
201 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler (FilmEditor::content_activated), 0, this);
202 _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
203 _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
204 _content_properties->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_properties_clicked), 0, this);
205 _content_timeline->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_timeline_clicked), 0, this);
206 _loop_content->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::loop_content_toggled), 0, this);
207 _loop_count->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::loop_count_changed), 0, this);
208 _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
209 _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
210 _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
211 _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
212 _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
213 _scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
214 _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
215 _dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
216 _best_dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
217 _ab->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::ab_toggled), 0, this);
218 _trim_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::trim_type_changed), 0, this);
219 _with_subtitles->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
220 _subtitle_offset->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_offset_changed), 0, this);
221 _subtitle_scale->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this);
222 _colour_lut->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::colour_lut_changed), 0, this);
223 _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_changed), 0, this);
224 _audio_gain->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_gain_changed), 0, this);
225 _audio_gain_calculate_button->Connect (
226 wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::audio_gain_calculate_button_clicked), 0, this
228 _show_audio->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::show_audio_clicked), 0, this);
229 _audio_delay->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
233 FilmEditor::make_video_panel ()
235 _video_panel = new wxPanel (_notebook);
236 _video_sizer = new wxBoxSizer (wxVERTICAL);
237 _video_panel->SetSizer (_video_sizer);
239 wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
240 _video_sizer->Add (grid, 0, wxALL, 8);
243 add_label_to_grid_bag_sizer (grid, _video_panel, _("Format"), wxGBPosition (r, 0));
244 _format = new wxChoice (_video_panel, wxID_ANY);
245 grid->Add (_format, wxGBPosition (r, 1));
248 add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0));
249 _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
250 grid->Add (_left_crop, wxGBPosition (r, 1));
253 add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), wxGBPosition (r, 0));
254 _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
255 grid->Add (_right_crop, wxGBPosition (r, 1));
258 add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), wxGBPosition (r, 0));
259 _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
260 grid->Add (_top_crop, wxGBPosition (r, 1));
263 add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), wxGBPosition (r, 0));
264 _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
265 grid->Add (_bottom_crop, wxGBPosition (r, 1));
268 _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
269 grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
270 wxFont font = _scaling_description->GetFont();
271 font.SetStyle(wxFONTSTYLE_ITALIC);
272 font.SetPointSize(font.GetPointSize() - 1);
273 _scaling_description->SetFont(font);
276 /* VIDEO-only stuff */
278 add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), wxGBPosition (r, 0));
279 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
280 _filters = new wxStaticText (_video_panel, wxID_ANY, _("None"));
281 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
282 _filters_button = new wxButton (_video_panel, wxID_ANY, _("Edit..."));
283 s->Add (_filters_button, 0);
284 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
288 add_label_to_grid_bag_sizer (grid, _video_panel, _("Scaler"), wxGBPosition (r, 0));
289 _scaler = new wxChoice (_video_panel, wxID_ANY);
290 grid->Add (_scaler, wxGBPosition (r, 1));
293 vector<Scaler const *> const sc = Scaler::all ();
294 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
295 _scaler->Append (std_to_wx ((*i)->name()));
298 add_label_to_grid_bag_sizer (grid, _video_panel, _("Colour look-up table"), wxGBPosition (r, 0));
299 _colour_lut = new wxChoice (_video_panel, wxID_ANY);
300 for (int i = 0; i < 2; ++i) {
301 _colour_lut->Append (std_to_wx (colour_lut_index_to_name (i)));
303 _colour_lut->SetSelection (0);
304 grid->Add (_colour_lut, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
308 add_label_to_grid_bag_sizer (grid, _video_panel, _("JPEG2000 bandwidth"), wxGBPosition (r, 0));
309 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
310 _j2k_bandwidth = new wxSpinCtrl (_video_panel, wxID_ANY);
311 s->Add (_j2k_bandwidth, 1);
312 add_label_to_sizer (s, _video_panel, _("MBps"));
313 grid->Add (s, wxGBPosition (r, 1));
317 _left_crop->SetRange (0, 1024);
318 _top_crop->SetRange (0, 1024);
319 _right_crop->SetRange (0, 1024);
320 _bottom_crop->SetRange (0, 1024);
321 _j2k_bandwidth->SetRange (50, 250);
325 FilmEditor::make_content_panel ()
327 _content_panel = new wxPanel (_notebook);
328 _content_sizer = new wxBoxSizer (wxVERTICAL);
329 _content_panel->SetSizer (_content_sizer);
332 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
334 _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
335 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
337 _content->InsertColumn (0, wxT(""));
338 _content->SetColumnWidth (0, 512);
340 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
341 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
342 b->Add (_content_add, 1, wxEXPAND | wxLEFT | wxRIGHT);
343 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
344 b->Add (_content_remove, 1, wxEXPAND | wxLEFT | wxRIGHT);
345 _content_properties = new wxButton (_content_panel, wxID_ANY, _("Properties..."));
346 b->Add (_content_properties);
347 _content_timeline = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
348 b->Add (_content_timeline, 1, wxEXPAND | wxLEFT | wxRIGHT);
350 s->Add (b, 0, wxALL, 4);
352 _content_sizer->Add (s, 0.75, wxEXPAND | wxALL, 6);
355 _content_information = new wxTextCtrl (_content_panel, wxID_ANY, wxT ("\n \n "), wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxTE_MULTILINE);
356 _content_sizer->Add (_content_information, 1, wxEXPAND | wxALL, 6);
358 wxBoxSizer* h = new wxBoxSizer (wxHORIZONTAL);
359 _loop_content = new wxCheckBox (_content_panel, wxID_ANY, _("Loop everything"));
360 h->Add (_loop_content, 0, wxALL, 6);
361 _loop_count = new wxSpinCtrl (_content_panel, wxID_ANY);
362 h->Add (_loop_count, 0, wxALL, 6);
363 add_label_to_sizer (h, _content_panel, _("times"));
364 _content_sizer->Add (h, 0, wxALL, 6);
366 _loop_count->SetRange (2, 1024);
370 FilmEditor::make_audio_panel ()
372 _audio_panel = new wxPanel (_notebook);
373 _audio_sizer = new wxBoxSizer (wxVERTICAL);
374 _audio_panel->SetSizer (_audio_sizer);
376 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
377 _audio_sizer->Add (grid, 0, wxALL, 8);
379 _show_audio = new wxButton (_audio_panel, wxID_ANY, _("Show Audio..."));
380 grid->Add (_show_audio, 1);
384 add_label_to_sizer (grid, _audio_panel, _("Audio Gain"));
385 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
386 _audio_gain = new wxSpinCtrl (_audio_panel);
387 s->Add (_audio_gain, 1);
388 add_label_to_sizer (s, _audio_panel, _("dB"));
389 _audio_gain_calculate_button = new wxButton (_audio_panel, wxID_ANY, _("Calculate..."));
390 s->Add (_audio_gain_calculate_button, 1, wxEXPAND);
395 add_label_to_sizer (grid, _audio_panel, _("Audio Delay"));
396 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
397 _audio_delay = new wxSpinCtrl (_audio_panel);
398 s->Add (_audio_delay, 1);
399 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
400 add_label_to_sizer (s, _audio_panel, _("ms"));
404 _audio_mapping = new AudioMappingView (_audio_panel);
405 _audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6);
407 _audio_gain->SetRange (-60, 60);
408 _audio_delay->SetRange (-1000, 1000);
412 FilmEditor::make_subtitle_panel ()
414 _subtitle_panel = new wxPanel (_notebook);
415 _subtitle_sizer = new wxBoxSizer (wxVERTICAL);
416 _subtitle_panel->SetSizer (_subtitle_sizer);
417 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
418 _subtitle_sizer->Add (grid, 0, wxALL, 8);
420 _with_subtitles = new wxCheckBox (_subtitle_panel, wxID_ANY, _("With Subtitles"));
421 grid->Add (_with_subtitles, 1);
425 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset"));
426 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
427 _subtitle_offset = new wxSpinCtrl (_subtitle_panel);
428 s->Add (_subtitle_offset);
429 add_label_to_sizer (s, _subtitle_panel, _("pixels"));
434 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Scale"));
435 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
436 _subtitle_scale = new wxSpinCtrl (_subtitle_panel);
437 s->Add (_subtitle_scale);
438 add_label_to_sizer (s, _subtitle_panel, _("%"));
442 _subtitle_offset->SetRange (-1024, 1024);
443 _subtitle_scale->SetRange (1, 1000);
446 /** Called when the left crop widget has been changed */
448 FilmEditor::left_crop_changed (wxCommandEvent &)
454 _film->set_left_crop (_left_crop->GetValue ());
457 /** Called when the right crop widget has been changed */
459 FilmEditor::right_crop_changed (wxCommandEvent &)
465 _film->set_right_crop (_right_crop->GetValue ());
468 /** Called when the top crop widget has been changed */
470 FilmEditor::top_crop_changed (wxCommandEvent &)
476 _film->set_top_crop (_top_crop->GetValue ());
479 /** Called when the bottom crop value has been changed */
481 FilmEditor::bottom_crop_changed (wxCommandEvent &)
487 _film->set_bottom_crop (_bottom_crop->GetValue ());
491 FilmEditor::trust_content_headers_changed (wxCommandEvent &)
497 _film->set_trust_content_headers (_trust_content_headers->GetValue ());
500 /** Called when the DCP A/B switch has been toggled */
502 FilmEditor::ab_toggled (wxCommandEvent &)
508 _film->set_ab (_ab->GetValue ());
511 /** Called when the name widget has been changed */
513 FilmEditor::name_changed (wxCommandEvent &)
519 _film->set_name (string (_name->GetValue().mb_str()));
523 FilmEditor::subtitle_offset_changed (wxCommandEvent &)
529 _film->set_subtitle_offset (_subtitle_offset->GetValue ());
533 FilmEditor::subtitle_scale_changed (wxCommandEvent &)
539 _film->set_subtitle_scale (_subtitle_scale->GetValue() / 100.0);
543 FilmEditor::colour_lut_changed (wxCommandEvent &)
549 _film->set_colour_lut (_colour_lut->GetSelection ());
553 FilmEditor::j2k_bandwidth_changed (wxCommandEvent &)
559 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
563 FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
569 _film->set_dcp_video_frame_rate (
570 boost::lexical_cast<int> (
571 wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
577 /** Called when the metadata stored in the Film object has changed;
578 * so that we can update the GUI.
579 * @param p Property of the Film that has changed.
582 FilmEditor::film_changed (Film::Property p)
599 setup_subtitle_control_sensitivity ();
600 setup_show_audio_sensitivity ();
604 checked_set (_loop_content, _film->loop() > 1);
605 checked_set (_loop_count, _film->loop());
606 setup_loop_sensitivity ();
608 case Film::TRUST_CONTENT_HEADERS:
609 checked_set (_trust_content_headers, _film->trust_content_headers ());
615 checked_set (_left_crop, _film->crop().left);
616 checked_set (_right_crop, _film->crop().right);
617 checked_set (_top_crop, _film->crop().top);
618 checked_set (_bottom_crop, _film->crop().bottom);
619 setup_scaling_description ();
623 pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
624 if (p.first.empty () && p.second.empty ()) {
625 _filters->SetLabel (_("None"));
627 string const b = p.first + " " + p.second;
628 _filters->SetLabel (std_to_wx (b));
630 _film_sizer->Layout ();
634 checked_set (_name, _film->name());
637 case Film::DCP_CONTENT_TYPE:
638 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
642 checked_set (_ab, _film->ab ());
645 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
647 case Film::TRIM_TYPE:
648 checked_set (_trim_type, _film->trim_type() == Film::CPL ? 0 : 1);
650 case Film::AUDIO_GAIN:
651 checked_set (_audio_gain, _film->audio_gain ());
653 case Film::AUDIO_DELAY:
654 checked_set (_audio_delay, _film->audio_delay ());
656 case Film::WITH_SUBTITLES:
657 checked_set (_with_subtitles, _film->with_subtitles ());
658 setup_subtitle_control_sensitivity ();
661 case Film::SUBTITLE_OFFSET:
662 checked_set (_subtitle_offset, _film->subtitle_offset ());
664 case Film::SUBTITLE_SCALE:
665 checked_set (_subtitle_scale, _film->subtitle_scale() * 100);
667 case Film::COLOUR_LUT:
668 checked_set (_colour_lut, _film->colour_lut ());
670 case Film::J2K_BANDWIDTH:
671 checked_set (_j2k_bandwidth, double (_film->j2k_bandwidth()) / 1e6);
673 case Film::USE_DCI_NAME:
674 checked_set (_use_dci_name, _film->use_dci_name ());
677 case Film::DCI_METADATA:
680 case Film::DCP_VIDEO_FRAME_RATE:
683 for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
684 if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_video_frame_rate())) {
685 checked_set (_dcp_frame_rate, i);
692 checked_set (_dcp_frame_rate, -1);
695 _best_dcp_frame_rate->Enable (_film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
696 setup_frame_rate_description ();
703 FilmEditor::film_content_changed (weak_ptr<Content> content, int property)
706 /* We call this method ourselves (as well as using it as a signal handler)
712 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
713 setup_subtitle_control_sensitivity ();
714 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
715 setup_show_audio_sensitivity ();
716 } else if (property == VideoContentProperty::VIDEO_LENGTH || property == AudioContentProperty::AUDIO_LENGTH) {
718 boost::shared_ptr<Content> c = content.lock ();
719 if (c && c == selected_content()) {
720 setup_content_information ();
722 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
724 setup_show_audio_sensitivity ();
729 FilmEditor::setup_format ()
732 vector<Format const *>::iterator i = _formats.begin ();
733 while (i != _formats.end() && *i != _film->format ()) {
738 if (i == _formats.end()) {
739 checked_set (_format, -1);
741 checked_set (_format, n);
745 setup_scaling_description ();
749 FilmEditor::setup_length ()
752 Time const length = _film->length ();
754 s << time_to_hms (length);
755 _length->SetLabel (std_to_wx (s.str ()));
759 FilmEditor::setup_frame_rate_description ()
767 if (_film->video_frame_rate()) {
768 d << std_to_wx (FrameRateConversion (_film->video_frame_rate(), _film->dcp_frame_rate()).description);
770 if (_film->audio_frame_rate() && _film->audio_frame_rate() != _film->target_audio_sample_rate ()) {
771 d << wxString::Format (
772 _("Audio will be resampled from %dHz to %dHz\n"),
773 _film->audio_frame_rate(),
774 _film->target_audio_sample_rate()
781 for (int i = lines; i < 2; ++i) {
785 _frame_rate_description->SetLabel (d);
788 /** Called when the format widget has been changed */
790 FilmEditor::format_changed (wxCommandEvent &)
796 int const n = _format->GetSelection ();
798 assert (n < int (_formats.size()));
799 _film->set_format (_formats[n]);
803 /** Called when the DCP content type widget has been changed */
805 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
811 int const n = _dcp_content_type->GetSelection ();
812 if (n != wxNOT_FOUND) {
813 _film->set_dcp_content_type (DCPContentType::from_index (n));
817 /** Sets the Film that we are editing */
819 FilmEditor::set_film (shared_ptr<Film> f)
821 set_things_sensitive (f != 0);
830 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
831 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1, _2));
835 FileChanged (_film->directory ());
841 _audio_dialog->set_film (_film);
844 film_changed (Film::NAME);
845 film_changed (Film::USE_DCI_NAME);
846 film_changed (Film::CONTENT);
847 film_changed (Film::LOOP);
848 film_changed (Film::TRUST_CONTENT_HEADERS);
849 film_changed (Film::DCP_CONTENT_TYPE);
850 film_changed (Film::FORMAT);
851 film_changed (Film::CROP);
852 film_changed (Film::FILTERS);
853 film_changed (Film::SCALER);
854 film_changed (Film::TRIM_START);
855 film_changed (Film::TRIM_END);
856 film_changed (Film::AB);
857 film_changed (Film::TRIM_TYPE);
858 film_changed (Film::AUDIO_GAIN);
859 film_changed (Film::AUDIO_DELAY);
860 film_changed (Film::WITH_SUBTITLES);
861 film_changed (Film::SUBTITLE_OFFSET);
862 film_changed (Film::SUBTITLE_SCALE);
863 film_changed (Film::COLOUR_LUT);
864 film_changed (Film::J2K_BANDWIDTH);
865 film_changed (Film::DCI_METADATA);
866 film_changed (Film::DCP_VIDEO_FRAME_RATE);
867 film_changed (Film::AUDIO_MAPPING);
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);
874 setup_content_information ();
877 /** Updates the sensitivity of lots of widgets to a given value.
878 * @param s true to make sensitive, false to make insensitive.
881 FilmEditor::set_things_sensitive (bool s)
883 _generally_sensitive = s;
886 _use_dci_name->Enable (s);
887 _edit_dci_button->Enable (s);
889 _content->Enable (s);
890 _trust_content_headers->Enable (s);
891 _content->Enable (s);
892 _left_crop->Enable (s);
893 _right_crop->Enable (s);
894 _top_crop->Enable (s);
895 _bottom_crop->Enable (s);
896 _filters_button->Enable (s);
898 _dcp_content_type->Enable (s);
899 _best_dcp_frame_rate->Enable (s);
900 _dcp_frame_rate->Enable (s);
902 _trim_type->Enable (s);
903 _colour_lut->Enable (s);
904 _j2k_bandwidth->Enable (s);
905 _audio_gain->Enable (s);
906 _audio_gain_calculate_button->Enable (s);
907 _show_audio->Enable (s);
908 _audio_delay->Enable (s);
910 setup_subtitle_control_sensitivity ();
911 setup_show_audio_sensitivity ();
912 setup_content_button_sensitivity ();
915 /** Called when the `Edit filters' button has been clicked */
917 FilmEditor::edit_filters_clicked (wxCommandEvent &)
919 FilterDialog* d = new FilterDialog (this, _film->filters());
920 d->ActiveChanged.connect (bind (&Film::set_filters, _film, _1));
925 /** Called when the scaler widget has been changed */
927 FilmEditor::scaler_changed (wxCommandEvent &)
933 int const n = _scaler->GetSelection ();
935 _film->set_scaler (Scaler::from_index (n));
940 FilmEditor::audio_gain_changed (wxCommandEvent &)
946 _film->set_audio_gain (_audio_gain->GetValue ());
950 FilmEditor::audio_delay_changed (wxCommandEvent &)
956 _film->set_audio_delay (_audio_delay->GetValue ());
960 FilmEditor::setup_notebook_size ()
962 _notebook->InvalidateBestSize ();
964 _film_sizer->Layout ();
965 _film_sizer->SetSizeHints (_film_panel);
966 _video_sizer->Layout ();
967 _video_sizer->SetSizeHints (_video_panel);
968 _audio_sizer->Layout ();
969 _audio_sizer->SetSizeHints (_audio_panel);
970 _subtitle_sizer->Layout ();
971 _subtitle_sizer->SetSizeHints (_subtitle_panel);
978 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
980 GainCalculatorDialog* d = new GainCalculatorDialog (this);
983 if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
988 _audio_gain->SetValue (
989 Config::instance()->sound_processor()->db_for_fader_change (
995 /* This appears to be necessary, as the change is not signalled,
998 wxCommandEvent dummy;
999 audio_gain_changed (dummy);
1005 FilmEditor::setup_formats ()
1007 _formats = Format::all ();
1010 for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
1011 _format->Append (std_to_wx ((*i)->name ()));
1014 _film_sizer->Layout ();
1018 FilmEditor::with_subtitles_toggled (wxCommandEvent &)
1024 _film->set_with_subtitles (_with_subtitles->GetValue ());
1028 FilmEditor::setup_subtitle_control_sensitivity ()
1031 if (_generally_sensitive && _film) {
1032 h = _film->has_subtitles ();
1035 _with_subtitles->Enable (h);
1039 j = _film->with_subtitles ();
1042 _subtitle_offset->Enable (j);
1043 _subtitle_scale->Enable (j);
1047 FilmEditor::use_dci_name_toggled (wxCommandEvent &)
1053 _film->set_use_dci_name (_use_dci_name->GetValue ());
1057 FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
1063 DCIMetadataDialog* d = new DCIMetadataDialog (this, _film->dci_metadata ());
1065 _film->set_dci_metadata (d->dci_metadata ());
1070 FilmEditor::active_jobs_changed (bool a)
1072 set_things_sensitive (!a);
1076 FilmEditor::setup_dcp_name ()
1078 string s = _film->dcp_name (true);
1079 if (s.length() > 28) {
1080 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
1081 _dcp_name->SetToolTip (std_to_wx (s));
1083 _dcp_name->SetLabel (std_to_wx (s));
1088 FilmEditor::show_audio_clicked (wxCommandEvent &)
1090 if (_audio_dialog) {
1091 _audio_dialog->Destroy ();
1095 _audio_dialog = new AudioDialog (this);
1096 _audio_dialog->Show ();
1097 _audio_dialog->set_film (_film);
1101 FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
1107 _film->set_dcp_video_frame_rate (_film->best_dcp_video_frame_rate ());
1111 FilmEditor::setup_show_audio_sensitivity ()
1113 _show_audio->Enable (_film);
1117 FilmEditor::setup_content ()
1119 string selected_summary;
1120 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1122 selected_summary = wx_to_std (_content->GetItemText (s));
1125 _content->DeleteAllItems ();
1127 Playlist::RegionList regions = _film->regions ();
1128 for (Playlist::RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
1129 int const t = _content->GetItemCount ();
1130 _content->InsertItem (t, std_to_wx (i->content->summary ()));
1131 if (i->content->summary() == selected_summary) {
1132 _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1136 if (selected_summary.empty () && !regions.empty ()) {
1137 /* Select the item of content if non was selected before */
1138 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1141 setup_content_information ();
1145 FilmEditor::content_add_clicked (wxCommandEvent &)
1147 wxFileDialog* d = new wxFileDialog (this, _("Choose a file or files"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
1148 int const r = d->ShowModal ();
1155 wxArrayString paths;
1156 d->GetPaths (paths);
1158 for (unsigned int i = 0; i < paths.GetCount(); ++i) {
1159 boost::filesystem::path p (wx_to_std (paths[i]));
1161 if (ImageMagickContent::valid_file (p)) {
1162 _film->add_content (shared_ptr<ImageMagickContent> (new ImageMagickContent (p)));
1163 } else if (SndfileContent::valid_file (p)) {
1164 _film->add_content (shared_ptr<SndfileContent> (new SndfileContent (p)));
1166 _film->add_content (shared_ptr<FFmpegContent> (new FFmpegContent (p)));
1172 FilmEditor::content_remove_clicked (wxCommandEvent &)
1174 shared_ptr<Content> c = selected_content ();
1176 _film->remove_content (c);
1181 FilmEditor::content_activated (wxListEvent& ev)
1183 Playlist::RegionList r = _film->regions ();
1184 assert (ev.GetIndex() >= 0 && size_t (ev.GetIndex()) < r.size ());
1186 content_properties (r[ev.GetIndex()].content);
1190 FilmEditor::content_properties_clicked (wxCommandEvent &)
1192 shared_ptr<Content> c = selected_content ();
1197 content_properties (c);
1201 FilmEditor::content_properties (shared_ptr<Content> content)
1203 shared_ptr<ImageMagickContent> im = dynamic_pointer_cast<ImageMagickContent> (content);
1205 ImageMagickContentDialog* d = new ImageMagickContentDialog (this, im);
1210 shared_ptr<FFmpegContent> ff = dynamic_pointer_cast<FFmpegContent> (content);
1212 FFmpegContentDialog* d = new FFmpegContentDialog (this, ff);
1219 FilmEditor::content_selection_changed (wxListEvent &)
1221 setup_content_button_sensitivity ();
1222 setup_content_information ();
1226 FilmEditor::setup_content_information ()
1228 shared_ptr<Content> c = selected_content ();
1230 _content_information->SetValue (wxT (""));
1234 _content_information->SetValue (std_to_wx (c->information ()));
1238 FilmEditor::setup_content_button_sensitivity ()
1240 _content_add->Enable (_generally_sensitive);
1242 shared_ptr<Content> selection = selected_content ();
1244 _content_properties->Enable (
1245 selection && _generally_sensitive &&
1246 (dynamic_pointer_cast<ImageMagickContent> (selection) || dynamic_pointer_cast<FFmpegContent> (selection))
1249 _content_remove->Enable (selection && _generally_sensitive);
1250 _content_timeline->Enable (_generally_sensitive);
1254 FilmEditor::selected_content ()
1256 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1258 return shared_ptr<Content> ();
1261 Playlist::RegionList r = _film->regions ();
1262 if (s < 0 || size_t (s) >= r.size ()) {
1263 return shared_ptr<Content> ();
1266 return r[s].content;
1270 FilmEditor::setup_scaling_description ()
1278 if (_film->video_size().width && _film->video_size().height) {
1279 d << wxString::Format (
1280 _("Original video is %dx%d (%.2f:1)\n"),
1281 _film->video_size().width, _film->video_size().height,
1282 float (_film->video_size().width) / _film->video_size().height
1287 Crop const crop = _film->crop ();
1288 if (crop.left || crop.right || crop.top || crop.bottom) {
1289 libdcp::Size const cropped = _film->cropped_size (_film->video_size ());
1290 d << wxString::Format (
1291 _("Cropped to %dx%d (%.2f:1)\n"),
1292 cropped.width, cropped.height,
1293 float (cropped.width) / cropped.height
1298 Format const * format = _film->format ();
1300 int const padding = format->dcp_padding (_film);
1301 libdcp::Size scaled = format->dcp_size ();
1302 scaled.width -= padding * 2;
1303 d << wxString::Format (
1304 _("Scaled to %dx%d (%.2f:1)\n"),
1305 scaled.width, scaled.height,
1306 float (scaled.width) / scaled.height
1311 d << wxString::Format (
1312 _("Padded with black to %dx%d (%.2f:1)\n"),
1313 format->dcp_size().width, format->dcp_size().height,
1314 float (format->dcp_size().width) / format->dcp_size().height
1320 for (int i = lines; i < 4; ++i) {
1325 _scaling_description->SetLabel (d);
1329 FilmEditor::trim_type_changed (wxCommandEvent &)
1331 _film->set_trim_type (_trim_type->GetSelection () == 0 ? Film::CPL : Film::ENCODE);
1335 FilmEditor::loop_content_toggled (wxCommandEvent &)
1337 if (_loop_content->GetValue ()) {
1338 _film->set_loop (_loop_count->GetValue ());
1340 _film->set_loop (1);
1343 setup_loop_sensitivity ();
1347 FilmEditor::loop_count_changed (wxCommandEvent &)
1349 _film->set_loop (_loop_count->GetValue ());
1353 FilmEditor::setup_loop_sensitivity ()
1355 _loop_count->Enable (_loop_content->GetValue ());
1359 FilmEditor::content_timeline_clicked (wxCommandEvent &)
1361 if (_timeline_dialog) {
1362 _timeline_dialog->Destroy ();
1363 _timeline_dialog = 0;
1366 _timeline_dialog = new TimelineDialog (this, _film);
1367 _timeline_dialog->Show ();