[Scummvm-cvs-logs] scummvm master -> 412ac740aa04428251a94073357f5458ed217f3f

clone2727 clone2727 at gmail.com
Fri Feb 1 20:19:04 CET 2013


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
412ac740aa MACOSX: Load soundfonts using FSRef instead of FSSpec on 10.5


Commit: 412ac740aa04428251a94073357f5458ed217f3f
    https://github.com/scummvm/scummvm/commit/412ac740aa04428251a94073357f5458ed217f3f
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2013-02-01T11:15:10-08:00

Commit Message:
MACOSX: Load soundfonts using FSRef instead of FSSpec on 10.5

Fixes bug #3602452

Changed paths:
    backends/midi/coreaudio.cpp



diff --git a/backends/midi/coreaudio.cpp b/backends/midi/coreaudio.cpp
index 94262d0..317268a 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) {






More information about the Scummvm-git-logs mailing list