Make subtitle addition optional.
[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
223         setup_visibility ();
224         setup_formats ();
225 }
226
227 /** Called when the left crop widget has been changed */
228 void
229 FilmEditor::left_crop_changed (wxCommandEvent &)
230 {
231         if (!_film) {
232                 return;
233         }
234
235         _ignore_changes = Film::CROP;
236         _film->set_left_crop (_left_crop->GetValue ());
237         _ignore_changes = Film::NONE;
238 }
239
240 /** Called when the right crop widget has been changed */
241 void
242 FilmEditor::right_crop_changed (wxCommandEvent &)
243 {
244         if (!_film) {
245                 return;
246         }
247
248         _ignore_changes = Film::CROP;
249         _film->set_right_crop (_right_crop->GetValue ());
250         _ignore_changes = Film::NONE;
251 }
252
253 /** Called when the top crop widget has been changed */
254 void
255 FilmEditor::top_crop_changed (wxCommandEvent &)
256 {
257         if (!_film) {
258                 return;
259         }
260
261         _ignore_changes = Film::CROP;
262         _film->set_top_crop (_top_crop->GetValue ());
263         _ignore_changes = Film::NONE;
264 }
265
266 /** Called when the bottom crop value has been changed */
267 void
268 FilmEditor::bottom_crop_changed (wxCommandEvent &)
269 {
270         if (!_film) {
271                 return;
272         }
273
274         _ignore_changes = Film::CROP;
275         _film->set_bottom_crop (_bottom_crop->GetValue ());
276         _ignore_changes = Film::NONE;
277 }
278
279 /** Called when the content filename has been changed */
280 void
281 FilmEditor::content_changed (wxCommandEvent &)
282 {
283         if (!_film) {
284                 return;
285         }
286
287         _ignore_changes = Film::CONTENT;
288         
289         try {
290                 _film->set_content (wx_to_std (_content->GetPath ()));
291         } catch (std::exception& e) {
292                 _content->SetPath (std_to_wx (_film->directory ()));
293                 error_dialog (this, String::compose ("Could not set content: %1", e.what ()));
294         }
295
296         _ignore_changes = Film::NONE;
297
298         setup_visibility ();
299         setup_formats ();
300         setup_subtitle_button ();
301 }
302
303 /** Called when the DCP A/B switch has been toggled */
304 void
305 FilmEditor::dcp_ab_toggled (wxCommandEvent &)
306 {
307         if (!_film) {
308                 return;
309         }
310         
311         _ignore_changes = Film::DCP_AB;
312         _film->set_dcp_ab (_dcp_ab->GetValue ());
313         _ignore_changes = Film::NONE;
314 }
315
316 /** Called when the name widget has been changed */
317 void
318 FilmEditor::name_changed (wxCommandEvent &)
319 {
320         if (!_film) {
321                 return;
322         }
323
324         _ignore_changes = Film::NAME;
325         _film->set_name (string (_name->GetValue().mb_str()));
326         _ignore_changes = Film::NONE;
327 }
328
329 /** Called when the metadata stored in the Film object has changed;
330  *  so that we can update the GUI.
331  *  @param p Property of the Film that has changed.
332  */
333 void
334 FilmEditor::film_changed (Film::Property p)
335 {
336         if (!_film || _ignore_changes == p) {
337                 return;
338         }
339
340         stringstream s;
341                 
342         switch (p) {
343         case Film::NONE:
344                 break;
345         case Film::CONTENT:
346                 _content->SetPath (std_to_wx (_film->content ()));
347                 setup_visibility ();
348                 setup_formats ();
349                 setup_subtitle_button ();
350                 break;
351         case Film::FORMAT:
352         {
353                 int n = 0;
354                 vector<Format const *>::iterator i = _formats.begin ();
355                 while (i != _formats.end() && *i != _film->format ()) {
356                         ++i;
357                         ++n;
358                 }
359                 _format->SetSelection (n);
360                 break;
361         }
362         case Film::CROP:
363                 _left_crop->SetValue (_film->crop().left);
364                 _right_crop->SetValue (_film->crop().right);
365                 _top_crop->SetValue (_film->crop().top);
366                 _bottom_crop->SetValue (_film->crop().bottom);
367                 break;
368         case Film::FILTERS:
369         {
370                 pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
371                 if (p.first.empty () && p.second.empty ()) {
372                         _filters->SetLabel (_("None"));
373                 } else {
374                         string const b = p.first + " " + p.second;
375                         _filters->SetLabel (std_to_wx (b));
376                 }
377                 _sizer->Layout ();
378                 break;
379         }
380         case Film::NAME:
381                 _name->ChangeValue (std_to_wx (_film->name ()));
382                 break;
383         case Film::FRAMES_PER_SECOND:
384         {
385                 stringstream s;
386                 s << fixed << setprecision(2) << _film->frames_per_second();
387                 _frames_per_second->SetLabel (std_to_wx (s.str ()));
388                 break;
389         }
390         case Film::AUDIO_CHANNELS:
391         case Film::AUDIO_SAMPLE_RATE:
392                 if (_film->audio_channels() == 0 && _film->audio_sample_rate() == 0) {
393                         _audio->SetLabel (wxT (""));
394                 } else {
395                         s << _film->audio_channels () << " channels, " << _film->audio_sample_rate() << "Hz";
396                         _audio->SetLabel (std_to_wx (s.str ()));
397                 }
398                 break;
399         case Film::SIZE:
400                 if (_film->size().width == 0 && _film->size().height == 0) {
401                         _original_size->SetLabel (wxT (""));
402                 } else {
403                         s << _film->size().width << " x " << _film->size().height;
404                         _original_size->SetLabel (std_to_wx (s.str ()));
405                 }
406                 break;
407         case Film::LENGTH:
408                 if (_film->frames_per_second() > 0 && _film->length() > 0) {
409                         s << _film->length() << " frames; " << seconds_to_hms (_film->length() / _film->frames_per_second());
410                 } else if (_film->length() > 0) {
411                         s << _film->length() << " frames";
412                 } 
413                 _length->SetLabel (std_to_wx (s.str ()));
414                 break;
415         case Film::DCP_CONTENT_TYPE:
416                 _dcp_content_type->SetSelection (DCPContentType::as_index (_film->dcp_content_type ()));
417                 break;
418         case Film::THUMBS:
419                 break;
420         case Film::DCP_FRAMES:
421                 if (_film->dcp_frames() == 0) {
422                         _dcp_range->SetLabel (wxT ("Whole film"));
423                 } else {
424                         stringstream s;
425                         s << "First " << _film->dcp_frames() << " frames";
426                         _dcp_range->SetLabel (std_to_wx (s.str ()));
427                 }
428                 _sizer->Layout ();
429                 break;
430         case Film::DCP_TRIM_ACTION:
431                 break;
432         case Film::DCP_AB:
433                 _dcp_ab->SetValue (_film->dcp_ab ());
434                 break;
435         case Film::SCALER:
436                 _scaler->SetSelection (Scaler::as_index (_film->scaler ()));
437                 break;
438         case Film::AUDIO_GAIN:
439                 _audio_gain->SetValue (_film->audio_gain ());
440                 break;
441         case Film::AUDIO_DELAY:
442                 _audio_delay->SetValue (_film->audio_delay ());
443                 break;
444         case Film::STILL_DURATION:
445                 _still_duration->SetValue (_film->still_duration ());
446                 break;
447         case Film::WITH_SUBTITLES:
448                 _with_subtitles->SetValue (_film->with_subtitles ());
449                 break;
450         }
451 }
452
453 /** Called when the format widget has been changed */
454 void
455 FilmEditor::format_changed (wxCommandEvent &)
456 {
457         if (!_film) {
458                 return;
459         }
460
461         _ignore_changes = Film::FORMAT;
462         int const n = _format->GetSelection ();
463         if (n >= 0) {
464                 assert (n < int (_formats.size()));
465                 _film->set_format (_formats[n]);
466         }
467         _ignore_changes = Film::NONE;
468 }
469
470 /** Called when the DCP content type widget has been changed */
471 void
472 FilmEditor::dcp_content_type_changed (wxCommandEvent &)
473 {
474         if (!_film) {
475                 return;
476         }
477
478         _ignore_changes = Film::DCP_CONTENT_TYPE;
479         int const n = _dcp_content_type->GetSelection ();
480         if (n >= 0) {
481                 _film->set_dcp_content_type (DCPContentType::from_index (n));
482         }
483         _ignore_changes = Film::NONE;
484 }
485
486 /** Sets the Film that we are editing */
487 void
488 FilmEditor::set_film (Film* f)
489 {
490         _film = f;
491
492         set_things_sensitive (_film != 0);
493
494         if (_film) {
495                 _film->Changed.connect (sigc::mem_fun (*this, &FilmEditor::film_changed));
496         }
497
498         if (_film) {
499                 FileChanged (_film->directory ());
500         } else {
501                 FileChanged ("");
502         }
503         
504         film_changed (Film::NAME);
505         film_changed (Film::CONTENT);
506         film_changed (Film::DCP_CONTENT_TYPE);
507         film_changed (Film::FORMAT);
508         film_changed (Film::CROP);
509         film_changed (Film::FILTERS);
510         film_changed (Film::DCP_FRAMES);
511         film_changed (Film::DCP_TRIM_ACTION);
512         film_changed (Film::DCP_AB);
513         film_changed (Film::SIZE);
514         film_changed (Film::LENGTH);
515         film_changed (Film::FRAMES_PER_SECOND);
516         film_changed (Film::AUDIO_CHANNELS);
517         film_changed (Film::AUDIO_SAMPLE_RATE);
518         film_changed (Film::SCALER);
519         film_changed (Film::AUDIO_GAIN);
520         film_changed (Film::AUDIO_DELAY);
521         film_changed (Film::STILL_DURATION);
522 }
523
524 /** Updates the sensitivity of lots of widgets to a given value.
525  *  @param s true to make sensitive, false to make insensitive.
526  */
527 void
528 FilmEditor::set_things_sensitive (bool s)
529 {
530         _name->Enable (s);
531         _frames_per_second->Enable (s);
532         _format->Enable (s);
533         _content->Enable (s);
534         _left_crop->Enable (s);
535         _right_crop->Enable (s);
536         _top_crop->Enable (s);
537         _bottom_crop->Enable (s);
538         _filters_button->Enable (s);
539         _scaler->Enable (s);
540         _dcp_content_type->Enable (s);
541         _dcp_range->Enable (s);
542         _change_dcp_range_button->Enable (s);
543         _dcp_ab->Enable (s);
544         _audio_gain->Enable (s);
545         _audio_gain_calculate_button->Enable (s);
546         _audio_delay->Enable (s);
547         _still_duration->Enable (s);
548 }
549
550 /** Called when the `Edit filters' button has been clicked */
551 void
552 FilmEditor::edit_filters_clicked (wxCommandEvent &)
553 {
554         FilterDialog* d = new FilterDialog (this, _film->filters ());
555         d->ActiveChanged.connect (sigc::mem_fun (*_film, &Film::set_filters));
556         d->ShowModal ();
557         d->Destroy ();
558 }
559
560 /** Called when the scaler widget has been changed */
561 void
562 FilmEditor::scaler_changed (wxCommandEvent &)
563 {
564         if (!_film) {
565                 return;
566         }
567
568         _ignore_changes = Film::SCALER;
569         int const n = _scaler->GetSelection ();
570         if (n >= 0) {
571                 _film->set_scaler (Scaler::from_index (n));
572         }
573         _ignore_changes = Film::NONE;
574 }
575
576 void
577 FilmEditor::audio_gain_changed (wxCommandEvent &)
578 {
579         if (!_film) {
580                 return;
581         }
582
583         _ignore_changes = Film::AUDIO_GAIN;
584         _film->set_audio_gain (_audio_gain->GetValue ());
585         _ignore_changes = Film::NONE;
586 }
587
588 void
589 FilmEditor::audio_delay_changed (wxCommandEvent &)
590 {
591         if (!_film) {
592                 return;
593         }
594
595         _ignore_changes = Film::AUDIO_DELAY;
596         _film->set_audio_delay (_audio_delay->GetValue ());
597         _ignore_changes = Film::NONE;
598 }
599
600 wxControl *
601 FilmEditor::video_control (wxControl* c)
602 {
603         _video_controls.push_back (c);
604         return c;
605 }
606
607 wxControl *
608 FilmEditor::still_control (wxControl* c)
609 {
610         _still_controls.push_back (c);
611         return c;
612 }
613
614 void
615 FilmEditor::setup_visibility ()
616 {
617         ContentType c = VIDEO;
618
619         if (_film) {
620                 c = _film->content_type ();
621         }
622
623         for (list<wxControl*>::iterator i = _video_controls.begin(); i != _video_controls.end(); ++i) {
624                 (*i)->Show (c == VIDEO);
625         }
626
627         for (list<wxControl*>::iterator i = _still_controls.begin(); i != _still_controls.end(); ++i) {
628                 (*i)->Show (c == STILL);
629         }
630
631         _sizer->Layout ();
632 }
633
634 void
635 FilmEditor::still_duration_changed (wxCommandEvent &)
636 {
637         if (!_film) {
638                 return;
639         }
640
641         _ignore_changes = Film::STILL_DURATION;
642         _film->set_still_duration (_still_duration->GetValue ());
643         _ignore_changes = Film::NONE;
644 }
645
646 void
647 FilmEditor::change_dcp_range_clicked (wxCommandEvent &)
648 {
649         DCPRangeDialog* d = new DCPRangeDialog (this, _film);
650         d->Changed.connect (sigc::mem_fun (*this, &FilmEditor::dcp_range_changed));
651         d->ShowModal ();
652 }
653
654 void
655 FilmEditor::dcp_range_changed (int frames, TrimAction action)
656 {
657         _film->set_dcp_frames (frames);
658         _film->set_dcp_trim_action (action);
659 }
660
661 void
662 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
663 {
664         GainCalculatorDialog* d = new GainCalculatorDialog (this);
665         d->ShowModal ();
666
667         if (d->wanted_fader() == 0 || d->actual_fader() == 0) {
668                 d->Destroy ();
669                 return;
670         }
671         
672         _audio_gain->SetValue (
673                 Config::instance()->sound_processor()->db_for_fader_change (
674                         d->wanted_fader (),
675                         d->actual_fader ()
676                         )
677                 );
678
679         /* This appears to be necessary, as the change is not signalled,
680            I think.
681         */
682         wxCommandEvent dummy;
683         audio_gain_changed (dummy);
684         
685         d->Destroy ();
686 }
687
688 void
689 FilmEditor::setup_formats ()
690 {
691         ContentType c = VIDEO;
692
693         if (_film) {
694                 c = _film->content_type ();
695         }
696         
697         _formats.clear ();
698
699         vector<Format const *> fmt = Format::all ();
700         for (vector<Format const *>::iterator i = fmt.begin(); i != fmt.end(); ++i) {
701                 if (c == VIDEO && dynamic_cast<FixedFormat const *> (*i)) {
702                         _formats.push_back (*i);
703                 } else if (c == STILL && dynamic_cast<VariableFormat const *> (*i)) {
704                         _formats.push_back (*i);
705                 }
706         }
707
708         _format->Clear ();
709         for (vector<Format const *>::iterator i = _formats.begin(); i != _formats.end(); ++i) {
710                 _format->Append (std_to_wx ((*i)->name ()));
711         }
712
713         _sizer->Layout ();
714 }
715
716 void
717 FilmEditor::with_subtitles_toggled (wxCommandEvent &)
718 {
719         if (!_film) {
720                 return;
721         }
722
723         _ignore_changes = Film::WITH_SUBTITLES;
724         _film->set_with_subtitles (_with_subtitles->GetValue ());
725         _ignore_changes = Film::NONE;
726 }
727
728 void
729 FilmEditor::setup_subtitle_button ()
730 {
731         _with_subtitles->Enable (_film->has_subtitles ());
732         if (!_film->has_subtitles ()) {
733                 _with_subtitles->SetValue (false);
734         }
735 }
736