2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "filter_dialog.h"
21 #include "video_panel.h"
23 #include "content_colour_conversion_dialog.h"
24 #include "content_widget.h"
25 #include "content_panel.h"
26 #include "lib/filter.h"
27 #include "lib/ffmpeg_content.h"
28 #include "lib/colour_conversion.h"
29 #include "lib/config.h"
31 #include "lib/ratio.h"
32 #include "lib/frame_rate_change.h"
33 #include "lib/dcp_content.h"
34 #include "lib/video_content.h"
35 #include <wx/spinctrl.h>
36 #include <boost/foreach.hpp>
46 using boost::shared_ptr;
47 using boost::dynamic_pointer_cast;
49 using boost::optional;
51 static VideoContentScale
52 index_to_scale (int n)
54 vector<VideoContentScale> scales = VideoContentScale::all ();
55 DCPOMATIC_ASSERT (n >= 0);
56 DCPOMATIC_ASSERT (n < int (scales.size ()));
61 scale_to_index (VideoContentScale scale)
63 vector<VideoContentScale> scales = VideoContentScale::all ();
64 for (size_t i = 0; i < scales.size(); ++i) {
65 if (scales[i] == scale) {
70 DCPOMATIC_ASSERT (false);
73 VideoPanel::VideoPanel (ContentPanel* p)
74 : ContentSubPanel (p, _("Video"))
76 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
77 _sizer->Add (grid, 0, wxALL, 8);
81 _reference = new wxCheckBox (this, wxID_ANY, _("Refer to existing DCP"));
82 grid->Add (_reference, wxGBPosition (r, 0), wxGBSpan (1, 2));
85 add_label_to_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
86 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
88 new wxChoice (this, wxID_ANY),
89 VideoContentProperty::VIDEO_FRAME_TYPE,
90 boost::mem_fn (&VideoContent::video_frame_type),
91 boost::mem_fn (&VideoContent::set_video_frame_type),
92 &caster<int, VideoFrameType>,
93 &caster<VideoFrameType, int>
95 _frame_type->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
98 add_label_to_sizer (grid, this, _("Crop"), true, wxGBPosition (r, 0));
101 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
103 add_label_to_sizer (crop, this, _("Left"), true, wxGBPosition (cr, 0));
104 _left_crop = new ContentSpinCtrl<VideoContent> (
106 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
107 VideoContentProperty::VIDEO_CROP,
108 boost::mem_fn (&VideoContent::left_crop),
109 boost::mem_fn (&VideoContent::set_left_crop)
111 _left_crop->add (crop, wxGBPosition (cr, 1));
113 add_label_to_sizer (crop, this, _("Right"), true, wxGBPosition (cr, 2));
114 _right_crop = new ContentSpinCtrl<VideoContent> (
116 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
117 VideoContentProperty::VIDEO_CROP,
118 boost::mem_fn (&VideoContent::right_crop),
119 boost::mem_fn (&VideoContent::set_right_crop)
121 _right_crop->add (crop, wxGBPosition (cr, 3));
125 add_label_to_sizer (crop, this, _("Top"), true, wxGBPosition (cr, 0));
126 _top_crop = new ContentSpinCtrl<VideoContent> (
128 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
129 VideoContentProperty::VIDEO_CROP,
130 boost::mem_fn (&VideoContent::top_crop),
131 boost::mem_fn (&VideoContent::set_top_crop)
133 _top_crop->add (crop, wxGBPosition (cr, 1));
135 add_label_to_sizer (crop, this, _("Bottom"), true, wxGBPosition (cr, 2));
136 _bottom_crop = new ContentSpinCtrl<VideoContent> (
138 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
139 VideoContentProperty::VIDEO_CROP,
140 boost::mem_fn (&VideoContent::bottom_crop),
141 boost::mem_fn (&VideoContent::set_bottom_crop)
143 _bottom_crop->add (crop, wxGBPosition (cr, 3));
145 grid->Add (crop, wxGBPosition (r, 1), wxGBSpan (2, 3));
148 add_label_to_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0));
149 _fade_in = new Timecode<ContentTime> (this);
150 grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
153 add_label_to_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0));
154 _fade_out = new Timecode<ContentTime> (this);
155 grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
158 add_label_to_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
159 _scale = new ContentChoice<VideoContent, VideoContentScale> (
161 new wxChoice (this, wxID_ANY),
162 VideoContentProperty::VIDEO_SCALE,
163 boost::mem_fn (&VideoContent::scale),
164 boost::mem_fn (&VideoContent::set_scale),
168 _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
171 wxClientDC dc (this);
172 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
175 add_label_to_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
177 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
179 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
180 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
181 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
182 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
184 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
188 add_label_to_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
190 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
192 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
193 _colour_conversion->Append (_("None"));
194 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
195 _colour_conversion->Append (std_to_wx (i.name));
198 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
199 _colour_conversion->Append (S_("Colour|Custom"));
200 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
202 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
203 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
205 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
209 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
210 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
211 wxFont font = _description->GetFont();
212 font.SetStyle(wxFONTSTYLE_ITALIC);
213 font.SetPointSize(font.GetPointSize() - 1);
214 _description->SetFont(font);
217 _left_crop->wrapped()->SetRange (0, 1024);
218 _top_crop->wrapped()->SetRange (0, 1024);
219 _right_crop->wrapped()->SetRange (0, 1024);
220 _bottom_crop->wrapped()->SetRange (0, 1024);
222 _scale->wrapped()->Clear ();
223 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
224 _scale->wrapped()->Append (std_to_wx (i.name ()));
227 _frame_type->wrapped()->Append (_("2D"));
228 _frame_type->wrapped()->Append (_("3D left/right"));
229 _frame_type->wrapped()->Append (_("3D top/bottom"));
230 _frame_type->wrapped()->Append (_("3D alternate"));
231 _frame_type->wrapped()->Append (_("3D left only"));
232 _frame_type->wrapped()->Append (_("3D right only"));
234 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
235 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
237 _reference->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&VideoPanel::reference_clicked, this));
238 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
239 _colour_conversion->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::colour_conversion_changed, this));
240 _edit_colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
244 VideoPanel::film_changed (Film::Property property)
247 case Film::CONTAINER:
248 case Film::VIDEO_FRAME_RATE:
249 case Film::RESOLUTION:
250 setup_description ();
252 case Film::REEL_TYPE:
253 setup_sensitivity ();
260 VideoPanel::film_content_changed (int property)
262 ContentList vc = _parent->selected_video ();
263 shared_ptr<Content> vcs;
264 shared_ptr<FFmpegContent> fcs;
267 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
270 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
271 setup_description ();
272 } else if (property == VideoContentProperty::VIDEO_CROP) {
273 setup_description ();
274 } else if (property == VideoContentProperty::VIDEO_SCALE) {
275 setup_description ();
276 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
277 setup_description ();
278 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
279 if (vcs && vcs->video->colour_conversion ()) {
280 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
281 vector<PresetColourConversion> cc = PresetColourConversion::all ();
283 checked_set (_colour_conversion, preset.get() + 1);
285 checked_set (_colour_conversion, cc.size() + 1);
288 checked_set (_colour_conversion, 0);
291 setup_sensitivity ();
293 } else if (property == FFmpegContentProperty::FILTERS) {
295 string p = Filter::ffmpeg_string (fcs->filters ());
297 checked_set (_filters, _("None"));
299 if (p.length() > 25) {
300 p = p.substr (0, 25) + "...";
302 checked_set (_filters, p);
305 } else if (property == VideoContentProperty::VIDEO_FADE_IN) {
307 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
308 check.insert (i->video->fade_in ());
311 if (check.size() == 1) {
313 ContentTime::from_frames (vc.front()->video->fade_in (), vc.front()->video->video_frame_rate ()),
314 vc.front()->video->video_frame_rate ()
319 } else if (property == VideoContentProperty::VIDEO_FADE_OUT) {
321 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
322 check.insert (i->video->fade_out ());
325 if (check.size() == 1) {
327 ContentTime::from_frames (vc.front()->video->fade_out (), vc.front()->video->video_frame_rate ()),
328 vc.front()->video->video_frame_rate ()
333 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
334 if (vc.size() == 1) {
335 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
336 checked_set (_reference, dcp ? dcp->reference_video () : false);
338 checked_set (_reference, false);
341 setup_sensitivity ();
345 /** Called when the `Edit filters' button has been clicked */
347 VideoPanel::edit_filters_clicked ()
349 FFmpegContentList c = _parent->selected_ffmpeg ();
354 FilterDialog* d = new FilterDialog (this, c.front()->filters());
355 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
361 VideoPanel::setup_description ()
363 ContentList vc = _parent->selected_video ();
365 checked_set (_description, wxT (""));
367 } else if (vc.size() > 1) {
368 checked_set (_description, _("Multiple content selected"));
372 string d = vc.front()->video->processing_description ();
373 size_t lines = count (d.begin(), d.end(), '\n');
375 for (int i = lines; i < 6; ++i) {
379 checked_set (_description, d);
384 VideoPanel::colour_conversion_changed ()
386 ContentList vc = _parent->selected_video ();
387 if (vc.size() != 1) {
391 int const s = _colour_conversion->GetSelection ();
392 vector<PresetColourConversion> all = PresetColourConversion::all ();
395 vc.front()->video->unset_colour_conversion ();
396 } else if (s == int (all.size() + 1)) {
397 edit_colour_conversion_clicked ();
399 vc.front()->video->set_colour_conversion (all[s - 1].conversion);
404 VideoPanel::edit_colour_conversion_clicked ()
406 ContentList vc = _parent->selected_video ();
407 if (vc.size() != 1) {
411 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->yuv ());
412 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front ().conversion));
414 vc.front()->video->set_colour_conversion (d->get ());
419 VideoPanel::content_selection_changed ()
421 ContentList video_sel = _parent->selected_video ();
423 _frame_type->set_content (video_sel);
424 _left_crop->set_content (video_sel);
425 _right_crop->set_content (video_sel);
426 _top_crop->set_content (video_sel);
427 _bottom_crop->set_content (video_sel);
428 _scale->set_content (video_sel);
430 film_content_changed (VideoContentProperty::VIDEO_CROP);
431 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
432 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
433 film_content_changed (VideoContentProperty::VIDEO_FADE_IN);
434 film_content_changed (VideoContentProperty::VIDEO_FADE_OUT);
435 film_content_changed (FFmpegContentProperty::FILTERS);
436 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
438 setup_sensitivity ();
442 VideoPanel::setup_sensitivity ()
444 ContentList sel = _parent->selected ();
446 shared_ptr<DCPContent> dcp;
447 if (sel.size() == 1) {
448 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
451 list<string> why_not;
452 bool const can_reference = dcp && dcp->can_reference_video (why_not);
453 setup_refer_button (_reference, dcp, can_reference, why_not);
455 if (_reference->GetValue ()) {
456 _frame_type->wrapped()->Enable (false);
457 _left_crop->wrapped()->Enable (false);
458 _right_crop->wrapped()->Enable (false);
459 _top_crop->wrapped()->Enable (false);
460 _bottom_crop->wrapped()->Enable (false);
461 _fade_in->Enable (false);
462 _fade_out->Enable (false);
463 _scale->wrapped()->Enable (false);
464 _description->Enable (false);
465 _filters->Enable (false);
466 _filters_button->Enable (false);
467 _colour_conversion->Enable (false);
469 ContentList video_sel = _parent->selected_video ();
470 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
471 bool const single = video_sel.size() == 1;
473 _frame_type->wrapped()->Enable (true);
474 _left_crop->wrapped()->Enable (true);
475 _right_crop->wrapped()->Enable (true);
476 _top_crop->wrapped()->Enable (true);
477 _bottom_crop->wrapped()->Enable (true);
478 _fade_in->Enable (!video_sel.empty ());
479 _fade_out->Enable (!video_sel.empty ());
480 _scale->wrapped()->Enable (true);
481 _description->Enable (true);
482 _filters->Enable (true);
483 _filters_button->Enable (single && !ffmpeg_sel.empty ());
484 _colour_conversion->Enable (single && !video_sel.empty ());
487 ContentList vc = _parent->selected_video ();
488 shared_ptr<Content> vcs;
493 if (vcs && vcs->video->colour_conversion ()) {
494 _edit_colour_conversion_button->Enable (!vcs->colour_conversion().get().preset());
496 _edit_colour_conversion_button->Enable (false);
501 VideoPanel::fade_in_changed ()
503 BOOST_FOREACH (shared_ptr<VideoContent> i, _parent->selected_video ()) {
504 int const vfr = _parent->film()->video_frame_rate ();
505 i->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
510 VideoPanel::fade_out_changed ()
512 BOOST_FOREACH (shared_ptr<VideoContent> i, _parent->selected_video ()) {
513 int const vfr = _parent->film()->video_frame_rate ();
514 i->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
519 VideoPanel::reference_clicked ()
521 ContentList c = _parent->selected ();
526 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
531 d->set_reference_video (_reference->GetValue ());