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 "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>
42 using boost::shared_ptr;
43 using boost::dynamic_pointer_cast;
45 using boost::optional;
47 static VideoContentScale
48 index_to_scale (int n)
50 vector<VideoContentScale> scales = VideoContentScale::all ();
51 DCPOMATIC_ASSERT (n >= 0);
52 DCPOMATIC_ASSERT (n < int (scales.size ()));
57 scale_to_index (VideoContentScale scale)
59 vector<VideoContentScale> scales = VideoContentScale::all ();
60 for (size_t i = 0; i < scales.size(); ++i) {
61 if (scales[i] == scale) {
66 DCPOMATIC_ASSERT (false);
69 VideoPanel::VideoPanel (ContentPanel* p)
70 : ContentSubPanel (p, _("Video"))
72 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
73 _sizer->Add (grid, 0, wxALL, 8);
77 add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
78 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
80 new wxChoice (this, wxID_ANY),
81 VideoContentProperty::VIDEO_FRAME_TYPE,
82 boost::mem_fn (&VideoContent::video_frame_type),
83 boost::mem_fn (&VideoContent::set_video_frame_type),
84 &caster<int, VideoFrameType>,
85 &caster<VideoFrameType, int>
87 _frame_type->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
91 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
93 add_label_to_grid_bag_sizer (crop, this, _("Left crop"), true, wxGBPosition (cr, 0));
94 _left_crop = new ContentSpinCtrl<VideoContent> (
96 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
97 VideoContentProperty::VIDEO_CROP,
98 boost::mem_fn (&VideoContent::left_crop),
99 boost::mem_fn (&VideoContent::set_left_crop)
101 _left_crop->add (crop, wxGBPosition (cr, 1));
103 add_label_to_grid_bag_sizer (crop, this, _("Right crop"), true, wxGBPosition (cr, 2));
104 _right_crop = new ContentSpinCtrl<VideoContent> (
106 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
107 VideoContentProperty::VIDEO_CROP,
108 boost::mem_fn (&VideoContent::right_crop),
109 boost::mem_fn (&VideoContent::set_right_crop)
111 _right_crop->add (crop, wxGBPosition (cr, 3));
115 add_label_to_grid_bag_sizer (crop, this, _("Top crop"), true, wxGBPosition (cr, 0));
116 _top_crop = new ContentSpinCtrl<VideoContent> (
118 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
119 VideoContentProperty::VIDEO_CROP,
120 boost::mem_fn (&VideoContent::top_crop),
121 boost::mem_fn (&VideoContent::set_top_crop)
123 _top_crop->add (crop, wxGBPosition (cr, 1));
125 add_label_to_grid_bag_sizer (crop, this, _("Bottom crop"), true, wxGBPosition (cr, 2));
126 _bottom_crop = new ContentSpinCtrl<VideoContent> (
128 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
129 VideoContentProperty::VIDEO_CROP,
130 boost::mem_fn (&VideoContent::bottom_crop),
131 boost::mem_fn (&VideoContent::set_bottom_crop)
133 _bottom_crop->add (crop, wxGBPosition (cr, 3));
135 grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 3));
138 add_label_to_grid_bag_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0));
139 _fade_in = new Timecode<ContentTime> (this);
140 grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
143 add_label_to_grid_bag_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0));
144 _fade_out = new Timecode<ContentTime> (this);
145 grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
148 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
149 _scale = new ContentChoice<VideoContent, VideoContentScale> (
151 new wxChoice (this, wxID_ANY),
152 VideoContentProperty::VIDEO_SCALE,
153 boost::mem_fn (&VideoContent::scale),
154 boost::mem_fn (&VideoContent::set_scale),
158 _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
161 wxClientDC dc (this);
162 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
165 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
166 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
167 grid->Add (_filters, wxGBPosition (r, 1), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL);
168 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
169 grid->Add (_filters_button, wxGBPosition (r, 3), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
172 _enable_colour_conversion = new wxCheckBox (this, wxID_ANY, _("Colour conversion"));
173 grid->Add (_enable_colour_conversion, wxGBPosition (r, 0), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL);
174 _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
175 grid->Add (_colour_conversion, wxGBPosition (r, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
176 _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
177 grid->Add (_colour_conversion_button, wxGBPosition (r, 3), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
180 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
181 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
182 wxFont font = _description->GetFont();
183 font.SetStyle(wxFONTSTYLE_ITALIC);
184 font.SetPointSize(font.GetPointSize() - 1);
185 _description->SetFont(font);
188 _left_crop->wrapped()->SetRange (0, 1024);
189 _top_crop->wrapped()->SetRange (0, 1024);
190 _right_crop->wrapped()->SetRange (0, 1024);
191 _bottom_crop->wrapped()->SetRange (0, 1024);
193 vector<VideoContentScale> scales = VideoContentScale::all ();
194 _scale->wrapped()->Clear ();
195 for (vector<VideoContentScale>::iterator i = scales.begin(); i != scales.end(); ++i) {
196 _scale->wrapped()->Append (std_to_wx (i->name ()));
199 _frame_type->wrapped()->Append (_("2D"));
200 _frame_type->wrapped()->Append (_("3D left/right"));
201 _frame_type->wrapped()->Append (_("3D top/bottom"));
202 _frame_type->wrapped()->Append (_("3D alternate"));
203 _frame_type->wrapped()->Append (_("3D left only"));
204 _frame_type->wrapped()->Append (_("3D right only"));
206 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
207 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
209 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
210 _enable_colour_conversion->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&VideoPanel::enable_colour_conversion_clicked, this));
211 _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
215 VideoPanel::film_changed (Film::Property property)
218 case Film::CONTAINER:
219 case Film::VIDEO_FRAME_RATE:
220 case Film::RESOLUTION:
221 setup_description ();
229 VideoPanel::film_content_changed (int property)
231 VideoContentList vc = _parent->selected_video ();
232 shared_ptr<VideoContent> vcs;
233 shared_ptr<FFmpegContent> fcs;
236 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
239 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
240 setup_description ();
241 } else if (property == VideoContentProperty::VIDEO_CROP) {
242 setup_description ();
243 } else if (property == VideoContentProperty::VIDEO_SCALE) {
244 setup_description ();
245 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
246 setup_description ();
247 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
249 _colour_conversion->SetLabel (wxT (""));
250 } else if (vcs->colour_conversion ()) {
251 optional<size_t> preset = vcs->colour_conversion().get().preset ();
252 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
253 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
254 _enable_colour_conversion->SetValue (true);
255 _colour_conversion->Enable (true);
256 _colour_conversion_button->Enable (true);
258 _colour_conversion->SetLabel (_("None"));
259 _enable_colour_conversion->SetValue (false);
260 _colour_conversion->Enable (false);
261 _colour_conversion_button->Enable (false);
263 } else if (property == FFmpegContentProperty::FILTERS) {
265 string const p = Filter::ffmpeg_string (fcs->filters ());
267 _filters->SetLabel (_("None"));
269 _filters->SetLabel (std_to_wx (p));
272 } else if (property == VideoContentProperty::VIDEO_FADE_IN) {
273 set<ContentTime> check;
274 for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) {
275 check.insert ((*i)->fade_in ());
278 if (check.size() == 1) {
279 _fade_in->set (vc.front()->fade_in (), vc.front()->video_frame_rate ());
283 } else if (property == VideoContentProperty::VIDEO_FADE_OUT) {
284 set<ContentTime> check;
285 for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) {
286 check.insert ((*i)->fade_out ());
289 if (check.size() == 1) {
290 _fade_out->set (vc.front()->fade_out (), vc.front()->video_frame_rate ());
297 /** Called when the `Edit filters' button has been clicked */
299 VideoPanel::edit_filters_clicked ()
301 FFmpegContentList c = _parent->selected_ffmpeg ();
306 FilterDialog* d = new FilterDialog (this, c.front()->filters());
307 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
313 VideoPanel::setup_description ()
315 VideoContentList vc = _parent->selected_video ();
317 _description->SetLabel ("");
319 } else if (vc.size() > 1) {
320 _description->SetLabel (_("Multiple content selected"));
324 string d = vc.front()->processing_description ();
325 size_t lines = count (d.begin(), d.end(), '\n');
327 for (int i = lines; i < 6; ++i) {
331 _description->SetLabel (std_to_wx (d));
336 VideoPanel::edit_colour_conversion_clicked ()
338 VideoContentList vc = _parent->selected_video ();
339 if (vc.size() != 1) {
343 if (!vc.front()->colour_conversion ()) {
347 ColourConversion conversion = vc.front()->colour_conversion().get ();
348 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
352 vc.front()->set_colour_conversion (d->get ());
357 VideoPanel::content_selection_changed ()
359 VideoContentList video_sel = _parent->selected_video ();
360 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
362 bool const single = video_sel.size() == 1;
364 _left_crop->set_content (video_sel);
365 _right_crop->set_content (video_sel);
366 _top_crop->set_content (video_sel);
367 _bottom_crop->set_content (video_sel);
368 _frame_type->set_content (video_sel);
369 _scale->set_content (video_sel);
371 _filters_button->Enable (single && !ffmpeg_sel.empty ());
372 _colour_conversion_button->Enable (single);
374 film_content_changed (VideoContentProperty::VIDEO_CROP);
375 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
376 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
377 film_content_changed (VideoContentProperty::VIDEO_FADE_IN);
378 film_content_changed (VideoContentProperty::VIDEO_FADE_OUT);
379 film_content_changed (FFmpegContentProperty::FILTERS);
383 VideoPanel::fade_in_changed ()
385 VideoContentList vc = _parent->selected_video ();
386 for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
387 (*i)->set_fade_in (_fade_in->get (_parent->film()->video_frame_rate ()));
392 VideoPanel::fade_out_changed ()
394 VideoContentList vc = _parent->selected_video ();
395 for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
396 (*i)->set_fade_out (_fade_out->get (_parent->film()->video_frame_rate ()));
401 VideoPanel::enable_colour_conversion_clicked ()
403 VideoContentList vc = _parent->selected_video ();
404 if (vc.size() != 1) {
408 if (_enable_colour_conversion->GetValue()) {
409 vc.front()->set_default_colour_conversion ();
411 vc.front()->unset_colour_conversion ();