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 "filter_dialog.h"
24 #include "video_panel.h"
26 #include "film_editor.h"
32 using boost::shared_ptr;
33 using boost::dynamic_pointer_cast;
36 VideoPanel::VideoPanel (FilmEditor* e)
37 : FilmEditorPanel (e, _("Video"))
39 wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
40 _sizer->Add (grid, 0, wxALL, 8);
44 add_label_to_grid_bag_sizer (grid, this, _("Type"), true, wxGBPosition (r, 0));
45 _frame_type = new wxChoice (this, wxID_ANY);
46 grid->Add (_frame_type, wxGBPosition (r, 1));
49 add_label_to_grid_bag_sizer (grid, this, _("Left crop"), true, wxGBPosition (r, 0));
50 _left_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
51 grid->Add (_left_crop, wxGBPosition (r, 1));
54 add_label_to_grid_bag_sizer (grid, this, _("Right crop"), true, wxGBPosition (r, 0));
55 _right_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
56 grid->Add (_right_crop, wxGBPosition (r, 1));
59 add_label_to_grid_bag_sizer (grid, this, _("Top crop"), true, wxGBPosition (r, 0));
60 _top_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
61 grid->Add (_top_crop, wxGBPosition (r, 1));
64 add_label_to_grid_bag_sizer (grid, this, _("Bottom crop"), true, wxGBPosition (r, 0));
65 _bottom_crop = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
66 grid->Add (_bottom_crop, wxGBPosition (r, 1));
69 add_label_to_grid_bag_sizer (grid, this, _("Scale to"), true, wxGBPosition (r, 0));
70 _ratio = new wxChoice (this, wxID_ANY);
71 grid->Add (_ratio, wxGBPosition (r, 1));
74 _scaling_description = new wxStaticText (this, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
75 grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
76 wxFont font = _scaling_description->GetFont();
77 font.SetStyle(wxFONTSTYLE_ITALIC);
78 font.SetPointSize(font.GetPointSize() - 1);
79 _scaling_description->SetFont(font);
83 add_label_to_grid_bag_sizer (grid, this, _("Filters"), true, wxGBPosition (r, 0));
84 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
85 _filters = new wxStaticText (this, wxID_ANY, _("None"));
86 s->Add (_filters, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
87 _filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
88 s->Add (_filters_button, 0, wxALIGN_CENTER_VERTICAL);
89 grid->Add (s, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
93 _left_crop->SetRange (0, 1024);
94 _top_crop->SetRange (0, 1024);
95 _right_crop->SetRange (0, 1024);
96 _bottom_crop->SetRange (0, 1024);
98 vector<Ratio const *> ratios = Ratio::all ();
100 for (vector<Ratio const *>::iterator i = ratios.begin(); i != ratios.end(); ++i) {
101 _ratio->Append (std_to_wx ((*i)->nickname ()));
104 _frame_type->Append (_("2D"));
105 _frame_type->Append (_("3D left/right"));
107 _frame_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, bind (&VideoPanel::frame_type_changed, this));
108 _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (VideoPanel::left_crop_changed), 0, this);
109 _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (VideoPanel::right_crop_changed), 0, this);
110 _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (VideoPanel::top_crop_changed), 0, this);
111 _bottom_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (VideoPanel::bottom_crop_changed), 0, this);
112 _ratio->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (VideoPanel::ratio_changed), 0, this);
113 _filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (VideoPanel::edit_filters_clicked), 0, this);
117 /** Called when the left crop widget has been changed */
119 VideoPanel::left_crop_changed (wxCommandEvent &)
121 shared_ptr<VideoContent> c = _editor->selected_video_content ();
126 c->set_left_crop (_left_crop->GetValue ());
129 /** Called when the right crop widget has been changed */
131 VideoPanel::right_crop_changed (wxCommandEvent &)
133 shared_ptr<VideoContent> c = _editor->selected_video_content ();
138 c->set_right_crop (_right_crop->GetValue ());
141 /** Called when the top crop widget has been changed */
143 VideoPanel::top_crop_changed (wxCommandEvent &)
145 shared_ptr<VideoContent> c = _editor->selected_video_content ();
150 c->set_top_crop (_top_crop->GetValue ());
153 /** Called when the bottom crop value has been changed */
155 VideoPanel::bottom_crop_changed (wxCommandEvent &)
157 shared_ptr<VideoContent> c = _editor->selected_video_content ();
162 c->set_bottom_crop (_bottom_crop->GetValue ());
166 VideoPanel::film_changed (Film::Property property)
169 case Film::CONTAINER:
170 setup_scaling_description ();
178 VideoPanel::film_content_changed (shared_ptr<Content> c, int property)
180 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (c);
181 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
183 if (property == VideoContentProperty::VIDEO_FRAME_TYPE) {
184 checked_set (_frame_type, vc ? vc->video_frame_type () : VIDEO_FRAME_TYPE_2D);
185 } else if (property == VideoContentProperty::VIDEO_CROP) {
186 checked_set (_left_crop, vc ? vc->crop().left : 0);
187 checked_set (_right_crop, vc ? vc->crop().right : 0);
188 checked_set (_top_crop, vc ? vc->crop().top : 0);
189 checked_set (_bottom_crop, vc ? vc->crop().bottom : 0);
190 setup_scaling_description ();
191 } else if (property == VideoContentProperty::VIDEO_RATIO) {
194 vector<Ratio const *> ratios = Ratio::all ();
195 vector<Ratio const *>::iterator i = ratios.begin ();
196 while (i != ratios.end() && *i != vc->ratio()) {
201 if (i == ratios.end()) {
202 checked_set (_ratio, -1);
204 checked_set (_ratio, n);
207 checked_set (_ratio, -1);
209 setup_scaling_description ();
210 } else if (property == FFmpegContentProperty::FILTERS) {
212 pair<string, string> p = Filter::ffmpeg_strings (fc->filters ());
213 if (p.first.empty () && p.second.empty ()) {
214 _filters->SetLabel (_("None"));
216 string const b = p.first + " " + p.second;
217 _filters->SetLabel (std_to_wx (b));
223 /** Called when the `Edit filters' button has been clicked */
225 VideoPanel::edit_filters_clicked (wxCommandEvent &)
227 shared_ptr<Content> c = _editor->selected_content ();
232 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
237 FilterDialog* d = new FilterDialog (this, fc->filters());
238 d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, fc, _1));
244 VideoPanel::setup_scaling_description ()
246 shared_ptr<VideoContent> vc = _editor->selected_video_content ();
248 _scaling_description->SetLabel ("");
256 if (vc->video_size().width && vc->video_size().height) {
257 d << wxString::Format (
258 _("Original video is %dx%d (%.2f:1)\n"),
259 vc->video_size().width, vc->video_size().height,
260 float (vc->video_size().width) / vc->video_size().height
265 Crop const crop = vc->crop ();
266 if ((crop.left || crop.right || crop.top || crop.bottom) && vc->video_size() != libdcp::Size (0, 0)) {
267 libdcp::Size cropped = vc->video_size ();
268 cropped.width -= crop.left + crop.right;
269 cropped.height -= crop.top + crop.bottom;
270 d << wxString::Format (
271 _("Cropped to %dx%d (%.2f:1)\n"),
272 cropped.width, cropped.height,
273 float (cropped.width) / cropped.height
278 Ratio const * ratio = vc->ratio ();
280 libdcp::Size container_size = _editor->film()->container()->size (_editor->film()->full_frame ());
282 libdcp::Size const scaled = ratio->size (container_size);
283 d << wxString::Format (
284 _("Scaled to %dx%d (%.2f:1)\n"),
285 scaled.width, scaled.height,
286 float (scaled.width) / scaled.height
290 if (scaled != container_size) {
291 d << wxString::Format (
292 _("Padded with black to %dx%d (%.2f:1)\n"),
293 container_size.width, container_size.height,
294 float (container_size.width) / container_size.height
300 for (int i = lines; i < 4; ++i) {
304 _scaling_description->SetLabel (d);
310 VideoPanel::ratio_changed (wxCommandEvent &)
312 if (!_editor->film ()) {
316 shared_ptr<VideoContent> vc = _editor->selected_video_content ();
318 int const n = _ratio->GetSelection ();
320 vector<Ratio const *> ratios = Ratio::all ();
321 assert (n < int (ratios.size()));
322 vc->set_ratio (ratios[n]);
327 VideoPanel::frame_type_changed ()
329 shared_ptr<VideoContent> vc = _editor->selected_video_content ();
331 vc->set_video_frame_type (static_cast<VideoFrameType> (_frame_type->GetSelection ()));