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>
50 using boost::shared_ptr;
51 using boost::dynamic_pointer_cast;
53 using boost::optional;
54 using namespace dcpomatic;
56 static VideoContentScale
57 index_to_scale (int n)
59 vector<VideoContentScale> scales = VideoContentScale::all ();
60 DCPOMATIC_ASSERT (n >= 0);
61 DCPOMATIC_ASSERT (n < int (scales.size ()));
66 scale_to_index (VideoContentScale scale)
68 vector<VideoContentScale> scales = VideoContentScale::all ();
69 for (size_t i = 0; i < scales.size(); ++i) {
70 if (scales[i] == scale) {
75 DCPOMATIC_ASSERT (false);
78 VideoPanel::VideoPanel (ContentPanel* p)
79 : ContentSubPanel (p, _("Video"))
81 _reference = new CheckBox (this, _("Use this DCP's video as OV and make VF"));
82 _reference_note = new StaticText (this, wxT(""));
83 _reference_note->Wrap (200);
84 wxFont font = _reference_note->GetFont();
85 font.SetStyle(wxFONTSTYLE_ITALIC);
86 font.SetPointSize(font.GetPointSize() - 1);
87 _reference_note->SetFont(font);
89 _use = new wxCheckBox (this, wxID_ANY, _("Use"));
91 _type_label = create_label (this, _("Type"), true);
92 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
94 new wxChoice (this, wxID_ANY),
95 VideoContentProperty::FRAME_TYPE,
97 boost::mem_fn (&VideoContent::frame_type),
98 boost::mem_fn (&VideoContent::set_frame_type),
99 &caster<int, VideoFrameType>,
100 &caster<VideoFrameType, int>
103 _left_crop_label = create_label (this, _("Left crop"), true);
104 _left_crop = new ContentSpinCtrl<VideoContent> (
106 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
107 VideoContentProperty::CROP,
109 boost::mem_fn (&VideoContent::left_crop),
110 boost::mem_fn (&VideoContent::set_left_crop)
113 _right_crop_label = create_label (this, _("Right crop"), true);
114 _right_crop = new ContentSpinCtrl<VideoContent> (
116 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
117 VideoContentProperty::CROP,
119 boost::mem_fn (&VideoContent::right_crop),
120 boost::mem_fn (&VideoContent::set_right_crop)
123 _top_crop_label = create_label (this, _("Top crop"), true);
124 _top_crop = new ContentSpinCtrl<VideoContent> (
126 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
127 VideoContentProperty::CROP,
129 boost::mem_fn (&VideoContent::top_crop),
130 boost::mem_fn (&VideoContent::set_top_crop)
133 _bottom_crop_label = create_label (this, _("Bottom crop"), true);
134 _bottom_crop = new ContentSpinCtrl<VideoContent> (
136 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
137 VideoContentProperty::CROP,
139 boost::mem_fn (&VideoContent::bottom_crop),
140 boost::mem_fn (&VideoContent::set_bottom_crop)
143 _fade_in_label = create_label (this, _("Fade in"), true);
144 _fade_in = new Timecode<ContentTime> (this);
146 _fade_out_label = create_label (this, _("Fade out"), true);
147 _fade_out = new Timecode<ContentTime> (this);
149 _scale_to_label = create_label (this, _("Scale to"), true);
150 _scale = new ContentChoice<VideoContent, VideoContentScale> (
152 new wxChoice (this, wxID_ANY),
153 VideoContentProperty::SCALE,
155 boost::mem_fn (&VideoContent::scale),
156 boost::mem_fn (&VideoContent::set_scale),
161 wxClientDC dc (this);
162 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
165 _filters_label = create_label (this, _("Filters"), true);
166 _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
167 _filters_button = new Button (this, _("Edit..."));
169 _colour_conversion_label = create_label (this, _("Colour conversion"), true);
170 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
171 _colour_conversion->Append (_("None"));
172 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
173 _colour_conversion->Append (std_to_wx (i.name));
176 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
177 _colour_conversion->Append (S_("Colour|Custom"));
178 _edit_colour_conversion_button = new Button (this, _("Edit..."));
180 _range_label = create_label (this, _("Range"), true);
181 _range = new wxChoice (this, wxID_ANY);
182 _range->Append (_("Full (JPEG, 0-255)"));
183 _range->Append (_("Video (MPEG, 16-235)"));
185 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
186 _description->SetFont(font);
188 _left_crop->wrapped()->SetRange (0, 4096);
189 _top_crop->wrapped()->SetRange (0, 4096);
190 _right_crop->wrapped()->SetRange (0, 4096);
191 _bottom_crop->wrapped()->SetRange (0, 4096);
193 _scale->wrapped()->Clear ();
194 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
195 _scale->wrapped()->Append (std_to_wx (i.name ()));
198 _frame_type->wrapped()->Append (_("2D"));
199 _frame_type->wrapped()->Append (_("3D"));
200 _frame_type->wrapped()->Append (_("3D left/right"));
201 _frame_type->wrapped()->Append (_("3D top/bottom"));
202 _frame_type->wrapped()->Append (_("3D alternate"));
203 _frame_type->wrapped()->Append (_("3D left only"));
204 _frame_type->wrapped()->Append (_("3D right only"));
206 content_selection_changed ();
208 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
209 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
211 _use->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::use_clicked, this));
212 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
213 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
214 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
215 _range->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::range_changed, this));
216 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
222 VideoPanel::add_to_grid ()
224 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
228 _reference->Show (full);
229 _reference_note->Show (full && !_reference_note->GetLabel().IsEmpty());
232 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
233 reference_sizer->Add (_reference, 0);
234 reference_sizer->Add (_reference_note, 0);
235 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
240 _grid->Add (_use, wxGBPosition(r, 0), wxGBSpan(1, 2));
243 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
244 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
248 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
249 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
250 _left_crop->add (crop, wxGBPosition (cr, 1));
251 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
252 _right_crop->add (crop, wxGBPosition (cr, 3));
254 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
255 _top_crop->add (crop, wxGBPosition (cr, 1));
256 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
257 _bottom_crop->add (crop, wxGBPosition (cr, 3));
258 _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
261 _scale_to_label->Show (full);
263 _filters_label->Show (full);
264 _filters->Show (full);
265 _filters_button->Show (full);
266 _colour_conversion_label->Show (full);
267 _colour_conversion->Show (full);
268 _edit_colour_conversion_button->Show (full);
269 _range_label->Show (full);
272 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
273 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
276 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
277 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
281 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
282 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
285 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
287 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
288 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
289 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
290 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
294 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
296 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
297 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
298 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
299 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
303 add_label_to_sizer (_grid, _range_label, true, wxGBPosition(r, 0));
304 _grid->Add (_range, wxGBPosition(r, 1), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL);
308 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
313 VideoPanel::range_changed ()
315 ContentList vc = _parent->selected_video ();
316 if (vc.size() != 1) {
320 switch (_range->GetSelection()) {
322 vc.front()->video->set_range (VIDEO_RANGE_FULL);
325 vc.front()->video->set_range (VIDEO_RANGE_VIDEO);
328 DCPOMATIC_ASSERT (false);
334 VideoPanel::film_changed (Film::Property property)
337 case Film::VIDEO_FRAME_RATE:
338 case Film::CONTAINER:
339 case Film::RESOLUTION:
340 setup_description ();
341 setup_sensitivity ();
343 case Film::REEL_TYPE:
345 setup_sensitivity ();
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 if (vcs && vcs->video->colour_conversion ()) {
370 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
371 vector<PresetColourConversion> cc = PresetColourConversion::all ();
373 checked_set (_colour_conversion, preset.get() + 1);
375 checked_set (_colour_conversion, cc.size() + 1);
378 checked_set (_colour_conversion, 0);
381 setup_sensitivity ();
383 } else if (property == FFmpegContentProperty::FILTERS) {
385 string p = Filter::ffmpeg_string (fcs->filters ());
387 checked_set (_filters, _("None"));
389 if (p.length() > 25) {
390 p = p.substr (0, 25) + "...";
392 checked_set (_filters, p);
395 } else if (property == VideoContentProperty::USE) {
397 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
398 check.insert (i->video->use());
401 if (check.size() == 1) {
402 checked_set (_use, vc.front()->video->use());
404 checked_set (_use, false);
407 setup_sensitivity ();
408 } else if (property == VideoContentProperty::FADE_IN) {
410 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
411 check.insert (i->video->fade_in ());
414 if (check.size() == 1) {
416 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
417 vc.front()->active_video_frame_rate(_parent->film())
422 } else if (property == VideoContentProperty::FADE_OUT) {
424 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
425 check.insert (i->video->fade_out ());
428 if (check.size() == 1) {
430 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
431 vc.front()->active_video_frame_rate(_parent->film())
436 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
437 if (vc.size() == 1) {
438 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
439 checked_set (_reference, dcp ? dcp->reference_video () : false);
441 checked_set (_reference, false);
444 setup_sensitivity ();
445 } else if (property == VideoContentProperty::RANGE) {
447 checked_set (_range, vcs->video->range() == VIDEO_RANGE_FULL ? 0 : 1);
449 checked_set (_range, 0);
452 setup_sensitivity ();
456 /** Called when the `Edit filters' button has been clicked */
458 VideoPanel::edit_filters_clicked ()
460 FFmpegContentList c = _parent->selected_ffmpeg ();
465 FilterDialog* d = new FilterDialog (this, c.front()->filters());
466 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
472 VideoPanel::setup_description ()
474 ContentList vc = _parent->selected_video ();
476 checked_set (_description, wxT (""));
478 } else if (vc.size() > 1) {
479 checked_set (_description, _("Multiple content selected"));
483 string d = vc.front()->video->processing_description (_parent->film());
484 size_t lines = count (d.begin(), d.end(), '\n');
486 for (int i = lines; i < 6; ++i) {
490 checked_set (_description, d);
495 VideoPanel::colour_conversion_changed ()
497 ContentList vc = _parent->selected_video ();
498 if (vc.size() != 1) {
502 int const s = _colour_conversion->GetSelection ();
503 vector<PresetColourConversion> all = PresetColourConversion::all ();
506 vc.front()->video->unset_colour_conversion ();
507 } else if (s == int (all.size() + 1)) {
508 edit_colour_conversion_clicked ();
510 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
515 VideoPanel::edit_colour_conversion_clicked ()
517 ContentList vc = _parent->selected_video ();
518 if (vc.size() != 1) {
522 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
523 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
524 if (d->ShowModal() == wxID_OK) {
525 vc.front()->video->set_colour_conversion (d->get ());
527 /* Reset the colour conversion choice */
528 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
534 VideoPanel::content_selection_changed ()
536 ContentList video_sel = _parent->selected_video ();
538 _frame_type->set_content (video_sel);
539 _left_crop->set_content (video_sel);
540 _right_crop->set_content (video_sel);
541 _top_crop->set_content (video_sel);
542 _bottom_crop->set_content (video_sel);
543 _scale->set_content (video_sel);
545 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
546 film_content_changed (VideoContentProperty::CROP);
547 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
548 film_content_changed (VideoContentProperty::FADE_IN);
549 film_content_changed (VideoContentProperty::FADE_OUT);
550 film_content_changed (VideoContentProperty::RANGE);
551 film_content_changed (VideoContentProperty::USE);
552 film_content_changed (FFmpegContentProperty::FILTERS);
553 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
555 setup_sensitivity ();
559 VideoPanel::setup_sensitivity ()
561 ContentList sel = _parent->selected ();
563 shared_ptr<DCPContent> dcp;
564 if (sel.size() == 1) {
565 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
569 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
571 if (why_not.empty()) {
572 cannot = _("Cannot reference this DCP's video.");
574 cannot = _("Cannot reference this DCP's video: ") + std_to_wx(why_not);
576 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
578 bool const enable = !_reference->GetValue() && _use->GetValue();
580 _use->Enable (!_reference->GetValue());
583 _frame_type->wrapped()->Enable (false);
584 _left_crop->wrapped()->Enable (false);
585 _right_crop->wrapped()->Enable (false);
586 _top_crop->wrapped()->Enable (false);
587 _bottom_crop->wrapped()->Enable (false);
588 _fade_in->Enable (false);
589 _fade_out->Enable (false);
590 _scale->wrapped()->Enable (false);
591 _description->Enable (false);
592 _filters->Enable (false);
593 _filters_button->Enable (false);
594 _colour_conversion->Enable (false);
595 _range->Enable (false);
597 ContentList video_sel = _parent->selected_video ();
598 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
599 bool const single = video_sel.size() == 1;
601 _frame_type->wrapped()->Enable (true);
602 _left_crop->wrapped()->Enable (true);
603 _right_crop->wrapped()->Enable (true);
604 _top_crop->wrapped()->Enable (true);
605 _bottom_crop->wrapped()->Enable (true);
606 _fade_in->Enable (!video_sel.empty ());
607 _fade_out->Enable (!video_sel.empty ());
608 _scale->wrapped()->Enable (true);
609 _description->Enable (true);
610 _filters->Enable (true);
611 _filters_button->Enable (single && !ffmpeg_sel.empty ());
612 _colour_conversion->Enable (single && !video_sel.empty ());
613 _range->Enable (single && !video_sel.empty());
616 ContentList vc = _parent->selected_video ();
617 shared_ptr<Content> vcs;
622 if (vcs && vcs->video->colour_conversion ()) {
623 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
625 _edit_colour_conversion_button->Enable (false);
630 VideoPanel::fade_in_changed ()
632 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
633 int const vfr = i->active_video_frame_rate (_parent->film());
634 i->video->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
639 VideoPanel::fade_out_changed ()
641 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
642 int const vfr = i->active_video_frame_rate (_parent->film());
643 i->video->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
648 VideoPanel::use_clicked ()
650 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
651 i->video->set_use (_use->GetValue());
656 VideoPanel::reference_clicked ()
658 ContentList c = _parent->selected ();
663 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
668 d->set_reference_video (_reference->GetValue ());