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 ContentChoice<VideoContent, VideoFrameType> (
55 new wxChoice (this, wxID_ANY),
56 VideoContentProperty::VIDEO_FRAME_TYPE,
57 boost::mem_fn (&VideoContent::video_frame_type),
58 boost::mem_fn (&VideoContent::set_video_frame_type)
60 _frame_type->add (grid, wxGBPosition (r, 1));
63 add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0));
64 _left_crop = new ContentSpinCtrl<VideoContent> (
66 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
67 VideoContentProperty::VIDEO_CROP,
68 boost::mem_fn (&VideoContent::left_crop),
69 boost::mem_fn (&VideoContent::set_left_crop)
71 _left_crop->add (grid, wxGBPosition (r, 1));
74 add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0));
75 _right_crop = new ContentSpinCtrl<VideoContent> (
77 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
78 VideoContentProperty::VIDEO_CROP,
79 boost::mem_fn (&VideoContent::right_crop),
80 boost::mem_fn (&VideoContent::set_right_crop)
82 _right_crop->add (grid, wxGBPosition (r, 1));
85 add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0));
86 _top_crop = new ContentSpinCtrl<VideoContent> (
88 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
89 VideoContentProperty::VIDEO_CROP,
90 boost::mem_fn (&VideoContent::top_crop),
91 boost::mem_fn (&VideoContent::set_top_crop)
93 _top_crop->add (grid, wxGBPosition (r,1 ));
96 add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0));
97 _bottom_crop = new ContentSpinCtrl<VideoContent> (
99 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
100 VideoContentProperty::VIDEO_CROP,
101 boost::mem_fn (&VideoContent::bottom_crop),
102 boost::mem_fn (&VideoContent::set_bottom_crop)
104 _bottom_crop->add (grid, wxGBPosition (r, 1));
107 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
108 _ratio = new wxChoice (this, wxID_ANY);
109 grid->Add (_ratio, wxGBPosition (r, 1));
113 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
114 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
116 wxClientDC dc (this);
117 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
120 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
121 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
122 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
123 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
124 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
129 add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
130 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
132 wxClientDC dc (this);
133 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
136 _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
138 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
139 _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
140 s->Add (_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
141 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
145 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
146 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
147 wxFont font = _description->GetFont();
148 font.SetStyle(wxFONTSTYLE_ITALIC);
149 font.SetPointSize(font.GetPointSize() - 1);
150 _description->SetFont(font);
153 _left_crop->wrapped()->SetRange (0, 1024);
154 _top_crop->wrapped()->SetRange (0, 1024);
155 _right_crop->wrapped()->SetRange (0, 1024);
156 _bottom_crop->wrapped()->SetRange (0, 1024);
158 vector<Ratio const *> ratios = Ratio::all ();
160 for (vector<Ratio const *>::iterator i = ratios.begin(); i != ratios.end(); ++i) {
161 _ratio->Append (std_to_wx ((*i)->nickname ()));
163 _ratio->Append (_("No stretch"));
165 _frame_type->wrapped()->Append (_("2D"));
166 _frame_type->wrapped()->Append (_("3D left/right"));
168 _ratio->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::ratio_changed, this));
169 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
170 _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
174 VideoPanel::film_changed (Film::Property property)
177 case Film::CONTAINER:
178 case Film::VIDEO_FRAME_RATE:
179 setup_description ();
187 VideoPanel::film_content_changed (int property)
189 VideoContentList vc = _editor->selected_video_content ();
190 shared_ptr<VideoContent> vcs;
191 shared_ptr<FFmpegContent> fcs;
194 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
197 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
198 setup_description ();
199 } else if (property == VideoContentProperty::VIDEO_CROP) {
200 setup_description ();
201 } else if (property == VideoContentProperty::VIDEO_RATIO) {
204 vector<Ratio const *> ratios = Ratio::all ();
205 vector<Ratio const *>::iterator i = ratios.begin ();
206 while (i != ratios.end() && *i != vcs->ratio()) {
211 if (i == ratios.end()) {
212 checked_set (_ratio, ratios.size ());
214 checked_set (_ratio, n);
217 checked_set (_ratio, -1);
219 setup_description ();
220 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
221 setup_description ();
222 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
223 optional<size_t> preset = vcs ? vcs->colour_conversion().preset () : optional<size_t> ();
224 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
225 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
226 } else if (property == FFmpegContentProperty::FILTERS) {
228 pair<string, string> p = Filter::ffmpeg_strings (fcs->filters ());
229 if (p.first.empty () && p.second.empty ()) {
230 _filters->SetLabel (_("None"));
232 string const b = p.first + " " + p.second;
233 _filters->SetLabel (std_to_wx (b));
239 /** Called when the `Edit filters' button has been clicked */
241 VideoPanel::edit_filters_clicked ()
243 FFmpegContentList c = _editor->selected_ffmpeg_content ();
248 FilterDialog* d = new FilterDialog (this, c.front()->filters());
249 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
255 VideoPanel::setup_description ()
257 FFmpegContentList vc = _editor->selected_ffmpeg_content ();
259 _description->SetLabel ("");
261 } else if (vc.size() > 1) {
262 _description->SetLabel (_("Multiple content selected"));
266 shared_ptr<FFmpegContent> vcs = vc.front ();
272 if (vcs->video_size().width && vcs->video_size().height) {
273 d << wxString::Format (
274 _("Content video is %dx%d (%.2f:1)\n"),
275 vcs->video_size_after_3d_split().width,
276 vcs->video_size_after_3d_split().height,
277 vcs->video_size_after_3d_split().ratio ()
282 Crop const crop = vcs->crop ();
283 if ((crop.left || crop.right || crop.top || crop.bottom) && vcs->video_size() != libdcp::Size (0, 0)) {
284 libdcp::Size cropped = vcs->video_size_after_crop ();
285 d << wxString::Format (
286 _("Cropped to %dx%d (%.2f:1)\n"),
287 cropped.width, cropped.height,
293 Ratio const * ratio = vcs->ratio ();
294 libdcp::Size container_size = fit_ratio_within (_editor->film()->container()->ratio (), _editor->film()->full_frame ());
295 float const ratio_value = ratio ? ratio->ratio() : vcs->video_size_after_crop().ratio ();
297 /* We have a specified ratio to scale to */
298 libdcp::Size const scaled = fit_ratio_within (ratio_value, container_size);
300 d << wxString::Format (
301 _("Scaled to %dx%d (%.2f:1)\n"),
302 scaled.width, scaled.height,
307 if (scaled != container_size) {
308 d << wxString::Format (
309 _("Padded with black to %dx%d (%.2f:1)\n"),
310 container_size.width, container_size.height,
311 container_size.ratio ()
316 d << wxString::Format (_("Content frame rate %.4f\n"), vcs->video_frame_rate ());
318 FrameRateConversion frc (vcs->video_frame_rate(), _editor->film()->video_frame_rate ());
319 d << frc.description << "\n";
322 for (int i = lines; i < 6; ++i) {
326 _description->SetLabel (d);
332 VideoPanel::ratio_changed ()
334 if (!_editor->film ()) {
338 VideoContentList vc = _editor->selected_video_content ();
339 if (vc.size() != 1) {
343 int const n = _ratio->GetSelection ();
345 vector<Ratio const *> ratios = Ratio::all ();
346 if (n < int (ratios.size ())) {
347 vc.front()->set_ratio (ratios[n]);
349 vc.front()->set_ratio (0);
355 VideoPanel::edit_colour_conversion_clicked ()
357 VideoContentList vc = _editor->selected_video_content ();
358 if (vc.size() != 1) {
362 ColourConversion conversion = vc.front()->colour_conversion ();
363 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
367 vc.front()->set_colour_conversion (d->get ());
372 VideoPanel::content_selection_changed ()
374 VideoContentList sel = _editor->selected_video_content ();
375 bool const single = sel.size() == 1;
377 _left_crop->set_content (sel);
378 _right_crop->set_content (sel);
379 _top_crop->set_content (sel);
380 _bottom_crop->set_content (sel);
381 _frame_type->set_content (sel);
383 /* Things that are only allowed with single selections */
384 _ratio->Enable (single);
385 _filters_button->Enable (single);
386 _colour_conversion_button->Enable (single);
388 film_content_changed (VideoContentProperty::VIDEO_CROP);
389 film_content_changed (VideoContentProperty::VIDEO_RATIO);
390 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
391 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
392 film_content_changed (FFmpegContentProperty::FILTERS);