Fixed bug 1566 - make native_midi_osx to use AUGraphAddNode() on 10.5
authorSam Lantinga <slouken@libsdl.org>
Sat, 11 Aug 2012 23:21:14 -0700
changeset 589a9a8e029a84b
parent 588 2ebb0d016f27
child 590 180ef9af767b
Fixed bug 1566 - make native_midi_osx to use AUGraphAddNode() on 10.5

Ozkan Sezer 2012-08-10 02:53:51 PDT

Current native_midi_osx uses AUGraphAddNode() only on 10.6 because of struct
AudioComponentDescription being a 10.6 SDK thing. However,
AudioComponentDescription is actually the same as struct ComponentDescription
with 20 bytes of size and the same offsets of all members, therefore, is binary
compatible. So, defining AudioComponentDescription as ComponentDescription when
compiling against 10.5 SDK does the trick. A patch is attached.
native_midi/native_midi_macosx.c
     1.1 --- a/native_midi/native_midi_macosx.c	Sun Jul 22 16:33:37 2012 -0700
     1.2 +++ b/native_midi/native_midi_macosx.c	Sat Aug 11 23:21:14 2012 -0700
     1.3 @@ -26,7 +26,8 @@
     1.4  
     1.5  #if __MACOSX__
     1.6  
     1.7 -#include <Carbon/Carbon.h>
     1.8 +#include <CoreServices/CoreServices.h>		/* ComponentDescription */
     1.9 +#include <AudioUnit/AudioUnit.h>
    1.10  #include <AudioToolbox/AudioToolbox.h>
    1.11  #include <AvailabilityMacros.h>
    1.12  
    1.13 @@ -107,7 +108,7 @@
    1.14          if (AUGraphGetIndNode(graph, i, &node) != noErr)
    1.15              continue;  /* better luck next time. */
    1.16  
    1.17 -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 /* this is deprecated, but works back to 10.0 */
    1.18 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 /* this is deprecated, but works back to 10.0 */
    1.19          {
    1.20              struct ComponentDescription desc;
    1.21              UInt32 classdatasize = 0;
    1.22 @@ -123,6 +124,14 @@
    1.23          }
    1.24          #else  /* not deprecated, but requires 10.5 or later */
    1.25          {
    1.26 +        # if !defined(AUDIO_UNIT_VERSION) || ((AUDIO_UNIT_VERSION + 0) < 1060)
    1.27 +         /* AUGraphAddNode () is changed to take an AudioComponentDescription*
    1.28 +          * desc parameter instead of a ComponentDescription* in the 10.6 SDK.
    1.29 +          * AudioComponentDescription is in 10.6 or newer, but it is actually
    1.30 +          * the same as struct ComponentDescription with 20 bytes of size and
    1.31 +          * the same offsets of all members, therefore, is binary compatible. */
    1.32 +        #   define AudioComponentDescription ComponentDescription
    1.33 +        # endif
    1.34              AudioComponentDescription desc;
    1.35              if (AUGraphNodeInfo(graph, node, &desc, aunit) != noErr)
    1.36                  continue;