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