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"));
203 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
204 _colour_conversion_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_colour_conversion_clicked, this));
208 VideoPanel::film_changed (Film::Property property)
211 case Film::CONTAINER:
212 case Film::VIDEO_FRAME_RATE:
213 setup_description ();
221 VideoPanel::film_content_changed (int property)
223 VideoContentList vc = _editor->selected_video_content ();
224 shared_ptr<VideoContent> vcs;
225 shared_ptr<FFmpegContent> fcs;
228 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
231 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
232 setup_description ();
233 } else if (property == VideoContentProperty::VIDEO_CROP) {
234 setup_description ();
235 } else if (property == VideoContentProperty::VIDEO_RATIO) {
236 setup_description ();
237 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
238 setup_description ();
239 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
240 optional<size_t> preset = vcs ? vcs->colour_conversion().preset () : optional<size_t> ();
241 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
242 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
243 } else if (property == FFmpegContentProperty::FILTERS) {
245 pair<string, string> p = Filter::ffmpeg_strings (fcs->filters ());
246 if (p.first.empty () && p.second.empty ()) {
247 _filters->SetLabel (_("None"));
249 string const b = p.first + " " + p.second;
250 _filters->SetLabel (std_to_wx (b));
256 /** Called when the `Edit filters' button has been clicked */
258 VideoPanel::edit_filters_clicked ()
260 FFmpegContentList c = _editor->selected_ffmpeg_content ();
265 FilterDialog* d = new FilterDialog (this, c.front()->filters());
266 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
272 VideoPanel::setup_description ()
274 FFmpegContentList vc = _editor->selected_ffmpeg_content ();
276 _description->SetLabel ("");
278 } else if (vc.size() > 1) {
279 _description->SetLabel (_("Multiple content selected"));
283 shared_ptr<FFmpegContent> vcs = vc.front ();
289 if (vcs->video_size().width && vcs->video_size().height) {
290 d << wxString::Format (
291 _("Content video is %dx%d (%.2f:1)\n"),
292 vcs->video_size_after_3d_split().width,
293 vcs->video_size_after_3d_split().height,
294 vcs->video_size_after_3d_split().ratio ()
299 Crop const crop = vcs->crop ();
300 if ((crop.left || crop.right || crop.top || crop.bottom) && vcs->video_size() != libdcp::Size (0, 0)) {
301 libdcp::Size cropped = vcs->video_size_after_crop ();
302 d << wxString::Format (
303 _("Cropped to %dx%d (%.2f:1)\n"),
304 cropped.width, cropped.height,
310 Ratio const * ratio = vcs->ratio ();
311 libdcp::Size container_size = fit_ratio_within (_editor->film()->container()->ratio (), _editor->film()->full_frame ());
312 float const ratio_value = ratio ? ratio->ratio() : vcs->video_size_after_crop().ratio ();
314 /* We have a specified ratio to scale to */
315 libdcp::Size const scaled = fit_ratio_within (ratio_value, container_size);
317 d << wxString::Format (
318 _("Scaled to %dx%d (%.2f:1)\n"),
319 scaled.width, scaled.height,
324 if (scaled != container_size) {
325 d << wxString::Format (
326 _("Padded with black to %dx%d (%.2f:1)\n"),
327 container_size.width, container_size.height,
328 container_size.ratio ()
333 d << wxString::Format (_("Content frame rate %.4f\n"), vcs->video_frame_rate ());
335 FrameRateChange frc (vcs->video_frame_rate(), _editor->film()->video_frame_rate ());
336 d << frc.description << "\n";
339 for (int i = lines; i < 6; ++i) {
343 _description->SetLabel (d);
348 VideoPanel::edit_colour_conversion_clicked ()
350 VideoContentList vc = _editor->selected_video_content ();
351 if (vc.size() != 1) {
355 ColourConversion conversion = vc.front()->colour_conversion ();
356 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
360 vc.front()->set_colour_conversion (d->get ());
365 VideoPanel::content_selection_changed ()
367 VideoContentList sel = _editor->selected_video_content ();
368 bool const single = sel.size() == 1;
370 _left_crop->set_content (sel);
371 _right_crop->set_content (sel);
372 _top_crop->set_content (sel);
373 _bottom_crop->set_content (sel);
374 _frame_type->set_content (sel);
375 _ratio->set_content (sel);
377 /* Things that are only allowed with single selections */
378 _filters_button->Enable (single);
379 _colour_conversion_button->Enable (single);
381 film_content_changed (VideoContentProperty::VIDEO_CROP);
382 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
383 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
384 film_content_changed (FFmpegContentProperty::FILTERS);