2 Copyright (C) 2012-2016 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 "lib/filter.h"
28 #include "lib/ffmpeg_content.h"
29 #include "lib/colour_conversion.h"
30 #include "lib/config.h"
32 #include "lib/ratio.h"
33 #include "lib/frame_rate_change.h"
34 #include "lib/dcp_content.h"
35 #include "lib/video_content.h"
36 #include <wx/spinctrl.h>
37 #include <boost/foreach.hpp>
47 using boost::shared_ptr;
48 using boost::dynamic_pointer_cast;
50 using boost::optional;
52 static VideoContentScale
53 index_to_scale (int n)
55 vector<VideoContentScale> scales = VideoContentScale::all ();
56 DCPOMATIC_ASSERT (n >= 0);
57 DCPOMATIC_ASSERT (n < int (scales.size ()));
62 scale_to_index (VideoContentScale scale)
64 vector<VideoContentScale> scales = VideoContentScale::all ();
65 for (size_t i = 0; i < scales.size(); ++i) {
66 if (scales[i] == scale) {
71 DCPOMATIC_ASSERT (false);
74 VideoPanel::VideoPanel (ContentPanel* p)
75 : ContentSubPanel (p, _("Video"))
77 _reference = new wxCheckBox (this, wxID_ANY, _("Use this DCP's video as OV and make VF"));
78 _reference_note = new wxStaticText (this, wxID_ANY, _(""));
79 _reference_note->Wrap (200);
80 wxFont font = _reference_note->GetFont();
81 font.SetStyle(wxFONTSTYLE_ITALIC);
82 font.SetPointSize(font.GetPointSize() - 1);
83 _reference_note->SetFont(font);
85 _grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
86 _sizer->Add (_grid, 0, wxALL, 8);
88 _type_label = create_label (this, _("Type"), true);
89 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
91 new wxChoice (this, wxID_ANY),
92 VideoContentProperty::FRAME_TYPE,
94 boost::mem_fn (&VideoContent::frame_type),
95 boost::mem_fn (&VideoContent::set_frame_type),
96 &caster<int, VideoFrameType>,
97 &caster<VideoFrameType, int>
100 _left_crop_label = create_label (this, _("Left crop"), true);
101 _left_crop = new ContentSpinCtrl<VideoContent> (
103 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
104 VideoContentProperty::CROP,
106 boost::mem_fn (&VideoContent::left_crop),
107 boost::mem_fn (&VideoContent::set_left_crop)
110 _right_crop_label = create_label (this, _("Right crop"), true);
111 _right_crop = new ContentSpinCtrl<VideoContent> (
113 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
114 VideoContentProperty::CROP,
116 boost::mem_fn (&VideoContent::right_crop),
117 boost::mem_fn (&VideoContent::set_right_crop)
120 _top_crop_label = create_label (this, _("Top crop"), true);
121 _top_crop = new ContentSpinCtrl<VideoContent> (
123 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
124 VideoContentProperty::CROP,
126 boost::mem_fn (&VideoContent::top_crop),
127 boost::mem_fn (&VideoContent::set_top_crop)
130 _bottom_crop_label = create_label (this, _("Bottom crop"), true);
131 _bottom_crop = new ContentSpinCtrl<VideoContent> (
133 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
134 VideoContentProperty::CROP,
136 boost::mem_fn (&VideoContent::bottom_crop),
137 boost::mem_fn (&VideoContent::set_bottom_crop)
140 _fade_in_label = create_label (this, _("Fade in"), true);
141 _fade_in = new Timecode<ContentTime> (this);
143 _fade_out_label = create_label (this, _("Fade out"), true);
144 _fade_out = new Timecode<ContentTime> (this);
146 _scale_to_label = create_label (this, _("Scale to"), true);
147 _scale = new ContentChoice<VideoContent, VideoContentScale> (
149 new wxChoice (this, wxID_ANY),
150 VideoContentProperty::SCALE,
152 boost::mem_fn (&VideoContent::scale),
153 boost::mem_fn (&VideoContent::set_scale),
158 wxClientDC dc (this);
159 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
162 _filters_label = create_label (this, _("Filters"), true);
163 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
164 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
166 _colour_conversion_label = create_label (this, _("Colour conversion"), true);
167 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
168 _colour_conversion->Append (_("None"));
169 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
170 _colour_conversion->Append (std_to_wx (i.name));
173 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
174 _colour_conversion->Append (S_("Colour|Custom"));
175 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
177 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
178 _description->SetFont(font);
180 _left_crop->wrapped()->SetRange (0, 1024);
181 _top_crop->wrapped()->SetRange (0, 1024);
182 _right_crop->wrapped()->SetRange (0, 1024);
183 _bottom_crop->wrapped()->SetRange (0, 1024);
185 _scale->wrapped()->Clear ();
186 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
187 _scale->wrapped()->Append (std_to_wx (i.name ()));
190 _frame_type->wrapped()->Append (_("2D"));
191 _frame_type->wrapped()->Append (_("3D"));
192 _frame_type->wrapped()->Append (_("3D left/right"));
193 _frame_type->wrapped()->Append (_("3D top/bottom"));
194 _frame_type->wrapped()->Append (_("3D alternate"));
195 _frame_type->wrapped()->Append (_("3D left only"));
196 _frame_type->wrapped()->Append (_("3D right only"));
198 content_selection_changed ();
200 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
201 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
203 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
204 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
205 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
206 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
208 Config::instance()->Changed.connect (boost::bind (&VideoPanel::config_changed, this, _1));
214 VideoPanel::config_changed (Config::Property p)
216 if (p == Config::INTERFACE_COMPLEXITY) {
225 VideoPanel::add_to_grid ()
227 Config::Interface const interface = Config::instance()->interface_complexity();
231 _reference->Show (interface == Config::INTERFACE_FULL);
232 _reference_note->Show (interface == Config::INTERFACE_FULL);
234 if (interface == Config::INTERFACE_FULL) {
235 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
236 reference_sizer->Add (_reference, 0);
237 reference_sizer->Add (_reference_note, 0);
238 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
242 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
243 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
248 flags |= wxALIGN_RIGHT;
251 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
252 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
253 _left_crop->add (crop, wxGBPosition (cr, 1));
254 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
255 _right_crop->add (crop, wxGBPosition (cr, 3));
257 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
258 _top_crop->add (crop, wxGBPosition (cr, 1));
259 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
260 _bottom_crop->add (crop, wxGBPosition (cr, 3));
261 _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
264 _fade_in_label->Show (interface == Config::INTERFACE_FULL);
265 _fade_in->Show (interface == Config::INTERFACE_FULL);
266 _fade_out_label->Show (interface == Config::INTERFACE_FULL);
267 _fade_out->Show (interface == Config::INTERFACE_FULL);
268 _scale_to_label->Show (interface == Config::INTERFACE_FULL);
269 _scale->show (interface == Config::INTERFACE_FULL);
270 _filters_label->Show (interface == Config::INTERFACE_FULL);
271 _filters->Show (interface == Config::INTERFACE_FULL);
272 _filters_button->Show (interface == Config::INTERFACE_FULL);
273 _colour_conversion_label->Show (interface == Config::INTERFACE_FULL);
274 _colour_conversion->Show (interface == Config::INTERFACE_FULL);
275 _edit_colour_conversion_button->Show (interface == Config::INTERFACE_FULL);
277 if (interface == Config::INTERFACE_FULL) {
278 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
279 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
282 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
283 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
286 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
287 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
290 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
292 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
293 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
294 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
295 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
299 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
301 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
302 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
303 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
304 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
309 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
315 VideoPanel::film_changed (Film::Property property)
318 case Film::VIDEO_FRAME_RATE:
319 case Film::CONTAINER:
320 setup_description ();
321 setup_sensitivity ();
323 case Film::RESOLUTION:
324 setup_description ();
326 case Film::REEL_TYPE:
328 setup_sensitivity ();
336 VideoPanel::film_content_changed (int property)
338 ContentList vc = _parent->selected_video ();
339 shared_ptr<Content> vcs;
340 shared_ptr<FFmpegContent> fcs;
343 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
346 if (property == ContentProperty::VIDEO_FRAME_RATE ||
347 property == VideoContentProperty::FRAME_TYPE ||
348 property == VideoContentProperty::CROP ||
349 property == VideoContentProperty::SCALE) {
350 setup_description ();
351 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
352 if (vcs && vcs->video->colour_conversion ()) {
353 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
354 vector<PresetColourConversion> cc = PresetColourConversion::all ();
356 checked_set (_colour_conversion, preset.get() + 1);
358 checked_set (_colour_conversion, cc.size() + 1);
361 checked_set (_colour_conversion, 0);
364 setup_sensitivity ();
366 } else if (property == FFmpegContentProperty::FILTERS) {
368 string p = Filter::ffmpeg_string (fcs->filters ());
370 checked_set (_filters, _("None"));
372 if (p.length() > 25) {
373 p = p.substr (0, 25) + "...";
375 checked_set (_filters, p);
378 } else if (property == VideoContentProperty::FADE_IN) {
380 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
381 check.insert (i->video->fade_in ());
384 if (check.size() == 1) {
386 ContentTime::from_frames (vc.front()->video->fade_in (), vc.front()->active_video_frame_rate ()),
387 vc.front()->active_video_frame_rate ()
392 } else if (property == VideoContentProperty::FADE_OUT) {
394 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
395 check.insert (i->video->fade_out ());
398 if (check.size() == 1) {
400 ContentTime::from_frames (vc.front()->video->fade_out (), vc.front()->active_video_frame_rate ()),
401 vc.front()->active_video_frame_rate ()
406 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
407 if (vc.size() == 1) {
408 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
409 checked_set (_reference, dcp ? dcp->reference_video () : false);
411 checked_set (_reference, false);
414 setup_sensitivity ();
418 /** Called when the `Edit filters' button has been clicked */
420 VideoPanel::edit_filters_clicked ()
422 FFmpegContentList c = _parent->selected_ffmpeg ();
427 FilterDialog* d = new FilterDialog (this, c.front()->filters());
428 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
434 VideoPanel::setup_description ()
436 ContentList vc = _parent->selected_video ();
438 checked_set (_description, wxT (""));
440 } else if (vc.size() > 1) {
441 checked_set (_description, _("Multiple content selected"));
445 string d = vc.front()->video->processing_description ();
446 size_t lines = count (d.begin(), d.end(), '\n');
448 for (int i = lines; i < 6; ++i) {
452 checked_set (_description, d);
457 VideoPanel::colour_conversion_changed ()
459 ContentList vc = _parent->selected_video ();
460 if (vc.size() != 1) {
464 int const s = _colour_conversion->GetSelection ();
465 vector<PresetColourConversion> all = PresetColourConversion::all ();
468 vc.front()->video->unset_colour_conversion ();
469 } else if (s == int (all.size() + 1)) {
470 edit_colour_conversion_clicked ();
472 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
477 VideoPanel::edit_colour_conversion_clicked ()
479 ContentList vc = _parent->selected_video ();
480 if (vc.size() != 1) {
484 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
485 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
486 if (d->ShowModal() == wxID_OK) {
487 vc.front()->video->set_colour_conversion (d->get ());
489 /* Reset the colour conversion choice */
490 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
496 VideoPanel::content_selection_changed ()
498 ContentList video_sel = _parent->selected_video ();
500 _frame_type->set_content (video_sel);
501 _left_crop->set_content (video_sel);
502 _right_crop->set_content (video_sel);
503 _top_crop->set_content (video_sel);
504 _bottom_crop->set_content (video_sel);
505 _scale->set_content (video_sel);
507 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
508 film_content_changed (VideoContentProperty::CROP);
509 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
510 film_content_changed (VideoContentProperty::FADE_IN);
511 film_content_changed (VideoContentProperty::FADE_OUT);
512 film_content_changed (FFmpegContentProperty::FILTERS);
513 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
515 setup_sensitivity ();
519 VideoPanel::setup_sensitivity ()
521 ContentList sel = _parent->selected ();
523 shared_ptr<DCPContent> dcp;
524 if (sel.size() == 1) {
525 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
529 bool const can_reference = dcp && dcp->can_reference_video (why_not);
530 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
532 if (_reference->GetValue ()) {
533 _frame_type->wrapped()->Enable (false);
534 _left_crop->wrapped()->Enable (false);
535 _right_crop->wrapped()->Enable (false);
536 _top_crop->wrapped()->Enable (false);
537 _bottom_crop->wrapped()->Enable (false);
538 _fade_in->Enable (false);
539 _fade_out->Enable (false);
540 _scale->wrapped()->Enable (false);
541 _description->Enable (false);
542 _filters->Enable (false);
543 _filters_button->Enable (false);
544 _colour_conversion->Enable (false);
546 ContentList video_sel = _parent->selected_video ();
547 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
548 bool const single = video_sel.size() == 1;
550 _frame_type->wrapped()->Enable (true);
551 _left_crop->wrapped()->Enable (true);
552 _right_crop->wrapped()->Enable (true);
553 _top_crop->wrapped()->Enable (true);
554 _bottom_crop->wrapped()->Enable (true);
555 _fade_in->Enable (!video_sel.empty ());
556 _fade_out->Enable (!video_sel.empty ());
557 _scale->wrapped()->Enable (true);
558 _description->Enable (true);
559 _filters->Enable (true);
560 _filters_button->Enable (single && !ffmpeg_sel.empty ());
561 _colour_conversion->Enable (single && !video_sel.empty ());
564 ContentList vc = _parent->selected_video ();
565 shared_ptr<Content> vcs;
570 if (vcs && vcs->video->colour_conversion ()) {
571 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
573 _edit_colour_conversion_button->Enable (false);
578 VideoPanel::fade_in_changed ()
580 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
581 int const vfr = _parent->film()->video_frame_rate ();
582 i->video->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
587 VideoPanel::fade_out_changed ()
589 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
590 int const vfr = _parent->film()->video_frame_rate ();
591 i->video->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
596 VideoPanel::reference_clicked ()
598 ContentList c = _parent->selected ();
603 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
608 d->set_reference_video (_reference->GetValue ());