diff options
Diffstat (limited to 'backends/midi/coreaudio.cpp')
-rw-r--r-- | backends/midi/coreaudio.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/backends/midi/coreaudio.cpp b/backends/midi/coreaudio.cpp index 75c512cad7..0158cc4a1d 100644 --- a/backends/midi/coreaudio.cpp +++ b/backends/midi/coreaudio.cpp @@ -72,7 +72,9 @@ do { \ class MidiDriver_CORE : public MidiDriver_MPU401 { public: MidiDriver_CORE(); + ~MidiDriver_CORE(); int open(); + bool isOpen() const { return _auGraph != 0; } void close(); void send(uint32 b); void sysEx(const byte *msg, uint16 length); @@ -86,10 +88,18 @@ MidiDriver_CORE::MidiDriver_CORE() : _auGraph(0) { } +MidiDriver_CORE::~MidiDriver_CORE() { + if (_auGraph) { + AUGraphStop(_auGraph); + DisposeAUGraph(_auGraph); + _auGraph = 0; + } +} + int MidiDriver_CORE::open() { OSStatus err = 0; - if (_auGraph) + if (isOpen()) return MERR_ALREADY_OPEN; // Open the Music Device. @@ -176,7 +186,6 @@ bail: void MidiDriver_CORE::close() { MidiDriver_MPU401::close(); - if (_auGraph) { AUGraphStop(_auGraph); DisposeAUGraph(_auGraph); @@ -185,7 +194,7 @@ void MidiDriver_CORE::close() { } void MidiDriver_CORE::send(uint32 b) { - assert(_auGraph != NULL); + assert(isOpen()); byte status_byte = (b & 0x000000FF); byte first_byte = (b & 0x0000FF00) >> 8; @@ -198,7 +207,7 @@ void MidiDriver_CORE::sysEx(const byte *msg, uint16 length) { unsigned char buf[266]; assert(length + 2 <= ARRAYSIZE(buf)); - assert(_auGraph != NULL); + assert(isOpen()); // Add SysEx frame buf[0] = 0xF0; |