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 _crop_label = create_label (this, _("Crop"), true);
107 _left_crop_label = create_label (this, _("Left"), true);
108 _left_crop = new ContentSpinCtrl<VideoContent> (
110 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
111 VideoContentProperty::CROP,
113 boost::mem_fn (&VideoContent::left_crop),
114 boost::mem_fn (&VideoContent::set_left_crop)
117 _right_crop_label = create_label (this, _("Right"), true);
118 _right_crop = new ContentSpinCtrl<VideoContent> (
120 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
121 VideoContentProperty::CROP,
123 boost::mem_fn (&VideoContent::right_crop),
124 boost::mem_fn (&VideoContent::set_right_crop)
127 _top_crop_label = create_label (this, _("Top"), true);
128 _top_crop = new ContentSpinCtrl<VideoContent> (
130 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
131 VideoContentProperty::CROP,
133 boost::mem_fn (&VideoContent::top_crop),
134 boost::mem_fn (&VideoContent::set_top_crop)
137 _bottom_crop_label = create_label (this, _("Bottom"), true);
138 _bottom_crop = new ContentSpinCtrl<VideoContent> (
140 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
141 VideoContentProperty::CROP,
143 boost::mem_fn (&VideoContent::bottom_crop),
144 boost::mem_fn (&VideoContent::set_bottom_crop)
147 _fade_in_label = create_label (this, _("Fade in"), true);
148 _fade_in = new Timecode<ContentTime> (this);
150 _fade_out_label = create_label (this, _("Fade out"), true);
151 _fade_out = new Timecode<ContentTime> (this);
153 _scale_to_label = create_label (this, _("Scale to"), true);
154 _scale = new ContentChoice<VideoContent, VideoContentScale> (
156 new wxChoice (this, wxID_ANY),
157 VideoContentProperty::SCALE,
159 boost::mem_fn (&VideoContent::scale),
160 boost::mem_fn (&VideoContent::set_scale),
165 wxClientDC dc (this);
166 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
169 _filters_label = create_label (this, _("Filters"), true);
170 _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
171 _filters_button = new Button (this, _("Edit..."));
173 _colour_conversion_label = create_label (this, _("Colour conversion"), true);
174 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
175 _colour_conversion->Append (_("None"));
176 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
177 _colour_conversion->Append (std_to_wx (i.name));
180 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
181 _colour_conversion->Append (S_("Colour|Custom"));
182 _edit_colour_conversion_button = new Button (this, _("Edit..."));
184 _range_label = create_label (this, _("Range"), true);
185 _range = new wxChoice (this, wxID_ANY);
186 _range->Append (_("Full (JPEG, 0-255)"));
187 _range->Append (_("Video (MPEG, 16-235)"));
189 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
190 _description->SetFont(font);
192 _left_crop->wrapped()->SetRange (0, 4096);
193 _top_crop->wrapped()->SetRange (0, 4096);
194 _right_crop->wrapped()->SetRange (0, 4096);
195 _bottom_crop->wrapped()->SetRange (0, 4096);
197 _scale->wrapped()->Clear ();
198 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
199 _scale->wrapped()->Append (std_to_wx (i.name ()));
202 _frame_type->wrapped()->Append (_("2D"));
203 _frame_type->wrapped()->Append (_("3D"));
204 _frame_type->wrapped()->Append (_("3D left/right"));
205 _frame_type->wrapped()->Append (_("3D top/bottom"));
206 _frame_type->wrapped()->Append (_("3D alternate"));
207 _frame_type->wrapped()->Append (_("3D left only"));
208 _frame_type->wrapped()->Append (_("3D right only"));
210 content_selection_changed ();
212 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
213 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
215 _use->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::use_clicked, this));
216 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
217 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
218 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
219 _range->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::range_changed, this));
220 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
226 VideoPanel::add_to_grid ()
228 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
232 _reference->Show (full);
233 _reference_note->Show (full && !_reference_note->GetLabel().IsEmpty());
236 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
237 reference_sizer->Add (_reference, 0);
238 reference_sizer->Add (_reference_note, 0);
239 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
244 _grid->Add (_use, wxGBPosition(r, 0), wxGBSpan(1, 2));
247 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
248 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
252 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
253 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
254 _left_crop->add (crop, wxGBPosition (cr, 1));
255 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
256 _right_crop->add (crop, wxGBPosition (cr, 3));
258 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
259 _top_crop->add (crop, wxGBPosition (cr, 1));
260 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
261 _bottom_crop->add (crop, wxGBPosition (cr, 3));
262 add_label_to_sizer (_grid, _crop_label, true, wxGBPosition(r, 0));
263 _grid->Add (crop, wxGBPosition(r, 1), wxGBSpan(2, 3));
266 _scale_to_label->Show (full);
268 _filters_label->Show (full);
269 _filters->Show (full);
270 _filters_button->Show (full);
271 _colour_conversion_label->Show (full);
272 _colour_conversion->Show (full);
273 _edit_colour_conversion_button->Show (full);
274 _range_label->Show (full);
277 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
278 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
281 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
282 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
286 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
287 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
290 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
292 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
293 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
294 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
295 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
299 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
301 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
302 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
303 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
304 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
308 add_label_to_sizer (_grid, _range_label, true, wxGBPosition(r, 0));
309 _grid->Add (_range, wxGBPosition(r, 1), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL);
313 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
318 VideoPanel::range_changed ()
320 ContentList vc = _parent->selected_video ();
321 if (vc.size() != 1) {
325 switch (_range->GetSelection()) {
327 vc.front()->video->set_range (VIDEO_RANGE_FULL);
330 vc.front()->video->set_range (VIDEO_RANGE_VIDEO);
333 DCPOMATIC_ASSERT (false);
339 VideoPanel::film_changed (Film::Property property)
342 case Film::VIDEO_FRAME_RATE:
343 case Film::CONTAINER:
344 case Film::RESOLUTION:
345 setup_description ();
346 setup_sensitivity ();
348 case Film::REEL_TYPE:
350 setup_sensitivity ();
358 hash_value (boost::optional<ColourConversion> const & c)
360 boost::hash<string> hasher;
362 return hasher ("none");
364 return hasher (c->identifier());
369 VideoPanel::film_content_changed (int property)
371 ContentList vc = _parent->selected_video ();
372 shared_ptr<Content> vcs;
373 shared_ptr<FFmpegContent> fcs;
376 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
379 if (property == ContentProperty::VIDEO_FRAME_RATE ||
380 property == VideoContentProperty::FRAME_TYPE ||
381 property == VideoContentProperty::CROP ||
382 property == VideoContentProperty::SCALE) {
383 setup_description ();
384 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
385 boost::unordered_set<optional<ColourConversion> > check;
386 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
387 check.insert (i->video->colour_conversion());
390 /* Remove any "Many" entry that we might have added previously. There should
391 * be entries for each preset plus one for "None" and one for "Custom".
393 vector<PresetColourConversion> cc = PresetColourConversion::all ();
394 if (_colour_conversion->GetCount() > cc.size() + 2) {
395 _colour_conversion->Delete (_colour_conversion->GetCount() - 1);
398 if (check.size() == 1) {
399 if (vcs && vcs->video->colour_conversion ()) {
400 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
402 checked_set (_colour_conversion, preset.get() + 1);
404 checked_set (_colour_conversion, cc.size() + 1);
407 checked_set (_colour_conversion, 0);
409 } else if (check.size() > 1) {
410 /* Add a "many" entry and select it as an indication that multiple different
411 * colour conversions are present in the selection.
413 _colour_conversion->Append (_("Many"));
414 checked_set (_colour_conversion, _colour_conversion->GetCount() - 1);
417 setup_sensitivity ();
419 } else if (property == FFmpegContentProperty::FILTERS) {
421 string p = Filter::ffmpeg_string (fcs->filters ());
423 checked_set (_filters, _("None"));
425 if (p.length() > 25) {
426 p = p.substr (0, 25) + "...";
428 checked_set (_filters, p);
431 } else if (property == VideoContentProperty::USE) {
433 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
434 check.insert (i->video->use());
437 if (check.size() == 1) {
438 checked_set (_use, vc.front()->video->use());
440 checked_set (_use, false);
443 setup_sensitivity ();
444 } else if (property == VideoContentProperty::FADE_IN) {
446 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
447 check.insert (i->video->fade_in ());
450 if (check.size() == 1) {
452 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
453 vc.front()->active_video_frame_rate(_parent->film())
458 } else if (property == VideoContentProperty::FADE_OUT) {
460 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
461 check.insert (i->video->fade_out ());
464 if (check.size() == 1) {
466 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
467 vc.front()->active_video_frame_rate(_parent->film())
472 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
473 if (vc.size() == 1) {
474 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
475 checked_set (_reference, dcp ? dcp->reference_video () : false);
477 checked_set (_reference, false);
480 setup_sensitivity ();
481 } else if (property == VideoContentProperty::RANGE) {
483 checked_set (_range, vcs->video->range() == VIDEO_RANGE_FULL ? 0 : 1);
485 checked_set (_range, 0);
488 setup_sensitivity ();
492 /** Called when the `Edit filters' button has been clicked */
494 VideoPanel::edit_filters_clicked ()
496 FFmpegContentList c = _parent->selected_ffmpeg ();
501 FilterDialog* d = new FilterDialog (this, c.front()->filters());
502 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
508 VideoPanel::setup_description ()
510 ContentList vc = _parent->selected_video ();
512 checked_set (_description, wxT (""));
514 } else if (vc.size() > 1) {
515 checked_set (_description, _("Multiple content selected"));
519 string d = vc.front()->video->processing_description (_parent->film());
520 size_t lines = count (d.begin(), d.end(), '\n');
522 for (int i = lines; i < 6; ++i) {
526 checked_set (_description, d);
531 VideoPanel::colour_conversion_changed ()
533 ContentList vc = _parent->selected_video ();
535 int const s = _colour_conversion->GetSelection ();
536 vector<PresetColourConversion> all = PresetColourConversion::all ();
538 if (s == int(all.size() + 1)) {
539 edit_colour_conversion_clicked ();
541 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
543 i->video->unset_colour_conversion ();
544 } else if (s != int(all.size() + 2)) {
545 i->video->set_colour_conversion (all[s - 1].conversion);
552 VideoPanel::edit_colour_conversion_clicked ()
554 ContentList vc = _parent->selected_video ();
556 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
557 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
558 if (d->ShowModal() == wxID_OK) {
559 BOOST_FOREACH (shared_ptr<Content> i, vc) {
560 i->video->set_colour_conversion (d->get ());
563 /* Reset the colour conversion choice */
564 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
570 VideoPanel::content_selection_changed ()
572 ContentList video_sel = _parent->selected_video ();
574 _frame_type->set_content (video_sel);
575 _left_crop->set_content (video_sel);
576 _right_crop->set_content (video_sel);
577 _top_crop->set_content (video_sel);
578 _bottom_crop->set_content (video_sel);
579 _scale->set_content (video_sel);
581 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
582 film_content_changed (VideoContentProperty::CROP);
583 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
584 film_content_changed (VideoContentProperty::FADE_IN);
585 film_content_changed (VideoContentProperty::FADE_OUT);
586 film_content_changed (VideoContentProperty::RANGE);
587 film_content_changed (VideoContentProperty::USE);
588 film_content_changed (FFmpegContentProperty::FILTERS);
589 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
591 setup_sensitivity ();
595 VideoPanel::setup_sensitivity ()
597 ContentList sel = _parent->selected ();
599 shared_ptr<DCPContent> dcp;
600 if (sel.size() == 1) {
601 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
605 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
607 if (why_not.empty()) {
608 cannot = _("Cannot reference this DCP's video.");
610 cannot = _("Cannot reference this DCP's video: ") + std_to_wx(why_not);
612 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
614 bool const enable = !_reference->GetValue() && _use->GetValue();
616 _use->Enable (!_reference->GetValue());
619 _frame_type->wrapped()->Enable (false);
620 _left_crop->wrapped()->Enable (false);
621 _right_crop->wrapped()->Enable (false);
622 _top_crop->wrapped()->Enable (false);
623 _bottom_crop->wrapped()->Enable (false);
624 _fade_in->Enable (false);
625 _fade_out->Enable (false);
626 _scale->wrapped()->Enable (false);
627 _description->Enable (false);
628 _filters->Enable (false);
629 _filters_button->Enable (false);
630 _colour_conversion->Enable (false);
631 _range->Enable (false);
633 ContentList video_sel = _parent->selected_video ();
634 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
635 bool const single = video_sel.size() == 1;
637 _frame_type->wrapped()->Enable (true);
638 _left_crop->wrapped()->Enable (true);
639 _right_crop->wrapped()->Enable (true);
640 _top_crop->wrapped()->Enable (true);
641 _bottom_crop->wrapped()->Enable (true);
642 _fade_in->Enable (!video_sel.empty ());
643 _fade_out->Enable (!video_sel.empty ());
644 _scale->wrapped()->Enable (true);
645 _description->Enable (true);
646 _filters->Enable (true);
647 _filters_button->Enable (single && !ffmpeg_sel.empty ());
648 _colour_conversion->Enable (!video_sel.empty());
649 _range->Enable (single && !video_sel.empty());
652 ContentList vc = _parent->selected_video ();
653 shared_ptr<Content> vcs;
658 if (vcs && vcs->video->colour_conversion ()) {
659 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
661 _edit_colour_conversion_button->Enable (false);
666 VideoPanel::fade_in_changed ()
668 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
669 double const vfr = i->active_video_frame_rate (_parent->film());
670 i->video->set_fade_in (_fade_in->get(vfr).frames_round(vfr));
675 VideoPanel::fade_out_changed ()
677 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
678 double const vfr = i->active_video_frame_rate (_parent->film());
679 i->video->set_fade_out (_fade_out->get(vfr).frames_round(vfr));
684 VideoPanel::use_clicked ()
686 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
687 i->video->set_use (_use->GetValue());
692 VideoPanel::reference_clicked ()
694 ContentList c = _parent->selected ();
699 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
704 d->set_reference_video (_reference->GetValue ());