2 Copyright (C) 2012-2018 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 "static_text.h"
28 #include "check_box.h"
29 #include "dcpomatic_button.h"
30 #include "lib/filter.h"
31 #include "lib/ffmpeg_content.h"
32 #include "lib/colour_conversion.h"
33 #include "lib/config.h"
35 #include "lib/ratio.h"
36 #include "lib/frame_rate_change.h"
37 #include "lib/dcp_content.h"
38 #include "lib/video_content.h"
39 #include <wx/spinctrl.h>
40 #include <boost/foreach.hpp>
41 #include <boost/unordered_set.hpp>
42 #include <boost/functional/hash.hpp>
52 using boost::shared_ptr;
53 using boost::dynamic_pointer_cast;
55 using boost::optional;
57 static VideoContentScale
58 index_to_scale (int n)
60 vector<VideoContentScale> scales = VideoContentScale::all ();
61 DCPOMATIC_ASSERT (n >= 0);
62 DCPOMATIC_ASSERT (n < int (scales.size ()));
67 scale_to_index (VideoContentScale scale)
69 vector<VideoContentScale> scales = VideoContentScale::all ();
70 for (size_t i = 0; i < scales.size(); ++i) {
71 if (scales[i] == scale) {
76 DCPOMATIC_ASSERT (false);
79 VideoPanel::VideoPanel (ContentPanel* p)
80 : ContentSubPanel (p, _("Video"))
82 _reference = new CheckBox (this, _("Use this DCP's video as OV and make VF"));
83 _reference_note = new StaticText (this, wxT(""));
84 _reference_note->Wrap (200);
85 wxFont font = _reference_note->GetFont();
86 font.SetStyle(wxFONTSTYLE_ITALIC);
87 font.SetPointSize(font.GetPointSize() - 1);
88 _reference_note->SetFont(font);
90 _type_label = create_label (this, _("Type"), true);
91 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
93 new wxChoice (this, wxID_ANY),
94 VideoContentProperty::FRAME_TYPE,
96 boost::mem_fn (&VideoContent::frame_type),
97 boost::mem_fn (&VideoContent::set_frame_type),
98 &caster<int, VideoFrameType>,
99 &caster<VideoFrameType, int>
102 _left_crop_label = create_label (this, _("Left crop"), 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 crop"), 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 crop"), 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 crop"), 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 StaticText (this, _("None"), wxDefaultPosition, size);
166 _filters_button = new Button (this, _("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 Button (this, _("Edit..."));
179 _description = new StaticText (this, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
180 _description->SetFont(font);
182 _left_crop->wrapped()->SetRange (0, 4096);
183 _top_crop->wrapped()->SetRange (0, 4096);
184 _right_crop->wrapped()->SetRange (0, 4096);
185 _bottom_crop->wrapped()->SetRange (0, 4096);
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));
214 VideoPanel::add_to_grid ()
216 bool const full = Config::instance()->interface_complexity() == Config::INTERFACE_FULL;
220 _reference->Show (full);
221 _reference_note->Show (full);
224 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
225 reference_sizer->Add (_reference, 0);
226 reference_sizer->Add (_reference_note, 0);
227 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 3));
231 add_label_to_sizer (_grid, _type_label, true, wxGBPosition(r, 0));
232 _frame_type->add (_grid, wxGBPosition(r, 1), wxGBSpan(1, 2));
236 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
237 add_label_to_sizer (crop, _left_crop_label, true, wxGBPosition (cr, 0));
238 _left_crop->add (crop, wxGBPosition (cr, 1));
239 add_label_to_sizer (crop, _right_crop_label, true, wxGBPosition (cr, 2));
240 _right_crop->add (crop, wxGBPosition (cr, 3));
242 add_label_to_sizer (crop, _top_crop_label, true, wxGBPosition (cr, 0));
243 _top_crop->add (crop, wxGBPosition (cr, 1));
244 add_label_to_sizer (crop, _bottom_crop_label, true, wxGBPosition (cr, 2));
245 _bottom_crop->add (crop, wxGBPosition (cr, 3));
246 _grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 4));
249 _scale_to_label->Show (full);
251 _filters_label->Show (full);
252 _filters->Show (full);
253 _filters_button->Show (full);
254 _colour_conversion_label->Show (full);
255 _colour_conversion->Show (full);
256 _edit_colour_conversion_button->Show (full);
258 add_label_to_sizer (_grid, _fade_in_label, true, wxGBPosition (r, 0));
259 _grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
262 add_label_to_sizer (_grid, _fade_out_label, true, wxGBPosition (r, 0));
263 _grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
267 add_label_to_sizer (_grid, _scale_to_label, true, wxGBPosition (r, 0));
268 _scale->add (_grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
271 add_label_to_sizer (_grid, _filters_label, true, wxGBPosition (r, 0));
273 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
274 s->Add (_filters, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
275 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
276 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
280 add_label_to_sizer (_grid, _colour_conversion_label, true, wxGBPosition(r, 0));
282 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
283 s->Add (_colour_conversion, 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
284 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
285 _grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
290 _grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL, 6);
296 VideoPanel::film_changed (Film::Property property)
299 case Film::VIDEO_FRAME_RATE:
300 case Film::CONTAINER:
301 case Film::RESOLUTION:
302 setup_description ();
303 setup_sensitivity ();
305 case Film::REEL_TYPE:
307 setup_sensitivity ();
315 hash_value (boost::optional<ColourConversion> const & c)
317 boost::hash<string> hasher;
319 return hasher ("none");
321 return hasher (c->identifier());
326 VideoPanel::film_content_changed (int property)
328 ContentList vc = _parent->selected_video ();
329 shared_ptr<Content> vcs;
330 shared_ptr<FFmpegContent> fcs;
333 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
336 if (property == ContentProperty::VIDEO_FRAME_RATE ||
337 property == VideoContentProperty::FRAME_TYPE ||
338 property == VideoContentProperty::CROP ||
339 property == VideoContentProperty::SCALE) {
340 setup_description ();
341 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
342 boost::unordered_set<optional<ColourConversion> > check;
343 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
344 check.insert (i->video->colour_conversion());
347 /* Remove any "Many" entry that we might have added previously. There should
348 * be entries for each preset plus one for "None" and one for "Custom".
350 vector<PresetColourConversion> cc = PresetColourConversion::all ();
351 if (_colour_conversion->GetCount() > cc.size() + 2) {
352 _colour_conversion->Delete (_colour_conversion->GetCount() - 1);
355 if (check.size() == 1) {
356 if (vcs && vcs->video->colour_conversion ()) {
357 optional<size_t> preset = vcs->video->colour_conversion().get().preset ();
359 checked_set (_colour_conversion, preset.get() + 1);
361 checked_set (_colour_conversion, cc.size() + 1);
364 checked_set (_colour_conversion, 0);
366 } else if (check.size() > 1) {
367 /* Add a "many" entry and select it as an indication that multiple different
368 * colour conversions are present in the selection.
370 _colour_conversion->Append (_("Many"));
371 checked_set (_colour_conversion, _colour_conversion->GetCount() - 1);
374 setup_sensitivity ();
376 } else if (property == FFmpegContentProperty::FILTERS) {
378 string p = Filter::ffmpeg_string (fcs->filters ());
380 checked_set (_filters, _("None"));
382 if (p.length() > 25) {
383 p = p.substr (0, 25) + "...";
385 checked_set (_filters, p);
388 } else if (property == VideoContentProperty::FADE_IN) {
390 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
391 check.insert (i->video->fade_in ());
394 if (check.size() == 1) {
396 ContentTime::from_frames (vc.front()->video->fade_in(), vc.front()->active_video_frame_rate(_parent->film())),
397 vc.front()->active_video_frame_rate(_parent->film())
402 } else if (property == VideoContentProperty::FADE_OUT) {
404 BOOST_FOREACH (shared_ptr<const Content> i, vc) {
405 check.insert (i->video->fade_out ());
408 if (check.size() == 1) {
410 ContentTime::from_frames (vc.front()->video->fade_out(), vc.front()->active_video_frame_rate(_parent->film())),
411 vc.front()->active_video_frame_rate(_parent->film())
416 } else if (property == DCPContentProperty::REFERENCE_VIDEO) {
417 if (vc.size() == 1) {
418 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (vc.front ());
419 checked_set (_reference, dcp ? dcp->reference_video () : false);
421 checked_set (_reference, false);
424 setup_sensitivity ();
428 /** Called when the `Edit filters' button has been clicked */
430 VideoPanel::edit_filters_clicked ()
432 FFmpegContentList c = _parent->selected_ffmpeg ();
437 FilterDialog* d = new FilterDialog (this, c.front()->filters());
438 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
444 VideoPanel::setup_description ()
446 ContentList vc = _parent->selected_video ();
448 checked_set (_description, wxT (""));
450 } else if (vc.size() > 1) {
451 checked_set (_description, _("Multiple content selected"));
455 string d = vc.front()->video->processing_description (_parent->film());
456 size_t lines = count (d.begin(), d.end(), '\n');
458 for (int i = lines; i < 6; ++i) {
462 checked_set (_description, d);
467 VideoPanel::colour_conversion_changed ()
469 ContentList vc = _parent->selected_video ();
471 int const s = _colour_conversion->GetSelection ();
472 vector<PresetColourConversion> all = PresetColourConversion::all ();
474 if (s == int(all.size() + 1)) {
475 edit_colour_conversion_clicked ();
477 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video()) {
479 i->video->unset_colour_conversion ();
480 } else if (s != int(all.size() + 2)) {
481 i->video->set_colour_conversion (all[s - 1].conversion);
488 VideoPanel::edit_colour_conversion_clicked ()
490 ContentList vc = _parent->selected_video ();
492 ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
493 d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
494 if (d->ShowModal() == wxID_OK) {
495 BOOST_FOREACH (shared_ptr<Content> i, vc) {
496 i->video->set_colour_conversion (d->get ());
499 /* Reset the colour conversion choice */
500 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
506 VideoPanel::content_selection_changed ()
508 ContentList video_sel = _parent->selected_video ();
510 _frame_type->set_content (video_sel);
511 _left_crop->set_content (video_sel);
512 _right_crop->set_content (video_sel);
513 _top_crop->set_content (video_sel);
514 _bottom_crop->set_content (video_sel);
515 _scale->set_content (video_sel);
517 film_content_changed (ContentProperty::VIDEO_FRAME_RATE);
518 film_content_changed (VideoContentProperty::CROP);
519 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
520 film_content_changed (VideoContentProperty::FADE_IN);
521 film_content_changed (VideoContentProperty::FADE_OUT);
522 film_content_changed (FFmpegContentProperty::FILTERS);
523 film_content_changed (DCPContentProperty::REFERENCE_VIDEO);
525 setup_sensitivity ();
529 VideoPanel::setup_sensitivity ()
531 ContentList sel = _parent->selected ();
533 shared_ptr<DCPContent> dcp;
534 if (sel.size() == 1) {
535 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
539 bool const can_reference = dcp && dcp->can_reference_video (_parent->film(), why_not);
540 setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
542 if (_reference->GetValue ()) {
543 _frame_type->wrapped()->Enable (false);
544 _left_crop->wrapped()->Enable (false);
545 _right_crop->wrapped()->Enable (false);
546 _top_crop->wrapped()->Enable (false);
547 _bottom_crop->wrapped()->Enable (false);
548 _fade_in->Enable (false);
549 _fade_out->Enable (false);
550 _scale->wrapped()->Enable (false);
551 _description->Enable (false);
552 _filters->Enable (false);
553 _filters_button->Enable (false);
554 _colour_conversion->Enable (false);
556 ContentList video_sel = _parent->selected_video ();
557 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
558 bool const single = video_sel.size() == 1;
560 _frame_type->wrapped()->Enable (true);
561 _left_crop->wrapped()->Enable (true);
562 _right_crop->wrapped()->Enable (true);
563 _top_crop->wrapped()->Enable (true);
564 _bottom_crop->wrapped()->Enable (true);
565 _fade_in->Enable (!video_sel.empty ());
566 _fade_out->Enable (!video_sel.empty ());
567 _scale->wrapped()->Enable (true);
568 _description->Enable (true);
569 _filters->Enable (true);
570 _filters_button->Enable (single && !ffmpeg_sel.empty ());
571 _colour_conversion->Enable (!video_sel.empty());
574 ContentList vc = _parent->selected_video ();
575 shared_ptr<Content> vcs;
580 if (vcs && vcs->video->colour_conversion ()) {
581 _edit_colour_conversion_button->Enable (!vcs->video->colour_conversion().get().preset());
583 _edit_colour_conversion_button->Enable (false);
588 VideoPanel::fade_in_changed ()
590 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
591 double const vfr = i->active_video_frame_rate (_parent->film());
592 i->video->set_fade_in (_fade_in->get(vfr).frames_round(vfr));
597 VideoPanel::fade_out_changed ()
599 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_video ()) {
600 double const vfr = i->active_video_frame_rate (_parent->film());
601 i->video->set_fade_out (_fade_out->get(vfr).frames_round(vfr));
606 VideoPanel::reference_clicked ()
608 ContentList c = _parent->selected ();
613 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
618 d->set_reference_video (_reference->GetValue ());