resonance 1.0.1
Loading...
Searching...
No Matches
LevelConverter Class Reference

Converter that reads a Standard MIDI File and fills a LevelBuilder from its events. More...

#include <levelconverter.h>

Inheritance diagram for LevelConverter:
Collaboration diagram for LevelConverter:

Classes

struct  PendingEvent
 One note on waiting for its note off. More...
struct  Span
 One gem of a gem track, as the three span collections store it. More...

Public Member Functions

 LevelConverter ()
virtual ~LevelConverter ()
void Convert (const char *pszPath, void *pBuffer, int nLength, LevelBuilder *pBuilder)
 Read one Standard MIDI File and fill a builder from it.
virtual void NewTrack (unsigned char nTrack)
 Reset the per-track state and begin one track.
virtual void NoteOn (int nTick, unsigned char nNote, unsigned char nVelocity, unsigned char nChannel)
 Receive a note on and forward it under MIDI status 0x90.
virtual void NoteOff (int nTick, unsigned char nNote, unsigned char nChannel)
 Receive a note off and forward it under MIDI status 0x80.
virtual void Controller (int nTick, unsigned char nController, unsigned char nValue, unsigned char nChannel)
 Receive a controller change and forward it under MIDI status 0xb0.
virtual void ProgramChange (int nTick, unsigned char nProgram, unsigned char nChannel)
 Receive a program change and forward it under MIDI status 0xc0.
virtual void PitchBend (int nTick, unsigned char nLow, unsigned char nHigh, unsigned char nChannel)
 Receive a pitch bend and forward it under MIDI status 0xe0.
virtual void Tempo (int nTick, int nMicrosecondsPerQuarter)
 Hand a tempo meta event to the builder and record that the file has a tempo.
virtual void TextEvent (int nTick, const char *pText, unsigned char nType)
 Parse a track name, and ignore every other text event.
virtual void EndTrack ()
 Finish the track NewTrack() began.
Public Member Functions inherited from Mid::Receiver
virtual ~Receiver ()
virtual void AllDone ()
 Report that the whole file has been delivered.
virtual void UnusedFirstHook ()
 Do nothing.
virtual void UnusedSecondHook ()
 Do nothing.
virtual void UnusedThirdHook ()
 Do nothing.
virtual void UnusedFourthHook ()
 Do nothing.

Friends

class GrooveWorld

Detailed Description

Converter that reads a Standard MIDI File and fills a LevelBuilder from its events.

Its RTTI descriptor is at 0x008ef230. It has Mid::Receiver as its one base at offset 0. Its table is at 0x007e76b8 and has sixteen entries with a zero terminator at index 16, the same length as the base table. The class adds no virtual. It overrides slots 2 through 10 and inherits slots 11 through 15.

Slot 11 is worth stating separately. The derived table records 0x001ea360 where the base records 0x001ea2c0, and both are the same two instructions. This toolchain re-emits an inline empty body into every translation unit that needs one, so a unique address for an empty body is no evidence of an override. The slot is recorded as inherited and nothing is declared for it.

The object is at least 0xcc bytes, and several members are unrecovered. Every member whose purpose is undetermined retains its offset.

Convert() is the entry point. It stores the builder, extracts the file's base name into a global buffer at 0x00891a38, reads two display-configuration codes, builds three stack objects for the file, the byte stream, and the Standard MIDI File reader, hands itself to the reader as the event sink, and runs it. The three stack objects are an HxMemStream with HxStream::mSwapBytes set to 1, an HxIListChunk over the whole stream, and a Mid::Reader. The file-static comparator at 0x001e6450 is stored in Mid::Reader::mCompare before Mid::Reader::ReadAllTracks() runs. The comparator ranks each event by its status class (note off first, note on last).

The five event handlers all follow one shape. They report through ReportError() on the error paths, check the channel through CheckChannel(), and then forward to one of two sinks. With mRiffTrack clear the event goes to LevelBuilder::AddEvent(). With it set the event goes to Riff::AddMidiMsg() on mRiff instead, with the position rebased against mRiffStart and saturated to Sch::Tick's bounds.

Every method name below that is not a Mid::Receiver override is inferred from its body.

Constructor & Destructor Documentation

◆ LevelConverter()

LevelConverter::LevelConverter ( )
Ghidra address:
NTSC-U/C: 0x001e6278
Ghidra address:
PAL: 0x001ec410

◆ ~LevelConverter()

virtual LevelConverter::~LevelConverter ( )
virtual
Ghidra address:
NTSC-U/C: 0x001e9ee0
Ghidra address:
PAL: 0x001f0128

Member Function Documentation

◆ Convert()

void LevelConverter::Convert ( const char * pszPath,
void * pBuffer,
int nLength,
LevelBuilder * pBuilder )

Read one Standard MIDI File and fill a builder from it.

The error log path is the file's base name with .err appended. The file is read through an HxMemStream with byte swapping on, an HxIListChunk, and a Mid::Reader whose events of one position are ordered by status class (note off first, note on last). LevelBuilder::DoneLoading() and FinishErrorLog() run after the file is read.

Parameters
pszPathThe file to read.
pBufferThe file's contents, forwarded to the HxMemStream constructor. GrooveWorld::FinishLoad() passes the buffer its asynchronous read filled.
nLengthThe length of pBuffer in bytes, forwarded to the same object.
pBuilderThe builder the events are appended to.
Ghidra address:
NTSC-U/C: 0x001e65e0
Ghidra address:
PAL: 0x001ec7b0

◆ NewTrack()

virtual void LevelConverter::NewTrack ( unsigned char nTrack)
virtual

