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 "filter_dialog.h"
25 #include "video_panel.h"
27 #include "film_editor.h"
33 using boost::shared_ptr;
34 using boost::dynamic_pointer_cast;
37 VideoPanel::VideoPanel (FilmEditor* e)
38 : FilmEditorPanel (e, _("Video"))
40 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
41 _sizer->Add (grid, 0, wxALL, 8);
45 add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
46 _frame_type = new wxChoice (this, wxID_ANY);
47 grid->Add (_frame_type, wxGBPosition (r, 1));
50 add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0));
51 _left_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
52 grid->Add (_left_crop, wxGBPosition (r, 1));
55 add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0));
56 _right_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
57 grid->Add (_right_crop, wxGBPosition (r, 1));
60 add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0));
61 _top_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
62 grid->Add (_top_crop, wxGBPosition (r, 1));
65 add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0));
66 _bottom_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
67 grid->Add (_bottom_crop, wxGBPosition (r, 1));
70 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
71 _ratio = new wxChoice (this, wxID_ANY);
72 grid->Add (_ratio, wxGBPosition (r, 1));
76 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
77 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
78 _filters = new wxStaticText (this, wxID_ANY, _("None"));
79 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
80 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
81 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
82 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
86 _description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n \n"), wxDefaultPosition, wxDefaultSize);
87 grid->Add (_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
88 wxFont font = _description->GetFont();
89 font.SetStyle(wxFONTSTYLE_ITALIC);
90 font.SetPointSize(font.GetPointSize() - 1);
91 _description->SetFont(font);
94 _left_crop->SetRange (0, 1024);
95 _top_crop->SetRange (0, 1024);
96 _right_crop->SetRange (0, 1024);
97 _bottom_crop->SetRange (0, 1024);
99 vector<Ratio const *> ratios = Ratio::all ();
101 for (vector<Ratio const *>::iterator i = ratios.begin(); i != ratios.end(); ++i) {
102 _ratio->Append (std_to_wx ((*i)->nickname ()));
105 _frame_type->Append (_("2D"));
106 _frame_type->Append (_("3D left/right"));
108 _frame_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::frame_type_changed, this));
109 _left_crop->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::left_crop_changed, this));
110 _right_crop->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::right_crop_changed, this));
111 _top_crop->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::top_crop_changed, this));
112 _bottom_crop->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&VideoPanel::bottom_crop_changed, this));
113 _ratio->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&VideoPanel::ratio_changed, this));
114 _filters_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&VideoPanel::edit_filters_clicked, this));
118 /** Called when the left crop widget has been changed */
120 VideoPanel::left_crop_changed ()
122 shared_ptr<VideoContent> c = _editor->selected_video_content ();
127 c->set_left_crop (_left_crop->GetValue ());
130 /** Called when the right crop widget has been changed */
132 VideoPanel::right_crop_changed ()
134 shared_ptr<VideoContent> c = _editor->selected_video_content ();
139 c->set_right_crop (_right_crop->GetValue ());
142 /** Called when the top crop widget has been changed */
144 VideoPanel::top_crop_changed ()
146 shared_ptr<VideoContent> c = _editor->selected_video_content ();
151 c->set_top_crop (_top_crop->GetValue ());
154 /** Called when the bottom crop value has been changed */
156 VideoPanel::bottom_crop_changed ()
158 shared_ptr<VideoContent> c = _editor->selected_video_content ();
163 c->set_bottom_crop (_bottom_crop->GetValue ());
167 VideoPanel::film_changed (Film::Property property)
170 case Film::CONTAINER:
171 case Film::VIDEO_FRAME_RATE:
172 setup_description ();
180 VideoPanel::film_content_changed (shared_ptr<Content> c, int property)
182 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
183 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
185 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
186 checked_set (_frame_type, vc ? vc->video_frame_type () : VIDEO_FRAME_TYPE_2D);
187 setup_description ();
188 } else if (property == VideoContentProperty::VIDEO_CROP) {
189 checked_set (_left_crop, vc ? vc->crop().left : 0);
190 checked_set (_right_crop, vc ? vc->crop().right : 0);
191 checked_set (_top_crop, vc ? vc->crop().top : 0);
192 checked_set (_bottom_crop, vc ? vc->crop().bottom : 0);
193 setup_description ();
194 } else if (property == VideoContentProperty::VIDEO_RATIO) {
197 vector<Ratio const *> ratios = Ratio::all ();
198 vector<Ratio const *>::iterator i = ratios.begin ();
199 while (i != ratios.end() && *i != vc->ratio()) {
204 if (i == ratios.end()) {
205 checked_set (_ratio, -1);
207 checked_set (_ratio, n);
210 checked_set (_ratio, -1);
212 setup_description ();
213 } else if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
214 setup_description ();
215 } else if (property == FFmpegContentProperty::FILTERS) {
217 pair<string, string> p = Filter::ffmpeg_strings (fc->filters ());
218 if (p.first.empty () && p.second.empty ()) {
219 _filters->SetLabel (_("None"));
221 string const b = p.first + " " + p.second;
222 _filters->SetLabel (std_to_wx (b));
228 /** Called when the `Edit filters' button has been clicked */
230 VideoPanel::edit_filters_clicked ()
232 shared_ptr<Content> c = _editor->selected_content ();
237 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
242 FilterDialog* d = new FilterDialog (this, fc->filters());
243 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, fc, _1));
249 VideoPanel::setup_description ()
251 shared_ptr<VideoContent> vc = _editor->selected_video_content ();
253 _description->SetLabel ("");
261 if (vc->video_size().width && vc->video_size().height) {
262 d << wxString::Format (
263 _("Content video is %dx%d (%.2f:1)\n"),
264 vc->video_size_after_3d_split().width, vc->video_size_after_3d_split().height,
265 float (vc->video_size_after_3d_split().width) / vc->video_size_after_3d_split().height
270 Crop const crop = vc->crop ();
271 if ((crop.left || crop.right || crop.top || crop.bottom) && vc->video_size() != libdcp::Size (0, 0)) {
272 libdcp::Size cropped = vc->video_size_after_3d_split ();
273 cropped.width -= crop.left + crop.right;
274 cropped.height -= crop.top + crop.bottom;
275 d << wxString::Format (
276 _("Cropped to %dx%d (%.2f:1)\n"),
277 cropped.width, cropped.height,
278 float (cropped.width) / cropped.height
283 Ratio const * ratio = vc->ratio ();
285 libdcp::Size container_size = _editor->film()->container()->size (_editor->film()->full_frame ());
287 libdcp::Size const scaled = ratio->size (container_size);
288 d << wxString::Format (
289 _("Scaled to %dx%d (%.2f:1)\n"),
290 scaled.width, scaled.height,
291 float (scaled.width) / scaled.height
295 if (scaled != container_size) {
296 d << wxString::Format (
297 _("Padded with black to %dx%d (%.2f:1)\n"),
298 container_size.width, container_size.height,
299 float (container_size.width) / container_size.height
305 d << wxString::Format (_("Content frame rate %.4f\n"), vc->video_frame_rate ());
307 FrameRateConversion frc (vc->video_frame_rate(), _editor->film()->video_frame_rate ());
308 d << frc.description << "\n";
311 for (int i = lines; i < 6; ++i) {
315 _description->SetLabel (d);
321 VideoPanel::ratio_changed ()
323 if (!_editor->film ()) {
327 shared_ptr<VideoContent> vc = _editor->selected_video_content ();
329 int const n = _ratio->GetSelection ();
331 vector<Ratio const *> ratios = Ratio::all ();
332 assert (n < int (ratios.size()));
333 vc->set_ratio (ratios[n]);
338 VideoPanel::frame_type_changed ()
340 shared_ptr<VideoContent> vc = _editor->selected_video_content ();
342 vc->set_video_frame_type (static_cast<VideoFrameType> (_frame_type->GetSelection ()));