// May be called in other thread than the main thread
AudioUnit audioUnit = config->samplerAudioUnit;
AUSamplerInstrumentData instData;
instData.fileURL = url;
instData.bankLSB = kAUSampler_DefaultBankLSB;
instData.bankMSB = kAUSampler_DefaultMelodicBankMSB;
instData.presetID = presetNo;
instData.instrumentType = kInstrumentType_SF2Preset;
errno = 0; // Workaround for iOS bug; AudioUnitSetProperty() may fail when invoked on different thread than main thread
// Load soundfont preset by setting the kAUSamplerProperty_LoadPresetFromBank property
OSStatus result;
result = AudioUnitSetProperty(audioUnit, kAUSamplerProperty_LoadInstrument, kAudioUnitScope_Global, 0, &instData, sizeof(AUSamplerInstrumentData));
if (result != noErr) {
DLog(@"Could not load preset %u from soundfont '%@': result=%d", presetNo, ((__bridge NSURL *)url).lastPathComponent, (int)result);
} else {
DLog(@"Loaded preset %u from soundfont '%@'", presetNo, ((__bridge NSURL *)url).lastPathComponent);
OSAtomicTestAndSet(0, &config->presetLoaded);
}