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 _crop_label = create_label (this, _("Crop"), true);
102 _left_crop_label = create_label (this, _("Left"), true);
103 _left_crop = new ContentSpinCtrl<VideoContent> (
105 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
106 VideoContentProperty::CROP,
108 boost::mem_fn (&VideoContent::left_crop),
109 boost::mem_fn (&VideoContent::set_left_crop)
112 _right_crop_label = create_label (this, _("Right"), true);
113 _right_crop = new ContentSpinCtrl<VideoContent> (
115 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
116 VideoContentProperty::CROP,
118 boost::mem_fn (&VideoContent::right_crop),
119 boost::mem_fn (&VideoContent::set_right_crop)
122 _top_crop_label = create_label (this, _("Top"), true);
123 _top_crop = new ContentSpinCtrl<VideoContent> (
125 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
126 VideoContentProperty::CROP,
128 boost::mem_fn (&VideoContent::top_crop),
129 boost::mem_fn (&VideoContent::set_top_crop)
132 _bottom_crop_label = create_label (this, _("Bottom"), true);
133 _bottom_crop = new ContentSpinCtrl<VideoContent> (
135 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
136 VideoContentProperty::CROP,
138 boost::mem_fn (&VideoContent::bottom_crop),
139 boost::mem_fn (&VideoContent::set_bottom_crop)
142 _fade_in_label = create_label (this, _("Fade in"), true);
143 _fade_in = new Timecode<ContentTime> (this);
145 _fade_out_label = create_label (this, _("Fade out"), true);
146 _fade_out = new Timecode<ContentTime> (this);
148 _scale_to_label = create_label (this, _("Scale to"), true);
149 _scale = new ContentChoice<VideoContent, VideoContentScale> (
151 new wxChoice (this, wxID_ANY),
152 VideoContentProperty::SCALE,
154 boost::mem_fn (&VideoContent::scale),
155 boost::mem_fn (&VideoContent::set_scale),
160 wxClientDC dc (this);
161 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
164 _filters_label = create_label (this, _("Filters"), true);
165 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
166 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
168 _colour_conversion_label = create_label (this, _("Colour conversion"), true);
169 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
170 _colour_conversion->Append (_("None"));
171 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
172 _colour_conversion->Append (std_to_wx (i.name));
175 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
176 _colour_conversion->Append (S_("Colour|Custom"));
177 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
179 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
180 _description->SetFont(font);
182 _left_crop->wrapped()->SetRange (0, 1024);
183 _top_crop->wrapped()->SetRange (0, 1024);
184 _right_crop->wrapped()->SetRange (0, 1024);
185 _bottom_crop->wrapped()->SetRange (0, 1024);
187 _scale->wrapped()->Clear ();
188 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
189 _scale->wrapped()->Append (std_to_wx (i.name ()));
192 _frame_type->wrapped()->Append (_("2D"));
193 _frame_type->wrapped()->Append (_("3D"));
194 _frame_type->wrapped()->Append (_("3D left/right"));
195 _frame_type->wrapped()->Append (_("3D top/bottom"));
196 _frame_type->wrapped()->Append (_("3D alternate"));
197 _frame_type->wrapped()->Append (_("3D left only"));
198 _frame_type->wrapped()->Append (_("3D right only"));
200 content_selection_changed ();
202 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
203 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
205 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
206 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
207 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
208 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
210 Config::instance()->Changed.connect (boost::bind (&VideoPanel::config_changed, this, _1));
216 VideoPanel::config_changed (Config::Property p)
218 if (p == Config::INTERFACE_COMPLEXITY) {
227 VideoPanel::add_to_grid ()
229 Config::Interface const interface = Config::instance()->interface_complexity();
233 _reference->Show (interface == Config::INTERFACE_FULL);
234 _reference_note->Show (interface == Config::INTERFACE_FULL);
236 if (interface == Config::INTERFACE_FULL) {
237 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
238 reference_sizer->Add (_reference, 0);
239 reference_sizer->Add (_reference_note, 0);
240 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
244 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
245 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
250 flags |= wxALIGN_RIGHT;
252 _grid->Add (_crop_label, wxGBPosition(r, 0), wxDefaultSpan, flags, DCPOMATIC_SIZER_Y_GAP / 2);
255 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
256 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
257 _left_crop->add (crop, wxGBPosition (cr, 1));
258 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
259 _right_crop->add (crop, wxGBPosition (cr, 3));
261 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
262 _top_crop->add (crop, wxGBPosition (cr, 1));
263 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
264 _bottom_crop->add (crop, wxGBPosition (cr, 3));
265 _grid->Add (crop, wxGBPosition (r, 1), wxGBSpan (2, 3));
268 _fade_in_label->Show (interface == Config::INTERFACE_FULL);
269 _fade_in->Show (interface == Config::INTERFACE_FULL);
270 _fade_out_label->Show (interface == Config::INTERFACE_FULL);
271 _fade_out->Show (interface == Config::INTERFACE_FULL);
272 _scale_to_label->Show (interface == Config::INTERFACE_FULL);
273 _scale->show (interface == Config::INTERFACE_FULL);
274 _filters_label->Show (interface == Config::INTERFACE_FULL);
275 _filters->Show (interface == Config::INTERFACE_FULL);
276 _filters_button->Show (interface == Config::INTERFACE_FULL);
277 _colour_conversion_label->Show (interface == Config::INTERFACE_FULL);
278 _colour_conversion->Show (interface == Config::INTERFACE_FULL);
279 _edit_colour_conversion_button->Show (interface == Config::INTERFACE_FULL);
281 if (interface == Config::INTERFACE_FULL) {
282 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
283 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
286 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
287 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
290 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
291 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
294 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
296 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
297 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
298 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
299 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
303 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
305 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
306 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
307 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
308 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
313 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
319 VideoPanel::film_changed (Film::Property property)
322 case Film::VIDEO_FRAME_RATE:
323 case Film::CONTAINER:
324 setup_description ();
325 setup_sensitivity ();
327 case Film::RESOLUTION:
328 setup_description ();
330 case Film::REEL_TYPE:
332 setup_sensitivity ();
340 VideoPanel::film_content_changed (int property)
342 ContentList vc = _parent->selected_video ();
343 shared_ptr<Content> vcs;
344 shared_ptr<FFmpegContent> fcs;
347 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
350 if (property == ContentProperty::VIDEO_FRAME_RATE ||
351 property == VideoContentProperty::FRAME_TYPE ||
352 property == VideoContentProperty::CROP ||
353 property == VideoContentProperty::SCALE) {
354 setup_description ();
355 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
356 if (vcs && vcs->video->colour_conversion ()) {
357 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
358 vector<PresetColourConversion> cc = PresetColourConversion::all ();
360 checked_set (_colour_conversion, preset.get() + 1);
362 checked_set (_colour_conversion, cc.size() + 1);
365 checked_set (_colour_conversion, 0);
368 setup_sensitivity ();
370 } else if (property == FFmpegContentProperty::FILTERS) {
372 string p = Filter::ffmpeg_string (fcs->filters ());
374 checked_set (_filters, _("None"));
376 if (p.length() > 25) {
377 p = p.substr (0, 25) + "...";
379 checked_set (_filters, p);
382 } else if (property == VideoContentProperty::FADE_IN) {
384 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
385 check.insert (i->video->fade_in ());
388 if (check.size() == 1) {
390 ContentTime::from_frames (vc.front()->video->fade_in (), vc.front()->active_video_frame_rate ()),
391 vc.front()->active_video_frame_rate ()
396 } else if (property == VideoContentProperty::FADE_OUT) {
398 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
399 check.insert (i->video->fade_out ());
402 if (check.size() == 1) {
404 ContentTime::from_frames (vc.front()->video->fade_out (), vc.front()->active_video_frame_rate ()),
405 vc.front()->active_video_frame_rate ()
410 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
411 if (vc.size() == 1) {
412 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
413 checked_set (_reference, dcp ? dcp->reference_video () : false);
415 checked_set (_reference, false);
418 setup_sensitivity ();
422 /** Called when the `Edit filters' button has been clicked */
424 VideoPanel::edit_filters_clicked ()
426 FFmpegContentList c = _parent->selected_ffmpeg ();
431 FilterDialog* d = new FilterDialog (this, c.front()->filters());
432 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
438 VideoPanel::setup_description ()
440 ContentList vc = _parent->selected_video ();
442 checked_set (_description, wxT (""));
444 } else if (vc.size() > 1) {
445 checked_set (_description, _("Multiple content selected"));
449 string d = vc.front()->video->processing_description ();
450 size_t lines = count (d.begin(), d.end(), '\n');
452 for (int i = lines; i < 6; ++i) {
456 checked_set (_description, d);
461 VideoPanel::colour_conversion_changed ()
463 ContentList vc = _parent->selected_video ();
464 if (vc.size() != 1) {
468 int const s = _colour_conversion->GetSelection ();
469 vector<PresetColourConversion> all = PresetColourConversion::all ();
472 vc.front()->video->unset_colour_conversion ();
473 } else if (s == int (all.size() + 1)) {
474 edit_colour_conversion_clicked ();
476 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
481 VideoPanel::edit_colour_conversion_clicked ()
483 ContentList vc = _parent->selected_video ();
484 if (vc.size() != 1) {
488 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
489 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
490 if (d->ShowModal() == wxID_OK) {
491 vc.front()->video->set_colour_conversion (d->get ());
493 /* Reset the colour conversion choice */
494 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
500 VideoPanel::content_selection_changed ()
502 ContentList video_sel = _parent->selected_video ();
504 _frame_type->set_content (video_sel);
505 _left_crop->set_content (video_sel);
506 _right_crop->set_content (video_sel);
507 _top_crop->set_content (video_sel);
508 _bottom_crop->set_content (video_sel);
509 _scale->set_content (video_sel);
511 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
512 film_content_changed (VideoContentProperty::CROP);
513 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
514 film_content_changed (VideoContentProperty::FADE_IN);
515 film_content_changed (VideoContentProperty::FADE_OUT);
516 film_content_changed (FFmpegContentProperty::FILTERS);
517 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
519 setup_sensitivity ();
523 VideoPanel::setup_sensitivity ()
525 ContentList sel = _parent->selected ();
527 shared_ptr<DCPContent> dcp;
528 if (sel.size() == 1) {
529 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
533 bool const can_reference = dcp && dcp->can_reference_video (why_not);
534 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
536 if (_reference->GetValue ()) {
537 _frame_type->wrapped()->Enable (false);
538 _left_crop->wrapped()->Enable (false);
539 _right_crop->wrapped()->Enable (false);
540 _top_crop->wrapped()->Enable (false);
541 _bottom_crop->wrapped()->Enable (false);
542 _fade_in->Enable (false);
543 _fade_out->Enable (false);
544 _scale->wrapped()->Enable (false);
545 _description->Enable (false);
546 _filters->Enable (false);
547 _filters_button->Enable (false);
548 _colour_conversion->Enable (false);
550 ContentList video_sel = _parent->selected_video ();
551 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
552 bool const single = video_sel.size() == 1;
554 _frame_type->wrapped()->Enable (true);
555 _left_crop->wrapped()->Enable (true);
556 _right_crop->wrapped()->Enable (true);
557 _top_crop->wrapped()->Enable (true);
558 _bottom_crop->wrapped()->Enable (true);
559 _fade_in->Enable (!video_sel.empty ());
560 _fade_out->Enable (!video_sel.empty ());
561 _scale->wrapped()->Enable (true);
562 _description->Enable (true);
563 _filters->Enable (true);
564 _filters_button->Enable (single && !ffmpeg_sel.empty ());
565 _colour_conversion->Enable (single && !video_sel.empty ());
568 ContentList vc = _parent->selected_video ();
569 shared_ptr<Content> vcs;
574 if (vcs && vcs->video->colour_conversion ()) {
575 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
577 _edit_colour_conversion_button->Enable (false);
582 VideoPanel::fade_in_changed ()
584 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
585 int const vfr = _parent->film()->video_frame_rate ();
586 i->video->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
591 VideoPanel::fade_out_changed ()
593 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
594 int const vfr = _parent->film()->video_frame_rate ();
595 i->video->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
600 VideoPanel::reference_clicked ()
602 ContentList c = _parent->selected ();
607 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
612 d->set_reference_video (_reference->GetValue ());