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