Split timing panel into its own class.
[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 boost::shared_ptr;
28 using boost::dynamic_pointer_cast;
29
30 TimingPanel::TimingPanel (FilmEditor* e)
31         : FilmEditorPanel (e, _("Timing"))
32 {
33         wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4);
34         _sizer->Add (grid, 0, wxALL, 8);
35
36         add_label_to_sizer (grid, this, _("Start time"), true);
37         _start = new Timecode (this);
38         grid->Add (_start);
39         add_label_to_sizer (grid, this, _("Length"), true);
40         _length = new Timecode (this);
41         grid->Add (_length);
42
43         _start->Changed.connect  (boost::bind (&TimingPanel::start_changed, this));
44         _length->Changed.connect (boost::bind (&TimingPanel::length_changed, this));
45 }
46
47 void
48 TimingPanel::film_content_changed (shared_ptr<Content> content, int property)
49 {
50         if (property == ContentProperty::START) {
51                 if (content) {
52                         _start->set (content->start (), _editor->film()->dcp_video_frame_rate ());
53                 } else {
54                         _start->set (0, 24);
55                 }
56         } else if (property == ContentProperty::LENGTH) {
57                 if (content) {
58                         _length->set (content->length (), _editor->film()->dcp_video_frame_rate ());
59                 } else {
60                         _length->set (0, 24);
61                 }
62         }
63 }
64
65 void
66 TimingPanel::start_changed ()
67 {
68         shared_ptr<Content> c = _editor->selected_content ();
69         if (!c) {
70                 return;
71         }
72
73         c->set_start (_start->get (_editor->film()->dcp_video_frame_rate ()));
74 }
75
76 void
77 TimingPanel::length_changed ()
78 {
79         shared_ptr<Content> c = _editor->selected_content ();
80         if (!c) {
81                 return;
82         }
83
84         shared_ptr<StillImageContent> ic = dynamic_pointer_cast<StillImageContent> (c);
85         if (ic) {
86                 ic->set_video_length (_length->get (_editor->film()->dcp_video_frame_rate()) * ic->video_frame_rate() / TIME_HZ);
87         }
88 }