Ardour  8.7-14-g57a6773833
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 namespace ArdourSurface { namespace MACKIE_NAMESPACE {
29 
33 class Timer
34 {
35 public:
36 
41  Timer( bool shouldStart = true )
42  {
43  if ( shouldStart )
44  start();
45  }
46 
50  unsigned long start()
51  {
52  _start = g_get_monotonic_time();
53  return _start / 1000;
54  }
55 
60  unsigned long stop()
61  {
62  _stop = g_get_monotonic_time();
63  return elapsed();
64  }
65 
69  unsigned long elapsed() const
70  {
71  if ( running )
72  {
73  uint64_t now = g_get_monotonic_time();
74  return (now - _start) / 1000;
75  }
76  else
77  {
78  return (_stop - _start) / 1000;
79  }
80  }
81 
85  unsigned long restart()
86  {
87  unsigned long retval = stop();
88  start();
89  return retval;
90  }
91 
92 private:
93  uint64_t _start;
94  uint64_t _stop;
95  bool running;
96 };
97 
98 } // Mackie namespace
99 } // ArdourSurface namespace
100 
101 #endif
PBD::PropertyDescriptor< bool > running
PBD::PropertyDescriptor< timepos_t > start
#define MACKIE_NAMESPACE