Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
MidiPlayerParser Class Reference

Midi file parser. More...

#include <midiplayerparser.h>

Inheritance diagram for MidiPlayerParser:
Inheritance graph
Collaboration diagram for MidiPlayerParser:
Collaboration graph

Public Member Functions

 MidiPlayerParser (MidiPlayer *player, MidiPlayerEventList *eventlist, int verbosity=0)
 Constructor. More...
 
bool parse (QByteArray &data)
 Parse a Midi file and store it in the EventList. More...
 

Private Member Functions

int findNextChunk (QByteArray &data, QString tag)
 Find the next chunk tag. More...
 
quint32 parseInt32 (QByteArray &data)
 Parse a 32-bit (4-byte) integer and advance the cursor. More...
 
quint16 parseInt16 (QByteArray &data)
 Parse a 16bit (2-byte) integer and advance the cursor. More...
 
quint32 parseVariableLengthNumber (QByteArray &data)
 Parse a variable-length integer. More...
 
bool parseTrack (QByteArray &data, int length, quint8 track)
 Parse an entire track. More...
 
bool parseEvent (QByteArray &data, quint8 track, quint32 delta, double cumulativeDelta)
 Parse a single event In the Midi specifications three types of events are defined, namely, ordinary Midi events, sysex events, and meta events. This function detects the event type and takes action accordingly. More...
 
bool parseMetaEvent (QByteArray &data, quint8 track, double cumulativeDelta)
 Parse a meta event and display info in qDebug. More...
 
void reportError (QString msg) const
 Report an error back to MidiPlayer. More...
 

Private Attributes

MidiPlayerpMidiPlayer
 Pointer back to the MidiPlayer. More...
 
MidiPlayerEventListpEventList
 Pointer to event list held by MidiPlayer. More...
 
int mCursor
 Cursor from where the events are being played. More...
 
bool SMPTE
 Flag indicating the time format. More...
 
quint8 mLastMidiCommand
 Variable storing the last Midi command. More...
 
int mVerbosity
 Level of verbosity of qDebug() messages. More...
 

Detailed Description

Midi file parser.

This function parses a Midi file sequentially. The specifications can be found e.g. in https://www.midi.org/specifications. The external user only has to call the constructor, passing a pointer to the event list in which the Midi events are supposed to be stored. Then call 'parse' with the file content of the Midi file stored in a QByteArray. The function then parses the Midi file and stores the events in the event list without distinguishing the tracks.

Definition at line 45 of file midiplayerparser.h.

Constructor & Destructor Documentation

MidiPlayerParser::MidiPlayerParser ( MidiPlayer player,
MidiPlayerEventList eventlist,
int  verbosity = 0 
)

Constructor.

Parameters
player: Pointer back to the MidiPlayer
eventlist: Pointer to the list of events
verbosity: Level of verbosity for qDebug messages

Definition at line 42 of file midiplayerparser.cpp.

Member Function Documentation

int MidiPlayerParser::findNextChunk ( QByteArray &  data,
QString  tag 
)
private

Find the next chunk tag.

Midi files are orginized in terms of 'chunks'. Each chunk starts with a 4-letter ASCII tag, e.g. "MThd" or "MTrk". This function looks for such a tag starting at the current cursor position, moves the cursor to the starting point of the chunk data and returns the length of the chunk data block if successful.

Parameters
data: Reference QByteArray holding the file content
tag: Four-letter ASCII tag
Returns
: length of the data chunk, 0 if not found

Definition at line 146 of file midiplayerparser.cpp.

Here is the call graph for this function:

bool MidiPlayerParser::parse ( QByteArray &  data)

Parse a Midi file and store it in the EventList.

This is the main public function of the class which is called from the MidiPlayer. The file has already been read and is now assumed to be stored in a QByteArray (Midi files are usually very short so that this is no problem). The function then parses the content of the file, looking for headers and chunks. The keystrokes of all tracks are merged and mapped to a single event list (a pointer to which was passed in the constructor).

