wavelength 1.0.0
Loading...
Searching...
No Matches
MidiReader Class Reference

Reader of a Standard MIDI File that reports each track and event to a MidiReceiver. More...

#include <midireader.h>

Classes

struct  Midi
 One channel event waiting in mPending. More...
struct  ChunkName
 The four-character name of a chunk. More...
struct  VarLen
 A variable-length quantity, read seven bits a byte from the most significant. More...

Public Types

enum  State { kStateHeader = 0 , kStateTrackStart = 1 , kStateEvent = 2 , kStateDone = 3 }
 Values of mState. More...
using Compare = bool (*)(const Midi &left, const Midi &right)
 Ordering of mPending.

Public Member Functions

 MidiReader (const char *pszFile, MidiReceiver *pReceiver)
 Open a MIDI file.
 MidiReader (char *pBuffer, int nSize, MidiReceiver *pReceiver)
 Read a MIDI file from memory.
 ~MidiReader ()
 Close the stream.
void ReadAll ()
 Read the whole file.
bool ReadTrack ()
 Read up to the end of the next track.
bool ReadSteps (int nSteps)
 Take a number of steps.
bool ReadFor (float fMs)
 Take steps until a time has passed.

Static Public Member Functions

static bool CompareMidi (const Midi &left, const Midi &right)
 Order channel events so note offs come first, then controllers, programs, channel pressure, pitch bends, key pressure, and note ons, and any other message last.

Detailed Description

Reader of a Standard MIDI File that reports each track and event to a MidiReceiver.

The class is not polymorphic and has no RTTI. The name is inferred. The reader advances one step at a time: the header, the start of a track, or one event. Event positions are rescaled from the division of the file to 480 ticks per quarter note. The channel events of one position are collected and sorted with mCompare before they are reported.

Member Typedef Documentation

◆ Compare

using MidiReader::Compare = bool (*)(const Midi &left, const Midi &right)

Ordering of mPending.

The result is true when the first event sorts first.

Member Enumeration Documentation

◆ State

Values of mState.

Enumerator
kStateHeader 

The header is next.

kStateTrackStart 

The start of a track is next.

kStateEvent 

An event of the current track is next.

kStateDone 

The file is read.

Constructor & Destructor Documentation

◆ MidiReader() [1/2]

MidiReader::MidiReader ( const char * pszFile,
MidiReceiver * pReceiver )

Open a MIDI file.

Parameters
pszFileThe file.
pReceiverThe receiver of the tracks and events.
Ghidra address:
NTSC-U/C: 0x00158fa8
Ghidra address:
PAL: 0x0015a830

◆ MidiReader() [2/2]

MidiReader::MidiReader ( char * pBuffer,
int nSize,
MidiReceiver * pReceiver )

Read a MIDI file from memory.

Parameters
pBufferThe contents of the file. The caller retains them.
nSizeThe size of the contents in bytes.
pReceiverThe receiver of the tracks and events.
Ghidra address:
NTSC-U/C: 0x00159048
Ghidra address:
PAL: 0x0015a8d0

◆ ~MidiReader()

MidiReader::~MidiReader ( )

Close the stream.

Ghidra address:
NTSC-U/C: 0x001590f0
Ghidra address:
PAL: 0x0015a978

Member Function Documentation

◆ CompareMidi()

bool MidiReader::CompareMidi ( const Midi & left,
const Midi & right )
static

Order channel events so note offs come first, then controllers, programs, channel pressure, pitch bends, key pressure, and note ons, and any other message last.

Parameters
leftThe first event.
rightThe second event.
Returns
Whether the first event sorts first.
Ghidra address:
NTSC-U/C: 0x00158e50
Ghidra address:
PAL: 0x0015a6d8

◆ ReadAll()

void MidiReader::ReadAll ( )

Read the whole file.

Ghidra address:
NTSC-U/C: 0x00159198
Ghidra address:
PAL: 0x0015aa20

◆ ReadTrack()

bool MidiReader::ReadTrack ( )

Read up to the end of the next track.

Returns
Whether a track ended, and false at the end of the file.
Ghidra address:
NTSC-U/C: 0x001591d0
Ghidra address:
PAL: 0x0015aa58

◆ ReadSteps()

bool MidiReader::ReadSteps ( int nSteps)

Take a number of steps.

Parameters
nStepsThe number of steps.
Returns
Whether the file is not yet read.
Ghidra address:
NTSC-U/C: 0x00159228
Ghidra address:
PAL: 0x0015aab0

◆ ReadFor()

bool MidiReader::ReadFor ( float fMs)

Take steps until a time has passed.

Parameters
fMsThe time in milliseconds.
Returns
Whether the file is not yet read.
Ghidra address:
NTSC-U/C: 0x001592a0
Ghidra address:
PAL: 0x0015ab28

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