2 Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 #include "filter_dialog.h"
22 #include "video_panel.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 "dcpomatic_button.h"
30 #include "lib/filter.h"
31 #include "lib/ffmpeg_content.h"
32 #include "lib/colour_conversion.h"
33 #include "lib/config.h"
35 #include "lib/ratio.h"
36 #include "lib/frame_rate_change.h"
37 #include "lib/dcp_content.h"
38 #include "lib/video_content.h"
39 #include <wx/spinctrl.h>
40 #include <boost/foreach.hpp>
41 #include <boost/unordered_set.hpp>
42 #include <boost/functional/hash.hpp>
52 using boost::shared_ptr;
53 using boost::dynamic_pointer_cast;
55 using boost::optional;
56 using namespace dcpomatic;
58 static VideoContentScale
59 index_to_scale (int n)
61 vector<VideoContentScale> scales = VideoContentScale::all ();
62 DCPOMATIC_ASSERT (n >= 0);
63 DCPOMATIC_ASSERT (n < int (scales.size ()));
68 scale_to_index (VideoContentScale scale)
70 vector<VideoContentScale> scales = VideoContentScale::all ();
71 for (size_t i = 0; i < scales.size(); ++i) {
72 if (scales[i] == scale) {
77 DCPOMATIC_ASSERT (false);
80 VideoPanel::VideoPanel (ContentPanel* p)
81 : ContentSubPanel (p, _("Video"))
83 _reference = new CheckBox (this, _("Use this DCP's video as OV and make VF"));
84 _reference_note = new StaticText (this, wxT(""));
85 _reference_note->Wrap (200);
86 wxFont font = _reference_note->GetFont();
87 font.SetStyle(wxFONTSTYLE_ITALIC);
88 font.SetPointSize(font.GetPointSize() - 1);
89 _reference_note->SetFont(font);
91 _use = new wxCheckBox (this, wxID_ANY, _("Use"));
93 _type_label = create_label (this, _("Type"), true);
94 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
96 new wxChoice (this, wxID_ANY),
97 VideoContentProperty::FRAME_TYPE,
99 boost::mem_fn (&VideoContent::frame_type),
100 boost::mem_fn (&VideoContent::set_frame_type),
101 &caster<int, VideoFrameType>,
102 &caster<VideoFrameType, int>
105 _left_crop_label = create_label (this, _("Left crop"), true);
106 _left_crop = new ContentSpinCtrl<VideoContent> (
108 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
109 VideoContentProperty::CROP,
111 boost::mem_fn (&VideoContent::left_crop),
112 boost::mem_fn (&VideoContent::set_left_crop)
115 _right_crop_label = create_label (this, _("Right crop"), true);
116 _right_crop = new ContentSpinCtrl<VideoContent> (
118 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
119 VideoContentProperty::CROP,
121 boost::mem_fn (&VideoContent::right_crop),
122 boost::mem_fn (&VideoContent::set_right_crop)
125 _top_crop_label = create_label (this, _("Top crop"), true);
126 _top_crop = new ContentSpinCtrl<VideoContent> (
128 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
129 VideoContentProperty::CROP,
131 boost::mem_fn (&VideoContent::top_crop),
132 boost::mem_fn (&VideoContent::set_top_crop)
135 _bottom_crop_label = create_label (this, _("Bottom crop"), true);
136 _bottom_crop = new ContentSpinCtrl<VideoContent> (
138 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
139 VideoContentProperty::CROP,
141 boost::mem_fn (&VideoContent::bottom_crop),
142 boost::mem_fn (&VideoContent::set_bottom_crop)
145 _fade_in_label = create_label (this, _("Fade in"), true);
146 _fade_in = new Timecode<ContentTime> (this);
148 _fade_out_label = create_label (this, _("Fade out"), true);
149 _fade_out = new Timecode<ContentTime> (this);
151 _scale_to_label = create_label (this, _("Scale to"), true);
152 _scale = new ContentChoice<VideoContent, VideoContentScale> (
154 new wxChoice (this, wxID_ANY),
155 VideoContentProperty::SCALE,
157 boost::mem_fn (&VideoContent::scale),
158 boost::mem_fn (&VideoContent::set_scale),
163 wxClientDC dc (this);
164 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
167 _filters_label = create_label (this, _("Filters"), true);
168 _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
169 _filters_button = new Button (this, _("Edit..."));
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));
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..."));
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)"));
187 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
188 _description->SetFont(font);
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);
195 _scale->wrapped()->Clear ();
196 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
197 _scale->wrapped()->Append (std_to_wx (i.name ()));
200 _frame_type->wrapped()->Append (_("2D"));
201 _frame_type->wrapped()->Append (_("3D"));
202 _frame_type->wrapped()->Append (_("3D left/right"));
203 _frame_type->wrapped()->Append (_("3D top/bottom"));
204 _frame_type->wrapped()->Append (_("3D alternate"));
205 _frame_type->wrapped()->Append (_("3D left only"));
206 _frame_type->wrapped()->Append (_("3D right only"));
208 content_selection_changed ();
210 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
211 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
213 _use->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::use_clicked, this));
214 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
215 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
216 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
217 _range->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::range_changed, this));
218 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
224 VideoPanel::add_to_grid ()
226 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
230 _reference->Show (full);
231 _reference_note->Show (full && !_reference_note->GetLabel().IsEmpty());
234 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
235 reference_sizer->Add (_reference, 0);
236 reference_sizer->Add (_reference_note, 0);
237 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
242 _grid->Add (_use, wxGBPosition(r, 0), wxGBSpan(1, 2));
245 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
246 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
250 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
251 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
252 _left_crop->add (crop, wxGBPosition (cr, 1));
253 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
254 _right_crop->add (crop, wxGBPosition (cr, 3));
256 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
257 _top_crop->add (crop, wxGBPosition (cr, 1));
258 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
259 _bottom_crop->add (crop, wxGBPosition (cr, 3));
260 _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
263 _scale_to_label->Show (full);
265 _filters_label->Show (full);
266 _filters->Show (full);
267 _filters_button->Show (full);
268 _colour_conversion_label->Show (full);
269 _colour_conversion->Show (full);
270 _edit_colour_conversion_button->Show (full);
271 _range_label->Show (full);
274 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
275 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
278 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
279 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
283 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
284 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
287 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
289 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
290 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
291 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
292 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
296 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
298 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
299 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
300 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
301 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
305 add_label_to_sizer (_grid, _range_label, true, wxGBPosition(r, 0));
306 _grid->Add (_range, wxGBPosition(r, 1), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL);
310 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
315 VideoPanel::range_changed ()
317 ContentList vc = _parent->selected_video ();
318 if (vc.size() != 1) {
322 switch (_range->GetSelection()) {
324 vc.front()->video->set_range (VIDEO_RANGE_FULL);
327 vc.front()->video->set_range (VIDEO_RANGE_VIDEO);
330 DCPOMATIC_ASSERT (false);
336 VideoPanel::film_changed (Film::Property property)
339 case Film::VIDEO_FRAME_RATE:
340 case Film::CONTAINER:
341 case Film::RESOLUTION:
342 setup_description ();
343 setup_sensitivity ();
345 case Film::REEL_TYPE:
347 setup_sensitivity ();
355 hash_value (boost::optional<ColourConversion> const & c)
357 boost::hash<string> hasher;
359 return hasher ("none");
361 return hasher (c->identifier());
366 VideoPanel::film_content_changed (int property)
368 ContentList vc = _parent->selected_video ();
369 shared_ptr<Content> vcs;
370 shared_ptr<FFmpegContent> fcs;
373 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
376 if (property == ContentProperty::VIDEO_FRAME_RATE ||
377 property == VideoContentProperty::FRAME_TYPE ||
378 property == VideoContentProperty::CROP ||
379 property == VideoContentProperty::SCALE) {
380 setup_description ();
381 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
382 boost::unordered_set<optional<ColourConversion> > check;
383 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
384 check.insert (i->video->colour_conversion());
387 /* Remove any "Many" entry that we might have added previously. There should
388 * be entries for each preset plus one for "None" and one for "Custom".
390 vector<PresetColourConversion> cc = PresetColourConversion::all ();
391 if (_colour_conversion->GetCount() > cc.size() + 2) {
392 _colour_conversion->Delete (_colour_conversion->GetCount() - 1);
395 if (check.size() == 1) {
396 if (vcs && vcs->video->colour_conversion ()) {
397 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
399 checked_set (_colour_conversion, preset.get() + 1);
401 checked_set (_colour_conversion, cc.size() + 1);
404 checked_set (_colour_conversion, 0);
406 } else if (check.size() > 1) {
407 /* Add a "many" entry and select it as an indication that multiple different
408 * colour conversions are present in the selection.
410 _colour_conversion->Append (_("Many"));
411 checked_set (_colour_conversion, _colour_conversion->GetCount() - 1);
414 setup_sensitivity ();
416 } else if (property == FFmpegContentProperty::FILTERS) {
418 string p = Filter::ffmpeg_string (fcs->filters ());
420 checked_set (_filters, _("None"));
422 if (p.length() > 25) {
423 p = p.substr (0, 25) + "...";
425 checked_set (_filters, p);
428 } else if (property == VideoContentProperty::USE) {
430 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
431 check.insert (i->video->use());
434 if (check.size() == 1) {
435 checked_set (_use, vc.front()->video->use());
437 checked_set (_use, false);
440 setup_sensitivity ();
441 } else if (property == VideoContentProperty::FADE_IN) {
443 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
444 check.insert (i->video->fade_in ());
447 if (check.size() == 1) {
449 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
450 vc.front()->active_video_frame_rate(_parent->film())
455 } else if (property == VideoContentProperty::FADE_OUT) {
457 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
458 check.insert (i->video->fade_out ());
461 if (check.size() == 1) {
463 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
464 vc.front()->active_video_frame_rate(_parent->film())
469 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
470 if (vc.size() == 1) {
471 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
472 checked_set (_reference, dcp ? dcp->reference_video () : false);
474 checked_set (_reference, false);
477 setup_sensitivity ();
478 } else if (property == VideoContentProperty::RANGE) {
480 checked_set (_range, vcs->video->range() == VIDEO_RANGE_FULL ? 0 : 1);
482 checked_set (_range, 0);
485 setup_sensitivity ();
489 /** Called when the `Edit filters' button has been clicked */
491 VideoPanel::edit_filters_clicked ()
493 FFmpegContentList c = _parent->selected_ffmpeg ();
498 FilterDialog* d = new FilterDialog (this, c.front()->filters());
499 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
505 VideoPanel::setup_description ()
507 ContentList vc = _parent->selected_video ();
509 checked_set (_description, wxT (""));
511 } else if (vc.size() > 1) {
512 checked_set (_description, _("Multiple content selected"));
516 string d = vc.front()->video->processing_description (_parent->film());
517 size_t lines = count (d.begin(), d.end(), '\n');
519 for (int i = lines; i < 6; ++i) {
523 checked_set (_description, d);
528 VideoPanel::colour_conversion_changed ()
530 ContentList vc = _parent->selected_video ();
532 int const s = _colour_conversion->GetSelection ();
533 vector<PresetColourConversion> all = PresetColourConversion::all ();
535 if (s == int(all.size() + 1)) {
536 edit_colour_conversion_clicked ();
538 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
540 i->video->unset_colour_conversion ();
541 } else if (s != int(all.size() + 2)) {
542 i->video->set_colour_conversion (all[s - 1].conversion);
549 VideoPanel::edit_colour_conversion_clicked ()
551 ContentList vc = _parent->selected_video ();
553 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
554 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
555 if (d->ShowModal() == wxID_OK) {
556 BOOST_FOREACH (shared_ptr<Content> i, vc) {
557 i->video->set_colour_conversion (d->get ());
560 /* Reset the colour conversion choice */
561 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
567 VideoPanel::content_selection_changed ()
569 ContentList video_sel = _parent->selected_video ();
571 _frame_type->set_content (video_sel);
572 _left_crop->set_content (video_sel);
573 _right_crop->set_content (video_sel);
574 _top_crop->set_content (video_sel);
575 _bottom_crop->set_content (video_sel);
576 _scale->set_content (video_sel);
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 (FFmpegContentProperty::FILTERS);
586 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
588 setup_sensitivity ();
592 VideoPanel::setup_sensitivity ()
594 ContentList sel = _parent->selected ();
596 shared_ptr<DCPContent> dcp;
597 if (sel.size() == 1) {
598 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
602 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
604 if (why_not.empty()) {
605 cannot = _("Cannot reference this DCP's video.");
607 cannot = _("Cannot reference this DCP's video: ") + std_to_wx(why_not);
609 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
611 bool const enable = !_reference->GetValue() && _use->GetValue();
613 _use->Enable (!_reference->GetValue());
616 _frame_type->wrapped()->Enable (false);
617 _left_crop->wrapped()->Enable (false);
618 _right_crop->wrapped()->Enable (false);
619 _top_crop->wrapped()->Enable (false);
620 _bottom_crop->wrapped()->Enable (false);
621 _fade_in->Enable (false);
622 _fade_out->Enable (false);
623 _scale->wrapped()->Enable (false);
624 _description->Enable (false);
625 _filters->Enable (false);
626 _filters_button->Enable (false);
627 _colour_conversion->Enable (false);
628 _range->Enable (false);
630 ContentList video_sel = _parent->selected_video ();
631 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
632 bool const single = video_sel.size() == 1;
634 _frame_type->wrapped()->Enable (true);
635 _left_crop->wrapped()->Enable (true);
636 _right_crop->wrapped()->Enable (true);
637 _top_crop->wrapped()->Enable (true);
638 _bottom_crop->wrapped()->Enable (true);
639 _fade_in->Enable (!video_sel.empty ());
640 _fade_out->Enable (!video_sel.empty ());
641 _scale->wrapped()->Enable (true);
642 _description->Enable (true);
643 _filters->Enable (true);
644 _filters_button->Enable (single && !ffmpeg_sel.empty ());
645 _colour_conversion->Enable (!video_sel.empty());
646 _range->Enable (single && !video_sel.empty());
649 ContentList vc = _parent->selected_video ();
650 shared_ptr<Content> vcs;
655 if (vcs && vcs->video->colour_conversion ()) {
656 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
658 _edit_colour_conversion_button->Enable (false);
663 VideoPanel::fade_in_changed ()
665 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
666 double const vfr = i->active_video_frame_rate (_parent->film());
667 i->video->set_fade_in (_fade_in->get(vfr).frames_round(vfr));
672 VideoPanel::fade_out_changed ()
674 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
675 double const vfr = i->active_video_frame_rate (_parent->film());
676 i->video->set_fade_out (_fade_out->get(vfr).frames_round(vfr));
681 VideoPanel::use_clicked ()
683 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
684 i->video->set_use (_use->GetValue());
689 VideoPanel::reference_clicked ()
691 ContentList c = _parent->selected ();
696 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
701 d->set_reference_video (_reference->GetValue ());