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 _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 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
183 _description->SetFont(font);
185 _left_crop->wrapped()->SetRange (0, 4096);
186 _top_crop->wrapped()->SetRange (0, 4096);
187 _right_crop->wrapped()->SetRange (0, 4096);
188 _bottom_crop->wrapped()->SetRange (0, 4096);
190 _scale->wrapped()->Clear ();
191 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
192 _scale->wrapped()->Append (std_to_wx (i.name ()));
195 _frame_type->wrapped()->Append (_("2D"));
196 _frame_type->wrapped()->Append (_("3D"));
197 _frame_type->wrapped()->Append (_("3D left/right"));
198 _frame_type->wrapped()->Append (_("3D top/bottom"));
199 _frame_type->wrapped()->Append (_("3D alternate"));
200 _frame_type->wrapped()->Append (_("3D left only"));
201 _frame_type->wrapped()->Append (_("3D right only"));
203 content_selection_changed ();
205 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
206 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
208 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
209 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
210 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
211 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
217 VideoPanel::add_to_grid ()
219 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
223 _reference->Show (full);
224 _reference_note->Show (full);
227 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
228 reference_sizer->Add (_reference, 0);
229 reference_sizer->Add (_reference_note, 0);
230 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
234 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
235 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
239 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
240 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
241 _left_crop->add (crop, wxGBPosition (cr, 1));
242 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
243 _right_crop->add (crop, wxGBPosition (cr, 3));
245 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
246 _top_crop->add (crop, wxGBPosition (cr, 1));
247 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
248 _bottom_crop->add (crop, wxGBPosition (cr, 3));
249 _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
252 _scale_to_label->Show (full);
254 _filters_label->Show (full);
255 _filters->Show (full);
256 _filters_button->Show (full);
257 _colour_conversion_label->Show (full);
258 _colour_conversion->Show (full);
259 _edit_colour_conversion_button->Show (full);
261 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
262 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
265 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
266 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
270 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
271 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
274 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
276 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
277 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
278 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
279 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
283 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
285 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
286 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
287 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
288 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
293 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
299 VideoPanel::film_changed (Film::Property property)
302 case Film::VIDEO_FRAME_RATE:
303 case Film::CONTAINER:
304 case Film::RESOLUTION:
305 setup_description ();
306 setup_sensitivity ();
308 case Film::REEL_TYPE:
310 setup_sensitivity ();
318 hash_value (boost::optional<ColourConversion> const & c)
320 boost::hash<string> hasher;
322 return hasher ("none");
324 return hasher (c->identifier());
329 VideoPanel::film_content_changed (int property)
331 ContentList vc = _parent->selected_video ();
332 shared_ptr<Content> vcs;
333 shared_ptr<FFmpegContent> fcs;
336 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
339 if (property == ContentProperty::VIDEO_FRAME_RATE ||
340 property == VideoContentProperty::FRAME_TYPE ||
341 property == VideoContentProperty::CROP ||
342 property == VideoContentProperty::SCALE) {
343 setup_description ();
344 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
345 boost::unordered_set<optional<ColourConversion> > check;
346 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
347 check.insert (i->video->colour_conversion());
350 /* Remove any "Many" entry that we might have added previously. There should
351 * be entries for each preset plus one for "None" and one for "Custom".
353 vector<PresetColourConversion> cc = PresetColourConversion::all ();
354 if (_colour_conversion->GetCount() > cc.size() + 2) {
355 _colour_conversion->Delete (_colour_conversion->GetCount() - 1);
358 if (check.size() == 1) {
359 if (vcs && vcs->video->colour_conversion ()) {
360 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
362 checked_set (_colour_conversion, preset.get() + 1);
364 checked_set (_colour_conversion, cc.size() + 1);
367 checked_set (_colour_conversion, 0);
369 } else if (check.size() > 1) {
370 /* Add a "many" entry and select it as an indication that multiple different
371 * colour conversions are present in the selection.
373 _colour_conversion->Append (_("Many"));
374 checked_set (_colour_conversion, _colour_conversion->GetCount() - 1);
377 setup_sensitivity ();
379 } else if (property == FFmpegContentProperty::FILTERS) {
381 string p = Filter::ffmpeg_string (fcs->filters ());
383 checked_set (_filters, _("None"));
385 if (p.length() > 25) {
386 p = p.substr (0, 25) + "...";
388 checked_set (_filters, p);
391 } else if (property == VideoContentProperty::FADE_IN) {
393 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
394 check.insert (i->video->fade_in ());
397 if (check.size() == 1) {
399 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
400 vc.front()->active_video_frame_rate(_parent->film())
405 } else if (property == VideoContentProperty::FADE_OUT) {
407 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
408 check.insert (i->video->fade_out ());
411 if (check.size() == 1) {
413 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
414 vc.front()->active_video_frame_rate(_parent->film())
419 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
420 if (vc.size() == 1) {
421 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
422 checked_set (_reference, dcp ? dcp->reference_video () : false);
424 checked_set (_reference, false);
427 setup_sensitivity ();
431 /** Called when the `Edit filters' button has been clicked */
433 VideoPanel::edit_filters_clicked ()
435 FFmpegContentList c = _parent->selected_ffmpeg ();
440 FilterDialog* d = new FilterDialog (this, c.front()->filters());
441 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
447 VideoPanel::setup_description ()
449 ContentList vc = _parent->selected_video ();
451 checked_set (_description, wxT (""));
453 } else if (vc.size() > 1) {
454 checked_set (_description, _("Multiple content selected"));
458 string d = vc.front()->video->processing_description (_parent->film());
459 size_t lines = count (d.begin(), d.end(), '\n');
461 for (int i = lines; i < 6; ++i) {
465 checked_set (_description, d);
470 VideoPanel::colour_conversion_changed ()
472 ContentList vc = _parent->selected_video ();
474 int const s = _colour_conversion->GetSelection ();
475 vector<PresetColourConversion> all = PresetColourConversion::all ();
477 if (s == int(all.size() + 1)) {
478 edit_colour_conversion_clicked ();
480 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
482 i->video->unset_colour_conversion ();
483 } else if (s != int(all.size() + 2)) {
484 i->video->set_colour_conversion (all[s - 1].conversion);
491 VideoPanel::edit_colour_conversion_clicked ()
493 ContentList vc = _parent->selected_video ();
495 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
496 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
497 if (d->ShowModal() == wxID_OK) {
498 BOOST_FOREACH (shared_ptr<Content> i, vc) {
499 i->video->set_colour_conversion (d->get ());
502 /* Reset the colour conversion choice */
503 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
509 VideoPanel::content_selection_changed ()
511 ContentList video_sel = _parent->selected_video ();
513 _frame_type->set_content (video_sel);
514 _left_crop->set_content (video_sel);
515 _right_crop->set_content (video_sel);
516 _top_crop->set_content (video_sel);
517 _bottom_crop->set_content (video_sel);
518 _scale->set_content (video_sel);
520 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
521 film_content_changed (VideoContentProperty::CROP);
522 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
523 film_content_changed (VideoContentProperty::FADE_IN);
524 film_content_changed (VideoContentProperty::FADE_OUT);
525 film_content_changed (FFmpegContentProperty::FILTERS);
526 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
528 setup_sensitivity ();
532 VideoPanel::setup_sensitivity ()
534 ContentList sel = _parent->selected ();
536 shared_ptr<DCPContent> dcp;
537 if (sel.size() == 1) {
538 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
542 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
543 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
545 if (_reference->GetValue ()) {
546 _frame_type->wrapped()->Enable (false);
547 _left_crop->wrapped()->Enable (false);
548 _right_crop->wrapped()->Enable (false);
549 _top_crop->wrapped()->Enable (false);
550 _bottom_crop->wrapped()->Enable (false);
551 _fade_in->Enable (false);
552 _fade_out->Enable (false);
553 _scale->wrapped()->Enable (false);
554 _description->Enable (false);
555 _filters->Enable (false);
556 _filters_button->Enable (false);
557 _colour_conversion->Enable (false);
559 ContentList video_sel = _parent->selected_video ();
560 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
561 bool const single = video_sel.size() == 1;
563 _frame_type->wrapped()->Enable (true);
564 _left_crop->wrapped()->Enable (true);
565 _right_crop->wrapped()->Enable (true);
566 _top_crop->wrapped()->Enable (true);
567 _bottom_crop->wrapped()->Enable (true);
568 _fade_in->Enable (!video_sel.empty ());
569 _fade_out->Enable (!video_sel.empty ());
570 _scale->wrapped()->Enable (true);
571 _description->Enable (true);
572 _filters->Enable (true);
573 _filters_button->Enable (single && !ffmpeg_sel.empty ());
574 _colour_conversion->Enable (!video_sel.empty());
577 ContentList vc = _parent->selected_video ();
578 shared_ptr<Content> vcs;
583 if (vcs && vcs->video->colour_conversion ()) {
584 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
586 _edit_colour_conversion_button->Enable (false);
591 VideoPanel::fade_in_changed ()
593 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
594 double const vfr = i->active_video_frame_rate (_parent->film());
595 i->video->set_fade_in (_fade_in->get(vfr).frames_round(vfr));
600 VideoPanel::fade_out_changed ()
602 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
603 double const vfr = i->active_video_frame_rate (_parent->film());
604 i->video->set_fade_out (_fade_out->get(vfr).frames_round(vfr));
609 VideoPanel::reference_clicked ()
611 ContentList c = _parent->selected ();
616 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
621 d->set_reference_video (_reference->GetValue ());