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