2 Copyright (C) 2012-2013 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/ratio.h"
22 #include "lib/filter.h"
23 #include "lib/ffmpeg_content.h"
24 #include "lib/colour_conversion.h"
25 #include "lib/config.h"
27 #include "filter_dialog.h"
28 #include "video_panel.h"
30 #include "film_editor.h"
31 #include "content_colour_conversion_dialog.h"
32 #include "multiple_widget.h"
39 using boost::shared_ptr;
40 using boost::dynamic_pointer_cast;
42 using boost::optional;
44 VideoPanel::VideoPanel (FilmEditor* e)
45 : FilmEditorPanel (e, _("Video"))
47 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
48 _sizer->Add (grid, 0, wxALL, 8);
52 add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
53 _frame_type = new wxChoice (this, wxID_ANY);
54 grid->Add (_frame_type, wxGBPosition (r, 1));
57 add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0));
58 _left_crop = new MultipleWidget<wxSpinCtrl> (this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)));
59 _left_crop->add (grid, wxGBPosition (r, 1));
62 add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0));
63 _right_crop = new MultipleWidget<wxSpinCtrl> (this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)));
64 _right_crop->add (grid, wxGBPosition (r, 1));
67 add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0));
68 _top_crop = new MultipleWidget<wxSpinCtrl> (this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)));
69 _top_crop->add (grid, wxGBPosition (r,1 ));
72 add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0));
73 _bottom_crop = new MultipleWidget<wxSpinCtrl> (this, new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)));
74 _bottom_crop->add (grid, wxGBPosition (r, 1));
77 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
78 _ratio = new wxChoice (this, wxID_ANY);
79 grid->Add (_ratio, wxGBPosition (r, 1));
83 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
84 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
87 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
90 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
91 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
92 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
93 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
94 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
99 add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
100 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
102 wxClientDC dc (this);
103 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
106 _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
108 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
109 _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
110 s->Add (_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
111 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
115 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
116 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
117 wxFont font = _description->GetFont();
118 font.SetStyle(wxFONTSTYLE_ITALIC);
119 font.SetPointSize(font.GetPointSize() - 1);
120 _description->SetFont(font);
123 _left_crop->wrapped()->SetRange (0, 1024);
124 _top_crop->wrapped()->SetRange (0, 1024);
125 _right_crop->wrapped()->SetRange (0, 1024);
126 _bottom_crop->wrapped()->SetRange (0, 1024);
128 vector<Ratio const *> ratios = Ratio::all ();
130 for (vector<Ratio const *>::iterator i = ratios.begin(); i != ratios.end(); ++i) {
131 _ratio->Append (std_to_wx ((*i)->nickname ()));
133 _ratio->Append (_("No stretch"));
135 _frame_type->Append (_("2D"));
136 _frame_type->Append (_("3D left/right"));
138 _frame_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::frame_type_changed, this));
139 _left_crop->SetAllSame.connect (boost::bind (&VideoPanel::set_left_crop_same, this));
140 _left_crop->wrapped()->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::left_crop_changed, this));
141 _right_crop->wrapped()->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::right_crop_changed, this));
142 _top_crop->wrapped()->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::top_crop_changed, this));
143 _bottom_crop->wrapped()->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::bottom_crop_changed, this));
144 _ratio->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::ratio_changed, this));
145 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
146 _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
150 /** Called when the left crop widget has been changed */
152 VideoPanel::left_crop_changed ()
154 VideoContentList c = _editor->selected_video_content ();
155 for (VideoContentList::iterator i = c.begin(); i != c.end(); ++i) {
156 (*i)->set_left_crop (_left_crop->wrapped()->GetValue ());
160 /** Called when the right crop widget has been changed */
162 VideoPanel::right_crop_changed ()
164 VideoContentList c = _editor->selected_video_content ();
165 for (VideoContentList::iterator i = c.begin(); i != c.end(); ++i) {
166 (*i)->set_right_crop (_right_crop->wrapped()->GetValue ());
170 /** Called when the top crop widget has been changed */
172 VideoPanel::top_crop_changed ()
174 VideoContentList c = _editor->selected_video_content ();
175 for (VideoContentList::iterator i = c.begin(); i != c.end(); ++i) {
176 (*i)->set_top_crop (_top_crop->wrapped()->GetValue ());
180 /** Called when the bottom crop value has been changed */
182 VideoPanel::bottom_crop_changed ()
184 VideoContentList c = _editor->selected_video_content ();
185 for (VideoContentList::iterator i = c.begin(); i != c.end(); ++i) {
186 (*i)->set_bottom_crop (_bottom_crop->wrapped()->GetValue ());
191 VideoPanel::film_changed (Film::Property property)
194 case Film::CONTAINER:
195 case Film::VIDEO_FRAME_RATE:
196 setup_description ();
204 VideoPanel::film_content_changed (int property)
206 VideoContentList vc = _editor->selected_video_content ();
207 shared_ptr<VideoContent> vcs;
208 shared_ptr<FFmpegContent> fcs;
211 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
214 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
215 checked_set (_frame_type, vcs ? vcs->video_frame_type () : VIDEO_FRAME_TYPE_2D);
216 setup_description ();
217 } else if (property == VideoContentProperty::VIDEO_CROP) {
218 set_multiple<VideoContent> (vc, _left_crop, &VideoContent::left_crop);
219 set_multiple<VideoContent> (vc, _right_crop, &VideoContent::right_crop);
220 set_multiple<VideoContent> (vc, _top_crop, &VideoContent::top_crop);
221 set_multiple<VideoContent> (vc, _bottom_crop, &VideoContent::bottom_crop);
222 setup_description ();
223 } else if (property == VideoContentProperty::VIDEO_RATIO) {
226 vector<Ratio const *> ratios = Ratio::all ();
227 vector<Ratio const *>::iterator i = ratios.begin ();
228 while (i != ratios.end() && *i != vcs->ratio()) {
233 if (i == ratios.end()) {
234 checked_set (_ratio, ratios.size ());
236 checked_set (_ratio, n);
239 checked_set (_ratio, -1);
241 setup_description ();
242 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
243 setup_description ();
244 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
245 optional<size_t> preset = vcs ? vcs->colour_conversion().preset () : optional<size_t> ();
246 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
247 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
248 } else if (property == FFmpegContentProperty::FILTERS) {
250 pair<string, string> p = Filter::ffmpeg_strings (fcs->filters ());
251 if (p.first.empty () && p.second.empty ()) {
252 _filters->SetLabel (_("None"));
254 string const b = p.first + " " + p.second;
255 _filters->SetLabel (std_to_wx (b));
261 /** Called when the `Edit filters' button has been clicked */
263 VideoPanel::edit_filters_clicked ()
265 FFmpegContentList c = _editor->selected_ffmpeg_content ();
270 FilterDialog* d = new FilterDialog (this, c.front()->filters());
271 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
277 VideoPanel::setup_description ()
279 FFmpegContentList vc = _editor->selected_ffmpeg_content ();
281 _description->SetLabel ("");
283 } else if (vc.size() > 1) {
284 _description->SetLabel (_("Multiple content selected"));
288 shared_ptr<FFmpegContent> vcs = vc.front ();
294 if (vcs->video_size().width && vcs->video_size().height) {
295 d << wxString::Format (
296 _("Content video is %dx%d (%.2f:1)\n"),
297 vcs->video_size_after_3d_split().width,
298 vcs->video_size_after_3d_split().height,
299 vcs->video_size_after_3d_split().ratio ()
304 Crop const crop = vcs->crop ();
305 if ((crop.left || crop.right || crop.top || crop.bottom) && vcs->video_size() != libdcp::Size (0, 0)) {
306 libdcp::Size cropped = vcs->video_size_after_crop ();
307 d << wxString::Format (
308 _("Cropped to %dx%d (%.2f:1)\n"),
309 cropped.width, cropped.height,
315 Ratio const * ratio = vcs->ratio ();
316 libdcp::Size container_size = fit_ratio_within (_editor->film()->container()->ratio (), _editor->film()->full_frame ());
317 float const ratio_value = ratio ? ratio->ratio() : vcs->video_size_after_crop().ratio ();
319 /* We have a specified ratio to scale to */
320 libdcp::Size const scaled = fit_ratio_within (ratio_value, container_size);
322 d << wxString::Format (
323 _("Scaled to %dx%d (%.2f:1)\n"),
324 scaled.width, scaled.height,
329 if (scaled != container_size) {
330 d << wxString::Format (
331 _("Padded with black to %dx%d (%.2f:1)\n"),
332 container_size.width, container_size.height,
333 container_size.ratio ()
338 d << wxString::Format (_("Content frame rate %.4f\n"), vcs->video_frame_rate ());
340 FrameRateConversion frc (vcs->video_frame_rate(), _editor->film()->video_frame_rate ());
341 d << frc.description << "\n";
344 for (int i = lines; i < 6; ++i) {
348 _description->SetLabel (d);
354 VideoPanel::ratio_changed ()
356 if (!_editor->film ()) {
360 VideoContentList vc = _editor->selected_video_content ();
361 if (vc.size() != 1) {
365 int const n = _ratio->GetSelection ();
367 vector<Ratio const *> ratios = Ratio::all ();
368 if (n < int (ratios.size ())) {
369 vc.front()->set_ratio (ratios[n]);
371 vc.front()->set_ratio (0);
377 VideoPanel::frame_type_changed ()
379 VideoContentList vc = _editor->selected_video_content ();
380 if (vc.size() == 1) {
381 vc.front()->set_video_frame_type (static_cast<VideoFrameType> (_frame_type->GetSelection ()));
386 VideoPanel::edit_colour_conversion_clicked ()
388 VideoContentList vc = _editor->selected_video_content ();
389 if (vc.size() != 1) {
393 ColourConversion conversion = vc.front()->colour_conversion ();
394 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
398 vc.front()->set_colour_conversion (d->get ());
403 VideoPanel::content_selection_changed ()
405 VideoContentList sel = _editor->selected_video_content ();
406 bool const single = sel.size() == 1;
407 bool const multiple = sel.size() > 1;
409 /* Things that are allowed with multiple selections */
410 _left_crop->wrapped()->Enable (single || multiple);
411 _right_crop->wrapped()->Enable (single || multiple);
412 _top_crop->wrapped()->Enable (single || multiple);
413 _bottom_crop->wrapped()->Enable (single || multiple);
415 /* Things that are only allowed with single selections */
416 _frame_type->Enable (single);
417 _ratio->Enable (single);
418 _filters_button->Enable (single);
419 _colour_conversion_button->Enable (single);
421 film_content_changed (VideoContentProperty::VIDEO_FRAME_TYPE);
422 film_content_changed (VideoContentProperty::VIDEO_CROP);
423 film_content_changed (VideoContentProperty::VIDEO_RATIO);
424 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
425 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
426 film_content_changed (FFmpegContentProperty::FILTERS);
430 VideoPanel::set_left_crop_same ()
432 VideoContentList sel = _editor->selected_video_content ();
433 for (VideoContentList::iterator i = sel.begin(); i != sel.end(); ++i) {
434 (*i)->set_left_crop (sel.front()->left_crop ());