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