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 <libdcp/raw_convert.h>
21 #include "lib/content.h"
22 #include "lib/image_content.h"
23 #include "timing_panel.h"
26 #include "film_editor.h"
31 using boost::shared_ptr;
32 using boost::dynamic_pointer_cast;
33 using libdcp::raw_convert;
35 TimingPanel::TimingPanel (FilmEditor* e)
36 /* horrid hack for apparent lack of context support with wxWidgets i18n code */
37 : FilmEditorPanel (e, S_("Timing|Timing"))
39 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
40 _sizer->Add (grid, 0, wxALL, 8);
42 add_label_to_sizer (grid, this, _("Position"), true);
43 _position = new Timecode (this);
44 grid->Add (_position);
45 add_label_to_sizer (grid, this, _("Full length"), true);
46 _full_length = new Timecode (this);
47 grid->Add (_full_length);
48 add_label_to_sizer (grid, this, _("Trim from start"), true);
49 _trim_start = new Timecode (this);
50 grid->Add (_trim_start);
51 add_label_to_sizer (grid, this, _("Trim from end"), true);
52 _trim_end = new Timecode (this);
53 grid->Add (_trim_end);
54 add_label_to_sizer (grid, this, _("Play length"), true);
55 _play_length = new Timecode (this);
56 grid->Add (_play_length);
59 add_label_to_sizer (grid, this, _("Video frame rate"), true);
60 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
61 _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
62 s->Add (_video_frame_rate, 1, wxEXPAND);
63 _set_video_frame_rate = new wxButton (this, wxID_ANY, _("Set"));
64 _set_video_frame_rate->Enable (false);
65 s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
66 grid->Add (s, 1, wxEXPAND);
69 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
70 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
71 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
72 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
73 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
74 _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this));
75 _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this));
79 TimingPanel::film_content_changed (int property)
81 ContentList cl = _editor->selected_content ();
82 int const film_video_frame_rate = _editor->film()->video_frame_rate ();
84 /* Here we check to see if we have exactly one different value of various
85 properties, and fill the controls with that value if so.
88 if (property == ContentProperty::POSITION) {
91 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
92 check.insert ((*i)->position ());
95 if (check.size() == 1) {
96 _position->set (cl.front()->position(), film_video_frame_rate);
102 property == ContentProperty::LENGTH ||
103 property == VideoContentProperty::VIDEO_FRAME_RATE ||
104 property == VideoContentProperty::VIDEO_FRAME_TYPE
108 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
109 check.insert ((*i)->full_length ());
112 if (check.size() == 1) {
113 _full_length->set (cl.front()->full_length (), film_video_frame_rate);
115 _full_length->clear ();
118 } else if (property == ContentProperty::TRIM_START) {
121 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
122 check.insert ((*i)->trim_start ());
125 if (check.size() == 1) {
126 _trim_start->set (cl.front()->trim_start (), film_video_frame_rate);
128 _trim_start->clear ();
131 } else if (property == ContentProperty::TRIM_END) {
134 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
135 check.insert ((*i)->trim_end ());
138 if (check.size() == 1) {
139 _trim_end->set (cl.front()->trim_end (), film_video_frame_rate);
141 _trim_end->set (0, 24);
146 property == ContentProperty::LENGTH ||
147 property == ContentProperty::TRIM_START ||
148 property == ContentProperty::TRIM_END ||
149 property == VideoContentProperty::VIDEO_FRAME_RATE ||
150 property == VideoContentProperty::VIDEO_FRAME_TYPE
154 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
155 check.insert ((*i)->length_after_trim ());
158 if (check.size() == 1) {
159 _play_length->set (cl.front()->length_after_trim (), film_video_frame_rate);
161 _play_length->clear ();
165 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
167 shared_ptr<VideoContent> vc;
168 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
169 shared_ptr<VideoContent> t = dynamic_pointer_cast<VideoContent> (*i);
171 check.insert (t->video_frame_rate ());
175 if (check.size() == 1) {
176 _video_frame_rate->SetValue (std_to_wx (raw_convert<string> (vc->video_frame_rate (), 5)));
177 _video_frame_rate->Enable (true);
179 _video_frame_rate->SetValue ("");
180 _video_frame_rate->Enable (false);
184 bool have_still = false;
185 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
186 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
187 if (ic && ic->still ()) {
192 _full_length->set_editable (have_still);
193 _play_length->set_editable (!have_still);
194 _set_video_frame_rate->Enable (false);
198 TimingPanel::position_changed ()
200 ContentList c = _editor->selected_content ();
201 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
202 (*i)->set_position (_position->get (_editor->film()->video_frame_rate ()));
207 TimingPanel::full_length_changed ()
209 ContentList c = _editor->selected_content ();
210 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
211 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
212 if (ic && ic->still ()) {
213 ic->set_video_length (rint (_full_length->get (_editor->film()->video_frame_rate()) * ic->video_frame_rate() / TIME_HZ));
219 TimingPanel::trim_start_changed ()
221 ContentList c = _editor->selected_content ();
222 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
223 (*i)->set_trim_start (_trim_start->get (_editor->film()->video_frame_rate ()));
229 TimingPanel::trim_end_changed ()
231 ContentList c = _editor->selected_content ();
232 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
233 (*i)->set_trim_end (_trim_end->get (_editor->film()->video_frame_rate ()));
238 TimingPanel::play_length_changed ()
240 ContentList c = _editor->selected_content ();
241 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
242 (*i)->set_trim_end ((*i)->full_length() - _play_length->get (_editor->film()->video_frame_rate()) - (*i)->trim_start());
247 TimingPanel::video_frame_rate_changed ()
249 _set_video_frame_rate->Enable (true);
253 TimingPanel::set_video_frame_rate ()
255 ContentList c = _editor->selected_content ();
256 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
257 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*i);
259 vc->set_video_frame_rate (raw_convert<float> (wx_to_std (_video_frame_rate->GetValue ())));
261 _set_video_frame_rate->Enable (false);
266 TimingPanel::content_selection_changed ()
268 bool const e = !_editor->selected_content().empty ();
270 _position->Enable (e);
271 _full_length->Enable (e);
272 _trim_start->Enable (e);
273 _trim_end->Enable (e);
274 _play_length->Enable (e);
275 _video_frame_rate->Enable (e);
277 film_content_changed (ContentProperty::POSITION);
278 film_content_changed (ContentProperty::LENGTH);
279 film_content_changed (ContentProperty::TRIM_START);
280 film_content_changed (ContentProperty::TRIM_END);
281 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);