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

A MIDITickComponent implementing a metronome. More...

#include <metronome.h>

Inheritance diagram for Metronome:
MIDITickComponent

Public Member Functions

 Metronome (MIDISequencerGUINotifier *n=0)
 The constructor. More...
 
virtual ~Metronome ()
 The destructor. The MIDISequencerGUINotifier is not owned by the Metronome. More...
 
virtual void Reset ()
 Stops the metronome and resets it to its default values. More...
 
MIDIClockTime GetCurrentMIDIClockTime () const
 Returns current MIDIClockTime in MIDI ticks from the start of the metronome. More...
 
float GetCurrentTimeMs () const
 Returns current time in milliseconds from the start of the metronome. More...
 
unsigned int GetCurrentMeasure () const
 Returns current measure (1st measure is 0). More...
 
unsigned int GetCurrentBeat () const
 Returns current beat in the measure (1st beat is 0). More...
 
unsigned int GetTempoScale () const
 Returns current tempo scale in percentage (100 = no scaling, 200 = twice faster, etc.). More...
 
float GetTempoWithoutScale () const
 Returns current tempo (BPM) without scaling. More...
 
float GetTempoWithScale () const
 Returns current tempo (BPM) taking into account scaling (this is the true actual tempo). More...
 
unsigned int GetOutPort () const
 Returns the number of the MIDI out port assigned to the metronome. More...
 
unsigned int GetOutChannel () const
 Returns the number of the MIDI channel assigned to the metronome. More...
 
unsigned char GetMeasNote () const
 Returns the MIDI note number for the measure click. More...
 
unsigned char GetBeatNote () const
 Returns the MIDI note number for the ordinary beat click. More...
 
unsigned char GetSubdNote () const
 Returns the MIDI note number for the subdivision click. More...
 
unsigned char GetSubdType () const
 Returns the subdivision type. It can be 0 (subd clicks disabled), 2, 3, 4, 5, 6. More...
 
unsigned char GetTimeSigNumerator () const
 Returns the numerator of the current timesig. More...
 
bool SetTempo (float t)
 Sets the musical tempo. More...
 
bool SetTempoScale (unsigned int scale)
 Sets the global tempo scale. More...
 
bool SetOutPort (unsigned int port)
 Sets the MIDI out port for the metronome clicks. More...
 
bool SetOutChannel (unsigned int chan)
 Sets the MIDI channel for the metronome clicks. More...
 
void SetMeasNote (unsigned char note)
 Sets the MIDI note number for the measure click (the 1st beat of the measure). More...
 
void SetBeatNote (unsigned char note)
 Sets the MIDI note number for the ordinary beat click. More...
 
void SetSubdNote (unsigned char note)
 Sets the MIDI note number for the subdivision click. More...
 
bool SetSubdType (unsigned char type)
 Sets the subdivision type. More...
 
void SetTimeSigNumerator (unsigned char n)
 Sets the numerator of the current timesig. More...
 
virtual void Start ()
 Starts the metronome. More...
 
virtual void Stop ()
 Stops the metronome. More...
 
- Public Member Functions inherited from MIDITickComponent
 MIDITickComponent (tPriority pr, MIDITick func)
 The constructor. More...
 
virtual ~MIDITickComponent ()
 The destructor. 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...
 

Protected Member Functions

void UpdateValues ()
 Copies the temp values assigned by the set methods into the effective ones. More...
 
virtual void TickProc (tMsecs sys_time)
 Implements the pure virtual method inherited from MIDITickComponent (you must not call it directly). More...
 

Static Protected Member Functions

static void StaticTickProc (tMsecs sys_time, void *pt)
 Implements the static method inherited from MIDITickComponent and called at every timer tick. More...
 
- Static Protected Member Functions inherited from MIDITickComponent
static void StaticTickProc (tMsecs sys_time, void *pt)
 This is the static callback procedure which the MIDIManager will call at every MIDITimer tick. More...
 

Additional Inherited Members

- Protected Attributes inherited from MIDITickComponent
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 MIDITickComponent implementing a metronome.

You can select the port, channel and MIDI notes of the metronome clicks; moreover you can have three types of click: the ordinary (beat) click, the measure click (first beat of a measure) and a subdivision click. If you enable measure clicks the metronome can count the measures and the beats of a measure (so you can represent them in a graphical interface). When you change some parameter (tempo, measure, etc./) the metronome is not updated immediately, but only at the subsequent click (see UpdateValues()).

Examples
test_metronome.cpp.

Constructor & Destructor Documentation

◆ Metronome()

Metronome::Metronome ( MIDISequencerGUINotifier n = 0)

The constructor.

It raises an exception if in your system there are no MIDI out ports.

Parameters
na pointer to a MIDISequencerGUINotifier. If you leave 0 the sequencer will not notify the GUI.
Exceptions
RtMidiError::INVALID_DEVICEif in the system are not present MIDI out ports.

◆ ~Metronome()

virtual Metronome::~Metronome ( )
inlinevirtual

The destructor. The MIDISequencerGUINotifier is not owned by the Metronome.

Member Function Documentation

◆ Reset()

virtual void Metronome::Reset ( )
virtual

Stops the metronome and resets it to its default values.

Implements MIDITickComponent.

◆ GetCurrentMIDIClockTime()

MIDIClockTime Metronome::GetCurrentMIDIClockTime ( ) const
inline

Returns current MIDIClockTime in MIDI ticks from the start of the metronome.

◆ GetCurrentTimeMs()

float Metronome::GetCurrentTimeMs ( ) const

Returns current time in milliseconds from the start of the metronome.

◆ GetCurrentMeasure()

unsigned int Metronome::GetCurrentMeasure ( ) const
inline

Returns current measure (1st measure is 0).

