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 _type_label = create_label (this, _("Type"), true);
90 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
92 new wxChoice (this, wxID_ANY),
93 VideoContentProperty::FRAME_TYPE,
95 boost::mem_fn (&VideoContent::frame_type),
96 boost::mem_fn (&VideoContent::set_frame_type),
97 &caster<int, VideoFrameType>,
98 &caster<VideoFrameType, int>
101 _left_crop_label = create_label (this, _("Left crop"), true);
102 _left_crop = new ContentSpinCtrl<VideoContent> (
104 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
105 VideoContentProperty::CROP,
107 boost::mem_fn (&VideoContent::left_crop),
108 boost::mem_fn (&VideoContent::set_left_crop)
111 _right_crop_label = create_label (this, _("Right crop"), true);
112 _right_crop = new ContentSpinCtrl<VideoContent> (
114 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
115 VideoContentProperty::CROP,
117 boost::mem_fn (&VideoContent::right_crop),
118 boost::mem_fn (&VideoContent::set_right_crop)
121 _top_crop_label = create_label (this, _("Top crop"), true);
122 _top_crop = new ContentSpinCtrl<VideoContent> (
124 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
125 VideoContentProperty::CROP,
127 boost::mem_fn (&VideoContent::top_crop),
128 boost::mem_fn (&VideoContent::set_top_crop)
131 _bottom_crop_label = create_label (this, _("Bottom crop"), true);
132 _bottom_crop = new ContentSpinCtrl<VideoContent> (
134 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
135 VideoContentProperty::CROP,
137 boost::mem_fn (&VideoContent::bottom_crop),
138 boost::mem_fn (&VideoContent::set_bottom_crop)
141 _fade_in_label = create_label (this, _("Fade in"), true);
142 _fade_in = new Timecode<ContentTime> (this);
144 _fade_out_label = create_label (this, _("Fade out"), true);
145 _fade_out = new Timecode<ContentTime> (this);
147 _scale_to_label = create_label (this, _("Scale to"), true);
148 _scale = new ContentChoice<VideoContent, VideoContentScale> (
150 new wxChoice (this, wxID_ANY),
151 VideoContentProperty::SCALE,
153 boost::mem_fn (&VideoContent::scale),
154 boost::mem_fn (&VideoContent::set_scale),
159 wxClientDC dc (this);
160 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
163 _filters_label = create_label (this, _("Filters"), true);
164 _filters = new StaticText (this, _("None"), wxDefaultPosition, size);
165 _filters_button = new Button (this, _("Edit..."));
167 _colour_conversion_label = create_label (this, _("Colour conversion"), true);
168 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
169 _colour_conversion->Append (_("None"));
170 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
171 _colour_conversion->Append (std_to_wx (i.name));
174 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
175 _colour_conversion->Append (S_("Colour|Custom"));
176 _edit_colour_conversion_button = new Button (this, _("Edit..."));
178 _range_label = create_label (this, _("Range"), true);
179 _range = new wxChoice (this, wxID_ANY);
180 _range->Append (_("Full (JPEG, 0-255)"));
181 _range->Append (_("Video (MPEG, 16-235)"));
183 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
184 _description->SetFont(font);
186 _left_crop->wrapped()->SetRange (0, 4096);
187 _top_crop->wrapped()->SetRange (0, 4096);
188 _right_crop->wrapped()->SetRange (0, 4096);
189 _bottom_crop->wrapped()->SetRange (0, 4096);
191 _scale->wrapped()->Clear ();
192 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
193 _scale->wrapped()->Append (std_to_wx (i.name ()));
196 _frame_type->wrapped()->Append (_("2D"));
197 _frame_type->wrapped()->Append (_("3D"));
198 _frame_type->wrapped()->Append (_("3D left/right"));
199 _frame_type->wrapped()->Append (_("3D top/bottom"));
200 _frame_type->wrapped()->Append (_("3D alternate"));
201 _frame_type->wrapped()->Append (_("3D left only"));
202 _frame_type->wrapped()->Append (_("3D right only"));
204 content_selection_changed ();
206 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
207 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
209 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
210 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
211 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
212 _range->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::range_changed, this));
213 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
219 VideoPanel::add_to_grid ()
221 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
225 _reference->Show (full);
226 _reference_note->Show (full);
229 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
230 reference_sizer->Add (_reference, 0);
231 reference_sizer->Add (_reference_note, 0);
232 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
236 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
237 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
241 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
242 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
243 _left_crop->add (crop, wxGBPosition (cr, 1));
244 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
245 _right_crop->add (crop, wxGBPosition (cr, 3));
247 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
248 _top_crop->add (crop, wxGBPosition (cr, 1));
249 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
250 _bottom_crop->add (crop, wxGBPosition (cr, 3));
251 _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
254 _scale_to_label->Show (full);
256 _filters_label->Show (full);
257 _filters->Show (full);
258 _filters_button->Show (full);
259 _colour_conversion_label->Show (full);
260 _colour_conversion->Show (full);
261 _edit_colour_conversion_button->Show (full);
262 _range_label->Show (full);
265 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
266 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
269 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
270 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
274 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
275 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
278 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
280 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
281 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
282 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
283 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
287 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
289 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
290 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
291 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
292 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
296 add_label_to_sizer (_grid, _range_label, true, wxGBPosition(r, 0));
297 _grid->Add (_range, wxGBPosition(r, 1), wxGBSpan(1, 2), wxALIGN_CENTER_VERTICAL);
301 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
306 VideoPanel::range_changed ()
308 ContentList vc = _parent->selected_video ();
309 if (vc.size() != 1) {
313 switch (_range->GetSelection()) {
315 vc.front()->video->set_range (VIDEO_RANGE_FULL);
318 vc.front()->video->set_range (VIDEO_RANGE_VIDEO);
321 DCPOMATIC_ASSERT (false);
327 VideoPanel::film_changed (Film::Property property)
330 case Film::VIDEO_FRAME_RATE:
331 case Film::CONTAINER:
332 case Film::RESOLUTION:
333 setup_description ();
334 setup_sensitivity ();
336 case Film::REEL_TYPE:
338 setup_sensitivity ();
346 VideoPanel::film_content_changed (int property)
348 ContentList vc = _parent->selected_video ();
349 shared_ptr<Content> vcs;
350 shared_ptr<FFmpegContent> fcs;
353 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
356 if (property == ContentProperty::VIDEO_FRAME_RATE ||
357 property == VideoContentProperty::FRAME_TYPE ||
358 property == VideoContentProperty::CROP ||
359 property == VideoContentProperty::SCALE) {
360 setup_description ();
361 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
362 if (vcs && vcs->video->colour_conversion ()) {
363 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
364 vector<PresetColourConversion> cc = PresetColourConversion::all ();
366 checked_set (_colour_conversion, preset.get() + 1);
368 checked_set (_colour_conversion, cc.size() + 1);
371 checked_set (_colour_conversion, 0);
374 setup_sensitivity ();
376 } else if (property == FFmpegContentProperty::FILTERS) {
378 string p = Filter::ffmpeg_string (fcs->filters ());
380 checked_set (_filters, _("None"));
382 if (p.length() > 25) {
383 p = p.substr (0, 25) + "...";
385 checked_set (_filters, p);
388 } else if (property == VideoContentProperty::FADE_IN) {
390 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
391 check.insert (i->video->fade_in ());
394 if (check.size() == 1) {
396 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
397 vc.front()->active_video_frame_rate(_parent->film())
402 } else if (property == VideoContentProperty::FADE_OUT) {
404 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
405 check.insert (i->video->fade_out ());
408 if (check.size() == 1) {
410 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
411 vc.front()->active_video_frame_rate(_parent->film())
416 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
417 if (vc.size() == 1) {
418 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
419 checked_set (_reference, dcp ? dcp->reference_video () : false);
421 checked_set (_reference, false);
424 setup_sensitivity ();
425 } else if (property == VideoContentProperty::RANGE) {
427 checked_set (_range, vcs->video->range() == VIDEO_RANGE_FULL ? 0 : 1);
429 checked_set (_range, 0);
432 setup_sensitivity ();
436 /** Called when the `Edit filters' button has been clicked */
438 VideoPanel::edit_filters_clicked ()
440 FFmpegContentList c = _parent->selected_ffmpeg ();
445 FilterDialog* d = new FilterDialog (this, c.front()->filters());
446 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
452 VideoPanel::setup_description ()
454 ContentList vc = _parent->selected_video ();
456 checked_set (_description, wxT (""));
458 } else if (vc.size() > 1) {
459 checked_set (_description, _("Multiple content selected"));
463 string d = vc.front()->video->processing_description (_parent->film());
464 size_t lines = count (d.begin(), d.end(), '\n');
466 for (int i = lines; i < 6; ++i) {
470 checked_set (_description, d);
475 VideoPanel::colour_conversion_changed ()
477 ContentList vc = _parent->selected_video ();
478 if (vc.size() != 1) {
482 int const s = _colour_conversion->GetSelection ();
483 vector<PresetColourConversion> all = PresetColourConversion::all ();
486 vc.front()->video->unset_colour_conversion ();
487 } else if (s == int (all.size() + 1)) {
488 edit_colour_conversion_clicked ();
490 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
495 VideoPanel::edit_colour_conversion_clicked ()
497 ContentList vc = _parent->selected_video ();
498 if (vc.size() != 1) {
502 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
503 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
504 if (d->ShowModal() == wxID_OK) {
505 vc.front()->video->set_colour_conversion (d->get ());
507 /* Reset the colour conversion choice */
508 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
514 VideoPanel::content_selection_changed ()
516 ContentList video_sel = _parent->selected_video ();
518 _frame_type->set_content (video_sel);
519 _left_crop->set_content (video_sel);
520 _right_crop->set_content (video_sel);
521 _top_crop->set_content (video_sel);
522 _bottom_crop->set_content (video_sel);
523 _scale->set_content (video_sel);
525 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
526 film_content_changed (VideoContentProperty::CROP);
527 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
528 film_content_changed (VideoContentProperty::FADE_IN);
529 film_content_changed (VideoContentProperty::FADE_OUT);
530 film_content_changed (VideoContentProperty::RANGE);
531 film_content_changed (FFmpegContentProperty::FILTERS);
532 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
534 setup_sensitivity ();
538 VideoPanel::setup_sensitivity ()
540 ContentList sel = _parent->selected ();
542 shared_ptr<DCPContent> dcp;
543 if (sel.size() == 1) {
544 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
548 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
549 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
551 if (_reference->GetValue ()) {
552 _frame_type->wrapped()->Enable (false);
553 _left_crop->wrapped()->Enable (false);
554 _right_crop->wrapped()->Enable (false);
555 _top_crop->wrapped()->Enable (false);
556 _bottom_crop->wrapped()->Enable (false);
557 _fade_in->Enable (false);
558 _fade_out->Enable (false);
559 _scale->wrapped()->Enable (false);
560 _description->Enable (false);
561 _filters->Enable (false);
562 _filters_button->Enable (false);
563 _colour_conversion->Enable (false);
564 _range->Enable (false);
566 ContentList video_sel = _parent->selected_video ();
567 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
568 bool const single = video_sel.size() == 1;
570 _frame_type->wrapped()->Enable (true);
571 _left_crop->wrapped()->Enable (true);
572 _right_crop->wrapped()->Enable (true);
573 _top_crop->wrapped()->Enable (true);
574 _bottom_crop->wrapped()->Enable (true);
575 _fade_in->Enable (!video_sel.empty ());
576 _fade_out->Enable (!video_sel.empty ());
577 _scale->wrapped()->Enable (true);
578 _description->Enable (true);
579 _filters->Enable (true);
580 _filters_button->Enable (single && !ffmpeg_sel.empty ());
581 _colour_conversion->Enable (single && !video_sel.empty ());
582 _range->Enable (single && !video_sel.empty());
585 ContentList vc = _parent->selected_video ();
586 shared_ptr<Content> vcs;
591 if (vcs && vcs->video->colour_conversion ()) {
592 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
594 _edit_colour_conversion_button->Enable (false);
599 VideoPanel::fade_in_changed ()
601 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
602 int const vfr = _parent->film()->video_frame_rate ();
603 i->video->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
608 VideoPanel::fade_out_changed ()
610 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
611 int const vfr = _parent->film()->video_frame_rate ();
612 i->video->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
617 VideoPanel::reference_clicked ()
619 ContentList c = _parent->selected ();
624 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
629 d->set_reference_video (_reference->GetValue ());