Midi file parser.
More...
#include <midiplayerparser.h>
|
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...
|
|
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.
- 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.
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.
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.
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.
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.
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.
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.
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.
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 |
int MidiPlayerParser::mCursor |
|
private |
quint8 MidiPlayerParser::mLastMidiCommand |
|
private |
int MidiPlayerParser::mVerbosity |
|
private |
bool MidiPlayerParser::SMPTE |
|
private |
The documentation for this class was generated from the following files: