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