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