Extract common code out into kdm_for_screen()
[dcpomatic.git] / src / wx / video_panel.cc
1 /*
2     Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "filter_dialog.h"
22 #include "video_panel.h"
23 #include "wx_util.h"
24 #include "content_colour_conversion_dialog.h"
25 #include "content_widget.h"
26 #include "content_panel.h"
27 #include "static_text.h"
28 #include "check_box.h"
29 #include "dcpomatic_button.h"
30 #include "lib/filter.h"
31 #include "lib/ffmpeg_content.h"
32 #include "lib/colour_conversion.h"
33 #include "lib/config.h"
34 #include "lib/util.h"
35 #include "lib/ratio.h"
36 #include "lib/frame_rate_change.h"
37 #include "lib/dcp_content.h"
38 #include "lib/video_content.h"
39 #include <wx/spinctrl.h>
40 #include <boost/foreach.hpp>
41 #include <boost/unordered_set.hpp>
42 #include <boost/functional/hash.hpp>
43 #include <set>
44 #include <iostream>
45
46 using std::vector;
47 using std::string;
48 using std::pair;
49 using std::cout;
50 using std::list;
51 using std::set;
52 using boost::shared_ptr;
53 using boost::dynamic_pointer_cast;
54 using boost::bind;
55 using boost::optional;
56 using namespace dcpomatic;
57
58 static VideoContentScale
59 index_to_scale (int n)
60 {
61         vector<VideoContentScale> scales = VideoContentScale::all ();
62         DCPOMATIC_ASSERT (n >= 0);
63         DCPOMATIC_ASSERT (n < int (scales.size ()));
64         return scales[n];
65 }
66
67 static int
68 scale_to_index (VideoContentScale scale)
69 {
70         vector<VideoContentScale> scales = VideoContentScale::all ();
71         for (size_t i = 0; i < scales.size(); ++i) {
72                 if (scales[i] == scale) {
73                         return i;
74                 }
75         }
76
77         DCPOMATIC_ASSERT (false);
78 }
79
80 VideoPanel::VideoPanel (ContentPanel* p)
81         : ContentSubPanel (p, _("Video"))
82 {
83         _reference = new CheckBox (this, _("Use this DCP's video as OV and make VF"));
84         _reference_note = new StaticText (this, wxT(""));
85         _reference_note->Wrap (200);
86         wxFont font = _reference_note->GetFont();
87         font.SetStyle(wxFONTSTYLE_ITALIC);
88         font.SetPointSize(font.GetPointSize() - 1);
89         _reference_note->SetFont(font);
90
91         _use = new wxCheckBox (this, wxID_ANY, _("Use"));
92
93         _type_label = create_label (this, _("Type"), true);
94         _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
95                 this,
96                 new wxChoice (this, wxID_ANY),
97                 VideoContentProperty::FRAME_TYPE,
98                 &Content::video,
99                 boost::mem_fn (&VideoContent::frame_type),
100                 boost::mem_fn (&VideoContent::set_frame_type),
101                 &caster<int, VideoFrameType>,
102                 &caster<VideoFrameType, int>
103                 );
104
105         _left_crop_label = create_label (this, _("Left crop"), true);
106         _left_crop = new ContentSpinCtrl<VideoContent> (
107                 this,
108                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
109                 VideoContentProperty::CROP,
110                 &Content::video,
111                 boost::mem_fn (&VideoContent::left_crop),
112                 boost::mem_fn (&VideoContent::set_left_crop)
113                 );
114
115         _right_crop_label = create_label (this, _("Right crop"), true);
116         _right_crop = new ContentSpinCtrl<VideoContent> (
117                 this,
118                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
119                 VideoContentProperty::CROP,
120                 &Content::video,
121                 boost::mem_fn (&VideoContent::right_crop),
122                 boost::mem_fn (&VideoContent::set_right_crop)
123                 );
124
125         _top_crop_label = create_label (this, _("Top crop"), true);
126         _top_crop = new ContentSpinCtrl<VideoContent> (
127                 this,
128                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
129                 VideoContentProperty::CROP,
130                 &Content::video,
131                 boost::mem_fn (&VideoContent::top_crop),
132                 boost::mem_fn (&VideoContent::set_top_crop)
133                 );
134
135         _bottom_crop_label = create_label (this, _("Bottom crop"), true);
136         _bottom_crop = new ContentSpinCtrl<VideoContent> (
137                 this,
138                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
139                 VideoContentProperty::CROP,
140                 &Content::video,
141                 boost::mem_fn (&VideoContent::bottom_crop),
142                 boost::mem_fn (&VideoContent::set_bottom_crop)
143                 );
144
145         _fade_in_label = create_label (this, _("Fade in"), true);
146         _fade_in = new Timecode<ContentTime> (this);
147
148         _fade_out_label = create_label (this, _("Fade out"), true);
149         _fade_out = new Timecode<ContentTime> (this);
150
151         _scale_to_label = create_label (this, _("Scale to"), true);
152         _scale = new ContentChoice<VideoContent, VideoContentScale> (
153                 this,
154                 new wxChoice (this, wxID_ANY),
155                 VideoContentProperty::SCALE,
156                 &Content::video,
157                 boost::mem_fn (&VideoContent::scale),
158                 boost::mem_fn (&VideoContent::set_scale),
159                 &index_to_scale,
160                 &scale_to_index
161                 );
162
163         wxClientDC dc (this);
164         wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
165         size.SetHeight (-1);
166
167         _filters_label = create_label (this, _("Filters"), true);
168         _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
169         _filters_button = new Button (this, _("Edit..."));
170
171         _colour_conversion_label = create_label (this, _("Colour conversion"), true);
172         _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
173         _colour_conversion->Append (_("None"));
174         BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
175                 _colour_conversion->Append (std_to_wx (i.name));
176         }
177
178         /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
179         _colour_conversion->Append (S_("Colour|Custom"));
180         _edit_colour_conversion_button = new Button (this, _("Edit..."));
181
182         _range_label = create_label (this, _("Range"), true);
183         _range = new wxChoice (this, wxID_ANY);
184         _range->Append (_("Full (JPEG, 0-255)"));
185         _range->Append (_("Video (MPEG, 16-235)"));
186
187         _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
188         _description->SetFont(font);
189
190         _left_crop->wrapped()->SetRange (0, 4096);
191         _top_crop->wrapped()->SetRange (0, 4096);
192         _right_crop->wrapped()->SetRange (0, 4096);
193         _bottom_crop->wrapped()->SetRange (0, 4096);
194
195         _scale->wrapped()->Clear ();
196         BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
197                 _scale->wrapped()->Append (std_to_wx (i.name ()));
198         }
199
200         _frame_type->wrapped()->Append (_("2D"));
201         _frame_type->wrapped()->Append (_("3D"));
202         _frame_type->wrapped()->Append (_("3D left/right"));
203         _frame_type->wrapped()->Append (_("3D top/bottom"));
204         _frame_type->wrapped()->Append (_("3D alternate"));
205         _frame_type->wrapped()->Append (_("3D left only"));
206         _frame_type->wrapped()->Append (_("3D right only"));
207
208         content_selection_changed ();
209
210         _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
211         _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
212
213         _use->Bind                           (wxEVT_CHECKBOX, boost::bind (&VideoPanel::use_clicked, this));
214         _reference->Bind                     (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
215         _filters_button->Bind                (wxEVT_BUTTON,   boost::bind (&VideoPanel::edit_filters_clicked, this));
216         _colour_conversion->Bind             (wxEVT_CHOICE,   boost::bind (&VideoPanel::colour_conversion_changed, this));
217         _range->Bind                         (wxEVT_CHOICE,   boost::bind (&VideoPanel::range_changed, this));
218         _edit_colour_conversion_button->Bind (wxEVT_BUTTON,   boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
219
220         add_to_grid ();
221 }
222
223 void
224 VideoPanel::add_to_grid ()
225 {
226         bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
227
228         int r = 0;
229
230         _reference->Show (full);
231         _reference_note->Show (full && !_reference_note->GetLabel().IsEmpty());
232
233         if (full) {
234                 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
235                 reference_sizer->Add (_reference, 0);
236                 reference_sizer->Add (_reference_note, 0);
237                 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
238                 ++r;
239         }
240
241         _use->Show (full);
242         _grid->Add (_use, wxGBPosition(r, 0), wxGBSpan(1, 2));
243         ++r;
244
245         add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
246         _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
247         ++r;
248
249         int cr = 0;
250         wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
251         add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
252         _left_crop->add (crop, wxGBPosition (cr, 1));
253         add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
254         _right_crop->add (crop, wxGBPosition (cr, 3));
255         ++cr;
256         add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
257         _top_crop->add (crop, wxGBPosition (cr, 1));
258         add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
259         _bottom_crop->add (crop, wxGBPosition (cr, 3));
260         _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
261         r += 2;
262
263         _scale_to_label->Show (full);
264         _scale->show (full);
265         _filters_label->Show (full);
266         _filters->Show (full);
267         _filters_button->Show (full);
268         _colour_conversion_label->Show (full);
269         _colour_conversion->Show (full);
270         _edit_colour_conversion_button->Show (full);
271         _range_label->Show (full);
272         _range->Show (full);
273
274         add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
275         _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
276         ++r;
277
278         add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
279         _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
280         ++r;
281
282         if (full) {
283                 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
284                 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
285                 ++r;
286
287                 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
288                 {
289                         wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
290                         s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
291                         s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
292                         _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
293                 }
294                 ++r;
295
296                 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
297                 {
298                         wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
299                         s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
300                         s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
301                         _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
302                 }
303                 ++r;
304
305                 add_label_to_sizer (_grid, _range_label, true, wxGBPosition(r, 0));
306                 _grid->Add (_range, wxGBPosition(r, 1), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL);
307                 ++r;
308         }
309
310         _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
311         ++r;
312 }
313
314 void
315 VideoPanel::range_changed ()
316 {
317         ContentList vc = _parent->selected_video ();
318         if (vc.size() != 1) {
319                 return;
320         }
321
322         switch (_range->GetSelection()) {
323         case 0:
324                 vc.front()->video->set_range (VIDEO_RANGE_FULL);
325                 break;
326         case 1:
327                 vc.front()->video->set_range (VIDEO_RANGE_VIDEO);
328                 break;
329         default:
330                 DCPOMATIC_ASSERT (false);
331         }
332 }
333
334
335 void
336 VideoPanel::film_changed (Film::Property property)
337 {
338         switch (property) {
339         case Film::VIDEO_FRAME_RATE:
340         case Film::CONTAINER:
341         case Film::RESOLUTION:
342                 setup_description ();
343                 setup_sensitivity ();
344                 break;
345         case Film::REEL_TYPE:
346         case Film::INTEROP:
347                 setup_sensitivity ();
348                 break;
349         default:
350                 break;
351         }
352 }
353
354 std::size_t
355 hash_value (boost::optional<ColourConversion> const & c)
356 {
357         boost::hash<string> hasher;
358         if (!c) {
359                 return hasher ("none");
360         }
361         return hasher (c->identifier());
362 }
363
364
365 void
366 VideoPanel::film_content_changed (int property)
367 {
368         ContentList vc = _parent->selected_video ();
369         shared_ptr<Content> vcs;
370         shared_ptr<FFmpegContent> fcs;
371         if (!vc.empty ()) {
372                 vcs = vc.front ();
373                 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
374         }
375
376         if (property == ContentProperty::VIDEO_FRAME_RATE ||
377             property == VideoContentProperty::FRAME_TYPE ||
378             property == VideoContentProperty::CROP ||
379             property == VideoContentProperty::SCALE) {
380                 setup_description ();
381         } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
382                 boost::unordered_set<optional<ColourConversion> > check;
383                 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
384                         check.insert (i->video->colour_conversion());
385                 }
386
387                 /* Remove any "Many" entry that we might have added previously.  There should
388                  * be entries for each preset plus one for "None" and one for "Custom".
389                  */
390                 vector<PresetColourConversion> cc = PresetColourConversion::all ();
391                 if (_colour_conversion->GetCount() > cc.size() + 2) {
392                         _colour_conversion->Delete (_colour_conversion->GetCount() - 1);
393                 }
394
395                 if (check.size() == 1) {
396                         if (vcs && vcs->video->colour_conversion ()) {
397                                 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
398                                 if (preset) {
399                                         checked_set (_colour_conversion, preset.get() + 1);
400                                 } else {
401                                         checked_set (_colour_conversion, cc.size() + 1);
402                                 }
403                         } else {
404                                 checked_set (_colour_conversion, 0);
405                         }
406                 } else if (check.size() > 1) {
407                         /* Add a "many" entry and select it as an indication that multiple different
408                          * colour conversions are present in the selection.
409                          */
410                         _colour_conversion->Append (_("Many"));
411                         checked_set (_colour_conversion, _colour_conversion->GetCount() - 1);
412                 }
413
414                 setup_sensitivity ();
415
416         } else if (property == FFmpegContentProperty::FILTERS) {
417                 if (fcs) {
418                         string p = Filter::ffmpeg_string (fcs->filters ());
419                         if (p.empty ()) {
420                                 checked_set (_filters, _("None"));
421                         } else {
422                                 if (p.length() > 25) {
423                                         p = p.substr (0, 25) + "...";
424                                 }
425                                 checked_set (_filters, p);
426                         }
427                 }
428         } else if (property == VideoContentProperty::USE) {
429                 set<bool> check;
430                 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
431                         check.insert (i->video->use());
432                 }
433
434                 if (check.size() == 1) {
435                         checked_set (_use, vc.front()->video->use());
436                 } else {
437                         checked_set (_use, false);
438                 }
439
440                 setup_sensitivity ();
441         } else if (property == VideoContentProperty::FADE_IN) {
442                 set<Frame> check;
443                 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
444                         check.insert (i->video->fade_in ());
445                 }
446
447                 if (check.size() == 1) {
448                         _fade_in->set (
449                                 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
450                                 vc.front()->active_video_frame_rate(_parent->film())
451                                 );
452                 } else {
453                         _fade_in->clear ();
454                 }
455         } else if (property == VideoContentProperty::FADE_OUT) {
456                 set<Frame> check;
457                 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
458                         check.insert (i->video->fade_out ());
459                 }
460
461                 if (check.size() == 1) {
462                         _fade_out->set (
463                                 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
464                                 vc.front()->active_video_frame_rate(_parent->film())
465                                 );
466                 } else {
467                         _fade_out->clear ();
468                 }
469         } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
470                 if (vc.size() == 1) {
471                         shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
472                         checked_set (_reference, dcp ? dcp->reference_video () : false);
473                 } else {
474                         checked_set (_reference, false);
475                 }
476
477                 setup_sensitivity ();
478         } else if (property == VideoContentProperty::RANGE) {
479                 if (vcs) {
480                         checked_set (_range, vcs->video->range() == VIDEO_RANGE_FULL ? 0 : 1);
481                 } else {
482                         checked_set (_range, 0);
483                 }
484
485                 setup_sensitivity ();
486         }
487 }
488
489 /** Called when the `Edit filters' button has been clicked */
490 void
491 VideoPanel::edit_filters_clicked ()
492 {
493         FFmpegContentList c = _parent->selected_ffmpeg ();
494         if (c.size() != 1) {
495                 return;
496         }
497
498         FilterDialog* d = new FilterDialog (this, c.front()->filters());
499         d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
500         d->ShowModal ();
501         d->Destroy ();
502 }
503
504 void
505 VideoPanel::setup_description ()
506 {
507         ContentList vc = _parent->selected_video ();
508         if (vc.empty ()) {
509                 checked_set (_description, wxT (""));
510                 return;
511         } else if (vc.size() > 1) {
512                 checked_set (_description, _("Multiple content selected"));
513                 return;
514         }
515
516         string d = vc.front()->video->processing_description (_parent->film());
517         size_t lines = count (d.begin(), d.end(), '\n');
518
519         for (int i = lines; i < 6; ++i) {
520                 d += "\n ";
521         }
522
523         checked_set (_description, d);
524         _sizer->Layout ();
525 }
526
527 void
528 VideoPanel::colour_conversion_changed ()
529 {
530         ContentList vc = _parent->selected_video ();
531
532         int const s = _colour_conversion->GetSelection ();
533         vector<PresetColourConversion> all = PresetColourConversion::all ();
534
535         if (s == int(all.size() + 1)) {
536                 edit_colour_conversion_clicked ();
537         } else {
538                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
539                         if (s == 0) {
540                                 i->video->unset_colour_conversion ();
541                         } else if (s != int(all.size() + 2)) {
542                                 i->video->set_colour_conversion (all[s - 1].conversion);
543                         }
544                 }
545         }
546 }
547
548 void
549 VideoPanel::edit_colour_conversion_clicked ()
550 {
551         ContentList vc = _parent->selected_video ();
552
553         ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
554         d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
555         if (d->ShowModal() == wxID_OK) {
556                 BOOST_FOREACH (shared_ptr<Content> i, vc) {
557                         i->video->set_colour_conversion (d->get ());
558                 }
559         } else {
560                 /* Reset the colour conversion choice */
561                 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
562         }
563         d->Destroy ();
564 }
565
566 void
567 VideoPanel::content_selection_changed ()
568 {
569         ContentList video_sel = _parent->selected_video ();
570
571         _frame_type->set_content (video_sel);
572         _left_crop->set_content (video_sel);
573         _right_crop->set_content (video_sel);
574         _top_crop->set_content (video_sel);
575         _bottom_crop->set_content (video_sel);
576         _scale->set_content (video_sel);
577
578         film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
579         film_content_changed (VideoContentProperty::CROP);
580         film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
581         film_content_changed (VideoContentProperty::FADE_IN);
582         film_content_changed (VideoContentProperty::FADE_OUT);
583         film_content_changed (VideoContentProperty::RANGE);
584         film_content_changed (VideoContentProperty::USE);
585         film_content_changed (FFmpegContentProperty::FILTERS);
586         film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
587
588         setup_sensitivity ();
589 }
590
591 void
592 VideoPanel::setup_sensitivity ()
593 {
594         ContentList sel = _parent->selected ();
595
596         shared_ptr<DCPContent> dcp;
597         if (sel.size() == 1) {
598                 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
599         }
600
601         string why_not;
602         bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
603         wxString cannot;
604         if (why_not.empty()) {
605                 cannot = _("Cannot reference this DCP's video.");
606         } else {
607                 cannot = _("Cannot reference this DCP's video: ") + std_to_wx(why_not);
608         }
609         setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
610
611         bool const enable = !_reference->GetValue() && _use->GetValue();
612
613         _use->Enable (!_reference->GetValue());
614
615         if (!enable) {
616                 _frame_type->wrapped()->Enable (false);
617                 _left_crop->wrapped()->Enable (false);
618                 _right_crop->wrapped()->Enable (false);
619                 _top_crop->wrapped()->Enable (false);
620                 _bottom_crop->wrapped()->Enable (false);
621                 _fade_in->Enable (false);
622                 _fade_out->Enable (false);
623                 _scale->wrapped()->Enable (false);
624                 _description->Enable (false);
625                 _filters->Enable (false);
626                 _filters_button->Enable (false);
627                 _colour_conversion->Enable (false);
628                 _range->Enable (false);
629         } else {
630                 ContentList video_sel = _parent->selected_video ();
631                 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
632                 bool const single = video_sel.size() == 1;
633
634                 _frame_type->wrapped()->Enable (true);
635                 _left_crop->wrapped()->Enable (true);
636                 _right_crop->wrapped()->Enable (true);
637                 _top_crop->wrapped()->Enable (true);
638                 _bottom_crop->wrapped()->Enable (true);
639                 _fade_in->Enable (!video_sel.empty ());
640                 _fade_out->Enable (!video_sel.empty ());
641                 _scale->wrapped()->Enable (true);
642                 _description->Enable (true);
643                 _filters->Enable (true);
644                 _filters_button->Enable (single && !ffmpeg_sel.empty ());
645                 _colour_conversion->Enable (!video_sel.empty());
646                 _range->Enable (single && !video_sel.empty());
647         }
648
649         ContentList vc = _parent->selected_video ();
650         shared_ptr<Content> vcs;
651         if (!vc.empty ()) {
652                 vcs = vc.front ();
653         }
654
655         if (vcs && vcs->video->colour_conversion ()) {
656                 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
657         } else {
658                 _edit_colour_conversion_button->Enable (false);
659         }
660 }
661
662 void
663 VideoPanel::fade_in_changed ()
664 {
665         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
666                 double const vfr = i->active_video_frame_rate (_parent->film());
667                 i->video->set_fade_in (_fade_in->get(vfr).frames_round(vfr));
668         }
669 }
670
671 void
672 VideoPanel::fade_out_changed ()
673 {
674         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
675                 double const vfr = i->active_video_frame_rate (_parent->film());
676                 i->video->set_fade_out (_fade_out->get(vfr).frames_round(vfr));
677         }
678 }
679
680 void
681 VideoPanel::use_clicked ()
682 {
683         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
684                 i->video->set_use (_use->GetValue());
685         }
686 }
687
688 void
689 VideoPanel::reference_clicked ()
690 {
691         ContentList c = _parent->selected ();
692         if (c.size() != 1) {
693                 return;
694         }
695
696         shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
697         if (!d) {
698                 return;
699         }
700
701         d->set_reference_video (_reference->GetValue ());
702 }