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"
25 #include "film_viewer.h"
27 #include "content_panel.h"
28 #include <boost/foreach.hpp>
34 using boost::shared_ptr;
35 using boost::dynamic_pointer_cast;
37 TimingPanel::TimingPanel (ContentPanel* p, FilmViewer* viewer)
38 /* horrid hack for apparent lack of context support with wxWidgets i18n code */
39 : ContentSubPanel (p, S_("Timing|Timing"))
42 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
43 _sizer->Add (grid, 0, wxALL, 8);
45 wxSize size = TimecodeBase::size (this);
47 wxSizer* labels = new wxBoxSizer (wxHORIZONTAL);
48 //// TRANSLATORS: this is an abbreviation for "hours"
49 wxStaticText* t = new wxStaticText (this, wxID_ANY, _("h"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
50 #ifdef DCPOMATIC_LINUX
51 /* Hack to work around failure to centre text on GTK */
52 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
54 labels->Add (t, 1, wxEXPAND);
55 add_label_to_sizer (labels, this, wxT (":"), false);
56 //// TRANSLATORS: this is an abbreviation for "minutes"
57 t = new wxStaticText (this, wxID_ANY, _("m"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
58 #ifdef DCPOMATIC_LINUX
59 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
61 labels->Add (t, 1, wxEXPAND);
62 add_label_to_sizer (labels, this, wxT (":"), false);
63 //// TRANSLATORS: this is an abbreviation for "seconds"
64 t = new wxStaticText (this, wxID_ANY, _("s"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
65 #ifdef DCPOMATIC_LINUX
66 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
68 labels->Add (t, 1, wxEXPAND);
69 add_label_to_sizer (labels, this, wxT (":"), false);
70 //// TRANSLATORS: this is an abbreviation for "frames"
71 t = new wxStaticText (this, wxID_ANY, _("f"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
72 #ifdef DCPOMATIC_LINUX
73 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
75 labels->Add (t, 1, wxEXPAND);
76 grid->Add (new wxStaticText (this, wxID_ANY, wxT ("")));
79 add_label_to_sizer (grid, this, _("Position"), true);
80 _position = new Timecode<DCPTime> (this);
81 grid->Add (_position);
82 add_label_to_sizer (grid, this, _("Full length"), true);
83 _full_length = new Timecode<DCPTime> (this);
84 grid->Add (_full_length);
85 add_label_to_sizer (grid, this, _("Trim from start"), true);
86 _trim_start = new Timecode<DCPTime> (this);
87 grid->Add (_trim_start);
88 _trim_start_to_playhead = new wxButton (this, wxID_ANY, _("Trim up to current position"));
90 grid->Add (_trim_start_to_playhead);
91 add_label_to_sizer (grid, this, _("Trim from end"), true);
92 _trim_end = new Timecode<DCPTime> (this);
93 grid->Add (_trim_end);
94 _trim_end_to_playhead = new wxButton (this, wxID_ANY, _("Trim after current position"));
96 grid->Add (_trim_end_to_playhead);
97 add_label_to_sizer (grid, this, _("Play length"), true);
98 _play_length = new Timecode<DCPTime> (this);
99 grid->Add (_play_length);
102 add_label_to_sizer (grid, this, _("Video frame rate"), true);
103 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
104 _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
105 s->Add (_video_frame_rate, 1, wxEXPAND);
106 _set_video_frame_rate = new wxButton (this, wxID_ANY, _("Set"));
107 _set_video_frame_rate->Enable (false);
108 s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
109 grid->Add (s, 1, wxEXPAND);
114 /* We can't use Wrap() here as it doesn't work with markup:
115 * http://trac.wxwidgets.org/ticket/13389
118 wxString in = _("<i>Only change this if it the content's frame rate has been read incorrectly.</i>");
120 int const width = 20;
122 for (size_t i = 0; i < in.Length(); ++i) {
123 if (in[i] == ' ' && current >= width) {
132 t = new wxStaticText (this, wxID_ANY, wxT (""));
133 t->SetLabelMarkup (out);
134 grid->Add (t, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 6);
136 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
137 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
138 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
139 _trim_start_to_playhead->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::trim_start_to_playhead_clicked, this));
140 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
141 _trim_end_to_playhead->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::trim_end_to_playhead_clicked, this));
142 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
143 _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this));
144 _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this));
148 TimingPanel::update_full_length ()
150 ContentList cl = _parent->selected ();
153 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
154 check.insert ((*i)->full_length ());
157 if (check.size() == 1) {
158 _full_length->set (cl.front()->full_length (), _parent->film()->video_frame_rate ());
160 _full_length->clear ();
165 TimingPanel::update_play_length ()
167 ContentList cl = _parent->selected ();
170 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
171 check.insert ((*i)->length_after_trim ());
174 if (check.size() == 1) {
175 _play_length->set (cl.front()->length_after_trim (), _parent->film()->video_frame_rate ());
177 _play_length->clear ();
182 TimingPanel::film_content_changed (int property)
184 ContentList cl = _parent->selected ();
185 int const film_video_frame_rate = _parent->film()->video_frame_rate ();
187 /* Here we check to see if we have exactly one different value of various
188 properties, and fill the controls with that value if so.
191 if (property == ContentProperty::POSITION) {
194 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
195 check.insert ((*i)->position ());
198 if (check.size() == 1) {
199 _position->set (cl.front()->position(), film_video_frame_rate);
205 property == ContentProperty::LENGTH ||
206 property == VideoContentProperty::VIDEO_FRAME_RATE ||
207 property == VideoContentProperty::VIDEO_FRAME_TYPE
210 update_full_length ();
212 } else if (property == ContentProperty::TRIM_START) {
215 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
216 check.insert ((*i)->trim_start ());
219 if (check.size() == 1) {
220 _trim_start->set (cl.front()->trim_start (), film_video_frame_rate);
222 _trim_start->clear ();
225 } else if (property == ContentProperty::TRIM_END) {
228 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
229 check.insert ((*i)->trim_end ());
232 if (check.size() == 1) {
233 _trim_end->set (cl.front()->trim_end (), film_video_frame_rate);
240 property == ContentProperty::LENGTH ||
241 property == ContentProperty::TRIM_START ||
242 property == ContentProperty::TRIM_END ||
243 property == VideoContentProperty::VIDEO_FRAME_RATE ||
244 property == VideoContentProperty::VIDEO_FRAME_TYPE
247 update_play_length ();
250 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
252 shared_ptr<VideoContent> vc;
253 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
254 shared_ptr<VideoContent> t = dynamic_pointer_cast<VideoContent> (*i);
256 check.insert (t->video_frame_rate ());
260 if (check.size() == 1) {
261 checked_set (_video_frame_rate, raw_convert<string> (vc->video_frame_rate (), 5));
262 _video_frame_rate->Enable (true);
264 checked_set (_video_frame_rate, wxT (""));
265 _video_frame_rate->Enable (false);
269 bool have_still = false;
270 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
271 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
272 if (ic && ic->still ()) {
277 _full_length->set_editable (have_still);
278 _play_length->set_editable (!have_still);
279 _set_video_frame_rate->Enable (false);
283 TimingPanel::position_changed ()
285 ContentList c = _parent->selected ();
286 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
287 (*i)->set_position (_position->get (_parent->film()->video_frame_rate ()));
292 TimingPanel::full_length_changed ()
294 ContentList c = _parent->selected ();
295 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
296 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
297 if (ic && ic->still ()) {
298 int const vfr = _parent->film()->video_frame_rate ();
299 ic->set_video_length (_full_length->get (vfr).frames (vfr));
305 TimingPanel::trim_start_changed ()
307 ContentList c = _parent->selected ();
308 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
309 (*i)->set_trim_start (_trim_start->get (_parent->film()->video_frame_rate ()));
315 TimingPanel::trim_end_changed ()
317 ContentList c = _parent->selected ();
318 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
319 (*i)->set_trim_end (_trim_end->get (_parent->film()->video_frame_rate ()));
324 TimingPanel::play_length_changed ()
326 ContentList c = _parent->selected ();
327 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
328 (*i)->set_trim_end ((*i)->full_length() - _play_length->get (_parent->film()->video_frame_rate()) - (*i)->trim_start());
333 TimingPanel::video_frame_rate_changed ()
335 _set_video_frame_rate->Enable (true);
339 TimingPanel::set_video_frame_rate ()
341 ContentList c = _parent->selected ();
342 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
343 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*i);
345 vc->set_video_frame_rate (raw_convert<float> (wx_to_std (_video_frame_rate->GetValue ())));
347 _set_video_frame_rate->Enable (false);
352 TimingPanel::content_selection_changed ()
354 bool const e = !_parent->selected().empty ();
356 _position->Enable (e);
357 _full_length->Enable (e);
358 _trim_start->Enable (e);
359 _trim_end->Enable (e);
360 _play_length->Enable (e);
361 _video_frame_rate->Enable (e);
363 film_content_changed (ContentProperty::POSITION);
364 film_content_changed (ContentProperty::LENGTH);
365 film_content_changed (ContentProperty::TRIM_START);
366 film_content_changed (ContentProperty::TRIM_END);
367 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
371 TimingPanel::film_changed (Film::Property p)
373 if (p == Film::VIDEO_FRAME_RATE) {
374 update_full_length ();
375 update_play_length ();
380 TimingPanel::trim_start_to_playhead_clicked ()
382 DCPTime const ph = _viewer->position ();
383 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
384 if (i->position() < ph && ph < i->end ()) {
385 i->set_trim_start (i->trim_start() + ph - i->position ());
391 TimingPanel::trim_end_to_playhead_clicked ()
393 DCPTime const ph = _viewer->position ();
394 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
395 if (i->position() < ph && ph < i->end ()) {
396 i->set_trim_end (i->position() + i->full_length() - i->trim_start() - ph);