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 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
179 _description->SetFont(font);
181 _left_crop->wrapped()->SetRange (0, 4096);
182 _top_crop->wrapped()->SetRange (0, 4096);
183 _right_crop->wrapped()->SetRange (0, 4096);
184 _bottom_crop->wrapped()->SetRange (0, 4096);
186 _scale->wrapped()->Clear ();
187 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
188 _scale->wrapped()->Append (std_to_wx (i.name ()));
191 _frame_type->wrapped()->Append (_("2D"));
192 _frame_type->wrapped()->Append (_("3D"));
193 _frame_type->wrapped()->Append (_("3D left/right"));
194 _frame_type->wrapped()->Append (_("3D top/bottom"));
195 _frame_type->wrapped()->Append (_("3D alternate"));
196 _frame_type->wrapped()->Append (_("3D left only"));
197 _frame_type->wrapped()->Append (_("3D right only"));
199 content_selection_changed ();
201 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
202 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
204 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
205 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
206 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
207 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
213 VideoPanel::add_to_grid ()
215 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
219 _reference->Show (full);
220 _reference_note->Show (full);
223 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
224 reference_sizer->Add (_reference, 0);
225 reference_sizer->Add (_reference_note, 0);
226 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
230 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
231 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
235 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
236 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
237 _left_crop->add (crop, wxGBPosition (cr, 1));
238 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
239 _right_crop->add (crop, wxGBPosition (cr, 3));
241 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
242 _top_crop->add (crop, wxGBPosition (cr, 1));
243 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
244 _bottom_crop->add (crop, wxGBPosition (cr, 3));
245 _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
248 _scale_to_label->Show (full);
250 _filters_label->Show (full);
251 _filters->Show (full);
252 _filters_button->Show (full);
253 _colour_conversion_label->Show (full);
254 _colour_conversion->Show (full);
255 _edit_colour_conversion_button->Show (full);
257 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
258 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
261 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
262 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
266 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
267 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
270 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
272 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
273 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
274 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
275 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
279 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
281 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
282 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
283 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
284 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
289 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
295 VideoPanel::film_changed (Film::Property property)
298 case Film::VIDEO_FRAME_RATE:
299 case Film::CONTAINER:
300 case Film::RESOLUTION:
301 setup_description ();
302 setup_sensitivity ();
304 case Film::REEL_TYPE:
306 setup_sensitivity ();
314 VideoPanel::film_content_changed (int property)
316 ContentList vc = _parent->selected_video ();
317 shared_ptr<Content> vcs;
318 shared_ptr<FFmpegContent> fcs;
321 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
324 if (property == ContentProperty::VIDEO_FRAME_RATE ||
325 property == VideoContentProperty::FRAME_TYPE ||
326 property == VideoContentProperty::CROP ||
327 property == VideoContentProperty::SCALE) {
328 setup_description ();
329 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
330 if (vcs && vcs->video->colour_conversion ()) {
331 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
332 vector<PresetColourConversion> cc = PresetColourConversion::all ();
334 checked_set (_colour_conversion, preset.get() + 1);
336 checked_set (_colour_conversion, cc.size() + 1);
339 checked_set (_colour_conversion, 0);
342 setup_sensitivity ();
344 } else if (property == FFmpegContentProperty::FILTERS) {
346 string p = Filter::ffmpeg_string (fcs->filters ());
348 checked_set (_filters, _("None"));
350 if (p.length() > 25) {
351 p = p.substr (0, 25) + "...";
353 checked_set (_filters, p);
356 } else if (property == VideoContentProperty::FADE_IN) {
358 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
359 check.insert (i->video->fade_in ());
362 if (check.size() == 1) {
364 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
365 vc.front()->active_video_frame_rate(_parent->film())
370 } else if (property == VideoContentProperty::FADE_OUT) {
372 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
373 check.insert (i->video->fade_out ());
376 if (check.size() == 1) {
378 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
379 vc.front()->active_video_frame_rate(_parent->film())
384 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
385 if (vc.size() == 1) {
386 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
387 checked_set (_reference, dcp ? dcp->reference_video () : false);
389 checked_set (_reference, false);
392 setup_sensitivity ();
396 /** Called when the `Edit filters' button has been clicked */
398 VideoPanel::edit_filters_clicked ()
400 FFmpegContentList c = _parent->selected_ffmpeg ();
405 FilterDialog* d = new FilterDialog (this, c.front()->filters());
406 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
412 VideoPanel::setup_description ()
414 ContentList vc = _parent->selected_video ();
416 checked_set (_description, wxT (""));
418 } else if (vc.size() > 1) {
419 checked_set (_description, _("Multiple content selected"));
423 string d = vc.front()->video->processing_description (_parent->film());
424 size_t lines = count (d.begin(), d.end(), '\n');
426 for (int i = lines; i < 6; ++i) {
430 checked_set (_description, d);
435 VideoPanel::colour_conversion_changed ()
437 ContentList vc = _parent->selected_video ();
438 if (vc.size() != 1) {
442 int const s = _colour_conversion->GetSelection ();
443 vector<PresetColourConversion> all = PresetColourConversion::all ();
446 vc.front()->video->unset_colour_conversion ();
447 } else if (s == int (all.size() + 1)) {
448 edit_colour_conversion_clicked ();
450 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
455 VideoPanel::edit_colour_conversion_clicked ()
457 ContentList vc = _parent->selected_video ();
458 if (vc.size() != 1) {
462 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
463 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
464 if (d->ShowModal() == wxID_OK) {
465 vc.front()->video->set_colour_conversion (d->get ());
467 /* Reset the colour conversion choice */
468 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
474 VideoPanel::content_selection_changed ()
476 ContentList video_sel = _parent->selected_video ();
478 _frame_type->set_content (video_sel);
479 _left_crop->set_content (video_sel);
480 _right_crop->set_content (video_sel);
481 _top_crop->set_content (video_sel);
482 _bottom_crop->set_content (video_sel);
483 _scale->set_content (video_sel);
485 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
486 film_content_changed (VideoContentProperty::CROP);
487 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
488 film_content_changed (VideoContentProperty::FADE_IN);
489 film_content_changed (VideoContentProperty::FADE_OUT);
490 film_content_changed (FFmpegContentProperty::FILTERS);
491 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
493 setup_sensitivity ();
497 VideoPanel::setup_sensitivity ()
499 ContentList sel = _parent->selected ();
501 shared_ptr<DCPContent> dcp;
502 if (sel.size() == 1) {
503 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
507 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
508 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
510 if (_reference->GetValue ()) {
511 _frame_type->wrapped()->Enable (false);
512 _left_crop->wrapped()->Enable (false);
513 _right_crop->wrapped()->Enable (false);
514 _top_crop->wrapped()->Enable (false);
515 _bottom_crop->wrapped()->Enable (false);
516 _fade_in->Enable (false);
517 _fade_out->Enable (false);
518 _scale->wrapped()->Enable (false);
519 _description->Enable (false);
520 _filters->Enable (false);
521 _filters_button->Enable (false);
522 _colour_conversion->Enable (false);
524 ContentList video_sel = _parent->selected_video ();
525 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
526 bool const single = video_sel.size() == 1;
528 _frame_type->wrapped()->Enable (true);
529 _left_crop->wrapped()->Enable (true);
530 _right_crop->wrapped()->Enable (true);
531 _top_crop->wrapped()->Enable (true);
532 _bottom_crop->wrapped()->Enable (true);
533 _fade_in->Enable (!video_sel.empty ());
534 _fade_out->Enable (!video_sel.empty ());
535 _scale->wrapped()->Enable (true);
536 _description->Enable (true);
537 _filters->Enable (true);
538 _filters_button->Enable (single && !ffmpeg_sel.empty ());
539 _colour_conversion->Enable (single && !video_sel.empty ());
542 ContentList vc = _parent->selected_video ();
543 shared_ptr<Content> vcs;
548 if (vcs && vcs->video->colour_conversion ()) {
549 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
551 _edit_colour_conversion_button->Enable (false);
556 VideoPanel::fade_in_changed ()
558 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
559 int const vfr = _parent->film()->video_frame_rate ();
560 i->video->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
565 VideoPanel::fade_out_changed ()
567 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
568 int const vfr = _parent->film()->video_frame_rate ();
569 i->video->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
574 VideoPanel::reference_clicked ()
576 ContentList c = _parent->selected ();
581 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
586 d->set_reference_video (_reference->GetValue ());