30#ifndef _NICMIDI_TIMER_H
31#define _NICMIDI_TIMER_H
66 typedef std::chrono::steady_clock::time_point
timepoint;
76 static bool IsOpen() {
return (num_open > 0); }
101 {
return std::chrono::duration_cast<std::chrono::milliseconds>
102 (std::chrono::steady_clock::now() - sys_clock_base).count(); }
105 static void Wait(
unsigned int msecs)
106 { std::this_thread::sleep_for(std::chrono::milliseconds(msecs)); }
117 static unsigned int resolution;
119 static void* tick_param;
120 static std::thread bg_thread;
121 static std::atomic<int> num_open;
A static class which provides the timing required for MIDI playback, using the C++11 <chrono> methods...
Definition: timer.h:62
static MIDITick * GetMIDITick()
Returns the pointer to the callback function set by the user.
Definition: timer.h:74
static bool IsOpen()
Returns true if the timer is running.
Definition: timer.h:76
static void HardStop()
Stops the timer, joining the background thread procedure, regardless the number of times Start() was ...
MIDITimer()=delete
The constructor is deleted.
std::chrono::steady_clock::time_point timepoint
Type for a variable which can hold a specific time point (internal use).
Definition: timer.h:66
static const unsigned int DEFAULT_RESOLUTION
The default timer resolution.
Definition: timer.h:110
static unsigned int GetResolution()
Returns the timer resolution, i.e. the time interval (in milliseconds) between two ticks.
Definition: timer.h:72
static tMsecs GetSysTimeMs()
Returns the elapsed time in milliseconds since the start of application.
Definition: timer.h:100
static void SetResolution(unsigned int res)
Sets the timer resolution to the given value in milliseconds.
static void SetMIDITick(MIDITick *t, void *tp=0)
Sets the callback function to be called at every timer tick and its parameter.
static void ThreadProc()
The background thread procedure.
static void Stop()
Stops the timer, joining the background thread procedure.
static void Wait(unsigned int msecs)
Stops the calling thread for the given number of milliseconds.
Definition: timer.h:105
std::chrono::milliseconds duration
Type for a variable which can hold a time duration (in milliseconds).
Definition: timer.h:68
static bool Start()
Starts the background thread procedure which calls the callback function at every timer tick.
unsigned long long tMsecs
The type of a variable which can hold the elapsed time in milliseconds.
Definition: timer.h:44
void() MIDITick(tMsecs, void *)
This is the typedef of the callback functions which are called at every timer tick.
Definition: timer.h:47