MACOSX: Load soundfonts using FSRef instead of FSSpec on 10.5

Fixes bug #3602452
This commit is contained in:
Matthew Hoops 2013-02-01 14:13:24 -05:00
parent cef07f30d8
commit 412ac740aa

View File

@ -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) {