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

The MIDITimedMessage class inherits from the MIDIMessage and represents a message associated with a specific MIDIClockTime (i.e. More...

#include <msg.h>

Inheritance diagram for MIDITimedMessage:
MIDIMessage

Public Member Functions

 MIDITimedMessage ()
 Creates a a NoOp MIDITimedMessage with the time set to 0. More...
 
 MIDITimedMessage (const MIDITimedMessage &msg)
 Copy constructor. More...
 
 MIDITimedMessage (const MIDIMessage &msg)
 Copy constructor (sets the time to 0). More...
 
 ~MIDITimedMessage ()
 Destructor. More...
 
virtual void Clear ()
 Resets the message, frees the MIDISystemExclusive pointer and sets the time to 0. More...
 
const MIDITimedMessageoperator= (const MIDITimedMessage &msg)
 Assignment operator. More...
 
const MIDITimedMessageoperator= (const MIDIMessage &msg)
 Assignment operator (sets the time to 0). More...
 
virtual std::string MsgToText (unsigned char chan_from_1=0) const
 Returns a human readable ascii string describing the message content. More...
 
MIDIClockTime GetTime () const
 Returns the MIDIClockTime associated with the message. More...
 
void SetTime (MIDIClockTime t)
 Sets the MIDIClockTime associated with the message. More...
 
void AddTime (MIDIClockTime t)
 Adds the given amount to the associated time. More...
 
void SubTime (MIDIClockTime t)
 Subtracts the given amount from the associated time (if t is greater set the time to 0). More...
 
void SetNoOp ()
 The same of Clear(), makes the message an undefined message which will be ignored. More...
 
- Public Member Functions inherited from MIDIMessage
 MIDIMessage ()
 Creates a a NoOp MIDIMessage (an undefined MIDI message, which will be ignored when playing). More...
 
 MIDIMessage (const MIDIMessage &msg)
 The copy constructor. More...
 
virtual ~MIDIMessage ()
 The destructor. More...
 
void ClearSysEx ()
 Frees the MIDISystemExclusive pointer without changing other bytes. More...
 
const MIDIMessageoperator= (const MIDIMessage &msg)
 The assignment operator. More...
 
int GetLength () const
 Returns the length in bytes of the entire message. More...
 
unsigned char GetStatus () const
 Returns the status byte of the message. More...
 
unsigned char GetChannel () const
 If the message is a channel message, returns its MIDI channel. More...
 
unsigned char GetType () const
 Returns the relevant top 4 bits of the status byte, which describe what type of channel message it is. More...
 
unsigned char GetMetaType () const
 If the message is a meta-message, returns the type byte. See MIDI Enumerations for meta event types.. More...
 
unsigned char GetByte1 () const
 Returns the raw value of the data byte 1 of the message. More...
 
unsigned char GetByte2 () const
 Returns the raw value of the data byte 2 of the message. More...
 
unsigned char GetByte3 () const
 Returns the raw value of the data byte 3 of the message. More...
 
MIDISystemExclusiveGetSysEx ()
 Returns a pointer to the MIDISystemExclusive object (0 if it is not allocated). More...
 
const MIDISystemExclusiveGetSysEx () const
 Returns a pointer to the MIDISystemExclusive object (0 if it is not allocated). More...
 
unsigned char GetNote () const
 If the message is a note on, note off, or poly aftertouch message, returns the note number. More...
 
unsigned char GetVelocity () const
 If the message is a note on, note off, or poly aftertouch message, returns the note velocity (or pressure). More...
 
unsigned char GetChannelPressure () const
 If the message is a channel pressure message, returns the pressure value. More...
 
unsigned char GetProgramValue () const
 If the message is a program change (patch) message, returns the program number. More...
 
unsigned char GetController () const
 If the message is a control change message, returns the controller number. More...
 
unsigned char GetControllerValue () const
 If the message is a control change message, returns the controller value. More...
 
int16_t GetBenderValue () const
 If the message is a bender message, returns the signed 14 bit bender value. More...
 
uint16_t GetMetaValue () const
 If the message is a meta-message, returns the unsigned 14 bit value attached. More...
 
unsigned char GetTimeSigNumerator () const
 If the message is a time signature meta-message, returns the numerator of the time signature. More...
 
unsigned char GetTimeSigDenominator () const
 If the message is a time signature meta-message, returns the denominator of the time signature. More...
 
signed char GetKeySigSharpsFlats () const
 If the message is a key signature meta-message, returns the key in SMF format. More...
 
unsigned char GetKeySigMode () const
 If the message is a key signature meta-message, returns major/minor SMF flag. More...
 
float GetTempo () const
 If the message is a tempo change meta-message, returns the tempo value in bpm. More...
 
unsigned long GetInternalTempo () const
 If the message is a tempo change meta-message, returns the tempo in SMF format. More...
 
std::string GetText () const
 If the message is a text meta-message, returns the associated text as a std::string. More...
 
bool IsChannelMsg () const
 Returns true if the message is some sort of channel message. More...
 
bool IsNoteOn () const
 Returns true if the message is a note on message (status == NOTE_ON and velocity > 0). More...
 
bool IsNoteOff () const
 Returns true if the message is a note off message (status == NOTE_OFF or status == NOTE_ON and velocity == 0). More...
 
bool IsNote () const
 Returns true if the message is a note on or a note off message. More...
 
bool IsPolyPressure () const
 Returns true if the message is a polyphonic pressure channel message. More...
 
bool IsControlChange () const
 Returns true if the message is a control change message. More...
 
bool IsVolumeChange () const
 Returns true if the message is a volume change message (control == 0x07). More...
 
bool IsPanChange () const
 Returns true if the message is a pan change message (control == 0x0A). More...
 
bool IsPedalOn () const
 Returns true if the message is a pedal on message (control == 0x40 and value >= 0x64). More...
 
bool IsPedalOff () const
 Returns true if the message is a pedal off message (control == 0x40 and value < 0x64). More...
 
bool IsProgramChange () const
 Returns true if the message is a program change message. More...
 
bool IsChannelPressure () const
 Returns true if the message is a channel pressure message. More...
 
bool IsPitchBend () const
 Returns true if the message is a bender message. More...
 
bool IsChannelMode () const
 Returns true if the message is a channel mode message (a control change with control >= 0x7A). More...
 
bool IsAllNotesOff () const
 Returns true if the message is a all notes off message. More...
 
bool IsSystemMessage () const
 Returns true if the message is a system message (the status byte is 0xf0 or higher). More...
 
bool IsSysEx () const
 Returns true if the message is a system exclusive message. More...
 
bool IsMetaEvent () const
 Returns true if the message is a meta event message. More...
 
bool IsTextEvent () const
 Returns true if the message is a text message (a subset of meta events). More...
 
bool IsTrackName () const
 Returns true if the message is a track name meta-message. More...
 
bool IsMarkerText () const
 Returns true if the message is a marker text meta-message. More...
 
bool IsTempo () const
 Returns true if the message is a tempo change meta-message. More...
 
bool IsDataEnd () const
 Returns true if the message is a data end (i.e. end of track) meta-message. More...
 
bool IsSMPTEOffset () const
 Returns true if the message is a SMPTE offset meta-message. More...
 
bool IsTimeSig () const
 Returns true if the message is a time Signature meta-message. More...
 
bool IsKeySig () const
 Returns true if the message is a key signature meta-message. More...
 
bool IsNoOp () const
 Returns true if the message is a NoOp (not initialized) message. More...
 
bool IsBeatMarker () const
 Returns true if the message is a beat marker message. More...
 
void SetStatus (unsigned char s)
 Sets all 8 bits of the status byte of the message. These define, for channel messages, the type and the channel. More...
 
void SetChannel (unsigned char s)
 Sets the lower 4 bits of the status byte without changing the upper 4 bits. See Numbering conventions. More...
 
void SetType (unsigned char s)
 Sets the upper 4 bits of the status byte without changing the lower 4 bits. More...
 
void SetByte1 (unsigned char b)
 Sets the raw value of the data byte 1 of the message. More...
 
void SetByte2 (unsigned char b)
 Sets the raw value of the data byte 2 of the message. More...
 
void SetByte3 (unsigned char b)
 Sets the raw value of the data byte 3 of the message. More...
 
void SetNote (unsigned char n)
 Sets the note number for note on, note off, and polyphonic aftertouch messages. More...
 
void SetVelocity (unsigned char v)
 Sets the velocity for note on, note off and polyphonic aftertouch messages. More...
 
void SetController (unsigned char c)
 Sets the controller number for a control change message. More...
 
void SetControllerValue (unsigned char v)
 Sets the controller value for a control change message. More...
 
void SetProgramValue (unsigned char v)
 Sets the program number for a program change message. More...
 
void SetBenderValue (int16_t v)
 Sets the bender value (a signed 14 bit value) for a bender message. More...
 
void SetMetaType (unsigned char t)
 Sets the meta message type for a meta-event message. More...
 
void SetMetaValue (unsigned short v)
 Sets the meta value for a meta-event message. More...
 
void SetNoteOn (unsigned char chan, unsigned char note, unsigned char vel)
 Makes the message a note on message with given channel, note and velocity. More...
 
void SetNoteOff (unsigned char chan, unsigned char note, unsigned char vel)
 Makes the message a note off message with given channel, note and velocity. More...
 
void SetPolyPressure (unsigned char chan, unsigned char note, unsigned char pres)
 Makes the message a polyphonic aftertouch message with given channel, note and pressure. More...
 
void SetControlChange (unsigned char chan, unsigned char ctrl, unsigned char val)
 Makes the message a control change message with given channel, controller and value. More...
 
void SetVolumeChange (unsigned char chan, unsigned char val)
 Makes the message a volume change (control == 0x07) message with given channel and value. More...
 
void SetPanChange (unsigned char chan, unsigned char val)
 Makes the message a pan change (control == 0x0A) message with given channel and value. More...
 
void SetProgramChange (unsigned char chan, unsigned char prog)
 Makes the message a program change message with given channel and program. More...
 
void SetChannelPressure (unsigned char chan, unsigned char pres)
 Makes the message a channel pressure message with given channel and pressure. More...
 
void SetPitchBend (unsigned char chan, short val)
 Makes the message a pitch bend message with given channel and value (unsigned 14 bit). More...
 
void SetChannelMode (unsigned char chan, unsigned char type, unsigned char val=0)
 Makes the message a channel mode message (i.e. More...
 
void SetAllNotesOff (unsigned char chan)
 Makes the message a all notes off message with given channel. More...
 
void SetSysEx (const MIDISystemExclusive *se)
 Makes the message a system exclusive message with given MIDISystemExclusive object. More...
 
void SetMTC (unsigned char field, unsigned char val)
 Makes the message a MIDI time code message with given field (3 bits) and value (4 bits). Frees the sysex pointer. More...
 
void SetSongPosition (int16_t pos)
 Makes the message a song position system message with given position (14 bits). Frees the sysex pointer. More...
 
void SetSongSelect (unsigned char sng)
 Makes the message a song select system message with given song. Frees the sysex pointer. More...
 
void SetSystemMessage (unsigned char type)
 Makes the message a one-byte system message with given status (type must be a valid MIDI system message status byte, see MIDI Enumerations). More...
 
void SetMetaEvent (unsigned char type, unsigned char v1, unsigned char v2)
 Makes the message a meta-message with given type and data value. More...
 
void SetMetaEvent (unsigned char type, unsigned short val)
 Makes the message a meta-message with given type and data value. More...
 
void SetText (const char *text, unsigned char type=META_GENERIC_TEXT)
 Makes the message a text meta-message with given type. More...
 
void SetDataEnd ()
 Makes the message a data end (i.e. end of track) meta-message. More...
 
void SetTempo (float tempo_bpm)
 Makes the message a tempo change meta-message with given tempo (in bpm). More...
 
void SetSMPTEOffset (unsigned char hour, unsigned char min, unsigned char sec, unsigned char frame, unsigned char subframe)
 Makes the message a SMPTE offset meta-message with given data. More...
 
void SetTimeSig (unsigned char num, unsigned char den, unsigned char clocks_per_metronome=0, unsigned char num_32_per_quarter=8)
 Makes the message a time signature meta-message with given time (numerator and denominator). More...
 
void SetKeySig (signed char sharp_flats, unsigned char major_minor)
 Makes the message a key signature meta-message with given accidents and mode. More...
 
void SetNoOp ()
 The same of Clear(), makes the message an uninitialized message which will be ignored. More...
 
void SetBeatMarker ()
 Makes the message a beat marker internal service message. More...
 
virtual std::string MsgToText (bool chan_from_1=false) const
 Returns a human readable ascii string describing the message content. More...
 
void AllocateSysEx (unsigned int len)
 Allocates a MIDISystemExclusive object, with a buffer of given max size. More...
 
void CopySysEx (const MIDISystemExclusive *se)
 Copies the given MIDISystemExclusive object into the message without changing other bytes. More...
 

Protected Attributes

MIDIClockTime time
 The time of the event. More...
 

Friends

int CompareEventsForInsert (const MIDITimedMessage &m1, const MIDITimedMessage &m2)
 Used by the MIDITrack::InsertEvent() and MIDITrack::InsertNote() methods for ordering events when inserting them in a MIDITrack. More...
 
bool IsSameKind (const MIDITimedMessage &m1, const MIDITimedMessage &m2)
 Used by methods that search and insert events in a MIDITrack to find events that are of the same kind and would normally be incompatible in the same track and at the same time. More...
 
bool operator== (const MIDITimedMessage &m1, const MIDITimedMessage &m2)
 The equal operator. It compares the messages bitwise. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MIDIMessage
static void UseNoteOnv0ForOff (bool f)
 This static method determines if the SetNoteOff() method will produce a MIDI NOTE_OFF message or a NOTE_ON with velocity 0. More...
 

Detailed Description

The MIDITimedMessage class inherits from the MIDIMessage and represents a message associated with a specific MIDIClockTime (i.e.

the number of MIDI ticks from the start. The MIDITrack class stores a vector of ordered MIDITimedMessage items, and they are used for playing, writing and loading MIDI files.

Examples
test_advancedsequencer_noinput.cpp, test_component.cpp, test_recorder.cpp, test_stepsequencer.cpp, test_thru.cpp, and test_writefile.cpp.

Constructor & Destructor Documentation

◆ MIDITimedMessage() [1/3]

MIDITimedMessage::MIDITimedMessage ( )

Creates a a NoOp MIDITimedMessage with the time set to 0.

This is an undefined MIDI message), which will be ignored when playing.

◆ MIDITimedMessage() [2/3]

MIDITimedMessage::MIDITimedMessage ( const MIDITimedMessage msg)

Copy constructor.

See also
MIDIMessage::MIDIMessage()

◆ MIDITimedMessage() [3/3]

MIDITimedMessage::MIDITimedMessage ( const MIDIMessage msg)

Copy constructor (sets the time to 0).

See also
MIDIMessage::(MIDIMessage()

◆ ~MIDITimedMessage()

MIDITimedMessage::~MIDITimedMessage ( )

Destructor.

Member Function Documentation

◆ Clear()

virtual void MIDITimedMessage::Clear ( )
virtual

Resets the message, frees the MIDISystemExclusive pointer and sets the time to 0.

The message becomes a NoOp.

Reimplemented from MIDIMessage.

Examples
test_advancedsequencer_noinput.cpp, and test_writefile.cpp.

◆ operator=() [1/2]

const MIDITimedMessage & MIDITimedMessage::operator= ( const MIDITimedMessage msg)

Assignment operator.

See also
MIDIMessage::operator=()

◆ operator=() [2/2]

const MIDITimedMessage & MIDITimedMessage::operator= ( const MIDIMessage msg)

Assignment operator (sets the time to 0).

See also
MIDIMessage::operator=()

◆ MsgToText()

virtual std::string MIDITimedMessage::MsgToText ( unsigned char  chan_from_1 = 0) const
virtual

Returns a human readable ascii string describing the message content.

Parameters
chan_from_1if zero channels are numbered 0 ... 15, otherwise 1 ... 16. See Numbering conventions

◆ GetTime()

MIDIClockTime MIDITimedMessage::GetTime ( ) const
inline

Returns the MIDIClockTime associated with the message.

◆ SetTime()

void MIDITimedMessage::SetTime ( MIDIClockTime  t)
inline

Sets the MIDIClockTime associated with the message.

Examples
test_advancedsequencer_noinput.cpp, test_stepsequencer.cpp, and test_writefile.cpp.

◆ AddTime()

void MIDITimedMessage::AddTime ( MIDIClockTime  t)
inline

Adds the given amount to the associated time.

◆ SubTime()

void MIDITimedMessage::SubTime ( MIDIClockTime  t)
inline

Subtracts the given amount from the associated time (if t is greater set the time to 0).

◆ SetNoOp()

void MIDITimedMessage::SetNoOp ( )
inline

The same of Clear(), makes the message an undefined message which will be ignored.

Friends And Related Function Documentation

◆ CompareEventsForInsert

int CompareEventsForInsert ( const MIDITimedMessage m1,
const MIDITimedMessage m2 
)
friend

Used by the MIDITrack::InsertEvent() and MIDITrack::InsertNote() methods for ordering events when inserting them in a MIDITrack.

It compares events m1 and m2; the following tests are done in sequence:

  • if m1 (or m2) is a NoOp it's larger
  • if m1 (or m2) has lesser MIDI time it's smaller (sorts for increasing time)
  • if m1 (or m2) is an EndOfTrack event it's larger
  • if m1 (or m2) is a Meta event it is smaller (Meta go before channel messages)
  • if m1 (or m2) is a SysEx it is larger (Sysex go after channel messages) // TODO: is this correct?
  • if m1 and m2 are both channel messages sort for ascending channel
  • if m1 (or m2) is not a note message it's smaller (non note go before notes)
  • if m1 (or m2) is a Note Off it's smaller (Note Off go before Note On)
Returns
1 if a < b , 2 if a > b, 0 if none of these (their order is indifferent)

◆ IsSameKind

bool IsSameKind ( const MIDITimedMessage m1,
const MIDITimedMessage m2 
)
friend

Used by methods that search and insert events in a MIDITrack to find events that are of the same kind and would normally be incompatible in the same track and at the same time.

It compares the events m1 and m2 and returns true if they have the same MIDI time and they are:

  • both NoOp
  • both Note On or Note Off with the same channel and the same note number
  • both Control Change with the same channel and the same control number
  • both channel messages (not notes or control) with the same channel and type
  • both MetaEvent with the same meta type
  • both non channel events (not Meta) with the same status

If the input mode is set to INSMODE_REPLACE or INSMODE_INSERT_OR_REPLACE the functions MIDITrack::InsertEvent and MIDITrack::InsertNote search if at same MIDI time of the event to insert exists such an event and, if they find it, they replace the event, rather than inserting it.

◆ operator==

bool operator== ( const MIDITimedMessage m1,
const MIDITimedMessage m2 
)
friend

The equal operator. It compares the messages bitwise.

Member Data Documentation

◆ time

MIDIClockTime MIDITimedMessage::time
protected

The time of the event.


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