NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
|
A static class which provides the timing required for MIDI playback, using the C++11 <chrono> methods. More...
#include <timer.h>
Public Types | |
typedef std::chrono::steady_clock::time_point | timepoint |
Type for a variable which can hold a specific time point (internal use). More... | |
typedef std::chrono::milliseconds | duration |
Type for a variable which can hold a time duration (in milliseconds). More... | |
Public Member Functions | |
MIDITimer ()=delete | |
The constructor is deleted. More... | |
Static Public Member Functions | |
static unsigned int | GetResolution () |
Returns the timer resolution, i.e. the time interval (in milliseconds) between two ticks. More... | |
static MIDITick * | GetMIDITick () |
Returns the pointer to the callback function set by the user. More... | |
static bool | IsOpen () |
Returns true if the timer is running. More... | |
static void | SetResolution (unsigned int res) |
Sets the timer resolution to the given value in milliseconds. More... | |
static void | SetMIDITick (MIDITick *t, void *tp=0) |
Sets the callback function to be called at every timer tick and its parameter. More... | |
static bool | Start () |
Starts the background thread procedure which calls the callback function at every timer tick. More... | |
static void | Stop () |
Stops the timer, joining the background thread procedure. More... | |
static void | HardStop () |
Stops the timer, joining the background thread procedure, regardless the number of times Start() was called. More... | |
static tMsecs | GetSysTimeMs () |
Returns the elapsed time in milliseconds since the start of application. More... | |
static void | Wait (unsigned int msecs) |
Stops the calling thread for the given number of milliseconds. More... | |
Static Protected Member Functions | |
static void | ThreadProc () |
The background thread procedure. More... | |
Static Protected Attributes | |
static const unsigned int | DEFAULT_RESOLUTION = 10 |
The default timer resolution. More... | |
A static class which provides the timing required for MIDI playback, using the C++11 <chrono> methods.
It implements a timer which can call a user-defined callback function at a regular pace; when the timer is started, a background thread is created for this task. You can set the timer resolution in milliseconds (default is DEFAULT_RESOLUTION) and the callback function. Moreover, it provides some other timing utilities as static functions: you can stop a thread for a given number of milliseconds and get the system time elapsed from the application start. The MIDIManager class embeds the MIDITimer, controlling its start and stop, so you probably won't have to deal with it.
typedef std::chrono::steady_clock::time_point MIDITimer::timepoint |
Type for a variable which can hold a specific time point (internal use).
typedef std::chrono::milliseconds MIDITimer::duration |
Type for a variable which can hold a time duration (in milliseconds).
|
delete |
The constructor is deleted.
|
inlinestatic |
Returns the timer resolution, i.e. the time interval (in milliseconds) between two ticks.
|
inlinestatic |
Returns the pointer to the callback function set by the user.
|
inlinestatic |
Returns true if the timer is running.
|
static |
Sets the timer resolution to the given value in milliseconds.
This method stops the timer if it is running.
|
static |
Sets the callback function to be called at every timer tick and its parameter.
The function must be of MIDITick type (i.e. void Funct(tMsecs, void*) ) and it's called with the system time as first parameter and the given void pointer as second. This method stops the timer if it is running.
|
static |
Starts the background thread procedure which calls the callback function at every timer tick.
If you call this more than once you must call Stop() an equal number of times (or call HardStop()) to interrupt the background thread.
|
static |
Stops the timer, joining the background thread procedure.
If Start() was called more than once it only decrements the count of calls.
|
static |
Stops the timer, joining the background thread procedure, regardless the number of times Start() was called.
|
inlinestatic |
Returns the elapsed time in milliseconds since the start of application.
The 0 time is a chrono::steady_clock::timepoint static variable.
|
inlinestatic |
Stops the calling thread for the given number of milliseconds.
Other threads continue their execution.
|
staticprotected |
The background thread procedure.
This calls the tick_proc callback supplied by the user and sleeps until next tick.
|
staticprotected |
The default timer resolution.