MidiMsg
A MidiMsg contains information about a single MIDI message.
class MidiMsg {
public:
enum
{
note_off = 0,
note_on = 1,
poly_press = 2,
control_chn = 3,
program_chn = 4,
chan_press = 5,
pitch_bend = 6,
system = 7
};
long time;
uchar s, d1, d2;
ext_dataPtr ed;
static int msgt( uchar sb );
static int smsgt( uchar sb );
static int note_num(const char* name);
MidiMsg();
MidiMsg(const MidiMsg& m);
int msgt() const;
int smsgt() const;
int chan() const;
int dat14() const;
int bend() const;
int key() const;
int vel() const;
int len() const;
bool is_note_end() const;
bool is_ext() const;
void set_bend( float v );
void set_stat_byt( int msgt, int lsn );
void set_data14( int v );
void set_chan(int c);
void set_key(int k);
void set_key(const char* k);
void set_vel(int v);
void set_sys_ex( uchar *r, long len );
void set_meta( int meta_type, uchar *r, long len );
void sprint( char *s ) const;
UtilStringPtr unparse() const;
bool operator==(const MidiMsg& m) const;
MidiMsg& operator=(const MidiMsg& m);
};
long time
- This member is used to store various time information. The
filereader stores the time here in units of ticks, the ScorePlayer
stores the time here in units of ScoreTime, and parsers receieve MIDI
messages stamped with time in units of ScheduleTime.
uchar s, d1, d2
- These three bytes represent the three bytes that actually make up
the MIDI message when it is sent over the MIDI protocol.
ext_dataPtr ed
- Additional data for System Exclusive and Meta messages is stored
in
ed.
static int msgt( uchar sb )
msgt(sb) returns the basic MIDI message type as stored in the
high nibble of sb. The basic MIDI message types appear as
enumerated constants within MidiMsg.
static int smsgt( uchar sb )
smsgt(sb)
returns the system message type as stored in the low nibble of
sb. The MIDI system message types appear as enumerated
constants in the smsgt class. Note that smsgt() is
only applicable to system messages (i.e. those for which
msgt(sb)==system).
static int note_num(const char* name)
- This function interprets its argument as the name of a note. For
example, "C4" is middle C (MIDI note 60), "B3" is
the note below middle C (MIDI note 59), "C#4" is a half-step
above middle C (MIDI note 61), and "C5" is the note an
octave above middle C (MIDI note 72). Sharps
#, flats
b, double sharps ##, and double flats
bb are all supported. note_num() returns the
MIDI note number if successful, or -1 if its argument cannot be parsed
as a valid note name.
MidiMsg()
- This constructor creates a MidiMsg. All members are initialized to
zero. Note that this means that the inital value of a MidiMsg is not a
valid MIDI message, since a valid MIDI message must have the high bit
of the status byte set.
MidiMsg(const MidiMsg& m)
- This constructor creates a new MidiMsg which is set equal to
m. Note that if m is an extended message, the
ed member of the new MidiMsg points to the same
ext_data as the ed member of
m, so a change to the contents of one's extended data
will affect the other.
int msgt() const
msgt() returns the basic MIDI message type as stored in the
high nibble of the status byte. The basic MIDI message types appear as
enumerated constants within MidiMsg.
int smsgt() const
smsgt()
returns the system message type as stored in the low nibble of the
status byte. The MIDI system message types appear as enumerated
constants in the smsgt class. Note that smsgt() is
only applicable to system messages (i.e. those for which
msgt()==system).
int chan() const
chan() returns the channel as
stored in the low nibble of the status byte. Note that this function
is only applicable to channel messages (i.e. those for which
msgt()!=system).
int dat14() const
dat14() returns the interpretation
of the data bytes as an unsigned14-bit integer.
int bend() const
bend()
returns the interpretation of the data bytes as a signed 14-bit
integer.
int key() const
key() returns the key number (applicable to note on
or note off messages only).
int vel() const
vel()
returns the velocity (applicable to note on or note off messages only).
int len() const
len() returns the length of the entire MIDI message.
bool is_note_end() const
is_note_end() tells whether theMidiMsg is a note
end. But what, you may ask, is a note end? Here I seek to introduce
an unambiguous vocabulary to deal with the somewhat confusing issue of
the representation of notes in MIDI. There are two ways to end a
note in MIDI: a note off message with any release velocity or a note on
message with a velocity of zero. I introduce the term "note end" to
refer to either of these types of messages.
bool is_ext() const
is_ext()tells whether the message
contains extended data, i.e. whether theext_data pointer
ed is non-NULL.
void set_bend( float v )
set_bend() sets the object's data bytes as if they were for a
pitch bend, but allows the amount of bend to be specified as a float in
[-1.0 ...1.0] which may be more convenient than as an integer. This
function will never produce the maximum negative pitch bend, 0x0000
(interpreted as -8192) since it scales symmetrically about zero and
the maximum positive pitch bend is only 0xF7F7 (interpreted as 8191).
Note that this function only manipulates the two data bytes, i.e. if
the status byte doesn't already indicate a pitch bend it needs to be
separately set to do so.
void set_stat_byt( int msgt, int lsn )
set_stat_byt() sets the object's status byte to contain
message typemsgt and least significant nibble lsn.
For channel messages,the least significant nibble is the channel and
for system messages, it is the system message type.
void set_data14( int v )
set_data14() sets the object's data bytes to
contain the 14-bit unsigned integer passed to it.
void set_chan(int c)
set_chan() sets the least significant nibble of the
MidiMsg's status byte to c.
void set_key(int k)
set_key() sets the first data byte of the MidiMsg to k.
void set_key(const char* k)
- This version of
set_key sets the first data byte of
the MidiMsg to the MIDI note number of the note named k.
The translation is performed using note_num(), and if
k is an invalid note name then the note is set to middle C.
void set_vel(int v)
set_vel() sets the second data byte of the MidiMsg to v.
void set_sys_ex( uchar *r, long len )
set_sys_ex() is used to set the extended data in a
MidiMsg. r is a pointer to the raw data and
len is the length of this data. Implementation Note: extended
data is implemented by stealing an undefined system message type (see
smsgt::ext) to flag that an extended message is pointed to by
ed.
void set_meta( int meta_type, uchar *r, long len )
set_meta() is used to set the extended data in a
MidiMsg. r is a pointer to the raw data,
len is the length of this data, and
meta_type is the type of metamessage. Meta message types are
enumerated in the class meta. Implementation Note: extended
data is implemented by stealing an undefined system message type (see
smsgt::ext) to flag that an extended message is pointed to by
ed.
void sprint( char *s ) const
sprint() puts a textual representation of the
MidiMsg into the string pointed to by s.
UtilStringPtr unparse() const
- Because
sprint() has the disadvantage that you
don't know how long of a buffer you will need to store the string,
unparse() is provided to eliminate this problem. It
returns the same string as sprint, but returns it as a
UtilPtr to a UtilString.
bool operator==(const MidiMsg& m) const
- Returns true if m is equal to this MidiMsg, and false if it is not.
MidiMsg& operator=(const MidiMsg& m)
- Sets this MidiMsg equal to m.
Modified 17 January 1996 pepellet@mit.edu