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 "lib/filter.h"
21 #include "lib/ffmpeg_content.h"
22 #include "lib/colour_conversion.h"
23 #include "lib/config.h"
25 #include "lib/ratio.h"
26 #include "lib/frame_rate_change.h"
27 #include "filter_dialog.h"
28 #include "video_panel.h"
30 #include "content_colour_conversion_dialog.h"
31 #include "content_widget.h"
32 #include "content_panel.h"
33 #include <wx/spinctrl.h>
34 #include <boost/foreach.hpp>
43 using boost::shared_ptr;
44 using boost::dynamic_pointer_cast;
46 using boost::optional;
48 static VideoContentScale
49 index_to_scale (int n)
51 vector<VideoContentScale> scales = VideoContentScale::all ();
52 DCPOMATIC_ASSERT (n >= 0);
53 DCPOMATIC_ASSERT (n < int (scales.size ()));
58 scale_to_index (VideoContentScale scale)
60 vector<VideoContentScale> scales = VideoContentScale::all ();
61 for (size_t i = 0; i < scales.size(); ++i) {
62 if (scales[i] == scale) {
67 DCPOMATIC_ASSERT (false);
70 VideoPanel::VideoPanel (ContentPanel* p)
71 : ContentSubPanel (p, _("Video"))
73 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
74 _sizer->Add (grid, 0, wxALL, 8);
78 add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
79 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
81 new wxChoice (this, wxID_ANY),
82 VideoContentProperty::VIDEO_FRAME_TYPE,
83 boost::mem_fn (&VideoContent::video_frame_type),
84 boost::mem_fn (&VideoContent::set_video_frame_type),
85 &caster<int, VideoFrameType>,
86 &caster<VideoFrameType, int>
88 _frame_type->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
91 add_label_to_grid_bag_sizer (grid, this, _("Crop"), true, wxGBPosition (r, 0));
94 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
96 add_label_to_grid_bag_sizer (crop, this, _("Left"), true, wxGBPosition (cr, 0));
97 _left_crop = new ContentSpinCtrl<VideoContent> (
99 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
100 VideoContentProperty::VIDEO_CROP,
101 boost::mem_fn (&VideoContent::left_crop),
102 boost::mem_fn (&VideoContent::set_left_crop)
104 _left_crop->add (crop, wxGBPosition (cr, 1));
106 add_label_to_grid_bag_sizer (crop, this, _("Right"), true, wxGBPosition (cr, 2));
107 _right_crop = new ContentSpinCtrl<VideoContent> (
109 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
110 VideoContentProperty::VIDEO_CROP,
111 boost::mem_fn (&VideoContent::right_crop),
112 boost::mem_fn (&VideoContent::set_right_crop)
114 _right_crop->add (crop, wxGBPosition (cr, 3));
118 add_label_to_grid_bag_sizer (crop, this, _("Top"), true, wxGBPosition (cr, 0));
119 _top_crop = new ContentSpinCtrl<VideoContent> (
121 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
122 VideoContentProperty::VIDEO_CROP,
123 boost::mem_fn (&VideoContent::top_crop),
124 boost::mem_fn (&VideoContent::set_top_crop)
126 _top_crop->add (crop, wxGBPosition (cr, 1));
128 add_label_to_grid_bag_sizer (crop, this, _("Bottom"), true, wxGBPosition (cr, 2));
129 _bottom_crop = new ContentSpinCtrl<VideoContent> (
131 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
132 VideoContentProperty::VIDEO_CROP,
133 boost::mem_fn (&VideoContent::bottom_crop),
134 boost::mem_fn (&VideoContent::set_bottom_crop)
136 _bottom_crop->add (crop, wxGBPosition (cr, 3));
138 grid->Add (crop, wxGBPosition (r, 1), wxGBSpan (2, 3));
141 add_label_to_grid_bag_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0));
142 _fade_in = new Timecode<ContentTime> (this);
143 grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
146 add_label_to_grid_bag_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0));
147 _fade_out = new Timecode<ContentTime> (this);
148 grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
151 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
152 _scale = new ContentChoice<VideoContent, VideoContentScale> (
154 new wxChoice (this, wxID_ANY),
155 VideoContentProperty::VIDEO_SCALE,
156 boost::mem_fn (&VideoContent::scale),
157 boost::mem_fn (&VideoContent::set_scale),
161 _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
164 wxClientDC dc (this);
165 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
168 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
170 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
172 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
173 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
174 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
175 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
177 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
181 add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
183 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
185 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
186 _colour_conversion->Append (_("None"));
187 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
188 _colour_conversion->Append (std_to_wx (i.name));
190 _colour_conversion->Append (_("Custom"));
191 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
193 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
194 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
196 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
200 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
201 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
202 wxFont font = _description->GetFont();
203 font.SetStyle(wxFONTSTYLE_ITALIC);
204 font.SetPointSize(font.GetPointSize() - 1);
205 _description->SetFont(font);
208 _left_crop->wrapped()->SetRange (0, 1024);
209 _top_crop->wrapped()->SetRange (0, 1024);
210 _right_crop->wrapped()->SetRange (0, 1024);
211 _bottom_crop->wrapped()->SetRange (0, 1024);
213 vector<VideoContentScale> scales = VideoContentScale::all ();
214 _scale->wrapped()->Clear ();
215 for (vector<VideoContentScale>::iterator i = scales.begin(); i != scales.end(); ++i) {
216 _scale->wrapped()->Append (std_to_wx (i->name ()));
219 _frame_type->wrapped()->Append (_("2D"));
220 _frame_type->wrapped()->Append (_("3D left/right"));
221 _frame_type->wrapped()->Append (_("3D top/bottom"));
222 _frame_type->wrapped()->Append (_("3D alternate"));
223 _frame_type->wrapped()->Append (_("3D left only"));
224 _frame_type->wrapped()->Append (_("3D right only"));
226 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
227 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
229 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
230 _colour_conversion->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::colour_conversion_changed, this));
231 _edit_colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
235 VideoPanel::film_changed (Film::Property property)
238 case Film::CONTAINER:
239 case Film::VIDEO_FRAME_RATE:
240 case Film::RESOLUTION:
241 setup_description ();
249 VideoPanel::film_content_changed (int property)
251 VideoContentList vc = _parent->selected_video ();
252 shared_ptr<VideoContent> vcs;
253 shared_ptr<FFmpegContent> fcs;
256 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
259 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
260 setup_description ();
261 } else if (property == VideoContentProperty::VIDEO_CROP) {
262 setup_description ();
263 } else if (property == VideoContentProperty::VIDEO_SCALE) {
264 setup_description ();
265 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
266 setup_description ();
267 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
269 checked_set (_colour_conversion, 0);
270 _edit_colour_conversion_button->Enable (false);
271 } else if (vcs->colour_conversion ()) {
272 optional<size_t> preset = vcs->colour_conversion().get().preset ();
273 vector<PresetColourConversion> cc = PresetColourConversion::all ();
275 checked_set (_colour_conversion, preset.get() + 1);
276 _edit_colour_conversion_button->Enable (false);
278 checked_set (_colour_conversion, cc.size() + 1);
279 _edit_colour_conversion_button->Enable (true);
282 checked_set (_colour_conversion, 0);
283 _edit_colour_conversion_button->Enable (false);
285 } else if (property == FFmpegContentProperty::FILTERS) {
287 string p = Filter::ffmpeg_string (fcs->filters ());
289 checked_set (_filters, _("None"));
291 if (p.length() > 25) {
292 p = p.substr (0, 25) + "...";
294 checked_set (_filters, p);
297 } else if (property == VideoContentProperty::VIDEO_FADE_IN) {
299 for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) {
300 check.insert ((*i)->fade_in ());
303 if (check.size() == 1) {
304 _fade_in->set (ContentTime::from_frames (vc.front()->fade_in (), vc.front()->video_frame_rate ()), vc.front()->video_frame_rate ());
308 } else if (property == VideoContentProperty::VIDEO_FADE_OUT) {
310 for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) {
311 check.insert ((*i)->fade_out ());
314 if (check.size() == 1) {
315 _fade_out->set (ContentTime::from_frames (vc.front()->fade_out (), vc.front()->video_frame_rate ()), vc.front()->video_frame_rate ());
322 /** Called when the `Edit filters' button has been clicked */
324 VideoPanel::edit_filters_clicked ()
326 FFmpegContentList c = _parent->selected_ffmpeg ();
331 FilterDialog* d = new FilterDialog (this, c.front()->filters());
332 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
338 VideoPanel::setup_description ()
340 VideoContentList vc = _parent->selected_video ();
342 checked_set (_description, wxT (""));
344 } else if (vc.size() > 1) {
345 checked_set (_description, _("Multiple content selected"));
349 string d = vc.front()->processing_description ();
350 size_t lines = count (d.begin(), d.end(), '\n');
352 for (int i = lines; i < 6; ++i) {
356 checked_set (_description, d);
361 VideoPanel::colour_conversion_changed ()
363 VideoContentList vc = _parent->selected_video ();
364 if (vc.size() != 1) {
368 int const s = _colour_conversion->GetSelection ();
369 vector<PresetColourConversion> all = PresetColourConversion::all ();
372 vc.front()->unset_colour_conversion ();
373 } else if (s == int (all.size() + 1)) {
374 edit_colour_conversion_clicked ();
376 vc.front()->set_colour_conversion (all[s - 1].conversion);
381 VideoPanel::edit_colour_conversion_clicked ()
383 VideoContentList vc = _parent->selected_video ();
384 if (vc.size() != 1) {
388 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
389 d->set (vc.front()->colour_conversion().get_value_or (PresetColourConversion::all().front ().conversion));
391 vc.front()->set_colour_conversion (d->get ());
396 VideoPanel::content_selection_changed ()
398 VideoContentList video_sel = _parent->selected_video ();
399 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
401 bool const single = video_sel.size() == 1;
403 _frame_type->set_content (video_sel);
404 _left_crop->set_content (video_sel);
405 _right_crop->set_content (video_sel);
406 _top_crop->set_content (video_sel);
407 _bottom_crop->set_content (video_sel);
408 _fade_in->Enable (!video_sel.empty ());
409 _fade_out->Enable (!video_sel.empty ());
410 _scale->set_content (video_sel);
412 _colour_conversion->Enable (single && !video_sel.empty ());
413 _filters_button->Enable (single && !ffmpeg_sel.empty ());
415 film_content_changed (VideoContentProperty::VIDEO_CROP);
416 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
417 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
418 film_content_changed (VideoContentProperty::VIDEO_FADE_IN);
419 film_content_changed (VideoContentProperty::VIDEO_FADE_OUT);
420 film_content_changed (FFmpegContentProperty::FILTERS);
424 VideoPanel::fade_in_changed ()
426 VideoContentList vc = _parent->selected_video ();
427 for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
428 int const vfr = _parent->film()->video_frame_rate ();
429 (*i)->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
434 VideoPanel::fade_out_changed ()
436 VideoContentList vc = _parent->selected_video ();
437 for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
438 int const vfr = _parent->film()->video_frame_rate ();
439 (*i)->set_fade_out (_fade_out->get (vfr).frames_round (vfr));