NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
MIDITimer Class Reference

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 MIDITickGetMIDITick ()
 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...
 

Detailed Description

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.

Member Typedef Documentation

◆ timepoint

typedef std::chrono::steady_clock::time_point MIDITimer::timepoint

Type for a variable which can hold a specific time point (internal use).

◆ duration

typedef std::chrono::milliseconds MIDITimer::duration

Type for a variable which can hold a time duration (in milliseconds).

Constructor & Destructor Documentation

◆ MIDITimer()

MIDITimer::MIDITimer ( )
delete

The constructor is deleted.

Member Function Documentation

◆ GetResolution()

static unsigned int MIDITimer::GetResolution ( )
inlinestatic

Returns the timer resolution, i.e. the time interval (in milliseconds) between two ticks.

◆ GetMIDITick()

static MIDITick * MIDITimer::GetMIDITick ( )
inlinestatic

Returns the pointer to the callback function set by the user.

◆ IsOpen()

static bool MIDITimer::IsOpen ( )
inlinestatic

Returns true if the timer is running.

◆ SetResolution()

static void MIDITimer::SetResolution ( unsigned int  res)
static

Sets the timer resolution to the given value in milliseconds.

This method stops the timer if it is running.

◆ SetMIDITick()

static void MIDITimer::SetMIDITick ( MIDITick t,
void *  tp = 0 
)
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.

◆ Start()

static bool MIDITimer::Start ( )
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.

◆ Stop()

static void MIDITimer::Stop ( )
static

Stops the timer, joining the background thread procedure.

If Start() was called more than once it only decrements the count of calls.

◆ HardStop()

static void MIDITimer::HardStop ( )
static

Stops the timer, joining the background thread procedure, regardless the number of times Start() was called.

◆ GetSysTimeMs()

static tMsecs MIDITimer::GetSysTimeMs ( )
inlinestatic

Returns the elapsed time in milliseconds since the start of application.

The 0 time is a chrono::steady_clock::timepoint static variable.

◆ Wait()

static void MIDITimer::Wait ( unsigned int  msecs)
inlinestatic

Stops the calling thread for the given number of milliseconds.

Other threads continue their execution.

Examples
test_advancedsequencer_noinput.cpp, test_component.cpp, test_recorder2.cpp, and test_writefile.cpp.

◆ ThreadProc()

static void MIDITimer::ThreadProc ( )
staticprotected

The background thread procedure.

This calls the tick_proc callback supplied by the user and sleeps until next tick.

Member Data Documentation

◆ DEFAULT_RESOLUTION

const unsigned int MIDITimer::DEFAULT_RESOLUTION = 10
staticprotected

The default timer resolution.


The documentation for this class was generated from the following file: