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));
90 wxGridBagSizer* crop = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
92 add_label_to_grid_bag_sizer (crop, this, _("Left crop"), true, wxGBPosition (cr, 0));
93 _left_crop = new ContentSpinCtrl<VideoContent> (
95 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
96 VideoContentProperty::VIDEO_CROP,
97 boost::mem_fn (&VideoContent::left_crop),
98 boost::mem_fn (&VideoContent::set_left_crop)
100 _left_crop->add (crop, wxGBPosition (cr, 1));
102 add_label_to_grid_bag_sizer (crop, this, _("Right crop"), true, wxGBPosition (cr, 2));
103 _right_crop = new ContentSpinCtrl<VideoContent> (
105 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
106 VideoContentProperty::VIDEO_CROP,
107 boost::mem_fn (&VideoContent::right_crop),
108 boost::mem_fn (&VideoContent::set_right_crop)
110 _right_crop->add (crop, wxGBPosition (cr, 3));
114 add_label_to_grid_bag_sizer (crop, this, _("Top crop"), true, wxGBPosition (cr, 0));
115 _top_crop = new ContentSpinCtrl<VideoContent> (
117 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
118 VideoContentProperty::VIDEO_CROP,
119 boost::mem_fn (&VideoContent::top_crop),
120 boost::mem_fn (&VideoContent::set_top_crop)
122 _top_crop->add (crop, wxGBPosition (cr, 1));
124 add_label_to_grid_bag_sizer (crop, this, _("Bottom crop"), true, wxGBPosition (cr, 2));
125 _bottom_crop = new ContentSpinCtrl<VideoContent> (
127 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
128 VideoContentProperty::VIDEO_CROP,
129 boost::mem_fn (&VideoContent::bottom_crop),
130 boost::mem_fn (&VideoContent::set_bottom_crop)
132 _bottom_crop->add (crop, wxGBPosition (cr, 3));
134 grid->Add (crop, wxGBPosition (r, 0), wxGBSpan (2, 3));
137 add_label_to_grid_bag_sizer (grid, this, _("Fade in"), true, wxGBPosition (r, 0));
138 _fade_in = new Timecode<ContentTime> (this);
139 grid->Add (_fade_in, wxGBPosition (r, 1), wxGBSpan (1, 3));
142 add_label_to_grid_bag_sizer (grid, this, _("Fade out"), true, wxGBPosition (r, 0));
143 _fade_out = new Timecode<ContentTime> (this);
144 grid->Add (_fade_out, wxGBPosition (r, 1), wxGBSpan (1, 3));
147 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
148 _scale = new ContentChoice<VideoContent, VideoContentScale> (
150 new wxChoice (this, wxID_ANY),
151 VideoContentProperty::VIDEO_SCALE,
152 boost::mem_fn (&VideoContent::scale),
153 boost::mem_fn (&VideoContent::set_scale),
157 _scale->add (grid, wxGBPosition (r, 1), wxGBSpan (1, 2));
160 wxClientDC dc (this);
161 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
164 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
165 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
166 grid->Add (_filters, wxGBPosition (r, 1), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL);
167 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
168 grid->Add (_filters_button, wxGBPosition (r, 3), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
171 _enable_colour_conversion = new wxCheckBox (this, wxID_ANY, _("Colour conversion"));
172 grid->Add (_enable_colour_conversion, wxGBPosition (r, 0), wxGBSpan (1, 2), wxALIGN_CENTER_VERTICAL);
173 _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
174 grid->Add (_colour_conversion, wxGBPosition (r, 2), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
175 _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
176 grid->Add (_colour_conversion_button, wxGBPosition (r, 3), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
179 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
180 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 4), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
181 wxFont font = _description->GetFont();
182 font.SetStyle(wxFONTSTYLE_ITALIC);
183 font.SetPointSize(font.GetPointSize() - 1);
184 _description->SetFont(font);
187 _left_crop->wrapped()->SetRange (0, 1024);
188 _top_crop->wrapped()->SetRange (0, 1024);
189 _right_crop->wrapped()->SetRange (0, 1024);
190 _bottom_crop->wrapped()->SetRange (0, 1024);
192 vector<VideoContentScale> scales = VideoContentScale::all ();
193 _scale->wrapped()->Clear ();
194 for (vector<VideoContentScale>::iterator i = scales.begin(); i != scales.end(); ++i) {
195 _scale->wrapped()->Append (std_to_wx (i->name ()));
198 _frame_type->wrapped()->Append (_("2D"));
199 _frame_type->wrapped()->Append (_("3D left/right"));
200 _frame_type->wrapped()->Append (_("3D top/bottom"));
201 _frame_type->wrapped()->Append (_("3D alternate"));
202 _frame_type->wrapped()->Append (_("3D left only"));
203 _frame_type->wrapped()->Append (_("3D right only"));
205 _fade_in->Changed.connect (boost::bind (&VideoPanel::fade_in_changed, this));
206 _fade_out->Changed.connect (boost::bind (&VideoPanel::fade_out_changed, this));
208 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
209 _enable_colour_conversion->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&VideoPanel::enable_colour_conversion_clicked, this));
210 _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
214 VideoPanel::film_changed (Film::Property property)
217 case Film::CONTAINER:
218 case Film::VIDEO_FRAME_RATE:
219 case Film::RESOLUTION:
220 setup_description ();
228 VideoPanel::film_content_changed (int property)
230 VideoContentList vc = _parent->selected_video ();
231 shared_ptr<VideoContent> vcs;
232 shared_ptr<FFmpegContent> fcs;
235 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
238 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
239 setup_description ();
240 } else if (property == VideoContentProperty::VIDEO_CROP) {
241 setup_description ();
242 } else if (property == VideoContentProperty::VIDEO_SCALE) {
243 setup_description ();
244 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
245 setup_description ();
246 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
248 _colour_conversion->SetLabel (wxT (""));
249 } else if (vcs->colour_conversion ()) {
250 optional<size_t> preset = vcs->colour_conversion().get().preset ();
251 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
252 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
253 _enable_colour_conversion->SetValue (true);
254 _colour_conversion->Enable (true);
255 _colour_conversion_button->Enable (true);
257 _colour_conversion->SetLabel (_("None"));
258 _enable_colour_conversion->SetValue (false);
259 _colour_conversion->Enable (false);
260 _colour_conversion_button->Enable (false);
262 } else if (property == FFmpegContentProperty::FILTERS) {
264 string const p = Filter::ffmpeg_string (fcs->filters ());
266 _filters->SetLabel (_("None"));
268 _filters->SetLabel (std_to_wx (p));
271 } else if (property == VideoContentProperty::VIDEO_FADE_IN) {
272 set<ContentTime> check;
273 for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) {
274 check.insert ((*i)->fade_in ());
277 if (check.size() == 1) {
278 _fade_in->set (vc.front()->fade_in (), vc.front()->video_frame_rate ());
282 } else if (property == VideoContentProperty::VIDEO_FADE_OUT) {
283 set<ContentTime> check;
284 for (VideoContentList::const_iterator i = vc.begin (); i != vc.end(); ++i) {
285 check.insert ((*i)->fade_out ());
288 if (check.size() == 1) {
289 _fade_out->set (vc.front()->fade_out (), vc.front()->video_frame_rate ());
296 /** Called when the `Edit filters' button has been clicked */
298 VideoPanel::edit_filters_clicked ()
300 FFmpegContentList c = _parent->selected_ffmpeg ();
305 FilterDialog* d = new FilterDialog (this, c.front()->filters());
306 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
312 VideoPanel::setup_description ()
314 VideoContentList vc = _parent->selected_video ();
316 _description->SetLabel ("");
318 } else if (vc.size() > 1) {
319 _description->SetLabel (_("Multiple content selected"));
323 string d = vc.front()->processing_description ();
324 size_t lines = count (d.begin(), d.end(), '\n');
326 for (int i = lines; i < 6; ++i) {
330 _description->SetLabel (std_to_wx (d));
335 VideoPanel::edit_colour_conversion_clicked ()
337 VideoContentList vc = _parent->selected_video ();
338 if (vc.size() != 1) {
342 if (!vc.front()->colour_conversion ()) {
346 ColourConversion conversion = vc.front()->colour_conversion().get ();
347 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
351 vc.front()->set_colour_conversion (d->get ());
356 VideoPanel::content_selection_changed ()
358 VideoContentList video_sel = _parent->selected_video ();
359 FFmpegContentList ffmpeg_sel = _parent->selected_ffmpeg ();
361 bool const single = video_sel.size() == 1;
363 _left_crop->set_content (video_sel);
364 _right_crop->set_content (video_sel);
365 _top_crop->set_content (video_sel);
366 _bottom_crop->set_content (video_sel);
367 _frame_type->set_content (video_sel);
368 _scale->set_content (video_sel);
370 _filters_button->Enable (single && !ffmpeg_sel.empty ());
371 _colour_conversion_button->Enable (single);
373 film_content_changed (VideoContentProperty::VIDEO_CROP);
374 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
375 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
376 film_content_changed (VideoContentProperty::VIDEO_FADE_IN);
377 film_content_changed (VideoContentProperty::VIDEO_FADE_OUT);
378 film_content_changed (FFmpegContentProperty::FILTERS);
382 VideoPanel::fade_in_changed ()
384 VideoContentList vc = _parent->selected_video ();
385 for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
386 (*i)->set_fade_in (_fade_in->get (_parent->film()->video_frame_rate ()));
391 VideoPanel::fade_out_changed ()
393 VideoContentList vc = _parent->selected_video ();
394 for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
395 (*i)->set_fade_out (_fade_out->get (_parent->film()->video_frame_rate ()));
400 VideoPanel::enable_colour_conversion_clicked ()
402 VideoContentList vc = _parent->selected_video ();
403 if (vc.size() != 1) {
407 if (_enable_colour_conversion->GetValue()) {
408 vc.front()->set_default_colour_conversion ();
410 vc.front()->unset_colour_conversion ();