Basic video fade support.
[dcpomatic.git] / src / wx / timecode.h
1 /*
2     Copyright (C) 2013-2014 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 #ifndef DCPOMATIC_WX_TIMECODE_H
21 #define DCPOMATIC_WX_TIMECODE_H
22
23 #include "wx_util.h"
24 #include "lib/types.h"
25 #include <wx/wx.h>
26 #include <boost/signals2.hpp>
27 #include <boost/lexical_cast.hpp>
28
29 class TimecodeBase : public wxPanel
30 {
31 public:
32         TimecodeBase (wxWindow *);
33
34         void clear ();
35
36         void set_editable (bool);
37
38         boost::signals2::signal<void ()> Changed;
39
40 protected:
41         void changed ();
42         void set_clicked ();
43         
44         wxSizer* _sizer;
45         wxPanel* _editable;
46         wxTextCtrl* _hours;
47         wxTextCtrl* _minutes;
48         wxTextCtrl* _seconds;
49         wxTextCtrl* _frames;
50         wxButton* _set_button;
51         wxStaticText* _fixed;
52 };
53
54 template <class T>
55 class Timecode : public TimecodeBase
56 {
57 public:
58         Timecode (wxWindow* parent)
59                 : TimecodeBase (parent)
60         {
61
62         }
63
64         void set (T t, int fps)
65         {
66                 int h;
67                 int m;
68                 int s;
69                 int f;
70                 t.split (fps, h, m, s, f);
71                 
72                 checked_set (_hours, boost::lexical_cast<std::string> (h));
73                 checked_set (_minutes, boost::lexical_cast<std::string> (m));
74                 checked_set (_seconds, boost::lexical_cast<std::string> (s));
75                 checked_set (_frames, boost::lexical_cast<std::string> (f));
76                 
77                 _fixed->SetLabel (std_to_wx (t.timecode (fps)));
78         }
79
80         T get (int fps) const
81         {
82                 T t;
83                 std::string const h = wx_to_std (_hours->GetValue ());
84                 t += T::from_seconds (boost::lexical_cast<int> (h.empty() ? "0" : h) * 3600);
85                 std::string const m = wx_to_std (_minutes->GetValue());
86                 t += T::from_seconds (boost::lexical_cast<int> (m.empty() ? "0" : m) * 60);
87                 std::string const s = wx_to_std (_seconds->GetValue());
88                 t += T::from_seconds (boost::lexical_cast<int> (s.empty() ? "0" : s));
89                 std::string const f = wx_to_std (_frames->GetValue());
90                 t += T::from_seconds (boost::lexical_cast<double> (f.empty() ? "0" : f) / fps);
91                 
92                 return t;
93         }
94 };
95
96 #endif