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 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
79 _reference = new wxCheckBox (this, wxID_ANY, _("Use this DCP's video as OV and make VF"));
80 reference_sizer->Add (_reference, 0, wxLEFT | wxRIGHT | wxTOP, DCPOMATIC_SIZER_GAP);
82 _reference_note = new wxStaticText (this, wxID_ANY, _(""));
83 _reference_note->Wrap (200);
84 reference_sizer->Add (_reference_note, 0, wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
85 wxFont font = _reference_note->GetFont();
86 font.SetStyle(wxFONTSTYLE_ITALIC);
87 font.SetPointSize(font.GetPointSize() - 1);
88 _reference_note->SetFont(font);
90 _sizer->Add (reference_sizer);
92 _grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
93 _sizer->Add (_grid, 0, wxALL, 8);
95 _type_label = create_label (this, _("Type"), true);
96 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
98 new wxChoice (this, wxID_ANY),
99 VideoContentProperty::FRAME_TYPE,
101 boost::mem_fn (&VideoContent::frame_type),
102 boost::mem_fn (&VideoContent::set_frame_type),
103 &caster<int, VideoFrameType>,
104 &caster<VideoFrameType, int>
107 _crop_label = create_label (this, _("Crop"), true);
109 _left_crop_label = create_label (this, _("Left"), true);
110 _left_crop = new ContentSpinCtrl<VideoContent> (
112 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
113 VideoContentProperty::CROP,
115 boost::mem_fn (&VideoContent::left_crop),
116 boost::mem_fn (&VideoContent::set_left_crop)
119 _right_crop_label = create_label (this, _("Right"), true);
120 _right_crop = new ContentSpinCtrl<VideoContent> (
122 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
123 VideoContentProperty::CROP,
125 boost::mem_fn (&VideoContent::right_crop),
126 boost::mem_fn (&VideoContent::set_right_crop)
129 _top_crop_label = create_label (this, _("Top"), true);
130 _top_crop = new ContentSpinCtrl<VideoContent> (
132 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
133 VideoContentProperty::CROP,
135 boost::mem_fn (&VideoContent::top_crop),
136 boost::mem_fn (&VideoContent::set_top_crop)
139 _bottom_crop_label = create_label (this, _("Bottom"), true);
140 _bottom_crop = new ContentSpinCtrl<VideoContent> (
142 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
143 VideoContentProperty::CROP,
145 boost::mem_fn (&VideoContent::bottom_crop),
146 boost::mem_fn (&VideoContent::set_bottom_crop)
149 _fade_in_label = create_label (this, _("Fade in"), true);
150 _fade_in = new Timecode<ContentTime> (this);
152 _fade_out_label = create_label (this, _("Fade out"), true);
153 _fade_out = new Timecode<ContentTime> (this);
155 _scale_to_label = create_label (this, _("Scale to"), true);
156 _scale = new ContentChoice<VideoContent, VideoContentScale> (
158 new wxChoice (this, wxID_ANY),
159 VideoContentProperty::SCALE,
161 boost::mem_fn (&VideoContent::scale),
162 boost::mem_fn (&VideoContent::set_scale),
167 wxClientDC dc (this);
168 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
171 _filters_label = create_label (this, _("Filters"), true);
172 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
173 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
175 _colour_conversion_label = create_label (this, _("Colour conversion"), true);
176 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
177 _colour_conversion->Append (_("None"));
178 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
179 _colour_conversion->Append (std_to_wx (i.name));
182 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
183 _colour_conversion->Append (S_("Colour|Custom"));
184 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
186 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
187 _description->SetFont(font);
189 _left_crop->wrapped()->SetRange (0, 1024);
190 _top_crop->wrapped()->SetRange (0, 1024);
191 _right_crop->wrapped()->SetRange (0, 1024);
192 _bottom_crop->wrapped()->SetRange (0, 1024);
194 _scale->wrapped()->Clear ();
195 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
196 _scale->wrapped()->Append (std_to_wx (i.name ()));
199 _frame_type->wrapped()->Append (_("2D"));
200 _frame_type->wrapped()->Append (_("3D"));
201 _frame_type->wrapped()->Append (_("3D left/right"));
202 _frame_type->wrapped()->Append (_("3D top/bottom"));
203 _frame_type->wrapped()->Append (_("3D alternate"));
204 _frame_type->wrapped()->Append (_("3D left only"));
205 _frame_type->wrapped()->Append (_("3D right only"));
207 content_selection_changed ();
209 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
210 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
212 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
213 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
214 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
215 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
217 Config::instance()->Changed.connect (boost::bind (&VideoPanel::config_changed, this, _1));
223 VideoPanel::config_changed (Config::Property p)
225 if (p == Config::INTERFACE_COMPLEXITY) {
234 VideoPanel::add_to_grid ()
236 Config::Interface const interface = Config::instance()->interface_complexity();
240 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
241 _frame_type->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
244 add_label_to_sizer (_grid, _crop_label, true, wxGBPosition(r, 0));
247 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
248 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
249 _left_crop->add (crop, wxGBPosition (cr, 1));
250 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
251 _right_crop->add (crop, wxGBPosition (cr, 3));
253 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
254 _top_crop->add (crop, wxGBPosition (cr, 1));
255 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
256 _bottom_crop->add (crop, wxGBPosition (cr, 3));
257 _grid->Add (crop, wxGBPosition (r, 1), wxGBSpan (2, 3));
260 _fade_in_label->Show (interface == Config::INTERFACE_FULL);
261 _fade_in->Show (interface == Config::INTERFACE_FULL);
262 _fade_out_label->Show (interface == Config::INTERFACE_FULL);
263 _fade_out->Show (interface == Config::INTERFACE_FULL);
264 _scale_to_label->Show (interface == Config::INTERFACE_FULL);
265 _scale->show (interface == Config::INTERFACE_FULL);
266 _filters_label->Show (interface == Config::INTERFACE_FULL);
267 _filters->Show (interface == Config::INTERFACE_FULL);
268 _filters_button->Show (interface == Config::INTERFACE_FULL);
269 _colour_conversion_label->Show (interface == Config::INTERFACE_FULL);
270 _colour_conversion->Show (interface == Config::INTERFACE_FULL);
271 _edit_colour_conversion_button->Show (interface == Config::INTERFACE_FULL);
273 if (interface == Config::INTERFACE_FULL) {
274 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
275 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
278 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
279 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
282 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
283 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
286 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
288 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
289 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
290 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
291 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
295 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
297 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
298 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
299 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
300 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
305 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
311 VideoPanel::film_changed (Film::Property property)
314 case Film::VIDEO_FRAME_RATE:
315 case Film::CONTAINER:
316 setup_description ();
317 setup_sensitivity ();
319 case Film::RESOLUTION:
320 setup_description ();
322 case Film::REEL_TYPE:
324 setup_sensitivity ();
332 VideoPanel::film_content_changed (int property)
334 ContentList vc = _parent->selected_video ();
335 shared_ptr<Content> vcs;
336 shared_ptr<FFmpegContent> fcs;
339 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
342 if (property == ContentProperty::VIDEO_FRAME_RATE ||
343 property == VideoContentProperty::FRAME_TYPE ||
344 property == VideoContentProperty::CROP ||
345 property == VideoContentProperty::SCALE) {
346 setup_description ();
347 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
348 if (vcs && vcs->video->colour_conversion ()) {
349 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
350 vector<PresetColourConversion> cc = PresetColourConversion::all ();
352 checked_set (_colour_conversion, preset.get() + 1);
354 checked_set (_colour_conversion, cc.size() + 1);
357 checked_set (_colour_conversion, 0);
360 setup_sensitivity ();
362 } else if (property == FFmpegContentProperty::FILTERS) {
364 string p = Filter::ffmpeg_string (fcs->filters ());
366 checked_set (_filters, _("None"));
368 if (p.length() > 25) {
369 p = p.substr (0, 25) + "...";
371 checked_set (_filters, p);
374 } else if (property == VideoContentProperty::FADE_IN) {
376 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
377 check.insert (i->video->fade_in ());
380 if (check.size() == 1) {
382 ContentTime::from_frames (vc.front()->video->fade_in (), vc.front()->active_video_frame_rate ()),
383 vc.front()->active_video_frame_rate ()
388 } else if (property == VideoContentProperty::FADE_OUT) {
390 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
391 check.insert (i->video->fade_out ());
394 if (check.size() == 1) {
396 ContentTime::from_frames (vc.front()->video->fade_out (), vc.front()->active_video_frame_rate ()),
397 vc.front()->active_video_frame_rate ()
402 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
403 if (vc.size() == 1) {
404 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
405 checked_set (_reference, dcp ? dcp->reference_video () : false);
407 checked_set (_reference, false);
410 setup_sensitivity ();
414 /** Called when the `Edit filters' button has been clicked */
416 VideoPanel::edit_filters_clicked ()
418 FFmpegContentList c = _parent->selected_ffmpeg ();
423 FilterDialog* d = new FilterDialog (this, c.front()->filters());
424 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
430 VideoPanel::setup_description ()
432 ContentList vc = _parent->selected_video ();
434 checked_set (_description, wxT (""));
436 } else if (vc.size() > 1) {
437 checked_set (_description, _("Multiple content selected"));
441 string d = vc.front()->video->processing_description ();
442 size_t lines = count (d.begin(), d.end(), '\n');
444 for (int i = lines; i < 6; ++i) {
448 checked_set (_description, d);
453 VideoPanel::colour_conversion_changed ()
455 ContentList vc = _parent->selected_video ();
456 if (vc.size() != 1) {
460 int const s = _colour_conversion->GetSelection ();
461 vector<PresetColourConversion> all = PresetColourConversion::all ();
464 vc.front()->video->unset_colour_conversion ();
465 } else if (s == int (all.size() + 1)) {
466 edit_colour_conversion_clicked ();
468 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
473 VideoPanel::edit_colour_conversion_clicked ()
475 ContentList vc = _parent->selected_video ();
476 if (vc.size() != 1) {
480 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
481 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
482 if (d->ShowModal() == wxID_OK) {
483 vc.front()->video->set_colour_conversion (d->get ());
485 /* Reset the colour conversion choice */
486 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
492 VideoPanel::content_selection_changed ()
494 ContentList video_sel = _parent->selected_video ();
496 _frame_type->set_content (video_sel);
497 _left_crop->set_content (video_sel);
498 _right_crop->set_content (video_sel);
499 _top_crop->set_content (video_sel);
500 _bottom_crop->set_content (video_sel);
501 _scale->set_content (video_sel);
503 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
504 film_content_changed (VideoContentProperty::CROP);
505 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
506 film_content_changed (VideoContentProperty::FADE_IN);
507 film_content_changed (VideoContentProperty::FADE_OUT);
508 film_content_changed (FFmpegContentProperty::FILTERS);
509 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
511 setup_sensitivity ();
515 VideoPanel::setup_sensitivity ()
517 ContentList sel = _parent->selected ();
519 shared_ptr<DCPContent> dcp;
520 if (sel.size() == 1) {
521 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
525 bool const can_reference = dcp && dcp->can_reference_video (why_not);
526 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
528 if (_reference->GetValue ()) {
529 _frame_type->wrapped()->Enable (false);
530 _left_crop->wrapped()->Enable (false);
531 _right_crop->wrapped()->Enable (false);
532 _top_crop->wrapped()->Enable (false);
533 _bottom_crop->wrapped()->Enable (false);
534 _fade_in->Enable (false);
535 _fade_out->Enable (false);
536 _scale->wrapped()->Enable (false);
537 _description->Enable (false);
538 _filters->Enable (false);
539 _filters_button->Enable (false);
540 _colour_conversion->Enable (false);
542 ContentList video_sel = _parent->selected_video ();
543 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
544 bool const single = video_sel.size() == 1;
546 _frame_type->wrapped()->Enable (true);
547 _left_crop->wrapped()->Enable (true);
548 _right_crop->wrapped()->Enable (true);
549 _top_crop->wrapped()->Enable (true);
550 _bottom_crop->wrapped()->Enable (true);
551 _fade_in->Enable (!video_sel.empty ());
552 _fade_out->Enable (!video_sel.empty ());
553 _scale->wrapped()->Enable (true);
554 _description->Enable (true);
555 _filters->Enable (true);
556 _filters_button->Enable (single && !ffmpeg_sel.empty ());
557 _colour_conversion->Enable (single && !video_sel.empty ());
560 ContentList vc = _parent->selected_video ();
561 shared_ptr<Content> vcs;
566 if (vcs && vcs->video->colour_conversion ()) {
567 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
569 _edit_colour_conversion_button->Enable (false);
574 VideoPanel::fade_in_changed ()
576 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
577 int const vfr = _parent->film()->video_frame_rate ();
578 i->video->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
583 VideoPanel::fade_out_changed ()
585 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
586 int const vfr = _parent->film()->video_frame_rate ();
587 i->video->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
592 VideoPanel::reference_clicked ()
594 ContentList c = _parent->selected ();
599 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
604 d->set_reference_video (_reference->GetValue ());