2 Copyright (C) 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 <boost/lexical_cast.hpp>
25 using boost::lexical_cast;
27 Timecode::Timecode (wxWindow* parent)
30 wxClientDC dc (parent);
31 wxSize size = dc.GetTextExtent (wxT ("9999"));
34 wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
37 string n = "0123456789";
38 for (size_t i = 0; i < n.length(); ++i) {
42 validator.SetIncludes (list);
44 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
45 _hours = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size, 0, validator);
46 _hours->SetMaxLength (2);
48 add_label_to_sizer (sizer, this, ":");
49 _minutes = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
50 _minutes->SetMaxLength (2);
51 sizer->Add (_minutes);
52 add_label_to_sizer (sizer, this, ":");
53 _seconds = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
54 _seconds->SetMaxLength (2);
55 sizer->Add (_seconds);
56 add_label_to_sizer (sizer, this, ".");
57 _frames = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, size);
58 _frames->SetMaxLength (2);
61 SetSizerAndFit (sizer);
65 Timecode::set (Time t, int fps)
67 int const h = t / (3600 * TIME_HZ);
68 t -= h * 3600 * TIME_HZ;
69 int const m = t / (60 * TIME_HZ);
70 t -= m * 60 * TIME_HZ;
71 int const s = t / TIME_HZ;
73 int const f = t * fps / TIME_HZ;
75 _hours->SetValue (wxString::Format ("%02d", h));
76 _minutes->SetValue (wxString::Format ("%02d", m));
77 _seconds->SetValue (wxString::Format ("%02d", s));
78 _frames->SetValue (wxString::Format ("%02d", f));
82 Timecode::get (int fps) const
85 t += lexical_cast<int> (wx_to_std (_hours->GetValue())) * 3600 * TIME_HZ;
86 t += lexical_cast<int> (wx_to_std (_minutes->GetValue())) * 60 * TIME_HZ;
87 t += lexical_cast<int> (wx_to_std (_seconds->GetValue())) * TIME_HZ;
88 t += lexical_cast<int> (wx_to_std (_frames->GetValue())) * TIME_HZ / fps;