NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
MIDITickComponent Class Referenceabstract

A pure virtual class implementing an object which has a callback procedure to be called at every tick of a MIDITimer. More...

#include <tick.h>

Inheritance diagram for MIDITickComponent:
MIDIRecorder MIDISequencer MIDIThru Metronome AdvancedSequencer

Public Member Functions

 MIDITickComponent (tPriority pr, MIDITick func)
 The constructor. More...
 
virtual ~MIDITickComponent ()
 The destructor. More...
 
virtual void Reset ()=0
 A pure virtual method which should reinitialize the class parameters. More...
 
MIDITickGetFunc () const
 Returns the address of the StaticTickProc() method, which will be called by the MIDIManager at every clock tick. More...
 
tPriority GetPriority () const
 Returns the priority. More...
 
tMsecs GetDevOffset () const
 Returns the user time offset parameter (see SetDevOffset()). More...
 
bool IsPlaying () const
 Returns true if the callback procedure is active. More...
 
void SetDevOffset (tMsecs dev_offs)
 Sets an user defined time offset, which will be added to every time calculation. More...
 
virtual void Start ()
 Sets the running status as true and starts to call the callback. More...
 
virtual void Stop ()
 Sets the running status as false and stops the callback. More...
 

Protected Member Functions

virtual void TickProc (tMsecs sys_time)=0
 This is the pure virtual function you must implement in your subclass. More...
 

Static Protected Member Functions

static void StaticTickProc (tMsecs sys_time, void *pt)
 This is the static callback procedure which the MIDIManager will call at every MIDITimer tick. More...
 

Protected Attributes

const MIDITicktick_proc
 The pointer to the static callback (set by the constructor to StaticTickProc()). More...
 
tMsecs dev_time_offset
 A time offset set by the user and which you can use for your calculations. More...
 
tMsecs sys_time_offset
 The system time of the last call of Start(). More...
 
std::recursive_mutex proc_lock
 A mutex you can use for implementing thread safe methods. More...
 

Detailed Description

A pure virtual class implementing an object which has a callback procedure to be called at every tick of a MIDITimer.

You can use this feature to send, receive or manipulate MIDI messages with accurate timing: the MIDISequencer, MIDIThru and MIDIRecorder classes inherit by this. To use a MIDITickComponent object it must be placed in the MIDIManager queue with the MIDIManager::AddMIDITick() method: this is done by the base class constructor so the user doesn't need to do this; you can hence call the Start() and Stop() methods of the object to start and stop the callback. A priority parameter is supplied to determine the position of the MIDITickComponent in the MIDIManager queue.

Examples
test_component.cpp.

Constructor & Destructor Documentation

◆ MIDITickComponent()

MIDITickComponent::MIDITickComponent ( tPriority  pr,
MIDITick  func 
)

The constructor.

It adds the component to the MIDIManager queue calling MIDIManager::AddMIDITick(), so the user doesn't need to do it manually.

Parameters
prthe priority (see tPriority)
funca pointer to the static callback: this should be the address of the StaticTickProc() you have implemented in your subclass

◆ ~MIDITickComponent()

virtual MIDITickComponent::~MIDITickComponent ( )
virtual

The destructor.

Before deleting the object it tries to remove its pointer from the MIDIManager queue to prevent the manager from using an invalid pointer. If a derived class destructor needs to delete something it should call Stop() as first statement, then do its work.

Member Function Documentation

◆ Reset()

virtual void MIDITickComponent::Reset ( )
pure virtual

A pure virtual method which should reinitialize the class parameters.

Implemented in AdvancedSequencer, Metronome, MIDIRecorder, MIDISequencer, and MIDIThru.

Examples
test_component.cpp.

◆ GetFunc()

MIDITick * MIDITickComponent::GetFunc ( ) const
inline

Returns the address of the StaticTickProc() method, which will be called by the MIDIManager at every clock tick.

◆ GetPriority()

tPriority MIDITickComponent::GetPriority ( ) const
inline

Returns the priority.

◆ GetDevOffset()

tMsecs MIDITickComponent::GetDevOffset ( ) const
inline

Returns the user time offset parameter (see SetDevOffset()).

◆ IsPlaying()

bool MIDITickComponent::IsPlaying ( ) const
inline

Returns true if the callback procedure is active.

Examples
test_advancedsequencer_noinput.cpp, test_thru.cpp, and test_writefile.cpp.

◆ SetDevOffset()

void MIDITickComponent::SetDevOffset ( tMsecs  dev_offs)

Sets an user defined time offset, which will be added to every time calculation.

For example, the MIDISequencer uses this as the start time of the sequencer.

◆ Start()

virtual void MIDITickComponent::Start ( )
virtual

Sets the running status as true and starts to call the callback.

Moreover it set the sys_time_offset parameter to the now time so, at every subsequent call of the callback, you can calculate the elapsed time. In your derived class you probably will want to redefine this for doing other things before starting the callback (for example opening MIDI ports): however in your derived method you must call this base class method.

Reimplemented in AdvancedSequencer, Metronome, MIDIRecorder, MIDISequencer, and MIDIThru.

Examples
test_component.cpp.

◆ Stop()

virtual void MIDITickComponent::Stop ( )
virtual

Sets the running status as false and stops the callback.

See also
Start()

Reimplemented in AdvancedSequencer, Metronome, MIDIRecorder, MIDISequencer, and MIDIThru.

Examples
test_component.cpp.

◆ StaticTickProc()

static void MIDITickComponent::StaticTickProc ( tMsecs  sys_time,
void *  pt 
)
inlinestaticprotected

This is the static callback procedure which the MIDIManager will call at every MIDITimer tick.

The parameters are automatically set by the MIDIManager at every function call.

Parameters
sys_timethe now system time
ptthe this pointer of the object instance.

You must implement it in your subclass and give this function address in the constructor. Typically this should only cast the void pointer pt to a pointer to your object and then call the pt->TickProc(sys_time), i.e. your non static procedure.

Examples
test_component.cpp.

◆ TickProc()

virtual void MIDITickComponent::TickProc ( tMsecs  sys_time)
protectedpure virtual

This is the pure virtual function you must implement in your subclass.

This function is called at every timer tick and in it you should do all the work of your component.

Implemented in Metronome, MIDIRecorder, MIDISequencer, and MIDIThru.

Examples
test_component.cpp.

Member Data Documentation

◆ tick_proc

const MIDITick* MIDITickComponent::tick_proc
protected

The pointer to the static callback (set by the constructor to StaticTickProc()).

◆ dev_time_offset

tMsecs MIDITickComponent::dev_time_offset
protected

A time offset set by the user and which you can use for your calculations.

◆ sys_time_offset

tMsecs MIDITickComponent::sys_time_offset
protected

The system time of the last call of Start().

You can use this for calculating the time elapsed between the start of the callback and the actual call of TickProc().

◆ proc_lock

std::recursive_mutex MIDITickComponent::proc_lock
protected

A mutex you can use for implementing thread safe methods.


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