24099e1ccd97ed2b524ce31a9bc20490542e4e25
[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         _use = new wxCheckBox (this, wxID_ANY, _("Use"));
73
74         _type_label = create_label (this, _("Type"), true);
75         _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
76                 this,
77                 new wxChoice (this, wxID_ANY),
78                 VideoContentProperty::FRAME_TYPE,
79                 &Content::video,
80                 boost::mem_fn (&VideoContent::frame_type),
81                 boost::mem_fn (&VideoContent::set_frame_type),
82                 &caster<int, VideoFrameType>,
83                 &caster<VideoFrameType, int>
84                 );
85
86         _crop_label = create_label (this, _("Crop"), true);
87
88         int const crop_width = 56;
89         int const link_height = 28;
90
91         _left_crop_label = create_label (this, _("Left"), true);
92         _left_crop = new ContentSpinCtrl<VideoContent> (
93                 this,
94                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
95                 VideoContentProperty::CROP,
96                 &Content::video,
97                 boost::mem_fn (&VideoContent::left_crop),
98                 boost::mem_fn (&VideoContent::set_left_crop),
99                 boost::bind (&VideoPanel::left_crop_changed, this)
100                 );
101
102         _left_right_link = new wxToggleButton (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(22, link_height));
103         _left_right_link->SetBitmap (wxBitmap(bitmap_path("link"), wxBITMAP_TYPE_PNG));
104
105         _right_crop_label = create_label (this, _("Right"), true);
106         _right_crop = new ContentSpinCtrl<VideoContent> (
107                 this,
108                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
109                 VideoContentProperty::CROP,
110                 &Content::video,
111                 boost::mem_fn (&VideoContent::right_crop),
112                 boost::mem_fn (&VideoContent::set_right_crop),
113                 boost::bind (&VideoPanel::right_crop_changed, this)
114                 );
115
116         _top_crop_label = create_label (this, _("Top"), true);
117         _top_crop = new ContentSpinCtrl<VideoContent> (
118                 this,
119                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
120                 VideoContentProperty::CROP,
121                 &Content::video,
122                 boost::mem_fn (&VideoContent::top_crop),
123                 boost::mem_fn (&VideoContent::set_top_crop),
124                 boost::bind (&VideoPanel::top_crop_changed, this)
125                 );
126
127         _top_bottom_link = new wxToggleButton (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(22, link_height));
128         _top_bottom_link->SetBitmap (wxBitmap(bitmap_path("link"), wxBITMAP_TYPE_PNG));
129
130         _bottom_crop_label = create_label (this, _("Bottom"), true);
131         _bottom_crop = new ContentSpinCtrl<VideoContent> (
132                 this,
133                 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(crop_width, -1)),
134                 VideoContentProperty::CROP,
135                 &Content::video,
136                 boost::mem_fn (&VideoContent::bottom_crop),
137                 boost::mem_fn (&VideoContent::set_bottom_crop),
138                 boost::bind (&VideoPanel::bottom_crop_changed, this)
139                 );
140
141         _fade_in_label = create_label (this, _("Fade in"), true);
142         _fade_in = new Timecode<ContentTime> (this);
143
144         _fade_out_label = create_label (this, _("Fade out"), true);
145         _fade_out = new Timecode<ContentTime> (this);
146
147         wxClientDC dc (this);
148         wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
149         size.SetHeight (-1);
150
151         _scale_label = create_label (this, _("Scale"), true);
152         _scale_fit = new wxRadioButton (this, wxID_ANY, _("to fit DCP"));
153         _scale_custom = new wxRadioButton (this, wxID_ANY, _("custom"), wxDefaultPosition, size);
154         _scale_custom_edit = new Button (this, _("Edit..."));
155
156         _filters_label = create_label (this, _("Filters"), true);
157         _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
158         _filters_button = new Button (this, _("Edit..."));
159
160         _colour_conversion_label = create_label (this, _("Colour conversion"), true);
161         _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
162         _colour_conversion->Append (_("None"));
163         BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
164                 _colour_conversion->Append (std_to_wx (i.name));
165         }
166
167         /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
168         _colour_conversion->Append (S_("Colour|Custom"));
169         _edit_colour_conversion_button = new Button (this, _("Edit..."));
170
171         _range_label = create_label (this, _("Range"), true);
172         _range = new wxChoice (this, wxID_ANY);
173         _range->Append (_("Full (JPEG, 0-255)"));
174         _range->Append (_("Video (MPEG, 16-235)"));
175
176         _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
177         _description->SetFont(font);
178
179         _left_crop->wrapped()->SetRange (0, 4096);
180         _top_crop->wrapped()->SetRange (0, 4096);
181         _right_crop->wrapped()->SetRange (0, 4096);
182         _bottom_crop->wrapped()->SetRange (0, 4096);
183
184         _frame_type->wrapped()->Append (_("2D"));
185         _frame_type->wrapped()->Append (_("3D"));
186         _frame_type->wrapped()->Append (_("3D left/right"));
187         _frame_type->wrapped()->Append (_("3D top/bottom"));
188         _frame_type->wrapped()->Append (_("3D alternate"));
189         _frame_type->wrapped()->Append (_("3D left only"));
190         _frame_type->wrapped()->Append (_("3D right only"));
191
192         content_selection_changed ();
193
194         _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
195         _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
196
197         _use->Bind                           (wxEVT_CHECKBOX, boost::bind (&VideoPanel::use_clicked, this));
198         _reference->Bind                     (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
199         _filters_button->Bind                (wxEVT_BUTTON,   boost::bind (&VideoPanel::edit_filters_clicked, this));
200         _scale_fit->Bind                     (wxEVT_RADIOBUTTON, boost::bind (&VideoPanel::scale_fit_clicked, this));
201         _scale_custom->Bind                  (wxEVT_RADIOBUTTON, boost::bind (&VideoPanel::scale_custom_clicked, this));
202         _scale_custom_edit->Bind             (wxEVT_BUTTON,   boost::bind (&VideoPanel::scale_custom_edit_clicked, this));
203         _colour_conversion->Bind             (wxEVT_CHOICE,   boost::bind (&VideoPanel::colour_conversion_changed, this));
204         _range->Bind                         (wxEVT_CHOICE,   boost::bind (&VideoPanel::range_changed, this));
205         _edit_colour_conversion_button->Bind (wxEVT_BUTTON,   boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
206         _left_right_link->Bind               (wxEVT_TOGGLEBUTTON, boost::bind(&VideoPanel::left_right_link_clicked, this));
207         _top_bottom_link->Bind               (wxEVT_TOGGLEBUTTON, boost::bind(&VideoPanel::top_bottom_link_clicked, this));
208
209         add_to_grid ();
210 }
211
212 void
213 VideoPanel::add_to_grid ()
214 {
215         bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
216
217         int r = 0;
218
219         _reference->Show (full);
220         _reference_note->Show (full && !_reference_note->GetLabel().IsEmpty());
221
222         if (full) {
223                 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
224                 reference_sizer->Add (_reference, 0);
225                 reference_sizer->Add (_reference_note, 0);
226                 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
227                 ++r;
228         }
229
230         _use->Show (full);
231         _grid->Add (_use, wxGBPosition(r, 0), wxGBSpan(1, 2));
232         ++r;
233
234         add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
235         _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
236         ++r;
237
238         int cr = 0;
239         wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
240         add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
241         _left_crop->add (crop, wxGBPosition (cr, 1));
242         crop->Add (_left_right_link, wxGBPosition(cr, 2));
243         add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 3));
244         _right_crop->add (crop, wxGBPosition (cr, 4));
245         ++cr;
246         add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
247         _top_crop->add (crop, wxGBPosition (cr, 1));
248         crop->Add (_top_bottom_link, wxGBPosition(cr, 2));
249         add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 3));
250         _bottom_crop->add (crop, wxGBPosition (cr, 4));
251         add_label_to_sizer (_grid, _crop_label, true, wxGBPosition(r, 0));
252         _grid->Add (crop, wxGBPosition(r, 1));
253         ++r;
254
255         _scale_label->Show (full);
256         _scale_fit->Show (full);
257         _scale_custom->Show (full);
258         _scale_custom_edit->Show (full);
259         _filters_label->Show (full);
260         _filters->Show (full);
261         _filters_button->Show (full);
262         _colour_conversion_label->Show (full);
263         _colour_conversion->Show (full);
264         _edit_colour_conversion_button->Show (full);
265         _range_label->Show (full);
266         _range->Show (full);
267
268         add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
269         _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
270         ++r;
271
272         add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
273         _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
274         ++r;
275
276         if (full) {
277                 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
278                 {
279                         wxSizer* v = new wxBoxSizer (wxVERTICAL);
280                         v->Add (_scale_fit, 0, wxBOTTOM, 4);
281                         wxSizer* h = new wxBoxSizer (wxHORIZONTAL);
282                         h->Add (_scale_custom, 1, wxRIGHT, 6);
283                         h->Add (_scale_custom_edit, 0);
284                         v->Add (h, 0);
285                         _grid->Add (v, wxGBPosition(r, 1));
286                 }
287                 ++r;
288
289                 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
290                 {
291                         wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
292                         s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
293                         s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
294                         _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
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 == FFmpegContentProperty::FILTERS) {
419                 if (fcs) {
420                         string p = Filter::ffmpeg_string (fcs->filters ());
421                         if (p.empty ()) {
422                                 checked_set (_filters, _("None"));
423                         } else {
424                                 if (p.length() > 25) {
425                                         p = p.substr (0, 25) + "...";
426                                 }
427                                 checked_set (_filters, p);
428                         }
429                 }
430         } else if (property == VideoContentProperty::USE) {
431                 set<bool> check;
432                 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
433                         check.insert (i->video->use());
434                 }
435
436                 if (check.size() == 1) {
437                         checked_set (_use, vc.front()->video->use());
438                 } else {
439                         checked_set (_use, false);
440                 }
441
442                 setup_sensitivity ();
443         } else if (property == VideoContentProperty::FADE_IN) {
444                 set<Frame> check;
445                 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
446                         check.insert (i->video->fade_in ());
447                 }
448
449                 if (check.size() == 1) {
450                         _fade_in->set (
451                                 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
452                                 vc.front()->active_video_frame_rate(_parent->film())
453                                 );
454                 } else {
455                         _fade_in->clear ();
456                 }
457         } else if (property == VideoContentProperty::FADE_OUT) {
458                 set<Frame> check;
459                 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
460                         check.insert (i->video->fade_out ());
461                 }
462
463                 if (check.size() == 1) {
464                         _fade_out->set (
465                                 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
466                                 vc.front()->active_video_frame_rate(_parent->film())
467                                 );
468                 } else {
469                         _fade_out->clear ();
470                 }
471         } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
472                 if (vc.size() == 1) {
473                         shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
474                         checked_set (_reference, dcp ? dcp->reference_video () : false);
475                 } else {
476                         checked_set (_reference, false);
477                 }
478
479                 setup_sensitivity ();
480         } else if (property == VideoContentProperty::RANGE) {
481                 if (vcs) {
482                         checked_set (_range, vcs->video->range() == VIDEO_RANGE_FULL ? 0 : 1);
483                 } else {
484                         checked_set (_range, 0);
485                 }
486
487                 setup_sensitivity ();
488         } else if (property == VideoContentProperty::CUSTOM_RATIO || property == VideoContentProperty::CUSTOM_SIZE) {
489                 set<Frame> check;
490                 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
491                         check.insert (i->video->custom_ratio() || i->video->custom_size());
492                 }
493
494                 if (check.size() == 1) {
495                         checked_set (_scale_fit, !vc.front()->video->custom_ratio() && !vc.front()->video->custom_size());
496                         checked_set (_scale_custom, vc.front()->video->custom_ratio() || vc.front()->video->custom_size());
497                 } else {
498                         checked_set (_scale_fit, true);
499                         checked_set (_scale_custom, false);
500                 }
501                 setup_sensitivity ();
502         }
503 }
504
505 /** Called when the `Edit filters' button has been clicked */
506 void
507 VideoPanel::edit_filters_clicked ()
508 {
509         FFmpegContentList c = _parent->selected_ffmpeg ();
510         if (c.size() != 1) {
511                 return;
512         }
513
514         FilterDialog* d = new FilterDialog (this, c.front()->filters());
515         d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
516         d->ShowModal ();
517         d->Destroy ();
518 }
519
520 void
521 VideoPanel::setup_description ()
522 {
523         ContentList vc = _parent->selected_video ();
524         if (vc.empty ()) {
525                 checked_set (_description, wxT (""));
526                 return;
527         } else if (vc.size() > 1) {
528                 checked_set (_description, _("Multiple content selected"));
529                 return;
530         }
531
532         string d = vc.front()->video->processing_description (_parent->film());
533         size_t lines = count (d.begin(), d.end(), '\n');
534
535         for (int i = lines; i < 6; ++i) {
536                 d += "\n ";
537         }
538
539         checked_set (_description, d);
540         _sizer->Layout ();
541 }
542
543 void
544 VideoPanel::colour_conversion_changed ()
545 {
546         ContentList vc = _parent->selected_video ();
547
548         int const s = _colour_conversion->GetSelection ();
549         vector<PresetColourConversion> all = PresetColourConversion::all ();
550
551         if (s == int(all.size() + 1)) {
552                 edit_colour_conversion_clicked ();
553         } else {
554                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
555                         if (s == 0) {
556                                 i->video->unset_colour_conversion ();
557                         } else if (s != int(all.size() + 2)) {
558                                 i->video->set_colour_conversion (all[s - 1].conversion);
559                         }
560                 }
561         }
562 }
563
564 void
565 VideoPanel::edit_colour_conversion_clicked ()
566 {
567         ContentList vc = _parent->selected_video ();
568
569         ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
570         d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
571         if (d->ShowModal() == wxID_OK) {
572                 BOOST_FOREACH (shared_ptr<Content> i, vc) {
573                         i->video->set_colour_conversion (d->get ());
574                 }
575         } else {
576                 /* Reset the colour conversion choice */
577                 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
578         }
579         d->Destroy ();
580 }
581
582 void
583 VideoPanel::content_selection_changed ()
584 {
585         ContentList video_sel = _parent->selected_video ();
586
587         _frame_type->set_content (video_sel);
588         _left_crop->set_content (video_sel);
589         _right_crop->set_content (video_sel);
590         _top_crop->set_content (video_sel);
591         _bottom_crop->set_content (video_sel);
592
593         film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
594         film_content_changed (VideoContentProperty::CROP);
595         film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
596         film_content_changed (VideoContentProperty::FADE_IN);
597         film_content_changed (VideoContentProperty::FADE_OUT);
598         film_content_changed (VideoContentProperty::RANGE);
599         film_content_changed (VideoContentProperty::USE);
600         film_content_changed (VideoContentProperty::CUSTOM_RATIO);
601         film_content_changed (VideoContentProperty::CUSTOM_SIZE);
602         film_content_changed (FFmpegContentProperty::FILTERS);
603         film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
604
605         setup_sensitivity ();
606 }
607
608 void
609 VideoPanel::setup_sensitivity ()
610 {
611         ContentList sel = _parent->selected ();
612
613         shared_ptr<DCPContent> dcp;
614         if (sel.size() == 1) {
615                 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
616         }
617
618         string why_not;
619         bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
620         wxString cannot;
621         if (why_not.empty()) {
622                 cannot = _("Cannot reference this DCP's video.");
623         } else {
624                 cannot = _("Cannot reference this DCP's video: ") + std_to_wx(why_not);
625         }
626         setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
627
628         bool const enable = !_reference->GetValue() && _use->GetValue();
629
630         _use->Enable (!_reference->GetValue());
631
632         if (!enable) {
633                 _frame_type->wrapped()->Enable (false);
634                 _left_crop->wrapped()->Enable (false);
635                 _right_crop->wrapped()->Enable (false);
636                 _top_crop->wrapped()->Enable (false);
637                 _bottom_crop->wrapped()->Enable (false);
638                 _fade_in->Enable (false);
639                 _fade_out->Enable (false);
640                 _scale_fit->Enable (false);
641                 _scale_custom->Enable (false);
642                 _scale_custom_edit->Enable (false);
643                 _description->Enable (false);
644                 _filters->Enable (false);
645                 _filters_button->Enable (false);
646                 _colour_conversion->Enable (false);
647                 _range->Enable (false);
648         } else {
649                 ContentList video_sel = _parent->selected_video ();
650                 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
651                 bool const single = video_sel.size() == 1;
652
653                 _frame_type->wrapped()->Enable (true);
654                 _left_crop->wrapped()->Enable (true);
655                 _right_crop->wrapped()->Enable (true);
656                 _top_crop->wrapped()->Enable (true);
657                 _bottom_crop->wrapped()->Enable (true);
658                 _fade_in->Enable (!video_sel.empty ());
659                 _fade_out->Enable (!video_sel.empty ());
660                 _scale_fit->Enable (true);
661                 _scale_custom->Enable (true);
662                 _scale_custom_edit->Enable (_scale_custom->GetValue());
663                 _description->Enable (true);
664                 _filters->Enable (true);
665                 _filters_button->Enable (single && !ffmpeg_sel.empty ());
666                 _colour_conversion->Enable (!video_sel.empty());
667                 _range->Enable (single && !video_sel.empty());
668         }
669
670         ContentList vc = _parent->selected_video ();
671         shared_ptr<Content> vcs;
672         if (!vc.empty ()) {
673                 vcs = vc.front ();
674         }
675
676         if (vcs && vcs->video->colour_conversion ()) {
677                 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
678         } else {
679                 _edit_colour_conversion_button->Enable (false);
680         }
681 }
682
683 void
684 VideoPanel::fade_in_changed ()
685 {
686         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
687                 double const vfr = i->active_video_frame_rate (_parent->film());
688                 i->video->set_fade_in (_fade_in->get(vfr).frames_round(vfr));
689         }
690 }
691
692 void
693 VideoPanel::fade_out_changed ()
694 {
695         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
696                 double const vfr = i->active_video_frame_rate (_parent->film());
697                 i->video->set_fade_out (_fade_out->get(vfr).frames_round(vfr));
698         }
699 }
700
701 void
702 VideoPanel::use_clicked ()
703 {
704         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
705                 i->video->set_use (_use->GetValue());
706         }
707 }
708
709 void
710 VideoPanel::reference_clicked ()
711 {
712         ContentList c = _parent->selected ();
713         if (c.size() != 1) {
714                 return;
715         }
716
717         shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
718         if (!d) {
719                 return;
720         }
721
722         d->set_reference_video (_reference->GetValue ());
723 }
724
725
726 void
727 VideoPanel::scale_fit_clicked ()
728 {
729         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
730                 i->video->set_custom_ratio (optional<float>());
731         }
732 }
733
734
735 void
736 VideoPanel::scale_custom_clicked ()
737 {
738         if (!scale_custom_edit_clicked()) {
739                 _scale_fit->SetValue (true);
740         }
741 }
742
743
744 bool
745 VideoPanel::scale_custom_edit_clicked ()
746 {
747         shared_ptr<const VideoContent> vc = _parent->selected_video().front()->video;
748         CustomScaleDialog* d = new CustomScaleDialog (this, vc->size(), _parent->film()->frame_size(), vc->custom_ratio(), vc->custom_size());
749         int const r = d->ShowModal ();
750         if (r == wxID_OK) {
751                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
752                         i->video->set_custom_ratio (d->custom_ratio());
753                         i->video->set_custom_size (d->custom_size());
754                 }
755         }
756         d->Destroy ();
757         return r == wxID_OK;
758 }
759
760
761 void
762 VideoPanel::left_right_link_clicked ()
763 {
764         right_crop_changed ();
765 }
766
767
768 void
769 VideoPanel::top_bottom_link_clicked ()
770 {
771         bottom_crop_changed ();
772 }
773
774
775 void
776 VideoPanel::left_crop_changed ()
777 {
778         if (_left_right_link->GetValue()) {
779                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
780                         i->video->set_right_crop (i->video->left_crop());
781                 }
782         }
783 }
784
785
786 void
787 VideoPanel::right_crop_changed ()
788 {
789         if (_left_right_link->GetValue()) {
790                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
791                         i->video->set_left_crop (i->video->right_crop());
792                 }
793         }
794 }
795
796
797 void
798 VideoPanel::top_crop_changed ()
799 {
800         if (_top_bottom_link->GetValue()) {
801                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
802                         i->video->set_bottom_crop (i->video->top_crop());
803                 }
804         }
805 }
806
807
808 void
809 VideoPanel::bottom_crop_changed ()
810 {
811         if (_top_bottom_link->GetValue()) {
812                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
813                         i->video->set_top_crop (i->video->bottom_crop());
814                 }
815         }
816 }
817
818
819