diff options
author | Chris Robinson <[email protected]> | 2013-12-19 00:57:07 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-12-19 00:57:07 -0800 |
commit | 99933fac4940303903fcf4fbb022f48824196ed9 (patch) | |
tree | 8d7e345003f87f34e5990c7127240e2f6a638ea3 | |
parent | 57491bf14c43de01ffcbcd61d6bdff6df49f4066 (diff) |
Allow creating instrument objects
-rw-r--r-- | Alc/ALc.c | 13 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 9 | ||||
-rw-r--r-- | OpenAL32/Include/alMidi.h | 8 | ||||
-rw-r--r-- | OpenAL32/alInstrument.c | 141 |
5 files changed, 172 insertions, 0 deletions
@@ -287,6 +287,9 @@ static const ALCfunction alcFunctions[] = { DECL(alGenPresetsSOFT), DECL(alDeletePresetsSOFT), DECL(alIsPresetSOFT), + DECL(alGenInstrumentsSOFT), + DECL(alDeleteInstrumentsSOFT), + DECL(alIsInstrumentSOFT), DECL(alMidiSoundfontSOFT), DECL(alMidiEventSOFT), DECL(alMidiSysExSOFT), @@ -1966,6 +1969,13 @@ static ALCvoid FreeDevice(ALCdevice *device) } ResetUIntMap(&device->PresetMap); + if(device->InstrumentMap.size > 0) + { + WARN("(%p) Deleting %d Instrument(s)\n", device, device->InstrumentMap.size); + ReleaseALInstruments(device); + } + ResetUIntMap(&device->InstrumentMap); + free(device->Bs2b); device->Bs2b = NULL; @@ -2904,6 +2914,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) InitUIntMap(&device->FilterMap, ~0); InitUIntMap(&device->SfontMap, ~0); InitUIntMap(&device->PresetMap, ~0); + InitUIntMap(&device->InstrumentMap, ~0); //Set output format device->FmtChans = DevFmtChannelsDefault; @@ -3190,6 +3201,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, InitUIntMap(&device->FilterMap, ~0); InitUIntMap(&device->SfontMap, ~0); InitUIntMap(&device->PresetMap, ~0); + InitUIntMap(&device->InstrumentMap, ~0); device->DeviceName = NULL; @@ -3369,6 +3381,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN InitUIntMap(&device->FilterMap, ~0); InitUIntMap(&device->SfontMap, ~0); InitUIntMap(&device->PresetMap, ~0); + InitUIntMap(&device->InstrumentMap, ~0); factory = ALCloopbackFactory_getFactory(); device->Backend = V(factory,createBackend)(device, ALCbackend_Loopback); diff --git a/CMakeLists.txt b/CMakeLists.txt index 14170704..c5019323 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -491,6 +491,7 @@ SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c OpenAL32/alError.c OpenAL32/alExtension.c OpenAL32/alFilter.c + OpenAL32/alInstrument.c OpenAL32/alListener.c OpenAL32/alMidi.c OpenAL32/alPreset.c diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 70068f37..ce229c73 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -44,6 +44,9 @@ typedef ALboolean (AL_APIENTRY*LPALISSOUNDFONTSOFT)(ALuint id); typedef void (AL_APIENTRY*LPALGENPRESETSSOFT)(ALsizei n, ALuint *ids); typedef void (AL_APIENTRY*LPALDELETEPRESETSSOFT)(ALsizei n, const ALuint *ids); typedef ALboolean (AL_APIENTRY*LPALISPRESETSOFT)(ALuint id); +typedef void (AL_APIENTRY*LPALGENINSTRUMENTSSOFT)(ALsizei n, ALuint *ids); +typedef void (AL_APIENTRY*LPALDELETEINSTRUMENTSSOFT)(ALsizei n, const ALuint *ids); +typedef ALboolean (AL_APIENTRY*LPALISINSTRUMENTSOFT)(ALuint id); typedef void (AL_APIENTRY*LPALMIDISOUNDFONTSOFT)(const char *filename); typedef void (AL_APIENTRY*LPALMIDIEVENTSOFT)(ALuint64SOFT time, ALenum event, ALsizei channel, ALsizei param1, ALsizei param2); typedef void (AL_APIENTRY*LPALMIDISYSEXSOFT)(ALuint64SOFT time, const ALbyte *data, ALsizei size); @@ -61,6 +64,9 @@ AL_API ALboolean AL_APIENTRY alIsSoundfontSOFT(ALuint id); AL_API void AL_APIENTRY alGenPresetsSOFT(ALsizei n, ALuint *ids); AL_API void AL_APIENTRY alDeletePresetsSOFT(ALsizei n, const ALuint *ids); AL_API ALboolean AL_APIENTRY alIsPresetSOFT(ALuint id); +AL_API void AL_APIENTRY alGenInstrumentsSOFT(ALsizei n, ALuint *ids); +AL_API void AL_APIENTRY alDeleteInstrumentsSOFT(ALsizei n, const ALuint *ids); +AL_API ALboolean AL_APIENTRY alIsInstrumentSOFT(ALuint id); AL_API void AL_APIENTRY alMidiSoundfontSOFT(const char *filename); AL_API void AL_APIENTRY alMidiEventSOFT(ALuint64SOFT time, ALenum event, ALsizei channel, ALsizei param1, ALsizei param2); AL_API void AL_APIENTRY alMidiSysExSOFT(ALuint64SOFT time, const ALbyte *data, ALsizei size); @@ -440,6 +446,9 @@ struct ALCdevice_struct // Map of Presets for this device UIntMap PresetMap; + // Map of Instruments for this device + UIntMap InstrumentMap; + /* MIDI synth engine */ struct MidiSynth *Synth; diff --git a/OpenAL32/Include/alMidi.h b/OpenAL32/Include/alMidi.h index c2ddd728..b6835649 100644 --- a/OpenAL32/Include/alMidi.h +++ b/OpenAL32/Include/alMidi.h @@ -76,6 +76,14 @@ void ALsfinstrument_Construct(ALsfinstrument *self); void ALsfinstrument_Destruct(ALsfinstrument *self); +inline struct ALsfinstrument *LookupInstrument(ALCdevice *device, ALuint id) +{ return (struct ALsfinstrument*)LookupUIntMapKey(&device->InstrumentMap, id); } +inline struct ALsfinstrument *RemoveInstrument(ALCdevice *device, ALuint id) +{ return (struct ALsfinstrument*)RemoveUIntMapKey(&device->InstrumentMap, id); } + +void ReleaseALInstruments(ALCdevice *device); + + typedef struct ALsfpreset { volatile RefCount ref; diff --git a/OpenAL32/alInstrument.c b/OpenAL32/alInstrument.c new file mode 100644 index 00000000..69f6868f --- /dev/null +++ b/OpenAL32/alInstrument.c @@ -0,0 +1,141 @@ + +#include "config.h" + +#include <stdlib.h> +#include <string.h> + +#include "alMain.h" +#include "alMidi.h" +#include "alError.h" +#include "alThunk.h" + +#include "midi/base.h" + + +extern inline struct ALsfinstrument *LookupInstrument(ALCdevice *device, ALuint id); +extern inline struct ALsfinstrument *RemoveInstrument(ALCdevice *device, ALuint id); + + +AL_API void AL_APIENTRY alGenInstrumentsSOFT(ALsizei n, ALuint *ids) +{ + ALCdevice *device; + ALCcontext *context; + ALsizei cur = 0; + ALenum err; + + context = GetContextRef(); + if(!context) return; + + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + + device = context->Device; + for(cur = 0;cur < n;cur++) + { + ALsfinstrument *inst = calloc(1, sizeof(ALsfinstrument)); + if(!inst) + { + alDeleteInstrumentsSOFT(cur, ids); + SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); + } + ALsfinstrument_Construct(inst); + + err = NewThunkEntry(&inst->id); + if(err == AL_NO_ERROR) + err = InsertUIntMapEntry(&device->InstrumentMap, inst->id, inst); + if(err != AL_NO_ERROR) + { + FreeThunkEntry(inst->id); + ALsfinstrument_Destruct(inst); + memset(inst, 0, sizeof(*inst)); + free(inst); + + alDeleteInstrumentsSOFT(cur, ids); + SET_ERROR_AND_GOTO(context, err, done); + } + + ids[cur] = inst->id; + } + +done: + ALCcontext_DecRef(context); +} + +AL_API ALvoid AL_APIENTRY alDeleteInstrumentsSOFT(ALsizei n, const ALuint *ids) +{ + ALCdevice *device; + ALCcontext *context; + ALsfinstrument *inst; + 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++) + { + if(!ids[i]) + continue; + + /* Check for valid ID */ + if((inst=LookupInstrument(device, ids[i])) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + if(inst->ref != 0) + SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); + } + + for(i = 0;i < n;i++) + { + if((inst=RemoveInstrument(device, ids[i])) == NULL) + continue; + FreeThunkEntry(inst->id); + + ALsfinstrument_Destruct(inst); + + memset(inst, 0, sizeof(*inst)); + free(inst); + } + +done: + ALCcontext_DecRef(context); +} + +AL_API ALboolean AL_APIENTRY alIsInstrumentSOFT(ALuint id) +{ + ALCcontext *context; + ALboolean ret; + + context = GetContextRef(); + if(!context) return AL_FALSE; + + ret = ((!id || LookupInstrument(context->Device, id)) ? + AL_TRUE : AL_FALSE); + + ALCcontext_DecRef(context); + + return ret; +} + + +/* ReleaseALInstruments + * + * Called to destroy any instruments that still exist on the device + */ +void ReleaseALInstruments(ALCdevice *device) +{ + ALsizei i; + for(i = 0;i < device->InstrumentMap.size;i++) + { + ALsfinstrument *temp = device->InstrumentMap.array[i].value; + device->InstrumentMap.array[i].value = NULL; + + FreeThunkEntry(temp->id); + ALsfinstrument_Destruct(temp); + + memset(temp, 0, sizeof(*temp)); + free(temp); + } +} |