Make length editable only for still images.
[dcpomatic.git] / src / wx / timing_panel.cc
1 /*
2     Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include "lib/content.h"
21 #include "lib/still_image_content.h"
22 #include "timing_panel.h"
23 #include "wx_util.h"
24 #include "timecode.h"
25 #include "film_editor.h"
26
27 using std::cout;
28 using boost::shared_ptr;
29 using boost::dynamic_pointer_cast;
30
31 TimingPanel::TimingPanel (FilmEditor* e)
32         : FilmEditorPanel (e, _("Timing"))
33 {
34         wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
35         _sizer->Add (grid, 0, wxALL, 8);
36
37         add_label_to_sizer (grid, this, _("Start time"), true);
38         _start = new Timecode (this);
39         grid->Add (_start);
40         add_label_to_sizer (grid, this, _("Length"), true);
41         _length = new Timecode (this);
42         grid->Add (_length);
43
44         _start->Changed.connect  (boost::bind (&TimingPanel::start_changed, this));
45         _length->Changed.connect (boost::bind (&TimingPanel::length_changed, this));
46 }
47
48 void
49 TimingPanel::film_content_changed (shared_ptr<Content> content, int property)
50 {
51         if (property == ContentProperty::START) {
52                 if (content) {
53                         _start->set (content->start (), _editor->film()->video_frame_rate ());
54                 } else {
55                         _start->set (0, 24);
56                 }
57         } else if (property == ContentProperty::LENGTH) {
58                 if (content) {
59                         _length->set (content->length (), _editor->film()->video_frame_rate ());
60                 } else {
61                         _length->set (0, 24);
62                 }
63         }
64
65         _length->set_editable (dynamic_pointer_cast<StillImageContent> (content));
66 }
67
68 void
69 TimingPanel::start_changed ()
70 {
71         shared_ptr<Content> c = _editor->selected_content ();
72         if (!c) {
73                 return;
74         }
75
76         c->set_start (_start->get (_editor->film()->video_frame_rate ()));
77 }
78
79 void
80 TimingPanel::length_changed ()
81 {
82         shared_ptr<Content> c = _editor->selected_content ();
83         if (!c) {
84                 return;
85         }
86
87         shared_ptr<StillImageContent> ic = dynamic_pointer_cast<StillImageContent> (c);
88         if (ic) {
89                 ic->set_video_length (_length->get (_editor->film()->video_frame_rate()) * ic->video_frame_rate() / TIME_HZ);
90         }
91 }