2 Copyright (C) 2012-2014 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/filter.h"
22 #include "lib/ffmpeg_content.h"
23 #include "lib/colour_conversion.h"
24 #include "lib/config.h"
26 #include "lib/ratio.h"
27 #include "lib/frame_rate_change.h"
28 #include "filter_dialog.h"
29 #include "video_panel.h"
31 #include "film_editor.h"
32 #include "content_colour_conversion_dialog.h"
33 #include "content_widget.h"
40 using boost::shared_ptr;
41 using boost::dynamic_pointer_cast;
43 using boost::optional;
45 static VideoContentScale
46 index_to_scale (int n)
48 vector<VideoContentScale> scales = VideoContentScale::all ();
50 assert (n < int (scales.size ()));
55 scale_to_index (VideoContentScale scale)
57 vector<VideoContentScale> scales = VideoContentScale::all ();
58 for (size_t i = 0; i < scales.size(); ++i) {
59 if (scales[i] == scale) {
67 VideoPanel::VideoPanel (FilmEditor* e)
68 : FilmEditorPanel (e, _("Video"))
70 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
71 _sizer->Add (grid, 0, wxALL, 8);
75 add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
76 _frame_type = new ContentChoice<VideoContent, VideoFrameType> (
78 new wxChoice (this, wxID_ANY),
79 VideoContentProperty::VIDEO_FRAME_TYPE,
80 boost::mem_fn (&VideoContent::video_frame_type),
81 boost::mem_fn (&VideoContent::set_video_frame_type),
82 &caster<int, VideoFrameType>,
83 &caster<VideoFrameType, int>
85 _frame_type->add (grid, wxGBPosition (r, 1));
88 add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0));
89 _left_crop = new ContentSpinCtrl<VideoContent> (
91 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
92 VideoContentProperty::VIDEO_CROP,
93 boost::mem_fn (&VideoContent::left_crop),
94 boost::mem_fn (&VideoContent::set_left_crop)
96 _left_crop->add (grid, wxGBPosition (r, 1));
99 add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0));
100 _right_crop = new ContentSpinCtrl<VideoContent> (
102 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
103 VideoContentProperty::VIDEO_CROP,
104 boost::mem_fn (&VideoContent::right_crop),
105 boost::mem_fn (&VideoContent::set_right_crop)
107 _right_crop->add (grid, wxGBPosition (r, 1));
110 add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0));
111 _top_crop = new ContentSpinCtrl<VideoContent> (
113 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
114 VideoContentProperty::VIDEO_CROP,
115 boost::mem_fn (&VideoContent::top_crop),
116 boost::mem_fn (&VideoContent::set_top_crop)
118 _top_crop->add (grid, wxGBPosition (r,1 ));
121 add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0));
122 _bottom_crop = new ContentSpinCtrl<VideoContent> (
124 new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1)),
125 VideoContentProperty::VIDEO_CROP,
126 boost::mem_fn (&VideoContent::bottom_crop),
127 boost::mem_fn (&VideoContent::set_bottom_crop)
129 _bottom_crop->add (grid, wxGBPosition (r, 1));
132 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
133 _scale = new ContentChoice<VideoContent, VideoContentScale> (
135 new wxChoice (this, wxID_ANY),
136 VideoContentProperty::VIDEO_SCALE,
137 boost::mem_fn (&VideoContent::scale),
138 boost::mem_fn (&VideoContent::set_scale),
142 _scale->add (grid, wxGBPosition (r, 1));
146 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
147 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
149 wxClientDC dc (this);
150 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
153 _filters = new wxStaticText (this, wxID_ANY, _("None"), wxDefaultPosition, size);
154 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
155 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
156 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
157 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
162 add_label_to_grid_bag_sizer (grid, this, _("Colour conversion"), true, wxGBPosition (r, 0));
163 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
165 wxClientDC dc (this);
166 wxSize size = dc.GetTextExtent (wxT ("A quite long name"));
169 _colour_conversion = new wxStaticText (this, wxID_ANY, wxT (""), wxDefaultPosition, size);
171 s->Add (_colour_conversion, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
172 _colour_conversion_button = new wxButton (this, wxID_ANY, _("Edit..."));
173 s->Add (_colour_conversion_button, 0, wxALIGN_CENTER_VERTICAL);
174 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
178 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
179 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
180 wxFont font = _description->GetFont();
181 font.SetStyle(wxFONTSTYLE_ITALIC);
182 font.SetPointSize(font.GetPointSize() - 1);
183 _description->SetFont(font);
186 _left_crop->wrapped()->SetRange (0, 1024);
187 _top_crop->wrapped()->SetRange (0, 1024);
188 _right_crop->wrapped()->SetRange (0, 1024);
189 _bottom_crop->wrapped()->SetRange (0, 1024);
191 vector<VideoContentScale> scales = VideoContentScale::all ();
192 _scale->wrapped()->Clear ();
193 for (vector<VideoContentScale>::iterator i = scales.begin(); i != scales.end(); ++i) {
194 _scale->wrapped()->Append (std_to_wx (i->name ()));
197 _frame_type->wrapped()->Append (_("2D"));
198 _frame_type->wrapped()->Append (_("3D left/right"));
199 _frame_type->wrapped()->Append (_("3D top/bottom"));
200 _frame_type->wrapped()->Append (_("3D alternate"));
201 _frame_type->wrapped()->Append (_("3D left only"));
202 _frame_type->wrapped()->Append (_("3D right only"));
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_SCALE) {
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 string const p = Filter::ffmpeg_string (fcs->filters ());
249 _filters->SetLabel (_("None"));
251 _filters->SetLabel (std_to_wx (p));
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 libdcp::Size const container_size = _editor->film()->frame_size ();
312 libdcp::Size const scaled = vcs->scale().size (vcs, container_size, container_size);
314 if (scaled != vcs->video_size_after_crop ()) {
315 d << wxString::Format (
316 _("Scaled to %dx%d (%.2f:1)\n"),
317 scaled.width, scaled.height,
323 if (scaled != container_size) {
324 d << wxString::Format (
325 _("Padded with black to %dx%d (%.2f:1)\n"),
326 container_size.width, container_size.height,
327 container_size.ratio ()
332 d << wxString::Format (_("Content frame rate %.4f\n"), vcs->video_frame_rate ());
334 FrameRateChange frc (vcs->video_frame_rate(), _editor->film()->video_frame_rate ());
335 d << std_to_wx (frc.description ()) << "\n";
338 for (int i = lines; i < 6; ++i) {
342 _description->SetLabel (d);
347 VideoPanel::edit_colour_conversion_clicked ()
349 VideoContentList vc = _editor->selected_video_content ();
350 if (vc.size() != 1) {
354 ColourConversion conversion = vc.front()->colour_conversion ();
355 ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
359 vc.front()->set_colour_conversion (d->get ());
364 VideoPanel::content_selection_changed ()
366 VideoContentList sel = _editor->selected_video_content ();
367 bool const single = sel.size() == 1;
369 _left_crop->set_content (sel);
370 _right_crop->set_content (sel);
371 _top_crop->set_content (sel);
372 _bottom_crop->set_content (sel);
373 _frame_type->set_content (sel);
374 _scale->set_content (sel);
376 /* Things that are only allowed with single selections */
377 _filters_button->Enable (single);
378 _colour_conversion_button->Enable (single);
380 film_content_changed (VideoContentProperty::VIDEO_CROP);
381 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
382 film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
383 film_content_changed (FFmpegContentProperty::FILTERS);