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>
44 using boost::shared_ptr;
45 using boost::dynamic_pointer_cast;
47 using boost::optional;
49 static VideoContentScale
50 index_to_scale (int n)
52 vector<VideoContentScale> scales = VideoContentScale::all ();
53 DCPOMATIC_ASSERT (n >= 0);
54 DCPOMATIC_ASSERT (n < int (scales.size ()));
59 scale_to_index (VideoContentScale scale)
61 vector<VideoContentScale> scales = VideoContentScale::all ();
62 for (size_t i = 0; i < scales.size(); ++i) {
63 if (scales[i] == scale) {
68 DCPOMATIC_ASSERT (false);
71 VideoPanel::VideoPanel (ContentPanel* p)
72 : ContentSubPanel (p, _("Video"))
74 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
75 _sizer->Add (grid, 0, wxALL, 8);
79 add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
80 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
82 new wxChoice (this, wxID_ANY),
83 VideoContentProperty::VIDEO_FRAME_TYPE,
84 boost::mem_fn (&VideoContent::video_frame_type),
85 boost::mem_fn (&VideoContent::set_video_frame_type),
86 &caster<int, VideoFrameType>,
87 &caster<VideoFrameType, int>
89 _frame_type->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
92 add_label_to_grid_bag_sizer (grid, this, _("Crop"), true, wxGBPosition (r, 0));
95 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
97 add_label_to_grid_bag_sizer (crop, this, _("Left"), true, wxGBPosition (cr, 0));
98 _left_crop = new ContentSpinCtrl<VideoContent> (
100 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
101 VideoContentProperty::VIDEO_CROP,
102 boost::mem_fn (&VideoContent::left_crop),
103 boost::mem_fn (&VideoContent::set_left_crop)
105 _left_crop->add (crop, wxGBPosition (cr, 1));
107 add_label_to_grid_bag_sizer (crop, this, _("Right"), true, wxGBPosition (cr, 2));
108 _right_crop = new ContentSpinCtrl<VideoContent> (
110 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
111 VideoContentProperty::VIDEO_CROP,
112 boost::mem_fn (&VideoContent::right_crop),
113 boost::mem_fn (&VideoContent::set_right_crop)
115 _right_crop->add (crop, wxGBPosition (cr, 3));
119 add_label_to_grid_bag_sizer (crop, this, _("Top"), true, wxGBPosition (cr, 0));
120 _top_crop = new ContentSpinCtrl<VideoContent> (
122 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
123 VideoContentProperty::VIDEO_CROP,
124 boost::mem_fn (&VideoContent::top_crop),
125 boost::mem_fn (&VideoContent::set_top_crop)
127 _top_crop->add (crop, wxGBPosition (cr, 1));
129 add_label_to_grid_bag_sizer (crop, this, _("Bottom"), true, wxGBPosition (cr, 2));
130 _bottom_crop = new ContentSpinCtrl<VideoContent> (
132 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
133 VideoContentProperty::VIDEO_CROP,
134 boost::mem_fn (&VideoContent::bottom_crop),
135 boost::mem_fn (&VideoContent::set_bottom_crop)
137 _bottom_crop->add (crop, wxGBPosition (cr, 3));
139 grid->Add (crop, wxGBPosition (r, 1), wxGBSpan (2, 3));
142 add_label_to_grid_bag_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0));
143 _fade_in = new Timecode<ContentTime> (this);
144 grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
147 add_label_to_grid_bag_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0));
148 _fade_out = new Timecode<ContentTime> (this);
149 grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
152 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
153 _scale = new ContentChoice<VideoContent, VideoContentScale> (
155 new wxChoice (this, wxID_ANY),
156 VideoContentProperty::VIDEO_SCALE,
157 boost::mem_fn (&VideoContent::scale),
158 boost::mem_fn (&VideoContent::set_scale),
162 _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
165 wxClientDC dc (this);
166 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
169 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
171 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
173 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
174 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
175 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
176 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
178 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
182 add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
184 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
186 _colour_conversion = new wxChoice (this, wxID_ANY, wxDefaultPosition, size);
187 _colour_conversion->Append (_("None"));
188 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all()) {
189 _colour_conversion->Append (std_to_wx (i.name));
191 _colour_conversion->Append (_("Custom"));
192 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
194 _edit_colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
195 s->Add (_edit_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
197 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
201 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
202 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
203 wxFont font = _description->GetFont();
204 font.SetStyle(wxFONTSTYLE_ITALIC);
205 font.SetPointSize(font.GetPointSize() - 1);
206 _description->SetFont(font);
209 _left_crop->wrapped()->SetRange (0, 1024);
210 _top_crop->wrapped()->SetRange (0, 1024);
211 _right_crop->wrapped()->SetRange (0, 1024);
212 _bottom_crop->wrapped()->SetRange (0, 1024);
214 _scale->wrapped()->Clear ();
215 BOOST_FOREACH (VideoContentScale const & i, VideoContentScale::all ()) {
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 BOOST_FOREACH (shared_ptr<const VideoContent> i, vc) {
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 BOOST_FOREACH (shared_ptr<const VideoContent> i, vc) {
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 BOOST_FOREACH (shared_ptr<VideoContent> i, _parent->selected_video ()) {
427 int const vfr = _parent->film()->video_frame_rate ();
428 i->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
433 VideoPanel::fade_out_changed ()
435 BOOST_FOREACH (shared_ptr<VideoContent> i, _parent->selected_video ()) {
436 int const vfr = _parent->film()->video_frame_rate ();
437 i->set_fade_out (_fade_out->get (vfr).frames_round (vfr));