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>
35 using boost::shared_ptr;
36 using boost::dynamic_pointer_cast;
38 TimingPanel::TimingPanel (ContentPanel* p, FilmViewer* viewer)
39 /* horrid hack for apparent lack of context support with wxWidgets i18n code */
40 : ContentSubPanel (p, S_("Timing|Timing"))
43 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
44 _sizer->Add (grid, 0, wxALL, 8);
46 wxSize size = TimecodeBase::size (this);
48 wxSizer* labels = new wxBoxSizer (wxHORIZONTAL);
49 //// TRANSLATORS: this is an abbreviation for "hours"
50 wxStaticText* t = new wxStaticText (this, wxID_ANY, _("h"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
51 #ifdef DCPOMATIC_LINUX
52 /* Hack to work around failure to centre text on GTK */
53 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
55 labels->Add (t, 1, wxEXPAND);
56 add_label_to_sizer (labels, this, wxT (":"), false);
57 //// TRANSLATORS: this is an abbreviation for "minutes"
58 t = new wxStaticText (this, wxID_ANY, _("m"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
59 #ifdef DCPOMATIC_LINUX
60 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
62 labels->Add (t, 1, wxEXPAND);
63 add_label_to_sizer (labels, this, wxT (":"), false);
64 //// TRANSLATORS: this is an abbreviation for "seconds"
65 t = new wxStaticText (this, wxID_ANY, _("s"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
66 #ifdef DCPOMATIC_LINUX
67 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
69 labels->Add (t, 1, wxEXPAND);
70 add_label_to_sizer (labels, this, wxT (":"), false);
71 //// TRANSLATORS: this is an abbreviation for "frames"
72 t = new wxStaticText (this, wxID_ANY, _("f"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
73 #ifdef DCPOMATIC_LINUX
74 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
76 labels->Add (t, 1, wxEXPAND);
77 grid->Add (new wxStaticText (this, wxID_ANY, wxT ("")));
80 add_label_to_sizer (grid, this, _("Position"), true);
81 _position = new Timecode<DCPTime> (this);
82 grid->Add (_position);
83 add_label_to_sizer (grid, this, _("Full length"), true);
84 _full_length = new Timecode<DCPTime> (this);
85 grid->Add (_full_length);
86 add_label_to_sizer (grid, this, _("Trim from start"), true);
87 _trim_start = new Timecode<ContentTime> (this);
88 grid->Add (_trim_start);
89 _trim_start_to_playhead = new wxButton (this, wxID_ANY, _("Trim up to current position"));
91 grid->Add (_trim_start_to_playhead);
92 add_label_to_sizer (grid, this, _("Trim from end"), true);
93 _trim_end = new Timecode<ContentTime> (this);
94 grid->Add (_trim_end);
95 _trim_end_to_playhead = new wxButton (this, wxID_ANY, _("Trim after current position"));
97 grid->Add (_trim_end_to_playhead);
98 add_label_to_sizer (grid, this, _("Play length"), true);
99 _play_length = new Timecode<DCPTime> (this);
100 grid->Add (_play_length);
103 add_label_to_sizer (grid, this, _("Video frame rate"), true);
104 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
105 _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
106 s->Add (_video_frame_rate, 1, wxEXPAND);
107 _set_video_frame_rate = new wxButton (this, wxID_ANY, _("Set"));
108 _set_video_frame_rate->Enable (false);
109 s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
110 grid->Add (s, 1, wxEXPAND);
115 /* We can't use Wrap() here as it doesn't work with markup:
116 * http://trac.wxwidgets.org/ticket/13389
119 wxString in = _("<i>Only change this if it the content's frame rate has been read incorrectly.</i>");
121 int const width = 20;
123 for (size_t i = 0; i < in.Length(); ++i) {
124 if (in[i] == ' ' && current >= width) {
133 t = new wxStaticText (this, wxID_ANY, wxT (""));
134 t->SetLabelMarkup (out);
135 grid->Add (t, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 6);
137 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
138 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
139 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
140 _trim_start_to_playhead->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::trim_start_to_playhead_clicked, this));
141 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
142 _trim_end_to_playhead->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::trim_end_to_playhead_clicked, this));
143 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
144 _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this));
145 _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this));
149 TimingPanel::update_full_length ()
152 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
153 check.insert (i->full_length ());
156 if (check.size() == 1) {
157 _full_length->set (_parent->selected().front()->full_length (), _parent->film()->video_frame_rate ());
159 _full_length->clear ();
164 TimingPanel::update_play_length ()
167 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
168 check.insert (i->length_after_trim ());
171 if (check.size() == 1) {
172 _play_length->set (_parent->selected().front()->length_after_trim (), _parent->film()->video_frame_rate ());
174 _play_length->clear ();
179 TimingPanel::film_content_changed (int property)
181 int const film_video_frame_rate = _parent->film()->video_frame_rate ();
183 /* Here we check to see if we have exactly one different value of various
184 properties, and fill the controls with that value if so.
187 if (property == ContentProperty::POSITION) {
190 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
191 check.insert (i->position ());
194 if (check.size() == 1) {
195 _position->set (_parent->selected().front()->position(), film_video_frame_rate);
201 property == ContentProperty::LENGTH ||
202 property == VideoContentProperty::VIDEO_FRAME_RATE ||
203 property == VideoContentProperty::VIDEO_FRAME_TYPE
206 update_full_length ();
208 } else if (property == ContentProperty::TRIM_START) {
210 set<ContentTime> check;
211 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
212 check.insert (i->trim_start ());
215 if (check.size() == 1) {
216 _trim_start->set (_parent->selected().front()->trim_start (), film_video_frame_rate);
218 _trim_start->clear ();
221 } else if (property == ContentProperty::TRIM_END) {
223 set<ContentTime> check;
224 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
225 check.insert (i->trim_end ());
228 if (check.size() == 1) {
229 _trim_end->set (_parent->selected().front()->trim_end (), film_video_frame_rate);
236 property == ContentProperty::LENGTH ||
237 property == ContentProperty::TRIM_START ||
238 property == ContentProperty::TRIM_END ||
239 property == VideoContentProperty::VIDEO_FRAME_RATE ||
240 property == VideoContentProperty::VIDEO_FRAME_TYPE
243 update_play_length ();
246 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
248 shared_ptr<const VideoContent> vc;
249 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
250 shared_ptr<const VideoContent> t = dynamic_pointer_cast<const VideoContent> (i);
252 check.insert (t->video_frame_rate ());
256 if (check.size() == 1) {
257 checked_set (_video_frame_rate, raw_convert<string> (vc->video_frame_rate (), 5));
258 _video_frame_rate->Enable (true);
260 checked_set (_video_frame_rate, wxT (""));
261 _video_frame_rate->Enable (false);
265 bool have_still = false;
266 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
267 shared_ptr<const ImageContent> ic = dynamic_pointer_cast<const ImageContent> (i);
268 if (ic && ic->still ()) {
273 _full_length->set_editable (have_still);
274 _play_length->set_editable (!have_still);
275 _set_video_frame_rate->Enable (false);
279 TimingPanel::position_changed ()
281 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
282 i->set_position (_position->get (_parent->film()->video_frame_rate ()));
287 TimingPanel::full_length_changed ()
289 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
290 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (i);
291 if (ic && ic->still ()) {
292 int const vfr = _parent->film()->video_frame_rate ();
293 ic->set_video_length (_full_length->get (vfr).frames_round (vfr));
299 TimingPanel::trim_start_changed ()
301 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
302 i->set_trim_start (_trim_start->get (_parent->film()->video_frame_rate ()));
308 TimingPanel::trim_end_changed ()
310 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
311 i->set_trim_end (_trim_end->get (_parent->film()->video_frame_rate ()));
316 TimingPanel::play_length_changed ()
318 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
319 FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
321 ContentTime (i->full_length() - _play_length->get (_parent->film()->video_frame_rate()), frc)
328 TimingPanel::video_frame_rate_changed ()
330 _set_video_frame_rate->Enable (true);
334 TimingPanel::set_video_frame_rate ()
336 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
337 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (i);
339 vc->set_video_frame_rate (raw_convert<double> (wx_to_std (_video_frame_rate->GetValue ())));
341 _set_video_frame_rate->Enable (false);
346 TimingPanel::content_selection_changed ()
348 bool const e = !_parent->selected().empty ();
350 _position->Enable (e);
351 _full_length->Enable (e);
352 _trim_start->Enable (e);
353 _trim_end->Enable (e);
354 _play_length->Enable (e);
355 _video_frame_rate->Enable (e);
357 film_content_changed (ContentProperty::POSITION);
358 film_content_changed (ContentProperty::LENGTH);
359 film_content_changed (ContentProperty::TRIM_START);
360 film_content_changed (ContentProperty::TRIM_END);
361 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
365 TimingPanel::film_changed (Film::Property p)
367 if (p == Film::VIDEO_FRAME_RATE) {
368 update_full_length ();
369 update_play_length ();
374 TimingPanel::trim_start_to_playhead_clicked ()
376 DCPTime const ph = _viewer->position ();
377 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
378 if (i->position() < ph && ph < i->end ()) {
379 FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
380 i->set_trim_start (i->trim_start() + ContentTime (ph - i->position (), frc));
386 TimingPanel::trim_end_to_playhead_clicked ()
388 DCPTime const ph = _viewer->position ();
389 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
390 if (i->position() < ph && ph < i->end ()) {
391 FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
392 i->set_trim_end (ContentTime (i->position() + i->full_length() - ph, frc) - i->trim_start());