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 "lib/content.h"
21 #include "lib/image_content.h"
22 #include "timing_panel.h"
25 #include "film_editor.h"
29 using boost::shared_ptr;
30 using boost::dynamic_pointer_cast;
31 using boost::lexical_cast;
33 TimingPanel::TimingPanel (FilmEditor* e)
34 : FilmEditorPanel (e, _("Timing"))
36 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
37 _sizer->Add (grid, 0, wxALL, 8);
39 add_label_to_sizer (grid, this, _("Position"), true);
40 _position = new Timecode (this);
41 grid->Add (_position);
42 add_label_to_sizer (grid, this, _("Full length"), true);
43 _full_length = new Timecode (this);
44 grid->Add (_full_length);
45 add_label_to_sizer (grid, this, _("Trim from start"), true);
46 _trim_start = new Timecode (this);
47 grid->Add (_trim_start);
48 add_label_to_sizer (grid, this, _("Trim from end"), true);
49 _trim_end = new Timecode (this);
50 grid->Add (_trim_end);
51 add_label_to_sizer (grid, this, _("Play length"), true);
52 _play_length = new Timecode (this);
53 grid->Add (_play_length);
56 add_label_to_sizer (grid, this, _("Video frame rate"), true);
57 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
58 _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
59 s->Add (_video_frame_rate, 1, wxEXPAND);
60 _set_video_frame_rate = new wxButton (this, wxID_ANY, _("Set"));
61 _set_video_frame_rate->Enable (false);
62 s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
63 grid->Add (s, 1, wxEXPAND);
66 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
67 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
68 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
69 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
70 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
71 _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this));
72 _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this));
76 TimingPanel::film_content_changed (int property)
78 ContentList cl = _editor->selected_content ();
79 shared_ptr<Content> content;
81 content = cl.front ();
84 int const film_video_frame_rate = _editor->film()->video_frame_rate ();
86 if (property == ContentProperty::POSITION) {
88 _position->set (content->position (), film_video_frame_rate);
90 _position->set (DCPTime () , 24);
93 property == ContentProperty::LENGTH ||
94 property == VideoContentProperty::VIDEO_FRAME_RATE ||
95 property == VideoContentProperty::VIDEO_FRAME_TYPE
98 _full_length->set (content->full_length (), film_video_frame_rate);
99 _play_length->set (content->length_after_trim (), film_video_frame_rate);
101 _full_length->set (DCPTime (), 24);
102 _play_length->set (DCPTime (), 24);
104 } else if (property == ContentProperty::TRIM_START) {
106 _trim_start->set (content->trim_start (), film_video_frame_rate);
107 _play_length->set (content->length_after_trim (), film_video_frame_rate);
109 _trim_start->set (DCPTime (), 24);
110 _play_length->set (DCPTime (), 24);
112 } else if (property == ContentProperty::TRIM_END) {
114 _trim_end->set (content->trim_end (), film_video_frame_rate);
115 _play_length->set (content->length_after_trim (), film_video_frame_rate);
117 _trim_end->set (DCPTime (), 24);
118 _play_length->set (DCPTime (), 24);
122 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
124 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (content);
126 _video_frame_rate->SetValue (std_to_wx (lexical_cast<string> (vc->video_frame_rate ())));
128 _video_frame_rate->SetValue ("24");
131 _video_frame_rate->SetValue ("24");
135 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (content);
136 _full_length->set_editable (ic && ic->still ());
137 _play_length->set_editable (!ic || !ic->still ());
138 _video_frame_rate->Enable (ic && !ic->still ());
139 _set_video_frame_rate->Enable (false);
143 TimingPanel::position_changed ()
145 ContentList c = _editor->selected_content ();
147 c.front()->set_position (_position->get (_editor->film()->video_frame_rate ()));
152 TimingPanel::full_length_changed ()
154 ContentList c = _editor->selected_content ();
156 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (c.front ());
157 if (ic && ic->still ()) {
158 /* XXX: No effective FRC here... is this right? */
159 ic->set_video_length (ContentTime (_full_length->get (_editor->film()->video_frame_rate()), FrameRateChange (1, 1)));
165 TimingPanel::trim_start_changed ()
167 ContentList c = _editor->selected_content ();
169 c.front()->set_trim_start (_trim_start->get (_editor->film()->video_frame_rate ()));
175 TimingPanel::trim_end_changed ()
177 ContentList c = _editor->selected_content ();
179 c.front()->set_trim_end (_trim_end->get (_editor->film()->video_frame_rate ()));
184 TimingPanel::play_length_changed ()
186 ContentList c = _editor->selected_content ();
188 c.front()->set_trim_end (c.front()->full_length() - _play_length->get (_editor->film()->video_frame_rate()) - c.front()->trim_start());
193 TimingPanel::video_frame_rate_changed ()
195 _set_video_frame_rate->Enable (true);
199 TimingPanel::set_video_frame_rate ()
201 ContentList c = _editor->selected_content ();
203 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (c.front ());
205 ic->set_video_frame_rate (lexical_cast<float> (wx_to_std (_video_frame_rate->GetValue ())));
207 _set_video_frame_rate->Enable (false);
212 TimingPanel::content_selection_changed ()
214 ContentList sel = _editor->selected_content ();
215 bool const single = sel.size() == 1;
217 /* Things that are only allowed with single selections */
218 _position->Enable (single);
219 _full_length->Enable (single);
220 _trim_start->Enable (single);
221 _trim_end->Enable (single);
222 _play_length->Enable (single);
223 _video_frame_rate->Enable (single);
225 film_content_changed (ContentProperty::POSITION);
226 film_content_changed (ContentProperty::LENGTH);
227 film_content_changed (ContentProperty::TRIM_START);
228 film_content_changed (ContentProperty::TRIM_END);
229 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);