resonance 1.0.1
Loading...
Searching...
No Matches
Mid::Reader Class Reference

Standard MIDI File reader that delivers each event to a Mid::Receiver. More...

#include <reader.h>

Collaboration diagram for Mid::Reader:

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.

Detailed Description

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.

Member Typedef Documentation

◆ EventCompare

typedef bool(* Mid::Reader::EventCompare) (const Midi &left, const Midi &right)

Ordering mPending is sorted by.

The result is non-zero when the first event sorts first.

Constructor & Destructor Documentation

◆ Reader()

Mid::Reader::Reader ( HxIListChunk * pReader,
Receiver * pReceiver )

Build a reader over the chunks of a file.

Parameters
pReaderThe chunk reader positioned at the start of the file.
pReceiverThe sink for every event.
Ghidra address:
NTSC-U/C: 0x003d4a68
Ghidra address:
PAL: 0x0040c958

Member Function Documentation

◆ ReadAllTracks()

void Mid::Reader::ReadAllTracks ( )

Read every chunk of the file.

Ghidra address:
NTSC-U/C: 0x003d6528
Ghidra address:
PAL: 0x0040e418

◆ ReadChunk()

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.

Returns
Whether a chunk was read.
Ghidra address:
NTSC-U/C: 0x003d4ac8
Ghidra address:
PAL: 0x0040c9b8

◆ AllTracksRead()

void Mid::Reader::AllTracksRead ( )

Report the end of the file to the receiver's AllDone().

Ghidra address:
NTSC-U/C: 0x003d65a8
Ghidra address:
PAL: 0x0040e498

◆ ReadHeader()

void Mid::Reader::ReadHeader ( HxStream & stream)

Read the format, track count, and division of an MThd chunk.

Parameters
streamThe chunk payload.
Ghidra address:
NTSC-U/C: 0x003d6558
Ghidra address:
PAL: 0x0040e448

◆ ReadTrackChunk()

void Mid::Reader::ReadTrackChunk ( HxStream & stream)

Read one MTrk chunk when the file format has one track per chunk.

Parameters
streamThe chunk payload.
Ghidra address:
NTSC-U/C: 0x003d65d8
Ghidra address:
PAL: 0x0040e4c8

◆ ReadTrack()

void Mid::Reader::ReadTrack ( HxStream & stream)

Begin a track at the receiver and read its events until the end-of-track meta event.

Parameters
streamThe chunk payload.
Ghidra address:
NTSC-U/C: 0x003d6610
Ghidra address:
PAL: 0x0040e500

◆ ReadEvent()

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.

Parameters
streamThe chunk payload.
Ghidra address:
NTSC-U/C: 0x003d4c10
Ghidra address:
PAL: 0x0040cb00

◆ ReadSystemEvent()

void Mid::Reader::ReadSystemEvent ( HxStream & stream)

Skip a system-exclusive event or read a meta event, depending on mRunningStatus.

Parameters
streamThe chunk payload, positioned after the status byte.
Ghidra address:
NTSC-U/C: 0x003d4df0
Ghidra address:
PAL: 0x0040cce0

◆ ReadMeta()

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.

Parameters
nTypeThe meta type.
streamThe chunk payload, positioned at the length.
Ghidra address:
NTSC-U/C: 0x003d4f00
Ghidra address:
PAL: 0x0040cdf0

◆ SendChannelMsg()

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.

Parameters
tickThe position.
nStatusThe status byte.
nData1The first data byte.
nData2The second data byte.
Ghidra address:
NTSC-U/C: 0x003d5260
Ghidra address:
PAL: 0x0040d150

◆ QueueEvent()

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.

Parameters
tickThe position.
nStatusThe status byte.
nData1The first data byte.
nData2The second data byte.
Ghidra address:
NTSC-U/C: 0x003d66a8
Ghidra address:
PAL: 0x0040e598

◆ Flush()

void Mid::Reader::Flush ( )

Sort mPending with mCompare, deliver every event at mPendingTick, and empty it.

Ghidra address:
NTSC-U/C: 0x003d5140
Ghidra address:
PAL: 0x0040d030

Member Data Documentation

◆ kTargetDivision

short Mid::Reader::kTargetDivision = 480
staticconstexpr

Ticks per quarter note of every position delivered to the receiver.

◆ mFormat

short Mid::Reader::mFormat

The file format, or -1 before the header.

◆ mTrackCount

short Mid::Reader::mTrackCount

The track count from the header.

◆ mDivision

short Mid::Reader::mDivision

The file's ticks per quarter note.

◆ mTargetDivision

short Mid::Reader::mTargetDivision

Always kTargetDivision.

◆ mTrack

int Mid::Reader::mTrack

Index of the track being read.

◆ mReceiver

Receiver* Mid::Reader::mReceiver

The event sink.

◆ mTick

int Mid::Reader::mTick

Position in file ticks within the track.

◆ mRunningStatus

unsigned char Mid::Reader::mRunningStatus

The last status byte, or 0 after a system event.

◆ mTrackDone

int Mid::Reader::mTrackDone

Non-zero once the end-of-track event is read.

◆ mReader

HxIListChunk* Mid::Reader::mReader

The chunk reader over the file.

◆ mPending

std::vector<Midi> Mid::Reader::mPending

Events collected at mPendingTick.

◆ mPendingTick

Sch::Tick Mid::Reader::mPendingTick

Position of every event in mPending.

◆ mCompare

EventCompare Mid::Reader::mCompare

Ordering for mPending, or null to deliver directly.


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