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 "timing_panel.h"
25 #include "content_panel.h"
26 #include <dcp/raw_convert.h>
32 using boost::shared_ptr;
33 using boost::dynamic_pointer_cast;
34 using dcp::raw_convert;
36 TimingPanel::TimingPanel (ContentPanel* p)
37 /* horrid hack for apparent lack of context support with wxWidgets i18n code */
38 : ContentSubPanel (p, S_("Timing|Timing"))
40 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
41 _sizer->Add (grid, 0, wxALL, 8);
43 wxSize size = TimecodeBase::size (this);
45 wxSizer* labels = new wxBoxSizer (wxHORIZONTAL);
46 //// TRANSLATORS: this is an abbreviation for "hours"
47 wxStaticText* t = new wxStaticText (this, wxID_ANY, _("h"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
48 #ifdef DCPOMATIC_LINUX
49 /* Hack to work around failure to centre text on GTK */
50 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
52 labels->Add (t, 1, wxEXPAND);
53 add_label_to_sizer (labels, this, wxT (":"), false);
54 //// TRANSLATORS: this is an abbreviation for "minutes"
55 t = new wxStaticText (this, wxID_ANY, _("m"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
56 #ifdef DCPOMATIC_LINUX
57 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
59 labels->Add (t, 1, wxEXPAND);
60 add_label_to_sizer (labels, this, wxT (":"), false);
61 //// TRANSLATORS: this is an abbreviation for "seconds"
62 t = new wxStaticText (this, wxID_ANY, _("s"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
63 #ifdef DCPOMATIC_LINUX
64 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
66 labels->Add (t, 1, wxEXPAND);
67 add_label_to_sizer (labels, this, wxT (":"), false);
68 //// TRANSLATORS: this is an abbreviation for "frames"
69 t = new wxStaticText (this, wxID_ANY, _("f"), wxDefaultPosition, size, wxALIGN_CENTRE_HORIZONTAL);
70 #ifdef DCPOMATIC_LINUX
71 gtk_label_set_line_wrap (GTK_LABEL (t->GetHandle()), FALSE);
73 labels->Add (t, 1, wxEXPAND);
74 grid->Add (new wxStaticText (this, wxID_ANY, wxT ("")));
77 add_label_to_sizer (grid, this, _("Position"), true);
78 _position = new Timecode<DCPTime> (this);
79 grid->Add (_position);
80 add_label_to_sizer (grid, this, _("Full length"), true);
81 _full_length = new Timecode<DCPTime> (this);
82 grid->Add (_full_length);
83 add_label_to_sizer (grid, this, _("Trim from start"), true);
84 _trim_start = new Timecode<DCPTime> (this);
85 grid->Add (_trim_start);
86 add_label_to_sizer (grid, this, _("Trim from end"), true);
87 _trim_end = new Timecode<DCPTime> (this);
88 grid->Add (_trim_end);
89 add_label_to_sizer (grid, this, _("Play length"), true);
90 _play_length = new Timecode<DCPTime> (this);
91 grid->Add (_play_length);
94 add_label_to_sizer (grid, this, _("Video frame rate"), true);
95 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
96 _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
97 s->Add (_video_frame_rate, 1, wxEXPAND);
98 _set_video_frame_rate = new wxButton (this, wxID_ANY, _("Set"));
99 _set_video_frame_rate->Enable (false);
100 s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
101 grid->Add (s, 1, wxEXPAND);
106 /* We can't use Wrap() here as it doesn't work with markup:
107 * http://trac.wxwidgets.org/ticket/13389
110 wxString in = _("<i>Only change this if it the content's frame rate has been read incorrectly.</i>");
112 int const width = 20;
114 for (size_t i = 0; i < in.Length(); ++i) {
115 if (in[i] == ' ' && current >= width) {
124 t = new wxStaticText (this, wxID_ANY, wxT (""));
125 t->SetLabelMarkup (out);
126 grid->Add (t, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 6);
128 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
129 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
130 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
131 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
132 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
133 _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this));
134 _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this));
138 TimingPanel::film_content_changed (int property)
140 ContentList cl = _parent->selected ();
141 int const film_video_frame_rate = _parent->film()->video_frame_rate ();
143 /* Here we check to see if we have exactly one different value of various
144 properties, and fill the controls with that value if so.
147 if (property == ContentProperty::POSITION) {
150 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
151 check.insert ((*i)->position ());
154 if (check.size() == 1) {
155 _position->set (cl.front()->position(), film_video_frame_rate);
161 property == ContentProperty::LENGTH ||
162 property == VideoContentProperty::VIDEO_FRAME_RATE ||
163 property == VideoContentProperty::VIDEO_FRAME_TYPE
167 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
168 check.insert ((*i)->full_length ());
171 if (check.size() == 1) {
172 _full_length->set (cl.front()->full_length (), film_video_frame_rate);
174 _full_length->clear ();
177 } else if (property == ContentProperty::TRIM_START) {
180 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
181 check.insert ((*i)->trim_start ());
184 if (check.size() == 1) {
185 _trim_start->set (cl.front()->trim_start (), film_video_frame_rate);
187 _trim_start->clear ();
190 } else if (property == ContentProperty::TRIM_END) {
193 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
194 check.insert ((*i)->trim_end ());
197 if (check.size() == 1) {
198 _trim_end->set (cl.front()->trim_end (), film_video_frame_rate);
205 property == ContentProperty::LENGTH ||
206 property == ContentProperty::TRIM_START ||
207 property == ContentProperty::TRIM_END ||
208 property == VideoContentProperty::VIDEO_FRAME_RATE ||
209 property == VideoContentProperty::VIDEO_FRAME_TYPE
213 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
214 check.insert ((*i)->length_after_trim ());
217 if (check.size() == 1) {
218 _play_length->set (cl.front()->length_after_trim (), film_video_frame_rate);
220 _play_length->clear ();
224 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
226 shared_ptr<VideoContent> vc;
227 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
228 shared_ptr<VideoContent> t = dynamic_pointer_cast<VideoContent> (*i);
230 check.insert (t->video_frame_rate ());
234 if (check.size() == 1) {
235 _video_frame_rate->SetValue (std_to_wx (raw_convert<string> (vc->video_frame_rate (), 5)));
236 _video_frame_rate->Enable (true);
238 _video_frame_rate->SetValue ("");
239 _video_frame_rate->Enable (false);
243 bool have_still = false;
244 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
245 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
246 if (ic && ic->still ()) {
251 _full_length->set_editable (have_still);
252 _play_length->set_editable (!have_still);
253 _set_video_frame_rate->Enable (false);
257 TimingPanel::position_changed ()
259 ContentList c = _parent->selected ();
260 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
261 (*i)->set_position (_position->get (_parent->film()->video_frame_rate ()));
266 TimingPanel::full_length_changed ()
268 ContentList c = _parent->selected ();
269 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
270 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
271 if (ic && ic->still ()) {
272 /* XXX: No effective FRC here... is this right? */
273 ic->set_video_length (ContentTime (_full_length->get (_parent->film()->video_frame_rate()), FrameRateChange (1, 1)));
279 TimingPanel::trim_start_changed ()
281 ContentList c = _parent->selected ();
282 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
283 (*i)->set_trim_start (_trim_start->get (_parent->film()->video_frame_rate ()));
289 TimingPanel::trim_end_changed ()
291 ContentList c = _parent->selected ();
292 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
293 (*i)->set_trim_end (_trim_end->get (_parent->film()->video_frame_rate ()));
298 TimingPanel::play_length_changed ()
300 ContentList c = _parent->selected ();
301 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
302 (*i)->set_trim_end ((*i)->full_length() - _play_length->get (_parent->film()->video_frame_rate()) - (*i)->trim_start());
307 TimingPanel::video_frame_rate_changed ()
309 _set_video_frame_rate->Enable (true);
313 TimingPanel::set_video_frame_rate ()
315 ContentList c = _parent->selected ();
316 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
317 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*i);
319 vc->set_video_frame_rate (raw_convert<float> (wx_to_std (_video_frame_rate->GetValue ())));
321 _set_video_frame_rate->Enable (false);
326 TimingPanel::content_selection_changed ()
328 bool const e = !_parent->selected().empty ();
330 _position->Enable (e);
331 _full_length->Enable (e);
332 _trim_start->Enable (e);
333 _trim_end->Enable (e);
334 _play_length->Enable (e);
335 _video_frame_rate->Enable (e);
337 film_content_changed (ContentProperty::POSITION);
338 film_content_changed (ContentProperty::LENGTH);
339 film_content_changed (ContentProperty::TRIM_START);
340 film_content_changed (ContentProperty::TRIM_END);
341 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);