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