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;
45 index_to_ratio (int n)
49 vector<Ratio const *> ratios = Ratio::all ();
50 if (n >= int (ratios.size ())) {
58 ratio_to_index (Ratio const * r)
60 vector<Ratio const *> ratios = Ratio::all ();
62 while (i < ratios.size() && ratios[i] != r) {
69 VideoPanel::VideoPanel (FilmEditor* e)
70 : FilmEditorPanel (e, _("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));
90 add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0));
91 _left_crop = new ContentSpinCtrl<VideoContent> (
93 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
94 VideoContentProperty::VIDEO_CROP,
95 boost::mem_fn (&VideoContent::left_crop),
96 boost::mem_fn (&VideoContent::set_left_crop)
98 _left_crop->add (grid, wxGBPosition (r, 1));
101 add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0));
102 _right_crop = new ContentSpinCtrl<VideoContent> (
104 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
105 VideoContentProperty::VIDEO_CROP,
106 boost::mem_fn (&VideoContent::right_crop),
107 boost::mem_fn (&VideoContent::set_right_crop)
109 _right_crop->add (grid, wxGBPosition (r, 1));
112 add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0));
113 _top_crop = new ContentSpinCtrl<VideoContent> (
115 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
116 VideoContentProperty::VIDEO_CROP,
117 boost::mem_fn (&VideoContent::top_crop),
118 boost::mem_fn (&VideoContent::set_top_crop)
120 _top_crop->add (grid, wxGBPosition (r,1 ));
123 add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0));
124 _bottom_crop = new ContentSpinCtrl<VideoContent> (
126 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
127 VideoContentProperty::VIDEO_CROP,
128 boost::mem_fn (&VideoContent::bottom_crop),
129 boost::mem_fn (&VideoContent::set_bottom_crop)
131 _bottom_crop->add (grid, wxGBPosition (r, 1));
134 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
135 _ratio = new ContentChoice<VideoContent, Ratio const *> (
137 new wxChoice (this, wxID_ANY),
138 VideoContentProperty::VIDEO_RATIO,
139 boost::mem_fn (&VideoContent::ratio),
140 boost::mem_fn (&VideoContent::set_ratio),
144 _ratio->add (grid, wxGBPosition (r, 1));
148 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
149 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
151 wxClientDC dc (this);
152 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
155 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
156 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
157 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
158 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
159 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
164 add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
165 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
167 wxClientDC dc (this);
168 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
171 _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
173 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
174 _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
175 s->Add (_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
176 grid->Add (s, wxGBPosition (r, 1), 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, 2), 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<Ratio const *> ratios = Ratio::all ();
194 _ratio->wrapped()->Clear ();
195 for (vector<Ratio const *>::iterator i = ratios.begin(); i != ratios.end(); ++i) {
196 _ratio->wrapped()->Append (std_to_wx ((*i)->nickname ()));
198 _ratio->wrapped()->Append (_("No stretch"));
200 _frame_type->wrapped()->Append (_("2D"));
201 _frame_type->wrapped()->Append (_("3D left/right"));
202 _frame_type->wrapped()->Append (_("3D top/bottom"));
204 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
205 _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
209 VideoPanel::film_changed (Film::Property property)
212 case Film::CONTAINER:
213 case Film::VIDEO_FRAME_RATE:
214 setup_description ();
222 VideoPanel::film_content_changed (int property)
224 VideoContentList vc = _editor->selected_video_content ();
225 shared_ptr<VideoContent> vcs;
226 shared_ptr<FFmpegContent> fcs;
229 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
232 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
233 setup_description ();
234 } else if (property == VideoContentProperty::VIDEO_CROP) {
235 setup_description ();
236 } else if (property == VideoContentProperty::VIDEO_RATIO) {
237 setup_description ();
238 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
239 setup_description ();
240 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
241 optional<size_t> preset = vcs ? vcs->colour_conversion().preset () : optional<size_t> ();
242 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
243 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
244 } else if (property == FFmpegContentProperty::FILTERS) {
246 pair<string, string> p = Filter::ffmpeg_strings (fcs->filters ());
247 if (p.first.empty () && p.second.empty ()) {
248 _filters->SetLabel (_("None"));
250 string const b = p.first + " " + p.second;
251 _filters->SetLabel (std_to_wx (b));
257 /** Called when the `Edit filters' button has been clicked */
259 VideoPanel::edit_filters_clicked ()
261 FFmpegContentList c = _editor->selected_ffmpeg_content ();
266 FilterDialog* d = new FilterDialog (this, c.front()->filters());
267 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
273 VideoPanel::setup_description ()
275 VideoContentList vc = _editor->selected_video_content ();
277 _description->SetLabel ("");
279 } else if (vc.size() > 1) {
280 _description->SetLabel (_("Multiple content selected"));
284 shared_ptr<VideoContent> vcs = vc.front ();
290 if (vcs->video_size().width && vcs->video_size().height) {
291 d << wxString::Format (
292 _("Content video is %dx%d (%.2f:1)\n"),
293 vcs->video_size_after_3d_split().width,
294 vcs->video_size_after_3d_split().height,
295 vcs->video_size_after_3d_split().ratio ()
300 Crop const crop = vcs->crop ();
301 if ((crop.left || crop.right || crop.top || crop.bottom) && vcs->video_size() != libdcp::Size (0, 0)) {
302 libdcp::Size cropped = vcs->video_size_after_crop ();
303 d << wxString::Format (
304 _("Cropped to %dx%d (%.2f:1)\n"),
305 cropped.width, cropped.height,
311 Ratio const * ratio = vcs->ratio ();
312 libdcp::Size container_size = fit_ratio_within (_editor->film()->container()->ratio (), _editor->film()->full_frame ());
313 float const ratio_value = ratio ? ratio->ratio() : vcs->video_size_after_crop().ratio ();
315 /* We have a specified ratio to scale to */
316 libdcp::Size const scaled = fit_ratio_within (ratio_value, container_size);
318 d << wxString::Format (
319 _("Scaled to %dx%d (%.2f:1)\n"),
320 scaled.width, scaled.height,
325 if (scaled != container_size) {
326 d << wxString::Format (
327 _("Padded with black to %dx%d (%.2f:1)\n"),
328 container_size.width, container_size.height,
329 container_size.ratio ()
334 d << wxString::Format (_("Content frame rate %.4f\n"), vcs->video_frame_rate ());
336 FrameRateConversion frc (vcs->video_frame_rate(), _editor->film()->video_frame_rate ());
337 d << frc.description << "\n";
340 for (int i = lines; i < 6; ++i) {
344 _description->SetLabel (d);
349 VideoPanel::edit_colour_conversion_clicked ()
351 VideoContentList vc = _editor->selected_video_content ();
352 if (vc.size() != 1) {
356 ColourConversion conversion = vc.front()->colour_conversion ();
357 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
361 vc.front()->set_colour_conversion (d->get ());
366 VideoPanel::content_selection_changed ()
368 VideoContentList sel = _editor->selected_video_content ();
369 bool const single = sel.size() == 1;
371 _left_crop->set_content (sel);
372 _right_crop->set_content (sel);
373 _top_crop->set_content (sel);
374 _bottom_crop->set_content (sel);
375 _frame_type->set_content (sel);
376 _ratio->set_content (sel);
378 /* Things that are only allowed with single selections */
379 _filters_button->Enable (single);
380 _colour_conversion_button->Enable (single);
382 film_content_changed (VideoContentProperty::VIDEO_CROP);
383 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
384 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
385 film_content_changed (FFmpegContentProperty::FILTERS);