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 #if BOOST_VERSION >= 106100
57 using namespace boost::placeholders;
60 static VideoContentScale
61 index_to_scale (int n)
63 vector<VideoContentScale> scales = VideoContentScale::all ();
64 DCPOMATIC_ASSERT (n >= 0);
65 DCPOMATIC_ASSERT (n < int (scales.size ()));
70 scale_to_index (VideoContentScale scale)
72 vector<VideoContentScale> scales = VideoContentScale::all ();
73 for (size_t i = 0; i < scales.size(); ++i) {
74 if (scales[i] == scale) {
79 DCPOMATIC_ASSERT (false);
82 VideoPanel::VideoPanel (ContentPanel* p)
83 : ContentSubPanel (p, _("Video"))
85 _reference = new CheckBox (this, _("Use this DCP's video as OV and make VF"));
86 _reference_note = new StaticText (this, wxT(""));
87 _reference_note->Wrap (200);
88 wxFont font = _reference_note->GetFont();
89 font.SetStyle(wxFONTSTYLE_ITALIC);
90 font.SetPointSize(font.GetPointSize() - 1);
91 _reference_note->SetFont(font);
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);
108 int const crop_width = 128;
110 int const crop_width = 56;
113 _left_crop_label = create_label (this, _("Left"), true);
114 _left_crop = new ContentSpinCtrl<VideoContent> (
116 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (crop_width, -1)),
117 VideoContentProperty::CROP,
119 boost::mem_fn (&VideoContent::left_crop),
120 boost::mem_fn (&VideoContent::set_left_crop)
123 _right_crop_label = create_label (this, _("Right"), true);
124 _right_crop = new ContentSpinCtrl<VideoContent> (
126 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (crop_width, -1)),
127 VideoContentProperty::CROP,
129 boost::mem_fn (&VideoContent::right_crop),
130 boost::mem_fn (&VideoContent::set_right_crop)
133 _top_crop_label = create_label (this, _("Top"), true);
134 _top_crop = new ContentSpinCtrl<VideoContent> (
136 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (crop_width, -1)),
137 VideoContentProperty::CROP,
139 boost::mem_fn (&VideoContent::top_crop),
140 boost::mem_fn (&VideoContent::set_top_crop)
143 _bottom_crop_label = create_label (this, _("Bottom"), true);
144 _bottom_crop = new ContentSpinCtrl<VideoContent> (
146 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (crop_width, -1)),
147 VideoContentProperty::CROP,
149 boost::mem_fn (&VideoContent::bottom_crop),
150 boost::mem_fn (&VideoContent::set_bottom_crop)
153 _fade_in_label = create_label (this, _("Fade in"), true);
154 _fade_in = new Timecode<ContentTime> (this);
156 _fade_out_label = create_label (this, _("Fade out"), true);
157 _fade_out = new Timecode<ContentTime> (this);
159 _scale_to_label = create_label (this, _("Scale to"), true);
160 _scale = new ContentChoice<VideoContent, VideoContentScale> (
162 new wxChoice (this, wxID_ANY),
163 VideoContentProperty::SCALE,
165 boost::mem_fn (&VideoContent::scale),
166 boost::mem_fn (&VideoContent::set_scale),
171 wxClientDC dc (this);
172 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
174 size.SetWidth (size.GetWidth() + 64);
178 _filters_label = create_label (this, _("Filters"), true);
179 _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
180 _filters_button = new Button (this, _("Edit..."));
182 _colour_conversion_label = create_label (this, _("Colour conversion"), true);
183 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
184 _colour_conversion->Append (_("None"));
185 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
186 _colour_conversion->Append (std_to_wx (i.name));
189 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
190 _colour_conversion->Append (S_("Colour|Custom"));
191 _edit_colour_conversion_button = new Button (this, _("Edit..."));
193 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
194 _description->SetFont(font);
196 _left_crop->wrapped()->SetRange (0, 4096);
197 _top_crop->wrapped()->SetRange (0, 4096);
198 _right_crop->wrapped()->SetRange (0, 4096);
199 _bottom_crop->wrapped()->SetRange (0, 4096);
201 _scale->wrapped()->Clear ();
202 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
203 _scale->wrapped()->Append (std_to_wx (i.name ()));
206 _frame_type->wrapped()->Append (_("2D"));
207 _frame_type->wrapped()->Append (_("3D"));
208 _frame_type->wrapped()->Append (_("3D left/right"));
209 _frame_type->wrapped()->Append (_("3D top/bottom"));
210 _frame_type->wrapped()->Append (_("3D alternate"));
211 _frame_type->wrapped()->Append (_("3D left only"));
212 _frame_type->wrapped()->Append (_("3D right only"));
214 content_selection_changed ();
216 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
217 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
219 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
220 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
221 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
222 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
228 VideoPanel::add_to_grid ()
230 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
234 _reference->Show (full);
235 _reference_note->Show (full);
238 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
239 reference_sizer->Add (_reference, 0);
240 reference_sizer->Add (_reference_note, 0);
241 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
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));
255 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 0));
256 _right_crop->add (crop, wxGBPosition (cr, 1));
258 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
259 _right_crop->add (crop, wxGBPosition (cr, 3));
262 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
263 _top_crop->add (crop, wxGBPosition (cr, 1));
266 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 0));
267 _bottom_crop->add (crop, wxGBPosition (cr, 1));
269 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
270 _bottom_crop->add (crop, wxGBPosition (cr, 3));
272 add_label_to_sizer (_grid, _crop_label, true, wxGBPosition(r, 0));
273 _grid->Add (crop, wxGBPosition(r, 1));
276 _scale_to_label->Show (full);
278 _filters_label->Show (full);
279 _filters->Show (full);
280 _filters_button->Show (full);
281 _colour_conversion_label->Show (full);
282 _colour_conversion->Show (full);
283 _edit_colour_conversion_button->Show (full);
285 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
286 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
289 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
290 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
294 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
295 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
298 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
300 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
301 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
302 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
303 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
307 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
309 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
310 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
311 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
312 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
317 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
323 VideoPanel::film_changed (Film::Property property)
326 case Film::VIDEO_FRAME_RATE:
327 case Film::CONTAINER:
328 case Film::RESOLUTION:
329 setup_description ();
330 setup_sensitivity ();
332 case Film::REEL_TYPE:
334 setup_sensitivity ();
342 hash_value (boost::optional<ColourConversion> const & c)
344 boost::hash<string> hasher;
346 return hasher ("none");
348 return hasher (c->identifier());
353 VideoPanel::film_content_changed (int property)
355 ContentList vc = _parent->selected_video ();
356 shared_ptr<Content> vcs;
357 shared_ptr<FFmpegContent> fcs;
360 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
363 if (property == ContentProperty::VIDEO_FRAME_RATE ||
364 property == VideoContentProperty::FRAME_TYPE ||
365 property == VideoContentProperty::CROP ||
366 property == VideoContentProperty::SCALE) {
367 setup_description ();
368 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
369 boost::unordered_set<optional<ColourConversion> > check;
370 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
371 check.insert (i->video->colour_conversion());
374 /* Remove any "Many" entry that we might have added previously. There should
375 * be entries for each preset plus one for "None" and one for "Custom".
377 vector<PresetColourConversion> cc = PresetColourConversion::all ();
378 if (_colour_conversion->GetCount() > cc.size() + 2) {
379 _colour_conversion->Delete (_colour_conversion->GetCount() - 1);
382 if (check.size() == 1) {
383 if (vcs && vcs->video->colour_conversion ()) {
384 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
386 checked_set (_colour_conversion, preset.get() + 1);
388 checked_set (_colour_conversion, cc.size() + 1);
391 checked_set (_colour_conversion, 0);
393 } else if (check.size() > 1) {
394 /* Add a "many" entry and select it as an indication that multiple different
395 * colour conversions are present in the selection.
397 _colour_conversion->Append (_("Many"));
398 checked_set (_colour_conversion, _colour_conversion->GetCount() - 1);
401 setup_sensitivity ();
403 } else if (property == FFmpegContentProperty::FILTERS) {
405 string p = Filter::ffmpeg_string (fcs->filters ());
407 checked_set (_filters, _("None"));
409 if (p.length() > 25) {
410 p = p.substr (0, 25) + "...";
412 checked_set (_filters, p);
415 } else if (property == VideoContentProperty::FADE_IN) {
417 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
418 check.insert (i->video->fade_in ());
421 if (check.size() == 1) {
423 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
424 vc.front()->active_video_frame_rate(_parent->film())
429 } else if (property == VideoContentProperty::FADE_OUT) {
431 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
432 check.insert (i->video->fade_out ());
435 if (check.size() == 1) {
437 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
438 vc.front()->active_video_frame_rate(_parent->film())
443 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
444 if (vc.size() == 1) {
445 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
446 checked_set (_reference, dcp ? dcp->reference_video () : false);
448 checked_set (_reference, false);
451 setup_sensitivity ();
455 /** Called when the `Edit filters' button has been clicked */
457 VideoPanel::edit_filters_clicked ()
459 FFmpegContentList c = _parent->selected_ffmpeg ();
464 FilterDialog* d = new FilterDialog (this, c.front()->filters());
465 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
471 VideoPanel::setup_description ()
473 ContentList vc = _parent->selected_video ();
475 checked_set (_description, wxT (""));
477 } else if (vc.size() > 1) {
478 checked_set (_description, _("Multiple content selected"));
482 string d = vc.front()->video->processing_description (_parent->film());
483 size_t lines = count (d.begin(), d.end(), '\n');
485 for (int i = lines; i < 6; ++i) {
489 checked_set (_description, d);
494 VideoPanel::colour_conversion_changed ()
496 ContentList vc = _parent->selected_video ();
498 int const s = _colour_conversion->GetSelection ();
499 vector<PresetColourConversion> all = PresetColourConversion::all ();
501 if (s == int(all.size() + 1)) {
502 edit_colour_conversion_clicked ();
504 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
506 i->video->unset_colour_conversion ();
507 } else if (s != int(all.size() + 2)) {
508 i->video->set_colour_conversion (all[s - 1].conversion);
515 VideoPanel::edit_colour_conversion_clicked ()
517 ContentList vc = _parent->selected_video ();
519 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
520 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
521 if (d->ShowModal() == wxID_OK) {
522 BOOST_FOREACH (shared_ptr<Content> i, vc) {
523 i->video->set_colour_conversion (d->get ());
526 /* Reset the colour conversion choice */
527 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
533 VideoPanel::content_selection_changed ()
535 ContentList video_sel = _parent->selected_video ();
537 _frame_type->set_content (video_sel);
538 _left_crop->set_content (video_sel);
539 _right_crop->set_content (video_sel);
540 _top_crop->set_content (video_sel);
541 _bottom_crop->set_content (video_sel);
542 _scale->set_content (video_sel);
544 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
545 film_content_changed (VideoContentProperty::CROP);
546 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
547 film_content_changed (VideoContentProperty::FADE_IN);
548 film_content_changed (VideoContentProperty::FADE_OUT);
549 film_content_changed (FFmpegContentProperty::FILTERS);
550 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
552 setup_sensitivity ();
556 VideoPanel::setup_sensitivity ()
558 ContentList sel = _parent->selected ();
560 shared_ptr<DCPContent> dcp;
561 if (sel.size() == 1) {
562 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
566 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
567 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
569 if (_reference->GetValue ()) {
570 _frame_type->wrapped()->Enable (false);
571 _left_crop->wrapped()->Enable (false);
572 _right_crop->wrapped()->Enable (false);
573 _top_crop->wrapped()->Enable (false);
574 _bottom_crop->wrapped()->Enable (false);
575 _fade_in->Enable (false);
576 _fade_out->Enable (false);
577 _scale->wrapped()->Enable (false);
578 _description->Enable (false);
579 _filters->Enable (false);
580 _filters_button->Enable (false);
581 _colour_conversion->Enable (false);
583 ContentList video_sel = _parent->selected_video ();
584 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
585 bool const single = video_sel.size() == 1;
587 _frame_type->wrapped()->Enable (true);
588 _left_crop->wrapped()->Enable (true);
589 _right_crop->wrapped()->Enable (true);
590 _top_crop->wrapped()->Enable (true);
591 _bottom_crop->wrapped()->Enable (true);
592 _fade_in->Enable (!video_sel.empty ());
593 _fade_out->Enable (!video_sel.empty ());
594 _scale->wrapped()->Enable (true);
595 _description->Enable (true);
596 _filters->Enable (true);
597 _filters_button->Enable (single && !ffmpeg_sel.empty ());
598 _colour_conversion->Enable (!video_sel.empty());
601 ContentList vc = _parent->selected_video ();
602 shared_ptr<Content> vcs;
607 if (vcs && vcs->video->colour_conversion ()) {
608 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
610 _edit_colour_conversion_button->Enable (false);
615 VideoPanel::fade_in_changed ()
617 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
618 double const vfr = i->active_video_frame_rate (_parent->film());
619 i->video->set_fade_in (_fade_in->get(vfr).frames_round(vfr));
624 VideoPanel::fade_out_changed ()
626 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
627 double const vfr = i->active_video_frame_rate (_parent->film());
628 i->video->set_fade_out (_fade_out->get(vfr).frames_round(vfr));
633 VideoPanel::reference_clicked ()
635 ContentList c = _parent->selected ();
640 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
645 d->set_reference_video (_reference->GetValue ());