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