diff options
author | Chris Robinson <[email protected]> | 2014-01-02 10:39:21 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-01-02 10:39:21 -0800 |
commit | 01f547b93e8ce7e1ad774fee73c81777a034028e (patch) | |
tree | 58435de17187bb81d2a7498458e5c5850d10dd18 | |
parent | 3ff33e2f79a7b251ca7709704e995385c792e799 (diff) |
Move some preset alloc/dealloc code to separate functions
-rw-r--r-- | Alc/midi/base.c | 28 | ||||
-rw-r--r-- | OpenAL32/Include/alMidi.h | 5 | ||||
-rw-r--r-- | OpenAL32/alPreset.c | 96 |
3 files changed, 73 insertions, 56 deletions
diff --git a/Alc/midi/base.c b/Alc/midi/base.c index b726f47b..599dc6dc 100644 --- a/Alc/midi/base.c +++ b/Alc/midi/base.c @@ -416,34 +416,6 @@ ALenum ALfontsound_addModulator(ALfontsound *self, ALenum sourceop, ALenum desto } -void ALsfpreset_Construct(ALsfpreset *self) -{ - self->ref = 0; - - self->Preset = 0; - self->Bank = 0; - - self->Sounds = NULL; - self->NumSounds = 0; - - self->id = 0; -} - -void ALsfpreset_Destruct(ALsfpreset *self) -{ - ALsizei i; - - FreeThunkEntry(self->id); - self->id = 0; - - for(i = 0;i < self->NumSounds;i++) - DecrementRef(&self->Sounds[i]->ref); - free(self->Sounds); - self->Sounds = NULL; - self->NumSounds = 0; -} - - void ALsoundfont_Construct(ALsoundfont *self) { self->ref = 0; diff --git a/OpenAL32/Include/alMidi.h b/OpenAL32/Include/alMidi.h index c31992b3..8037cff8 100644 --- a/OpenAL32/Include/alMidi.h +++ b/OpenAL32/Include/alMidi.h @@ -122,9 +122,8 @@ typedef struct ALsfpreset { ALuint id; } ALsfpreset; -void ALsfpreset_Construct(ALsfpreset *self); -void ALsfpreset_Destruct(ALsfpreset *self); - +ALsfpreset *NewPreset(ALCcontext *context); +void DeletePreset(ALsfpreset *preset, ALCdevice *device); inline struct ALsfpreset *LookupPreset(ALCdevice *device, ALuint id) { return (struct ALsfpreset*)LookupUIntMapKey(&device->PresetMap, id); } diff --git a/OpenAL32/alPreset.c b/OpenAL32/alPreset.c index fda06e95..976e45f9 100644 --- a/OpenAL32/alPreset.c +++ b/OpenAL32/alPreset.c @@ -15,13 +15,14 @@ extern inline struct ALsfpreset *LookupPreset(ALCdevice *device, ALuint id); extern inline struct ALsfpreset *RemovePreset(ALCdevice *device, ALuint id); +static void ALsfpreset_Construct(ALsfpreset *self); +static void ALsfpreset_Destruct(ALsfpreset *self); + AL_API void AL_APIENTRY alGenPresetsSOFT(ALsizei n, ALuint *ids) { - ALCdevice *device; ALCcontext *context; ALsizei cur = 0; - ALenum err; context = GetContextRef(); if(!context) return; @@ -29,28 +30,13 @@ AL_API void AL_APIENTRY alGenPresetsSOFT(ALsizei n, ALuint *ids) if(!(n >= 0)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); - device = context->Device; for(cur = 0;cur < n;cur++) { - ALsfpreset *preset = calloc(1, sizeof(ALsfpreset)); + ALsfpreset *preset = NewPreset(context); if(!preset) { alDeletePresetsSOFT(cur, ids); - SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); - } - ALsfpreset_Construct(preset); - - err = NewThunkEntry(&preset->id); - if(err == AL_NO_ERROR) - err = InsertUIntMapEntry(&device->PresetMap, preset->id, preset); - if(err != AL_NO_ERROR) - { - ALsfpreset_Destruct(preset); - memset(preset, 0, sizeof(*preset)); - free(preset); - - alDeletePresetsSOFT(cur, ids); - SET_ERROR_AND_GOTO(context, err, done); + break; } ids[cur] = preset->id; @@ -85,13 +71,9 @@ AL_API ALvoid AL_APIENTRY alDeletePresetsSOFT(ALsizei n, const ALuint *ids) for(i = 0;i < n;i++) { - if((preset=RemovePreset(device, ids[i])) == NULL) + if((preset=LookupPreset(device, ids[i])) == NULL) continue; - - ALsfpreset_Destruct(preset); - - memset(preset, 0, sizeof(*preset)); - free(preset); + DeletePreset(preset, device); } done: @@ -276,6 +258,70 @@ done: } +ALsfpreset *NewPreset(ALCcontext *context) +{ + ALCdevice *device = context->Device; + ALsfpreset *preset; + ALenum err; + + preset = calloc(1, sizeof(*preset)); + if(!preset) + SET_ERROR_AND_RETURN_VALUE(context, AL_OUT_OF_MEMORY, NULL); + ALsfpreset_Construct(preset); + + err = NewThunkEntry(&preset->id); + if(err == AL_NO_ERROR) + err = InsertUIntMapEntry(&device->PresetMap, preset->id, preset); + if(err != AL_NO_ERROR) + { + ALsfpreset_Destruct(preset); + memset(preset, 0, sizeof(*preset)); + free(preset); + + SET_ERROR_AND_RETURN_VALUE(context, err, NULL); + } + + return preset; +} + +void DeletePreset(ALsfpreset *preset, ALCdevice *device) +{ + RemovePreset(device, preset->id); + + ALsfpreset_Destruct(preset); + memset(preset, 0, sizeof(*preset)); + free(preset); +} + + +static void ALsfpreset_Construct(ALsfpreset *self) +{ + self->ref = 0; + + self->Preset = 0; + self->Bank = 0; + + self->Sounds = NULL; + self->NumSounds = 0; + + self->id = 0; +} + +static void ALsfpreset_Destruct(ALsfpreset *self) +{ + ALsizei i; + + FreeThunkEntry(self->id); + self->id = 0; + + for(i = 0;i < self->NumSounds;i++) + DecrementRef(&self->Sounds[i]->ref); + free(self->Sounds); + self->Sounds = NULL; + self->NumSounds = 0; +} + + /* ReleaseALPresets * * Called to destroy any presets that still exist on the device |