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 "content_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 ContentWidget<VideoContent, wxSpinCtrl> (
60 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
61 VideoContentProperty::VIDEO_CROP,
62 boost::mem_fn (&VideoContent::left_crop),
63 boost::mem_fn (&VideoContent::set_left_crop)
65 _left_crop->add (grid, wxGBPosition (r, 1));
68 add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0));
69 _right_crop = new ContentWidget<VideoContent, wxSpinCtrl> (
71 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
72 VideoContentProperty::VIDEO_CROP,
73 boost::mem_fn (&VideoContent::right_crop),
74 boost::mem_fn (&VideoContent::set_right_crop)
76 _right_crop->add (grid, wxGBPosition (r, 1));
79 add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0));
80 _top_crop = new ContentWidget<VideoContent, wxSpinCtrl> (
82 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
83 VideoContentProperty::VIDEO_CROP,
84 boost::mem_fn (&VideoContent::top_crop),
85 boost::mem_fn (&VideoContent::set_top_crop)
87 _top_crop->add (grid, wxGBPosition (r,1 ));
90 add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0));
91 _bottom_crop = new ContentWidget<VideoContent, wxSpinCtrl> (
93 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
94 VideoContentProperty::VIDEO_CROP,
95 boost::mem_fn (&VideoContent::bottom_crop),
96 boost::mem_fn (&VideoContent::set_bottom_crop)
98 _bottom_crop->add (grid, wxGBPosition (r, 1));
101 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
102 _ratio = new wxChoice (this, wxID_ANY);
103 grid->Add (_ratio, wxGBPosition (r, 1));
107 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
108 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
110 wxClientDC dc (this);
111 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
114 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
115 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
116 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
117 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
118 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
123 add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
124 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
126 wxClientDC dc (this);
127 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
130 _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
132 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
133 _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
134 s->Add (_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
135 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
139 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
140 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
141 wxFont font = _description->GetFont();
142 font.SetStyle(wxFONTSTYLE_ITALIC);
143 font.SetPointSize(font.GetPointSize() - 1);
144 _description->SetFont(font);
147 _left_crop->wrapped()->SetRange (0, 1024);
148 _top_crop->wrapped()->SetRange (0, 1024);
149 _right_crop->wrapped()->SetRange (0, 1024);
150 _bottom_crop->wrapped()->SetRange (0, 1024);
152 vector<Ratio const *> ratios = Ratio::all ();
154 for (vector<Ratio const *>::iterator i = ratios.begin(); i != ratios.end(); ++i) {
155 _ratio->Append (std_to_wx ((*i)->nickname ()));
157 _ratio->Append (_("No stretch"));
159 _frame_type->Append (_("2D"));
160 _frame_type->Append (_("3D left/right"));
162 _frame_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::frame_type_changed, this));
163 _ratio->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::ratio_changed, this));
164 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
165 _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
169 VideoPanel::film_changed (Film::Property property)
172 case Film::CONTAINER:
173 case Film::VIDEO_FRAME_RATE:
174 setup_description ();
182 VideoPanel::film_content_changed (int property)
184 VideoContentList vc = _editor->selected_video_content ();
185 shared_ptr<VideoContent> vcs;
186 shared_ptr<FFmpegContent> fcs;
189 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
192 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
193 checked_set (_frame_type, vcs ? vcs->video_frame_type () : VIDEO_FRAME_TYPE_2D);
194 setup_description ();
195 } else if (property == VideoContentProperty::VIDEO_CROP) {
196 setup_description ();
197 } else if (property == VideoContentProperty::VIDEO_RATIO) {
200 vector<Ratio const *> ratios = Ratio::all ();
201 vector<Ratio const *>::iterator i = ratios.begin ();
202 while (i != ratios.end() && *i != vcs->ratio()) {
207 if (i == ratios.end()) {
208 checked_set (_ratio, ratios.size ());
210 checked_set (_ratio, n);
213 checked_set (_ratio, -1);
215 setup_description ();
216 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
217 setup_description ();
218 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
219 optional<size_t> preset = vcs ? vcs->colour_conversion().preset () : optional<size_t> ();
220 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
221 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
222 } else if (property == FFmpegContentProperty::FILTERS) {
224 pair<string, string> p = Filter::ffmpeg_strings (fcs->filters ());
225 if (p.first.empty () && p.second.empty ()) {
226 _filters->SetLabel (_("None"));
228 string const b = p.first + " " + p.second;
229 _filters->SetLabel (std_to_wx (b));
235 /** Called when the `Edit filters' button has been clicked */
237 VideoPanel::edit_filters_clicked ()
239 FFmpegContentList c = _editor->selected_ffmpeg_content ();
244 FilterDialog* d = new FilterDialog (this, c.front()->filters());
245 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
251 VideoPanel::setup_description ()
253 FFmpegContentList vc = _editor->selected_ffmpeg_content ();
255 _description->SetLabel ("");
257 } else if (vc.size() > 1) {
258 _description->SetLabel (_("Multiple content selected"));
262 shared_ptr<FFmpegContent> vcs = vc.front ();
268 if (vcs->video_size().width && vcs->video_size().height) {
269 d << wxString::Format (
270 _("Content video is %dx%d (%.2f:1)\n"),
271 vcs->video_size_after_3d_split().width,
272 vcs->video_size_after_3d_split().height,
273 vcs->video_size_after_3d_split().ratio ()
278 Crop const crop = vcs->crop ();
279 if ((crop.left || crop.right || crop.top || crop.bottom) && vcs->video_size() != libdcp::Size (0, 0)) {
280 libdcp::Size cropped = vcs->video_size_after_crop ();
281 d << wxString::Format (
282 _("Cropped to %dx%d (%.2f:1)\n"),
283 cropped.width, cropped.height,
289 Ratio const * ratio = vcs->ratio ();
290 libdcp::Size container_size = fit_ratio_within (_editor->film()->container()->ratio (), _editor->film()->full_frame ());
291 float const ratio_value = ratio ? ratio->ratio() : vcs->video_size_after_crop().ratio ();
293 /* We have a specified ratio to scale to */
294 libdcp::Size const scaled = fit_ratio_within (ratio_value, container_size);
296 d << wxString::Format (
297 _("Scaled to %dx%d (%.2f:1)\n"),
298 scaled.width, scaled.height,
303 if (scaled != container_size) {
304 d << wxString::Format (
305 _("Padded with black to %dx%d (%.2f:1)\n"),
306 container_size.width, container_size.height,
307 container_size.ratio ()
312 d << wxString::Format (_("Content frame rate %.4f\n"), vcs->video_frame_rate ());
314 FrameRateConversion frc (vcs->video_frame_rate(), _editor->film()->video_frame_rate ());
315 d << frc.description << "\n";
318 for (int i = lines; i < 6; ++i) {
322 _description->SetLabel (d);
328 VideoPanel::ratio_changed ()
330 if (!_editor->film ()) {
334 VideoContentList vc = _editor->selected_video_content ();
335 if (vc.size() != 1) {
339 int const n = _ratio->GetSelection ();
341 vector<Ratio const *> ratios = Ratio::all ();
342 if (n < int (ratios.size ())) {
343 vc.front()->set_ratio (ratios[n]);
345 vc.front()->set_ratio (0);
351 VideoPanel::frame_type_changed ()
353 VideoContentList vc = _editor->selected_video_content ();
354 if (vc.size() == 1) {
355 vc.front()->set_video_frame_type (static_cast<VideoFrameType> (_frame_type->GetSelection ()));
360 VideoPanel::edit_colour_conversion_clicked ()
362 VideoContentList vc = _editor->selected_video_content ();
363 if (vc.size() != 1) {
367 ColourConversion conversion = vc.front()->colour_conversion ();
368 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
372 vc.front()->set_colour_conversion (d->get ());
377 VideoPanel::content_selection_changed ()
379 VideoContentList sel = _editor->selected_video_content ();
380 bool const single = sel.size() == 1;
382 _left_crop->set_content (sel);
383 _right_crop->set_content (sel);
384 _top_crop->set_content (sel);
385 _bottom_crop->set_content (sel);
387 /* Things that are only allowed with single selections */
388 _frame_type->Enable (single);
389 _ratio->Enable (single);
390 _filters_button->Enable (single);
391 _colour_conversion_button->Enable (single);
393 film_content_changed (VideoContentProperty::VIDEO_FRAME_TYPE);
394 film_content_changed (VideoContentProperty::VIDEO_CROP);
395 film_content_changed (VideoContentProperty::VIDEO_RATIO);
396 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
397 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
398 film_content_changed (FFmpegContentProperty::FILTERS);