#include trimming.
[dcpomatic.git] / src / wx / film_editor.cc
1 /*
2     Copyright (C) 2012-2014 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/film.h"
33 #include "lib/transcode_job.h"
34 #include "lib/exceptions.h"
35 #include "lib/job_manager.h"
36 #include "lib/filter.h"
37 #include "lib/ratio.h"
38 #include "lib/config.h"
39 #include "lib/image_content.h"
40 #include "lib/ffmpeg_content.h"
41 #include "lib/sndfile_content.h"
42 #include "lib/dcp_content_type.h"
43 #include "lib/scaler.h"
44 #include "lib/playlist.h"
45 #include "lib/content.h"
46 #include "lib/content_factory.h"
47 #include "lib/dcp_content.h"
48 #include "timecode.h"
49 #include "wx_util.h"
50 #include "film_editor.h"
51 #include "isdcf_metadata_dialog.h"
52 #include "timeline_dialog.h"
53 #include "timing_panel.h"
54 #include "subtitle_panel.h"
55 #include "audio_panel.h"
56 #include "video_panel.h"
57 #include "content_panel.h"
58
59 using std::string;
60 using std::cout;
61 using std::stringstream;
62 using std::pair;
63 using std::fixed;
64 using std::setprecision;
65 using std::list;
66 using std::vector;
67 using std::max;
68 using boost::shared_ptr;
69 using boost::weak_ptr;
70 using boost::dynamic_pointer_cast;
71 using boost::lexical_cast;
72
73 /** @param f Film to edit */
74 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
75         : wxPanel (parent)
76         , _generally_sensitive (true)
77 {
78         wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
79
80         _main_notebook = new wxNotebook (this, wxID_ANY);
81         s->Add (_main_notebook, 1);
82
83         _content_panel = new ContentPanel (_main_notebook, _film);
84         _main_notebook->AddPage (_content_panel->panel (), _("Content"), true);
85         make_dcp_panel ();
86         _main_notebook->AddPage (_dcp_panel, _("DCP"), false);
87         
88         set_film (f);
89         connect_to_widgets ();
90
91         JobManager::instance()->ActiveJobsChanged.connect (
92                 bind (&FilmEditor::active_jobs_changed, this, _1)
93                 );
94
95         Config::instance()->Changed.connect (boost::bind (&FilmEditor::config_changed, this));
96         
97         SetSizerAndFit (s);
98 }
99
100 void
101 FilmEditor::make_dcp_panel ()
102 {
103         _dcp_panel = new wxPanel (_main_notebook);
104         _dcp_sizer = new wxBoxSizer (wxVERTICAL);
105         _dcp_panel->SetSizer (_dcp_sizer);
106
107         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
108         _dcp_sizer->Add (grid, 0, wxEXPAND | wxALL, 8);
109
110         int r = 0;
111         
112         add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Name"), true, wxGBPosition (r, 0));
113         _name = new wxTextCtrl (_dcp_panel, wxID_ANY);
114         grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
115         ++r;
116         
117         add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), true, wxGBPosition (r, 0));
118         _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
119         grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
120         ++r;
121
122         int flags = wxALIGN_CENTER_VERTICAL;
123 #ifdef __WXOSX__
124         flags |= wxALIGN_RIGHT;
125 #endif  
126
127         _use_isdcf_name = new wxCheckBox (_dcp_panel, wxID_ANY, _("Use ISDCF name"));
128         grid->Add (_use_isdcf_name, wxGBPosition (r, 0), wxDefaultSpan, flags);
129         _edit_isdcf_button = new wxButton (_dcp_panel, wxID_ANY, _("Details..."));
130         grid->Add (_edit_isdcf_button, wxGBPosition (r, 1), wxDefaultSpan);
131         ++r;
132
133         add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), true, wxGBPosition (r, 0));
134         _container = new wxChoice (_dcp_panel, wxID_ANY);
135         grid->Add (_container, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
136         ++r;
137
138         add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Content Type"), true, wxGBPosition (r, 0));
139         _dcp_content_type = new wxChoice (_dcp_panel, wxID_ANY);
140         grid->Add (_dcp_content_type, wxGBPosition (r, 1));
141         ++r;
142
143         {
144                 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Frame Rate"), true, wxGBPosition (r, 0));
145                 _frame_rate_sizer = new wxBoxSizer (wxHORIZONTAL);
146                 _frame_rate_choice = new wxChoice (_dcp_panel, wxID_ANY);
147                 _frame_rate_sizer->Add (_frame_rate_choice, 1, wxALIGN_CENTER_VERTICAL);
148                 _frame_rate_spin = new wxSpinCtrl (_dcp_panel, wxID_ANY);
149                 _frame_rate_sizer->Add (_frame_rate_spin, 1, wxALIGN_CENTER_VERTICAL);
150                 setup_frame_rate_widget ();
151                 _best_frame_rate = new wxButton (_dcp_panel, wxID_ANY, _("Use best"));
152                 _frame_rate_sizer->Add (_best_frame_rate, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
153                 grid->Add (_frame_rate_sizer, wxGBPosition (r, 1));
154         }
155         ++r;
156
157         _burn_subtitles = new wxCheckBox (_dcp_panel, wxID_ANY, _("Burn subtitles into image"));
158         grid->Add (_burn_subtitles, wxGBPosition (r, 0), wxGBSpan (1, 2));
159         ++r;
160
161         _signed = new wxCheckBox (_dcp_panel, wxID_ANY, _("Signed"));
162         grid->Add (_signed, wxGBPosition (r, 0), wxGBSpan (1, 2));
163         ++r;
164         
165         _encrypted = new wxCheckBox (_dcp_panel, wxID_ANY, _("Encrypted"));
166         grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
167         ++r;
168
169         add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Audio channels"), true, wxGBPosition (r, 0));
170         _audio_channels = new wxSpinCtrl (_dcp_panel, wxID_ANY);
171         grid->Add (_audio_channels, wxGBPosition (r, 1));
172         ++r;
173
174         _three_d = new wxCheckBox (_dcp_panel, wxID_ANY, _("3D"));
175         grid->Add (_three_d, wxGBPosition (r, 0), wxGBSpan (1, 2));
176         ++r;
177
178         add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Resolution"), true, wxGBPosition (r, 0));
179         _resolution = new wxChoice (_dcp_panel, wxID_ANY);
180         grid->Add (_resolution, wxGBPosition (r, 1));
181         ++r;
182
183         {
184                 add_label_to_grid_bag_sizer (grid, _dcp_panel, _("JPEG2000 bandwidth"), true, wxGBPosition (r, 0));
185                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
186                 _j2k_bandwidth = new wxSpinCtrl (_dcp_panel, wxID_ANY);
187                 s->Add (_j2k_bandwidth, 1);
188                 add_label_to_sizer (s, _dcp_panel, _("Mbit/s"), false);
189                 grid->Add (s, wxGBPosition (r, 1));
190         }
191         ++r;
192
193         add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Standard"), true, wxGBPosition (r, 0));
194         _standard = new wxChoice (_dcp_panel, wxID_ANY);
195         grid->Add (_standard, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
196         ++r;
197
198         add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Scaler"), true, wxGBPosition (r, 0));
199         _scaler = new wxChoice (_dcp_panel, wxID_ANY);
200         grid->Add (_scaler, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
201         ++r;
202
203         vector<Scaler const *> const sc = Scaler::all ();
204         for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
205                 _scaler->Append (std_to_wx ((*i)->name()));
206         }
207
208         vector<Ratio const *> const ratio = Ratio::all ();
209         for (vector<Ratio const *>::const_iterator i = ratio.begin(); i != ratio.end(); ++i) {
210                 _container->Append (std_to_wx ((*i)->nickname ()));
211         }
212
213         vector<DCPContentType const *> const ct = DCPContentType::all ();
214         for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
215                 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
216         }
217
218         list<int> const dfr = Config::instance()->allowed_dcp_frame_rates ();
219         for (list<int>::const_iterator i = dfr.begin(); i != dfr.end(); ++i) {
220                 _frame_rate_choice->Append (std_to_wx (boost::lexical_cast<string> (*i)));
221         }
222
223         _audio_channels->SetRange (0, MAX_DCP_AUDIO_CHANNELS);
224         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
225         _frame_rate_spin->SetRange (1, 480);
226
227         _resolution->Append (_("2K"));
228         _resolution->Append (_("4K"));
229
230         _standard->Append (_("SMPTE"));
231         _standard->Append (_("Interop"));
232 }
233
234 void
235 FilmEditor::connect_to_widgets ()
236 {
237         _name->Bind             (wxEVT_COMMAND_TEXT_UPDATED,          boost::bind (&FilmEditor::name_changed, this));
238         _use_isdcf_name->Bind   (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&FilmEditor::use_isdcf_name_toggled, this));
239         _edit_isdcf_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&FilmEditor::edit_isdcf_button_clicked, this));
240         _container->Bind        (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::container_changed, this));
241         _scaler->Bind           (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::scaler_changed, this));
242         _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::dcp_content_type_changed, this));
243         _frame_rate_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::frame_rate_choice_changed, this));
244         _frame_rate_spin->Bind  (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&FilmEditor::frame_rate_spin_changed, this));
245         _best_frame_rate->Bind  (wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&FilmEditor::best_frame_rate_clicked, this));
246         _burn_subtitles->Bind   (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&FilmEditor::burn_subtitles_toggled, this));
247         _signed->Bind           (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&FilmEditor::signed_toggled, this));
248         _encrypted->Bind        (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&FilmEditor::encrypted_toggled, this));
249         _audio_channels->Bind   (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&FilmEditor::audio_channels_changed, this));
250         _j2k_bandwidth->Bind    (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&FilmEditor::j2k_bandwidth_changed, this));
251         _resolution->Bind       (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::resolution_changed, this));
252         _three_d->Bind          (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&FilmEditor::three_d_changed, this));
253         _standard->Bind         (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::standard_changed, this));
254 }
255
256 /** Called when the name widget has been changed */
257 void
258 FilmEditor::name_changed ()
259 {
260         if (!_film) {
261                 return;
262         }
263
264         _film->set_name (string (_name->GetValue().mb_str()));
265 }
266
267 void
268 FilmEditor::j2k_bandwidth_changed ()
269 {
270         if (!_film) {
271                 return;
272         }
273         
274         _film->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
275 }
276
277 void
278 FilmEditor::signed_toggled ()
279 {
280         if (!_film) {
281                 return;
282         }
283
284         _film->set_signed (_signed->GetValue ());
285 }
286
287 void
288 FilmEditor::burn_subtitles_toggled ()
289 {
290         if (!_film) {
291                 return;
292         }
293
294         _film->set_burn_subtitles (_burn_subtitles->GetValue ());
295 }
296
297 void
298 FilmEditor::encrypted_toggled ()
299 {
300         if (!_film) {
301                 return;
302         }
303
304         _film->set_encrypted (_encrypted->GetValue ());
305 }
306                                
307 /** Called when the frame rate choice widget has been changed */
308 void
309 FilmEditor::frame_rate_choice_changed ()
310 {
311         if (!_film) {
312                 return;
313         }
314
315         _film->set_video_frame_rate (
316                 boost::lexical_cast<int> (
317                         wx_to_std (_frame_rate_choice->GetString (_frame_rate_choice->GetSelection ()))
318                         )
319                 );
320 }
321
322 /** Called when the frame rate spin widget has been changed */
323 void
324 FilmEditor::frame_rate_spin_changed ()
325 {
326         if (!_film) {
327                 return;
328         }
329
330         _film->set_video_frame_rate (_frame_rate_spin->GetValue ());
331 }
332
333 void
334 FilmEditor::audio_channels_changed ()
335 {
336         if (!_film) {
337                 return;
338         }
339
340         _film->set_audio_channels (_audio_channels->GetValue ());
341 }
342
343 void
344 FilmEditor::resolution_changed ()
345 {
346         if (!_film) {
347                 return;
348         }
349
350         _film->set_resolution (_resolution->GetSelection() == 0 ? RESOLUTION_2K : RESOLUTION_4K);
351 }
352
353 void
354 FilmEditor::standard_changed ()
355 {
356         if (!_film) {
357                 return;
358         }
359
360         _film->set_interop (_standard->GetSelection() == 1);
361 }
362
363 /** Called when the metadata stored in the Film object has changed;
364  *  so that we can update the GUI.
365  *  @param p Property of the Film that has changed.
366  */
367 void
368 FilmEditor::film_changed (Film::Property p)
369 {
370         ensure_ui_thread ();
371         
372         if (!_film) {
373                 return;
374         }
375
376         stringstream s;
377
378         _content_panel->film_changed (p);
379
380         switch (p) {
381         case Film::NONE:
382                 break;
383         case Film::CONTAINER:
384                 setup_container ();
385                 break;
386         case Film::NAME:
387                 checked_set (_name, _film->name());
388                 setup_dcp_name ();
389                 break;
390         case Film::DCP_CONTENT_TYPE:
391                 checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
392                 setup_dcp_name ();
393                 break;
394         case Film::SCALER:
395                 checked_set (_scaler, Scaler::as_index (_film->scaler ()));
396                 break;
397         case Film::BURN_SUBTITLES:
398                 checked_set (_burn_subtitles, _film->burn_subtitles ());
399                 break;
400         case Film::SIGNED:
401                 checked_set (_signed, _film->is_signed ());
402                 break;
403         case Film::ENCRYPTED:
404                 checked_set (_encrypted, _film->encrypted ());
405                 if (_film->encrypted ()) {
406                         _film->set_signed (true);
407                         _signed->Enable (false);
408                 } else {
409                         _signed->Enable (_generally_sensitive);
410                 }
411                 break;
412         case Film::RESOLUTION:
413                 checked_set (_resolution, _film->resolution() == RESOLUTION_2K ? 0 : 1);
414                 setup_dcp_name ();
415                 break;
416         case Film::J2K_BANDWIDTH:
417                 checked_set (_j2k_bandwidth, _film->j2k_bandwidth() / 1000000);
418                 break;
419         case Film::USE_ISDCF_NAME:
420                 checked_set (_use_isdcf_name, _film->use_isdcf_name ());
421                 setup_dcp_name ();
422                 break;
423         case Film::ISDCF_METADATA:
424                 setup_dcp_name ();
425                 break;
426         case Film::VIDEO_FRAME_RATE:
427         {
428                 bool done = false;
429                 for (unsigned int i = 0; i < _frame_rate_choice->GetCount(); ++i) {
430                         if (wx_to_std (_frame_rate_choice->GetString(i)) == boost::lexical_cast<string> (_film->video_frame_rate())) {
431                                 checked_set (_frame_rate_choice, i);
432                                 done = true;
433                                 break;
434                         }
435                 }
436
437                 if (!done) {
438                         checked_set (_frame_rate_choice, -1);
439                 }
440
441                 _frame_rate_spin->SetValue (_film->video_frame_rate ());
442
443                 _best_frame_rate->Enable (_film->best_video_frame_rate () != _film->video_frame_rate ());
444                 break;
445         }
446         case Film::AUDIO_CHANNELS:
447                 checked_set (_audio_channels, _film->audio_channels ());
448                 setup_dcp_name ();
449                 break;
450         case Film::THREE_D:
451                 checked_set (_three_d, _film->three_d ());
452                 setup_dcp_name ();
453                 break;
454         case Film::INTEROP:
455                 checked_set (_standard, _film->interop() ? 1 : 0);
456                 break;
457         default:
458                 break;
459         }
460 }
461
462 void
463 FilmEditor::film_content_changed (int property)
464 {
465         ensure_ui_thread ();
466         
467         if (!_film) {
468                 /* We call this method ourselves (as well as using it as a signal handler)
469                    so _film can be 0.
470                 */
471                 return;
472         }
473
474         _content_panel->film_content_changed (property);
475
476         if (property == FFmpegContentProperty::AUDIO_STREAM || property == SubtitleContentProperty::USE_SUBTITLES) {
477                 setup_dcp_name ();
478         }
479 }
480
481 void
482 FilmEditor::setup_container ()
483 {
484         int n = 0;
485         vector<Ratio const *> ratios = Ratio::all ();
486         vector<Ratio const *>::iterator i = ratios.begin ();
487         while (i != ratios.end() && *i != _film->container ()) {
488                 ++i;
489                 ++n;
490         }
491         
492         if (i == ratios.end()) {
493                 checked_set (_container, -1);
494         } else {
495                 checked_set (_container, n);
496         }
497         
498         setup_dcp_name ();
499 }       
500
501 /** Called when the container widget has been changed */
502 void
503 FilmEditor::container_changed ()
504 {
505         if (!_film) {
506                 return;
507         }
508
509         int const n = _container->GetSelection ();
510         if (n >= 0) {
511                 vector<Ratio const *> ratios = Ratio::all ();
512                 assert (n < int (ratios.size()));
513                 _film->set_container (ratios[n]);
514         }
515 }
516
517 /** Called when the DCP content type widget has been changed */
518 void
519 FilmEditor::dcp_content_type_changed ()
520 {
521         if (!_film) {
522                 return;
523         }
524
525         int const n = _dcp_content_type->GetSelection ();
526         if (n != wxNOT_FOUND) {
527                 _film->set_dcp_content_type (DCPContentType::from_index (n));
528         }
529 }
530
531 /** Sets the Film that we are editing */
532 void
533 FilmEditor::set_film (shared_ptr<Film> f)
534 {
535         set_general_sensitivity (f != 0);
536
537         if (_film == f) {
538                 return;
539         }
540         
541         _film = f;
542
543         _content_panel->set_film (_film);
544
545         if (_film) {
546                 _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
547                 _film->ContentChanged.connect (bind (&FilmEditor::film_content_changed, this, _2));
548         }
549
550         if (_film) {
551                 FileChanged (_film->directory ());
552         } else {
553                 FileChanged ("");
554         }
555
556         film_changed (Film::NAME);
557         film_changed (Film::USE_ISDCF_NAME);
558         film_changed (Film::CONTENT);
559         film_changed (Film::DCP_CONTENT_TYPE);
560         film_changed (Film::CONTAINER);
561         film_changed (Film::RESOLUTION);
562         film_changed (Film::SCALER);
563         film_changed (Film::SIGNED);
564         film_changed (Film::BURN_SUBTITLES);
565         film_changed (Film::ENCRYPTED);
566         film_changed (Film::J2K_BANDWIDTH);
567         film_changed (Film::ISDCF_METADATA);
568         film_changed (Film::VIDEO_FRAME_RATE);
569         film_changed (Film::AUDIO_CHANNELS);
570         film_changed (Film::SEQUENCE_VIDEO);
571         film_changed (Film::THREE_D);
572         film_changed (Film::INTEROP);
573
574         if (!_film->content().empty ()) {
575                 _content_panel->set_selection (_film->content().front ());
576         }
577 }
578
579 void
580 FilmEditor::set_general_sensitivity (bool s)
581 {
582         _generally_sensitive = s;
583
584         _content_panel->set_general_sensitivity (s);
585
586         /* Stuff in the Content / DCP tabs */
587         _name->Enable (s);
588         _use_isdcf_name->Enable (s);
589         _edit_isdcf_button->Enable (s);
590         _dcp_content_type->Enable (s);
591
592         bool si = s;
593         if (_film && _film->encrypted ()) {
594                 si = false;
595         }
596         _burn_subtitles->Enable (s);
597         _signed->Enable (si);
598         
599         _encrypted->Enable (s);
600         _frame_rate_choice->Enable (s);
601         _frame_rate_spin->Enable (s);
602         _audio_channels->Enable (s);
603         _j2k_bandwidth->Enable (s);
604         _container->Enable (s);
605         _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
606         _resolution->Enable (s);
607         _scaler->Enable (s);
608         _three_d->Enable (s);
609         _standard->Enable (s);
610 }
611
612 /** Called when the scaler widget has been changed */
613 void
614 FilmEditor::scaler_changed ()
615 {
616         if (!_film) {
617                 return;
618         }
619
620         int const n = _scaler->GetSelection ();
621         if (n >= 0) {
622                 _film->set_scaler (Scaler::from_index (n));
623         }
624 }
625
626 void
627 FilmEditor::use_isdcf_name_toggled ()
628 {
629         if (!_film) {
630                 return;
631         }
632
633         _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
634 }
635
636 void
637 FilmEditor::edit_isdcf_button_clicked ()
638 {
639         if (!_film) {
640                 return;
641         }
642
643         ISDCFMetadataDialog* d = new ISDCFMetadataDialog (this, _film->isdcf_metadata ());
644         d->ShowModal ();
645         _film->set_isdcf_metadata (d->isdcf_metadata ());
646         d->Destroy ();
647 }
648
649 void
650 FilmEditor::active_jobs_changed (bool a)
651 {
652         set_general_sensitivity (!a);
653 }
654
655 void
656 FilmEditor::setup_dcp_name ()
657 {
658         string s = _film->dcp_name (true);
659         if (s.length() > 28) {
660                 _dcp_name->SetLabel (std_to_wx (s.substr (0, 28)) + N_("..."));
661                 _dcp_name->SetToolTip (std_to_wx (s));
662         } else {
663                 _dcp_name->SetLabel (std_to_wx (s));
664         }
665 }
666
667 void
668 FilmEditor::best_frame_rate_clicked ()
669 {
670         if (!_film) {
671                 return;
672         }
673         
674         _film->set_video_frame_rate (_film->best_video_frame_rate ());
675 }
676
677 void
678 FilmEditor::three_d_changed ()
679 {
680         if (!_film) {
681                 return;
682         }
683
684         _film->set_three_d (_three_d->GetValue ());
685 }
686
687 void
688 FilmEditor::config_changed ()
689 {
690         _j2k_bandwidth->SetRange (1, Config::instance()->maximum_j2k_bandwidth() / 1000000);
691         setup_frame_rate_widget ();
692 }
693
694 void
695 FilmEditor::setup_frame_rate_widget ()
696 {
697         if (Config::instance()->allow_any_dcp_frame_rate ()) {
698                 _frame_rate_choice->Hide ();
699                 _frame_rate_spin->Show ();
700         } else {
701                 _frame_rate_choice->Show ();
702                 _frame_rate_spin->Hide ();
703         }
704
705         _frame_rate_sizer->Layout ();
706 }