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 "lib/sndfile_content.h"
23 #include "timing_panel.h"
26 #include "film_editor.h"
30 using boost::shared_ptr;
31 using boost::dynamic_pointer_cast;
32 using boost::lexical_cast;
34 TimingPanel::TimingPanel (FilmEditor* e)
35 : FilmEditorPanel (e, _("Timing"))
37 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
38 _sizer->Add (grid, 0, wxALL, 8);
40 add_label_to_sizer (grid, this, _("Position"), true);
41 _position = new Timecode (this);
42 grid->Add (_position);
43 add_label_to_sizer (grid, this, _("Full length"), true);
44 _full_length = new Timecode (this);
45 grid->Add (_full_length);
46 add_label_to_sizer (grid, this, _("Trim from start"), true);
47 _trim_start = new Timecode (this);
48 grid->Add (_trim_start);
49 add_label_to_sizer (grid, this, _("Trim from end"), true);
50 _trim_end = new Timecode (this);
51 grid->Add (_trim_end);
52 add_label_to_sizer (grid, this, _("Play length"), true);
53 _play_length = new Timecode (this);
54 grid->Add (_play_length);
57 add_label_to_sizer (grid, this, _("Video frame rate"), true);
58 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
59 _video_frame_rate = new wxTextCtrl (this, wxID_ANY);
60 s->Add (_video_frame_rate, 1, wxEXPAND);
61 _set_video_frame_rate = new wxButton (this, wxID_ANY, _("Set"));
62 _set_video_frame_rate->Enable (false);
63 s->Add (_set_video_frame_rate, 0, wxLEFT | wxRIGHT, 8);
64 grid->Add (s, 1, wxEXPAND);
67 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
68 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
69 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
70 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
71 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
72 _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this));
73 _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this));
77 TimingPanel::film_content_changed (int property)
79 ContentList cl = _editor->selected_content ();
80 shared_ptr<Content> content;
82 content = cl.front ();
85 int const film_video_frame_rate = _editor->film()->video_frame_rate ();
87 if (property == ContentProperty::POSITION) {
89 _position->set (content->position (), film_video_frame_rate);
91 _position->set (0, 24);
94 property == ContentProperty::LENGTH ||
95 property == VideoContentProperty::VIDEO_FRAME_RATE ||
96 property == VideoContentProperty::VIDEO_FRAME_TYPE ||
97 property == SndfileContentProperty::VIDEO_FRAME_RATE
100 _full_length->set (content->full_length (), film_video_frame_rate);
101 _play_length->set (content->length_after_trim (), film_video_frame_rate);
103 _full_length->set (0, 24);
104 _play_length->set (0, 24);
106 } else if (property == ContentProperty::TRIM_START) {
108 _trim_start->set (content->trim_start (), film_video_frame_rate);
109 _play_length->set (content->length_after_trim (), film_video_frame_rate);
111 _trim_start->set (0, 24);
112 _play_length->set (0, 24);
114 } else if (property == ContentProperty::TRIM_END) {
116 _trim_end->set (content->trim_end (), film_video_frame_rate);
117 _play_length->set (content->length_after_trim (), film_video_frame_rate);
119 _trim_end->set (0, 24);
120 _play_length->set (0, 24);
124 if (property == VideoContentProperty::VIDEO_FRAME_RATE) {
126 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (content);
127 shared_ptr<SndfileContent> sc = dynamic_pointer_cast<SndfileContent> (content);
129 _video_frame_rate->SetValue (std_to_wx (lexical_cast<string> (vc->video_frame_rate ())));
131 _video_frame_rate->SetValue (std_to_wx (lexical_cast<string> (sc->video_frame_rate ())));
133 _video_frame_rate->SetValue ("24");
136 _video_frame_rate->SetValue ("24");
140 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (content);
141 shared_ptr<SndfileContent> sc = dynamic_pointer_cast<SndfileContent> (content);
142 _full_length->set_editable (ic && ic->still ());
143 _play_length->set_editable (!ic || !ic->still ());
144 _video_frame_rate->Enable ((ic && !ic->still ()) || sc);
145 _set_video_frame_rate->Enable (false);
149 TimingPanel::position_changed ()
151 ContentList c = _editor->selected_content ();
153 c.front()->set_position (_position->get (_editor->film()->video_frame_rate ()));
158 TimingPanel::full_length_changed ()
160 ContentList c = _editor->selected_content ();
162 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (c.front ());
163 if (ic && ic->still ()) {
164 ic->set_video_length (rint (_full_length->get (_editor->film()->video_frame_rate()) * ic->video_frame_rate() / TIME_HZ));
170 TimingPanel::trim_start_changed ()
172 ContentList c = _editor->selected_content ();
174 c.front()->set_trim_start (_trim_start->get (_editor->film()->video_frame_rate ()));
180 TimingPanel::trim_end_changed ()
182 ContentList c = _editor->selected_content ();
184 c.front()->set_trim_end (_trim_end->get (_editor->film()->video_frame_rate ()));
189 TimingPanel::play_length_changed ()
191 ContentList c = _editor->selected_content ();
193 c.front()->set_trim_end (c.front()->full_length() - _play_length->get (_editor->film()->video_frame_rate()) - c.front()->trim_start());
198 TimingPanel::video_frame_rate_changed ()
200 _set_video_frame_rate->Enable (true);
204 TimingPanel::set_video_frame_rate ()
206 ContentList c = _editor->selected_content ();
208 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (c.front ());
210 ic->set_video_frame_rate (lexical_cast<float> (wx_to_std (_video_frame_rate->GetValue ())));
212 shared_ptr<SndfileContent> sc = dynamic_pointer_cast<SndfileContent> (c.front ());
214 sc->set_video_frame_rate (lexical_cast<float> (wx_to_std (_video_frame_rate->GetValue ())));
216 _set_video_frame_rate->Enable (false);
221 TimingPanel::content_selection_changed ()
223 ContentList sel = _editor->selected_content ();
224 bool const single = sel.size() == 1;
226 /* Things that are only allowed with single selections */
227 _position->Enable (single);
228 _full_length->Enable (single);
229 _trim_start->Enable (single);
230 _trim_end->Enable (single);
231 _play_length->Enable (single);
232 _video_frame_rate->Enable (single);
234 film_content_changed (ContentProperty::POSITION);
235 film_content_changed (ContentProperty::LENGTH);
236 film_content_changed (ContentProperty::TRIM_START);
237 film_content_changed (ContentProperty::TRIM_END);
238 film_content_changed (VideoContentProperty::VIDEO_FRAME_RATE);