AL_API void AL_APIENTRY alGetSoundfontivSOFT(ALuint id, ALenum param, ALint *values) { ALCdevice *device; ALCcontext *context; ALsoundfont *sfont; ALsizei i; context = GetContextRef(); if(!context) return; device = context->Device; if(id == 0) sfont = ALsoundfont_getDefSoundfont(context); else if(!(sfont=LookupSfont(device, id))) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); switch(param) { case AL_PRESETS_SIZE_SOFT: values[0] = sfont->NumPresets; break; case AL_PRESETS_SOFT: for(i = 0;i < sfont->NumPresets;i++) values[i] = sfont->Presets[i]->id; break; default: SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done); } done: ALCcontext_DecRef(context); }
ALenum MidiSynth_selectSoundfonts(MidiSynth *self, ALCcontext *context, ALsizei count, const ALuint *ids) { ALCdevice *device = context->Device; ALsoundfont **sfonts; ALsizei i; if(self->State != AL_INITIAL && self->State != AL_STOPPED) return AL_INVALID_OPERATION; sfonts = calloc(1, count * sizeof(sfonts[0])); if(!sfonts) return AL_OUT_OF_MEMORY; for(i = 0;i < count;i++) { if(ids[i] == 0) sfonts[i] = ALsoundfont_getDefSoundfont(context); else if(!(sfonts[i]=LookupSfont(device, ids[i]))) { free(sfonts); return AL_INVALID_VALUE; } } for(i = 0;i < count;i++) IncrementRef(&sfonts[i]->ref); sfonts = ExchangePtr((XchgPtr*)&self->Soundfonts, sfonts); count = ExchangeInt(&self->NumSoundfonts, count); for(i = 0;i < count;i++) DecrementRef(&sfonts[i]->ref); free(sfonts); return AL_NO_ERROR; }
AL_API ALvoid AL_APIENTRY alDeleteSoundfontsSOFT(ALsizei n, const ALuint *ids) { ALCdevice *device; ALCcontext *context; ALsoundfont *sfont; ALsizei i; context = GetContextRef(); if(!context) return; if(!(n >= 0)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); device = context->Device; for(i = 0;i < n;i++) { /* Check for valid soundfont ID */ if(ids[i] == 0) { if(!(sfont=device->DefaultSfont)) continue; } else if((sfont=LookupSfont(device, ids[i])) == NULL) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); if(ReadRef(&sfont->ref) != 0) SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); } for(i = 0;i < n;i++) { if(ids[i] == 0) { MidiSynth *synth = device->Synth; WriteLock(&synth->Lock); if(device->DefaultSfont != NULL) ALsoundfont_deleteSoundfont(device->DefaultSfont, device); device->DefaultSfont = NULL; WriteUnlock(&synth->Lock); continue; } else if((sfont=RemoveSfont(device, ids[i])) == NULL) continue; ALsoundfont_Destruct(sfont); memset(sfont, 0, sizeof(*sfont)); free(sfont); } done: ALCcontext_DecRef(context); }
AL_API ALboolean AL_APIENTRY alIsSoundfontSOFT(ALuint id) { ALCcontext *context; ALboolean ret; context = GetContextRef(); if(!context) return AL_FALSE; ret = ((!id || LookupSfont(context->Device, id)) ? AL_TRUE : AL_FALSE); ALCcontext_DecRef(context); return ret; }
AL_API void AL_APIENTRY alLoadSoundfontSOFT(ALuint id, size_t(*cb)(ALvoid*,size_t,ALvoid*), ALvoid *user) { ALCdevice *device; ALCcontext *context; ALsoundfont *sfont; Reader reader; context = GetContextRef(); if(!context) return; device = context->Device; if(id == 0) SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); if(!(sfont=LookupSfont(device, id))) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); WriteLock(&sfont->Lock); if(ReadRef(&sfont->ref) != 0) { WriteUnlock(&sfont->Lock); SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); } if(sfont->NumPresets > 0) { WriteUnlock(&sfont->Lock); SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); } reader.cb = cb; reader.ptr = user; reader.error = 0; loadSf2(&reader, sfont, context); WriteUnlock(&sfont->Lock); done: ALCcontext_DecRef(context); }
AL_API void AL_APIENTRY alSoundfontPresetsSOFT(ALuint id, ALsizei count, const ALuint *pids) { ALCdevice *device; ALCcontext *context; ALsoundfont *sfont; ALsfpreset **presets; ALsizei i; context = GetContextRef(); if(!context) return; device = context->Device; if(id == 0) SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); if(!(sfont=LookupSfont(device, id))) SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); if(count < 0) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); WriteLock(&sfont->Lock); if(ReadRef(&sfont->ref) != 0) { WriteUnlock(&sfont->Lock); SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); } if(count == 0) presets = NULL; else { presets = calloc(count, sizeof(presets[0])); if(!presets) { WriteUnlock(&sfont->Lock); SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); } for(i = 0;i < count;i++) { if(!(presets[i]=LookupPreset(device, pids[i]))) { free(presets); WriteUnlock(&sfont->Lock); SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); } } } for(i = 0;i < count;i++) IncrementRef(&presets[i]->ref); presets = ExchangePtr((XchgPtr*)&sfont->Presets, presets); count = ExchangeInt(&sfont->NumPresets, count); WriteUnlock(&sfont->Lock); for(i = 0;i < count;i++) DecrementRef(&presets[i]->ref); free(presets); done: ALCcontext_DecRef(context); }