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