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"
52 #include "imagemagick_content_dialog.h"
53 #include "timeline_dialog.h"
54 #include "audio_mapping_view.h"
55 #include "container.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);
81 _main_notebook = new wxNotebook (this, wxID_ANY);
82 s->Add (_main_notebook, 1);
84 make_content_panel ();
85 _main_notebook->AddPage (_content_panel, _("Content"), true);
87 _main_notebook->AddPage (_dcp_panel, _("DCP"), false);
92 connect_to_widgets ();
94 JobManager::instance()->ActiveJobsChanged.connect (
95 bind (&FilmEditor::active_jobs_changed, this, _1)
102 FilmEditor::make_dcp_panel ()
104 _dcp_panel = new wxPanel (_main_notebook);
105 _dcp_sizer = new wxBoxSizer (wxVERTICAL);
106 _dcp_panel->SetSizer (_dcp_sizer);
108 wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
109 _dcp_sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
113 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Name"), wxGBPosition (r, 0));
114 _name = new wxTextCtrl (_dcp_panel, wxID_ANY);
115 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
118 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), wxGBPosition (r, 0));
119 _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
120 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
123 _use_dci_name = new wxCheckBox (_dcp_panel, wxID_ANY, _("Use DCI name"));
124 grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
125 _edit_dci_button = new wxButton (_dcp_panel, wxID_ANY, _("Details..."));
126 grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
129 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), wxGBPosition (r, 0));
130 _container = new wxChoice (_dcp_panel, wxID_ANY);
131 grid->Add (_container, wxGBPosition (r, 1));
134 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Content Type"), wxGBPosition (r, 0));
135 _dcp_content_type = new wxChoice (_dcp_panel, wxID_ANY);
136 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
140 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Frame Rate"), wxGBPosition (r, 0));
141 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
142 _dcp_frame_rate = new wxChoice (_dcp_panel, wxID_ANY);
143 s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
144 _best_dcp_frame_rate = new wxButton (_dcp_panel, wxID_ANY, _("Use best"));
145 s->Add (_best_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
146 grid->Add (s, wxGBPosition (r, 1));
151 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("JPEG2000 bandwidth"), wxGBPosition (r, 0));
152 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
153 _j2k_bandwidth = new wxSpinCtrl (_dcp_panel, wxID_ANY);
154 s->Add (_j2k_bandwidth, 1);
155 add_label_to_sizer (s, _dcp_panel, _("MBps"));
156 grid->Add (s, wxGBPosition (r, 1));
160 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Scaler"), wxGBPosition (r, 0));
161 _scaler = new wxChoice (_dcp_panel, wxID_ANY);
162 grid->Add (_scaler, wxGBPosition (r, 1));
165 vector<Scaler const *> const sc = Scaler::all ();
166 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
167 _scaler->Append (std_to_wx ((*i)->name()));
170 vector<Container const *> const co = Container::all ();
171 for (vector<Container const *>::const_iterator i = co.begin(); i != co.end(); ++i) {
172 _container->Append (std_to_wx ((*i)->name ()));
175 vector<DCPContentType const *> const ct = DCPContentType::all ();
176 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
177 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
180 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
181 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
182 _dcp_frame_rate->Append (std_to_wx (boost::lexical_cast<string> (*i)));
185 _j2k_bandwidth->SetRange (50, 250);
189 FilmEditor::connect_to_widgets ()
191 _name->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (FilmEditor::name_changed), 0, this);
192 _use_dci_name->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::use_dci_name_toggled), 0, this);
193 _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
194 _container->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::container_changed), 0, this);
195 // _format->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this);
196 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
197 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
198 _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
199 _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
200 _content_timeline->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_timeline_clicked), 0, this);
201 _loop_content->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::loop_content_toggled), 0, this);
202 _loop_count->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::loop_count_changed), 0, this);
203 _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
204 _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
205 _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
206 _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
207 _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
208 _scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
209 _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
210 _dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
211 _best_dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
212 _with_subtitles->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
213 _subtitle_offset->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_offset_changed), 0, this);
214 _subtitle_scale->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this);
215 _colour_lut->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::colour_lut_changed), 0, this);
216 _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_changed), 0, this);
217 _audio_gain->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_gain_changed), 0, this);
218 _audio_gain_calculate_button->Connect (
219 wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::audio_gain_calculate_button_clicked), 0, this
221 _show_audio->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::show_audio_clicked), 0, this);
222 _audio_delay->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
223 _audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::audio_stream_changed), 0, this);
224 _subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::subtitle_stream_changed), 0, this);
225 _audio_mapping->Changed.connect (bind (&FilmEditor::audio_mapping_changed, this, _1));
229 FilmEditor::make_video_panel ()
231 _video_panel = new wxPanel (_content_notebook);
232 wxBoxSizer* video_sizer = new wxBoxSizer (wxVERTICAL);
233 _video_panel->SetSizer (video_sizer);
235 wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
236 video_sizer->Add (grid, 0, wxALL, 8);
239 add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0));
240 _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
241 grid->Add (_left_crop, wxGBPosition (r, 1));
244 add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), wxGBPosition (r, 0));
245 _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
246 grid->Add (_right_crop, wxGBPosition (r, 1));
249 add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), wxGBPosition (r, 0));
250 _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
251 grid->Add (_top_crop, wxGBPosition (r, 1));
254 add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), wxGBPosition (r, 0));
255 _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
256 grid->Add (_bottom_crop, wxGBPosition (r, 1));
259 add_label_to_grid_bag_sizer (grid, _video_panel, _("Scale to"), wxGBPosition (r, 0));
260 _format = new wxChoice (_video_panel, wxID_ANY);
261 grid->Add (_format, wxGBPosition (r, 1));
264 _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
265 grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
266 wxFont font = _scaling_description->GetFont();
267 font.SetStyle(wxFONTSTYLE_ITALIC);
268 font.SetPointSize(font.GetPointSize() - 1);
269 _scaling_description->SetFont(font);
272 /* VIDEO-only stuff */
274 add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), wxGBPosition (r, 0));
275 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
276 _filters = new wxStaticText (_video_panel, wxID_ANY, _("None"));
277 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
278 _filters_button = new wxButton (_video_panel, wxID_ANY, _("Edit..."));
279 s->Add (_filters_button, 0);
280 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
284 add_label_to_grid_bag_sizer (grid, _video_panel, _("Colour look-up table"), wxGBPosition (r, 0));
285 _colour_lut = new wxChoice (_video_panel, wxID_ANY);
286 for (int i = 0; i < 2; ++i) {
287 _colour_lut->Append (std_to_wx (colour_lut_index_to_name (i)));
289 _colour_lut->SetSelection (0);
290 grid->Add (_colour_lut, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
293 _left_crop->SetRange (0, 1024);
294 _top_crop->SetRange (0, 1024);
295 _right_crop->SetRange (0, 1024);
296 _bottom_crop->SetRange (0, 1024);
300 FilmEditor::make_content_panel ()
302 _content_panel = new wxPanel (_main_notebook);
303 _content_sizer = new wxBoxSizer (wxVERTICAL);
304 _content_panel->SetSizer (_content_sizer);
307 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
309 _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
310 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
312 _content->InsertColumn (0, wxT(""));
313 _content->SetColumnWidth (0, 512);
315 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
316 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
317 b->Add (_content_add, 1, wxEXPAND | wxLEFT | wxRIGHT);
318 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
319 b->Add (_content_remove, 1, wxEXPAND | wxLEFT | wxRIGHT);
320 _content_timeline = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
321 b->Add (_content_timeline, 1, wxEXPAND | wxLEFT | wxRIGHT);
323 s->Add (b, 0, wxALL, 4);
325 _content_sizer->Add (s, 0.75, wxEXPAND | wxALL, 6);
328 wxBoxSizer* h = new wxBoxSizer (wxHORIZONTAL);
329 _loop_content = new wxCheckBox (_content_panel, wxID_ANY, _("Loop everything"));
330 h->Add (_loop_content, 0, wxALL, 6);
331 _loop_count = new wxSpinCtrl (_content_panel, wxID_ANY);
332 h->Add (_loop_count, 0, wxALL, 6);
333 add_label_to_sizer (h, _content_panel, _("times"));
334 _content_sizer->Add (h, 0, wxALL, 6);
336 _content_notebook = new wxNotebook (_content_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_LEFT);
337 _content_sizer->Add (_content_notebook, 1, wxEXPAND | wxTOP, 6);
340 _content_notebook->AddPage (_video_panel, _("Video"), false);
342 _content_notebook->AddPage (_audio_panel, _("Audio"), false);
343 make_subtitle_panel ();
344 _content_notebook->AddPage (_subtitle_panel, _("Subtitles"), false);
345 make_timing_panel ();
346 _content_notebook->AddPage (_timing_panel, _("Timing"), false);
348 _loop_count->SetRange (2, 1024);
352 FilmEditor::make_audio_panel ()
354 _audio_panel = new wxPanel (_content_notebook);
355 wxBoxSizer* audio_sizer = new wxBoxSizer (wxVERTICAL);
356 _audio_panel->SetSizer (audio_sizer);
358 wxFlexGridSizer* grid = new wxFlexGridSizer (3, 4, 4);
359 audio_sizer->Add (grid, 0, wxALL, 8);
361 _show_audio = new wxButton (_audio_panel, wxID_ANY, _("Show Audio..."));
362 grid->Add (_show_audio, 1);
366 add_label_to_sizer (grid, _audio_panel, _("Audio Gain"));
368 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
369 _audio_gain = new wxSpinCtrl (_audio_panel);
370 s->Add (_audio_gain, 1);
371 add_label_to_sizer (s, _audio_panel, _("dB"));
375 _audio_gain_calculate_button = new wxButton (_audio_panel, wxID_ANY, _("Calculate..."));
376 grid->Add (_audio_gain_calculate_button);
378 add_label_to_sizer (grid, _audio_panel, _("Audio Delay"));
380 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
381 _audio_delay = new wxSpinCtrl (_audio_panel);
382 s->Add (_audio_delay, 1);
383 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
384 add_label_to_sizer (s, _audio_panel, _("ms"));
390 add_label_to_sizer (grid, _audio_panel, _("Audio Stream"));
391 _audio_stream = new wxChoice (_audio_panel, wxID_ANY);
392 grid->Add (_audio_stream, 1);
393 _audio_description = new wxStaticText (_audio_panel, wxID_ANY, wxT (""));
396 grid->Add (_audio_description, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
400 _audio_mapping = new AudioMappingView (_audio_panel);
401 audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6);
403 _audio_gain->SetRange (-60, 60);
404 _audio_delay->SetRange (-1000, 1000);
408 FilmEditor::make_subtitle_panel ()
410 _subtitle_panel = new wxPanel (_content_notebook);
411 wxBoxSizer* 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 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Stream"));
439 _subtitle_stream = new wxChoice (_subtitle_panel, wxID_ANY);
440 grid->Add (_subtitle_stream, 1, wxEXPAND | wxALL, 6);
443 _subtitle_offset->SetRange (-1024, 1024);
444 _subtitle_scale->SetRange (1, 1000);
448 FilmEditor::make_timing_panel ()
450 _timing_panel = new wxPanel (_content_notebook);
451 wxBoxSizer* timing_sizer = new wxBoxSizer (wxVERTICAL);
452 _timing_panel->SetSizer (timing_sizer);
453 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
454 timing_sizer->Add (grid, 0, wxALL, 8);
456 add_label_to_sizer (grid, _timing_panel, _("Start time"));
457 _start = new Timecode (_timing_panel);
459 add_label_to_sizer (grid, _timing_panel, _("Length"));
460 _length = new Timecode (_timing_panel);
465 /** Called when the left crop widget has been changed */
467 FilmEditor::left_crop_changed (wxCommandEvent &)
469 shared_ptr<VideoContent> c = selected_video_content ();
474 c->set_left_crop (_left_crop->GetValue ());
477 /** Called when the right crop widget has been changed */
479 FilmEditor::right_crop_changed (wxCommandEvent &)
481 shared_ptr<VideoContent> c = selected_video_content ();
486 c->set_right_crop (_right_crop->GetValue ());
489 /** Called when the top crop widget has been changed */
491 FilmEditor::top_crop_changed (wxCommandEvent &)
493 shared_ptr<VideoContent> c = selected_video_content ();
498 c->set_top_crop (_top_crop->GetValue ());
501 /** Called when the bottom crop value has been changed */
503 FilmEditor::bottom_crop_changed (wxCommandEvent &)
505 shared_ptr<VideoContent> c = selected_video_content ();
510 c->set_bottom_crop (_bottom_crop->GetValue ());
513 /** Called when the name widget has been changed */
515 FilmEditor::name_changed (wxCommandEvent &)
521 _film->set_name (string (_name->GetValue().mb_str()));
525 FilmEditor::subtitle_offset_changed (wxCommandEvent &)
531 _film->set_subtitle_offset (_subtitle_offset->GetValue ());
535 FilmEditor::subtitle_scale_changed (wxCommandEvent &)
541 _film->set_subtitle_scale (_subtitle_scale->GetValue() / 100.0);
545 FilmEditor::colour_lut_changed (wxCommandEvent &)
551 _film->set_colour_lut (_colour_lut->GetSelection ());
555 FilmEditor::j2k_bandwidth_changed (wxCommandEvent &)
561 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
565 FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
571 _film->set_dcp_video_frame_rate (
572 boost::lexical_cast<int> (
573 wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
579 /** Called when the metadata stored in the Film object has changed;
580 * so that we can update the GUI.
581 * @param p Property of the Film that has changed.
584 FilmEditor::film_changed (Film::Property p)
601 setup_subtitle_control_sensitivity ();
602 setup_show_audio_sensitivity ();
605 checked_set (_loop_content, _film->loop() > 1);
606 checked_set (_loop_count, _film->loop());
607 setup_loop_sensitivity ();
609 case Film::CONTAINER:
613 checked_set (_name, _film->name());
616 case Film::DCP_CONTENT_TYPE:
617 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
621 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
623 case Film::WITH_SUBTITLES:
624 checked_set (_with_subtitles, _film->with_subtitles ());
625 setup_subtitle_control_sensitivity ();
628 case Film::SUBTITLE_OFFSET:
629 checked_set (_subtitle_offset, _film->subtitle_offset ());
631 case Film::SUBTITLE_SCALE:
632 checked_set (_subtitle_scale, _film->subtitle_scale() * 100);
634 case Film::COLOUR_LUT:
635 checked_set (_colour_lut, _film->colour_lut ());
637 case Film::J2K_BANDWIDTH:
638 checked_set (_j2k_bandwidth, double (_film->j2k_bandwidth()) / 1e6);
640 case Film::USE_DCI_NAME:
641 checked_set (_use_dci_name, _film->use_dci_name ());
644 case Film::DCI_METADATA:
647 case Film::DCP_VIDEO_FRAME_RATE:
650 for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
651 if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_video_frame_rate())) {
652 checked_set (_dcp_frame_rate, i);
659 checked_set (_dcp_frame_rate, -1);
662 _best_dcp_frame_rate->Enable (_film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
669 FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
672 /* We call this method ourselves (as well as using it as a signal handler)
678 shared_ptr<Content> content = weak_content.lock ();
679 shared_ptr<VideoContent> video_content;
680 shared_ptr<AudioContent> audio_content;
681 shared_ptr<FFmpegContent> ffmpeg_content;
683 video_content = dynamic_pointer_cast<VideoContent> (content);
684 audio_content = dynamic_pointer_cast<AudioContent> (content);
685 ffmpeg_content = dynamic_pointer_cast<FFmpegContent> (content);
688 /* We can't use case {} here */
690 if (property == ContentProperty::START) {
692 _start->set (content->start (), _film->dcp_video_frame_rate ());
697 } else if (property == VideoContentProperty::VIDEO_CROP) {
698 checked_set (_left_crop, video_content ? video_content->crop().left : 0);
699 checked_set (_right_crop, video_content ? video_content->crop().right : 0);
700 checked_set (_top_crop, video_content ? video_content->crop().top : 0);
701 checked_set (_bottom_crop, video_content ? video_content->crop().bottom : 0);
702 setup_scaling_description ();
703 } else if (property == AudioContentProperty::AUDIO_GAIN) {
704 checked_set (_audio_gain, audio_content ? audio_content->audio_gain() : 0);
705 } else if (property == AudioContentProperty::AUDIO_DELAY) {
706 checked_set (_audio_delay, audio_content ? audio_content->audio_delay() : 0);
707 } else if (property == AudioContentProperty::AUDIO_MAPPING) {
708 _audio_mapping->set (audio_content ? audio_content->audio_mapping () : AudioMapping ());
709 } else if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
710 _subtitle_stream->Clear ();
711 if (ffmpeg_content) {
712 vector<shared_ptr<FFmpegSubtitleStream> > s = ffmpeg_content->subtitle_streams ();
714 _subtitle_stream->Enable (false);
716 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
717 _subtitle_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
720 if (ffmpeg_content->subtitle_stream()) {
721 checked_set (_subtitle_stream, lexical_cast<string> (ffmpeg_content->subtitle_stream()->id));
723 _subtitle_stream->SetSelection (wxNOT_FOUND);
726 setup_subtitle_control_sensitivity ();
727 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
728 _audio_stream->Clear ();
729 if (ffmpeg_content) {
730 vector<shared_ptr<FFmpegAudioStream> > a = ffmpeg_content->audio_streams ();
731 for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
732 _audio_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
735 if (ffmpeg_content->audio_stream()) {
736 checked_set (_audio_stream, lexical_cast<string> (ffmpeg_content->audio_stream()->id));
739 setup_show_audio_sensitivity ();
740 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
742 setup_show_audio_sensitivity ();
743 } else if (property == FFmpegContentProperty::FILTERS) {
744 if (ffmpeg_content) {
745 pair<string, string> p = Filter::ffmpeg_strings (ffmpeg_content->filters ());
746 if (p.first.empty () && p.second.empty ()) {
747 _filters->SetLabel (_("None"));
749 string const b = p.first + " " + p.second;
750 _filters->SetLabel (std_to_wx (b));
752 _dcp_sizer->Layout ();
758 FilmEditor::setup_container ()
761 vector<Container const *> containers = Container::all ();
762 vector<Container const *>::iterator i = containers.begin ();
763 while (i != containers.end() && *i != _film->container ()) {
768 if (i == containers.end()) {
769 checked_set (_container, -1);
771 checked_set (_container, n);
775 setup_scaling_description ();
778 /** Called when the container widget has been changed */
780 FilmEditor::container_changed (wxCommandEvent &)
786 int const n = _container->GetSelection ();
788 vector<Container const *> containers = Container::all ();
789 assert (n < int (containers.size()));
790 _film->set_container (containers[n]);
794 /** Called when the DCP content type widget has been changed */
796 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
802 int const n = _dcp_content_type->GetSelection ();
803 if (n != wxNOT_FOUND) {
804 _film->set_dcp_content_type (DCPContentType::from_index (n));
808 /** Sets the Film that we are editing */
810 FilmEditor::set_film (shared_ptr<Film> f)
812 set_things_sensitive (f != 0);
821 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
822 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1, _2));
826 FileChanged (_film->directory ());
832 _audio_dialog->set_film (_film);
835 film_changed (Film::NAME);
836 film_changed (Film::USE_DCI_NAME);
837 film_changed (Film::CONTENT);
838 film_changed (Film::LOOP);
839 film_changed (Film::DCP_CONTENT_TYPE);
840 film_changed (Film::CONTAINER);
841 film_changed (Film::SCALER);
842 film_changed (Film::WITH_SUBTITLES);
843 film_changed (Film::SUBTITLE_OFFSET);
844 film_changed (Film::SUBTITLE_SCALE);
845 film_changed (Film::COLOUR_LUT);
846 film_changed (Film::J2K_BANDWIDTH);
847 film_changed (Film::DCI_METADATA);
848 film_changed (Film::DCP_VIDEO_FRAME_RATE);
850 film_content_changed (boost::shared_ptr<Content> (), ContentProperty::START);
851 film_content_changed (boost::shared_ptr<Content> (), VideoContentProperty::VIDEO_CROP);
852 film_content_changed (boost::shared_ptr<Content> (), AudioContentProperty::AUDIO_GAIN);
853 film_content_changed (boost::shared_ptr<Content> (), AudioContentProperty::AUDIO_DELAY);
854 film_content_changed (boost::shared_ptr<Content> (), AudioContentProperty::AUDIO_MAPPING);
855 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAMS);
856 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM);
857 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAMS);
858 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAM);
859 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::FILTERS);
862 /** Updates the sensitivity of lots of widgets to a given value.
863 * @param s true to make sensitive, false to make insensitive.
866 FilmEditor::set_things_sensitive (bool s)
868 _generally_sensitive = s;
871 _use_dci_name->Enable (s);
872 _edit_dci_button->Enable (s);
874 _content->Enable (s);
875 _content->Enable (s);
876 _left_crop->Enable (s);
877 _right_crop->Enable (s);
878 _top_crop->Enable (s);
879 _bottom_crop->Enable (s);
880 _filters_button->Enable (s);
882 _dcp_content_type->Enable (s);
883 _best_dcp_frame_rate->Enable (s);
884 _dcp_frame_rate->Enable (s);
885 _colour_lut->Enable (s);
886 _j2k_bandwidth->Enable (s);
887 _audio_gain->Enable (s);
888 _audio_gain_calculate_button->Enable (s);
889 _show_audio->Enable (s);
890 _audio_delay->Enable (s);
892 setup_subtitle_control_sensitivity ();
893 setup_show_audio_sensitivity ();
894 setup_content_sensitivity ();
897 /** Called when the `Edit filters' button has been clicked */
899 FilmEditor::edit_filters_clicked (wxCommandEvent &)
901 shared_ptr<Content> c = selected_content ();
906 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
911 FilterDialog* d = new FilterDialog (this, fc->filters());
912 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, fc, _1));
917 /** Called when the scaler widget has been changed */
919 FilmEditor::scaler_changed (wxCommandEvent &)
925 int const n = _scaler->GetSelection ();
927 _film->set_scaler (Scaler::from_index (n));
932 FilmEditor::audio_gain_changed (wxCommandEvent &)
934 shared_ptr<AudioContent> ac = selected_audio_content ();
939 ac->set_audio_gain (_audio_gain->GetValue ());
943 FilmEditor::audio_delay_changed (wxCommandEvent &)
945 shared_ptr<AudioContent> ac = selected_audio_content ();
950 ac->set_audio_delay (_audio_delay->GetValue ());
954 FilmEditor::setup_main_notebook_size ()
956 _main_notebook->InvalidateBestSize ();
958 _content_sizer->Layout ();
959 _content_sizer->SetSizeHints (_content_panel);
960 _dcp_sizer->Layout ();
961 _dcp_sizer->SetSizeHints (_dcp_panel);
963 _main_notebook->Fit ();
968 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
970 GainCalculatorDialog* d = new GainCalculatorDialog (this);
973 if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
978 _audio_gain->SetValue (
979 Config::instance()->sound_processor()->db_for_fader_change (
985 /* This appears to be necessary, as the change is not signalled,
988 wxCommandEvent dummy;
989 audio_gain_changed (dummy);
995 FilmEditor::setup_formats ()
997 _formats = Format::all ();
1000 for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
1001 _format->Append (std_to_wx ((*i)->name ()));
1004 _dcp_sizer->Layout ();
1008 FilmEditor::with_subtitles_toggled (wxCommandEvent &)
1014 _film->set_with_subtitles (_with_subtitles->GetValue ());
1018 FilmEditor::setup_subtitle_control_sensitivity ()
1021 if (_generally_sensitive && _film) {
1022 h = _film->has_subtitles ();
1025 _with_subtitles->Enable (h);
1029 j = _film->with_subtitles ();
1032 _subtitle_offset->Enable (j);
1033 _subtitle_scale->Enable (j);
1037 FilmEditor::use_dci_name_toggled (wxCommandEvent &)
1043 _film->set_use_dci_name (_use_dci_name->GetValue ());
1047 FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
1053 DCIMetadataDialog* d = new DCIMetadataDialog (this, _film->dci_metadata ());
1055 _film->set_dci_metadata (d->dci_metadata ());
1060 FilmEditor::active_jobs_changed (bool a)
1062 set_things_sensitive (!a);
1066 FilmEditor::setup_dcp_name ()
1068 string s = _film->dcp_name (true);
1069 if (s.length() > 28) {
1070 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
1071 _dcp_name->SetToolTip (std_to_wx (s));
1073 _dcp_name->SetLabel (std_to_wx (s));
1078 FilmEditor::show_audio_clicked (wxCommandEvent &)
1080 if (_audio_dialog) {
1081 _audio_dialog->Destroy ();
1085 _audio_dialog = new AudioDialog (this);
1086 _audio_dialog->Show ();
1087 _audio_dialog->set_film (_film);
1091 FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
1097 _film->set_dcp_video_frame_rate (_film->best_dcp_video_frame_rate ());
1101 FilmEditor::setup_show_audio_sensitivity ()
1103 _show_audio->Enable (_film);
1107 FilmEditor::setup_content ()
1109 string selected_summary;
1110 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1112 selected_summary = wx_to_std (_content->GetItemText (s));
1115 _content->DeleteAllItems ();
1117 Playlist::ContentList content = _film->content ();
1118 for (Playlist::ContentList::iterator i = content.begin(); i != content.end(); ++i) {
1119 int const t = _content->GetItemCount ();
1120 _content->InsertItem (t, std_to_wx ((*i)->summary ()));
1121 if ((*i)->summary() == selected_summary) {
1122 _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1126 if (selected_summary.empty () && !content.empty ()) {
1127 /* Select the item of content if non was selected before */
1128 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1133 FilmEditor::content_add_clicked (wxCommandEvent &)
1135 wxFileDialog* d = new wxFileDialog (this, _("Choose a file or files"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
1136 int const r = d->ShowModal ();
1143 wxArrayString paths;
1144 d->GetPaths (paths);
1146 for (unsigned int i = 0; i < paths.GetCount(); ++i) {
1147 boost::filesystem::path p (wx_to_std (paths[i]));
1149 if (ImageMagickContent::valid_file (p)) {
1150 _film->add_content (shared_ptr<ImageMagickContent> (new ImageMagickContent (_film, p)));
1151 } else if (SndfileContent::valid_file (p)) {
1152 _film->add_content (shared_ptr<SndfileContent> (new SndfileContent (_film, p)));
1154 _film->add_content (shared_ptr<FFmpegContent> (new FFmpegContent (_film, p)));
1160 FilmEditor::content_remove_clicked (wxCommandEvent &)
1162 shared_ptr<Content> c = selected_content ();
1164 _film->remove_content (c);
1169 FilmEditor::content_selection_changed (wxListEvent &)
1171 setup_content_sensitivity ();
1172 shared_ptr<Content> s = selected_content ();
1173 film_content_changed (s, ContentProperty::START);
1174 film_content_changed (s, VideoContentProperty::VIDEO_CROP);
1175 film_content_changed (s, AudioContentProperty::AUDIO_GAIN);
1176 film_content_changed (s, AudioContentProperty::AUDIO_DELAY);
1177 film_content_changed (s, AudioContentProperty::AUDIO_MAPPING);
1178 film_content_changed (s, FFmpegContentProperty::AUDIO_STREAM);
1179 film_content_changed (s, FFmpegContentProperty::AUDIO_STREAMS);
1180 film_content_changed (s, FFmpegContentProperty::SUBTITLE_STREAM);
1184 FilmEditor::setup_content_sensitivity ()
1186 _content_add->Enable (_generally_sensitive);
1188 shared_ptr<Content> selection = selected_content ();
1190 _content_remove->Enable (selection && _generally_sensitive);
1191 _content_timeline->Enable (_generally_sensitive);
1193 _video_panel->Enable (selection && dynamic_pointer_cast<VideoContent> (selection) && _generally_sensitive);
1194 _audio_panel->Enable (selection && dynamic_pointer_cast<AudioContent> (selection) && _generally_sensitive);
1195 _subtitle_panel->Enable (selection && dynamic_pointer_cast<FFmpegContent> (selection) && _generally_sensitive);
1199 FilmEditor::selected_content ()
1201 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1203 return shared_ptr<Content> ();
1206 Playlist::ContentList c = _film->content ();
1207 if (s < 0 || size_t (s) >= c.size ()) {
1208 return shared_ptr<Content> ();
1214 shared_ptr<VideoContent>
1215 FilmEditor::selected_video_content ()
1217 shared_ptr<Content> c = selected_content ();
1219 return shared_ptr<VideoContent> ();
1222 return dynamic_pointer_cast<VideoContent> (c);
1225 shared_ptr<AudioContent>
1226 FilmEditor::selected_audio_content ()
1228 shared_ptr<Content> c = selected_content ();
1230 return shared_ptr<AudioContent> ();
1233 return dynamic_pointer_cast<AudioContent> (c);
1237 FilmEditor::setup_scaling_description ()
1245 if (_film->video_size().width && _film->video_size().height) {
1246 d << wxString::Format (
1247 _("Original video is %dx%d (%.2f:1)\n"),
1248 _film->video_size().width, _film->video_size().height,
1249 float (_film->video_size().width) / _film->video_size().height
1254 Crop const crop = _film->crop ();
1255 if (crop.left || crop.right || crop.top || crop.bottom) {
1256 libdcp::Size const cropped = _film->cropped_size (_film->video_size ());
1257 d << wxString::Format (
1258 _("Cropped to %dx%d (%.2f:1)\n"),
1259 cropped.width, cropped.height,
1260 float (cropped.width) / cropped.height
1265 Format const * format = _film->format ();
1267 int const padding = format->dcp_padding (_film);
1268 libdcp::Size scaled = format->dcp_size ();
1269 scaled.width -= padding * 2;
1270 d << wxString::Format (
1271 _("Scaled to %dx%d (%.2f:1)\n"),
1272 scaled.width, scaled.height,
1273 float (scaled.width) / scaled.height
1278 d << wxString::Format (
1279 _("Padded with black to %dx%d (%.2f:1)\n"),
1280 format->dcp_size().width, format->dcp_size().height,
1281 float (format->dcp_size().width) / format->dcp_size().height
1287 for (int i = lines; i < 4; ++i) {
1292 _scaling_description->SetLabel (d);
1296 FilmEditor::loop_content_toggled (wxCommandEvent &)
1298 if (_loop_content->GetValue ()) {
1299 _film->set_loop (_loop_count->GetValue ());
1301 _film->set_loop (1);
1304 setup_loop_sensitivity ();
1308 FilmEditor::loop_count_changed (wxCommandEvent &)
1310 _film->set_loop (_loop_count->GetValue ());
1314 FilmEditor::setup_loop_sensitivity ()
1316 _loop_count->Enable (_loop_content->GetValue ());
1320 FilmEditor::content_timeline_clicked (wxCommandEvent &)
1322 if (_timeline_dialog) {
1323 _timeline_dialog->Destroy ();
1324 _timeline_dialog = 0;
1327 _timeline_dialog = new TimelineDialog (this, _film);
1328 _timeline_dialog->Show ();
1332 FilmEditor::audio_stream_changed (wxCommandEvent &)
1334 shared_ptr<Content> c = selected_content ();
1339 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
1344 vector<shared_ptr<FFmpegAudioStream> > a = fc->audio_streams ();
1345 vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin ();
1346 string const s = string_client_data (_audio_stream->GetClientObject (_audio_stream->GetSelection ()));
1347 while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
1351 if (i != a.end ()) {
1352 fc->set_audio_stream (*i);
1355 if (!fc->audio_stream ()) {
1356 _audio_description->SetLabel (wxT (""));
1359 if (fc->audio_channels() == 1) {
1360 s << _("1 channel");
1362 s << fc->audio_channels() << wxT (" ") << _("channels");
1364 s << wxT (", ") << fc->content_audio_frame_rate() << _("Hz");
1365 _audio_description->SetLabel (s);
1372 FilmEditor::subtitle_stream_changed (wxCommandEvent &)
1374 shared_ptr<Content> c = selected_content ();
1379 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
1384 vector<shared_ptr<FFmpegSubtitleStream> > a = fc->subtitle_streams ();
1385 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
1386 string const s = string_client_data (_subtitle_stream->GetClientObject (_subtitle_stream->GetSelection ()));
1387 while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
1391 if (i != a.end ()) {
1392 fc->set_subtitle_stream (*i);
1397 FilmEditor::audio_mapping_changed (AudioMapping m)
1399 shared_ptr<Content> c = selected_content ();
1404 shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (c);
1409 ac->set_audio_mapping (m);