2 Copyright (C) 2012-2013 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>
33 #include "lib/transcode_job.h"
34 #include "lib/exceptions.h"
35 #include "lib/job_manager.h"
36 #include "lib/filter.h"
37 #include "lib/ratio.h"
38 #include "lib/config.h"
39 #include "lib/still_image_content.h"
40 #include "lib/sndfile_content.h"
41 #include "lib/dcp_content_type.h"
42 #include "lib/sound_processor.h"
43 #include "lib/scaler.h"
45 #include "filter_dialog.h"
47 #include "film_editor.h"
48 #include "gain_calculator_dialog.h"
49 #include "dci_metadata_dialog.h"
50 #include "audio_dialog.h"
51 #include "timeline_dialog.h"
52 #include "audio_mapping_view.h"
53 #include "timing_panel.h"
54 #include "subtitle_panel.h"
58 using std::stringstream;
61 using std::setprecision;
65 using boost::shared_ptr;
66 using boost::weak_ptr;
67 using boost::dynamic_pointer_cast;
68 using boost::lexical_cast;
70 /** @param f Film to edit */
71 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
74 , _generally_sensitive (true)
76 , _timeline_dialog (0)
78 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
80 _main_notebook = new wxNotebook (this, wxID_ANY);
81 s->Add (_main_notebook, 1);
83 make_content_panel ();
84 _main_notebook->AddPage (_content_panel, _("Content"), true);
86 _main_notebook->AddPage (_dcp_panel, _("DCP"), false);
91 connect_to_widgets ();
93 JobManager::instance()->ActiveJobsChanged.connect (
94 bind (&FilmEditor::active_jobs_changed, this, _1)
101 FilmEditor::make_dcp_panel ()
103 _dcp_panel = new wxPanel (_main_notebook);
104 _dcp_sizer = new wxBoxSizer (wxVERTICAL);
105 _dcp_panel->SetSizer (_dcp_sizer);
107 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
108 _dcp_sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
112 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Name"), true, wxGBPosition (r, 0));
113 _name = new wxTextCtrl (_dcp_panel, wxID_ANY);
114 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
117 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), true, wxGBPosition (r, 0));
118 _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
119 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
122 int flags = wxALIGN_CENTER_VERTICAL;
124 flags |= wxALIGN_RIGHT;
127 _use_dci_name = new wxCheckBox (_dcp_panel, wxID_ANY, _("Use DCI name"));
128 grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
129 _edit_dci_button = new wxButton (_dcp_panel, wxID_ANY, _("Details..."));
130 grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
133 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), true, wxGBPosition (r, 0));
134 _container = new wxChoice (_dcp_panel, wxID_ANY);
135 grid->Add (_container, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
138 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Content Type"), true, wxGBPosition (r, 0));
139 _dcp_content_type = new wxChoice (_dcp_panel, wxID_ANY);
140 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
144 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Frame Rate"), true, wxGBPosition (r, 0));
145 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
146 _dcp_frame_rate = new wxChoice (_dcp_panel, wxID_ANY);
147 s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
148 _best_dcp_frame_rate = new wxButton (_dcp_panel, wxID_ANY, _("Use best"));
149 s->Add (_best_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
150 grid->Add (s, wxGBPosition (r, 1));
154 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Audio channels"), true, wxGBPosition (r, 0));
155 _dcp_audio_channels = new wxSpinCtrl (_dcp_panel, wxID_ANY);
156 grid->Add (_dcp_audio_channels, wxGBPosition (r, 1));
159 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Resolution"), true, wxGBPosition (r, 0));
160 _dcp_resolution = new wxChoice (_dcp_panel, wxID_ANY);
161 grid->Add (_dcp_resolution, wxGBPosition (r, 1));
165 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
166 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
167 _j2k_bandwidth = new wxSpinCtrl (_dcp_panel, wxID_ANY);
168 s->Add (_j2k_bandwidth, 1);
169 add_label_to_sizer (s, _dcp_panel, _("MBps"), false);
170 grid->Add (s, wxGBPosition (r, 1));
174 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Scaler"), true, wxGBPosition (r, 0));
175 _scaler = new wxChoice (_dcp_panel, wxID_ANY);
176 grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
179 vector<Scaler const *> const sc = Scaler::all ();
180 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
181 _scaler->Append (std_to_wx ((*i)->name()));
184 vector<Ratio const *> const ratio = Ratio::all ();
185 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
186 _container->Append (std_to_wx ((*i)->nickname ()));
189 vector<DCPContentType const *> const ct = DCPContentType::all ();
190 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
191 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
194 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
195 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
196 _dcp_frame_rate->Append (std_to_wx (boost::lexical_cast<string> (*i)));
199 _dcp_audio_channels->SetRange (0, MAX_AUDIO_CHANNELS);
200 _j2k_bandwidth->SetRange (50, 250);
202 _dcp_resolution->Append (_("2K"));
203 _dcp_resolution->Append (_("4K"));
207 FilmEditor::connect_to_widgets ()
209 _name->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (FilmEditor::name_changed), 0, this);
210 _use_dci_name->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::use_dci_name_toggled), 0, this);
211 _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
212 _container->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::container_changed), 0, this);
213 _ratio->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ratio_changed), 0, this);
214 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
215 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
216 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,wxListEventHandler (FilmEditor::content_right_click), 0, this);
217 _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
218 _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
219 _content_timeline->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_timeline_clicked), 0, this);
220 _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
221 _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
222 _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
223 _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
224 _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
225 _scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
226 _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
227 _dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
228 _best_dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
229 _dcp_audio_channels->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::dcp_audio_channels_changed), 0, this);
230 _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_changed), 0, this);
231 _audio_gain->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_gain_changed), 0, this);
232 _audio_gain_calculate_button->Connect (
233 wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::audio_gain_calculate_button_clicked), 0, this
235 _show_audio->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::show_audio_clicked), 0, this);
236 _audio_delay->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
237 _audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::audio_stream_changed), 0, this);
238 _dcp_resolution->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_resolution_changed), 0, this);
239 _sequence_video->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::sequence_video_changed), 0, this);
241 _audio_mapping->Changed.connect (boost::bind (&FilmEditor::audio_mapping_changed, this, _1));
245 FilmEditor::make_video_panel ()
247 _video_panel = new wxPanel (_content_notebook);
248 wxBoxSizer* video_sizer = new wxBoxSizer (wxVERTICAL);
249 _video_panel->SetSizer (video_sizer);
251 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
252 video_sizer->Add (grid, 0, wxALL, 8);
255 add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), true, wxGBPosition (r, 0));
256 _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
257 grid->Add (_left_crop, wxGBPosition (r, 1));
260 add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), true, wxGBPosition (r, 0));
261 _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
262 grid->Add (_right_crop, wxGBPosition (r, 1));
265 add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), true, wxGBPosition (r, 0));
266 _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
267 grid->Add (_top_crop, wxGBPosition (r, 1));
270 add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), true, wxGBPosition (r, 0));
271 _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
272 grid->Add (_bottom_crop, wxGBPosition (r, 1));
275 add_label_to_grid_bag_sizer (grid, _video_panel, _("Scale to"), true, wxGBPosition (r, 0));
276 _ratio = new wxChoice (_video_panel, wxID_ANY);
277 grid->Add (_ratio, wxGBPosition (r, 1));
280 _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
281 grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
282 wxFont font = _scaling_description->GetFont();
283 font.SetStyle(wxFONTSTYLE_ITALIC);
284 font.SetPointSize(font.GetPointSize() - 1);
285 _scaling_description->SetFont(font);
288 /* VIDEO-only stuff */
290 add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), true, wxGBPosition (r, 0));
291 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
292 _filters = new wxStaticText (_video_panel, wxID_ANY, _("None"));
293 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
294 _filters_button = new wxButton (_video_panel, wxID_ANY, _("Edit..."));
295 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
296 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
300 _left_crop->SetRange (0, 1024);
301 _top_crop->SetRange (0, 1024);
302 _right_crop->SetRange (0, 1024);
303 _bottom_crop->SetRange (0, 1024);
307 FilmEditor::make_content_panel ()
309 _content_panel = new wxPanel (_main_notebook);
310 _content_sizer = new wxBoxSizer (wxVERTICAL);
311 _content_panel->SetSizer (_content_sizer);
314 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
316 _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
317 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
319 _content->InsertColumn (0, wxT(""));
320 _content->SetColumnWidth (0, 512);
322 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
323 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
324 b->Add (_content_add, 1, wxEXPAND | wxLEFT | wxRIGHT);
325 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
326 b->Add (_content_remove, 1, wxEXPAND | wxLEFT | wxRIGHT);
327 _content_timeline = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
328 b->Add (_content_timeline, 1, wxEXPAND | wxLEFT | wxRIGHT);
330 s->Add (b, 0, wxALL, 4);
332 _content_sizer->Add (s, 0.75, wxEXPAND | wxALL, 6);
335 _sequence_video = new wxCheckBox (_content_panel, wxID_ANY, _("Keep video in sequence"));
336 _content_sizer->Add (_sequence_video);
338 _content_notebook = new wxNotebook (_content_panel, wxID_ANY);
339 _content_sizer->Add (_content_notebook, 1, wxEXPAND | wxTOP, 6);
342 _content_notebook->AddPage (_video_panel, _("Video"), false);
344 _content_notebook->AddPage (_audio_panel, _("Audio"), false);
345 _subtitle_panel = new SubtitlePanel (this);
346 _timing_panel = new TimingPanel (this);
350 FilmEditor::make_audio_panel ()
352 _audio_panel = new wxPanel (_content_notebook);
353 wxBoxSizer* audio_sizer = new wxBoxSizer (wxVERTICAL);
354 _audio_panel->SetSizer (audio_sizer);
356 wxFlexGridSizer* grid = new wxFlexGridSizer (3, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
357 audio_sizer->Add (grid, 0, wxALL, 8);
359 _show_audio = new wxButton (_audio_panel, wxID_ANY, _("Show Audio..."));
360 grid->Add (_show_audio, 1);
364 add_label_to_sizer (grid, _audio_panel, _("Audio Gain"), true);
366 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
367 _audio_gain = new wxSpinCtrl (_audio_panel);
368 s->Add (_audio_gain, 1);
369 add_label_to_sizer (s, _audio_panel, _("dB"), false);
373 _audio_gain_calculate_button = new wxButton (_audio_panel, wxID_ANY, _("Calculate..."));
374 grid->Add (_audio_gain_calculate_button);
376 add_label_to_sizer (grid, _audio_panel, _("Audio Delay"), false);
378 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
379 _audio_delay = new wxSpinCtrl (_audio_panel);
380 s->Add (_audio_delay, 1);
381 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
382 add_label_to_sizer (s, _audio_panel, _("ms"), false);
388 add_label_to_sizer (grid, _audio_panel, _("Audio Stream"), true);
389 _audio_stream = new wxChoice (_audio_panel, wxID_ANY);
390 grid->Add (_audio_stream, 1, wxEXPAND);
391 _audio_description = new wxStaticText (_audio_panel, wxID_ANY, wxT (""));
394 grid->Add (_audio_description, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
398 _audio_mapping = new AudioMappingView (_audio_panel);
399 audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6);
401 _audio_gain->SetRange (-60, 60);
402 _audio_delay->SetRange (-1000, 1000);
405 /** Called when the left crop widget has been changed */
407 FilmEditor::left_crop_changed (wxCommandEvent &)
409 shared_ptr<VideoContent> c = selected_video_content ();
414 c->set_left_crop (_left_crop->GetValue ());
417 /** Called when the right crop widget has been changed */
419 FilmEditor::right_crop_changed (wxCommandEvent &)
421 shared_ptr<VideoContent> c = selected_video_content ();
426 c->set_right_crop (_right_crop->GetValue ());
429 /** Called when the top crop widget has been changed */
431 FilmEditor::top_crop_changed (wxCommandEvent &)
433 shared_ptr<VideoContent> c = selected_video_content ();
438 c->set_top_crop (_top_crop->GetValue ());
441 /** Called when the bottom crop value has been changed */
443 FilmEditor::bottom_crop_changed (wxCommandEvent &)
445 shared_ptr<VideoContent> c = selected_video_content ();
450 c->set_bottom_crop (_bottom_crop->GetValue ());
453 /** Called when the name widget has been changed */
455 FilmEditor::name_changed (wxCommandEvent &)
461 _film->set_name (string (_name->GetValue().mb_str()));
465 FilmEditor::j2k_bandwidth_changed (wxCommandEvent &)
471 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
475 FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
481 _film->set_dcp_video_frame_rate (
482 boost::lexical_cast<int> (
483 wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
489 FilmEditor::dcp_audio_channels_changed (wxCommandEvent &)
495 _film->set_dcp_audio_channels (_dcp_audio_channels->GetValue ());
499 FilmEditor::dcp_resolution_changed (wxCommandEvent &)
505 _film->set_resolution (_dcp_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
509 /** Called when the metadata stored in the Film object has changed;
510 * so that we can update the GUI.
511 * @param p Property of the Film that has changed.
514 FilmEditor::film_changed (Film::Property p)
524 _subtitle_panel->film_changed (p);
525 _timing_panel->film_changed (p);
532 setup_show_audio_sensitivity ();
534 case Film::CONTAINER:
538 checked_set (_name, _film->name());
541 case Film::WITH_SUBTITLES:
544 case Film::DCP_CONTENT_TYPE:
545 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
549 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
551 case Film::RESOLUTION:
552 checked_set (_dcp_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
555 case Film::J2K_BANDWIDTH:
556 checked_set (_j2k_bandwidth, double (_film->j2k_bandwidth()) / 1e6);
558 case Film::USE_DCI_NAME:
559 checked_set (_use_dci_name, _film->use_dci_name ());
562 case Film::DCI_METADATA:
565 case Film::DCP_VIDEO_FRAME_RATE:
568 for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
569 if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_video_frame_rate())) {
570 checked_set (_dcp_frame_rate, i);
577 checked_set (_dcp_frame_rate, -1);
580 _best_dcp_frame_rate->Enable (_film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
583 case Film::DCP_AUDIO_CHANNELS:
584 _dcp_audio_channels->SetValue (_film->dcp_audio_channels ());
585 _audio_mapping->set_channels (_film->dcp_audio_channels ());
588 case Film::SEQUENCE_VIDEO:
589 checked_set (_sequence_video, _film->sequence_video ());
595 FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
600 /* We call this method ourselves (as well as using it as a signal handler)
606 shared_ptr<Content> content = weak_content.lock ();
607 if (content != selected_content ()) {
611 shared_ptr<VideoContent> video_content;
612 shared_ptr<AudioContent> audio_content;
613 shared_ptr<SubtitleContent> subtitle_content;
614 shared_ptr<FFmpegContent> ffmpeg_content;
616 video_content = dynamic_pointer_cast<VideoContent> (content);
617 audio_content = dynamic_pointer_cast<AudioContent> (content);
618 subtitle_content = dynamic_pointer_cast<SubtitleContent> (content);
619 ffmpeg_content = dynamic_pointer_cast<FFmpegContent> (content);
622 _subtitle_panel->film_content_changed (content, subtitle_content, ffmpeg_content, property);
623 _timing_panel->film_content_changed (content, subtitle_content, ffmpeg_content, property);
625 /* We can't use case {} here */
627 if (property == VideoContentProperty::VIDEO_CROP) {
628 checked_set (_left_crop, video_content ? video_content->crop().left : 0);
629 checked_set (_right_crop, video_content ? video_content->crop().right : 0);
630 checked_set (_top_crop, video_content ? video_content->crop().top : 0);
631 checked_set (_bottom_crop, video_content ? video_content->crop().bottom : 0);
632 setup_scaling_description ();
633 } else if (property == VideoContentProperty::VIDEO_RATIO) {
636 vector<Ratio const *> ratios = Ratio::all ();
637 vector<Ratio const *>::iterator i = ratios.begin ();
638 while (i != ratios.end() && *i != video_content->ratio()) {
643 if (i == ratios.end()) {
644 checked_set (_ratio, -1);
646 checked_set (_ratio, n);
649 checked_set (_ratio, -1);
651 setup_scaling_description ();
652 } else if (property == AudioContentProperty::AUDIO_GAIN) {
653 checked_set (_audio_gain, audio_content ? audio_content->audio_gain() : 0);
654 } else if (property == AudioContentProperty::AUDIO_DELAY) {
655 checked_set (_audio_delay, audio_content ? audio_content->audio_delay() : 0);
656 } else if (property == AudioContentProperty::AUDIO_MAPPING) {
657 _audio_mapping->set (audio_content ? audio_content->audio_mapping () : AudioMapping ());
658 } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
659 _audio_stream->Clear ();
660 if (ffmpeg_content) {
661 vector<shared_ptr<FFmpegAudioStream> > a = ffmpeg_content->audio_streams ();
662 for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
663 _audio_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
666 if (ffmpeg_content->audio_stream()) {
667 checked_set (_audio_stream, lexical_cast<string> (ffmpeg_content->audio_stream()->id));
670 setup_show_audio_sensitivity ();
671 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
673 setup_show_audio_sensitivity ();
674 } else if (property == FFmpegContentProperty::FILTERS) {
675 if (ffmpeg_content) {
676 pair<string, string> p = Filter::ffmpeg_strings (ffmpeg_content->filters ());
677 if (p.first.empty () && p.second.empty ()) {
678 _filters->SetLabel (_("None"));
680 string const b = p.first + " " + p.second;
681 _filters->SetLabel (std_to_wx (b));
683 _dcp_sizer->Layout ();
689 FilmEditor::setup_container ()
692 vector<Ratio const *> ratios = Ratio::all ();
693 vector<Ratio const *>::iterator i = ratios.begin ();
694 while (i != ratios.end() && *i != _film->container ()) {
699 if (i == ratios.end()) {
700 checked_set (_container, -1);
702 checked_set (_container, n);
706 setup_scaling_description ();
709 /** Called when the container widget has been changed */
711 FilmEditor::container_changed (wxCommandEvent &)
717 int const n = _container->GetSelection ();
719 vector<Ratio const *> ratios = Ratio::all ();
720 assert (n < int (ratios.size()));
721 _film->set_container (ratios[n]);
725 /** Called when the DCP content type widget has been changed */
727 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
733 int const n = _dcp_content_type->GetSelection ();
734 if (n != wxNOT_FOUND) {
735 _film->set_dcp_content_type (DCPContentType::from_index (n));
739 /** Sets the Film that we are editing */
741 FilmEditor::set_film (shared_ptr<Film> f)
743 set_things_sensitive (f != 0);
752 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
753 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1, _2));
757 FileChanged (_film->directory ());
762 film_changed (Film::NAME);
763 film_changed (Film::USE_DCI_NAME);
764 film_changed (Film::CONTENT);
765 film_changed (Film::DCP_CONTENT_TYPE);
766 film_changed (Film::CONTAINER);
767 film_changed (Film::RESOLUTION);
768 film_changed (Film::SCALER);
769 film_changed (Film::WITH_SUBTITLES);
770 film_changed (Film::J2K_BANDWIDTH);
771 film_changed (Film::DCI_METADATA);
772 film_changed (Film::DCP_VIDEO_FRAME_RATE);
773 film_changed (Film::DCP_AUDIO_CHANNELS);
774 film_changed (Film::SEQUENCE_VIDEO);
776 if (!_film->content().empty ()) {
777 set_selection (_film->content().front ());
781 content_selection_changed (ev);
784 /** Updates the sensitivity of lots of widgets to a given value.
785 * @param s true to make sensitive, false to make insensitive.
788 FilmEditor::set_things_sensitive (bool s)
790 _generally_sensitive = s;
793 _use_dci_name->Enable (s);
794 _edit_dci_button->Enable (s);
796 _content->Enable (s);
797 _left_crop->Enable (s);
798 _right_crop->Enable (s);
799 _top_crop->Enable (s);
800 _bottom_crop->Enable (s);
801 _filters_button->Enable (s);
803 _dcp_content_type->Enable (s);
804 _dcp_frame_rate->Enable (s);
805 _dcp_audio_channels->Enable (s);
806 _j2k_bandwidth->Enable (s);
807 _audio_gain->Enable (s);
808 _audio_gain_calculate_button->Enable (s);
809 _show_audio->Enable (s);
810 _audio_delay->Enable (s);
811 _container->Enable (s);
813 _subtitle_panel->setup_control_sensitivity ();
814 setup_show_audio_sensitivity ();
815 setup_content_sensitivity ();
816 _best_dcp_frame_rate->Enable (s && _film && _film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
819 /** Called when the `Edit filters' button has been clicked */
821 FilmEditor::edit_filters_clicked (wxCommandEvent &)
823 shared_ptr<Content> c = selected_content ();
828 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
833 FilterDialog* d = new FilterDialog (this, fc->filters());
834 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, fc, _1));
839 /** Called when the scaler widget has been changed */
841 FilmEditor::scaler_changed (wxCommandEvent &)
847 int const n = _scaler->GetSelection ();
849 _film->set_scaler (Scaler::from_index (n));
854 FilmEditor::audio_gain_changed (wxCommandEvent &)
856 shared_ptr<AudioContent> ac = selected_audio_content ();
861 ac->set_audio_gain (_audio_gain->GetValue ());
865 FilmEditor::audio_delay_changed (wxCommandEvent &)
867 shared_ptr<AudioContent> ac = selected_audio_content ();
872 ac->set_audio_delay (_audio_delay->GetValue ());
876 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
878 GainCalculatorDialog* d = new GainCalculatorDialog (this);
881 if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
886 _audio_gain->SetValue (
887 Config::instance()->sound_processor()->db_for_fader_change (
893 /* This appears to be necessary, as the change is not signalled,
896 wxCommandEvent dummy;
897 audio_gain_changed (dummy);
903 FilmEditor::setup_ratios ()
905 _ratios = Ratio::all ();
908 for (vector<Ratio const *>::iterator i = _ratios.begin(); i != _ratios.end(); ++i) {
909 _ratio->Append (std_to_wx ((*i)->nickname ()));
912 _dcp_sizer->Layout ();
916 FilmEditor::use_dci_name_toggled (wxCommandEvent &)
922 _film->set_use_dci_name (_use_dci_name->GetValue ());
926 FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
932 DCIMetadataDialog* d = new DCIMetadataDialog (this, _film->dci_metadata ());
934 _film->set_dci_metadata (d->dci_metadata ());
939 FilmEditor::active_jobs_changed (bool a)
941 set_things_sensitive (!a);
945 FilmEditor::setup_dcp_name ()
947 string s = _film->dcp_name (true);
948 if (s.length() > 28) {
949 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
950 _dcp_name->SetToolTip (std_to_wx (s));
952 _dcp_name->SetLabel (std_to_wx (s));
957 FilmEditor::show_audio_clicked (wxCommandEvent &)
960 _audio_dialog->Destroy ();
964 shared_ptr<Content> c = selected_content ();
969 shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (c);
974 _audio_dialog = new AudioDialog (this);
975 _audio_dialog->Show ();
976 _audio_dialog->set_content (ac);
980 FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
986 _film->set_dcp_video_frame_rate (_film->best_dcp_video_frame_rate ());
990 FilmEditor::setup_show_audio_sensitivity ()
992 _show_audio->Enable (_film);
996 FilmEditor::setup_content ()
998 string selected_summary;
999 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1001 selected_summary = wx_to_std (_content->GetItemText (s));
1004 _content->DeleteAllItems ();
1006 ContentList content = _film->content ();
1007 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
1008 int const t = _content->GetItemCount ();
1009 _content->InsertItem (t, std_to_wx ((*i)->summary ()));
1010 if ((*i)->summary() == selected_summary) {
1011 _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1015 if (selected_summary.empty () && !content.empty ()) {
1016 /* Select the item of content if none was selected before */
1017 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1022 FilmEditor::content_add_clicked (wxCommandEvent &)
1024 wxFileDialog* d = new wxFileDialog (this, _("Choose a file or files"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
1025 int const r = d->ShowModal ();
1032 wxArrayString paths;
1033 d->GetPaths (paths);
1035 for (unsigned int i = 0; i < paths.GetCount(); ++i) {
1036 boost::filesystem::path p (wx_to_std (paths[i]));
1038 shared_ptr<Content> c;
1040 if (StillImageContent::valid_file (p)) {
1041 c.reset (new StillImageContent (_film, p));
1042 } else if (SndfileContent::valid_file (p)) {
1043 c.reset (new SndfileContent (_film, p));
1045 c.reset (new FFmpegContent (_film, p));
1048 _film->examine_and_add_content (c);
1053 FilmEditor::content_remove_clicked (wxCommandEvent &)
1055 shared_ptr<Content> c = selected_content ();
1057 _film->remove_content (c);
1061 content_selection_changed (ev);
1065 FilmEditor::content_selection_changed (wxListEvent &)
1067 setup_content_sensitivity ();
1068 shared_ptr<Content> s = selected_content ();
1070 if (_audio_dialog && s && dynamic_pointer_cast<AudioContent> (s)) {
1071 _audio_dialog->set_content (dynamic_pointer_cast<AudioContent> (s));
1074 film_content_changed (s, ContentProperty::START);
1075 film_content_changed (s, ContentProperty::LENGTH);
1076 film_content_changed (s, VideoContentProperty::VIDEO_CROP);
1077 film_content_changed (s, VideoContentProperty::VIDEO_RATIO);
1078 film_content_changed (s, AudioContentProperty::AUDIO_GAIN);
1079 film_content_changed (s, AudioContentProperty::AUDIO_DELAY);
1080 film_content_changed (s, AudioContentProperty::AUDIO_MAPPING);
1081 film_content_changed (s, FFmpegContentProperty::AUDIO_STREAM);
1082 film_content_changed (s, FFmpegContentProperty::AUDIO_STREAMS);
1083 film_content_changed (s, FFmpegContentProperty::SUBTITLE_STREAM);
1084 film_content_changed (s, FFmpegContentProperty::SUBTITLE_STREAMS);
1085 film_content_changed (s, FFmpegContentProperty::FILTERS);
1086 film_content_changed (s, SubtitleContentProperty::SUBTITLE_OFFSET);
1087 film_content_changed (s, SubtitleContentProperty::SUBTITLE_SCALE);
1091 FilmEditor::setup_content_sensitivity ()
1093 _content_add->Enable (_generally_sensitive);
1095 shared_ptr<Content> selection = selected_content ();
1097 _content_remove->Enable (selection && _generally_sensitive);
1098 _content_timeline->Enable (_generally_sensitive);
1100 _video_panel->Enable (selection && dynamic_pointer_cast<VideoContent> (selection) && _generally_sensitive);
1101 _audio_panel->Enable (selection && dynamic_pointer_cast<AudioContent> (selection) && _generally_sensitive);
1102 _subtitle_panel->Enable (selection && dynamic_pointer_cast<FFmpegContent> (selection) && _generally_sensitive);
1103 _timing_panel->Enable (selection && _generally_sensitive);
1107 FilmEditor::selected_content ()
1109 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1111 return shared_ptr<Content> ();
1114 ContentList c = _film->content ();
1115 if (s < 0 || size_t (s) >= c.size ()) {
1116 return shared_ptr<Content> ();
1122 shared_ptr<VideoContent>
1123 FilmEditor::selected_video_content ()
1125 shared_ptr<Content> c = selected_content ();
1127 return shared_ptr<VideoContent> ();
1130 return dynamic_pointer_cast<VideoContent> (c);
1133 shared_ptr<AudioContent>
1134 FilmEditor::selected_audio_content ()
1136 shared_ptr<Content> c = selected_content ();
1138 return shared_ptr<AudioContent> ();
1141 return dynamic_pointer_cast<AudioContent> (c);
1144 shared_ptr<SubtitleContent>
1145 FilmEditor::selected_subtitle_content ()
1147 shared_ptr<Content> c = selected_content ();
1149 return shared_ptr<SubtitleContent> ();
1152 return dynamic_pointer_cast<SubtitleContent> (c);
1156 FilmEditor::setup_scaling_description ()
1158 shared_ptr<VideoContent> vc = selected_video_content ();
1160 _scaling_description->SetLabel ("");
1168 if (vc->video_size().width && vc->video_size().height) {
1169 d << wxString::Format (
1170 _("Original video is %dx%d (%.2f:1)\n"),
1171 vc->video_size().width, vc->video_size().height,
1172 float (vc->video_size().width) / vc->video_size().height
1177 Crop const crop = vc->crop ();
1178 if ((crop.left || crop.right || crop.top || crop.bottom) && vc->video_size() != libdcp::Size (0, 0)) {
1179 libdcp::Size cropped = vc->video_size ();
1180 cropped.width -= crop.left + crop.right;
1181 cropped.height -= crop.top + crop.bottom;
1182 d << wxString::Format (
1183 _("Cropped to %dx%d (%.2f:1)\n"),
1184 cropped.width, cropped.height,
1185 float (cropped.width) / cropped.height
1190 Ratio const * ratio = vc->ratio ();
1192 libdcp::Size container_size = _film->container()->size (_film->full_frame ());
1194 libdcp::Size const scaled = ratio->size (container_size);
1195 d << wxString::Format (
1196 _("Scaled to %dx%d (%.2f:1)\n"),
1197 scaled.width, scaled.height,
1198 float (scaled.width) / scaled.height
1202 if (scaled != container_size) {
1203 d << wxString::Format (
1204 _("Padded with black to %dx%d (%.2f:1)\n"),
1205 container_size.width, container_size.height,
1206 float (container_size.width) / container_size.height
1212 for (int i = lines; i < 4; ++i) {
1216 _scaling_description->SetLabel (d);
1220 FilmEditor::content_timeline_clicked (wxCommandEvent &)
1222 if (_timeline_dialog) {
1223 _timeline_dialog->Destroy ();
1224 _timeline_dialog = 0;
1227 _timeline_dialog = new TimelineDialog (this, _film);
1228 _timeline_dialog->Show ();
1232 FilmEditor::audio_stream_changed (wxCommandEvent &)
1234 shared_ptr<Content> c = selected_content ();
1239 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
1244 vector<shared_ptr<FFmpegAudioStream> > a = fc->audio_streams ();
1245 vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin ();
1246 string const s = string_client_data (_audio_stream->GetClientObject (_audio_stream->GetSelection ()));
1247 while (i != a.end() && lexical_cast<string> ((*i)->id) != s) {
1251 if (i != a.end ()) {
1252 fc->set_audio_stream (*i);
1255 if (!fc->audio_stream ()) {
1256 _audio_description->SetLabel (wxT (""));
1259 if (fc->audio_channels() == 1) {
1260 s << _("1 channel");
1262 s << fc->audio_channels() << wxT (" ") << _("channels");
1264 s << wxT (", ") << fc->content_audio_frame_rate() << _("Hz");
1265 _audio_description->SetLabel (s);
1270 FilmEditor::audio_mapping_changed (AudioMapping m)
1272 shared_ptr<Content> c = selected_content ();
1277 shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (c);
1282 ac->set_audio_mapping (m);
1286 FilmEditor::set_selection (weak_ptr<Content> wc)
1288 ContentList content = _film->content ();
1289 for (size_t i = 0; i < content.size(); ++i) {
1290 if (content[i] == wc.lock ()) {
1291 _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1293 _content->SetItemState (i, 0, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1299 FilmEditor::ratio_changed (wxCommandEvent &)
1305 shared_ptr<Content> c = selected_content ();
1310 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
1315 int const n = _ratio->GetSelection ();
1317 vector<Ratio const *> ratios = Ratio::all ();
1318 assert (n < int (ratios.size()));
1319 vc->set_ratio (ratios[n]);
1324 FilmEditor::sequence_video_changed (wxCommandEvent &)
1326 _film->set_sequence_video (_sequence_video->GetValue ());
1330 FilmEditor::content_right_click (wxListEvent& ev)
1333 cl.push_back (selected_content ());
1334 _menu.popup (cl, ev.GetPoint ());