Fix a few more things.
[dcpomatic.git] / src / wx / film_editor.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file src/film_editor.cc
21  *  @brief A wx widget to edit a film's metadata, and perform various functions.
22  */
23
24 #include <iostream>
25 #include <iomanip>
26 #include <wx/wx.h>
27 #include <wx/notebook.h>
28 #include <wx/listctrl.h>
29 #include <boost/thread.hpp>
30 #include <boost/filesystem.hpp>
31 #include <boost/lexical_cast.hpp>
32 #include "lib/format.h"
33 #include "lib/film.h"
34 #include "lib/transcode_job.h"
35 #include "lib/exceptions.h"
36 #include "lib/ab_transcode_job.h"
37 #include "lib/job_manager.h"
38 #include "lib/filter.h"
39 #include "lib/config.h"
40 #include "lib/ffmpeg_decoder.h"
41 #include "lib/imagemagick_content.h"
42 #include "lib/sndfile_content.h"
43 #include "filter_dialog.h"
44 #include "wx_util.h"
45 #include "film_editor.h"
46 #include "gain_calculator_dialog.h"
47 #include "sound_processor.h"
48 #include "dci_metadata_dialog.h"
49 #include "scaler.h"
50 #include "audio_dialog.h"
51
52 using std::string;
53 using std::cout;
54 using std::stringstream;
55 using std::pair;
56 using std::fixed;
57 using std::setprecision;
58 using std::list;
59 using std::vector;
60 using boost::shared_ptr;
61 using boost::dynamic_pointer_cast;
62
63 /** @param f Film to edit */
64 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
65         : wxPanel (parent)
66         , _film (f)
67         , _generally_sensitive (true)
68         , _audio_dialog (0)
69 {
70         wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
71         _notebook = new wxNotebook (this, wxID_ANY);
72         s->Add (_notebook, 1);
73
74         make_film_panel ();
75         _notebook->AddPage (_film_panel, _("Film"), true);
76         make_content_panel ();
77         _notebook->AddPage (_content_panel, _("Content"), false);
78         make_video_panel ();
79         _notebook->AddPage (_video_panel, _("Video"), false);
80         make_audio_panel ();
81         _notebook->AddPage (_audio_panel, _("Audio"), false);
82         make_subtitle_panel ();
83         _notebook->AddPage (_subtitle_panel, _("Subtitles"), false);
84
85         set_film (_film);
86         connect_to_widgets ();
87
88         JobManager::instance()->ActiveJobsChanged.connect (
89                 bind (&FilmEditor::active_jobs_changed, this, _1)
90                 );
91         
92         setup_formats ();
93
94         SetSizerAndFit (s);
95 }
96
97 void
98 FilmEditor::make_film_panel ()
99 {
100         _film_panel = new wxPanel (_notebook);
101         _film_sizer = new wxBoxSizer (wxVERTICAL);
102         _film_panel->SetSizer (_film_sizer);
103
104         wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
105         _film_sizer->Add (grid, 0, wxALL, 8);
106
107         int r = 0;
108         
109         add_label_to_grid_bag_sizer (grid, _film_panel, _("Name"), wxGBPosition (r, 0));
110         _name = new wxTextCtrl (_film_panel, wxID_ANY);
111         grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
112         ++r;
113         
114         add_label_to_grid_bag_sizer (grid, _film_panel, _("DCP Name"), wxGBPosition (r, 0));
115         _dcp_name = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
116         grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
117         ++r;
118
119         _use_dci_name = new wxCheckBox (_film_panel, wxID_ANY, _("Use DCI name"));
120         grid->Add (_use_dci_name, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
121         _edit_dci_button = new wxButton (_film_panel, wxID_ANY, _("Details..."));
122         grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
123         ++r;
124
125         _trust_content_headers = new wxCheckBox (_film_panel, wxID_ANY, _("Trust content's header"));
126         grid->Add (_trust_content_headers, wxGBPosition (r, 0), wxGBSpan(1, 2));
127         ++r;
128
129         add_label_to_grid_bag_sizer (grid, _film_panel, _("Content Type"), wxGBPosition (r, 0));
130         _dcp_content_type = new wxChoice (_film_panel, wxID_ANY);
131         grid->Add (_dcp_content_type, wxGBPosition (r, 1));
132         ++r;
133
134         {
135                 add_label_to_grid_bag_sizer (grid, _film_panel, _("DCP Frame Rate"), wxGBPosition (r, 0));
136                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
137                 _dcp_frame_rate = new wxChoice (_film_panel, wxID_ANY);
138                 s->Add (_dcp_frame_rate, 1, wxALIGN_CENTER_VERTICAL);
139                 _best_dcp_frame_rate = new wxButton (_film_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));
142         }
143         ++r;
144
145         _frame_rate_description = new wxStaticText (_film_panel, wxID_ANY, wxT (" \n "), wxDefaultPosition, wxDefaultSize);
146         grid->Add (_frame_rate_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
147         wxFont font = _frame_rate_description->GetFont();
148         font.SetStyle(wxFONTSTYLE_ITALIC);
149         font.SetPointSize(font.GetPointSize() - 1);
150         _frame_rate_description->SetFont(font);
151         ++r;
152         
153         add_label_to_grid_bag_sizer (grid, _film_panel, _("Original Size"), wxGBPosition (r, 0));
154         _original_size = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
155         grid->Add (_original_size, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
156         ++r;
157         
158         add_label_to_grid_bag_sizer (grid, _film_panel, _("Length"), wxGBPosition (r, 0));
159         _length = new wxStaticText (_film_panel, wxID_ANY, wxT (""));
160         grid->Add (_length, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
161         ++r;
162
163
164         {
165                 add_label_to_grid_bag_sizer (grid, _film_panel, _("Trim frames"), wxGBPosition (r, 0));
166                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
167                 add_label_to_sizer (s, _film_panel, _("Start"));
168                 _trim_start = new wxSpinCtrl (_film_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
169                 s->Add (_trim_start);
170                 add_label_to_sizer (s, _film_panel, _("End"));
171                 _trim_end = new wxSpinCtrl (_film_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
172                 s->Add (_trim_end);
173
174                 grid->Add (s, wxGBPosition (r, 1));
175         }
176         ++r;
177
178         _ab = new wxCheckBox (_film_panel, wxID_ANY, _("A/B"));
179         grid->Add (_ab, wxGBPosition (r, 0));
180         ++r;
181
182         vector<DCPContentType const *> const ct = DCPContentType::all ();
183         for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
184                 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
185         }
186
187         list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
188         for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
189                 _dcp_frame_rate->Append (std_to_wx (boost::lexical_cast<string> (*i)));
190         }
191 }
192
193 void
194 FilmEditor::connect_to_widgets ()
195 {
196         _name->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (FilmEditor::name_changed), 0, this);
197         _use_dci_name->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::use_dci_name_toggled), 0, this);
198         _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
199         _format->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this);
200         _trust_content_headers->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::trust_content_headers_changed), 0, this);
201         _content->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (FilmEditor::content_item_selected), 0, this);
202         _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
203         _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
204         _content_earlier->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_earlier_clicked), 0, this);
205         _content_later->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_later_clicked), 0, this);
206         _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
207         _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
208         _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
209         _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
210         _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
211         _scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
212         _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
213         _dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
214         _best_dcp_frame_rate->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
215         _ab->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::ab_toggled), 0, this);
216         _trim_start->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::trim_start_changed), 0, this);
217         _trim_end->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::trim_end_changed), 0, this);
218         _with_subtitles->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
219         _subtitle_offset->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_offset_changed), 0, this);
220         _subtitle_scale->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this);
221         _colour_lut->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::colour_lut_changed), 0, this);
222         _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::j2k_bandwidth_changed), 0, this);
223 //      _ffmpeg_subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ffmpeg_subtitle_stream_changed), 0, this);
224 //      _ffmpeg_audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::ffmpeg_audio_stream_changed), 0, this);
225         _audio_gain->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_gain_changed), 0, this);
226         _audio_gain_calculate_button->Connect (
227                 wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::audio_gain_calculate_button_clicked), 0, this
228                 );
229         _show_audio->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::show_audio_clicked), 0, this);
230         _audio_delay->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
231 }
232
233 void
234 FilmEditor::make_video_panel ()
235 {
236         _video_panel = new wxPanel (_notebook);
237         _video_sizer = new wxBoxSizer (wxVERTICAL);
238         _video_panel->SetSizer (_video_sizer);
239         
240         wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
241         _video_sizer->Add (grid, 0, wxALL, 8);
242
243         int r = 0;
244         add_label_to_grid_bag_sizer (grid, _video_panel, _("Format"), wxGBPosition (r, 0));
245         _format = new wxChoice (_video_panel, wxID_ANY);
246         grid->Add (_format, wxGBPosition (r, 1));
247         ++r;
248
249         _format_description = new wxStaticText (_video_panel, wxID_ANY, wxT (""), wxDefaultPosition, wxDefaultSize);
250         grid->Add (_format_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
251         wxFont font = _format_description->GetFont();
252         font.SetStyle(wxFONTSTYLE_ITALIC);
253         font.SetPointSize(font.GetPointSize() - 1);
254         _format_description->SetFont(font);
255         ++r;
256
257         add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0));
258         _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
259         grid->Add (_left_crop, wxGBPosition (r, 1));
260         ++r;
261
262         add_label_to_grid_bag_sizer (grid, _video_panel, _("Right crop"), wxGBPosition (r, 0));
263         _right_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
264         grid->Add (_right_crop, wxGBPosition (r, 1));
265         ++r;
266         
267         add_label_to_grid_bag_sizer (grid, _video_panel, _("Top crop"), wxGBPosition (r, 0));
268         _top_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
269         grid->Add (_top_crop, wxGBPosition (r, 1));
270         ++r;
271         
272         add_label_to_grid_bag_sizer (grid, _video_panel, _("Bottom crop"), wxGBPosition (r, 0));
273         _bottom_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
274         grid->Add (_bottom_crop, wxGBPosition (r, 1));
275         ++r;
276
277         /* VIDEO-only stuff */
278         {
279                 add_label_to_grid_bag_sizer (grid, _video_panel, _("Filters"), wxGBPosition (r, 0));
280                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
281                 _filters = new wxStaticText (_video_panel, wxID_ANY, _("None"));
282                 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
283                 _filters_button = new wxButton (_video_panel, wxID_ANY, _("Edit..."));
284                 s->Add (_filters_button, 0);
285                 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
286         }
287         ++r;
288
289         add_label_to_grid_bag_sizer (grid, _video_panel, _("Scaler"), wxGBPosition (r, 0));
290         _scaler = new wxChoice (_video_panel, wxID_ANY);
291         grid->Add (_scaler, wxGBPosition (r, 1));
292         ++r;
293
294         vector<Scaler const *> const sc = Scaler::all ();
295         for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
296                 _scaler->Append (std_to_wx ((*i)->name()));
297         }
298
299         add_label_to_grid_bag_sizer (grid, _video_panel, _("Colour look-up table"), wxGBPosition (r, 0));
300         _colour_lut = new wxChoice (_video_panel, wxID_ANY);
301         for (int i = 0; i < 2; ++i) {
302                 _colour_lut->Append (std_to_wx (colour_lut_index_to_name (i)));
303         }
304         _colour_lut->SetSelection (0);
305         grid->Add (_colour_lut, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
306         ++r;
307
308         {
309                 add_label_to_grid_bag_sizer (grid, _video_panel, _("JPEG2000 bandwidth"), wxGBPosition (r, 0));
310                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
311                 _j2k_bandwidth = new wxSpinCtrl (_video_panel, wxID_ANY);
312                 s->Add (_j2k_bandwidth, 1);
313                 add_label_to_sizer (s, _video_panel, _("MBps"));
314                 grid->Add (s, wxGBPosition (r, 1));
315         }
316         ++r;
317
318         _left_crop->SetRange (0, 1024);
319         _top_crop->SetRange (0, 1024);
320         _right_crop->SetRange (0, 1024);
321         _bottom_crop->SetRange (0, 1024);
322         _trim_start->SetRange (0, 100);
323         _trim_end->SetRange (0, 100);
324         _j2k_bandwidth->SetRange (50, 250);
325 }
326
327 void
328 FilmEditor::make_content_panel ()
329 {
330         _content_panel = new wxPanel (_notebook);
331         _content_sizer = new wxBoxSizer (wxVERTICAL);
332         _content_panel->SetSizer (_content_sizer);
333         
334         wxGridBagSizer* grid = new wxGridBagSizer (4, 4);
335         _content_sizer->Add (grid, 0, wxALL, 8);
336
337         int r = 0;
338
339         {
340                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
341                 
342                 _content = new wxListCtrl (_content_panel, wxID_ANY, wxDefaultPosition, wxSize (320, 160), wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
343                 s->Add (_content, 1, wxEXPAND | wxTOP | wxBOTTOM, 6);
344
345                 _content->InsertColumn (0, "");
346                 _content->SetColumnWidth (0, 512);
347
348                 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
349                 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
350                 b->Add (_content_add);
351                 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
352                 b->Add (_content_remove);
353                 _content_earlier = new wxButton (_content_panel, wxID_ANY, _("Earlier"));
354                 b->Add (_content_earlier);
355                 _content_later = new wxButton (_content_panel, wxID_ANY, _("Later"));
356                 b->Add (_content_later);
357
358                 s->Add (b, 0, wxALL, 4);
359
360                 grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND);
361                 ++r;
362         }
363 }
364
365 void
366 FilmEditor::make_audio_panel ()
367 {
368         _audio_panel = new wxPanel (_notebook);
369         _audio_sizer = new wxBoxSizer (wxVERTICAL);
370         _audio_panel->SetSizer (_audio_sizer);
371         
372         wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
373         _audio_sizer->Add (grid, 0, wxALL, 8);
374
375         _show_audio = new wxButton (_audio_panel, wxID_ANY, _("Show Audio..."));
376         grid->Add (_show_audio, 1);
377         grid->AddSpacer (0);
378
379         {
380                 add_label_to_sizer (grid, _audio_panel, _("Audio Gain"));
381                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
382                 _audio_gain = new wxSpinCtrl (_audio_panel);
383                 s->Add (_audio_gain, 1);
384                 add_label_to_sizer (s, _audio_panel, _("dB"));
385                 _audio_gain_calculate_button = new wxButton (_audio_panel, wxID_ANY, _("Calculate..."));
386                 s->Add (_audio_gain_calculate_button, 1, wxEXPAND);
387                 grid->Add (s);
388         }
389
390         {
391                 add_label_to_sizer (grid, _audio_panel, _("Audio Delay"));
392                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
393                 _audio_delay = new wxSpinCtrl (_audio_panel);
394                 s->Add (_audio_delay, 1);
395                 /// TRANSLATORS: this is an abbreviation for milliseconds, the unit of time
396                 add_label_to_sizer (s, _audio_panel, _("ms"));
397                 grid->Add (s);
398         }
399
400         _audio_gain->SetRange (-60, 60);
401         _audio_delay->SetRange (-1000, 1000);
402 }
403
404 void
405 FilmEditor::make_subtitle_panel ()
406 {
407         _subtitle_panel = new wxPanel (_notebook);
408         _subtitle_sizer = new wxBoxSizer (wxVERTICAL);
409         _subtitle_panel->SetSizer (_subtitle_sizer);
410         wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
411         _subtitle_sizer->Add (grid, 0, wxALL, 8);
412
413         _with_subtitles = new wxCheckBox (_subtitle_panel, wxID_ANY, _("With Subtitles"));
414         grid->Add (_with_subtitles, 1);
415         
416         _ffmpeg_subtitle_stream = new wxChoice (_subtitle_panel, wxID_ANY);
417         grid->Add (_ffmpeg_subtitle_stream);
418
419         add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Offset"));
420         _subtitle_offset = new wxSpinCtrl (_subtitle_panel);
421         grid->Add (_subtitle_offset, 1);
422
423         {
424                 add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Scale"));
425                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
426                 _subtitle_scale = new wxSpinCtrl (_subtitle_panel);
427                 s->Add (_subtitle_scale);
428                 add_label_to_sizer (s, _subtitle_panel, _("%"));
429                 grid->Add (s);
430         }
431
432         _subtitle_offset->SetRange (-1024, 1024);
433         _subtitle_scale->SetRange (1, 1000);
434 }
435
436 /** Called when the left crop widget has been changed */
437 void
438 FilmEditor::left_crop_changed (wxCommandEvent &)
439 {
440         if (!_film) {
441                 return;
442         }
443
444         _film->set_left_crop (_left_crop->GetValue ());
445 }
446
447 /** Called when the right crop widget has been changed */
448 void
449 FilmEditor::right_crop_changed (wxCommandEvent &)
450 {
451         if (!_film) {
452                 return;
453         }
454
455         _film->set_right_crop (_right_crop->GetValue ());
456 }
457
458 /** Called when the top crop widget has been changed */
459 void
460 FilmEditor::top_crop_changed (wxCommandEvent &)
461 {
462         if (!_film) {
463                 return;
464         }
465
466         _film->set_top_crop (_top_crop->GetValue ());
467 }
468
469 /** Called when the bottom crop value has been changed */
470 void
471 FilmEditor::bottom_crop_changed (wxCommandEvent &)
472 {
473         if (!_film) {
474                 return;
475         }
476
477         _film->set_bottom_crop (_bottom_crop->GetValue ());
478 }
479
480 void
481 FilmEditor::trust_content_headers_changed (wxCommandEvent &)
482 {
483         if (!_film) {
484                 return;
485         }
486
487         _film->set_trust_content_headers (_trust_content_headers->GetValue ());
488 }
489
490 /** Called when the DCP A/B switch has been toggled */
491 void
492 FilmEditor::ab_toggled (wxCommandEvent &)
493 {
494         if (!_film) {
495                 return;
496         }
497         
498         _film->set_ab (_ab->GetValue ());
499 }
500
501 /** Called when the name widget has been changed */
502 void
503 FilmEditor::name_changed (wxCommandEvent &)
504 {
505         if (!_film) {
506                 return;
507         }
508
509         _film->set_name (string (_name->GetValue().mb_str()));
510 }
511
512 void
513 FilmEditor::subtitle_offset_changed (wxCommandEvent &)
514 {
515         if (!_film) {
516                 return;
517         }
518
519         _film->set_subtitle_offset (_subtitle_offset->GetValue ());
520 }
521
522 void
523 FilmEditor::subtitle_scale_changed (wxCommandEvent &)
524 {
525         if (!_film) {
526                 return;
527         }
528
529         _film->set_subtitle_scale (_subtitle_scale->GetValue() / 100.0);
530 }
531
532 void
533 FilmEditor::colour_lut_changed (wxCommandEvent &)
534 {
535         if (!_film) {
536                 return;
537         }
538         
539         _film->set_colour_lut (_colour_lut->GetSelection ());
540 }
541
542 void
543 FilmEditor::j2k_bandwidth_changed (wxCommandEvent &)
544 {
545         if (!_film) {
546                 return;
547         }
548         
549         _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
550 }
551
552 void
553 FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
554 {
555         if (!_film) {
556                 return;
557         }
558
559         _film->set_dcp_frame_rate (
560                 boost::lexical_cast<int> (
561                         wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
562                         )
563                 );
564 }
565
566
567 /** Called when the metadata stored in the Film object has changed;
568  *  so that we can update the GUI.
569  *  @param p Property of the Film that has changed.
570  */
571 void
572 FilmEditor::film_changed (Film::Property p)
573 {
574         ensure_ui_thread ();
575         
576         if (!_film) {
577                 return;
578         }
579
580         stringstream s;
581                 
582         switch (p) {
583         case Film::NONE:
584                 break;
585         case Film::CONTENT:
586                 setup_content ();
587                 setup_formats ();
588                 setup_subtitle_control_sensitivity ();
589                 setup_streams ();
590                 setup_show_audio_sensitivity ();
591                 break;
592         case Film::TRUST_CONTENT_HEADERS:
593                 checked_set (_trust_content_headers, _film->trust_content_headers ());
594                 break;
595         case Film::FORMAT:
596         {
597                 int n = 0;
598                 vector<Format const *>::iterator i = _formats.begin ();
599                 while (i != _formats.end() && *i != _film->format ()) {
600                         ++i;
601                         ++n;
602                 }
603                 if (i == _formats.end()) {
604                         checked_set (_format, -1);
605                 } else {
606                         checked_set (_format, n);
607                 }
608                 setup_dcp_name ();
609
610                 if (_film->format ()) {
611                         _format_description->SetLabel (std_to_wx (_film->format()->description ()));
612                 } else {
613                         _format_description->SetLabel (wxT (""));
614                 }
615                 break;
616         }
617         case Film::CROP:
618                 checked_set (_left_crop, _film->crop().left);
619                 checked_set (_right_crop, _film->crop().right);
620                 checked_set (_top_crop, _film->crop().top);
621                 checked_set (_bottom_crop, _film->crop().bottom);
622                 break;
623         case Film::FILTERS:
624         {
625                 pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
626                 if (p.first.empty () && p.second.empty ()) {
627                         _filters->SetLabel (_("None"));
628                 } else {
629                         string const b = p.first + " " + p.second;
630                         _filters->SetLabel (std_to_wx (b));
631                 }
632                 _film_sizer->Layout ();
633                 break;
634         }
635         case Film::NAME:
636                 checked_set (_name, _film->name());
637                 setup_dcp_name ();
638                 break;
639 //      case Film::SOURCE_FRAME_RATE:
640 //              s << fixed << setprecision(2) << _film->source_frame_rate();
641 //              _source_frame_rate->SetLabel (std_to_wx (s.str ()));
642 //              break;
643 //      case Film::VIDEO_SIZE:
644 //              if (_film->size().width == 0 && _film->size().height == 0) {
645 //                      _original_size->SetLabel (wxT (""));
646 //              } else {
647 //                      s << _film->size().width << " x " << _film->size().height;
648 //                      _original_size->SetLabel (std_to_wx (s.str ()));
649 //              }
650 //              break;
651         case Film::DCP_CONTENT_TYPE:
652                 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
653                 setup_dcp_name ();
654                 break;
655         case Film::AB:
656                 checked_set (_ab, _film->ab ());
657                 break;
658         case Film::SCALER:
659                 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
660                 break;
661         case Film::TRIM_START:
662                 checked_set (_trim_start, _film->trim_start());
663                 break;
664         case Film::TRIM_END:
665                 checked_set (_trim_end, _film->trim_end());
666                 break;
667         case Film::AUDIO_GAIN:
668                 checked_set (_audio_gain, _film->audio_gain ());
669                 break;
670         case Film::AUDIO_DELAY:
671                 checked_set (_audio_delay, _film->audio_delay ());
672                 break;
673         case Film::WITH_SUBTITLES:
674                 checked_set (_with_subtitles, _film->with_subtitles ());
675                 setup_subtitle_control_sensitivity ();
676                 setup_dcp_name ();
677                 break;
678         case Film::SUBTITLE_OFFSET:
679                 checked_set (_subtitle_offset, _film->subtitle_offset ());
680                 break;
681         case Film::SUBTITLE_SCALE:
682                 checked_set (_subtitle_scale, _film->subtitle_scale() * 100);
683                 break;
684         case Film::COLOUR_LUT:
685                 checked_set (_colour_lut, _film->colour_lut ());
686                 break;
687         case Film::J2K_BANDWIDTH:
688                 checked_set (_j2k_bandwidth, double (_film->j2k_bandwidth()) / 1e6);
689                 break;
690         case Film::USE_DCI_NAME:
691                 checked_set (_use_dci_name, _film->use_dci_name ());
692                 setup_dcp_name ();
693                 break;
694         case Film::DCI_METADATA:
695                 setup_dcp_name ();
696                 break;
697 //      case Film::CONTENT_AUDIO_STREAM:
698 //              if (_film->content_audio_stream()) {
699 //                      checked_set (_audio_stream, _film->content_audio_stream()->to_string());
700 //              }
701 //              setup_dcp_name ();
702 //              setup_audio_details ();
703 //              setup_show_audio_sensitivity ();
704 //              break;
705 //      case Film::SUBTITLE_STREAM:
706 //              if (_film->subtitle_stream()) {
707 //                      checked_set (_subtitle_stream, _film->subtitle_stream()->to_string());
708 //              }
709 //              break;
710         case Film::DCP_FRAME_RATE:
711                 for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
712                         if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_frame_rate())) {
713                                 if (_dcp_frame_rate->GetSelection() != int(i)) {
714                                         _dcp_frame_rate->SetSelection (i);
715                                         break;
716                                 }
717                         }
718                 }
719
720                 if (_film->video_frame_rate()) {
721                         _frame_rate_description->SetLabel (std_to_wx (FrameRateConversion (_film->video_frame_rate(), _film->dcp_frame_rate()).description));
722                         _best_dcp_frame_rate->Enable (best_dcp_frame_rate (_film->video_frame_rate ()) != _film->dcp_frame_rate ());
723                 } else {
724                         _frame_rate_description->SetLabel (wxT (""));
725                         _best_dcp_frame_rate->Disable ();
726                 }
727         }
728 }
729
730 void
731 FilmEditor::film_content_changed (int p)
732 {
733         if (p == FFmpegContentProperty::SUBTITLE_STREAMS) {
734                 setup_subtitle_control_sensitivity ();
735                 setup_streams ();
736         } else if (p == FFmpegContentProperty::AUDIO_STREAMS) {
737                 setup_streams ();
738                 setup_show_audio_sensitivity ();
739         } else if (p == VideoContentProperty::VIDEO_LENGTH) {
740                 stringstream s;
741                 if (_film->video_frame_rate() > 0 && _film->video_length()) {
742                         s << _film->video_length() << " "
743                           << wx_to_std (_("frames")) << "; " << seconds_to_hms (_film->video_length() / _film->video_frame_rate());
744                 } else if (_film->video_length()) {
745                         s << _film->video_length() << " "
746                           << wx_to_std (_("frames"));
747                 } 
748                 _length->SetLabel (std_to_wx (s.str ()));
749                 if (_film->video_length()) {
750                         _trim_start->SetRange (0, _film->video_length());
751                         _trim_end->SetRange (0, _film->video_length());
752                 }
753         }
754 }
755
756
757 /** Called when the format widget has been changed */
758 void
759 FilmEditor::format_changed (wxCommandEvent &)
760 {
761         if (!_film) {
762                 return;
763         }
764
765         int const n = _format->GetSelection ();
766         if (n >= 0) {
767                 assert (n < int (_formats.size()));
768                 _film->set_format (_formats[n]);
769         }
770 }
771
772 /** Called when the DCP content type widget has been changed */
773 void
774 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
775 {
776         if (!_film) {
777                 return;
778         }
779
780         int const n = _dcp_content_type->GetSelection ();
781         if (n != wxNOT_FOUND) {
782                 _film->set_dcp_content_type (DCPContentType::from_index (n));
783         }
784 }
785
786 /** Sets the Film that we are editing */
787 void
788 FilmEditor::set_film (shared_ptr<Film> f)
789 {
790         _film = f;
791
792         set_things_sensitive (_film != 0);
793
794         if (_film) {
795                 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
796                 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _1));
797         }
798
799         if (_film) {
800                 FileChanged (_film->directory ());
801         } else {
802                 FileChanged ("");
803         }
804
805         if (_audio_dialog) {
806                 _audio_dialog->set_film (_film);
807         }
808         
809         film_changed (Film::NAME);
810         film_changed (Film::USE_DCI_NAME);
811         film_changed (Film::CONTENT);
812         film_changed (Film::TRUST_CONTENT_HEADERS);
813         film_changed (Film::DCP_CONTENT_TYPE);
814         film_changed (Film::FORMAT);
815         film_changed (Film::CROP);
816         film_changed (Film::FILTERS);
817         film_changed (Film::SCALER);
818         film_changed (Film::TRIM_START);
819         film_changed (Film::TRIM_END);
820         film_changed (Film::AB);
821         film_changed (Film::AUDIO_GAIN);
822         film_changed (Film::AUDIO_DELAY);
823         film_changed (Film::WITH_SUBTITLES);
824         film_changed (Film::SUBTITLE_OFFSET);
825         film_changed (Film::SUBTITLE_SCALE);
826         film_changed (Film::COLOUR_LUT);
827         film_changed (Film::J2K_BANDWIDTH);
828         film_changed (Film::DCI_METADATA);
829         film_changed (Film::DCP_FRAME_RATE);
830 }
831
832 /** Updates the sensitivity of lots of widgets to a given value.
833  *  @param s true to make sensitive, false to make insensitive.
834  */
835 void
836 FilmEditor::set_things_sensitive (bool s)
837 {
838         _generally_sensitive = s;
839         
840         _name->Enable (s);
841         _use_dci_name->Enable (s);
842         _edit_dci_button->Enable (s);
843         _format->Enable (s);
844         _content->Enable (s);
845         _trust_content_headers->Enable (s);
846         _content->Enable (s);
847         _left_crop->Enable (s);
848         _right_crop->Enable (s);
849         _top_crop->Enable (s);
850         _bottom_crop->Enable (s);
851         _filters_button->Enable (s);
852         _scaler->Enable (s);
853 //      _ffmpeg_audio_stream->Enable (s);
854         _dcp_content_type->Enable (s);
855         _dcp_frame_rate->Enable (s);
856         _trim_start->Enable (s);
857         _trim_end->Enable (s);
858         _ab->Enable (s);
859         _colour_lut->Enable (s);
860         _j2k_bandwidth->Enable (s);
861         _audio_gain->Enable (s);
862         _audio_gain_calculate_button->Enable (s);
863         _show_audio->Enable (s);
864         _audio_delay->Enable (s);
865
866         setup_subtitle_control_sensitivity ();
867         setup_show_audio_sensitivity ();
868         setup_content_button_sensitivity ();
869 }
870
871 /** Called when the `Edit filters' button has been clicked */
872 void
873 FilmEditor::edit_filters_clicked (wxCommandEvent &)
874 {
875         FilterDialog* d = new FilterDialog (this, _film->filters());
876         d->ActiveChanged.connect (bind (&Film::set_filters, _film, _1));
877         d->ShowModal ();
878         d->Destroy ();
879 }
880
881 /** Called when the scaler widget has been changed */
882 void
883 FilmEditor::scaler_changed (wxCommandEvent &)
884 {
885         if (!_film) {
886                 return;
887         }
888
889         int const n = _scaler->GetSelection ();
890         if (n >= 0) {
891                 _film->set_scaler (Scaler::from_index (n));
892         }
893 }
894
895 void
896 FilmEditor::audio_gain_changed (wxCommandEvent &)
897 {
898         if (!_film) {
899                 return;
900         }
901
902         _film->set_audio_gain (_audio_gain->GetValue ());
903 }
904
905 void
906 FilmEditor::audio_delay_changed (wxCommandEvent &)
907 {
908         if (!_film) {
909                 return;
910         }
911
912         _film->set_audio_delay (_audio_delay->GetValue ());
913 }
914
915 void
916 FilmEditor::trim_start_changed (wxCommandEvent &)
917 {
918         if (!_film) {
919                 return;
920         }
921
922         _film->set_trim_start (_trim_start->GetValue ());
923 }
924
925 void
926 FilmEditor::trim_end_changed (wxCommandEvent &)
927 {
928         if (!_film) {
929                 return;
930         }
931
932         _film->set_trim_end (_trim_end->GetValue ());
933 }
934
935 void
936 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
937 {
938         GainCalculatorDialog* d = new GainCalculatorDialog (this);
939         d->ShowModal ();
940
941         if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
942                 d->Destroy ();
943                 return;
944         }
945         
946         _audio_gain->SetValue (
947                 Config::instance()->sound_processor()->db_for_fader_change (
948                         d->wanted_fader (),
949                         d->actual_fader ()
950                         )
951                 );
952
953         /* This appears to be necessary, as the change is not signalled,
954            I think.
955         */
956         wxCommandEvent dummy;
957         audio_gain_changed (dummy);
958         
959         d->Destroy ();
960 }
961
962 void
963 FilmEditor::setup_formats ()
964 {
965         _formats = Format::all ();
966
967         _format->Clear ();
968         for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
969                 _format->Append (std_to_wx ((*i)->name ()));
970         }
971
972         _film_sizer->Layout ();
973 }
974
975 void
976 FilmEditor::with_subtitles_toggled (wxCommandEvent &)
977 {
978         if (!_film) {
979                 return;
980         }
981
982         _film->set_with_subtitles (_with_subtitles->GetValue ());
983 }
984
985 void
986 FilmEditor::setup_subtitle_control_sensitivity ()
987 {
988         bool h = false;
989         if (_generally_sensitive && _film) {
990 //              h = !_film->subtitle_streams().empty();
991         }
992         
993         _with_subtitles->Enable (h);
994
995         bool j = false;
996         if (_film) {
997                 j = _film->with_subtitles ();
998         }
999         
1000         _ffmpeg_subtitle_stream->Enable (j);
1001         _subtitle_offset->Enable (j);
1002         _subtitle_scale->Enable (j);
1003 }
1004
1005 void
1006 FilmEditor::use_dci_name_toggled (wxCommandEvent &)
1007 {
1008         if (!_film) {
1009                 return;
1010         }
1011
1012         _film->set_use_dci_name (_use_dci_name->GetValue ());
1013 }
1014
1015 void
1016 FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
1017 {
1018         if (!_film) {
1019                 return;
1020         }
1021
1022         DCIMetadataDialog* d = new DCIMetadataDialog (this, _film->dci_metadata ());
1023         d->ShowModal ();
1024         _film->set_dci_metadata (d->dci_metadata ());
1025         d->Destroy ();
1026 }
1027
1028 void
1029 FilmEditor::setup_streams ()
1030 {
1031 //      _ffmpeg_audio_stream->Clear ();
1032         vector<FFmpegAudioStream> a;// = _film->content_audio_streams ();
1033 //      for (vector<FFmpegAudioStream>::iterator i = a.begin(); i != a.end(); ++i) {
1034 //              _audio_stream->Append (std_to_wx (ffa->name()), new wxStringClientData (std_to_wx (i->to_string ())));
1035 //      }
1036         
1037 //      if (_film->use_content_audio() && _film->audio_stream()) {
1038 //              checked_set (_audio_stream, _film->audio_stream()->to_string());
1039 //      }
1040
1041         _ffmpeg_subtitle_stream->Clear ();
1042 //      vector<shared_ptr<SubtitleStream> > s = _film->subtitle_streams ();
1043 //      for (vector<shared_ptr<SubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
1044 //              _subtitle_stream->Append (std_to_wx ((*i)->name()), new wxStringClientData (std_to_wx ((*i)->to_string ())));
1045 //      }
1046 //      if (_film->subtitle_stream()) {
1047 //              checked_set (_subtitle_stream, _film->subtitle_stream()->to_string());
1048 //      } else {
1049 //              _subtitle_stream->SetSelection (wxNOT_FOUND);
1050 //      }
1051 }
1052
1053 void
1054 FilmEditor::ffmpeg_audio_stream_changed (wxCommandEvent &)
1055 {
1056         if (!_film) {
1057                 return;
1058         }
1059
1060 #if 0   
1061         _film->set_content_audio_stream (
1062                 audio_stream_factory (
1063                         string_client_data (_audio_stream->GetClientObject (_audio_stream->GetSelection ())),
1064                         Film::state_version
1065                         )
1066                 );
1067 #endif  
1068 }
1069
1070 void
1071 FilmEditor::ffmpeg_subtitle_stream_changed (wxCommandEvent &)
1072 {
1073         if (!_film) {
1074                 return;
1075         }
1076
1077 #if 0   
1078         _film->set_subtitle_stream (
1079                 subtitle_stream_factory (
1080                         string_client_data (_subtitle_stream->GetClientObject (_subtitle_stream->GetSelection ())),
1081                         Film::state_version
1082                         )
1083                 );
1084 #endif  
1085 }
1086
1087 void
1088 FilmEditor::setup_audio_details ()
1089 {
1090 #if 0   
1091         if (!_film->content_audio_stream()) {
1092                 _audio->SetLabel (wxT (""));
1093         } else {
1094                 stringstream s;
1095                 if (_film->audio_stream()->channels() == 1) {
1096                         s << wx_to_std (_("1 channel"));
1097                 } else {
1098                         s << _film->audio_stream()->channels () << " " << wx_to_std (_("channels"));
1099                 }
1100                 s << ", " << _film->audio_stream()->sample_rate() << wx_to_std (_("Hz"));
1101                 _audio->SetLabel (std_to_wx (s.str ()));
1102         }
1103 #endif  
1104 }
1105
1106 void
1107 FilmEditor::active_jobs_changed (bool a)
1108 {
1109         set_things_sensitive (!a);
1110 }
1111
1112 void
1113 FilmEditor::setup_dcp_name ()
1114 {
1115         string s = _film->dcp_name (true);
1116         if (s.length() > 28) {
1117                 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
1118                 _dcp_name->SetToolTip (std_to_wx (s));
1119         } else {
1120                 _dcp_name->SetLabel (std_to_wx (s));
1121         }
1122 }
1123
1124 void
1125 FilmEditor::show_audio_clicked (wxCommandEvent &)
1126 {
1127         if (_audio_dialog) {
1128                 _audio_dialog->Destroy ();
1129                 _audio_dialog = 0;
1130         }
1131         
1132         _audio_dialog = new AudioDialog (this);
1133         _audio_dialog->Show ();
1134         _audio_dialog->set_film (_film);
1135 }
1136
1137 void
1138 FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
1139 {
1140         if (!_film) {
1141                 return;
1142         }
1143         
1144         _film->set_dcp_frame_rate (best_dcp_frame_rate (_film->video_frame_rate ()));
1145 }
1146
1147 void
1148 FilmEditor::setup_show_audio_sensitivity ()
1149 {
1150         _show_audio->Enable (_film && _film->has_audio ());
1151 }
1152
1153 void
1154 FilmEditor::setup_content ()
1155 {
1156         _content->DeleteAllItems ();
1157
1158         ContentList content = _film->content ();
1159         for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
1160                 _content->InsertItem (_content->GetItemCount(), std_to_wx ((*i)->summary ()));
1161         }
1162 }
1163
1164 void
1165 FilmEditor::content_add_clicked (wxCommandEvent &)
1166 {
1167         wxFileDialog* d = new wxFileDialog (this);
1168         int const r = d->ShowModal ();
1169         d->Destroy ();
1170
1171         if (r != wxID_OK) {
1172                 return;
1173         }
1174
1175         boost::filesystem::path p (wx_to_std (d->GetPath()));
1176
1177         if (ImageMagickContent::valid_file (p)) {
1178                 _film->add_content (shared_ptr<ImageMagickContent> (new ImageMagickContent (p)));
1179         } else if (SndfileContent::valid_file (p)) {
1180                 _film->add_content (shared_ptr<SndfileContent> (new SndfileContent (p)));
1181         } else {
1182                 _film->add_content (shared_ptr<FFmpegContent> (new FFmpegContent (p)));
1183         }
1184         
1185 }
1186
1187 void
1188 FilmEditor::content_remove_clicked (wxCommandEvent &)
1189 {
1190         int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1191         if (s == -1) {
1192                 return;
1193         }
1194
1195         ContentList c = _film->content ();
1196         assert (s >= 0 && size_t (s) < c.size ());
1197         _film->remove_content (c[s]);
1198 }
1199
1200 void
1201 FilmEditor::content_earlier_clicked (wxCommandEvent &)
1202 {
1203         int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1204         if (s == -1) {
1205                 return;
1206         }
1207
1208         ContentList c = _film->content ();
1209         assert (s >= 0 && size_t (s) < c.size ());
1210         _film->move_content_earlier (c[s]);
1211 }
1212
1213 void
1214 FilmEditor::content_later_clicked (wxCommandEvent &)
1215 {
1216         int const s = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1217         if (s == -1) {
1218                 return;
1219         }
1220
1221         ContentList c = _film->content ();
1222         assert (s >= 0 && size_t (s) < c.size ());
1223         _film->move_content_later (c[s]);
1224 }
1225
1226 void
1227 FilmEditor::content_item_selected (wxListEvent &)
1228 {
1229         setup_content_button_sensitivity ();
1230 }
1231
1232 void
1233 FilmEditor::setup_content_button_sensitivity ()
1234 {
1235         _content_add->Enable (_generally_sensitive);
1236
1237         bool const have_selection = _content->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) != -1;
1238         _content_remove->Enable (have_selection && _generally_sensitive);
1239         _content_earlier->Enable (have_selection && _generally_sensitive);
1240         _content_later->Enable (have_selection && _generally_sensitive);
1241 }