2 Copyright (C) 2012-2015 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 <wx/spinctrl.h>
35 #include <boost/foreach.hpp>
45 using boost::shared_ptr;
46 using boost::dynamic_pointer_cast;
48 using boost::optional;
50 static VideoContentScale
51 index_to_scale (int n)
53 vector<VideoContentScale> scales = VideoContentScale::all ();
54 DCPOMATIC_ASSERT (n >= 0);
55 DCPOMATIC_ASSERT (n < int (scales.size ()));
60 scale_to_index (VideoContentScale scale)
62 vector<VideoContentScale> scales = VideoContentScale::all ();
63 for (size_t i = 0; i < scales.size(); ++i) {
64 if (scales[i] == scale) {
69 DCPOMATIC_ASSERT (false);
72 VideoPanel::VideoPanel (ContentPanel* p)
73 : ContentSubPanel (p, _("Video"))
75 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
76 _sizer->Add (grid, 0, wxALL, 8);
80 _reference = new wxCheckBox (this, wxID_ANY, _("Refer to existing DCP"));
81 grid->Add (_reference, wxGBPosition (r, 0), wxGBSpan (1, 2));
84 add_label_to_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
85 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
87 new wxChoice (this, wxID_ANY),
88 VideoContentProperty::VIDEO_FRAME_TYPE,
89 boost::mem_fn (&VideoContent::video_frame_type),
90 boost::mem_fn (&VideoContent::set_video_frame_type),
91 &caster<int, VideoFrameType>,
92 &caster<VideoFrameType, int>
94 _frame_type->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
97 add_label_to_sizer (grid, this, _("Crop"), true, wxGBPosition (r, 0));
100 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
102 add_label_to_sizer (crop, this, _("Left"), true, wxGBPosition (cr, 0));
103 _left_crop = new ContentSpinCtrl<VideoContent> (
105 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
106 VideoContentProperty::VIDEO_CROP,
107 boost::mem_fn (&VideoContent::left_crop),
108 boost::mem_fn (&VideoContent::set_left_crop)
110 _left_crop->add (crop, wxGBPosition (cr, 1));
112 add_label_to_sizer (crop, this, _("Right"), true, wxGBPosition (cr, 2));
113 _right_crop = new ContentSpinCtrl<VideoContent> (
115 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
116 VideoContentProperty::VIDEO_CROP,
117 boost::mem_fn (&VideoContent::right_crop),
118 boost::mem_fn (&VideoContent::set_right_crop)
120 _right_crop->add (crop, wxGBPosition (cr, 3));
124 add_label_to_sizer (crop, this, _("Top"), true, wxGBPosition (cr, 0));
125 _top_crop = new ContentSpinCtrl<VideoContent> (
127 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
128 VideoContentProperty::VIDEO_CROP,
129 boost::mem_fn (&VideoContent::top_crop),
130 boost::mem_fn (&VideoContent::set_top_crop)
132 _top_crop->add (crop, wxGBPosition (cr, 1));
134 add_label_to_sizer (crop, this, _("Bottom"), true, wxGBPosition (cr, 2));
135 _bottom_crop = new ContentSpinCtrl<VideoContent> (
137 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
138 VideoContentProperty::VIDEO_CROP,
139 boost::mem_fn (&VideoContent::bottom_crop),
140 boost::mem_fn (&VideoContent::set_bottom_crop)
142 _bottom_crop->add (crop, wxGBPosition (cr, 3));
144 grid->Add (crop, wxGBPosition (r, 1), wxGBSpan (2, 3));
147 add_label_to_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0));
148 _fade_in = new Timecode<ContentTime> (this);
149 grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
152 add_label_to_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0));
153 _fade_out = new Timecode<ContentTime> (this);
154 grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
157 add_label_to_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
158 _scale = new ContentChoice<VideoContent, VideoContentScale> (
160 new wxChoice (this, wxID_ANY),
161 VideoContentProperty::VIDEO_SCALE,
162 boost::mem_fn (&VideoContent::scale),
163 boost::mem_fn (&VideoContent::set_scale),
167 _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
170 wxClientDC dc (this);
171 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
174 add_label_to_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
176 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
178 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
179 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
180 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
181 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
183 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
187 add_label_to_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
189 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
191 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
192 _colour_conversion->Append (_("None"));
193 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
194 _colour_conversion->Append (std_to_wx (i.name));
197 /// TRANSLATORS: translate the word "Custom" here; do not include the "Colour|" prefix
198 _colour_conversion->Append (S_("Colour|Custom"));
199 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
201 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
202 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
204 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
208 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
209 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
210 wxFont font = _description->GetFont();
211 font.SetStyle(wxFONTSTYLE_ITALIC);
212 font.SetPointSize(font.GetPointSize() - 1);
213 _description->SetFont(font);
216 _left_crop->wrapped()->SetRange (0, 1024);
217 _top_crop->wrapped()->SetRange (0, 1024);
218 _right_crop->wrapped()->SetRange (0, 1024);
219 _bottom_crop->wrapped()->SetRange (0, 1024);
221 _scale->wrapped()->Clear ();
222 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
223 _scale->wrapped()->Append (std_to_wx (i.name ()));
226 _frame_type->wrapped()->Append (_("2D"));
227 _frame_type->wrapped()->Append (_("3D left/right"));
228 _frame_type->wrapped()->Append (_("3D top/bottom"));
229 _frame_type->wrapped()->Append (_("3D alternate"));
230 _frame_type->wrapped()->Append (_("3D left only"));
231 _frame_type->wrapped()->Append (_("3D right only"));
233 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
234 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
236 _reference->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&VideoPanel::reference_clicked, this));
237 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
238 _colour_conversion->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::colour_conversion_changed, this));
239 _edit_colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
243 VideoPanel::film_changed (Film::Property property)
246 case Film::CONTAINER:
247 case Film::VIDEO_FRAME_RATE:
248 case Film::RESOLUTION:
249 setup_description ();
251 case Film::REEL_TYPE:
252 setup_sensitivity ();
259 VideoPanel::film_content_changed (int property)
261 VideoContentList vc = _parent->selected_video ();
262 shared_ptr<VideoContent> vcs;
263 shared_ptr<FFmpegContent> fcs;
266 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
269 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
270 setup_description ();
271 } else if (property == VideoContentProperty::VIDEO_CROP) {
272 setup_description ();
273 } else if (property == VideoContentProperty::VIDEO_SCALE) {
274 setup_description ();
275 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
276 setup_description ();
277 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
278 if (vcs && vcs->colour_conversion ()) {
279 optional<size_t> preset = vcs->colour_conversion().get().preset ();
280 vector<PresetColourConversion> cc = PresetColourConversion::all ();
282 checked_set (_colour_conversion, preset.get() + 1);
284 checked_set (_colour_conversion, cc.size() + 1);
287 checked_set (_colour_conversion, 0);
290 setup_sensitivity ();
292 } else if (property == FFmpegContentProperty::FILTERS) {
294 string p = Filter::ffmpeg_string (fcs->filters ());
296 checked_set (_filters, _("None"));
298 if (p.length() > 25) {
299 p = p.substr (0, 25) + "...";
301 checked_set (_filters, p);
304 } else if (property == VideoContentProperty::VIDEO_FADE_IN) {
306 BOOST_FOREACH (shared_ptr<const VideoContent> i, vc) {
307 check.insert (i->fade_in ());
310 if (check.size() == 1) {
311 _fade_in->set (ContentTime::from_frames (vc.front()->fade_in (), vc.front()->video_frame_rate ()), vc.front()->video_frame_rate ());
315 } else if (property == VideoContentProperty::VIDEO_FADE_OUT) {
317 BOOST_FOREACH (shared_ptr<const VideoContent> i, vc) {
318 check.insert (i->fade_out ());
321 if (check.size() == 1) {
322 _fade_out->set (ContentTime::from_frames (vc.front()->fade_out (), vc.front()->video_frame_rate ()), vc.front()->video_frame_rate ());
326 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
327 if (vc.size() == 1) {
328 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
329 checked_set (_reference, dcp ? dcp->reference_video () : false);
331 checked_set (_reference, false);
334 setup_sensitivity ();
338 /** Called when the `Edit filters' button has been clicked */
340 VideoPanel::edit_filters_clicked ()
342 FFmpegContentList c = _parent->selected_ffmpeg ();
347 FilterDialog* d = new FilterDialog (this, c.front()->filters());
348 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
354 VideoPanel::setup_description ()
356 VideoContentList vc = _parent->selected_video ();
358 checked_set (_description, wxT (""));
360 } else if (vc.size() > 1) {
361 checked_set (_description, _("Multiple content selected"));
365 string d = vc.front()->processing_description ();
366 size_t lines = count (d.begin(), d.end(), '\n');
368 for (int i = lines; i < 6; ++i) {
372 checked_set (_description, d);
377 VideoPanel::colour_conversion_changed ()
379 VideoContentList vc = _parent->selected_video ();
380 if (vc.size() != 1) {
384 int const s = _colour_conversion->GetSelection ();
385 vector<PresetColourConversion> all = PresetColourConversion::all ();
388 vc.front()->unset_colour_conversion ();
389 } else if (s == int (all.size() + 1)) {
390 edit_colour_conversion_clicked ();
392 vc.front()->set_colour_conversion (all[s - 1].conversion);
397 VideoPanel::edit_colour_conversion_clicked ()
399 VideoContentList vc = _parent->selected_video ();
400 if (vc.size() != 1) {
404 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->yuv ());
405 d->set (vc.front()->colour_conversion().get_value_or (PresetColourConversion::all().front ().conversion));
407 vc.front()->set_colour_conversion (d->get ());
412 VideoPanel::content_selection_changed ()
414 VideoContentList video_sel = _parent->selected_video ();
416 _frame_type->set_content (video_sel);
417 _left_crop->set_content (video_sel);
418 _right_crop->set_content (video_sel);
419 _top_crop->set_content (video_sel);
420 _bottom_crop->set_content (video_sel);
421 _scale->set_content (video_sel);
423 film_content_changed (VideoContentProperty::VIDEO_CROP);
424 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
425 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
426 film_content_changed (VideoContentProperty::VIDEO_FADE_IN);
427 film_content_changed (VideoContentProperty::VIDEO_FADE_OUT);
428 film_content_changed (FFmpegContentProperty::FILTERS);
429 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
431 setup_sensitivity ();
435 VideoPanel::setup_sensitivity ()
437 ContentList sel = _parent->selected ();
439 shared_ptr<DCPContent> dcp;
440 if (sel.size() == 1) {
441 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
444 list<string> why_not;
445 bool const can_reference = dcp && dcp->can_reference_video (why_not);
446 setup_refer_button (_reference, dcp, can_reference, why_not);
448 if (_reference->GetValue ()) {
449 _frame_type->wrapped()->Enable (false);
450 _left_crop->wrapped()->Enable (false);
451 _right_crop->wrapped()->Enable (false);
452 _top_crop->wrapped()->Enable (false);
453 _bottom_crop->wrapped()->Enable (false);
454 _fade_in->Enable (false);
455 _fade_out->Enable (false);
456 _scale->wrapped()->Enable (false);
457 _description->Enable (false);
458 _filters->Enable (false);
459 _filters_button->Enable (false);
460 _colour_conversion->Enable (false);
462 VideoContentList video_sel = _parent->selected_video ();
463 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
464 bool const single = video_sel.size() == 1;
466 _frame_type->wrapped()->Enable (true);
467 _left_crop->wrapped()->Enable (true);
468 _right_crop->wrapped()->Enable (true);
469 _top_crop->wrapped()->Enable (true);
470 _bottom_crop->wrapped()->Enable (true);
471 _fade_in->Enable (!video_sel.empty ());
472 _fade_out->Enable (!video_sel.empty ());
473 _scale->wrapped()->Enable (true);
474 _description->Enable (true);
475 _filters->Enable (true);
476 _filters_button->Enable (single && !ffmpeg_sel.empty ());
477 _colour_conversion->Enable (single && !video_sel.empty ());
480 VideoContentList vc = _parent->selected_video ();
481 shared_ptr<VideoContent> vcs;
486 if (vcs && vcs->colour_conversion ()) {
487 _edit_colour_conversion_button->Enable (!vcs->colour_conversion().get().preset());
489 _edit_colour_conversion_button->Enable (false);
494 VideoPanel::fade_in_changed ()
496 BOOST_FOREACH (shared_ptr<VideoContent> i, _parent->selected_video ()) {
497 int const vfr = _parent->film()->video_frame_rate ();
498 i->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
503 VideoPanel::fade_out_changed ()
505 BOOST_FOREACH (shared_ptr<VideoContent> i, _parent->selected_video ()) {
506 int const vfr = _parent->film()->video_frame_rate ();
507 i->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
512 VideoPanel::reference_clicked ()
514 ContentList c = _parent->selected ();
519 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
524 d->set_reference_video (_reference->GetValue ());