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"
28 using boost::shared_ptr;
29 using boost::dynamic_pointer_cast;
31 TimingPanel::TimingPanel (FilmEditor* e)
32 : FilmEditorPanel (e, _("Timing"))
34 wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
35 _sizer->Add (grid, 0, wxALL, 8);
37 add_label_to_sizer (grid, this, _("Position"), true);
38 _position = new Timecode (this);
39 grid->Add (_position);
40 add_label_to_sizer (grid, this, _("Full length"), true);
41 _full_length = new Timecode (this);
42 grid->Add (_full_length);
43 add_label_to_sizer (grid, this, _("Trim from start"), true);
44 _trim_start = new Timecode (this);
45 grid->Add (_trim_start);
46 add_label_to_sizer (grid, this, _("Trim from end"), true);
47 _trim_end = new Timecode (this);
48 grid->Add (_trim_end);
49 add_label_to_sizer (grid, this, _("Play length"), true);
50 _play_length = new Timecode (this);
51 grid->Add (_play_length);
53 _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this));
54 _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this));
55 _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this));
56 _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this));
57 _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this));
61 TimingPanel::film_content_changed (int property)
63 ContentList cl = _editor->selected_content ();
64 shared_ptr<Content> content;
66 content = cl.front ();
69 if (property == ContentProperty::POSITION) {
71 _position->set (content->position (), _editor->film()->video_frame_rate ());
73 _position->set (0, 24);
75 } else if (property == ContentProperty::LENGTH) {
77 _full_length->set (content->full_length (), _editor->film()->video_frame_rate ());
78 _play_length->set (content->length_after_trim (), _editor->film()->video_frame_rate ());
80 _full_length->set (0, 24);
81 _play_length->set (0, 24);
83 } else if (property == ContentProperty::TRIM_START) {
85 _trim_start->set (content->trim_start (), _editor->film()->video_frame_rate ());
86 _play_length->set (content->length_after_trim (), _editor->film()->video_frame_rate ());
88 _trim_start->set (0, 24);
89 _play_length->set (0, 24);
91 } else if (property == ContentProperty::TRIM_END) {
93 _trim_end->set (content->trim_end (), _editor->film()->video_frame_rate ());
94 _play_length->set (content->length_after_trim (), _editor->film()->video_frame_rate ());
96 _trim_end->set (0, 24);
97 _play_length->set (0, 24);
101 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (content);
102 _full_length->set_editable (ic && ic->still ());
103 _play_length->set_editable (!ic || !ic->still ());
107 TimingPanel::position_changed ()
109 ContentList c = _editor->selected_content ();
111 c.front()->set_position (_position->get (_editor->film()->video_frame_rate ()));
116 TimingPanel::full_length_changed ()
118 ContentList c = _editor->selected_content ();
120 shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (c.front ());
121 if (ic && ic->still ()) {
122 ic->set_video_length (rint (_full_length->get (_editor->film()->video_frame_rate()) * ic->video_frame_rate() / TIME_HZ));
128 TimingPanel::trim_start_changed ()
130 ContentList c = _editor->selected_content ();
132 c.front()->set_trim_start (_trim_start->get (_editor->film()->video_frame_rate ()));
138 TimingPanel::trim_end_changed ()
140 ContentList c = _editor->selected_content ();
142 c.front()->set_trim_end (_trim_end->get (_editor->film()->video_frame_rate ()));
147 TimingPanel::play_length_changed ()
149 ContentList c = _editor->selected_content ();
151 c.front()->set_trim_end (c.front()->full_length() - _play_length->get (_editor->film()->video_frame_rate()) - c.front()->trim_start());
156 TimingPanel::content_selection_changed ()
158 ContentList sel = _editor->selected_content ();
159 bool const single = sel.size() == 1;
161 /* Things that are only allowed with single selections */
162 _position->Enable (single);
163 _full_length->Enable (single);
164 _trim_start->Enable (single);
165 _trim_end->Enable (single);
166 _play_length->Enable (single);
168 film_content_changed (ContentProperty::POSITION);
169 film_content_changed (ContentProperty::LENGTH);
170 film_content_changed (ContentProperty::TRIM_START);
171 film_content_changed (ContentProperty::TRIM_END);