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 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
78 _sizer->Add (grid, 0, wxALL, 8);
82 _reference = new wxCheckBox (this, wxID_ANY, _("Refer to existing DCP"));
83 grid->Add (_reference, wxGBPosition (r, 0), wxGBSpan (1, 2));
86 add_label_to_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
87 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
89 new wxChoice (this, wxID_ANY),
90 VideoContentProperty::FRAME_TYPE,
92 boost::mem_fn (&VideoContent::frame_type),
93 boost::mem_fn (&VideoContent::set_frame_type),
94 &caster<int, VideoFrameType>,
95 &caster<VideoFrameType, int>
97 _frame_type->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
100 add_label_to_sizer (grid, this, _("Crop"), true, wxGBPosition (r, 0));
103 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
105 add_label_to_sizer (crop, this, _("Left"), true, wxGBPosition (cr, 0));
106 _left_crop = new ContentSpinCtrl<VideoContent> (
108 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
109 VideoContentProperty::CROP,
111 boost::mem_fn (&VideoContent::left_crop),
112 boost::mem_fn (&VideoContent::set_left_crop)
114 _left_crop->add (crop, wxGBPosition (cr, 1));
116 add_label_to_sizer (crop, this, _("Right"), true, wxGBPosition (cr, 2));
117 _right_crop = new ContentSpinCtrl<VideoContent> (
119 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
120 VideoContentProperty::CROP,
122 boost::mem_fn (&VideoContent::right_crop),
123 boost::mem_fn (&VideoContent::set_right_crop)
125 _right_crop->add (crop, wxGBPosition (cr, 3));
129 add_label_to_sizer (crop, this, _("Top"), true, wxGBPosition (cr, 0));
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)
138 _top_crop->add (crop, wxGBPosition (cr, 1));
140 add_label_to_sizer (crop, this, _("Bottom"), true, wxGBPosition (cr, 2));
141 _bottom_crop = new ContentSpinCtrl<VideoContent> (
143 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
144 VideoContentProperty::CROP,
146 boost::mem_fn (&VideoContent::bottom_crop),
147 boost::mem_fn (&VideoContent::set_bottom_crop)
149 _bottom_crop->add (crop, wxGBPosition (cr, 3));
151 grid->Add (crop, wxGBPosition (r, 1), wxGBSpan (2, 3));
154 add_label_to_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0));
155 _fade_in = new Timecode<ContentTime> (this);
156 grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
159 add_label_to_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0));
160 _fade_out = new Timecode<ContentTime> (this);
161 grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
164 add_label_to_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
165 _scale = new ContentChoice<VideoContent, VideoContentScale> (
167 new wxChoice (this, wxID_ANY),
168 VideoContentProperty::SCALE,
170 boost::mem_fn (&VideoContent::scale),
171 boost::mem_fn (&VideoContent::set_scale),
175 _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
178 wxClientDC dc (this);
179 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
182 add_label_to_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
184 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
186 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
187 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
188 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
189 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
191 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
195 add_label_to_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
197 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
199 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
200 _colour_conversion->Append (_("None"));
201 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
202 _colour_conversion->Append (std_to_wx (i.name));
205 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
206 _colour_conversion->Append (S_("Colour|Custom"));
207 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
209 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
210 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
212 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
216 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
217 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
218 wxFont font = _description->GetFont();
219 font.SetStyle(wxFONTSTYLE_ITALIC);
220 font.SetPointSize(font.GetPointSize() - 1);
221 _description->SetFont(font);
224 _left_crop->wrapped()->SetRange (0, 1024);
225 _top_crop->wrapped()->SetRange (0, 1024);
226 _right_crop->wrapped()->SetRange (0, 1024);
227 _bottom_crop->wrapped()->SetRange (0, 1024);
229 _scale->wrapped()->Clear ();
230 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
231 _scale->wrapped()->Append (std_to_wx (i.name ()));
234 _frame_type->wrapped()->Append (_("2D"));
235 _frame_type->wrapped()->Append (_("3D"));
236 _frame_type->wrapped()->Append (_("3D left/right"));
237 _frame_type->wrapped()->Append (_("3D top/bottom"));
238 _frame_type->wrapped()->Append (_("3D alternate"));
239 _frame_type->wrapped()->Append (_("3D left only"));
240 _frame_type->wrapped()->Append (_("3D right only"));
242 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
243 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
245 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&VideoPanel::reference_clicked, this));
246 _filters_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_filters_clicked, this));
247 _colour_conversion->Bind (wxEVT_CHOICE, boost::bind (&VideoPanel::colour_conversion_changed, this));
248 _edit_colour_conversion_button->Bind (wxEVT_BUTTON, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
252 VideoPanel::film_changed (Film::Property property)
255 case Film::VIDEO_FRAME_RATE:
256 case Film::CONTAINER:
257 setup_description ();
258 setup_sensitivity ();
260 case Film::RESOLUTION:
261 setup_description ();
263 case Film::REEL_TYPE:
265 setup_sensitivity ();
273 VideoPanel::film_content_changed (int property)
275 ContentList vc = _parent->selected_video ();
276 shared_ptr<Content> vcs;
277 shared_ptr<FFmpegContent> fcs;
280 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
283 if (property == ContentProperty::VIDEO_FRAME_RATE ||
284 property == VideoContentProperty::FRAME_TYPE ||
285 property == VideoContentProperty::CROP ||
286 property == VideoContentProperty::SCALE) {
287 setup_description ();
288 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
289 if (vcs && vcs->video->colour_conversion ()) {
290 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
291 vector<PresetColourConversion> cc = PresetColourConversion::all ();
293 checked_set (_colour_conversion, preset.get() + 1);
295 checked_set (_colour_conversion, cc.size() + 1);
298 checked_set (_colour_conversion, 0);
301 setup_sensitivity ();
303 } else if (property == FFmpegContentProperty::FILTERS) {
305 string p = Filter::ffmpeg_string (fcs->filters ());
307 checked_set (_filters, _("None"));
309 if (p.length() > 25) {
310 p = p.substr (0, 25) + "...";
312 checked_set (_filters, p);
315 } else if (property == VideoContentProperty::FADE_IN) {
317 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
318 check.insert (i->video->fade_in ());
321 if (check.size() == 1) {
323 ContentTime::from_frames (vc.front()->video->fade_in (), vc.front()->active_video_frame_rate ()),
324 vc.front()->active_video_frame_rate ()
329 } else if (property == VideoContentProperty::FADE_OUT) {
331 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
332 check.insert (i->video->fade_out ());
335 if (check.size() == 1) {
337 ContentTime::from_frames (vc.front()->video->fade_out (), vc.front()->active_video_frame_rate ()),
338 vc.front()->active_video_frame_rate ()
343 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
344 if (vc.size() == 1) {
345 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
346 checked_set (_reference, dcp ? dcp->reference_video () : false);
348 checked_set (_reference, false);
351 setup_sensitivity ();
355 /** Called when the `Edit filters' button has been clicked */
357 VideoPanel::edit_filters_clicked ()
359 FFmpegContentList c = _parent->selected_ffmpeg ();
364 FilterDialog* d = new FilterDialog (this, c.front()->filters());
365 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
371 VideoPanel::setup_description ()
373 ContentList vc = _parent->selected_video ();
375 checked_set (_description, wxT (""));
377 } else if (vc.size() > 1) {
378 checked_set (_description, _("Multiple content selected"));
382 string d = vc.front()->video->processing_description ();
383 size_t lines = count (d.begin(), d.end(), '\n');
385 for (int i = lines; i < 6; ++i) {
389 checked_set (_description, d);
394 VideoPanel::colour_conversion_changed ()
396 ContentList vc = _parent->selected_video ();
397 if (vc.size() != 1) {
401 int const s = _colour_conversion->GetSelection ();
402 vector<PresetColourConversion> all = PresetColourConversion::all ();
405 vc.front()->video->unset_colour_conversion ();
406 } else if (s == int (all.size() + 1)) {
407 edit_colour_conversion_clicked ();
409 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
414 VideoPanel::edit_colour_conversion_clicked ()
416 ContentList vc = _parent->selected_video ();
417 if (vc.size() != 1) {
421 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
422 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
423 if (d->ShowModal() == wxID_OK) {
424 vc.front()->video->set_colour_conversion (d->get ());
426 /* Reset the colour conversion choice */
427 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
433 VideoPanel::content_selection_changed ()
435 ContentList video_sel = _parent->selected_video ();
437 _frame_type->set_content (video_sel);
438 _left_crop->set_content (video_sel);
439 _right_crop->set_content (video_sel);
440 _top_crop->set_content (video_sel);
441 _bottom_crop->set_content (video_sel);
442 _scale->set_content (video_sel);
444 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
445 film_content_changed (VideoContentProperty::CROP);
446 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
447 film_content_changed (VideoContentProperty::FADE_IN);
448 film_content_changed (VideoContentProperty::FADE_OUT);
449 film_content_changed (FFmpegContentProperty::FILTERS);
450 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
452 setup_sensitivity ();
456 VideoPanel::setup_sensitivity ()
458 ContentList sel = _parent->selected ();
460 shared_ptr<DCPContent> dcp;
461 if (sel.size() == 1) {
462 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
465 list<string> why_not;
466 bool const can_reference = dcp && dcp->can_reference_video (why_not);
467 setup_refer_button (_reference, dcp, can_reference, why_not);
469 if (_reference->GetValue ()) {
470 _frame_type->wrapped()->Enable (false);
471 _left_crop->wrapped()->Enable (false);
472 _right_crop->wrapped()->Enable (false);
473 _top_crop->wrapped()->Enable (false);
474 _bottom_crop->wrapped()->Enable (false);
475 _fade_in->Enable (false);
476 _fade_out->Enable (false);
477 _scale->wrapped()->Enable (false);
478 _description->Enable (false);
479 _filters->Enable (false);
480 _filters_button->Enable (false);
481 _colour_conversion->Enable (false);
483 ContentList video_sel = _parent->selected_video ();
484 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
485 bool const single = video_sel.size() == 1;
487 _frame_type->wrapped()->Enable (true);
488 _left_crop->wrapped()->Enable (true);
489 _right_crop->wrapped()->Enable (true);
490 _top_crop->wrapped()->Enable (true);
491 _bottom_crop->wrapped()->Enable (true);
492 _fade_in->Enable (!video_sel.empty ());
493 _fade_out->Enable (!video_sel.empty ());
494 _scale->wrapped()->Enable (true);
495 _description->Enable (true);
496 _filters->Enable (true);
497 _filters_button->Enable (single && !ffmpeg_sel.empty ());
498 _colour_conversion->Enable (single && !video_sel.empty ());
501 ContentList vc = _parent->selected_video ();
502 shared_ptr<Content> vcs;
507 if (vcs && vcs->video->colour_conversion ()) {
508 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
510 _edit_colour_conversion_button->Enable (false);
515 VideoPanel::fade_in_changed ()
517 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
518 int const vfr = _parent->film()->video_frame_rate ();
519 i->video->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
524 VideoPanel::fade_out_changed ()
526 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
527 int const vfr = _parent->film()->video_frame_rate ();
528 i->video->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
533 VideoPanel::reference_clicked ()
535 ContentList c = _parent->selected ();
540 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
545 d->set_reference_video (_reference->GetValue ());