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 case Film::RESOLUTION:
215 setup_description ();
223 VideoPanel::film_content_changed (int property)
225 VideoContentList vc = _editor->selected_video_content ();
226 shared_ptr<VideoContent> vcs;
227 shared_ptr<FFmpegContent> fcs;
230 fcs = dynamic_pointer_cast<FFmpegContent> (vcs);
233 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
234 setup_description ();
235 } else if (property == VideoContentProperty::VIDEO_CROP) {
236 setup_description ();
237 } else if (property == VideoContentProperty::VIDEO_RATIO) {
238 setup_description ();
239 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
240 setup_description ();
241 } else if (property == VideoContentProperty::COLOUR_CONVERSION) {
242 optional<size_t> preset = vcs ? vcs->colour_conversion().preset () : optional<size_t> ();
243 vector<PresetColourConversion> cc = Config::instance()->colour_conversions ();
244 _colour_conversion->SetLabel (preset ? std_to_wx (cc[preset.get()].name) : _("Custom"));
245 } else if (property == FFmpegContentProperty::FILTERS) {
247 pair<string, string> p = Filter::ffmpeg_strings (fcs->filters ());
248 if (p.first.empty () && p.second.empty ()) {
249 _filters->SetLabel (_("None"));
251 string const b = p.first + " " + p.second;
252 _filters->SetLabel (std_to_wx (b));
258 /** Called when the `Edit filters' button has been clicked */
260 VideoPanel::edit_filters_clicked ()
262 FFmpegContentList c = _editor->selected_ffmpeg_content ();
267 FilterDialog* d = new FilterDialog (this, c.front()->filters());
268 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, c.front(), _1));
274 VideoPanel::setup_description ()
276 VideoContentList vc = _editor->selected_video_content ();
278 _description->SetLabel ("");
280 } else if (vc.size() > 1) {
281 _description->SetLabel (_("Multiple content selected"));
285 shared_ptr<VideoContent> vcs = vc.front ();
291 if (vcs->video_size().width && vcs->video_size().height) {
292 d << wxString::Format (
293 _("Content video is %dx%d (%.2f:1)\n"),
294 vcs->video_size_after_3d_split().width,
295 vcs->video_size_after_3d_split().height,
296 vcs->video_size_after_3d_split().ratio ()
301 Crop const crop = vcs->crop ();
302 if ((crop.left || crop.right || crop.top || crop.bottom) && vcs->video_size() != dcp::Size (0, 0)) {
303 dcp::Size cropped = vcs->video_size_after_crop ();
304 d << wxString::Format (
305 _("Cropped to %dx%d (%.2f:1)\n"),
306 cropped.width, cropped.height,
312 Ratio const * ratio = vcs->ratio ();
313 dcp::Size container_size = fit_ratio_within (_editor->film()->container()->ratio (), _editor->film()->full_frame ());
314 float const ratio_value = ratio ? ratio->ratio() : vcs->video_size_after_crop().ratio ();
316 /* We have a specified ratio to scale to */
317 dcp::Size const scaled = fit_ratio_within (ratio_value, container_size);
319 d << wxString::Format (
320 _("Scaled to %dx%d (%.2f:1)\n"),
321 scaled.width, scaled.height,
326 if (scaled != container_size) {
327 d << wxString::Format (
328 _("Padded with black to %dx%d (%.2f:1)\n"),
329 container_size.width, container_size.height,
330 container_size.ratio ()
335 d << wxString::Format (_("Content frame rate %.4f\n"), vcs->video_frame_rate ());
337 FrameRateChange frc (vcs->video_frame_rate(), _editor->film()->video_frame_rate ());
338 d << std_to_wx (frc.description) << "\n";
341 for (int i = lines; i < 6; ++i) {
345 _description->SetLabel (d);
350 VideoPanel::edit_colour_conversion_clicked ()
352 VideoContentList vc = _editor->selected_video_content ();
353 if (vc.size() != 1) {
357 ColourConversion conversion = vc.front()->colour_conversion ();
358 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
362 vc.front()->set_colour_conversion (d->get ());
367 VideoPanel::content_selection_changed ()
369 VideoContentList sel = _editor->selected_video_content ();
370 bool const single = sel.size() == 1;
372 _left_crop->set_content (sel);
373 _right_crop->set_content (sel);
374 _top_crop->set_content (sel);
375 _bottom_crop->set_content (sel);
376 _frame_type->set_content (sel);
377 _ratio->set_content (sel);
379 /* Things that are only allowed with single selections */
380 _filters_button->Enable (single);
381 _colour_conversion_button->Enable (single);
383 film_content_changed (VideoContentProperty::VIDEO_CROP);
384 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
385 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
386 film_content_changed (FFmpegContentProperty::FILTERS);