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 "dci_metadata_dialog.h"
49 #include "timeline_dialog.h"
50 #include "timing_panel.h"
51 #include "subtitle_panel.h"
52 #include "audio_panel.h"
56 using std::stringstream;
59 using std::setprecision;
63 using boost::shared_ptr;
64 using boost::weak_ptr;
65 using boost::dynamic_pointer_cast;
66 using boost::lexical_cast;
68 /** @param f Film to edit */
69 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
72 , _generally_sensitive (true)
73 , _timeline_dialog (0)
75 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
77 _main_notebook = new wxNotebook (this, wxID_ANY);
78 s->Add (_main_notebook, 1);
80 make_content_panel ();
81 _main_notebook->AddPage (_content_panel, _("Content"), true);
83 _main_notebook->AddPage (_dcp_panel, _("DCP"), false);
88 connect_to_widgets ();
90 JobManager::instance()->ActiveJobsChanged.connect (
91 bind (&FilmEditor::active_jobs_changed, this, _1)
98 FilmEditor::make_dcp_panel ()
100 _dcp_panel = new wxPanel (_main_notebook);
101 _dcp_sizer = new wxBoxSizer (wxVERTICAL);
102 _dcp_panel->SetSizer (_dcp_sizer);
104 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
105 _dcp_sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
109 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Name"), true, wxGBPosition (r, 0));
110 _name = new wxTextCtrl (_dcp_panel, wxID_ANY);
111 grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
114 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), true, wxGBPosition (r, 0));
115 _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
116 grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
119 int flags = wxALIGN_CENTER_VERTICAL;
121 flags |= wxALIGN_RIGHT;
124 _use_dci_name = new wxCheckBox (_dcp_panel, wxID_ANY, _("Use DCI name"));
125 grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
126 _edit_dci_button = new wxButton (_dcp_panel, wxID_ANY, _("Details..."));
127 grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
130 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), true, wxGBPosition (r, 0));
131 _container = new wxChoice (_dcp_panel, wxID_ANY);
132 grid->Add (_container, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
135 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Content Type"), true, wxGBPosition (r, 0));
136 _dcp_content_type = new wxChoice (_dcp_panel, wxID_ANY);
137 grid->Add (_dcp_content_type, wxGBPosition (r, 1));
141 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Frame Rate"), true, wxGBPosition (r, 0));
142 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
143 _dcp_frame_rate = new wxChoice (_dcp_panel, wxID_ANY);
144 s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
145 _best_dcp_frame_rate = new wxButton (_dcp_panel, wxID_ANY, _("Use best"));
146 s->Add (_best_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
147 grid->Add (s, wxGBPosition (r, 1));
151 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Audio channels"), true, wxGBPosition (r, 0));
152 _dcp_audio_channels = new wxSpinCtrl (_dcp_panel, wxID_ANY);
153 grid->Add (_dcp_audio_channels, wxGBPosition (r, 1));
156 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Resolution"), true, wxGBPosition (r, 0));
157 _dcp_resolution = new wxChoice (_dcp_panel, wxID_ANY);
158 grid->Add (_dcp_resolution, wxGBPosition (r, 1));
162 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
163 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
164 _j2k_bandwidth = new wxSpinCtrl (_dcp_panel, wxID_ANY);
165 s->Add (_j2k_bandwidth, 1);
166 add_label_to_sizer (s, _dcp_panel, _("MBps"), false);
167 grid->Add (s, wxGBPosition (r, 1));
171 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Scaler"), true, wxGBPosition (r, 0));
172 _scaler = new wxChoice (_dcp_panel, wxID_ANY);
173 grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
176 vector<Scaler const *> const sc = Scaler::all ();
177 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
178 _scaler->Append (std_to_wx ((*i)->name()));
181 vector<Ratio const *> const ratio = Ratio::all ();
182 for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
183 _container->Append (std_to_wx ((*i)->nickname ()));
186 vector<DCPContentType const *> const ct = DCPContentType::all ();
187 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
188 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
191 list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
192 for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
193 _dcp_frame_rate->Append (std_to_wx (boost::lexical_cast<string> (*i)));
196 _dcp_audio_channels->SetRange (0, MAX_AUDIO_CHANNELS);
197 _j2k_bandwidth->SetRange (50, 250);
199 _dcp_resolution->Append (_("2K"));
200 _dcp_resolution->Append (_("4K"));
204 FilmEditor::connect_to_widgets ()
206 _name->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (FilmEditor::name_changed), 0, this);
207 _use_dci_name->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::use_dci_name_toggled), 0, this);
208 _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
209 _container->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::container_changed), 0, this);
210 _ratio->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ratio_changed), 0, this);
211 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
212 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (FilmEditor::content_selection_changed), 0, this);
213 _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,wxListEventHandler (FilmEditor::content_right_click), 0, this);
214 _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
215 _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
216 _content_timeline->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_timeline_clicked), 0, this);
217 _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
218 _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
219 _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
220 _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
221 _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
222 _scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
223 _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
224 _dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
225 _best_dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
226 _dcp_audio_channels->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::dcp_audio_channels_changed), 0, this);
227 _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_changed), 0, this);
228 _dcp_resolution->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_resolution_changed), 0, this);
229 _sequence_video->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::sequence_video_changed), 0, this);
233 FilmEditor::make_video_panel ()
235 _video_panel = new wxPanel (_content_notebook);
236 wxBoxSizer* video_sizer = new wxBoxSizer (wxVERTICAL);
237 _video_panel->SetSizer (video_sizer);
239 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
240 video_sizer->Add (grid, 0, wxALL, 8);
243 add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), true, wxGBPosition (r, 0));
244 _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
245 grid->Add (_left_crop, wxGBPosition (r, 1));
248 add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), true, wxGBPosition (r, 0));
249 _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
250 grid->Add (_right_crop, wxGBPosition (r, 1));
253 add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), true, wxGBPosition (r, 0));
254 _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
255 grid->Add (_top_crop, wxGBPosition (r, 1));
258 add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), true, wxGBPosition (r, 0));
259 _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
260 grid->Add (_bottom_crop, wxGBPosition (r, 1));
263 add_label_to_grid_bag_sizer (grid, _video_panel, _("Scale to"), true, wxGBPosition (r, 0));
264 _ratio = new wxChoice (_video_panel, wxID_ANY);
265 grid->Add (_ratio, wxGBPosition (r, 1));
268 _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
269 grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
270 wxFont font = _scaling_description->GetFont();
271 font.SetStyle(wxFONTSTYLE_ITALIC);
272 font.SetPointSize(font.GetPointSize() - 1);
273 _scaling_description->SetFont(font);
276 /* VIDEO-only stuff */
278 add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), true, wxGBPosition (r, 0));
279 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
280 _filters = new wxStaticText (_video_panel, wxID_ANY, _("None"));
281 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
282 _filters_button = new wxButton (_video_panel, wxID_ANY, _("Edit..."));
283 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
284 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
288 _left_crop->SetRange (0, 1024);
289 _top_crop->SetRange (0, 1024);
290 _right_crop->SetRange (0, 1024);
291 _bottom_crop->SetRange (0, 1024);
295 FilmEditor::make_content_panel ()
297 _content_panel = new wxPanel (_main_notebook);
298 _content_sizer = new wxBoxSizer (wxVERTICAL);
299 _content_panel->SetSizer (_content_sizer);
302 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
304 _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
305 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
307 _content->InsertColumn (0, wxT(""));
308 _content->SetColumnWidth (0, 512);
310 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
311 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
312 b->Add (_content_add, 1, wxEXPAND | wxLEFT | wxRIGHT);
313 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
314 b->Add (_content_remove, 1, wxEXPAND | wxLEFT | wxRIGHT);
315 _content_timeline = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
316 b->Add (_content_timeline, 1, wxEXPAND | wxLEFT | wxRIGHT);
318 s->Add (b, 0, wxALL, 4);
320 _content_sizer->Add (s, 0.75, wxEXPAND | wxALL, 6);
323 _sequence_video = new wxCheckBox (_content_panel, wxID_ANY, _("Keep video in sequence"));
324 _content_sizer->Add (_sequence_video);
326 _content_notebook = new wxNotebook (_content_panel, wxID_ANY);
327 _content_sizer->Add (_content_notebook, 1, wxEXPAND | wxTOP, 6);
330 _content_notebook->AddPage (_video_panel, _("Video"), false);
331 _audio_panel = new AudioPanel (this);
332 _subtitle_panel = new SubtitlePanel (this);
333 _timing_panel = new TimingPanel (this);
336 /** Called when the left crop widget has been changed */
338 FilmEditor::left_crop_changed (wxCommandEvent &)
340 shared_ptr<VideoContent> c = selected_video_content ();
345 c->set_left_crop (_left_crop->GetValue ());
348 /** Called when the right crop widget has been changed */
350 FilmEditor::right_crop_changed (wxCommandEvent &)
352 shared_ptr<VideoContent> c = selected_video_content ();
357 c->set_right_crop (_right_crop->GetValue ());
360 /** Called when the top crop widget has been changed */
362 FilmEditor::top_crop_changed (wxCommandEvent &)
364 shared_ptr<VideoContent> c = selected_video_content ();
369 c->set_top_crop (_top_crop->GetValue ());
372 /** Called when the bottom crop value has been changed */
374 FilmEditor::bottom_crop_changed (wxCommandEvent &)
376 shared_ptr<VideoContent> c = selected_video_content ();
381 c->set_bottom_crop (_bottom_crop->GetValue ());
384 /** Called when the name widget has been changed */
386 FilmEditor::name_changed (wxCommandEvent &)
392 _film->set_name (string (_name->GetValue().mb_str()));
396 FilmEditor::j2k_bandwidth_changed (wxCommandEvent &)
402 _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
406 FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
412 _film->set_dcp_video_frame_rate (
413 boost::lexical_cast<int> (
414 wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
420 FilmEditor::dcp_audio_channels_changed (wxCommandEvent &)
426 _film->set_dcp_audio_channels (_dcp_audio_channels->GetValue ());
430 FilmEditor::dcp_resolution_changed (wxCommandEvent &)
436 _film->set_resolution (_dcp_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
440 /** Called when the metadata stored in the Film object has changed;
441 * so that we can update the GUI.
442 * @param p Property of the Film that has changed.
445 FilmEditor::film_changed (Film::Property p)
455 _audio_panel->film_changed (p);
456 _subtitle_panel->film_changed (p);
457 _timing_panel->film_changed (p);
465 case Film::CONTAINER:
469 checked_set (_name, _film->name());
472 case Film::WITH_SUBTITLES:
475 case Film::DCP_CONTENT_TYPE:
476 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
480 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
482 case Film::RESOLUTION:
483 checked_set (_dcp_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
486 case Film::J2K_BANDWIDTH:
487 checked_set (_j2k_bandwidth, double (_film->j2k_bandwidth()) / 1e6);
489 case Film::USE_DCI_NAME:
490 checked_set (_use_dci_name, _film->use_dci_name ());
493 case Film::DCI_METADATA:
496 case Film::DCP_VIDEO_FRAME_RATE:
499 for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
500 if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_video_frame_rate())) {
501 checked_set (_dcp_frame_rate, i);
508 checked_set (_dcp_frame_rate, -1);
511 _best_dcp_frame_rate->Enable (_film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
514 case Film::DCP_AUDIO_CHANNELS:
515 _dcp_audio_channels->SetValue (_film->dcp_audio_channels ());
518 case Film::SEQUENCE_VIDEO:
519 checked_set (_sequence_video, _film->sequence_video ());
525 FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
530 /* We call this method ourselves (as well as using it as a signal handler)
536 shared_ptr<Content> content = weak_content.lock ();
537 if (content != selected_content ()) {
541 shared_ptr<VideoContent> video_content;
542 shared_ptr<AudioContent> audio_content;
543 shared_ptr<SubtitleContent> subtitle_content;
544 shared_ptr<FFmpegContent> ffmpeg_content;
546 video_content = dynamic_pointer_cast<VideoContent> (content);
547 audio_content = dynamic_pointer_cast<AudioContent> (content);
548 subtitle_content = dynamic_pointer_cast<SubtitleContent> (content);
549 ffmpeg_content = dynamic_pointer_cast<FFmpegContent> (content);
552 _audio_panel->film_content_changed (content, audio_content, subtitle_content, ffmpeg_content, property);
553 _subtitle_panel->film_content_changed (content, audio_content, subtitle_content, ffmpeg_content, property);
554 _timing_panel->film_content_changed (content, audio_content, subtitle_content, ffmpeg_content, property);
556 /* We can't use case {} here */
558 if (property == VideoContentProperty::VIDEO_CROP) {
559 checked_set (_left_crop, video_content ? video_content->crop().left : 0);
560 checked_set (_right_crop, video_content ? video_content->crop().right : 0);
561 checked_set (_top_crop, video_content ? video_content->crop().top : 0);
562 checked_set (_bottom_crop, video_content ? video_content->crop().bottom : 0);
563 setup_scaling_description ();
564 } else if (property == VideoContentProperty::VIDEO_RATIO) {
567 vector<Ratio const *> ratios = Ratio::all ();
568 vector<Ratio const *>::iterator i = ratios.begin ();
569 while (i != ratios.end() && *i != video_content->ratio()) {
574 if (i == ratios.end()) {
575 checked_set (_ratio, -1);
577 checked_set (_ratio, n);
580 checked_set (_ratio, -1);
582 setup_scaling_description ();
583 } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
585 } else if (property == FFmpegContentProperty::FILTERS) {
586 if (ffmpeg_content) {
587 pair<string, string> p = Filter::ffmpeg_strings (ffmpeg_content->filters ());
588 if (p.first.empty () && p.second.empty ()) {
589 _filters->SetLabel (_("None"));
591 string const b = p.first + " " + p.second;
592 _filters->SetLabel (std_to_wx (b));
594 _dcp_sizer->Layout ();
600 FilmEditor::setup_container ()
603 vector<Ratio const *> ratios = Ratio::all ();
604 vector<Ratio const *>::iterator i = ratios.begin ();
605 while (i != ratios.end() && *i != _film->container ()) {
610 if (i == ratios.end()) {
611 checked_set (_container, -1);
613 checked_set (_container, n);
617 setup_scaling_description ();
620 /** Called when the container widget has been changed */
622 FilmEditor::container_changed (wxCommandEvent &)
628 int const n = _container->GetSelection ();
630 vector<Ratio const *> ratios = Ratio::all ();
631 assert (n < int (ratios.size()));
632 _film->set_container (ratios[n]);
636 /** Called when the DCP content type widget has been changed */
638 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
644 int const n = _dcp_content_type->GetSelection ();
645 if (n != wxNOT_FOUND) {
646 _film->set_dcp_content_type (DCPContentType::from_index (n));
650 /** Sets the Film that we are editing */
652 FilmEditor::set_film (shared_ptr<Film> f)
654 set_things_sensitive (f != 0);
663 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
664 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1, _2));
668 FileChanged (_film->directory ());
673 film_changed (Film::NAME);
674 film_changed (Film::USE_DCI_NAME);
675 film_changed (Film::CONTENT);
676 film_changed (Film::DCP_CONTENT_TYPE);
677 film_changed (Film::CONTAINER);
678 film_changed (Film::RESOLUTION);
679 film_changed (Film::SCALER);
680 film_changed (Film::WITH_SUBTITLES);
681 film_changed (Film::J2K_BANDWIDTH);
682 film_changed (Film::DCI_METADATA);
683 film_changed (Film::DCP_VIDEO_FRAME_RATE);
684 film_changed (Film::DCP_AUDIO_CHANNELS);
685 film_changed (Film::SEQUENCE_VIDEO);
687 if (!_film->content().empty ()) {
688 set_selection (_film->content().front ());
692 content_selection_changed (ev);
695 /** Updates the sensitivity of lots of widgets to a given value.
696 * @param s true to make sensitive, false to make insensitive.
699 FilmEditor::set_things_sensitive (bool s)
701 _generally_sensitive = s;
704 _use_dci_name->Enable (s);
705 _edit_dci_button->Enable (s);
706 _content->Enable (s);
707 _dcp_content_type->Enable (s);
708 _dcp_frame_rate->Enable (s);
709 _dcp_audio_channels->Enable (s);
710 _j2k_bandwidth->Enable (s);
711 _container->Enable (s);
713 _subtitle_panel->setup_control_sensitivity ();
714 _audio_panel->setup_sensitivity ();
715 setup_content_sensitivity ();
716 _best_dcp_frame_rate->Enable (s && _film && _film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
719 /** Called when the `Edit filters' button has been clicked */
721 FilmEditor::edit_filters_clicked (wxCommandEvent &)
723 shared_ptr<Content> c = selected_content ();
728 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
733 FilterDialog* d = new FilterDialog (this, fc->filters());
734 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, fc, _1));
739 /** Called when the scaler widget has been changed */
741 FilmEditor::scaler_changed (wxCommandEvent &)
747 int const n = _scaler->GetSelection ();
749 _film->set_scaler (Scaler::from_index (n));
754 FilmEditor::setup_ratios ()
756 _ratios = Ratio::all ();
759 for (vector<Ratio const *>::iterator i = _ratios.begin(); i != _ratios.end(); ++i) {
760 _ratio->Append (std_to_wx ((*i)->nickname ()));
763 _dcp_sizer->Layout ();
767 FilmEditor::use_dci_name_toggled (wxCommandEvent &)
773 _film->set_use_dci_name (_use_dci_name->GetValue ());
777 FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
783 DCIMetadataDialog* d = new DCIMetadataDialog (this, _film->dci_metadata ());
785 _film->set_dci_metadata (d->dci_metadata ());
790 FilmEditor::active_jobs_changed (bool a)
792 set_things_sensitive (!a);
796 FilmEditor::setup_dcp_name ()
798 string s = _film->dcp_name (true);
799 if (s.length() > 28) {
800 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
801 _dcp_name->SetToolTip (std_to_wx (s));
803 _dcp_name->SetLabel (std_to_wx (s));
808 FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
814 _film->set_dcp_video_frame_rate (_film->best_dcp_video_frame_rate ());
818 FilmEditor::setup_content ()
820 string selected_summary;
821 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
823 selected_summary = wx_to_std (_content->GetItemText (s));
826 _content->DeleteAllItems ();
828 ContentList content = _film->content ();
829 for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
830 int const t = _content->GetItemCount ();
831 _content->InsertItem (t, std_to_wx ((*i)->summary ()));
832 if ((*i)->summary() == selected_summary) {
833 _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
837 if (selected_summary.empty () && !content.empty ()) {
838 /* Select the item of content if none was selected before */
839 _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
844 FilmEditor::content_add_clicked (wxCommandEvent &)
846 wxFileDialog* d = new wxFileDialog (this, _("Choose a file or files"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
847 int const r = d->ShowModal ();
857 for (unsigned int i = 0; i < paths.GetCount(); ++i) {
858 boost::filesystem::path p (wx_to_std (paths[i]));
860 shared_ptr<Content> c;
862 if (StillImageContent::valid_file (p)) {
863 c.reset (new StillImageContent (_film, p));
864 } else if (SndfileContent::valid_file (p)) {
865 c.reset (new SndfileContent (_film, p));
867 c.reset (new FFmpegContent (_film, p));
870 _film->examine_and_add_content (c);
875 FilmEditor::content_remove_clicked (wxCommandEvent &)
877 shared_ptr<Content> c = selected_content ();
879 _film->remove_content (c);
883 content_selection_changed (ev);
887 FilmEditor::content_selection_changed (wxListEvent &)
889 setup_content_sensitivity ();
890 shared_ptr<Content> s = selected_content ();
892 _audio_panel->content_selection_changed ();
894 film_content_changed (s, ContentProperty::START);
895 film_content_changed (s, ContentProperty::LENGTH);
896 film_content_changed (s, VideoContentProperty::VIDEO_CROP);
897 film_content_changed (s, VideoContentProperty::VIDEO_RATIO);
898 film_content_changed (s, AudioContentProperty::AUDIO_GAIN);
899 film_content_changed (s, AudioContentProperty::AUDIO_DELAY);
900 film_content_changed (s, AudioContentProperty::AUDIO_MAPPING);
901 film_content_changed (s, FFmpegContentProperty::AUDIO_STREAM);
902 film_content_changed (s, FFmpegContentProperty::AUDIO_STREAMS);
903 film_content_changed (s, FFmpegContentProperty::SUBTITLE_STREAM);
904 film_content_changed (s, FFmpegContentProperty::SUBTITLE_STREAMS);
905 film_content_changed (s, FFmpegContentProperty::FILTERS);
906 film_content_changed (s, SubtitleContentProperty::SUBTITLE_OFFSET);
907 film_content_changed (s, SubtitleContentProperty::SUBTITLE_SCALE);
911 FilmEditor::setup_content_sensitivity ()
913 _content_add->Enable (_generally_sensitive);
915 shared_ptr<Content> selection = selected_content ();
917 _content_remove->Enable (selection && _generally_sensitive);
918 _content_timeline->Enable (_generally_sensitive);
920 _video_panel->Enable (selection && dynamic_pointer_cast<VideoContent> (selection) && _generally_sensitive);
921 _audio_panel->Enable (selection && dynamic_pointer_cast<AudioContent> (selection) && _generally_sensitive);
922 _subtitle_panel->Enable (selection && dynamic_pointer_cast<FFmpegContent> (selection) && _generally_sensitive);
923 _timing_panel->Enable (selection && _generally_sensitive);
927 FilmEditor::selected_content ()
929 int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
931 return shared_ptr<Content> ();
934 ContentList c = _film->content ();
935 if (s < 0 || size_t (s) >= c.size ()) {
936 return shared_ptr<Content> ();
942 shared_ptr<VideoContent>
943 FilmEditor::selected_video_content ()
945 shared_ptr<Content> c = selected_content ();
947 return shared_ptr<VideoContent> ();
950 return dynamic_pointer_cast<VideoContent> (c);
953 shared_ptr<AudioContent>
954 FilmEditor::selected_audio_content ()
956 shared_ptr<Content> c = selected_content ();
958 return shared_ptr<AudioContent> ();
961 return dynamic_pointer_cast<AudioContent> (c);
964 shared_ptr<SubtitleContent>
965 FilmEditor::selected_subtitle_content ()
967 shared_ptr<Content> c = selected_content ();
969 return shared_ptr<SubtitleContent> ();
972 return dynamic_pointer_cast<SubtitleContent> (c);
976 FilmEditor::setup_scaling_description ()
978 shared_ptr<VideoContent> vc = selected_video_content ();
980 _scaling_description->SetLabel ("");
988 if (vc->video_size().width && vc->video_size().height) {
989 d << wxString::Format (
990 _("Original video is %dx%d (%.2f:1)\n"),
991 vc->video_size().width, vc->video_size().height,
992 float (vc->video_size().width) / vc->video_size().height
997 Crop const crop = vc->crop ();
998 if ((crop.left || crop.right || crop.top || crop.bottom) && vc->video_size() != libdcp::Size (0, 0)) {
999 libdcp::Size cropped = vc->video_size ();
1000 cropped.width -= crop.left + crop.right;
1001 cropped.height -= crop.top + crop.bottom;
1002 d << wxString::Format (
1003 _("Cropped to %dx%d (%.2f:1)\n"),
1004 cropped.width, cropped.height,
1005 float (cropped.width) / cropped.height
1010 Ratio const * ratio = vc->ratio ();
1012 libdcp::Size container_size = _film->container()->size (_film->full_frame ());
1014 libdcp::Size const scaled = ratio->size (container_size);
1015 d << wxString::Format (
1016 _("Scaled to %dx%d (%.2f:1)\n"),
1017 scaled.width, scaled.height,
1018 float (scaled.width) / scaled.height
1022 if (scaled != container_size) {
1023 d << wxString::Format (
1024 _("Padded with black to %dx%d (%.2f:1)\n"),
1025 container_size.width, container_size.height,
1026 float (container_size.width) / container_size.height
1032 for (int i = lines; i < 4; ++i) {
1036 _scaling_description->SetLabel (d);
1040 FilmEditor::content_timeline_clicked (wxCommandEvent &)
1042 if (_timeline_dialog) {
1043 _timeline_dialog->Destroy ();
1044 _timeline_dialog = 0;
1047 _timeline_dialog = new TimelineDialog (this, _film);
1048 _timeline_dialog->Show ();
1052 FilmEditor::set_selection (weak_ptr<Content> wc)
1054 ContentList content = _film->content ();
1055 for (size_t i = 0; i < content.size(); ++i) {
1056 if (content[i] == wc.lock ()) {
1057 _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
1059 _content->SetItemState (i, 0, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1065 FilmEditor::ratio_changed (wxCommandEvent &)
1071 shared_ptr<Content> c = selected_content ();
1076 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
1081 int const n = _ratio->GetSelection ();
1083 vector<Ratio const *> ratios = Ratio::all ();
1084 assert (n < int (ratios.size()));
1085 vc->set_ratio (ratios[n]);
1090 FilmEditor::sequence_video_changed (wxCommandEvent &)
1092 _film->set_sequence_video (_sequence_video->GetValue ());
1096 FilmEditor::content_right_click (wxListEvent& ev)
1099 cl.push_back (selected_content ());
1100 _menu.popup (cl, ev.GetPoint ());