AUDIO: Add pure virtual MidiDriver::isOpen() method

This in turn enables modifying MidiDriver_MPU401::close() to allow
it to be called on a midi driver that has not yet been opened.

The specific issue that triggered me to make these changes was a
crash-upon-quit in HUGO, caused by it instantiating a midi driver,
then encountering an error (missing hugo.dat) *before* having
opened the new midi driver; the general cleanup code then tries
to close the (not yet opened) midi driver -> kaboom

Also fixed some engines which were leaking MidiDriver instances.
This commit is contained in:
Max Horn 2011-03-21 15:42:17 +01:00
parent 92716d71ed
commit 8982fff1b7
43 changed files with 175 additions and 65 deletions

View file

@ -56,6 +56,7 @@ public:
MidiDriver_CoreMIDI();
~MidiDriver_CoreMIDI();
int open();
bool isOpen() const { return mOutPort != 0 && mDest != 0; }
void close();
void send(uint32 b);
void sysEx(const byte *msg, uint16 length);
@ -80,7 +81,7 @@ MidiDriver_CoreMIDI::~MidiDriver_CoreMIDI() {
}
int MidiDriver_CoreMIDI::open() {
if (mDest)
if (isOpen())
return MERR_ALREADY_OPEN;
OSStatus err = noErr;
@ -106,7 +107,7 @@ int MidiDriver_CoreMIDI::open() {
void MidiDriver_CoreMIDI::close() {
MidiDriver_MPU401::close();
if (mOutPort && mDest) {
if (isOpen()) {
MIDIPortDispose(mOutPort);
mOutPort = 0;
mDest = 0;
@ -114,8 +115,7 @@ void MidiDriver_CoreMIDI::close() {
}
void MidiDriver_CoreMIDI::send(uint32 b) {
assert(mOutPort != 0);
assert(mDest != 0);
assert(isOpen());
// Extract the MIDI data
byte status_byte = (b & 0x000000FF);
@ -158,8 +158,7 @@ void MidiDriver_CoreMIDI::send(uint32 b) {
}
void MidiDriver_CoreMIDI::sysEx(const byte *msg, uint16 length) {
assert(mOutPort != 0);
assert(mDest != 0);
assert(isOpen());
byte buf[384];
MIDIPacketList *packetList = (MIDIPacketList *)buf;