Ardour  9.0-pre0-427-gd2a3450e2f
surfaces/mackie/timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2007 John Anderson
3  * Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2014-2015 Robin Gareus <robin@gareus.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef timer_h
22 #define timer_h
23 
24 #include <glib.h>
25 
26 #include "types.h"
27 
28 #include <cstdint>
29 
30 namespace ArdourSurface { namespace MACKIE_NAMESPACE {
31 
35 class Timer
36 {
37 public:
38 
43  Timer( bool shouldStart = true )
44  {
45  if ( shouldStart )
46  start();
47  }
48 
52  unsigned long start()
53  {
54  _start = g_get_monotonic_time();
55  return _start / 1000;
56  }
57 
62  unsigned long stop()
63  {
64  _stop = g_get_monotonic_time();
65  return elapsed();
66  }
67 
71  unsigned long elapsed() const
72  {
73  if ( running )
74  {
75  uint64_t now = g_get_monotonic_time();
76  return (now - _start) / 1000;
77  }
78  else
79  {
80  return (_stop - _start) / 1000;
81  }
82  }
83 
87  unsigned long restart()
88  {
89  unsigned long retval = stop();
90  start();
91  return retval;
92  }
93 
94 private:
95  uint64_t _start;
96  uint64_t _stop;
97  bool running;
98 };
99 
100 } // Mackie namespace
101 } // ArdourSurface namespace
102 
103 #endif
PBD::PropertyDescriptor< bool > running
PBD::PropertyDescriptor< timepos_t > start
#define MACKIE_NAMESPACE