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 "timeline_dialog.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 , _timeline_dialog (0)
79 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
80 _notebook = new wxNotebook (this, wxID_ANY);
81 s->Add (_notebook, 1);
84 _notebook->AddPage (_film_panel, _("Film"), true);
85 make_content_panel ();
86 _notebook->AddPage (_content_panel, _("Content"), false);
88 _notebook->AddPage (_video_panel, _("Video"), false);
90 _notebook->AddPage (_audio_panel, _("Audio"), false);
91 make_subtitle_panel ();
92 _notebook->AddPage (_subtitle_panel, _("Subtitles"), false);
97 connect_to_widgets ();
99 JobManager::instance()->ActiveJobsChanged.connect (
100 bind (&FilmEditor::active_jobs_changed, this, _1)
107 FilmEditor::make_film_panel ()
109 _film_panel = new wxPanel (_notebook);
110 _film_sizer = new wxBoxSizer (wxVERTICAL);
111 _film_panel->SetSizer (_film_sizer);
113 wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
114 _film_sizer->Add (grid, 0, wxALL, 8);
118 add_label_to_grid_bag_sizer (grid, _film_panel, _("Name"), wxGBPosition (r, 0));
119 _name = new wxTextCtrl (_film_panel, wxID_ANY);
120 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
123 add_label_to_grid_bag_sizer (grid, _film_panel, _("DCP Name"), wxGBPosition (r, 0));
124 _dcp_name = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
125 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
128 _use_dci_name = new wxCheckBox (_film_panel, wxID_ANY, _("Use DCI name"));
129 grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
130 _edit_dci_button = new wxButton (_film_panel, wxID_ANY, _("Details..."));
131 grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
134 _trust_content_headers = new wxCheckBox (_film_panel, wxID_ANY, _("Trust content headers"));
135 grid->Add (_trust_content_headers, wxGBPosition (r, 0), wxGBSpan(1, 2));
138 add_label_to_grid_bag_sizer (grid, _film_panel, _("Content Type"), wxGBPosition (r, 0));
139 _dcp_content_type = new wxChoice (_film_panel, wxID_ANY);
140 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
144 add_label_to_grid_bag_sizer (grid, _film_panel, _("DCP Frame Rate"), wxGBPosition (r, 0));
145 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
146 _dcp_frame_rate = new wxChoice (_film_panel, wxID_ANY);
147 s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
148 _best_dcp_frame_rate = new wxButton (_film_panel, wxID_ANY, _("Use best"));
149 s->Add (_best_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 6);
150 grid->Add (s, wxGBPosition (r, 1));
154 _frame_rate_description = new wxStaticText (_film_panel, wxID_ANY, wxT ("\n \n "), wxDefaultPosition, wxDefaultSize);
155 grid->Add (_frame_rate_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
156 wxFont font = _frame_rate_description->GetFont();
157 font.SetStyle(wxFONTSTYLE_ITALIC);
158 font.SetPointSize(font.GetPointSize() - 1);
159 _frame_rate_description->SetFont(font);
162 add_label_to_grid_bag_sizer (grid, _film_panel, _("Length"), wxGBPosition (r, 0));
163 _length = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
164 grid->Add (_length, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
167 add_label_to_grid_bag_sizer (grid, _film_panel, _("Trim method"), wxGBPosition (r, 0));
168 _trim_type = new wxChoice (_film_panel, wxID_ANY);
169 grid->Add (_trim_type, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
172 _ab = new wxCheckBox (_film_panel, wxID_ANY, _("A/B"));
173 grid->Add (_ab, wxGBPosition (r, 0));
176 vector<DCPContentType const *> const ct = DCPContentType::all ();
177 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
178 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
181 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
182 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
183 _dcp_frame_rate->Append (std_to_wx (boost::lexical_cast<string> (*i)));
186 _trim_type->Append (_("encode all frames and play the subset"));
187 _trim_type->Append (_("encode only the subset"));
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_selection_changed), 0, this);
199 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
200 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler (FilmEditor::content_activated), 0, this);
201 _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
202 _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
203 _content_properties->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_properties_clicked), 0, this);
204 _content_timeline->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_timeline_clicked), 0, this);
205 _loop_content->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::loop_content_toggled), 0, this);
206 _loop_count->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::loop_count_changed), 0, this);
207 _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
208 _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
209 _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
210 _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
211 _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
212 _scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
213 _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
214 _dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
215 _best_dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
216 _ab->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::ab_toggled), 0, this);
217 _trim_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::trim_type_changed), 0, this);
218 _with_subtitles->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
219 _subtitle_offset->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_offset_changed), 0, this);
220 _subtitle_scale->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this);
221 _colour_lut->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::colour_lut_changed), 0, this);
222 _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_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 add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0));
248 _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
249 grid->Add (_left_crop, wxGBPosition (r, 1));
252 add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), wxGBPosition (r, 0));
253 _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
254 grid->Add (_right_crop, wxGBPosition (r, 1));
257 add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), wxGBPosition (r, 0));
258 _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
259 grid->Add (_top_crop, wxGBPosition (r, 1));
262 add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), wxGBPosition (r, 0));
263 _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
264 grid->Add (_bottom_crop, wxGBPosition (r, 1));
267 _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
268 grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
269 wxFont font = _scaling_description->GetFont();
270 font.SetStyle(wxFONTSTYLE_ITALIC);
271 font.SetPointSize(font.GetPointSize() - 1);
272 _scaling_description->SetFont(font);
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 _j2k_bandwidth->SetRange (50, 250);
324 FilmEditor::make_content_panel ()
326 _content_panel = new wxPanel (_notebook);
327 _content_sizer = new wxBoxSizer (wxVERTICAL);
328 _content_panel->SetSizer (_content_sizer);
331 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
333 _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
334 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
336 _content->InsertColumn (0, wxT(""));
337 _content->SetColumnWidth (0, 512);
339 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
340 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
341 b->Add (_content_add, 1, wxEXPAND | wxLEFT | wxRIGHT);
342 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
343 b->Add (_content_remove, 1, wxEXPAND | wxLEFT | wxRIGHT);
344 _content_properties = new wxButton (_content_panel, wxID_ANY, _("Properties..."));
345 b->Add (_content_properties);
346 _content_timeline = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
347 b->Add (_content_timeline, 1, wxEXPAND | wxLEFT | wxRIGHT);
349 s->Add (b, 0, wxALL, 4);
351 _content_sizer->Add (s, 0.75, wxEXPAND | wxALL, 6);
354 _content_information = new wxTextCtrl (_content_panel, wxID_ANY, wxT ("\n \n "), wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxTE_MULTILINE);
355 _content_sizer->Add (_content_information, 1, wxEXPAND | wxALL, 6);
357 wxBoxSizer* h = new wxBoxSizer (wxHORIZONTAL);
358 _loop_content = new wxCheckBox (_content_panel, wxID_ANY, _("Loop everything"));
359 h->Add (_loop_content, 0, wxALL, 6);
360 _loop_count = new wxSpinCtrl (_content_panel, wxID_ANY);
361 h->Add (_loop_count, 0, wxALL, 6);
362 add_label_to_sizer (h, _content_panel, _("times"));
363 _content_sizer->Add (h, 0, wxALL, 6);
365 _loop_count->SetRange (2, 1024);
369 FilmEditor::make_audio_panel ()
371 _audio_panel = new wxPanel (_notebook);
372 _audio_sizer = new wxBoxSizer (wxVERTICAL);
373 _audio_panel->SetSizer (_audio_sizer);
375 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
376 _audio_sizer->Add (grid, 0, wxALL, 8);
378 _show_audio = new wxButton (_audio_panel, wxID_ANY, _("Show Audio..."));
379 grid->Add (_show_audio, 1);
383 add_label_to_sizer (grid, _audio_panel, _("Audio Gain"));
384 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
385 _audio_gain = new wxSpinCtrl (_audio_panel);
386 s->Add (_audio_gain, 1);
387 add_label_to_sizer (s, _audio_panel, _("dB"));
388 _audio_gain_calculate_button = new wxButton (_audio_panel, wxID_ANY, _("Calculate..."));
389 s->Add (_audio_gain_calculate_button, 1, wxEXPAND);
394 add_label_to_sizer (grid, _audio_panel, _("Audio Delay"));
395 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
396 _audio_delay = new wxSpinCtrl (_audio_panel);
397 s->Add (_audio_delay, 1);
398 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
399 add_label_to_sizer (s, _audio_panel, _("ms"));
403 _audio_gain->SetRange (-60, 60);
404 _audio_delay->SetRange (-1000, 1000);
408 FilmEditor::make_subtitle_panel ()
410 _subtitle_panel = new wxPanel (_notebook);
411 _subtitle_sizer = new wxBoxSizer (wxVERTICAL);
412 _subtitle_panel->SetSizer (_subtitle_sizer);
413 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
414 _subtitle_sizer->Add (grid, 0, wxALL, 8);
416 _with_subtitles = new wxCheckBox (_subtitle_panel, wxID_ANY, _("With Subtitles"));
417 grid->Add (_with_subtitles, 1);
421 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset"));
422 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
423 _subtitle_offset = new wxSpinCtrl (_subtitle_panel);
424 s->Add (_subtitle_offset);
425 add_label_to_sizer (s, _subtitle_panel, _("pixels"));
430 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Scale"));
431 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
432 _subtitle_scale = new wxSpinCtrl (_subtitle_panel);
433 s->Add (_subtitle_scale);
434 add_label_to_sizer (s, _subtitle_panel, _("%"));
438 _subtitle_offset->SetRange (-1024, 1024);
439 _subtitle_scale->SetRange (1, 1000);
442 /** Called when the left crop widget has been changed */
444 FilmEditor::left_crop_changed (wxCommandEvent &)
450 _film->set_left_crop (_left_crop->GetValue ());
453 /** Called when the right crop widget has been changed */
455 FilmEditor::right_crop_changed (wxCommandEvent &)
461 _film->set_right_crop (_right_crop->GetValue ());
464 /** Called when the top crop widget has been changed */
466 FilmEditor::top_crop_changed (wxCommandEvent &)
472 _film->set_top_crop (_top_crop->GetValue ());
475 /** Called when the bottom crop value has been changed */
477 FilmEditor::bottom_crop_changed (wxCommandEvent &)
483 _film->set_bottom_crop (_bottom_crop->GetValue ());
487 FilmEditor::trust_content_headers_changed (wxCommandEvent &)
493 _film->set_trust_content_headers (_trust_content_headers->GetValue ());
496 /** Called when the DCP A/B switch has been toggled */
498 FilmEditor::ab_toggled (wxCommandEvent &)
504 _film->set_ab (_ab->GetValue ());
507 /** Called when the name widget has been changed */
509 FilmEditor::name_changed (wxCommandEvent &)
515 _film->set_name (string (_name->GetValue().mb_str()));
519 FilmEditor::subtitle_offset_changed (wxCommandEvent &)
525 _film->set_subtitle_offset (_subtitle_offset->GetValue ());
529 FilmEditor::subtitle_scale_changed (wxCommandEvent &)
535 _film->set_subtitle_scale (_subtitle_scale->GetValue() / 100.0);
539 FilmEditor::colour_lut_changed (wxCommandEvent &)
545 _film->set_colour_lut (_colour_lut->GetSelection ());
549 FilmEditor::j2k_bandwidth_changed (wxCommandEvent &)
555 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
559 FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
565 _film->set_dcp_video_frame_rate (
566 boost::lexical_cast<int> (
567 wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
573 /** Called when the metadata stored in the Film object has changed;
574 * so that we can update the GUI.
575 * @param p Property of the Film that has changed.
578 FilmEditor::film_changed (Film::Property p)
595 setup_subtitle_control_sensitivity ();
596 setup_show_audio_sensitivity ();
600 checked_set (_loop_content, _film->loop() > 1);
601 checked_set (_loop_count, _film->loop());
602 setup_loop_sensitivity ();
604 case Film::TRUST_CONTENT_HEADERS:
605 checked_set (_trust_content_headers, _film->trust_content_headers ());
611 checked_set (_left_crop, _film->crop().left);
612 checked_set (_right_crop, _film->crop().right);
613 checked_set (_top_crop, _film->crop().top);
614 checked_set (_bottom_crop, _film->crop().bottom);
615 setup_scaling_description ();
619 pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
620 if (p.first.empty () && p.second.empty ()) {
621 _filters->SetLabel (_("None"));
623 string const b = p.first + " " + p.second;
624 _filters->SetLabel (std_to_wx (b));
626 _film_sizer->Layout ();
630 checked_set (_name, _film->name());
633 case Film::DCP_CONTENT_TYPE:
634 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
638 checked_set (_ab, _film->ab ());
641 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
643 case Film::TRIM_TYPE:
644 checked_set (_trim_type, _film->trim_type() == Film::CPL ? 0 : 1);
646 case Film::AUDIO_GAIN:
647 checked_set (_audio_gain, _film->audio_gain ());
649 case Film::AUDIO_DELAY:
650 checked_set (_audio_delay, _film->audio_delay ());
652 case Film::WITH_SUBTITLES:
653 checked_set (_with_subtitles, _film->with_subtitles ());
654 setup_subtitle_control_sensitivity ();
657 case Film::SUBTITLE_OFFSET:
658 checked_set (_subtitle_offset, _film->subtitle_offset ());
660 case Film::SUBTITLE_SCALE:
661 checked_set (_subtitle_scale, _film->subtitle_scale() * 100);
663 case Film::COLOUR_LUT:
664 checked_set (_colour_lut, _film->colour_lut ());
666 case Film::J2K_BANDWIDTH:
667 checked_set (_j2k_bandwidth, double (_film->j2k_bandwidth()) / 1e6);
669 case Film::USE_DCI_NAME:
670 checked_set (_use_dci_name, _film->use_dci_name ());
673 case Film::DCI_METADATA:
676 case Film::DCP_VIDEO_FRAME_RATE:
679 for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
680 if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_video_frame_rate())) {
681 checked_set (_dcp_frame_rate, i);
688 checked_set (_dcp_frame_rate, -1);
691 _best_dcp_frame_rate->Enable (_film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
692 setup_frame_rate_description ();
699 FilmEditor::film_content_changed (weak_ptr<Content> content, int property)
702 /* We call this method ourselves (as well as using it as a signal handler)
708 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
709 setup_subtitle_control_sensitivity ();
710 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
711 setup_show_audio_sensitivity ();
712 } else if (property == VideoContentProperty::VIDEO_LENGTH || property == AudioContentProperty::AUDIO_LENGTH) {
714 boost::shared_ptr<Content> c = content.lock ();
715 if (selected_content() && c == selected_content()) {
716 setup_content_information ();
718 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
720 setup_show_audio_sensitivity ();
725 FilmEditor::setup_format ()
728 vector<Format const *>::iterator i = _formats.begin ();
729 while (i != _formats.end() && *i != _film->format ()) {
734 if (i == _formats.end()) {
735 checked_set (_format, -1);
737 checked_set (_format, n);
741 setup_scaling_description ();
745 FilmEditor::setup_length ()
748 Time const length = _film->length ();
750 s << time_to_hms (length);
751 _length->SetLabel (std_to_wx (s.str ()));
755 FilmEditor::setup_frame_rate_description ()
763 if (_film->video_frame_rate()) {
764 d << std_to_wx (FrameRateConversion (_film->video_frame_rate(), _film->dcp_frame_rate()).description);
766 if (_film->audio_frame_rate() && _film->audio_frame_rate() != _film->target_audio_sample_rate ()) {
767 d << wxString::Format (
768 _("Audio will be resampled from %dHz to %dHz\n"),
769 _film->audio_frame_rate(),
770 _film->target_audio_sample_rate()
777 for (int i = lines; i < 2; ++i) {
781 _frame_rate_description->SetLabel (d);
784 /** Called when the format widget has been changed */
786 FilmEditor::format_changed (wxCommandEvent &)
792 int const n = _format->GetSelection ();
794 assert (n < int (_formats.size()));
795 _film->set_format (_formats[n]);
799 /** Called when the DCP content type widget has been changed */
801 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
807 int const n = _dcp_content_type->GetSelection ();
808 if (n != wxNOT_FOUND) {
809 _film->set_dcp_content_type (DCPContentType::from_index (n));
813 /** Sets the Film that we are editing */
815 FilmEditor::set_film (shared_ptr<Film> f)
817 set_things_sensitive (f != 0);
826 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
827 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1, _2));
831 FileChanged (_film->directory ());
837 _audio_dialog->set_film (_film);
840 film_changed (Film::NAME);
841 film_changed (Film::USE_DCI_NAME);
842 film_changed (Film::CONTENT);
843 film_changed (Film::LOOP);
844 film_changed (Film::TRUST_CONTENT_HEADERS);
845 film_changed (Film::DCP_CONTENT_TYPE);
846 film_changed (Film::FORMAT);
847 film_changed (Film::CROP);
848 film_changed (Film::FILTERS);
849 film_changed (Film::SCALER);
850 film_changed (Film::TRIM_START);
851 film_changed (Film::TRIM_END);
852 film_changed (Film::AB);
853 film_changed (Film::TRIM_TYPE);
854 film_changed (Film::AUDIO_GAIN);
855 film_changed (Film::AUDIO_DELAY);
856 film_changed (Film::WITH_SUBTITLES);
857 film_changed (Film::SUBTITLE_OFFSET);
858 film_changed (Film::SUBTITLE_SCALE);
859 film_changed (Film::COLOUR_LUT);
860 film_changed (Film::J2K_BANDWIDTH);
861 film_changed (Film::DCI_METADATA);
862 film_changed (Film::DCP_VIDEO_FRAME_RATE);
864 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAMS);
865 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM);
866 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAMS);
867 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAM);
869 setup_content_information ();
872 /** Updates the sensitivity of lots of widgets to a given value.
873 * @param s true to make sensitive, false to make insensitive.
876 FilmEditor::set_things_sensitive (bool s)
878 _generally_sensitive = s;
881 _use_dci_name->Enable (s);
882 _edit_dci_button->Enable (s);
884 _content->Enable (s);
885 _trust_content_headers->Enable (s);
886 _content->Enable (s);
887 _left_crop->Enable (s);
888 _right_crop->Enable (s);
889 _top_crop->Enable (s);
890 _bottom_crop->Enable (s);
891 _filters_button->Enable (s);
893 _dcp_content_type->Enable (s);
894 _best_dcp_frame_rate->Enable (s);
895 _dcp_frame_rate->Enable (s);
897 _trim_type->Enable (s);
898 _colour_lut->Enable (s);
899 _j2k_bandwidth->Enable (s);
900 _audio_gain->Enable (s);
901 _audio_gain_calculate_button->Enable (s);
902 _show_audio->Enable (s);
903 _audio_delay->Enable (s);
905 setup_subtitle_control_sensitivity ();
906 setup_show_audio_sensitivity ();
907 setup_content_button_sensitivity ();
910 /** Called when the `Edit filters' button has been clicked */
912 FilmEditor::edit_filters_clicked (wxCommandEvent &)
914 FilterDialog* d = new FilterDialog (this, _film->filters());
915 d->ActiveChanged.connect (bind (&Film::set_filters, _film, _1));
920 /** Called when the scaler widget has been changed */
922 FilmEditor::scaler_changed (wxCommandEvent &)
928 int const n = _scaler->GetSelection ();
930 _film->set_scaler (Scaler::from_index (n));
935 FilmEditor::audio_gain_changed (wxCommandEvent &)
941 _film->set_audio_gain (_audio_gain->GetValue ());
945 FilmEditor::audio_delay_changed (wxCommandEvent &)
951 _film->set_audio_delay (_audio_delay->GetValue ());
955 FilmEditor::setup_notebook_size ()
957 _notebook->InvalidateBestSize ();
959 _film_sizer->Layout ();
960 _film_sizer->SetSizeHints (_film_panel);
961 _video_sizer->Layout ();
962 _video_sizer->SetSizeHints (_video_panel);
963 _audio_sizer->Layout ();
964 _audio_sizer->SetSizeHints (_audio_panel);
965 _subtitle_sizer->Layout ();
966 _subtitle_sizer->SetSizeHints (_subtitle_panel);
973 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
975 GainCalculatorDialog* d = new GainCalculatorDialog (this);
978 if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
983 _audio_gain->SetValue (
984 Config::instance()->sound_processor()->db_for_fader_change (
990 /* This appears to be necessary, as the change is not signalled,
993 wxCommandEvent dummy;
994 audio_gain_changed (dummy);
1000 FilmEditor::setup_formats ()
1002 _formats = Format::all ();
1005 for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
1006 _format->Append (std_to_wx ((*i)->name ()));
1009 _film_sizer->Layout ();
1013 FilmEditor::with_subtitles_toggled (wxCommandEvent &)
1019 _film->set_with_subtitles (_with_subtitles->GetValue ());
1023 FilmEditor::setup_subtitle_control_sensitivity ()
1026 if (_generally_sensitive && _film) {
1027 h = _film->has_subtitles ();
1030 _with_subtitles->Enable (h);
1034 j = _film->with_subtitles ();
1037 _subtitle_offset->Enable (j);
1038 _subtitle_scale->Enable (j);
1042 FilmEditor::use_dci_name_toggled (wxCommandEvent &)
1048 _film->set_use_dci_name (_use_dci_name->GetValue ());
1052 FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
1058 DCIMetadataDialog* d = new DCIMetadataDialog (this, _film->dci_metadata ());
1060 _film->set_dci_metadata (d->dci_metadata ());
1065 FilmEditor::active_jobs_changed (bool a)
1067 set_things_sensitive (!a);
1071 FilmEditor::setup_dcp_name ()
1073 string s = _film->dcp_name (true);
1074 if (s.length() > 28) {
1075 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
1076 _dcp_name->SetToolTip (std_to_wx (s));
1078 _dcp_name->SetLabel (std_to_wx (s));
1083 FilmEditor::show_audio_clicked (wxCommandEvent &)
1085 if (_audio_dialog) {
1086 _audio_dialog->Destroy ();
1090 _audio_dialog = new AudioDialog (this);
1091 _audio_dialog->Show ();
1092 _audio_dialog->set_film (_film);
1096 FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
1102 _film->set_dcp_video_frame_rate (_film->best_dcp_video_frame_rate ());
1106 FilmEditor::setup_show_audio_sensitivity ()
1108 _show_audio->Enable (_film);
1112 FilmEditor::setup_content ()
1114 string selected_summary;
1115 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1117 selected_summary = wx_to_std (_content->GetItemText (s));
1120 _content->DeleteAllItems ();
1122 Playlist::ContentList content = _film->content ();
1123 for (Playlist::ContentList::iterator i = content.begin(); i != content.end(); ++i) {
1124 int const t = _content->GetItemCount ();
1125 _content->InsertItem (t, std_to_wx ((*i)->summary ()));
1126 if ((*i)->summary() == selected_summary) {
1127 _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1131 if (selected_summary.empty () && !content.empty ()) {
1132 /* Select the item of content if non was selected before */
1133 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1136 setup_content_information ();
1140 FilmEditor::content_add_clicked (wxCommandEvent &)
1142 wxFileDialog* d = new wxFileDialog (this, _("Choose a file or files"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
1143 int const r = d->ShowModal ();
1150 wxArrayString paths;
1151 d->GetPaths (paths);
1153 for (unsigned int i = 0; i < paths.GetCount(); ++i) {
1154 boost::filesystem::path p (wx_to_std (paths[i]));
1156 if (ImageMagickContent::valid_file (p)) {
1157 _film->add_content (shared_ptr<ImageMagickContent> (new ImageMagickContent (p)));
1158 } else if (SndfileContent::valid_file (p)) {
1159 _film->add_content (shared_ptr<SndfileContent> (new SndfileContent (p)));
1161 _film->add_content (shared_ptr<FFmpegContent> (new FFmpegContent (p)));
1167 FilmEditor::content_remove_clicked (wxCommandEvent &)
1169 shared_ptr<Content> c = selected_content ();
1171 _film->remove_content (c);
1176 FilmEditor::content_activated (wxListEvent& ev)
1178 Playlist::ContentList c = _film->content ();
1179 assert (ev.GetIndex() >= 0 && size_t (ev.GetIndex()) < c.size ());
1181 content_properties (c[ev.GetIndex()]);
1185 FilmEditor::content_properties_clicked (wxCommandEvent &)
1187 shared_ptr<Content> c = selected_content ();
1192 content_properties (c);
1196 FilmEditor::content_properties (shared_ptr<Content> content)
1198 shared_ptr<ImageMagickContent> ic = dynamic_pointer_cast<ImageMagickContent> (content);
1200 ImageMagickContentDialog* d = new ImageMagickContentDialog (this, ic);
1205 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (content);
1207 FFmpegContentDialog* d = new FFmpegContentDialog (this, fc);
1214 FilmEditor::content_selection_changed (wxListEvent &)
1216 setup_content_button_sensitivity ();
1217 setup_content_information ();
1221 FilmEditor::setup_content_information ()
1223 shared_ptr<Content> c = selected_content ();
1225 _content_information->SetValue (wxT (""));
1229 _content_information->SetValue (std_to_wx (c->information ()));
1233 FilmEditor::setup_content_button_sensitivity ()
1235 _content_add->Enable (_generally_sensitive);
1237 shared_ptr<Content> selection = selected_content ();
1239 _content_properties->Enable (
1240 selection && _generally_sensitive &&
1241 (dynamic_pointer_cast<ImageMagickContent> (selection) || dynamic_pointer_cast<FFmpegContent> (selection))
1244 _content_remove->Enable (selection && _generally_sensitive);
1245 _content_timeline->Enable (_generally_sensitive);
1249 FilmEditor::selected_content ()
1251 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1253 return shared_ptr<Content> ();
1256 Playlist::ContentList c = _film->content ();
1257 if (s < 0 || size_t (s) >= c.size ()) {
1258 return shared_ptr<Content> ();
1265 FilmEditor::setup_scaling_description ()
1273 if (_film->video_size().width && _film->video_size().height) {
1274 d << wxString::Format (
1275 _("Original video is %dx%d (%.2f:1)\n"),
1276 _film->video_size().width, _film->video_size().height,
1277 float (_film->video_size().width) / _film->video_size().height
1282 Crop const crop = _film->crop ();
1283 if (crop.left || crop.right || crop.top || crop.bottom) {
1284 libdcp::Size const cropped = _film->cropped_size (_film->video_size ());
1285 d << wxString::Format (
1286 _("Cropped to %dx%d (%.2f:1)\n"),
1287 cropped.width, cropped.height,
1288 float (cropped.width) / cropped.height
1293 Format const * format = _film->format ();
1295 int const padding = format->dcp_padding (_film);
1296 libdcp::Size scaled = format->dcp_size ();
1297 scaled.width -= padding * 2;
1298 d << wxString::Format (
1299 _("Scaled to %dx%d (%.2f:1)\n"),
1300 scaled.width, scaled.height,
1301 float (scaled.width) / scaled.height
1306 d << wxString::Format (
1307 _("Padded with black to %dx%d (%.2f:1)\n"),
1308 format->dcp_size().width, format->dcp_size().height,
1309 float (format->dcp_size().width) / format->dcp_size().height
1315 for (int i = lines; i < 4; ++i) {
1320 _scaling_description->SetLabel (d);
1324 FilmEditor::trim_type_changed (wxCommandEvent &)
1326 _film->set_trim_type (_trim_type->GetSelection () == 0 ? Film::CPL : Film::ENCODE);
1330 FilmEditor::loop_content_toggled (wxCommandEvent &)
1332 if (_loop_content->GetValue ()) {
1333 _film->set_loop (_loop_count->GetValue ());
1335 _film->set_loop (1);
1338 setup_loop_sensitivity ();
1342 FilmEditor::loop_count_changed (wxCommandEvent &)
1344 _film->set_loop (_loop_count->GetValue ());
1348 FilmEditor::setup_loop_sensitivity ()
1350 _loop_count->Enable (_loop_content->GetValue ());
1354 FilmEditor::content_timeline_clicked (wxCommandEvent &)
1356 if (_timeline_dialog) {
1357 _timeline_dialog->Destroy ();
1358 _timeline_dialog = 0;
1361 _timeline_dialog = new TimelineDialog (this, _film);
1362 _timeline_dialog->Show ();