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