2 Copyright (C) 2012-2015 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 "lib/content.h"
21 #include "lib/image_content.h"
22 #include "lib/raw_convert.h"
23 #include "timing_panel.h"
26 #include "content_panel.h"
32 using boost::shared_ptr;
33 using boost::dynamic_pointer_cast;
35 TimingPanel::TimingPanel (ContentPanel* p)
36 /* horrid hack for apparent lack of context support with wxWidgets i18n code */
37 : ContentSubPanel (p, S_("Timing|Timing"))
39 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
40 _sizer->Add (grid, 0, wxALL, 8);
42 wxSize size = TimecodeBase::size (this);
44 wxSizer* labels = new wxBoxSizer (wxHORIZONTAL);
45 //// TRANSLATORS: this is an abbreviation for "hours"
46 wxStaticText* t = new wxStaticText (this, wxID_ANY, _("h"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
47 #ifdef DCPOMATIC_LINUX
48 /* Hack to work around failure to centre text on GTK */
49 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
51 labels->Add (t, 1, wxEXPAND);
52 add_label_to_sizer (labels, this, wxT (":"), false);
53 //// TRANSLATORS: this is an abbreviation for "minutes"
54 t = new wxStaticText (this, wxID_ANY, _("m"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
55 #ifdef DCPOMATIC_LINUX
56 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
58 labels->Add (t, 1, wxEXPAND);
59 add_label_to_sizer (labels, this, wxT (":"), false);
60 //// TRANSLATORS: this is an abbreviation for "seconds"
61 t = new wxStaticText (this, wxID_ANY, _("s"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
62 #ifdef DCPOMATIC_LINUX
63 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
65 labels->Add (t, 1, wxEXPAND);
66 add_label_to_sizer (labels, this, wxT (":"), false);
67 //// TRANSLATORS: this is an abbreviation for "frames"
68 t = new wxStaticText (this, wxID_ANY, _("f"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
69 #ifdef DCPOMATIC_LINUX
70 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
72 labels->Add (t, 1, wxEXPAND);
73 grid->Add (new wxStaticText (this, wxID_ANY, wxT ("")));
76 add_label_to_sizer (grid, this, _("Position"), true);
77 _position = new Timecode<DCPTime> (this);
78 grid->Add (_position);
79 add_label_to_sizer (grid, this, _("Full length"), true);
80 _full_length = new Timecode<DCPTime> (this);
81 grid->Add (_full_length);
82 add_label_to_sizer (grid, this, _("Trim from start"), true);
83 _trim_start = new Timecode<DCPTime> (this);
84 grid->Add (_trim_start);
85 add_label_to_sizer (grid, this, _("Trim from end"), true);
86 _trim_end = new Timecode<DCPTime> (this);
87 grid->Add (_trim_end);
88 add_label_to_sizer (grid, this, _("Play length"), true);
89 _play_length = new Timecode<DCPTime> (this);
90 grid->Add (_play_length);
93 add_label_to_sizer (grid, this, _("Video frame rate"), true);
94 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
95 _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
96 s->Add (_video_frame_rate, 1, wxEXPAND);
97 _set_video_frame_rate = new wxButton (this, wxID_ANY, _("Set"));
98 _set_video_frame_rate->Enable (false);
99 s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
100 grid->Add (s, 1, wxEXPAND);
105 /* We can't use Wrap() here as it doesn't work with markup:
106 * http://trac.wxwidgets.org/ticket/13389
109 wxString in = _("<i>Only change this if it the content's frame rate has been read incorrectly.</i>");
111 int const width = 20;
113 for (size_t i = 0; i < in.Length(); ++i) {
114 if (in[i] == ' ' && current >= width) {
123 t = new wxStaticText (this, wxID_ANY, wxT (""));
124 t->SetLabelMarkup (out);
125 grid->Add (t, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 6);
127 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
128 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
129 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
130 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
131 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
132 _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this));
133 _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this));
137 TimingPanel::update_full_length ()
139 ContentList cl = _parent->selected ();
142 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
143 check.insert ((*i)->full_length ());
146 if (check.size() == 1) {
147 _full_length->set (cl.front()->full_length (), _parent->film()->video_frame_rate ());
149 _full_length->clear ();
154 TimingPanel::update_play_length ()
156 ContentList cl = _parent->selected ();
159 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
160 check.insert ((*i)->length_after_trim ());
163 if (check.size() == 1) {
164 _play_length->set (cl.front()->length_after_trim (), _parent->film()->video_frame_rate ());
166 _play_length->clear ();
171 TimingPanel::film_content_changed (int property)
173 ContentList cl = _parent->selected ();
174 int const film_video_frame_rate = _parent->film()->video_frame_rate ();
176 /* Here we check to see if we have exactly one different value of various
177 properties, and fill the controls with that value if so.
180 if (property == ContentProperty::POSITION) {
183 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
184 check.insert ((*i)->position ());
187 if (check.size() == 1) {
188 _position->set (cl.front()->position(), film_video_frame_rate);
194 property == ContentProperty::LENGTH ||
195 property == VideoContentProperty::VIDEO_FRAME_RATE ||
196 property == VideoContentProperty::VIDEO_FRAME_TYPE
199 update_full_length ();
201 } else if (property == ContentProperty::TRIM_START) {
204 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
205 check.insert ((*i)->trim_start ());
208 if (check.size() == 1) {
209 _trim_start->set (cl.front()->trim_start (), film_video_frame_rate);
211 _trim_start->clear ();
214 } else if (property == ContentProperty::TRIM_END) {
217 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
218 check.insert ((*i)->trim_end ());
221 if (check.size() == 1) {
222 _trim_end->set (cl.front()->trim_end (), film_video_frame_rate);
229 property == ContentProperty::LENGTH ||
230 property == ContentProperty::TRIM_START ||
231 property == ContentProperty::TRIM_END ||
232 property == VideoContentProperty::VIDEO_FRAME_RATE ||
233 property == VideoContentProperty::VIDEO_FRAME_TYPE
236 update_play_length ();
239 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
241 shared_ptr<VideoContent> vc;
242 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
243 shared_ptr<VideoContent> t = dynamic_pointer_cast<VideoContent> (*i);
245 check.insert (t->video_frame_rate ());
249 if (check.size() == 1) {
250 checked_set (_video_frame_rate, raw_convert<string> (vc->video_frame_rate (), 5));
251 _video_frame_rate->Enable (true);
253 checked_set (_video_frame_rate, wxT (""));
254 _video_frame_rate->Enable (false);
258 bool have_still = false;
259 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
260 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
261 if (ic && ic->still ()) {
266 _full_length->set_editable (have_still);
267 _play_length->set_editable (!have_still);
268 _set_video_frame_rate->Enable (false);
272 TimingPanel::position_changed ()
274 ContentList c = _parent->selected ();
275 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
276 (*i)->set_position (_position->get (_parent->film()->video_frame_rate ()));
281 TimingPanel::full_length_changed ()
283 ContentList c = _parent->selected ();
284 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
285 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
286 if (ic && ic->still ()) {
287 /* XXX: No effective FRC here... is this right? */
288 ic->set_video_length (ContentTime (_full_length->get (_parent->film()->video_frame_rate()), FrameRateChange (1, 1)));
294 TimingPanel::trim_start_changed ()
296 ContentList c = _parent->selected ();
297 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
298 (*i)->set_trim_start (_trim_start->get (_parent->film()->video_frame_rate ()));
304 TimingPanel::trim_end_changed ()
306 ContentList c = _parent->selected ();
307 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
308 (*i)->set_trim_end (_trim_end->get (_parent->film()->video_frame_rate ()));
313 TimingPanel::play_length_changed ()
315 ContentList c = _parent->selected ();
316 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
317 (*i)->set_trim_end ((*i)->full_length() - _play_length->get (_parent->film()->video_frame_rate()) - (*i)->trim_start());
322 TimingPanel::video_frame_rate_changed ()
324 _set_video_frame_rate->Enable (true);
328 TimingPanel::set_video_frame_rate ()
330 ContentList c = _parent->selected ();
331 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
332 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*i);
334 vc->set_video_frame_rate (raw_convert<float> (wx_to_std (_video_frame_rate->GetValue ())));
336 _set_video_frame_rate->Enable (false);
341 TimingPanel::content_selection_changed ()
343 bool const e = !_parent->selected().empty ();
345 _position->Enable (e);
346 _full_length->Enable (e);
347 _trim_start->Enable (e);
348 _trim_end->Enable (e);
349 _play_length->Enable (e);
350 _video_frame_rate->Enable (e);
352 film_content_changed (ContentProperty::POSITION);
353 film_content_changed (ContentProperty::LENGTH);
354 film_content_changed (ContentProperty::TRIM_START);
355 film_content_changed (ContentProperty::TRIM_END);
356 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
360 TimingPanel::film_changed (Film::Property p)
362 if (p == Film::VIDEO_FRAME_RATE) {
363 update_full_length ();
364 update_play_length ();