Merge tag 'v2.16.79' into v2.17.x
[dcpomatic.git] / src / wx / video_panel.cc
1 /*
2     Copyright (C) 2012-2021 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
22 #include "check_box.h"
23 #include "content_colour_conversion_dialog.h"
24 #include "content_panel.h"
25 #include "content_widget.h"
26 #include "custom_scale_dialog.h"
27 #include "dcpomatic_button.h"
28 #include "filter_dialog.h"
29 #include "static_text.h"
30 #include "video_panel.h"
31 #include "wx_util.h"
32 #include "lib/colour_conversion.h"
33 #include "lib/config.h"
34 #include "lib/dcp_content.h"
35 #include "lib/ffmpeg_content.h"
36 #include "lib/film.h"
37 #include "lib/filter.h"
38 #include "lib/frame_rate_change.h"
39 #include "lib/ratio.h"
40 #include "lib/util.h"
41 #include "lib/video_content.h"
42 #include <dcp/warnings.h>
43 LIBDCP_DISABLE_WARNINGS
44 #include <wx/spinctrl.h>
45 #include <wx/tglbtn.h>
46 LIBDCP_ENABLE_WARNINGS
47 #include <boost/functional/hash.hpp>
48 #include <boost/unordered_set.hpp>
49 #include <set>
50 #include <iostream>
51
52
53 using std::vector;
54 using std::string;
55 using std::pair;
56 using std::cout;
57 using std::list;
58 using std::set;
59 using std::shared_ptr;
60 using std::dynamic_pointer_cast;
61 using boost::bind;
62 using boost::optional;
63 using namespace dcpomatic;
64 #if BOOST_VERSION >= 106100
65 using namespace boost::placeholders;
66 #endif
67
68
69 VideoPanel::VideoPanel (ContentPanel* p)
70         : ContentSubPanel (p, _("Video"))
71 {
72
73 }
74
75
76 void
77 VideoPanel::create ()
78 {
79         _type_label = create_label (this, _("Type"), true);
80         _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
81                 this,
82                 new wxChoice (this, wxID_ANY),
83                 VideoContentProperty::FRAME_TYPE,
84                 &Content::video,
85                 boost::mem_fn (&VideoContent::frame_type),
86                 boost::mem_fn (&VideoContent::set_frame_type),
87                 &caster<int, VideoFrameType>,
88                 &caster<VideoFrameType, int>
89                 );
90
91         _crop_label = create_label (this, _("Crop"), true);
92
93 #if defined(__WXGTK3__)
94         int const crop_width = 128;
95         int const link_width = 32;
96         int const link_height = 64;
97 #elif defined(__WXGTK20__)
98         int const crop_width = 56;
99         int const link_width = 24;
100         int const link_height = 32;
101 #elif defined(DCPOMATIC_OSX)
102         int const crop_width = 56;
103         int const link_width = 8 + 15 / dpi_scale_factor(this);
104         int const link_height = 28;
105 #else
106         int const crop_width = 56;
107         int const link_width = 22;
108         int const link_height = 28;
109 #endif
110
111         _left_crop_label = create_label (this, _("Left"), true);
112         _left_crop = new ContentSpinCtrl<VideoContent> (
113                 this,
114                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
115                 VideoContentProperty::CROP,
116                 &Content::video,
117                 boost::mem_fn (&VideoContent::requested_left_crop),
118                 boost::mem_fn (&VideoContent::set_left_crop),
119                 boost::bind (&VideoPanel::left_crop_changed, this)
120                 );
121
122         auto const link_path = bitmap_path(gui_is_dark() ? "link_white.png" : "link_black.png");
123
124         _left_right_link = new wxToggleButton (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(link_width, link_height));
125         _left_right_link->SetBitmap(wxBitmap(link_path, wxBITMAP_TYPE_PNG));
126
127         _right_crop_label = create_label (this, _("Right"), true);
128         _right_crop = new ContentSpinCtrl<VideoContent> (
129                 this,
130                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
131                 VideoContentProperty::CROP,
132                 &Content::video,
133                 boost::mem_fn (&VideoContent::requested_right_crop),
134                 boost::mem_fn (&VideoContent::set_right_crop),
135                 boost::bind (&VideoPanel::right_crop_changed, this)
136                 );
137
138         _top_crop_label = create_label (this, _("Top"), true);
139         _top_crop = new ContentSpinCtrl<VideoContent> (
140                 this,
141                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
142                 VideoContentProperty::CROP,
143                 &Content::video,
144                 boost::mem_fn (&VideoContent::requested_top_crop),
145                 boost::mem_fn (&VideoContent::set_top_crop),
146                 boost::bind (&VideoPanel::top_crop_changed, this)
147                 );
148
149         _top_bottom_link = new wxToggleButton (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(link_width, link_height));
150         _top_bottom_link->SetBitmap(wxBitmap(link_path, wxBITMAP_TYPE_PNG));
151
152         _bottom_crop_label = create_label (this, _("Bottom"), true);
153         _bottom_crop = new ContentSpinCtrl<VideoContent> (
154                 this,
155                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
156                 VideoContentProperty::CROP,
157                 &Content::video,
158                 boost::mem_fn (&VideoContent::requested_bottom_crop),
159                 boost::mem_fn (&VideoContent::set_bottom_crop),
160                 boost::bind (&VideoPanel::bottom_crop_changed, this)
161                 );
162
163         _fade_in_label = create_label (this, _("Fade in"), true);
164         _fade_in = new Timecode<ContentTime> (this);
165
166         _fade_out_label = create_label (this, _("Fade out"), true);
167         _fade_out = new Timecode<ContentTime> (this);
168
169         wxClientDC dc (this);
170         auto size = dc.GetTextExtent (wxT ("A quite long name"));
171 #ifdef __WXGTK3__
172         size.SetWidth (size.GetWidth() + 64);
173 #endif
174         size.SetHeight (-1);
175
176         _scale_label = create_label (this, _("Scale"), true);
177         _scale_fit = new wxRadioButton (this, wxID_ANY, _("to fit DCP"));
178         _scale_custom = new wxRadioButton (this, wxID_ANY, _("custom"));
179         _scale_custom_edit = new Button (this, _("Edit..."), wxDefaultPosition, small_button_size(this, _("Edit...")));
180
181         _colour_conversion_label = create_label (this, _("Colour"), true);
182         _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
183         _colour_conversion->Append (_("None"));
184         for (auto const& i: PresetColourConversion::all()) {
185                 _colour_conversion->Append (std_to_wx (i.name));
186         }
187
188         /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
189         _colour_conversion->Append (S_("Colour|Custom"));
190         _edit_colour_conversion_button = new Button (this, _("Edit..."), wxDefaultPosition, small_button_size(this, _("Edit...")));
191
192         _range_label = create_label (this, _("Range"), true);
193         _range = new wxChoice (this, wxID_ANY);
194         _range->Append (_("Full (JPEG, 0-255)"));
195         _range->Append (_("Video (MPEG, 16-235)"));
196
197         _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
198         auto font = _description->GetFont();
199         font.SetStyle(wxFONTSTYLE_ITALIC);
200         font.SetPointSize(font.GetPointSize() - 1);
201         _description->SetFont(font);
202
203         _left_crop->wrapped()->SetRange (0, 4096);
204         _top_crop->wrapped()->SetRange (0, 4096);
205         _right_crop->wrapped()->SetRange (0, 4096);
206         _bottom_crop->wrapped()->SetRange (0, 4096);
207
208         _frame_type->wrapped()->Append (_("2D"));
209         _frame_type->wrapped()->Append (_("3D"));
210         _frame_type->wrapped()->Append (_("3D left/right"));
211         _frame_type->wrapped()->Append (_("3D top/bottom"));
212         _frame_type->wrapped()->Append (_("3D alternate"));
213         _frame_type->wrapped()->Append (_("3D left only"));
214         _frame_type->wrapped()->Append (_("3D right only"));
215
216         content_selection_changed ();
217
218         _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
219         _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
220
221         _scale_fit->Bind                     (wxEVT_RADIOBUTTON, boost::bind (&VideoPanel::scale_fit_clicked, this));
222         _scale_custom->Bind                  (wxEVT_RADIOBUTTON, boost::bind (&VideoPanel::scale_custom_clicked, this));
223         _scale_custom_edit->Bind             (wxEVT_BUTTON,   boost::bind (&VideoPanel::scale_custom_edit_clicked, this));
224         _colour_conversion->Bind             (wxEVT_CHOICE,   boost::bind (&VideoPanel::colour_conversion_changed, this));
225         _range->Bind                         (wxEVT_CHOICE,   boost::bind (&VideoPanel::range_changed, this));
226         _edit_colour_conversion_button->Bind (wxEVT_BUTTON,   boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
227         _left_right_link->Bind               (wxEVT_TOGGLEBUTTON, boost::bind(&VideoPanel::left_right_link_clicked, this));
228         _top_bottom_link->Bind               (wxEVT_TOGGLEBUTTON, boost::bind(&VideoPanel::top_bottom_link_clicked, this));
229
230         add_to_grid ();
231
232         _sizer->Layout ();
233 }
234
235
236 void
237 VideoPanel::add_to_grid ()
238 {
239         int r = 0;
240
241         add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
242         _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
243         ++r;
244
245         int cr = 0;
246         auto crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
247
248         add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
249         _left_crop->add (crop, wxGBPosition(cr, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
250 #ifdef __WXGTK3__
251         crop->Add (_left_right_link, wxGBPosition(cr, 2), wxGBSpan(2, 1));
252         ++cr;
253         add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition(cr, 0));
254         _right_crop->add (crop, wxGBPosition(cr, 1));
255 #else
256         crop->Add (_left_right_link, wxGBPosition(cr, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
257         add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 3));
258         _right_crop->add (crop, wxGBPosition (cr, 4), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
259 #endif
260         ++cr;
261         add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
262         _top_crop->add (crop, wxGBPosition (cr, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
263 #ifdef __WXGTK3__
264         crop->Add (_top_bottom_link, wxGBPosition(cr, 2), wxGBSpan(2, 1));
265         ++cr;
266         add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition(cr, 0));
267         _bottom_crop->add (crop, wxGBPosition(cr, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
268 #else
269         crop->Add (_top_bottom_link, wxGBPosition(cr, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
270         add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 3));
271         _bottom_crop->add (crop, wxGBPosition (cr, 4), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
272 #endif
273         add_label_to_sizer (_grid, _crop_label, true, wxGBPosition(r, 0));
274         _grid->Add (crop, wxGBPosition(r, 1));
275         ++r;
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         add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
286         {
287                 auto v = new wxBoxSizer (wxVERTICAL);
288                 v->Add (_scale_fit, 0, wxBOTTOM, 4);
289                 auto h = new wxBoxSizer (wxHORIZONTAL);
290                 h->Add (_scale_custom, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 6);
291                 h->Add (_scale_custom_edit, 0, wxALIGN_CENTER_VERTICAL);
292                 v->Add (h, 0);
293                 _grid->Add (v, wxGBPosition(r, 1));
294         }
295         ++r;
296
297         add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
298         {
299                 auto s = new wxBoxSizer (wxHORIZONTAL);
300                 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
301                 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
302                 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
303         }
304         ++r;
305
306         add_label_to_sizer (_grid, _range_label, true, wxGBPosition(r, 0));
307         _grid->Add (_range, wxGBPosition(r, 1), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL);
308         ++r;
309
310         _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
311         ++r;
312 }
313
314
315 void
316 VideoPanel::range_changed ()
317 {
318         auto vc = _parent->selected_video ();
319         if (vc.size() != 1) {
320                 return;
321         }
322
323         switch (_range->GetSelection()) {
324         case 0:
325                 vc.front()->video->set_range (VideoRange::FULL);
326                 break;
327         case 1:
328                 vc.front()->video->set_range (VideoRange::VIDEO);
329                 break;
330         default:
331                 DCPOMATIC_ASSERT (false);
332         }
333 }
334
335
336 void
337 VideoPanel::film_changed(FilmProperty property)
338 {
339         switch (property) {
340         case FilmProperty::VIDEO_FRAME_RATE:
341         case FilmProperty::CONTAINER:
342         case FilmProperty::RESOLUTION:
343                 setup_description ();
344                 setup_sensitivity ();
345                 break;
346         case FilmProperty::REEL_TYPE:
347         case FilmProperty::INTEROP:
348                 setup_sensitivity ();
349                 break;
350         default:
351                 break;
352         }
353 }
354
355
356 std::size_t
357 hash_value (boost::optional<ColourConversion> const & c)
358 {
359         boost::hash<string> hasher;
360         if (!c) {
361                 return hasher ("none");
362         }
363         return hasher (c->identifier());
364 }
365
366
367 void
368 VideoPanel::film_content_changed (int property)
369 {
370         auto vc = _parent->selected_video ();
371         shared_ptr<Content> vcs;
372         shared_ptr<FFmpegContent> fcs;
373         if (!vc.empty()) {
374                 vcs = vc.front ();
375                 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
376         }
377
378         if (property == ContentProperty::VIDEO_FRAME_RATE ||
379             property == VideoContentProperty::FRAME_TYPE ||
380             property == VideoContentProperty::CROP ||
381             property == VideoContentProperty::CUSTOM_RATIO ||
382             property == VideoContentProperty::CUSTOM_SIZE) {
383                 setup_description ();
384         } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
385                 boost::unordered_set<optional<ColourConversion>> check;
386                 for (auto 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                 auto 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                                 auto 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 == VideoContentProperty::USE) {
420                 setup_sensitivity ();
421         } else if (property == VideoContentProperty::FADE_IN) {
422                 set<Frame> check;
423                 for (auto i: vc) {
424                         check.insert (i->video->fade_in ());
425                 }
426
427                 if (check.size() == 1) {
428                         _fade_in->set (
429                                 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
430                                 vc.front()->active_video_frame_rate(_parent->film())
431                                 );
432                 } else {
433                         _fade_in->clear ();
434                 }
435         } else if (property == VideoContentProperty::FADE_OUT) {
436                 set<Frame> check;
437                 for (auto i: vc) {
438                         check.insert (i->video->fade_out ());
439                 }
440
441                 if (check.size() == 1) {
442                         _fade_out->set (
443                                 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
444                                 vc.front()->active_video_frame_rate(_parent->film())
445                                 );
446                 } else {
447                         _fade_out->clear ();
448                 }
449         } else if (property == VideoContentProperty::RANGE) {
450                 if (vcs) {
451                         checked_set (_range, vcs->video->range() == VideoRange::FULL ? 0 : 1);
452                 } else {
453                         checked_set (_range, 0);
454                 }
455
456                 setup_sensitivity ();
457         } else if (property == VideoContentProperty::CUSTOM_RATIO || property == VideoContentProperty::CUSTOM_SIZE) {
458                 set<Frame> check;
459                 for (auto i: vc) {
460                         check.insert (i->video->custom_ratio() || i->video->custom_size());
461                 }
462
463                 if (check.size() == 1) {
464                         checked_set (_scale_fit, !vc.front()->video->custom_ratio() && !vc.front()->video->custom_size());
465                         checked_set (_scale_custom, vc.front()->video->custom_ratio() || vc.front()->video->custom_size());
466                 } else {
467                         checked_set (_scale_fit, true);
468                         checked_set (_scale_custom, false);
469                 }
470                 setup_sensitivity ();
471         }
472 }
473
474
475 void
476 VideoPanel::setup_description ()
477 {
478         auto vc = _parent->selected_video ();
479         if (vc.empty ()) {
480                 checked_set (_description, wxT (""));
481                 return;
482         } else if (vc.size() > 1) {
483                 checked_set (_description, _("Multiple content selected"));
484                 return;
485         }
486
487         auto d = vc.front()->video->processing_description(_parent->film());
488         size_t lines = count (d.begin(), d.end(), '\n');
489
490         for (int i = lines; i < 6; ++i) {
491                 d += "\n ";
492         }
493
494         checked_set (_description, d);
495         layout ();
496 }
497
498
499 void
500 VideoPanel::colour_conversion_changed ()
501 {
502         auto vc = _parent->selected_video ();
503
504         int const s = _colour_conversion->GetSelection ();
505         auto all = PresetColourConversion::all ();
506
507         if (s == int(all.size() + 1)) {
508                 edit_colour_conversion_clicked ();
509         } else {
510                 for (auto i: _parent->selected_video()) {
511                         if (s == 0) {
512                                 i->video->unset_colour_conversion ();
513                         } else if (s != int(all.size() + 2)) {
514                                 i->video->set_colour_conversion (all[s - 1].conversion);
515                         }
516                 }
517         }
518 }
519
520
521 void
522 VideoPanel::edit_colour_conversion_clicked ()
523 {
524         auto vc = _parent->selected_video ();
525
526         ContentColourConversionDialog dialog(this, vc.front()->video->yuv());
527         dialog.set(vc.front()->video->colour_conversion().get_value_or(PresetColourConversion::all().front().conversion));
528         if (dialog.ShowModal() == wxID_OK) {
529                 for (auto i: vc) {
530                         i->video->set_colour_conversion(dialog.get());
531                 }
532         } else {
533                 /* Reset the colour conversion choice */
534                 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
535         }
536 }
537
538
539 void
540 VideoPanel::content_selection_changed ()
541 {
542         auto video_sel = _parent->selected_video ();
543
544         _frame_type->set_content (video_sel);
545         _left_crop->set_content (video_sel);
546         _right_crop->set_content (video_sel);
547         _top_crop->set_content (video_sel);
548         _bottom_crop->set_content (video_sel);
549
550         film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
551         film_content_changed (VideoContentProperty::CROP);
552         film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
553         film_content_changed (VideoContentProperty::FADE_IN);
554         film_content_changed (VideoContentProperty::FADE_OUT);
555         film_content_changed (VideoContentProperty::RANGE);
556         film_content_changed (VideoContentProperty::USE);
557         film_content_changed (VideoContentProperty::CUSTOM_RATIO);
558         film_content_changed (VideoContentProperty::CUSTOM_SIZE);
559         film_content_changed (FFmpegContentProperty::FILTERS);
560         film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
561
562         setup_sensitivity ();
563 }
564
565
566 void
567 VideoPanel::setup_sensitivity ()
568 {
569         auto sel = _parent->selected ();
570
571         shared_ptr<DCPContent> dcp;
572         if (sel.size() == 1) {
573                 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
574         }
575
576         bool const reference = dcp && dcp->reference_video();
577
578         bool any_use = false;
579         for (auto i: _parent->selected_video()) {
580                 if (i->video && i->video->use()) {
581                         any_use = true;
582                 }
583         }
584
585         bool const enable = !reference && any_use;
586
587         if (!enable) {
588                 _frame_type->wrapped()->Enable (false);
589                 _left_crop->wrapped()->Enable (false);
590                 _right_crop->wrapped()->Enable (false);
591                 _top_crop->wrapped()->Enable (false);
592                 _bottom_crop->wrapped()->Enable (false);
593                 _fade_in->Enable (false);
594                 _fade_out->Enable (false);
595                 _scale_fit->Enable (false);
596                 _scale_custom->Enable (false);
597                 _scale_custom_edit->Enable (false);
598                 _description->Enable (false);
599                 _colour_conversion->Enable (false);
600                 _range->Enable (false);
601         } else {
602                 auto video_sel = _parent->selected_video ();
603                 auto ffmpeg_sel = _parent->selected_ffmpeg ();
604                 bool const single = video_sel.size() == 1;
605
606                 _frame_type->wrapped()->Enable (true);
607                 _left_crop->wrapped()->Enable (true);
608                 _right_crop->wrapped()->Enable (true);
609                 _top_crop->wrapped()->Enable (true);
610                 _bottom_crop->wrapped()->Enable (true);
611                 _fade_in->Enable (!video_sel.empty ());
612                 _fade_out->Enable (!video_sel.empty ());
613                 _scale_fit->Enable (true);
614                 _scale_custom->Enable (true);
615                 _scale_custom_edit->Enable (_scale_custom->GetValue());
616                 _description->Enable (true);
617                 _colour_conversion->Enable (!video_sel.empty());
618                 _range->Enable (single && !video_sel.empty() && !dcp);
619         }
620
621         auto vc = _parent->selected_video ();
622         shared_ptr<Content> vcs;
623         if (!vc.empty ()) {
624                 vcs = vc.front ();
625         }
626
627         if (vcs && vcs->video->colour_conversion ()) {
628                 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
629         } else {
630                 _edit_colour_conversion_button->Enable (false);
631         }
632 }
633
634
635 void
636 VideoPanel::fade_in_changed ()
637 {
638         auto const hmsf = _fade_in->get();
639         for (auto i: _parent->selected_video()) {
640                 auto const vfr = i->active_video_frame_rate(_parent->film());
641                 i->video->set_fade_in (dcpomatic::ContentTime(hmsf, vfr).frames_round(vfr));
642         }
643 }
644
645
646 void
647 VideoPanel::fade_out_changed ()
648 {
649         auto const hmsf = _fade_out->get();
650         for (auto i: _parent->selected_video()) {
651                 auto const vfr = i->active_video_frame_rate (_parent->film());
652                 i->video->set_fade_out (dcpomatic::ContentTime(hmsf, vfr).frames_round(vfr));
653         }
654 }
655
656
657 void
658 VideoPanel::scale_fit_clicked ()
659 {
660         for (auto i: _parent->selected_video()) {
661                 i->video->set_custom_ratio (optional<float>());
662                 i->video->set_custom_size (optional<dcp::Size>());
663         }
664
665         setup_sensitivity ();
666 }
667
668
669 void
670 VideoPanel::scale_custom_clicked ()
671 {
672         if (!scale_custom_edit_clicked()) {
673                 _scale_fit->SetValue (true);
674         }
675
676         setup_sensitivity ();
677 }
678
679
680 bool
681 VideoPanel::scale_custom_edit_clicked ()
682 {
683         auto vc = _parent->selected_video().front()->video;
684         auto size = vc->size();
685         DCPOMATIC_ASSERT(size);
686
687         CustomScaleDialog dialog(this, *size, _parent->film()->frame_size(), vc->custom_ratio(), vc->custom_size());
688         if (dialog.ShowModal() != wxID_OK) {
689                 return false;
690         }
691
692         for (auto i: _parent->selected_video()) {
693                 i->video->set_custom_ratio(dialog.custom_ratio());
694                 i->video->set_custom_size(dialog.custom_size());
695         }
696
697         return true;
698 }
699
700
701 void
702 VideoPanel::left_right_link_clicked ()
703 {
704         if (_left_changed_last) {
705                 left_crop_changed ();
706         } else {
707                 right_crop_changed ();
708         }
709 }
710
711
712 void
713 VideoPanel::top_bottom_link_clicked ()
714 {
715         if (_top_changed_last) {
716                 top_crop_changed ();
717         } else {
718                 bottom_crop_changed ();
719         }
720 }
721
722
723 void
724 VideoPanel::left_crop_changed ()
725 {
726         _left_changed_last = true;
727         if (_left_right_link->GetValue()) {
728                 for (auto const& i: _parent->selected_video()) {
729                         i->video->set_right_crop (i->video->requested_left_crop());
730                 }
731         }
732 }
733
734
735 void
736 VideoPanel::right_crop_changed ()
737 {
738         _left_changed_last = false;
739         if (_left_right_link->GetValue()) {
740                 for (auto const& i: _parent->selected_video()) {
741                         i->video->set_left_crop (i->video->requested_right_crop());
742                 }
743         }
744 }
745
746
747 void
748 VideoPanel::top_crop_changed ()
749 {
750         _top_changed_last = true;
751         if (_top_bottom_link->GetValue()) {
752                 for (auto i: _parent->selected_video()) {
753                         i->video->set_bottom_crop (i->video->requested_top_crop());
754                 }
755         }
756 }
757
758
759 void
760 VideoPanel::bottom_crop_changed ()
761 {
762         _top_changed_last = false;
763         if (_top_bottom_link->GetValue()) {
764                 for (auto i: _parent->selected_video()) {
765                         i->video->set_top_crop (i->video->requested_bottom_crop());
766                 }
767         }
768 }
769
770