2 Copyright (C) 2012-2014 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 <wx/spinctrl.h>
21 #include "lib/filter.h"
22 #include "lib/ffmpeg_content.h"
23 #include "lib/colour_conversion.h"
24 #include "lib/config.h"
26 #include "lib/ratio.h"
27 #include "lib/frame_rate_change.h"
28 #include "filter_dialog.h"
29 #include "video_panel.h"
31 #include "content_colour_conversion_dialog.h"
32 #include "content_widget.h"
33 #include "content_panel.h"
41 using boost::shared_ptr;
42 using boost::dynamic_pointer_cast;
44 using boost::optional;
46 static VideoContentScale
47 index_to_scale (int n)
49 vector<VideoContentScale> scales = VideoContentScale::all ();
51 assert (n < int (scales.size ()));
56 scale_to_index (VideoContentScale scale)
58 vector<VideoContentScale> scales = VideoContentScale::all ();
59 for (size_t i = 0; i < scales.size(); ++i) {
60 if (scales[i] == scale) {
68 VideoPanel::VideoPanel (ContentPanel* p)
69 : ContentSubPanel (p, _("Video"))
71 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
72 _sizer->Add (grid, 0, wxALL, 8);
76 add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
77 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
79 new wxChoice (this, wxID_ANY),
80 VideoContentProperty::VIDEO_FRAME_TYPE,
81 boost::mem_fn (&VideoContent::video_frame_type),
82 boost::mem_fn (&VideoContent::set_video_frame_type),
83 &caster<int, VideoFrameType>,
84 &caster<VideoFrameType, int>
86 _frame_type->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
89 add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0));
90 _left_crop = new ContentSpinCtrl<VideoContent> (
92 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
93 VideoContentProperty::VIDEO_CROP,
94 boost::mem_fn (&VideoContent::left_crop),
95 boost::mem_fn (&VideoContent::set_left_crop)
97 _left_crop->add (grid, wxGBPosition (r, 1));
99 add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 2));
100 _right_crop = new ContentSpinCtrl<VideoContent> (
102 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
103 VideoContentProperty::VIDEO_CROP,
104 boost::mem_fn (&VideoContent::right_crop),
105 boost::mem_fn (&VideoContent::set_right_crop)
107 _right_crop->add (grid, wxGBPosition (r, 3));
111 add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0));
112 _top_crop = new ContentSpinCtrl<VideoContent> (
114 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
115 VideoContentProperty::VIDEO_CROP,
116 boost::mem_fn (&VideoContent::top_crop),
117 boost::mem_fn (&VideoContent::set_top_crop)
119 _top_crop->add (grid, wxGBPosition (r, 1));
121 add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 2));
122 _bottom_crop = new ContentSpinCtrl<VideoContent> (
124 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
125 VideoContentProperty::VIDEO_CROP,
126 boost::mem_fn (&VideoContent::bottom_crop),
127 boost::mem_fn (&VideoContent::set_bottom_crop)
129 _bottom_crop->add (grid, wxGBPosition (r, 3));
133 add_label_to_grid_bag_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0));
134 _fade_in = new Timecode<ContentTime> (this);
135 grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
138 add_label_to_grid_bag_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0));
139 _fade_out = new Timecode<ContentTime> (this);
140 grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
143 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
144 _scale = new ContentChoice<VideoContent, VideoContentScale> (
146 new wxChoice (this, wxID_ANY),
147 VideoContentProperty::VIDEO_SCALE,
148 boost::mem_fn (&VideoContent::scale),
149 boost::mem_fn (&VideoContent::set_scale),
153 _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
156 wxClientDC dc (this);
157 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
160 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
161 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
162 grid->Add (_filters, wxGBPosition (r, 1), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL);
163 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
164 grid->Add (_filters_button, wxGBPosition (r, 3), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
167 _enable_colour_conversion = new wxCheckBox (this, wxID_ANY, _("Colour conversion"));
168 grid->Add (_enable_colour_conversion, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
169 _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
170 grid->Add (_colour_conversion, wxGBPosition (r, 1), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL);
171 _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
172 grid->Add (_colour_conversion_button, wxGBPosition (r, 3), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
175 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
176 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
177 wxFont font = _description->GetFont();
178 font.SetStyle(wxFONTSTYLE_ITALIC);
179 font.SetPointSize(font.GetPointSize() - 1);
180 _description->SetFont(font);
183 _left_crop->wrapped()->SetRange (0, 1024);
184 _top_crop->wrapped()->SetRange (0, 1024);
185 _right_crop->wrapped()->SetRange (0, 1024);
186 _bottom_crop->wrapped()->SetRange (0, 1024);
188 vector<VideoContentScale> scales = VideoContentScale::all ();
189 _scale->wrapped()->Clear ();
190 for (vector<VideoContentScale>::iterator i = scales.begin(); i != scales.end(); ++i) {
191 _scale->wrapped()->Append (std_to_wx (i->name ()));
194 _frame_type->wrapped()->Append (_("2D"));
195 _frame_type->wrapped()->Append (_("3D left/right"));
196 _frame_type->wrapped()->Append (_("3D top/bottom"));
197 _frame_type->wrapped()->Append (_("3D alternate"));
198 _frame_type->wrapped()->Append (_("3D left only"));
199 _frame_type->wrapped()->Append (_("3D right only"));
201 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
202 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
204 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
205 _enable_colour_conversion->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&VideoPanel::enable_colour_conversion_clicked, this));
206 _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
210 VideoPanel::film_changed (Film::Property property)
213 case Film::CONTAINER:
214 case Film::VIDEO_FRAME_RATE:
215 case Film::RESOLUTION:
216 setup_description ();
224 VideoPanel::film_content_changed (int property)
226 VideoContentList vc = _parent->selected_video ();
227 shared_ptr<VideoContent> vcs;
228 shared_ptr<FFmpegContent> fcs;
231 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
234 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
235 setup_description ();
236 } else if (property == VideoContentProperty::VIDEO_CROP) {
237 setup_description ();
238 } else if (property == VideoContentProperty::VIDEO_SCALE) {
239 setup_description ();
240 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
241 setup_description ();
242 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
244 _colour_conversion->SetLabel (wxT (""));
245 } else if (vcs->colour_conversion ()) {
246 optional<size_t> preset = vcs->colour_conversion().get().preset ();
247 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
248 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
249 _enable_colour_conversion->SetValue (true);
250 _colour_conversion->Enable (true);
251 _colour_conversion_button->Enable (true);
253 _colour_conversion->SetLabel (_("None"));
254 _enable_colour_conversion->SetValue (false);
255 _colour_conversion->Enable (false);
256 _colour_conversion_button->Enable (false);
258 } else if (property == FFmpegContentProperty::FILTERS) {
260 string const p = Filter::ffmpeg_string (fcs->filters ());
262 _filters->SetLabel (_("None"));
264 _filters->SetLabel (std_to_wx (p));
267 } else if (property == VideoContentProperty::VIDEO_FADE_IN) {
268 set<ContentTime> check;
269 for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) {
270 check.insert ((*i)->fade_in ());
273 if (check.size() == 1) {
274 _fade_in->set (vc.front()->fade_in (), vc.front()->video_frame_rate ());
278 } else if (property == VideoContentProperty::VIDEO_FADE_OUT) {
279 set<ContentTime> check;
280 for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) {
281 check.insert ((*i)->fade_out ());
284 if (check.size() == 1) {
285 _fade_out->set (vc.front()->fade_out (), vc.front()->video_frame_rate ());
292 /** Called when the `Edit filters' button has been clicked */
294 VideoPanel::edit_filters_clicked ()
296 FFmpegContentList c = _parent->selected_ffmpeg ();
301 FilterDialog* d = new FilterDialog (this, c.front()->filters());
302 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
308 VideoPanel::setup_description ()
310 VideoContentList vc = _parent->selected_video ();
312 _description->SetLabel ("");
314 } else if (vc.size() > 1) {
315 _description->SetLabel (_("Multiple content selected"));
319 shared_ptr<VideoContent> vcs = vc.front ();
325 if (vcs->video_size().width && vcs->video_size().height) {
326 d << wxString::Format (
327 _("Content video is %dx%d (%.2f:1)\n"),
328 vcs->video_size_after_3d_split().width,
329 vcs->video_size_after_3d_split().height,
330 vcs->video_size_after_3d_split().ratio ()
335 Crop const crop = vcs->crop ();
336 if ((crop.left || crop.right || crop.top || crop.bottom) && vcs->video_size() != dcp::Size (0, 0)) {
337 dcp::Size cropped = vcs->video_size_after_crop ();
338 d << wxString::Format (
339 _("Cropped to %dx%d (%.2f:1)\n"),
340 cropped.width, cropped.height,
346 dcp::Size const container_size = _parent->film()->frame_size ();
347 dcp::Size const scaled = vcs->scale().size (vcs, container_size, container_size, 1);
349 if (scaled != vcs->video_size_after_crop ()) {
350 d << wxString::Format (
351 _("Scaled to %dx%d (%.2f:1)\n"),
352 scaled.width, scaled.height,
358 if (scaled != container_size) {
359 d << wxString::Format (
360 _("Padded with black to %dx%d (%.2f:1)\n"),
361 container_size.width, container_size.height,
362 container_size.ratio ()
367 d << wxString::Format (_("Content frame rate %.4f\n"), vcs->video_frame_rate ());
369 FrameRateChange frc (vcs->video_frame_rate(), _parent->film()->video_frame_rate ());
370 d << std_to_wx (frc.description ()) << "\n";
373 for (int i = lines; i < 6; ++i) {
377 _description->SetLabel (d);
382 VideoPanel::edit_colour_conversion_clicked ()
384 VideoContentList vc = _parent->selected_video ();
385 if (vc.size() != 1) {
389 if (!vc.front()->colour_conversion ()) {
393 ColourConversion conversion = vc.front()->colour_conversion().get ();
394 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
398 vc.front()->set_colour_conversion (d->get ());
403 VideoPanel::content_selection_changed ()
405 VideoContentList video_sel = _parent->selected_video ();
406 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
408 bool const single = video_sel.size() == 1;
410 _left_crop->set_content (video_sel);
411 _right_crop->set_content (video_sel);
412 _top_crop->set_content (video_sel);
413 _bottom_crop->set_content (video_sel);
414 _frame_type->set_content (video_sel);
415 _scale->set_content (video_sel);
417 _filters_button->Enable (single && !ffmpeg_sel.empty ());
418 _colour_conversion_button->Enable (single);
420 film_content_changed (VideoContentProperty::VIDEO_CROP);
421 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
422 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
423 film_content_changed (VideoContentProperty::VIDEO_FADE_IN);
424 film_content_changed (VideoContentProperty::VIDEO_FADE_OUT);
425 film_content_changed (FFmpegContentProperty::FILTERS);
429 VideoPanel::fade_in_changed ()
431 VideoContentList vc = _parent->selected_video ();
432 for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
433 (*i)->set_fade_in (_fade_in->get (_parent->film()->video_frame_rate ()));
438 VideoPanel::fade_out_changed ()
440 VideoContentList vc = _parent->selected_video ();
441 for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
442 (*i)->set_fade_out (_fade_out->get (_parent->film()->video_frame_rate ()));
447 VideoPanel::enable_colour_conversion_clicked ()
449 VideoContentList vc = _parent->selected_video ();
450 if (vc.size() != 1) {
454 if (_enable_colour_conversion->GetValue()) {
455 vc.front()->set_default_colour_conversion ();
457 vc.front()->unset_colour_conversion ();