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