Tidy up; make viewer respond with with subtitles button.
[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 <boost/thread.hpp>
28 #include <boost/filesystem.hpp>
29 #include <boost/lexical_cast.hpp>
30 #include "lib/format.h"
31 #include "lib/film.h"
32 #include "lib/transcode_job.h"
33 #include "lib/exceptions.h"
34 #include "lib/ab_transcode_job.h"
35 #include "lib/thumbs_job.h"
36 #include "lib/job_manager.h"
37 #include "lib/filter.h"
38 #include "lib/screen.h"
39 #include "lib/config.h"
40 #include "filter_dialog.h"
41 #include "wx_util.h"
42 #include "film_editor.h"
43 #include "dcp_range_dialog.h"
44 #include "gain_calculator_dialog.h"
45 #include "sound_processor.h"
46
47 using namespace std;
48 using namespace boost;
49
50 /** @param f Film to edit */
51 FilmEditor::FilmEditor (Film* f, wxWindow* parent)
52         : wxPanel (parent)
53         , _ignore_changes (Film::NONE)
54         , _film (f)
55 {
56         _sizer = new wxFlexGridSizer (2, 4, 4);
57         SetSizer (_sizer);
58
59         add_label_to_sizer (_sizer, this, "Name");
60         _name = new wxTextCtrl (this, wxID_ANY);
61         _sizer->Add (_name, 1, wxEXPAND);
62
63         add_label_to_sizer (_sizer, this, "Content");
64         _content = new wxFilePickerCtrl (this, wxID_ANY, wxT (""), wxT ("Select Content File"), wxT("*.*"));
65         _sizer->Add (_content, 1, wxEXPAND);
66
67         add_label_to_sizer (_sizer, this, "Content Type");
68         _dcp_content_type = new wxComboBox (this, wxID_ANY);
69         _sizer->Add (_dcp_content_type);
70
71         add_label_to_sizer (_sizer, this, "Format");
72         _format = new wxComboBox (this, wxID_ANY);
73         _sizer->Add (_format);
74
75         {
76                 add_label_to_sizer (_sizer, this, "Crop");
77                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
78
79                 add_label_to_sizer (s, this, "L");
80                 _left_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
81                 s->Add (_left_crop, 0);
82                 add_label_to_sizer (s, this, "R");
83                 _right_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
84                 s->Add (_right_crop, 0);
85                 add_label_to_sizer (s, this, "T");
86                 _top_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
87                 s->Add (_top_crop, 0);
88                 add_label_to_sizer (s, this, "B");
89                 _bottom_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
90                 s->Add (_bottom_crop, 0);
91
92                 _sizer->Add (s);
93         }
94
95         /* VIDEO-only stuff */
96         {
97                 video_control (add_label_to_sizer (_sizer, this, "Filters"));
98                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
99                 _filters = new wxStaticText (this, wxID_ANY, wxT ("None"));
100                 video_control (_filters);
101                 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
102                 _filters_button = new wxButton (this, wxID_ANY, wxT ("Edit..."));
103                 video_control (_filters_button);
104                 s->Add (_filters_button, 0);
105                 _sizer->Add (s, 1);
106         }
107
108         video_control (add_label_to_sizer (_sizer, this, "Scaler"));
109         _scaler = new wxComboBox (this, wxID_ANY);
110         _sizer->Add (video_control (_scaler), 1);
111
112         {
113                 video_control (add_label_to_sizer (_sizer, this, "Audio Gain"));
114                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
115                 _audio_gain = new wxSpinCtrl (this);
116                 s->Add (video_control (_audio_gain), 1);
117                 video_control (add_label_to_sizer (s, this, "dB"));
118                 _audio_gain_calculate_button = new wxButton (this, wxID_ANY, _("Calculate..."));
119                 video_control (_audio_gain_calculate_button);
120                 s->Add (_audio_gain_calculate_button, 1, wxEXPAND);
121                 _sizer->Add (s);
122         }
123
124         {
125                 video_control (add_label_to_sizer (_sizer, this, "Audio Delay"));
126                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
127                 _audio_delay = new wxSpinCtrl (this);
128                 s->Add (video_control (_audio_delay), 1);
129                 video_control (add_label_to_sizer (s, this, "ms"));
130                 _sizer->Add (s);
131         }
132
133         _with_subtitles = new wxCheckBox (this, wxID_ANY, wxT("With Subtitles"));
134         video_control (_with_subtitles);
135         _sizer->Add (_with_subtitles, 1);
136         _sizer->AddSpacer (0);
137
138         video_control (add_label_to_sizer (_sizer, this, "Frames Per Second"));
139         _frames_per_second = new wxStaticText (this, wxID_ANY, wxT (""));
140         _sizer->Add (video_control (_frames_per_second), 1, wxALIGN_CENTER_VERTICAL);
141         
142         video_control (add_label_to_sizer (_sizer, this, "Original Size"));
143         _original_size = new wxStaticText (this, wxID_ANY, wxT (""));
144         _sizer->Add (video_control (_original_size), 1, wxALIGN_CENTER_VERTICAL);
145         
146         video_control (add_label_to_sizer (_sizer, this, "Length"));
147         _length = new wxStaticText (this, wxID_ANY, wxT (""));
148         _sizer->Add (video_control (_length), 1, wxALIGN_CENTER_VERTICAL);
149
150         video_control (add_label_to_sizer (_sizer, this, "Audio"));
151         _audio = new wxStaticText (this, wxID_ANY, wxT (""));
152         _sizer->Add (video_control (_audio), 1, wxALIGN_CENTER_VERTICAL);
153
154         {
155                 video_control (add_label_to_sizer (_sizer, this, "Range"));
156                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
157                 _dcp_range = new wxStaticText (this, wxID_ANY, wxT (""));
158                 s->Add (video_control (_dcp_range), 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
159                 _change_dcp_range_button = new wxButton (this, wxID_ANY, wxT ("Edit..."));
160                 s->Add (video_control (_change_dcp_range_button), 0, 0, 6);
161                 _sizer->Add (s);
162         }
163
164         _dcp_ab = new wxCheckBox (this, wxID_ANY, wxT ("A/B"));
165         video_control (_dcp_ab);
166         _sizer->Add (_dcp_ab, 1);
167         _sizer->AddSpacer (0);
168
169         /* STILL-only stuff */
170         {
171                 still_control (add_label_to_sizer (_sizer, this, "Duration"));
172                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
173                 _still_duration = new wxSpinCtrl (this);
174                 still_control (_still_duration);
175                 s->Add (_still_duration, 1, wxEXPAND);
176                 still_control (add_label_to_sizer (s, this, "s"));
177                 _sizer->Add (s);
178         }
179
180         /* Set up our editing widgets */
181         
182         _left_crop->SetRange (0, 1024);
183         _top_crop->SetRange (0, 1024);
184         _right_crop->SetRange (0, 1024);
185         _bottom_crop->SetRange (0, 1024);
186         _audio_gain->SetRange (-60, 60);
187         _audio_delay->SetRange (-1000, 1000);
188         _still_duration->SetRange (0, 60 * 60);
189
190         vector<DCPContentType const *> const ct = DCPContentType::all ();
191         for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
192                 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
193         }
194
195         vector<Scaler const *> const sc = Scaler::all ();
196         for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
197                 _scaler->Append (std_to_wx ((*i)->name()));
198         }
199
200         /* And set their values from the Film */
201         set_film (f);
202         
203         /* Now connect to them, since initial values are safely set */
204         _name->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (FilmEditor::name_changed), 0, this);
205         _format->Connect (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this);
206         _content->Connect (wxID_ANY, wxEVT_COMMAND_FILEPICKER_CHANGED, wxCommandEventHandler (FilmEditor::content_changed), 0, this);
207         _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
208         _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
209         _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
210         _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::bottom_crop_changed), 0, this);
211         _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_filters_clicked), 0, this);
212         _scaler->Connect (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler (FilmEditor::scaler_changed), 0, this);
213         _dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler (FilmEditor::dcp_content_type_changed), 0, this);
214         _dcp_ab->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::dcp_ab_toggled), 0, this);
215         _audio_gain->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_gain_changed), 0, this);
216         _audio_gain_calculate_button->Connect (
217                 wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::audio_gain_calculate_button_clicked), 0, this
218                 );
219         _audio_delay->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
220         _still_duration->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::still_duration_changed), 0, this);
221         _change_dcp_range_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::change_dcp_range_clicked), 0, this);
222         _with_subtitles->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
223
224         setup_visibility ();
225         setup_formats ();
226 }
227
228 /** Called when the left crop widget has been changed */
229 void
230 FilmEditor::left_crop_changed (wxCommandEvent &)
231 {
232         if (!_film) {
233                 return;
234         }
235
236         _ignore_changes = Film::CROP;
237         _film->set_left_crop (_left_crop->GetValue ());
238         _ignore_changes = Film::NONE;
239 }
240
241 /** Called when the right crop widget has been changed */
242 void
243 FilmEditor::right_crop_changed (wxCommandEvent &)
244 {
245         if (!_film) {
246                 return;
247         }
248
249         _ignore_changes = Film::CROP;
250         _film->set_right_crop (_right_crop->GetValue ());
251         _ignore_changes = Film::NONE;
252 }
253
254 /** Called when the top crop widget has been changed */
255 void
256 FilmEditor::top_crop_changed (wxCommandEvent &)
257 {
258         if (!_film) {
259                 return;
260         }
261
262         _ignore_changes = Film::CROP;
263         _film->set_top_crop (_top_crop->GetValue ());
264         _ignore_changes = Film::NONE;
265 }
266
267 /** Called when the bottom crop value has been changed */
268 void
269 FilmEditor::bottom_crop_changed (wxCommandEvent &)
270 {
271         if (!_film) {
272                 return;
273         }
274
275         _ignore_changes = Film::CROP;
276         _film->set_bottom_crop (_bottom_crop->GetValue ());
277         _ignore_changes = Film::NONE;
278 }
279
280 /** Called when the content filename has been changed */
281 void
282 FilmEditor::content_changed (wxCommandEvent &)
283 {
284         if (!_film) {
285                 return;
286         }
287
288         _ignore_changes = Film::CONTENT;
289         
290         try {
291                 _film->set_content (wx_to_std (_content->GetPath ()));
292         } catch (std::exception& e) {
293                 _content->SetPath (std_to_wx (_film->directory ()));
294                 error_dialog (this, String::compose ("Could not set content: %1", e.what ()));
295         }
296
297         _ignore_changes = Film::NONE;
298
299         setup_visibility ();
300         setup_formats ();
301         setup_subtitle_button ();
302 }
303
304 /** Called when the DCP A/B switch has been toggled */
305 void
306 FilmEditor::dcp_ab_toggled (wxCommandEvent &)
307 {
308         if (!_film) {
309                 return;
310         }
311         
312         _ignore_changes = Film::DCP_AB;
313         _film->set_dcp_ab (_dcp_ab->GetValue ());
314         _ignore_changes = Film::NONE;
315 }
316
317 /** Called when the name widget has been changed */
318 void
319 FilmEditor::name_changed (wxCommandEvent &)
320 {
321         if (!_film) {
322                 return;
323         }
324
325         _ignore_changes = Film::NAME;
326         _film->set_name (string (_name->GetValue().mb_str()));
327         _ignore_changes = Film::NONE;
328 }
329
330 /** Called when the metadata stored in the Film object has changed;
331  *  so that we can update the GUI.
332  *  @param p Property of the Film that has changed.
333  */
334 void
335 FilmEditor::film_changed (Film::Property p)
336 {
337         if (!_film || _ignore_changes == p) {
338                 return;
339         }
340
341         stringstream s;
342                 
343         switch (p) {
344         case Film::NONE:
345                 break;
346         case Film::CONTENT:
347                 _content->SetPath (std_to_wx (_film->content ()));
348                 setup_visibility ();
349                 setup_formats ();
350                 setup_subtitle_button ();
351                 break;
352         case Film::FORMAT:
353         {
354                 int n = 0;
355                 vector<Format const *>::iterator i = _formats.begin ();
356                 while (i != _formats.end() && *i != _film->format ()) {
357                         ++i;
358                         ++n;
359                 }
360                 _format->SetSelection (n);
361                 break;
362         }
363         case Film::CROP:
364                 _left_crop->SetValue (_film->crop().left);
365                 _right_crop->SetValue (_film->crop().right);
366                 _top_crop->SetValue (_film->crop().top);
367                 _bottom_crop->SetValue (_film->crop().bottom);
368                 break;
369         case Film::FILTERS:
370         {
371                 pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
372                 if (p.first.empty () && p.second.empty ()) {
373                         _filters->SetLabel (_("None"));
374                 } else {
375                         string const b = p.first + " " + p.second;
376                         _filters->SetLabel (std_to_wx (b));
377                 }
378                 _sizer->Layout ();
379                 break;
380         }
381         case Film::NAME:
382                 _name->ChangeValue (std_to_wx (_film->name ()));
383                 break;
384         case Film::FRAMES_PER_SECOND:
385         {
386                 stringstream s;
387                 s << fixed << setprecision(2) << _film->frames_per_second();
388                 _frames_per_second->SetLabel (std_to_wx (s.str ()));
389                 break;
390         }
391         case Film::AUDIO_CHANNELS:
392         case Film::AUDIO_SAMPLE_RATE:
393                 if (_film->audio_channels() == 0 && _film->audio_sample_rate() == 0) {
394                         _audio->SetLabel (wxT (""));
395                 } else {
396                         s << _film->audio_channels () << " channels, " << _film->audio_sample_rate() << "Hz";
397                         _audio->SetLabel (std_to_wx (s.str ()));
398                 }
399                 break;
400         case Film::SIZE:
401                 if (_film->size().width == 0 && _film->size().height == 0) {
402                         _original_size->SetLabel (wxT (""));
403                 } else {
404                         s << _film->size().width << " x " << _film->size().height;
405                         _original_size->SetLabel (std_to_wx (s.str ()));
406                 }
407                 break;
408         case Film::LENGTH:
409                 if (_film->frames_per_second() > 0 && _film->length() > 0) {
410                         s << _film->length() << " frames; " << seconds_to_hms (_film->length() / _film->frames_per_second());
411                 } else if (_film->length() > 0) {
412                         s << _film->length() << " frames";
413                 } 
414                 _length->SetLabel (std_to_wx (s.str ()));
415                 break;
416         case Film::DCP_CONTENT_TYPE:
417                 _dcp_content_type->SetSelection (DCPContentType::as_index (_film->dcp_content_type ()));
418                 break;
419         case Film::THUMBS:
420                 break;
421         case Film::DCP_FRAMES:
422                 if (_film->dcp_frames() == 0) {
423                         _dcp_range->SetLabel (wxT ("Whole film"));
424                 } else {
425                         stringstream s;
426                         s << "First " << _film->dcp_frames() << " frames";
427                         _dcp_range->SetLabel (std_to_wx (s.str ()));
428                 }
429                 _sizer->Layout ();
430                 break;
431         case Film::DCP_TRIM_ACTION:
432                 break;
433         case Film::DCP_AB:
434                 _dcp_ab->SetValue (_film->dcp_ab ());
435                 break;
436         case Film::SCALER:
437                 _scaler->SetSelection (Scaler::as_index (_film->scaler ()));
438                 break;
439         case Film::AUDIO_GAIN:
440                 _audio_gain->SetValue (_film->audio_gain ());
441                 break;
442         case Film::AUDIO_DELAY:
443                 _audio_delay->SetValue (_film->audio_delay ());
444                 break;
445         case Film::STILL_DURATION:
446                 _still_duration->SetValue (_film->still_duration ());
447                 break;
448         case Film::WITH_SUBTITLES:
449                 _with_subtitles->SetValue (_film->with_subtitles ());
450                 break;
451         }
452 }
453
454 /** Called when the format widget has been changed */
455 void
456 FilmEditor::format_changed (wxCommandEvent &)
457 {
458         if (!_film) {
459                 return;
460         }
461
462         _ignore_changes = Film::FORMAT;
463         int const n = _format->GetSelection ();
464         if (n >= 0) {
465                 assert (n < int (_formats.size()));
466                 _film->set_format (_formats[n]);
467         }
468         _ignore_changes = Film::NONE;
469 }
470
471 /** Called when the DCP content type widget has been changed */
472 void
473 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
474 {
475         if (!_film) {
476                 return;
477         }
478
479         _ignore_changes = Film::DCP_CONTENT_TYPE;
480         int const n = _dcp_content_type->GetSelection ();
481         if (n >= 0) {
482                 _film->set_dcp_content_type (DCPContentType::from_index (n));
483         }
484         _ignore_changes = Film::NONE;
485 }
486
487 /** Sets the Film that we are editing */
488 void
489 FilmEditor::set_film (Film* f)
490 {
491         _film = f;
492
493         set_things_sensitive (_film != 0);
494
495         if (_film) {
496                 _film->Changed.connect (sigc::mem_fun (*this, &FilmEditor::film_changed));
497         }
498
499         if (_film) {
500                 FileChanged (_film->directory ());
501         } else {
502                 FileChanged ("");
503         }
504         
505         film_changed (Film::NAME);
506         film_changed (Film::CONTENT);
507         film_changed (Film::DCP_CONTENT_TYPE);
508         film_changed (Film::FORMAT);
509         film_changed (Film::CROP);
510         film_changed (Film::FILTERS);
511         film_changed (Film::DCP_FRAMES);
512         film_changed (Film::DCP_TRIM_ACTION);
513         film_changed (Film::DCP_AB);
514         film_changed (Film::SIZE);
515         film_changed (Film::LENGTH);
516         film_changed (Film::FRAMES_PER_SECOND);
517         film_changed (Film::AUDIO_CHANNELS);
518         film_changed (Film::AUDIO_SAMPLE_RATE);
519         film_changed (Film::SCALER);
520         film_changed (Film::AUDIO_GAIN);
521         film_changed (Film::AUDIO_DELAY);
522         film_changed (Film::STILL_DURATION);
523 }
524
525 /** Updates the sensitivity of lots of widgets to a given value.
526  *  @param s true to make sensitive, false to make insensitive.
527  */
528 void
529 FilmEditor::set_things_sensitive (bool s)
530 {
531         _name->Enable (s);
532         _frames_per_second->Enable (s);
533         _format->Enable (s);
534         _content->Enable (s);
535         _left_crop->Enable (s);
536         _right_crop->Enable (s);
537         _top_crop->Enable (s);
538         _bottom_crop->Enable (s);
539         _filters_button->Enable (s);
540         _scaler->Enable (s);
541         _dcp_content_type->Enable (s);
542         _dcp_range->Enable (s);
543         _change_dcp_range_button->Enable (s);
544         _dcp_ab->Enable (s);
545         _audio_gain->Enable (s);
546         _audio_gain_calculate_button->Enable (s);
547         _audio_delay->Enable (s);
548         _still_duration->Enable (s);
549 }
550
551 /** Called when the `Edit filters' button has been clicked */
552 void
553 FilmEditor::edit_filters_clicked (wxCommandEvent &)
554 {
555         FilterDialog* d = new FilterDialog (this, _film->filters ());
556         d->ActiveChanged.connect (sigc::mem_fun (*_film, &Film::set_filters));
557         d->ShowModal ();
558         d->Destroy ();
559 }
560
561 /** Called when the scaler widget has been changed */
562 void
563 FilmEditor::scaler_changed (wxCommandEvent &)
564 {
565         if (!_film) {
566                 return;
567         }
568
569         _ignore_changes = Film::SCALER;
570         int const n = _scaler->GetSelection ();
571         if (n >= 0) {
572                 _film->set_scaler (Scaler::from_index (n));
573         }
574         _ignore_changes = Film::NONE;
575 }
576
577 void
578 FilmEditor::audio_gain_changed (wxCommandEvent &)
579 {
580         if (!_film) {
581                 return;
582         }
583
584         _ignore_changes = Film::AUDIO_GAIN;
585         _film->set_audio_gain (_audio_gain->GetValue ());
586         _ignore_changes = Film::NONE;
587 }
588
589 void
590 FilmEditor::audio_delay_changed (wxCommandEvent &)
591 {
592         if (!_film) {
593                 return;
594         }
595
596         _ignore_changes = Film::AUDIO_DELAY;
597         _film->set_audio_delay (_audio_delay->GetValue ());
598         _ignore_changes = Film::NONE;
599 }
600
601 wxControl *
602 FilmEditor::video_control (wxControl* c)
603 {
604         _video_controls.push_back (c);
605         return c;
606 }
607
608 wxControl *
609 FilmEditor::still_control (wxControl* c)
610 {
611         _still_controls.push_back (c);
612         return c;
613 }
614
615 void
616 FilmEditor::setup_visibility ()
617 {
618         ContentType c = VIDEO;
619
620         if (_film) {
621                 c = _film->content_type ();
622         }
623
624         for (list<wxControl*>::iterator i = _video_controls.begin(); i != _video_controls.end(); ++i) {
625                 (*i)->Show (c == VIDEO);
626         }
627
628         for (list<wxControl*>::iterator i = _still_controls.begin(); i != _still_controls.end(); ++i) {
629                 (*i)->Show (c == STILL);
630         }
631
632         _sizer->Layout ();
633 }
634
635 void
636 FilmEditor::still_duration_changed (wxCommandEvent &)
637 {
638         if (!_film) {
639                 return;
640         }
641
642         _ignore_changes = Film::STILL_DURATION;
643         _film->set_still_duration (_still_duration->GetValue ());
644         _ignore_changes = Film::NONE;
645 }
646
647 void
648 FilmEditor::change_dcp_range_clicked (wxCommandEvent &)
649 {
650         DCPRangeDialog* d = new DCPRangeDialog (this, _film);
651         d->Changed.connect (sigc::mem_fun (*this, &FilmEditor::dcp_range_changed));
652         d->ShowModal ();
653 }
654
655 void
656 FilmEditor::dcp_range_changed (int frames, TrimAction action)
657 {
658         _film->set_dcp_frames (frames);
659         _film->set_dcp_trim_action (action);
660 }
661
662 void
663 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
664 {
665         GainCalculatorDialog* d = new GainCalculatorDialog (this);
666         d->ShowModal ();
667
668         if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
669                 d->Destroy ();
670                 return;
671         }
672         
673         _audio_gain->SetValue (
674                 Config::instance()->sound_processor()->db_for_fader_change (
675                         d->wanted_fader (),
676                         d->actual_fader ()
677                         )
678                 );
679
680         /* This appears to be necessary, as the change is not signalled,
681            I think.
682         */
683         wxCommandEvent dummy;
684         audio_gain_changed (dummy);
685         
686         d->Destroy ();
687 }
688
689 void
690 FilmEditor::setup_formats ()
691 {
692         ContentType c = VIDEO;
693
694         if (_film) {
695                 c = _film->content_type ();
696         }
697         
698         _formats.clear ();
699
700         vector<Format const *> fmt = Format::all ();
701         for (vector<Format const *>::iterator i = fmt.begin(); i != fmt.end(); ++i) {
702                 if (c == VIDEO && dynamic_cast<FixedFormat const *> (*i)) {
703                         _formats.push_back (*i);
704                 } else if (c == STILL && dynamic_cast<VariableFormat const *> (*i)) {
705                         _formats.push_back (*i);
706                 }
707         }
708
709         _format->Clear ();
710         for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
711                 _format->Append (std_to_wx ((*i)->name ()));
712         }
713
714         _sizer->Layout ();
715 }
716
717 void
718 FilmEditor::with_subtitles_toggled (wxCommandEvent &)
719 {
720         if (!_film) {
721                 return;
722         }
723
724         _ignore_changes = Film::WITH_SUBTITLES;
725         _film->set_with_subtitles (_with_subtitles->GetValue ());
726         _ignore_changes = Film::NONE;
727 }
728
729 void
730 FilmEditor::setup_subtitle_button ()
731 {
732         _with_subtitles->Enable (_film->has_subtitles ());
733         if (!_film->has_subtitles ()) {
734                 _with_subtitles->SetValue (false);
735         }
736 }
737