From 412ac740aa04428251a94073357f5458ed217f3f Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 1 Feb 2013 14:13:24 -0500 Subject: MACOSX: Load soundfonts using FSRef instead of FSSpec on 10.5 Fixes bug #3602452 --- backends/midi/coreaudio.cpp | 111 ++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 46 deletions(-) (limited to 'backends/midi/coreaudio.cpp') diff --git a/backends/midi/coreaudio.cpp b/backends/midi/coreaudio.cpp index 94262d0d92..317268ae87 100644 --- a/backends/midi/coreaudio.cpp +++ b/backends/midi/coreaudio.cpp @@ -102,6 +102,7 @@ public: void sysEx(const byte *msg, uint16 length); private: + void loadSoundFont(const char *soundfont); AUGraph _auGraph; AudioUnit _synth; }; @@ -171,52 +172,8 @@ int MidiDriver_CORE::open() { #endif // Load custom soundfont, if specified - if (ConfMan.hasKey("soundfont")) { - const char *soundfont = ConfMan.get("soundfont").c_str(); - - // TODO: We should really check whether the file contains an - // actual soundfont... - -#if USE_DEPRECATED_COREAUDIO_API - // Before 10.5, we need to use kMusicDeviceProperty_SoundBankFSSpec - FSRef fsref; - FSSpec fsSpec; - err = FSPathMakeRef ((const byte *)soundfont, &fsref, NULL); - - if (err == noErr) { - err = FSGetCatalogInfo (&fsref, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL); - } - - if (err == noErr) { - err = AudioUnitSetProperty ( - _synth, - kMusicDeviceProperty_SoundBankFSSpec, kAudioUnitScope_Global, - 0, - &fsSpec, sizeof(fsSpec) - ); - } -#else - // kMusicDeviceProperty_SoundBankFSSpec is present on 10.6+, but broken - // kMusicDeviceProperty_SoundBankURL was added in 10.5 as a replacement - CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)soundfont, strlen(soundfont), false); - - if (url) { - err = AudioUnitSetProperty ( - _synth, - kMusicDeviceProperty_SoundBankURL, kAudioUnitScope_Global, - 0, - &url, sizeof(url) - ); - - CFRelease(url); - } else { - warning("Failed to allocate CFURLRef from '%s'", soundfont); - } -#endif - - if (err != noErr) - error("Failed loading custom sound font '%s' (error %ld)", soundfont, (long)err); - } + if (ConfMan.hasKey("soundfont")) + loadSoundFont(ConfMan.get("soundfont").c_str()); #ifdef COREAUDIO_DISABLE_REVERB // Disable reverb mode, as that sucks up a lot of CPU power, which can @@ -242,6 +199,68 @@ bail: return MERR_CANNOT_CONNECT; } +void MidiDriver_CORE::loadSoundFont(const char *soundfont) { + // TODO: We should really check whether the file contains an + // actual soundfont... + + OSStatus err = 0; + +#if USE_DEPRECATED_COREAUDIO_API + FSRef fsref; + err = FSPathMakeRef((const byte *)soundfont, &fsref, NULL); + +#ifdef MAC_OS_X_VERSION_10_5 + // Use kMusicDeviceProperty_SoundBankFSRef if we know it's available + // (This became available in 10.3, but the 10.2 SDK has 10.3/10.4 defines) + + if (err == noErr) { + err = AudioUnitSetProperty( + _synth, + kMusicDeviceProperty_SoundBankFSRef, kAudioUnitScope_Global, + 0, + &fsref, sizeof(fsref) + ); + } +#else + // Otherwise, we know kMusicDeviceProperty_SoundBankFSSpec is available + FSSpec fsSpec; + + if (err == noErr) + err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL); + + if (err == noErr) { + err = AudioUnitSetProperty( + _synth, + kMusicDeviceProperty_SoundBankFSSpec, kAudioUnitScope_Global, + 0, + &fsSpec, sizeof(fsSpec) + ); + } +#endif // MAC_OS_X_VERSION_10_5 + +#else + // kMusicDeviceProperty_SoundBankURL was added in 10.5 as a replacement + // In addition, the File Manager API became deprecated starting in 10.8 + CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)soundfont, strlen(soundfont), false); + + if (url) { + err = AudioUnitSetProperty( + _synth, + kMusicDeviceProperty_SoundBankURL, kAudioUnitScope_Global, + 0, + &url, sizeof(url) + ); + + CFRelease(url); + } else { + warning("Failed to allocate CFURLRef from '%s'", soundfont); + } +#endif // USE_DEPRECATED_COREAUDIO_API + + if (err != noErr) + error("Failed loading custom sound font '%s' (error %ld)", soundfont, (long)err); +} + void MidiDriver_CORE::close() { MidiDriver_MPU401::close(); if (_auGraph) { -- cgit v1.2.3 From 31252e10950ee5ab6f2f812ddc64c9c59697be75 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 1 Feb 2013 16:48:38 -0500 Subject: MACOSX: Fix compilation with the 10.2.8 SDK This is a pretty bad hack of not using the kMusicDeviceProperty_SoundBankFSRef symbol and using its value instead. It felt wrong breaking 10.2.8 support just because of Soundfonts. --- backends/midi/coreaudio.cpp | 58 +++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 26 deletions(-) (limited to 'backends/midi/coreaudio.cpp') diff --git a/backends/midi/coreaudio.cpp b/backends/midi/coreaudio.cpp index 317268ae87..e42b8ca313 100644 --- a/backends/midi/coreaudio.cpp +++ b/backends/midi/coreaudio.cpp @@ -209,35 +209,41 @@ void MidiDriver_CORE::loadSoundFont(const char *soundfont) { FSRef fsref; err = FSPathMakeRef((const byte *)soundfont, &fsref, NULL); -#ifdef MAC_OS_X_VERSION_10_5 - // Use kMusicDeviceProperty_SoundBankFSRef if we know it's available - // (This became available in 10.3, but the 10.2 SDK has 10.3/10.4 defines) + SInt32 version; + err = Gestalt(gestaltSystemVersion, &version); if (err == noErr) { - err = AudioUnitSetProperty( - _synth, - kMusicDeviceProperty_SoundBankFSRef, kAudioUnitScope_Global, - 0, - &fsref, sizeof(fsref) - ); - } -#else - // Otherwise, we know kMusicDeviceProperty_SoundBankFSSpec is available - FSSpec fsSpec; - - if (err == noErr) - err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL); - - if (err == noErr) { - err = AudioUnitSetProperty( - _synth, - kMusicDeviceProperty_SoundBankFSSpec, kAudioUnitScope_Global, - 0, - &fsSpec, sizeof(fsSpec) - ); + if (version >= 0x1030) { + // Use kMusicDeviceProperty_SoundBankFSRef in >= 10.3 + + // HACK HACK HACK HACK SUPER HACK: Using the value of 1012 instead of + // kMusicDeviceProperty_SoundBankFSRef so this compiles with the 10.2 + // SDK (which does not have that symbol). + if (err == noErr) { + err = AudioUnitSetProperty( + _synth, + /*kMusicDeviceProperty_SoundBankFSRef*/ 1012, kAudioUnitScope_Global, + 0, + &fsref, sizeof(fsref) + ); + } + } else { + // In 10.2, only kMusicDeviceProperty_SoundBankFSSpec is available + FSSpec fsSpec; + + if (err == noErr) + err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL); + + if (err == noErr) { + err = AudioUnitSetProperty( + _synth, + kMusicDeviceProperty_SoundBankFSSpec, kAudioUnitScope_Global, + 0, + &fsSpec, sizeof(fsSpec) + ); + } + } } -#endif // MAC_OS_X_VERSION_10_5 - #else // kMusicDeviceProperty_SoundBankURL was added in 10.5 as a replacement // In addition, the File Manager API became deprecated starting in 10.8 -- cgit v1.2.3