Measures count is suspended if you disable the measure click (see SetTimeSigNumerator()).

Examples
test_metronome.cpp.

◆ GetCurrentBeat()

unsigned int Metronome::GetCurrentBeat ( ) const
inline

Returns current beat in the measure (1st beat is 0).

Examples
test_metronome.cpp.

◆ GetTempoScale()

unsigned int Metronome::GetTempoScale ( ) const
inline

Returns current tempo scale in percentage (100 = no scaling, 200 = twice faster, etc.).

Examples
test_metronome.cpp.

◆ GetTempoWithoutScale()

float Metronome::GetTempoWithoutScale ( ) const
inline

Returns current tempo (BPM) without scaling.

Examples
test_metronome.cpp.

◆ GetTempoWithScale()

float Metronome::GetTempoWithScale ( ) const
inline

Returns current tempo (BPM) taking into account scaling (this is the true actual tempo).

Examples
test_metronome.cpp.

◆ GetOutPort()

unsigned int Metronome::GetOutPort ( ) const
inline

Returns the number of the MIDI out port assigned to the metronome.

Examples
test_metronome.cpp.

◆ GetOutChannel()

unsigned int Metronome::GetOutChannel ( ) const
inline

Returns the number of the MIDI channel assigned to the metronome.

See Numbering conventions.

Examples
test_metronome.cpp.

◆ GetMeasNote()

unsigned char Metronome::GetMeasNote ( ) const
inline

Returns the MIDI note number for the measure click.

Examples
test_metronome.cpp.

◆ GetBeatNote()

unsigned char Metronome::GetBeatNote ( ) const
inline

Returns the MIDI note number for the ordinary beat click.

Examples
test_metronome.cpp.

◆ GetSubdNote()

unsigned char Metronome::GetSubdNote ( ) const
inline

Returns the MIDI note number for the subdivision click.

Examples
test_metronome.cpp.

◆ GetSubdType()

unsigned char Metronome::GetSubdType ( ) const
inline

Returns the subdivision type. It can be 0 (subd clicks disabled), 2, 3, 4, 5, 6.

Examples
test_metronome.cpp.

◆ GetTimeSigNumerator()

unsigned char Metronome::GetTimeSigNumerator ( ) const
inline

Returns the numerator of the current timesig.

If it is 0 the measure clicks are disabled, otherwise the 1st click of a measure will sound with different note and volume.

Examples
test_metronome.cpp.

◆ SetTempo()

bool Metronome::SetTempo ( float  t)

Sets the musical tempo.

You can set it between 1.0 bpm and 300.0 bpm.

Returns
true if t is a valid tempo, false otherwise.
Examples
test_metronome.cpp.

◆ SetTempoScale()

bool Metronome::SetTempoScale ( unsigned int  scale)

Sets the global tempo scale.

Parameters
scalethe percentage: 100 = no scaling, 200 = twice faster, 50 = twice slower, etc.
Returns
true if scale is a valid number, false otherwise (actually only if it is 0).
Examples
test_metronome.cpp.

◆ SetOutPort()

bool Metronome::SetOutPort ( unsigned int  port)

Sets the MIDI out port for the metronome clicks.

Parameters
portThe out MIDI port id number
Returns
true if port is a valid port number, false otherwise.
Examples
test_metronome.cpp.

◆ SetOutChannel()

bool Metronome::SetOutChannel ( unsigned int  chan)

Sets the MIDI channel for the metronome clicks.

See Numbering conventions.

Returns
true if chan is a valid channel number, false otherwise.
Examples
test_metronome.cpp.

◆ SetMeasNote()

void Metronome::SetMeasNote ( unsigned char  note)

Sets the MIDI note number for the measure click (the 1st beat of the measure).

It is only effective if you have already set the timesig numerator (see SetTimesigNumerator()).

Examples
test_metronome.cpp.

◆ SetBeatNote()

void Metronome::SetBeatNote ( unsigned char  note)

Sets the MIDI note number for the ordinary beat click.

Examples
test_metronome.cpp.

◆ SetSubdNote()

void Metronome::SetSubdNote ( unsigned char  note)

Sets the MIDI note number for the subdivision click.

Examples
test_metronome.cpp.

◆ SetSubdType()

bool Metronome::SetSubdType ( unsigned char  type)

Sets the subdivision type.

It can be 0 (subd clicks disabled), 2, 3, 4, 5, 6.

Returns
true if type is a valid subdivision number, false otherwise.
Examples
test_metronome.cpp.

◆ SetTimeSigNumerator()

void Metronome::SetTimeSigNumerator ( unsigned char  n)

Sets the numerator of the current timesig.

If it is 0 the measure clicks are disabled, otherwise the 1st click of a measure will sound with different note and volume.

Examples
test_metronome.cpp.

◆ Start()

virtual void Metronome::Start ( )
virtual

Starts the metronome.

Reimplemented from MIDITickComponent.

Examples
test_metronome.cpp.

◆ Stop()

virtual void Metronome::Stop ( )
virtual

Stops the metronome.

Reimplemented from MIDITickComponent.

Examples
test_metronome.cpp.

◆ UpdateValues()

void Metronome::UpdateValues ( )
protected

Copies the temp values assigned by the set methods into the effective ones.

It is called immediately if the metronome is not running, otherwise at every click, so the metronome parameters are updated in sync.

◆ StaticTickProc()

static void Metronome::StaticTickProc ( tMsecs  sys_time,
void *  pt 
)
staticprotected

Implements the static method inherited from MIDITickComponent and called at every timer tick.

It only calls the member TickProc().

◆ TickProc()

virtual void Metronome::TickProc ( tMsecs  sys_time)
protectedvirtual

Implements the pure virtual method inherited from MIDITickComponent (you must not call it directly).

Implements MIDITickComponent.


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