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