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 "lib/filter.h"
30 #include "lib/ffmpeg_content.h"
31 #include "lib/colour_conversion.h"
32 #include "lib/config.h"
34 #include "lib/ratio.h"
35 #include "lib/frame_rate_change.h"
36 #include "lib/dcp_content.h"
37 #include "lib/video_content.h"
38 #include <wx/spinctrl.h>
39 #include <boost/foreach.hpp>
49 using boost::shared_ptr;
50 using boost::dynamic_pointer_cast;
52 using boost::optional;
54 static VideoContentScale
55 index_to_scale (int n)
57 vector<VideoContentScale> scales = VideoContentScale::all ();
58 DCPOMATIC_ASSERT (n >= 0);
59 DCPOMATIC_ASSERT (n < int (scales.size ()));
64 scale_to_index (VideoContentScale scale)
66 vector<VideoContentScale> scales = VideoContentScale::all ();
67 for (size_t i = 0; i < scales.size(); ++i) {
68 if (scales[i] == scale) {
73 DCPOMATIC_ASSERT (false);
76 VideoPanel::VideoPanel (ContentPanel* p)
77 : ContentSubPanel (p, _("Video"))
79 _reference = new CheckBox (this, _("Use this DCP's video as OV and make VF"));
80 _reference_note = new StaticText (this, wxT(""));
81 _reference_note->Wrap (200);
82 wxFont font = _reference_note->GetFont();
83 font.SetStyle(wxFONTSTYLE_ITALIC);
84 font.SetPointSize(font.GetPointSize() - 1);
85 _reference_note->SetFont(font);
87 _type_label = create_label (this, _("Type"), true);
88 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
90 new wxChoice (this, wxID_ANY),
91 VideoContentProperty::FRAME_TYPE,
93 boost::mem_fn (&VideoContent::frame_type),
94 boost::mem_fn (&VideoContent::set_frame_type),
95 &caster<int, VideoFrameType>,
96 &caster<VideoFrameType, int>
99 _left_crop_label = create_label (this, _("Left crop"), true);
100 _left_crop = new ContentSpinCtrl<VideoContent> (
102 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
103 VideoContentProperty::CROP,
105 boost::mem_fn (&VideoContent::left_crop),
106 boost::mem_fn (&VideoContent::set_left_crop)
109 _right_crop_label = create_label (this, _("Right crop"), true);
110 _right_crop = new ContentSpinCtrl<VideoContent> (
112 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
113 VideoContentProperty::CROP,
115 boost::mem_fn (&VideoContent::right_crop),
116 boost::mem_fn (&VideoContent::set_right_crop)
119 _top_crop_label = create_label (this, _("Top crop"), true);
120 _top_crop = new ContentSpinCtrl<VideoContent> (
122 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
123 VideoContentProperty::CROP,
125 boost::mem_fn (&VideoContent::top_crop),
126 boost::mem_fn (&VideoContent::set_top_crop)
129 _bottom_crop_label = create_label (this, _("Bottom crop"), true);
130 _bottom_crop = new ContentSpinCtrl<VideoContent> (
132 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
133 VideoContentProperty::CROP,
135 boost::mem_fn (&VideoContent::bottom_crop),
136 boost::mem_fn (&VideoContent::set_bottom_crop)
139 _fade_in_label = create_label (this, _("Fade in"), true);
140 _fade_in = new Timecode<ContentTime> (this);
142 _fade_out_label = create_label (this, _("Fade out"), true);
143 _fade_out = new Timecode<ContentTime> (this);
145 _scale_to_label = create_label (this, _("Scale to"), true);
146 _scale = new ContentChoice<VideoContent, VideoContentScale> (
148 new wxChoice (this, wxID_ANY),
149 VideoContentProperty::SCALE,
151 boost::mem_fn (&VideoContent::scale),
152 boost::mem_fn (&VideoContent::set_scale),
157 wxClientDC dc (this);
158 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
161 _filters_label = create_label (this, _("Filters"), true);
162 _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
163 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
165 _colour_conversion_label = create_label (this, _("Colour conversion"), true);
166 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
167 _colour_conversion->Append (_("None"));
168 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
169 _colour_conversion->Append (std_to_wx (i.name));
172 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
173 _colour_conversion->Append (S_("Colour|Custom"));
174 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
176 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
177 _description->SetFont(font);
179 _left_crop->wrapped()->SetRange (0, 4096);
180 _top_crop->wrapped()->SetRange (0, 4096);
181 _right_crop->wrapped()->SetRange (0, 4096);
182 _bottom_crop->wrapped()->SetRange (0, 4096);
184 _scale->wrapped()->Clear ();
185 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
186 _scale->wrapped()->Append (std_to_wx (i.name ()));
189 _frame_type->wrapped()->Append (_("2D"));
190 _frame_type->wrapped()->Append (_("3D"));
191 _frame_type->wrapped()->Append (_("3D left/right"));
192 _frame_type->wrapped()->Append (_("3D top/bottom"));
193 _frame_type->wrapped()->Append (_("3D alternate"));
194 _frame_type->wrapped()->Append (_("3D left only"));
195 _frame_type->wrapped()->Append (_("3D right only"));
197 content_selection_changed ();
199 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
200 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
202 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
203 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
204 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
205 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
211 VideoPanel::add_to_grid ()
213 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
217 _reference->Show (full);
218 _reference_note->Show (full);
221 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
222 reference_sizer->Add (_reference, 0);
223 reference_sizer->Add (_reference_note, 0);
224 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
228 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
229 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
233 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
234 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
235 _left_crop->add (crop, wxGBPosition (cr, 1));
236 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
237 _right_crop->add (crop, wxGBPosition (cr, 3));
239 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
240 _top_crop->add (crop, wxGBPosition (cr, 1));
241 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
242 _bottom_crop->add (crop, wxGBPosition (cr, 3));
243 _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
246 _fade_in_label->Show (full);
247 _fade_in->Show (full);
248 _fade_out_label->Show (full);
249 _fade_out->Show (full);
250 _scale_to_label->Show (full);
252 _filters_label->Show (full);
253 _filters->Show (full);
254 _filters_button->Show (full);
255 _colour_conversion_label->Show (full);
256 _colour_conversion->Show (full);
257 _edit_colour_conversion_button->Show (full);
260 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
261 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
264 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
265 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
268 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
269 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
272 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
274 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
275 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
276 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
277 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
281 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
283 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
284 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
285 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
286 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
291 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
297 VideoPanel::film_changed (Film::Property property)
300 case Film::VIDEO_FRAME_RATE:
301 case Film::CONTAINER:
302 case Film::RESOLUTION:
303 setup_description ();
304 setup_sensitivity ();
306 case Film::REEL_TYPE:
308 setup_sensitivity ();
316 VideoPanel::film_content_changed (int property)
318 ContentList vc = _parent->selected_video ();
319 shared_ptr<Content> vcs;
320 shared_ptr<FFmpegContent> fcs;
323 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
326 if (property == ContentProperty::VIDEO_FRAME_RATE ||
327 property == VideoContentProperty::FRAME_TYPE ||
328 property == VideoContentProperty::CROP ||
329 property == VideoContentProperty::SCALE) {
330 setup_description ();
331 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
332 if (vcs && vcs->video->colour_conversion ()) {
333 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
334 vector<PresetColourConversion> cc = PresetColourConversion::all ();
336 checked_set (_colour_conversion, preset.get() + 1);
338 checked_set (_colour_conversion, cc.size() + 1);
341 checked_set (_colour_conversion, 0);
344 setup_sensitivity ();
346 } else if (property == FFmpegContentProperty::FILTERS) {
348 string p = Filter::ffmpeg_string (fcs->filters ());
350 checked_set (_filters, _("None"));
352 if (p.length() > 25) {
353 p = p.substr (0, 25) + "...";
355 checked_set (_filters, p);
358 } else if (property == VideoContentProperty::FADE_IN) {
360 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
361 check.insert (i->video->fade_in ());
364 if (check.size() == 1) {
366 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
367 vc.front()->active_video_frame_rate(_parent->film())
372 } else if (property == VideoContentProperty::FADE_OUT) {
374 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
375 check.insert (i->video->fade_out ());
378 if (check.size() == 1) {
380 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
381 vc.front()->active_video_frame_rate(_parent->film())
386 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
387 if (vc.size() == 1) {
388 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
389 checked_set (_reference, dcp ? dcp->reference_video () : false);
391 checked_set (_reference, false);
394 setup_sensitivity ();
398 /** Called when the `Edit filters' button has been clicked */
400 VideoPanel::edit_filters_clicked ()
402 FFmpegContentList c = _parent->selected_ffmpeg ();
407 FilterDialog* d = new FilterDialog (this, c.front()->filters());
408 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
414 VideoPanel::setup_description ()
416 ContentList vc = _parent->selected_video ();
418 checked_set (_description, wxT (""));
420 } else if (vc.size() > 1) {
421 checked_set (_description, _("Multiple content selected"));
425 string d = vc.front()->video->processing_description (_parent->film());
426 size_t lines = count (d.begin(), d.end(), '\n');
428 for (int i = lines; i < 6; ++i) {
432 checked_set (_description, d);
437 VideoPanel::colour_conversion_changed ()
439 ContentList vc = _parent->selected_video ();
440 if (vc.size() != 1) {
444 int const s = _colour_conversion->GetSelection ();
445 vector<PresetColourConversion> all = PresetColourConversion::all ();
448 vc.front()->video->unset_colour_conversion ();
449 } else if (s == int (all.size() + 1)) {
450 edit_colour_conversion_clicked ();
452 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
457 VideoPanel::edit_colour_conversion_clicked ()
459 ContentList vc = _parent->selected_video ();
460 if (vc.size() != 1) {
464 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
465 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
466 if (d->ShowModal() == wxID_OK) {
467 vc.front()->video->set_colour_conversion (d->get ());
469 /* Reset the colour conversion choice */
470 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
476 VideoPanel::content_selection_changed ()
478 ContentList video_sel = _parent->selected_video ();
480 _frame_type->set_content (video_sel);
481 _left_crop->set_content (video_sel);
482 _right_crop->set_content (video_sel);
483 _top_crop->set_content (video_sel);
484 _bottom_crop->set_content (video_sel);
485 _scale->set_content (video_sel);
487 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
488 film_content_changed (VideoContentProperty::CROP);
489 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
490 film_content_changed (VideoContentProperty::FADE_IN);
491 film_content_changed (VideoContentProperty::FADE_OUT);
492 film_content_changed (FFmpegContentProperty::FILTERS);
493 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
495 setup_sensitivity ();
499 VideoPanel::setup_sensitivity ()
501 ContentList sel = _parent->selected ();
503 shared_ptr<DCPContent> dcp;
504 if (sel.size() == 1) {
505 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
509 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
510 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
512 if (_reference->GetValue ()) {
513 _frame_type->wrapped()->Enable (false);
514 _left_crop->wrapped()->Enable (false);
515 _right_crop->wrapped()->Enable (false);
516 _top_crop->wrapped()->Enable (false);
517 _bottom_crop->wrapped()->Enable (false);
518 _fade_in->Enable (false);
519 _fade_out->Enable (false);
520 _scale->wrapped()->Enable (false);
521 _description->Enable (false);
522 _filters->Enable (false);
523 _filters_button->Enable (false);
524 _colour_conversion->Enable (false);
526 ContentList video_sel = _parent->selected_video ();
527 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
528 bool const single = video_sel.size() == 1;
530 _frame_type->wrapped()->Enable (true);
531 _left_crop->wrapped()->Enable (true);
532 _right_crop->wrapped()->Enable (true);
533 _top_crop->wrapped()->Enable (true);
534 _bottom_crop->wrapped()->Enable (true);
535 _fade_in->Enable (!video_sel.empty ());
536 _fade_out->Enable (!video_sel.empty ());
537 _scale->wrapped()->Enable (true);
538 _description->Enable (true);
539 _filters->Enable (true);
540 _filters_button->Enable (single && !ffmpeg_sel.empty ());
541 _colour_conversion->Enable (single && !video_sel.empty ());
544 ContentList vc = _parent->selected_video ();
545 shared_ptr<Content> vcs;
550 if (vcs && vcs->video->colour_conversion ()) {
551 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
553 _edit_colour_conversion_button->Enable (false);
558 VideoPanel::fade_in_changed ()
560 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
561 int const vfr = _parent->film()->video_frame_rate ();
562 i->video->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
567 VideoPanel::fade_out_changed ()
569 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
570 int const vfr = _parent->film()->video_frame_rate ();
571 i->video->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
576 VideoPanel::reference_clicked ()
578 ContentList c = _parent->selected ();
583 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
588 d->set_reference_video (_reference->GetValue ());