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