Reset the per-track state and begin one track.

The track type, the routing flags, the pending notes, the riff, the channel, the program, and the harmony all return to their unset values.

Parameters
nTrackThe track index.
Ghidra address:
NTSC-U/C: 0x001e6880
Ghidra address:
PAL: 0x001eca50

Reimplemented from Mid::Receiver.

◆ NoteOn()

virtual void LevelConverter::NoteOn ( int nTick,
unsigned char nNote,
unsigned char nVelocity,
unsigned char nChannel )
virtual

Receive a note on and forward it under MIDI status 0x90.

A harmony track adds the note to the harmony through AddHarmonyNote(). A track that pairs notes stores the note on in mPending instead of forwarding it.

Parameters
nTickThe event position, in MIDI ticks.
nNoteThe note number.
nVelocityThe velocity.
nChannelThe channel.
Ghidra address:
NTSC-U/C: 0x001e6fc0
Ghidra address:
PAL: 0x001ed190

Reimplemented from Mid::Receiver.

◆ NoteOff()

virtual void LevelConverter::NoteOff ( int nTick,
unsigned char nNote,
unsigned char nChannel )
virtual

Receive a note off and forward it under MIDI status 0x80.

A harmony track ignores it. A track that pairs notes hands the first pending note on with the same note to AddNote() with the duration between the two, and reports a note off with no partner. Otherwise the forwarded call passes zero where the note-on path passes a velocity.

Parameters
nTickThe event position, in MIDI ticks.
nNoteThe note number.
nChannelThe channel.
Ghidra address:
NTSC-U/C: 0x001e7188
Ghidra address:
PAL: 0x001ed358

Reimplemented from Mid::Receiver.

◆ Controller()

virtual void LevelConverter::Controller ( int nTick,
unsigned char nController,
unsigned char nValue,
unsigned char nChannel )
virtual

Receive a controller change and forward it under MIDI status 0xb0.

Harmony and gem-span tracks reject it. On a riff track, controller 0x66 sets the bar quantisation (1, 2, 4, 8, or 16) unless mIgnoreQuantization is set, controller 7 (volume) is rejected, and controller 0x6a forwards whether its value is non-zero through LevelBuilder::SetActive(). Controller 0x6a is rejected on every other track, and controllers 0x68, 0x69, 0x6b, and 11 (expression) are rejected everywhere.

Parameters
nTickThe event position, in MIDI ticks.
nControllerThe controller number.
nValueThe value.
nChannelThe channel.
Ghidra address:
NTSC-U/C: 0x001e7788
Ghidra address:
PAL: 0x001ed958

Reimplemented from Mid::Receiver.

◆ ProgramChange()

virtual void LevelConverter::ProgramChange ( int nTick,
unsigned char nProgram,
unsigned char nChannel )
virtual

Receive a program change and forward it under MIDI status 0xc0.

Harmony and gem-span tracks reject it. A riff track stores the program in mProgram and sends nothing, and EmitRiffProgram() sends it with each riff instead.

Parameters
nTickThe event position, in MIDI ticks.
nProgramThe program number.
nChannelThe channel.
Ghidra address:
NTSC-U/C: 0x001ea370
Ghidra address:
PAL: 0x001f05e0

Reimplemented from Mid::Receiver.

◆ PitchBend()

virtual void LevelConverter::PitchBend ( int nTick,
unsigned char nLow,
unsigned char nHigh,
unsigned char nChannel )
virtual

Receive a pitch bend and forward it under MIDI status 0xe0.

Harmony and gem-span tracks reject it. Otherwise it takes the shared shape.

Parameters
nTickThe event position, in MIDI ticks.
nLowThe low seven bits of the bend.
nHighThe high seven bits of the bend.
nChannelThe channel.
Ghidra address:
NTSC-U/C: 0x001ea420
Ghidra address:
PAL: 0x001f0690

Reimplemented from Mid::Receiver.

◆ Tempo()

virtual void LevelConverter::Tempo ( int nTick,
int nMicrosecondsPerQuarter )
virtual

Hand a tempo meta event to the builder and record that the file has a tempo.

Both parameters pass through to LevelBuilder::AddTempo() in the registers they arrive in.

Parameters
nTickThe event position, in MIDI ticks.
nMicrosecondsPerQuarterThe tempo.
Ghidra address:
NTSC-U/C: 0x001ea570
Ghidra address:
PAL: 0x001f07e0

Reimplemented from Mid::Receiver.

◆ TextEvent()

virtual void LevelConverter::TextEvent ( int nTick,
const char * pText,
unsigned char nType )
virtual

Parse a track name, and ignore every other text event.

A type other than 3 and a position other than 0 are both ignored, and 3 is the MIDI track-name meta type. The discarded Sch::Tick::IsInRange(0) ahead of the test is the shape of an assertion compiled without its report.

Parameters
nTickThe event position, in MIDI ticks.
pTextThe text.
nTypeThe meta type.
Ghidra address:
NTSC-U/C: 0x001ea5a0
Ghidra address:
PAL: 0x001f0810

Reimplemented from Mid::Receiver.

◆ EndTrack()

virtual void LevelConverter::EndTrack ( )
virtual

Finish the track NewTrack() began.

A harmony that was started goes to the builder. A riff track that opened no riff forwards two zeroes through LevelBuilder::SetActive(). An axe riff with no length and a note on with no note off are both reported, and otherwise a riff track empties the three span collections.

Ghidra address:
NTSC-U/C: 0x001e6a30
Ghidra address:
PAL: 0x001ecc00

Reimplemented from Mid::Receiver.

◆ GrooveWorld

friend class GrooveWorld
friend

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