X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ftimecode.h;h=c31a6740c5ea86c86e1fb9a2763dba874a23e85d;hb=0254f2d12acb2ff8d770b4e47dc15599d145fe17;hp=0c99d536187cfeb61586cd9a28c1d91a62bebe08;hpb=48c75fff036cb6960fc4c86317231914588a668d;p=dcpomatic.git diff --git a/src/wx/timecode.h b/src/wx/timecode.h index 0c99d5361..c31a6740c 100644 --- a/src/wx/timecode.h +++ b/src/wx/timecode.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2020 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -22,6 +22,7 @@ #define DCPOMATIC_WX_TIMECODE_H #include "wx_util.h" +#include "lib/dcpomatic_time.h" #include "lib/types.h" #include #include @@ -53,6 +54,8 @@ protected: wxTextCtrl* _frames; wxButton* _set_button; wxStaticText* _fixed; + + bool _ignore_changed = false; }; template @@ -67,57 +70,45 @@ public: void set (T t, float fps) { - int h; - int m; - int s; - int f; - t.split (fps, h, m, s, f); + auto const hmsf = t.split (fps); - checked_set (_hours, dcp::raw_convert(h)); - checked_set (_minutes, dcp::raw_convert(m)); - checked_set (_seconds, dcp::raw_convert(s)); - checked_set (_frames, dcp::raw_convert(f)); + checked_set (_hours, dcp::raw_convert(hmsf.h)); + checked_set (_minutes, dcp::raw_convert(hmsf.m)); + checked_set (_seconds, dcp::raw_convert(hmsf.s)); + checked_set (_frames, dcp::raw_convert(hmsf.f)); checked_set (_fixed, t.timecode (fps)); } void set_hint (T t, float fps) { - int h; - int m; - int s; - int f; - t.split (fps, h, m, s, f); - - _hours->SetHint (std_to_wx(dcp::raw_convert(h))); - _minutes->SetHint (std_to_wx(dcp::raw_convert(m))); - _seconds->SetHint (std_to_wx(dcp::raw_convert(s))); - _frames->SetHint (std_to_wx(dcp::raw_convert(f))); + auto hmsf = t.split (fps); + + _hours->SetHint (std_to_wx(dcp::raw_convert(hmsf.h))); + _minutes->SetHint (std_to_wx(dcp::raw_convert(hmsf.m))); + _seconds->SetHint (std_to_wx(dcp::raw_convert(hmsf.s))); + _frames->SetHint (std_to_wx(dcp::raw_convert(hmsf.f))); } - T get (float fps) const + dcpomatic::HMSF get () const { - T t; - std::string const h = value_or_hint (_hours); - t += T::from_seconds (dcp::raw_convert(h.empty() ? "0" : h) * 3600); - std::string const m = value_or_hint (_minutes); - t += T::from_seconds (dcp::raw_convert(m.empty() ? "0" : m) * 60); - std::string const s = value_or_hint (_seconds); - t += T::from_seconds (dcp::raw_convert(s.empty() ? "0" : s)); - std::string const f = value_or_hint (_frames); - t += T::from_seconds (dcp::raw_convert(f.empty() ? "0" : f) / fps); - - return t; + auto value_or_hint = [](wxTextCtrl const * t) { + auto s = wx_to_std (t->GetValue().IsEmpty() ? t->GetHint() : t->GetValue()); + if (s.empty()) { + return 0; + } + return dcp::raw_convert(s); + }; + + return { value_or_hint(_hours), + value_or_hint(_minutes), + value_or_hint(_seconds), + value_or_hint(_frames) }; } -private: - std::string value_or_hint (wxTextCtrl const * t) const + T get (float fps) const { - if (!t->GetValue().IsEmpty()) { - return wx_to_std (t->GetValue()); - } else { - return wx_to_std (t->GetHint()); - } + return T(get(), fps); } };