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