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 "timeline_dialog.h"
56 #include "audio_mapping_view.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, _("Content Type"), wxGBPosition (r, 0));
130 _dcp_content_type = new wxChoice (_dcp_panel, wxID_ANY);
131 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
135 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Frame Rate"), wxGBPosition (r, 0));
136 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
137 _dcp_frame_rate = new wxChoice (_dcp_panel, wxID_ANY);
138 s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
139 _best_dcp_frame_rate = new wxButton (_dcp_panel, wxID_ANY, _("Use best"));
140 s->Add (_best_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 6);
141 grid->Add (s, wxGBPosition (r, 1));
145 vector<DCPContentType const *> const ct = DCPContentType::all ();
146 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
147 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
150 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
151 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
152 _dcp_frame_rate->Append (std_to_wx (boost::lexical_cast<string> (*i)));
157 FilmEditor::connect_to_widgets ()
159 _name->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (FilmEditor::name_changed), 0, this);
160 _use_dci_name->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::use_dci_name_toggled), 0, this);
161 _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
162 _format->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this);
163 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
164 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
165 _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
166 _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
167 _content_timeline->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_timeline_clicked), 0, this);
168 _loop_content->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::loop_content_toggled), 0, this);
169 _loop_count->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::loop_count_changed), 0, this);
170 _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
171 _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
172 _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
173 _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
174 _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
175 _scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
176 _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
177 _dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
178 _best_dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
179 _with_subtitles->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
180 _subtitle_offset->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_offset_changed), 0, this);
181 _subtitle_scale->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this);
182 _colour_lut->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::colour_lut_changed), 0, this);
183 _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_changed), 0, this);
184 _audio_gain->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_gain_changed), 0, this);
185 _audio_gain_calculate_button->Connect (
186 wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::audio_gain_calculate_button_clicked), 0, this
188 _show_audio->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::show_audio_clicked), 0, this);
189 _audio_delay->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
190 _audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::audio_stream_changed), 0, this);
191 _subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::subtitle_stream_changed), 0, this);
192 _audio_mapping->Changed.connect (bind (&FilmEditor::audio_mapping_changed, this, _1));
196 FilmEditor::make_video_panel ()
198 _video_panel = new wxPanel (_content_notebook);
199 _video_sizer = new wxBoxSizer (wxVERTICAL);
200 _video_panel->SetSizer (_video_sizer);
202 wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
203 _video_sizer->Add (grid, 0, wxALL, 8);
206 add_label_to_grid_bag_sizer (grid, _video_panel, _("Format"), wxGBPosition (r, 0));
207 _format = new wxChoice (_video_panel, wxID_ANY);
208 grid->Add (_format, wxGBPosition (r, 1));
211 add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0));
212 _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
213 grid->Add (_left_crop, wxGBPosition (r, 1));
216 add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), wxGBPosition (r, 0));
217 _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
218 grid->Add (_right_crop, wxGBPosition (r, 1));
221 add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), wxGBPosition (r, 0));
222 _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
223 grid->Add (_top_crop, wxGBPosition (r, 1));
226 add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), wxGBPosition (r, 0));
227 _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
228 grid->Add (_bottom_crop, wxGBPosition (r, 1));
231 _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
232 grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
233 wxFont font = _scaling_description->GetFont();
234 font.SetStyle(wxFONTSTYLE_ITALIC);
235 font.SetPointSize(font.GetPointSize() - 1);
236 _scaling_description->SetFont(font);
239 /* VIDEO-only stuff */
241 add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), wxGBPosition (r, 0));
242 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
243 _filters = new wxStaticText (_video_panel, wxID_ANY, _("None"));
244 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
245 _filters_button = new wxButton (_video_panel, wxID_ANY, _("Edit..."));
246 s->Add (_filters_button, 0);
247 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
251 add_label_to_grid_bag_sizer (grid, _video_panel, _("Scaler"), wxGBPosition (r, 0));
252 _scaler = new wxChoice (_video_panel, wxID_ANY);
253 grid->Add (_scaler, wxGBPosition (r, 1));
256 vector<Scaler const *> const sc = Scaler::all ();
257 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
258 _scaler->Append (std_to_wx ((*i)->name()));
261 add_label_to_grid_bag_sizer (grid, _video_panel, _("Colour look-up table"), wxGBPosition (r, 0));
262 _colour_lut = new wxChoice (_video_panel, wxID_ANY);
263 for (int i = 0; i < 2; ++i) {
264 _colour_lut->Append (std_to_wx (colour_lut_index_to_name (i)));
266 _colour_lut->SetSelection (0);
267 grid->Add (_colour_lut, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
271 add_label_to_grid_bag_sizer (grid, _video_panel, _("JPEG2000 bandwidth"), wxGBPosition (r, 0));
272 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
273 _j2k_bandwidth = new wxSpinCtrl (_video_panel, wxID_ANY);
274 s->Add (_j2k_bandwidth, 1);
275 add_label_to_sizer (s, _video_panel, _("MBps"));
276 grid->Add (s, wxGBPosition (r, 1));
280 _left_crop->SetRange (0, 1024);
281 _top_crop->SetRange (0, 1024);
282 _right_crop->SetRange (0, 1024);
283 _bottom_crop->SetRange (0, 1024);
284 _j2k_bandwidth->SetRange (50, 250);
288 FilmEditor::make_content_panel ()
290 _content_panel = new wxPanel (_main_notebook);
291 _content_sizer = new wxBoxSizer (wxVERTICAL);
292 _content_panel->SetSizer (_content_sizer);
295 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
297 _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
298 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
300 _content->InsertColumn (0, wxT(""));
301 _content->SetColumnWidth (0, 512);
303 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
304 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
305 b->Add (_content_add, 1, wxEXPAND | wxLEFT | wxRIGHT);
306 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
307 b->Add (_content_remove, 1, wxEXPAND | wxLEFT | wxRIGHT);
308 _content_timeline = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
309 b->Add (_content_timeline, 1, wxEXPAND | wxLEFT | wxRIGHT);
311 s->Add (b, 0, wxALL, 4);
313 _content_sizer->Add (s, 0.75, wxEXPAND | wxALL, 6);
316 wxBoxSizer* h = new wxBoxSizer (wxHORIZONTAL);
317 _loop_content = new wxCheckBox (_content_panel, wxID_ANY, _("Loop everything"));
318 h->Add (_loop_content, 0, wxALL, 6);
319 _loop_count = new wxSpinCtrl (_content_panel, wxID_ANY);
320 h->Add (_loop_count, 0, wxALL, 6);
321 add_label_to_sizer (h, _content_panel, _("times"));
322 _content_sizer->Add (h, 0, wxALL, 6);
324 _content_notebook = new wxNotebook (_content_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_LEFT);
325 _content_sizer->Add (_content_notebook, 1, wxEXPAND | wxTOP, 6);
328 _content_notebook->AddPage (_video_panel, _("Video"), false);
330 _content_notebook->AddPage (_audio_panel, _("Audio"), false);
331 make_subtitle_panel ();
332 _content_notebook->AddPage (_subtitle_panel, _("Subtitles"), false);
334 _loop_count->SetRange (2, 1024);
338 FilmEditor::make_audio_panel ()
340 _audio_panel = new wxPanel (_content_notebook);
341 _audio_sizer = new wxBoxSizer (wxVERTICAL);
342 _audio_panel->SetSizer (_audio_sizer);
344 wxFlexGridSizer* grid = new wxFlexGridSizer (3, 4, 4);
345 _audio_sizer->Add (grid, 0, wxALL, 8);
347 _show_audio = new wxButton (_audio_panel, wxID_ANY, _("Show Audio..."));
348 grid->Add (_show_audio, 1);
352 add_label_to_sizer (grid, _audio_panel, _("Audio Gain"));
354 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
355 _audio_gain = new wxSpinCtrl (_audio_panel);
356 s->Add (_audio_gain, 1);
357 add_label_to_sizer (s, _audio_panel, _("dB"));
361 _audio_gain_calculate_button = new wxButton (_audio_panel, wxID_ANY, _("Calculate..."));
362 grid->Add (_audio_gain_calculate_button);
364 add_label_to_sizer (grid, _audio_panel, _("Audio Delay"));
366 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
367 _audio_delay = new wxSpinCtrl (_audio_panel);
368 s->Add (_audio_delay, 1);
369 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
370 add_label_to_sizer (s, _audio_panel, _("ms"));
376 add_label_to_sizer (grid, _audio_panel, _("Audio Stream"));
377 _audio_stream = new wxChoice (_audio_panel, wxID_ANY);
378 grid->Add (_audio_stream, 1);
379 _audio_description = new wxStaticText (_audio_panel, wxID_ANY, wxT (""));
382 grid->Add (_audio_description, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
386 _audio_mapping = new AudioMappingView (_audio_panel);
387 _audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6);
389 _audio_gain->SetRange (-60, 60);
390 _audio_delay->SetRange (-1000, 1000);
394 FilmEditor::make_subtitle_panel ()
396 _subtitle_panel = new wxPanel (_content_notebook);
397 _subtitle_sizer = new wxBoxSizer (wxVERTICAL);
398 _subtitle_panel->SetSizer (_subtitle_sizer);
399 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
400 _subtitle_sizer->Add (grid, 0, wxALL, 8);
402 _with_subtitles = new wxCheckBox (_subtitle_panel, wxID_ANY, _("With Subtitles"));
403 grid->Add (_with_subtitles, 1);
407 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset"));
408 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
409 _subtitle_offset = new wxSpinCtrl (_subtitle_panel);
410 s->Add (_subtitle_offset);
411 add_label_to_sizer (s, _subtitle_panel, _("pixels"));
416 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Scale"));
417 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
418 _subtitle_scale = new wxSpinCtrl (_subtitle_panel);
419 s->Add (_subtitle_scale);
420 add_label_to_sizer (s, _subtitle_panel, _("%"));
424 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle stream"));
425 _subtitle_stream = new wxChoice (_subtitle_panel, wxID_ANY);
426 grid->Add (_subtitle_stream, 1, wxEXPAND | wxALL, 6);
429 _subtitle_offset->SetRange (-1024, 1024);
430 _subtitle_scale->SetRange (1, 1000);
433 /** Called when the left crop widget has been changed */
435 FilmEditor::left_crop_changed (wxCommandEvent &)
441 _film->set_left_crop (_left_crop->GetValue ());
444 /** Called when the right crop widget has been changed */
446 FilmEditor::right_crop_changed (wxCommandEvent &)
452 _film->set_right_crop (_right_crop->GetValue ());
455 /** Called when the top crop widget has been changed */
457 FilmEditor::top_crop_changed (wxCommandEvent &)
463 _film->set_top_crop (_top_crop->GetValue ());
466 /** Called when the bottom crop value has been changed */
468 FilmEditor::bottom_crop_changed (wxCommandEvent &)
474 _film->set_bottom_crop (_bottom_crop->GetValue ());
477 /** Called when the name widget has been changed */
479 FilmEditor::name_changed (wxCommandEvent &)
485 _film->set_name (string (_name->GetValue().mb_str()));
489 FilmEditor::subtitle_offset_changed (wxCommandEvent &)
495 _film->set_subtitle_offset (_subtitle_offset->GetValue ());
499 FilmEditor::subtitle_scale_changed (wxCommandEvent &)
505 _film->set_subtitle_scale (_subtitle_scale->GetValue() / 100.0);
509 FilmEditor::colour_lut_changed (wxCommandEvent &)
515 _film->set_colour_lut (_colour_lut->GetSelection ());
519 FilmEditor::j2k_bandwidth_changed (wxCommandEvent &)
525 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
529 FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
535 _film->set_dcp_video_frame_rate (
536 boost::lexical_cast<int> (
537 wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
543 /** Called when the metadata stored in the Film object has changed;
544 * so that we can update the GUI.
545 * @param p Property of the Film that has changed.
548 FilmEditor::film_changed (Film::Property p)
565 setup_subtitle_control_sensitivity ();
566 setup_show_audio_sensitivity ();
569 checked_set (_loop_content, _film->loop() > 1);
570 checked_set (_loop_count, _film->loop());
571 setup_loop_sensitivity ();
577 checked_set (_left_crop, _film->crop().left);
578 checked_set (_right_crop, _film->crop().right);
579 checked_set (_top_crop, _film->crop().top);
580 checked_set (_bottom_crop, _film->crop().bottom);
581 setup_scaling_description ();
585 pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
586 if (p.first.empty () && p.second.empty ()) {
587 _filters->SetLabel (_("None"));
589 string const b = p.first + " " + p.second;
590 _filters->SetLabel (std_to_wx (b));
592 _dcp_sizer->Layout ();
596 checked_set (_name, _film->name());
599 case Film::DCP_CONTENT_TYPE:
600 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
604 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
606 case Film::AUDIO_GAIN:
607 checked_set (_audio_gain, _film->audio_gain ());
609 case Film::AUDIO_DELAY:
610 checked_set (_audio_delay, _film->audio_delay ());
612 case Film::WITH_SUBTITLES:
613 checked_set (_with_subtitles, _film->with_subtitles ());
614 setup_subtitle_control_sensitivity ();
617 case Film::SUBTITLE_OFFSET:
618 checked_set (_subtitle_offset, _film->subtitle_offset ());
620 case Film::SUBTITLE_SCALE:
621 checked_set (_subtitle_scale, _film->subtitle_scale() * 100);
623 case Film::COLOUR_LUT:
624 checked_set (_colour_lut, _film->colour_lut ());
626 case Film::J2K_BANDWIDTH:
627 checked_set (_j2k_bandwidth, double (_film->j2k_bandwidth()) / 1e6);
629 case Film::USE_DCI_NAME:
630 checked_set (_use_dci_name, _film->use_dci_name ());
633 case Film::DCI_METADATA:
636 case Film::DCP_VIDEO_FRAME_RATE:
639 for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
640 if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_video_frame_rate())) {
641 checked_set (_dcp_frame_rate, i);
648 checked_set (_dcp_frame_rate, -1);
651 _best_dcp_frame_rate->Enable (_film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
658 FilmEditor::film_content_changed (weak_ptr<Content> content, int property)
661 /* We call this method ourselves (as well as using it as a signal handler)
667 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
668 setup_subtitle_control_sensitivity ();
669 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
670 setup_show_audio_sensitivity ();
671 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
673 setup_show_audio_sensitivity ();
678 FilmEditor::setup_format ()
681 vector<Format const *>::iterator i = _formats.begin ();
682 while (i != _formats.end() && *i != _film->format ()) {
687 if (i == _formats.end()) {
688 checked_set (_format, -1);
690 checked_set (_format, n);
694 setup_scaling_description ();
697 /** Called when the format widget has been changed */
699 FilmEditor::format_changed (wxCommandEvent &)
705 int const n = _format->GetSelection ();
707 assert (n < int (_formats.size()));
708 _film->set_format (_formats[n]);
712 /** Called when the DCP content type widget has been changed */
714 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
720 int const n = _dcp_content_type->GetSelection ();
721 if (n != wxNOT_FOUND) {
722 _film->set_dcp_content_type (DCPContentType::from_index (n));
726 /** Sets the Film that we are editing */
728 FilmEditor::set_film (shared_ptr<Film> f)
730 set_things_sensitive (f != 0);
739 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
740 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1, _2));
744 FileChanged (_film->directory ());
750 _audio_dialog->set_film (_film);
753 film_changed (Film::NAME);
754 film_changed (Film::USE_DCI_NAME);
755 film_changed (Film::CONTENT);
756 film_changed (Film::LOOP);
757 film_changed (Film::DCP_CONTENT_TYPE);
758 film_changed (Film::FORMAT);
759 film_changed (Film::CROP);
760 film_changed (Film::FILTERS);
761 film_changed (Film::SCALER);
762 film_changed (Film::AUDIO_GAIN);
763 film_changed (Film::AUDIO_DELAY);
764 film_changed (Film::WITH_SUBTITLES);
765 film_changed (Film::SUBTITLE_OFFSET);
766 film_changed (Film::SUBTITLE_SCALE);
767 film_changed (Film::COLOUR_LUT);
768 film_changed (Film::J2K_BANDWIDTH);
769 film_changed (Film::DCI_METADATA);
770 film_changed (Film::DCP_VIDEO_FRAME_RATE);
772 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAMS);
773 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM);
774 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAMS);
775 film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAM);
778 /** Updates the sensitivity of lots of widgets to a given value.
779 * @param s true to make sensitive, false to make insensitive.
782 FilmEditor::set_things_sensitive (bool s)
784 _generally_sensitive = s;
787 _use_dci_name->Enable (s);
788 _edit_dci_button->Enable (s);
790 _content->Enable (s);
791 _content->Enable (s);
792 _left_crop->Enable (s);
793 _right_crop->Enable (s);
794 _top_crop->Enable (s);
795 _bottom_crop->Enable (s);
796 _filters_button->Enable (s);
798 _dcp_content_type->Enable (s);
799 _best_dcp_frame_rate->Enable (s);
800 _dcp_frame_rate->Enable (s);
801 _colour_lut->Enable (s);
802 _j2k_bandwidth->Enable (s);
803 _audio_gain->Enable (s);
804 _audio_gain_calculate_button->Enable (s);
805 _show_audio->Enable (s);
806 _audio_delay->Enable (s);
808 setup_subtitle_control_sensitivity ();
809 setup_show_audio_sensitivity ();
810 setup_content_button_sensitivity ();
813 /** Called when the `Edit filters' button has been clicked */
815 FilmEditor::edit_filters_clicked (wxCommandEvent &)
817 FilterDialog* d = new FilterDialog (this, _film->filters());
818 d->ActiveChanged.connect (bind (&Film::set_filters, _film, _1));
823 /** Called when the scaler widget has been changed */
825 FilmEditor::scaler_changed (wxCommandEvent &)
831 int const n = _scaler->GetSelection ();
833 _film->set_scaler (Scaler::from_index (n));
838 FilmEditor::audio_gain_changed (wxCommandEvent &)
844 _film->set_audio_gain (_audio_gain->GetValue ());
848 FilmEditor::audio_delay_changed (wxCommandEvent &)
854 _film->set_audio_delay (_audio_delay->GetValue ());
858 FilmEditor::setup_main_notebook_size ()
860 _main_notebook->InvalidateBestSize ();
862 _content_sizer->Layout ();
863 _content_sizer->SetSizeHints (_content_panel);
864 _dcp_sizer->Layout ();
865 _dcp_sizer->SetSizeHints (_dcp_panel);
867 _main_notebook->Fit ();
872 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
874 GainCalculatorDialog* d = new GainCalculatorDialog (this);
877 if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
882 _audio_gain->SetValue (
883 Config::instance()->sound_processor()->db_for_fader_change (
889 /* This appears to be necessary, as the change is not signalled,
892 wxCommandEvent dummy;
893 audio_gain_changed (dummy);
899 FilmEditor::setup_formats ()
901 _formats = Format::all ();
904 for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
905 _format->Append (std_to_wx ((*i)->name ()));
908 _dcp_sizer->Layout ();
912 FilmEditor::with_subtitles_toggled (wxCommandEvent &)
918 _film->set_with_subtitles (_with_subtitles->GetValue ());
922 FilmEditor::setup_subtitle_control_sensitivity ()
925 if (_generally_sensitive && _film) {
926 h = _film->has_subtitles ();
929 _with_subtitles->Enable (h);
933 j = _film->with_subtitles ();
936 _subtitle_offset->Enable (j);
937 _subtitle_scale->Enable (j);
941 FilmEditor::use_dci_name_toggled (wxCommandEvent &)
947 _film->set_use_dci_name (_use_dci_name->GetValue ());
951 FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
957 DCIMetadataDialog* d = new DCIMetadataDialog (this, _film->dci_metadata ());
959 _film->set_dci_metadata (d->dci_metadata ());
964 FilmEditor::active_jobs_changed (bool a)
966 set_things_sensitive (!a);
970 FilmEditor::setup_dcp_name ()
972 string s = _film->dcp_name (true);
973 if (s.length() > 28) {
974 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
975 _dcp_name->SetToolTip (std_to_wx (s));
977 _dcp_name->SetLabel (std_to_wx (s));
982 FilmEditor::show_audio_clicked (wxCommandEvent &)
985 _audio_dialog->Destroy ();
989 _audio_dialog = new AudioDialog (this);
990 _audio_dialog->Show ();
991 _audio_dialog->set_film (_film);
995 FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
1001 _film->set_dcp_video_frame_rate (_film->best_dcp_video_frame_rate ());
1005 FilmEditor::setup_show_audio_sensitivity ()
1007 _show_audio->Enable (_film);
1011 FilmEditor::setup_content ()
1013 string selected_summary;
1014 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1016 selected_summary = wx_to_std (_content->GetItemText (s));
1019 _content->DeleteAllItems ();
1021 Playlist::ContentList content = _film->content ();
1022 for (Playlist::ContentList::iterator i = content.begin(); i != content.end(); ++i) {
1023 int const t = _content->GetItemCount ();
1024 _content->InsertItem (t, std_to_wx ((*i)->summary ()));
1025 if ((*i)->summary() == selected_summary) {
1026 _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1030 if (selected_summary.empty () && !content.empty ()) {
1031 /* Select the item of content if non was selected before */
1032 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1037 FilmEditor::content_add_clicked (wxCommandEvent &)
1039 wxFileDialog* d = new wxFileDialog (this, _("Choose a file or files"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
1040 int const r = d->ShowModal ();
1047 wxArrayString paths;
1048 d->GetPaths (paths);
1050 for (unsigned int i = 0; i < paths.GetCount(); ++i) {
1051 boost::filesystem::path p (wx_to_std (paths[i]));
1053 if (ImageMagickContent::valid_file (p)) {
1054 _film->add_content (shared_ptr<ImageMagickContent> (new ImageMagickContent (p)));
1055 } else if (SndfileContent::valid_file (p)) {
1056 _film->add_content (shared_ptr<SndfileContent> (new SndfileContent (p)));
1058 _film->add_content (shared_ptr<FFmpegContent> (new FFmpegContent (p)));
1064 FilmEditor::content_remove_clicked (wxCommandEvent &)
1066 shared_ptr<Content> c = selected_content ();
1068 _film->remove_content (c);
1073 FilmEditor::content_selection_changed (wxListEvent &)
1075 setup_content_button_sensitivity ();
1079 FilmEditor::setup_content_button_sensitivity ()
1081 _content_add->Enable (_generally_sensitive);
1083 shared_ptr<Content> selection = selected_content ();
1085 _content_remove->Enable (selection && _generally_sensitive);
1086 _content_timeline->Enable (_generally_sensitive);
1090 FilmEditor::selected_content ()
1092 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1094 return shared_ptr<Content> ();
1097 Playlist::ContentList c = _film->content ();
1098 if (s < 0 || size_t (s) >= c.size ()) {
1099 return shared_ptr<Content> ();
1106 FilmEditor::setup_scaling_description ()
1114 if (_film->video_size().width && _film->video_size().height) {
1115 d << wxString::Format (
1116 _("Original video is %dx%d (%.2f:1)\n"),
1117 _film->video_size().width, _film->video_size().height,
1118 float (_film->video_size().width) / _film->video_size().height
1123 Crop const crop = _film->crop ();
1124 if (crop.left || crop.right || crop.top || crop.bottom) {
1125 libdcp::Size const cropped = _film->cropped_size (_film->video_size ());
1126 d << wxString::Format (
1127 _("Cropped to %dx%d (%.2f:1)\n"),
1128 cropped.width, cropped.height,
1129 float (cropped.width) / cropped.height
1134 Format const * format = _film->format ();
1136 int const padding = format->dcp_padding (_film);
1137 libdcp::Size scaled = format->dcp_size ();
1138 scaled.width -= padding * 2;
1139 d << wxString::Format (
1140 _("Scaled to %dx%d (%.2f:1)\n"),
1141 scaled.width, scaled.height,
1142 float (scaled.width) / scaled.height
1147 d << wxString::Format (
1148 _("Padded with black to %dx%d (%.2f:1)\n"),
1149 format->dcp_size().width, format->dcp_size().height,
1150 float (format->dcp_size().width) / format->dcp_size().height
1156 for (int i = lines; i < 4; ++i) {
1161 _scaling_description->SetLabel (d);
1165 FilmEditor::loop_content_toggled (wxCommandEvent &)
1167 if (_loop_content->GetValue ()) {
1168 _film->set_loop (_loop_count->GetValue ());
1170 _film->set_loop (1);
1173 setup_loop_sensitivity ();
1177 FilmEditor::loop_count_changed (wxCommandEvent &)
1179 _film->set_loop (_loop_count->GetValue ());
1183 FilmEditor::setup_loop_sensitivity ()
1185 _loop_count->Enable (_loop_content->GetValue ());
1189 FilmEditor::content_timeline_clicked (wxCommandEvent &)
1191 if (_timeline_dialog) {
1192 _timeline_dialog->Destroy ();
1193 _timeline_dialog = 0;
1196 _timeline_dialog = new TimelineDialog (this, _film);
1197 _timeline_dialog->Show ();
1201 FilmEditor::setup_content_properties ()
1203 _audio_stream->Clear ();
1204 _subtitle_stream->Clear ();
1206 shared_ptr<Content> c = selected_content ();
1211 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
1214 vector<shared_ptr<FFmpegAudioStream> > a = fc->audio_streams ();
1215 for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
1216 _audio_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
1219 if (fc->audio_stream()) {
1220 checked_set (_audio_stream, lexical_cast<string> (fc->audio_stream()->id));
1223 vector<shared_ptr<FFmpegSubtitleStream> > s = fc->subtitle_streams ();
1225 _subtitle_stream->Enable (false);
1227 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
1228 _subtitle_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
1231 if (fc->subtitle_stream()) {
1232 checked_set (_subtitle_stream, lexical_cast<string> (fc->subtitle_stream()->id));
1234 _subtitle_stream->SetSelection (wxNOT_FOUND);
1237 /* XXX: should be general audiocontent */
1238 _audio_mapping->set_mapping (fc->audio_mapping ());
1243 FilmEditor::audio_stream_changed (wxCommandEvent &)
1245 shared_ptr<Content> c = selected_content ();
1250 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
1255 vector<shared_ptr<FFmpegAudioStream> > a = fc->audio_streams ();
1256 vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin ();
1257 string const s = string_client_data (_audio_stream->GetClientObject (_audio_stream->GetSelection ()));
1258 while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
1262 if (i != a.end ()) {
1263 fc->set_audio_stream (*i);
1266 if (!fc->audio_stream ()) {
1267 _audio_description->SetLabel (wxT (""));
1270 if (fc->audio_channels() == 1) {
1271 s << _("1 channel");
1273 s << fc->audio_channels() << wxT (" ") << _("channels");
1275 s << wxT (", ") << fc->content_audio_frame_rate() << _("Hz");
1276 _audio_description->SetLabel (s);
1283 FilmEditor::subtitle_stream_changed (wxCommandEvent &)
1285 shared_ptr<Content> c = selected_content ();
1290 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
1295 vector<shared_ptr<FFmpegSubtitleStream> > a = fc->subtitle_streams ();
1296 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
1297 string const s = string_client_data (_subtitle_stream->GetClientObject (_subtitle_stream->GetSelection ()));
1298 while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
1302 if (i != a.end ()) {
1303 fc->set_subtitle_stream (*i);
1308 FilmEditor::audio_mapping_changed (AudioMapping m)
1310 shared_ptr<Content> c = selected_content ();
1315 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
1320 /* XXX: should be general to audiocontent */
1321 fc->audio_stream()->mapping = m;