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<ContentTime> (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<ContentTime> (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 ()
151 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
152 check.insert (i->full_length ());
155 if (check.size() == 1) {
156 _full_length->set (_parent->selected().front()->full_length (), _parent->film()->video_frame_rate ());
158 _full_length->clear ();
163 TimingPanel::update_play_length ()
166 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
167 check.insert (i->length_after_trim ());
170 if (check.size() == 1) {
171 _play_length->set (_parent->selected().front()->length_after_trim (), _parent->film()->video_frame_rate ());
173 _play_length->clear ();
178 TimingPanel::film_content_changed (int property)
180 int const film_video_frame_rate = _parent->film()->video_frame_rate ();
182 /* Here we check to see if we have exactly one different value of various
183 properties, and fill the controls with that value if so.
186 if (property == ContentProperty::POSITION) {
189 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
190 check.insert (i->position ());
193 if (check.size() == 1) {
194 _position->set (_parent->selected().front()->position(), film_video_frame_rate);
200 property == ContentProperty::LENGTH ||
201 property == VideoContentProperty::VIDEO_FRAME_RATE ||
202 property == VideoContentProperty::VIDEO_FRAME_TYPE
205 update_full_length ();
207 } else if (property == ContentProperty::TRIM_START) {
209 set<ContentTime> check;
210 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
211 check.insert (i->trim_start ());
214 if (check.size() == 1) {
215 _trim_start->set (_parent->selected().front()->trim_start (), film_video_frame_rate);
217 _trim_start->clear ();
220 } else if (property == ContentProperty::TRIM_END) {
222 set<ContentTime> check;
223 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
224 check.insert (i->trim_end ());
227 if (check.size() == 1) {
228 _trim_end->set (_parent->selected().front()->trim_end (), film_video_frame_rate);
235 property == ContentProperty::LENGTH ||
236 property == ContentProperty::TRIM_START ||
237 property == ContentProperty::TRIM_END ||
238 property == VideoContentProperty::VIDEO_FRAME_RATE ||
239 property == VideoContentProperty::VIDEO_FRAME_TYPE
242 update_play_length ();
245 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
247 shared_ptr<const VideoContent> vc;
248 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
249 shared_ptr<const VideoContent> t = dynamic_pointer_cast<const VideoContent> (i);
251 check.insert (t->video_frame_rate ());
255 if (check.size() == 1) {
256 checked_set (_video_frame_rate, raw_convert<string> (vc->video_frame_rate (), 5));
257 _video_frame_rate->Enable (true);
259 checked_set (_video_frame_rate, wxT (""));
260 _video_frame_rate->Enable (false);
264 bool have_still = false;
265 BOOST_FOREACH (shared_ptr<const Content> i, _parent->selected ()) {
266 shared_ptr<const ImageContent> ic = dynamic_pointer_cast<const ImageContent> (i);
267 if (ic && ic->still ()) {
272 _full_length->set_editable (have_still);
273 _play_length->set_editable (!have_still);
274 _set_video_frame_rate->Enable (false);
278 TimingPanel::position_changed ()
280 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
281 i->set_position (_position->get (_parent->film()->video_frame_rate ()));
286 TimingPanel::full_length_changed ()
288 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
289 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (i);
290 if (ic && ic->still ()) {
291 int const vfr = _parent->film()->video_frame_rate ();
292 ic->set_video_length (_full_length->get (vfr).frames_round (vfr));
298 TimingPanel::trim_start_changed ()
300 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
301 i->set_trim_start (_trim_start->get (_parent->film()->video_frame_rate ()));
307 TimingPanel::trim_end_changed ()
309 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
310 i->set_trim_end (_trim_end->get (_parent->film()->video_frame_rate ()));
315 TimingPanel::play_length_changed ()
317 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
318 FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
320 ContentTime (i->full_length() - _play_length->get (_parent->film()->video_frame_rate()), frc)
327 TimingPanel::video_frame_rate_changed ()
329 _set_video_frame_rate->Enable (true);
333 TimingPanel::set_video_frame_rate ()
335 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
336 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (i);
338 vc->set_video_frame_rate (raw_convert<double> (wx_to_std (_video_frame_rate->GetValue ())));
340 _set_video_frame_rate->Enable (false);
345 TimingPanel::content_selection_changed ()
347 bool const e = !_parent->selected().empty ();
349 _position->Enable (e);
350 _full_length->Enable (e);
351 _trim_start->Enable (e);
352 _trim_end->Enable (e);
353 _play_length->Enable (e);
354 _video_frame_rate->Enable (e);
356 film_content_changed (ContentProperty::POSITION);
357 film_content_changed (ContentProperty::LENGTH);
358 film_content_changed (ContentProperty::TRIM_START);
359 film_content_changed (ContentProperty::TRIM_END);
360 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);
364 TimingPanel::film_changed (Film::Property p)
366 if (p == Film::VIDEO_FRAME_RATE) {
367 update_full_length ();
368 update_play_length ();
373 TimingPanel::trim_start_to_playhead_clicked ()
375 DCPTime const ph = _viewer->position ();
376 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
377 if (i->position() < ph && ph < i->end ()) {
378 FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
379 i->set_trim_start (i->trim_start() + ContentTime (ph - i->position (), frc));
385 TimingPanel::trim_end_to_playhead_clicked ()
387 DCPTime const ph = _viewer->position ();
388 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
389 if (i->position() < ph && ph < i->end ()) {
390 FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
391 i->set_trim_end (ContentTime (i->position() + i->full_length() - ph, frc) - i->trim_start());