|
resonance 1.0.1
|
Standard MIDI File reader that delivers each event to a Mid::Receiver. More...
#include <reader.h>

Classes | |
| struct | Midi |
| One channel event waiting in mPending. More... | |
Public Types | |
| typedef bool(* | EventCompare) (const Midi &left, const Midi &right) |
| Ordering mPending is sorted by. | |
Public Member Functions | |
| Reader (HxIListChunk *pReader, Receiver *pReceiver) | |
| Build a reader over the chunks of a file. | |
| void | ReadAllTracks () |
| Read every chunk of the file. | |
| bool | ReadChunk () |
| Read the next chunk. | |
| void | AllTracksRead () |
| Report the end of the file to the receiver's AllDone(). | |
| void | ReadHeader (HxStream &stream) |
| Read the format, track count, and division of an MThd chunk. | |
| void | ReadTrackChunk (HxStream &stream) |
| Read one MTrk chunk when the file format has one track per chunk. | |
| void | ReadTrack (HxStream &stream) |
| Begin a track at the receiver and read its events until the end-of-track meta event. | |
| void | ReadEvent (HxStream &stream) |
| Read one delta time and event. | |
| void | ReadSystemEvent (HxStream &stream) |
| Skip a system-exclusive event or read a meta event, depending on mRunningStatus. | |
| void | ReadMeta (unsigned char nType, HxStream &stream) |
| Read one meta event and deliver end of track, tempo, and the seven text types. | |
| void | SendChannelMsg (Sch::Tick tick, unsigned char nStatus, unsigned char nData1, unsigned char nData2) |
| Deliver one channel event to the receiver slot its status selects. | |
| void | QueueEvent (Sch::Tick tick, unsigned char nStatus, unsigned char nData1, unsigned char nData2) |
| Deliver a channel event, or collect it in mPending when mCompare is set. | |
| void | Flush () |
| Sort mPending with mCompare, deliver every event at mPendingTick, and empty it. | |
Public Attributes | |
| short | mFormat |
| short | mTrackCount |
| short | mDivision |
| short | mTargetDivision |
| int | mTrack |
| Receiver * | mReceiver |
| int | mTick |
| unsigned char | mRunningStatus |
| int | mTrackDone |
| HxIListChunk * | mReader |
| std::vector< Midi > | mPending |
| Sch::Tick | mPendingTick |
| EventCompare | mCompare |
Static Public Attributes | |
| static constexpr short | kTargetDivision = 480 |
| Ticks per quarter note of every position delivered to the receiver. | |
Standard MIDI File reader that delivers each event to a Mid::Receiver.
The class is not polymorphic and has no RTTI. Its name comes from the debugging symbols of the North American demo release. LevelConverter::Convert() is the one user. It builds the reader on the stack over an HxIListChunk, sets mCompare, and calls ReadAllTracks().
Event positions are rescaled from the file's division to kTargetDivision ticks per quarter note. With mCompare unset, every channel event goes straight to the receiver. With mCompare set, the reader collects the channel events of one position in mPending, sorts them with mCompare when the position changes or the track ends, and then delivers them in sorted order.
Only format 1 and format 2 files have their tracks read. A format 0 file delivers no event.
The destructor at 0x003d6450 is compiler-generated and destroys mPending. The uncalled routines at 0x003d6798 and 0x003d67f0 in the same unit are the constructor and Print() of the unused class that the image's Mid::MBT descriptor identifies, recorded on Sch::Tick in mid/tick.h.
Every member is public, because LevelConverter stores mCompare directly and the image exposes no accessor.
Ordering mPending is sorted by.
The result is non-zero when the first event sorts first.
| Mid::Reader::Reader | ( | HxIListChunk * | pReader, |
| Receiver * | pReceiver ) |
Build a reader over the chunks of a file.
| pReader | The chunk reader positioned at the start of the file. |
| pReceiver | The sink for every event. |
| void Mid::Reader::ReadAllTracks | ( | ) |
Read every chunk of the file.
| bool Mid::Reader::ReadChunk | ( | ) |
Read the next chunk.
An MThd chunk fills the header fields and an MTrk chunk is read as a track. A chunk with any other name is skipped. At the end of the file AllTracksRead() is called.
| void Mid::Reader::AllTracksRead | ( | ) |
Report the end of the file to the receiver's AllDone().
| void Mid::Reader::ReadHeader | ( | HxStream & | stream | ) |
Read the format, track count, and division of an MThd chunk.
| stream | The chunk payload. |
| void Mid::Reader::ReadTrackChunk | ( | HxStream & | stream | ) |
Read one MTrk chunk when the file format has one track per chunk.
| stream | The chunk payload. |
| void Mid::Reader::ReadTrack | ( | HxStream & | stream | ) |
Begin a track at the receiver and read its events until the end-of-track meta event.
| stream | The chunk payload. |
| void Mid::Reader::ReadEvent | ( | HxStream & | stream | ) |
Read one delta time and event.
A data byte in the status position repeats the running status. A note on with a velocity of 0 becomes a note off.
| stream | The chunk payload. |
| void Mid::Reader::ReadSystemEvent | ( | HxStream & | stream | ) |
Skip a system-exclusive event or read a meta event, depending on mRunningStatus.
| stream | The chunk payload, positioned after the status byte. |
| void Mid::Reader::ReadMeta | ( | unsigned char | nType, |
| HxStream & | stream ) |
Read one meta event and deliver end of track, tempo, and the seven text types.
The stream is left after the event's data whatever the type.
| nType | The meta type. |
| stream | The chunk payload, positioned at the length. |
| void Mid::Reader::SendChannelMsg | ( | Sch::Tick | tick, |
| unsigned char | nStatus, | ||
| unsigned char | nData1, | ||
| unsigned char | nData2 ) |
Deliver one channel event to the receiver slot its status selects.
Polyphonic and channel pressure are dropped.
| tick | The position. |
| nStatus | The status byte. |
| nData1 | The first data byte. |
| nData2 | The second data byte. |
| void Mid::Reader::QueueEvent | ( | Sch::Tick | tick, |
| unsigned char | nStatus, | ||
| unsigned char | nData1, | ||
| unsigned char | nData2 ) |
Deliver a channel event, or collect it in mPending when mCompare is set.
A position different from mPendingTick flushes mPending first.
| tick | The position. |
| nStatus | The status byte. |
| nData1 | The first data byte. |
| nData2 | The second data byte. |
| void Mid::Reader::Flush | ( | ) |
Sort mPending with mCompare, deliver every event at mPendingTick, and empty it.
|
staticconstexpr |
Ticks per quarter note of every position delivered to the receiver.
| short Mid::Reader::mFormat |
The file format, or -1 before the header.
| short Mid::Reader::mTrackCount |
The track count from the header.
| short Mid::Reader::mDivision |
The file's ticks per quarter note.
| short Mid::Reader::mTargetDivision |
Always kTargetDivision.
| int Mid::Reader::mTrack |
Index of the track being read.
| Receiver* Mid::Reader::mReceiver |
The event sink.
| int Mid::Reader::mTick |
Position in file ticks within the track.
| unsigned char Mid::Reader::mRunningStatus |
The last status byte, or 0 after a system event.
| int Mid::Reader::mTrackDone |
Non-zero once the end-of-track event is read.
| HxIListChunk* Mid::Reader::mReader |
The chunk reader over the file.
| std::vector<Midi> Mid::Reader::mPending |
Events collected at mPendingTick.
| Sch::Tick Mid::Reader::mPendingTick |
Position of every event in mPending.
| EventCompare Mid::Reader::mCompare |
Ordering for mPending, or null to deliver directly.