AUDIO: Move MIDI parser source handling to superclass

This commit moves the source handling from the SMF and XMIDI parsers to the
MIDI parser superclass. This reduces code duplication.
This commit is contained in:
Coen Rampen 2022-04-19 22:22:07 +02:00
parent 6a9fc73962
commit 32ba866499
5 changed files with 25 additions and 61 deletions

View File

@ -30,7 +30,8 @@
//
//////////////////////////////////////////////////
MidiParser::MidiParser() :
MidiParser::MidiParser(int8 source) :
_source(source),
_hangingNotesCount(0),
_driver(nullptr),
_timerRate(0x4A0000),
@ -84,11 +85,19 @@ void MidiParser::property(int prop, int value) {
}
void MidiParser::sendToDriver(uint32 b) {
_driver->send(b);
if (_source < 0) {
_driver->send(b);
} else {
_driver->send(_source, b);
}
}
void MidiParser::sendMetaEventToDriver(byte type, byte *data, uint16 length) {
_driver->metaEvent(type, data, length);
if (_source < 0) {
_driver->metaEvent(type, data, length);
} else {
_driver->metaEvent(_source, type, data, length);
}
}
void MidiParser::setTempo(uint32 tempo) {
@ -186,7 +195,7 @@ void MidiParser::onTimer() {
// even if the parser does not parse events.
_sysExDelay -= (_sysExDelay > _timerRate) ? _timerRate : _sysExDelay;
if (!_position._playPos || !_driver || !_doParse || _pause || !_driver->isReady())
if (!_position._playPos || !_driver || !_doParse || _pause || !_driver->isReady(_source))
return;
_abortParse = false;

View File

@ -320,6 +320,15 @@ protected:
bool _doParse; ///< True if the parser should be parsing; false if it should not be active
bool _pause; ///< True if the parser has paused parsing
/**
* The source number to use when sending MIDI messages to the driver.
* When using multiple sources, use source 0 and higher. This must be
* used when source volume or channel locking is used.
* By default this is -1, which means the parser is the only source
* of MIDI messages and multiple source functionality is disabled.
*/
int8 _source;
protected:
static uint32 readVLQ(byte * &data);
virtual void resetTracking();
@ -427,7 +436,7 @@ public:
public:
typedef void (*XMidiCallbackProc)(byte eventData, void *refCon);
MidiParser();
MidiParser(int8 source = -1);
virtual ~MidiParser() { stopPlaying(); }
virtual bool loadMusic(byte *data, uint32 size) = 0;

View File

@ -396,20 +396,4 @@ uint32 MidiParser_SMF::compressToType0(byte *tracks[], byte numTracks, byte *buf
return output - buffer;
}
void MidiParser_SMF::sendToDriver(uint32 b) {
if (_source < 0) {
MidiParser::sendToDriver(b);
} else {
_driver->send(_source, b);
}
}
void MidiParser_SMF::sendMetaEventToDriver(byte type, byte *data, uint16 length) {
if (_source < 0) {
MidiParser::sendMetaEventToDriver(type, data, length);
} else {
_driver->metaEvent(_source, type, data, length);
}
}
MidiParser *MidiParser::createParser_SMF(int8 source) { return new MidiParser_SMF(source); }

View File

@ -31,14 +31,6 @@ class MidiParser_SMF : public MidiParser {
protected:
byte *_buffer;
bool _malformedPitchBends;
/**
* The source number to use when sending MIDI messages to the driver.
* When using multiple sources, use source 0 and higher. This must be
* used when source volume or channel locking is used.
* By default this is -1, which means the parser is the only source
* of MIDI messages and multiple source functionality is disabled.
*/
int8 _source;
protected:
/**
@ -55,11 +47,8 @@ protected:
uint32 compressToType0(byte *tracks[], byte numTracks, byte *buffer, bool malformedPitchBends = false);
void parseNextEvent(EventInfo &info) override;
void sendToDriver(uint32 b) override;
void sendMetaEventToDriver(byte type, byte *data, uint16 length) override;
public:
MidiParser_SMF(int8 source = -1) : _buffer(nullptr), _malformedPitchBends(false), _source(source) {}
MidiParser_SMF(int8 source = -1) : MidiParser(source), _buffer(nullptr), _malformedPitchBends(false) {}
~MidiParser_SMF();
bool loadMusic(byte *data, uint32 size) override;

View File

@ -43,14 +43,6 @@ protected:
Loop _loop[4];
int _loopCount;
/**
* The source number to use when sending MIDI messages to the driver.
* When using multiple sources, use source 0 and higher. This must be
* used when source volume or channel locking is used.
* By default this is -1, which means the parser is the only source
* of MIDI messages and multiple source functionality is disabled.
*/
int8 _source;
/**
* The sequence branches defined for each track. These point to
* positions in the MIDI data.
@ -87,15 +79,12 @@ protected:
_loopCount = -1;
}
void onTrackStart(uint8 track) override;
void sendToDriver(uint32 b) override;
void sendMetaEventToDriver(byte type, byte *data, uint16 length) override;
public:
MidiParser_XMIDI(XMidiCallbackProc proc, void *data, int8 source = -1) :
MidiParser(source),
_callbackProc(proc),
_callbackData(data),
_newTimbreListDriver(nullptr),
_source(source),
_loopCount(-1) {
memset(_loop, 0, sizeof(_loop));
memset(_trackBranches, 0, sizeof(_trackBranches));
@ -572,22 +561,6 @@ void MidiParser_XMIDI::onTrackStart(uint8 track) {
_newTimbreListDriver->processXMIDITimbreChunk(_tracksTimbreList[track], _tracksTimbreListSize[track]);
}
void MidiParser_XMIDI::sendToDriver(uint32 b) {
if (_source < 0) {
MidiParser::sendToDriver(b);
} else {
_driver->send(_source, b);
}
}
void MidiParser_XMIDI::sendMetaEventToDriver(byte type, byte *data, uint16 length) {
if (_source < 0) {
MidiParser::sendMetaEventToDriver(type, data, length);
} else {
_driver->metaEvent(_source, type, data, length);
}
}
void MidiParser::defaultXMidiCallback(byte eventData, void *data) {
warning("MidiParser: defaultXMidiCallback(%d)", eventData);
}