Parameters
data: Reference to QByteArray holding the file content.
Returns
True if parsing process was successful.

Definition at line 71 of file midiplayerparser.cpp.

Here is the call graph for this function:

bool MidiPlayerParser::parseEvent ( QByteArray &  data,
quint8  track,
quint32  delta,
double  cumulativeDelta 
)
private

Parse a single event In the Midi specifications three types of events are defined, namely, ordinary Midi events, sysex events, and meta events. This function detects the event type and takes action accordingly.

Parameters
data: Reference QByteArray holding the file content
track: The track number
delta: Value of delta preceding the actual event.
cumulativeDelta: Sum of all preceding deltas
Returns
True if successful

Definition at line 286 of file midiplayerparser.cpp.

Here is the call graph for this function:

quint16 MidiPlayerParser::parseInt16 ( QByteArray &  data)
private

Parse a 16bit (2-byte) integer and advance the cursor.

Parameters
data: Reference QByteArray holding the file content
Returns
Value of the integer

Definition at line 194 of file midiplayerparser.cpp.

Here is the call graph for this function:

quint32 MidiPlayerParser::parseInt32 ( QByteArray &  data)
private

Parse a 32-bit (4-byte) integer and advance the cursor.

Parameters
data: Reference QByteArray holding the file content
Returns
Value of the integer

Definition at line 170 of file midiplayerparser.cpp.

Here is the call graph for this function:

bool MidiPlayerParser::parseMetaEvent ( QByteArray &  data,
quint8  track,
double  cumulativeDelta 
)
private

Parse a meta event and display info in qDebug.

Parameters
data: Reference QByteArray holding the file content
track: Midi track number
cumulativeDelta: Cumulative delta time parameter
Returns
True if successful

Definition at line 364 of file midiplayerparser.cpp.

Here is the call graph for this function:

bool MidiPlayerParser::parseTrack ( QByteArray &  data,
int  length,
quint8  track 
)
private

Parse an entire track.

A track consists of a variable-length integer holding the time elapsed since the last event, followed by an event (see parseEvent(...)). This function reads these pairs subsequently until the expected length has been read.

Parameters
data: Reference QByteArray holding the file content
length: Expected length of the track
track: The track number
Returns
: True if successfull

Definition at line 252 of file midiplayerparser.cpp.

Here is the call graph for this function:

quint32 MidiPlayerParser::parseVariableLengthNumber ( QByteArray &  data)
private

Parse a variable-length integer.

The Midi specifications involve the use of so-called variable length integers. In these integers the MSB of each byte is used to indicate whether another byte will follow. This allows Midi files to save space since most of the time intervals are very short. The actual range of integers is in practice limited to 32 bit.

Parameters
data: Reference QByteArray holding the file content
Returns
: Value of the integer

Definition at line 221 of file midiplayerparser.cpp.

void MidiPlayerParser::reportError ( QString  msg) const
private

Report an error back to MidiPlayer.

Parameters
msg: Error message string

Definition at line 415 of file midiplayerparser.cpp.

Here is the call graph for this function:

Member Data Documentation

int MidiPlayerParser::mCursor
private

Cursor from where the events are being played.

Definition at line 65 of file midiplayerparser.h.

quint8 MidiPlayerParser::mLastMidiCommand
private

Variable storing the last Midi command.

Definition at line 67 of file midiplayerparser.h.

int MidiPlayerParser::mVerbosity
private

Level of verbosity of qDebug() messages.

Definition at line 68 of file midiplayerparser.h.

MidiPlayerEventList* MidiPlayerParser::pEventList
private

Pointer to event list held by MidiPlayer.

Definition at line 64 of file midiplayerparser.h.

MidiPlayer* MidiPlayerParser::pMidiPlayer
private

Pointer back to the MidiPlayer.

Definition at line 63 of file midiplayerparser.h.

bool MidiPlayerParser::SMPTE
private

Flag indicating the time format.

Definition at line 66 of file midiplayerparser.h.


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