Ardour  9.0-pre0-582-g084a23a80d
pbd/pbd/timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Tim Mayberry <mojofunk@gmail.com>
3  * Copyright (C) 2015 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 #include <sigc++/signal.h>
23 
24 #include <glibmm/main.h>
25 
26 #include "pbd/libpbd_visibility.h"
27 
28 namespace PBD {
29 
36 {
37 public:
38 
39  Timer (unsigned int interval,
40  const Glib::RefPtr<Glib::MainContext>& main_context);
41 
42  unsigned int get_interval () const;
43 
44  void set_interval (unsigned int new_interval);
45 
46  virtual unsigned int connection_count () const = 0;
47 
48  void suspend () { m_suspended = true; }
49  void resume () { m_suspended = false; }
50 
51 protected:
52 
53  virtual ~Timer() { }
54 
55  void start ();
56 
57  void stop ();
58 
59  virtual bool on_elapsed () = 0;
60 
61  bool suspended () const { return m_suspended; }
62 
63 private:
64 
65  Timer(const Timer&);
66  Timer& operator= (const Timer&);
67 
68 private:
69 
70  static gboolean _timeout_handler (void *data);
71 
72  bool timeout_handler ();
73 
74  GSource* m_timeout_source;
75 
76  unsigned int m_timeout_interval;
77 
78  const Glib::RefPtr<Glib::MainContext> m_main_context;
79 
81 
82 };
83 
85 {
86 public:
87 
88  StandardTimer (unsigned int interval,
89  const Glib::RefPtr<Glib::MainContext>& main_context = Glib::MainContext::get_default());
90 
91  sigc::connection connect (const sigc::slot<void>& slot);
92 
93  virtual unsigned int connection_count () const
94  { return m_signal.size (); }
95 
96 protected:
97 
98  virtual bool on_elapsed ();
99 
100  sigc::signal<void> m_signal;
101 
102 };
103 
105 {
106 public:
107 
108  BlinkTimer (unsigned int interval,
109  const Glib::RefPtr<Glib::MainContext>& main_context = Glib::MainContext::get_default());
110 
111 
112  sigc::connection connect (const sigc::slot<void, bool>& slot);
113 
114  virtual unsigned int connection_count () const
115  { return m_blink_signal.size (); }
116 
117 protected:
118 
119  virtual bool on_elapsed ();
120 
121  sigc::signal<void, bool> m_blink_signal;
122 
123 };
124 
125 } // namespace PBD
126 
sigc::connection connect(const sigc::slot< void, bool > &slot)
BlinkTimer(unsigned int interval, const Glib::RefPtr< Glib::MainContext > &main_context=Glib::MainContext::get_default())
virtual bool on_elapsed()
virtual unsigned int connection_count() const
sigc::signal< void, bool > m_blink_signal
sigc::connection connect(const sigc::slot< void > &slot)
virtual bool on_elapsed()
StandardTimer(unsigned int interval, const Glib::RefPtr< Glib::MainContext > &main_context=Glib::MainContext::get_default())
sigc::signal< void > m_signal
virtual unsigned int connection_count() const
Definition: pbd/pbd/timer.h:93
const Glib::RefPtr< Glib::MainContext > m_main_context
Definition: pbd/pbd/timer.h:78
bool suspended() const
Definition: pbd/pbd/timer.h:61
virtual ~Timer()
Definition: pbd/pbd/timer.h:53
GSource * m_timeout_source
Definition: pbd/pbd/timer.h:74
void suspend()
Definition: pbd/pbd/timer.h:48
unsigned int m_timeout_interval
Definition: pbd/pbd/timer.h:76
virtual unsigned int connection_count() const =0
static gboolean _timeout_handler(void *data)
bool m_suspended
Definition: pbd/pbd/timer.h:80
unsigned int get_interval() const
void resume()
Definition: pbd/pbd/timer.h:49
void set_interval(unsigned int new_interval)
void stop()
bool timeout_handler()
Timer(const Timer &)
void start()
virtual bool on_elapsed()=0
Timer(unsigned int interval, const Glib::RefPtr< Glib::MainContext > &main_context)
#define LIBPBD_API
Definition: axis_view.h:42