2 Copyright (C) 2012-2013 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 <dcp/raw_convert.h>
21 #include "lib/content.h"
22 #include "lib/image_content.h"
23 #include "timing_panel.h"
26 #include "content_panel.h"
31 using boost::shared_ptr;
32 using boost::dynamic_pointer_cast;
33 using dcp::raw_convert;
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 add_label_to_sizer (grid, this, _("Position"), true);
43 _position = new Timecode<DCPTime> (this);
44 grid->Add (_position);
45 add_label_to_sizer (grid, this, _("Full length"), true);
46 _full_length = new Timecode<DCPTime> (this);
47 grid->Add (_full_length);
48 add_label_to_sizer (grid, this, _("Trim from start"), true);
49 _trim_start = new Timecode<DCPTime> (this);
50 grid->Add (_trim_start);
51 add_label_to_sizer (grid, this, _("Trim from end"), true);
52 _trim_end = new Timecode<DCPTime> (this);
53 grid->Add (_trim_end);
54 add_label_to_sizer (grid, this, _("Play length"), true);
55 _play_length = new Timecode<DCPTime> (this);
56 grid->Add (_play_length);
59 add_label_to_sizer (grid, this, _("Video frame rate"), true);
60 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
61 _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
62 s->Add (_video_frame_rate, 1, wxEXPAND);
63 _set_video_frame_rate = new wxButton (this, wxID_ANY, _("Set"));
64 _set_video_frame_rate->Enable (false);
65 s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
66 grid->Add (s, 1, wxEXPAND);
69 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
70 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
71 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
72 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
73 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
74 _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this));
75 _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this));
79 TimingPanel::film_content_changed (int property)
81 ContentList cl = _parent->selected ();
82 int const film_video_frame_rate = _parent->film()->video_frame_rate ();
84 /* Here we check to see if we have exactly one different value of various
85 properties, and fill the controls with that value if so.
88 if (property == ContentProperty::POSITION) {
91 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
92 check.insert ((*i)->position ());
95 if (check.size() == 1) {
96 _position->set (cl.front()->position(), film_video_frame_rate);
102 property == ContentProperty::LENGTH ||
103 property == VideoContentProperty::VIDEO_FRAME_RATE ||
104 property == VideoContentProperty::VIDEO_FRAME_TYPE
108 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
109 check.insert ((*i)->full_length ());
112 if (check.size() == 1) {
113 _full_length->set (cl.front()->full_length (), film_video_frame_rate);
115 _full_length->clear ();
118 } else if (property == ContentProperty::TRIM_START) {
121 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
122 check.insert ((*i)->trim_start ());
125 if (check.size() == 1) {
126 _trim_start->set (cl.front()->trim_start (), film_video_frame_rate);
128 _trim_start->clear ();
131 } else if (property == ContentProperty::TRIM_END) {
134 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
135 check.insert ((*i)->trim_end ());
138 if (check.size() == 1) {
139 _trim_end->set (cl.front()->trim_end (), film_video_frame_rate);
146 property == ContentProperty::LENGTH ||
147 property == ContentProperty::TRIM_START ||
148 property == ContentProperty::TRIM_END ||
149 property == VideoContentProperty::VIDEO_FRAME_RATE ||
150 property == VideoContentProperty::VIDEO_FRAME_TYPE
154 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
155 check.insert ((*i)->length_after_trim ());
158 if (check.size() == 1) {
159 _play_length->set (cl.front()->length_after_trim (), film_video_frame_rate);
161 _play_length->clear ();
165 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
167 shared_ptr<VideoContent> vc;
168 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
169 shared_ptr<VideoContent> t = dynamic_pointer_cast<VideoContent> (*i);
171 check.insert (t->video_frame_rate ());
175 if (check.size() == 1) {
176 _video_frame_rate->SetValue (std_to_wx (raw_convert<string> (vc->video_frame_rate (), 5)));
177 _video_frame_rate->Enable (true);
179 _video_frame_rate->SetValue ("");
180 _video_frame_rate->Enable (false);
184 bool have_still = false;
185 for (ContentList::const_iterator i = cl.begin (); i != cl.end(); ++i) {
186 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
187 if (ic && ic->still ()) {
192 _full_length->set_editable (have_still);
193 _play_length->set_editable (!have_still);
194 _set_video_frame_rate->Enable (false);
198 TimingPanel::position_changed ()
200 ContentList c = _parent->selected ();
201 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
202 (*i)->set_position (_position->get (_parent->film()->video_frame_rate ()));
207 TimingPanel::full_length_changed ()
209 ContentList c = _parent->selected ();
210 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
211 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
212 if (ic && ic->still ()) {
213 /* XXX: No effective FRC here... is this right? */
214 ic->set_video_length (ContentTime (_full_length->get (_parent->film()->video_frame_rate()), FrameRateChange (1, 1)));
220 TimingPanel::trim_start_changed ()
222 ContentList c = _parent->selected ();
223 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
224 (*i)->set_trim_start (_trim_start->get (_parent->film()->video_frame_rate ()));
230 TimingPanel::trim_end_changed ()
232 ContentList c = _parent->selected ();
233 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
234 (*i)->set_trim_end (_trim_end->get (_parent->film()->video_frame_rate ()));
239 TimingPanel::play_length_changed ()
241 ContentList c = _parent->selected ();
242 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
243 (*i)->set_trim_end ((*i)->full_length() - _play_length->get (_parent->film()->video_frame_rate()) - (*i)->trim_start());
248 TimingPanel::video_frame_rate_changed ()
250 _set_video_frame_rate->Enable (true);
254 TimingPanel::set_video_frame_rate ()
256 ContentList c = _parent->selected ();
257 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
258 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*i);
260 vc->set_video_frame_rate (raw_convert<float> (wx_to_std (_video_frame_rate->GetValue ())));
262 _set_video_frame_rate->Enable (false);
267 TimingPanel::content_selection_changed ()
269 bool const e = !_parent->selected().empty ();
271 _position->Enable (e);
272 _full_length->Enable (e);
273 _trim_start->Enable (e);
274 _trim_end->Enable (e);
275 _play_length->Enable (e);
276 _video_frame_rate->Enable (e);
278 film_content_changed (ContentProperty::POSITION);
279 film_content_changed (ContentProperty::LENGTH);
280 film_content_changed (ContentProperty::TRIM_START);
281 film_content_changed (ContentProperty::TRIM_END);
282 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);