Implement AL_EFFECTSLOT_EFFECT property
[openal-soft.git] / OpenAL32 / alAuxEffectSlot.c
blob8e76984f386800c8999cf55293e66a00de5a4703
1 /**
2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
21 #include <stdlib.h>
23 #include "config.h"
25 #include "AL/al.h"
26 #include "AL/alc.h"
28 #include "alMain.h"
29 #include "alAuxEffectSlot.h"
31 static ALeffectslot *g_AuxiliaryEffectSlotList;
32 static ALuint g_AuxiliaryEffectSlotCount;
35 AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
37 ALCcontext *Context;
38 ALsizei i;
40 Context = alcGetCurrentContext();
41 SuspendContext(Context);
43 if (n > 0)
45 /* NOTE: We only support one slot currently */
46 if(n == 1 && g_AuxiliaryEffectSlotCount == 0)
48 // Check that enough memory has been allocted in the 'sources' array for n Sources
49 if (!IsBadWritePtr((void*)effectslots, n * sizeof(ALuint)))
51 ALeffectslot **list = &g_AuxiliaryEffectSlotList;
52 while(*list)
53 list = &(*list)->next;
55 i = 0;
56 while(i < n)
58 *list = calloc(1, sizeof(ALeffectslot));
59 if(!(*list))
61 // We must have run out or memory
62 alDeleteAuxiliaryEffectSlots(i, effectslots);
63 alSetError(AL_OUT_OF_MEMORY);
64 break;
67 effectslots[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
68 (*list)->effectslot = effectslots[i];
70 g_AuxiliaryEffectSlotCount++;
71 i++;
75 else
76 alSetError(AL_INVALID_OPERATION);
79 ProcessContext(Context);
82 AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
84 ALCcontext *Context;
85 ALeffectslot *ALAuxiliaryEffectSlot;
86 ALsizei i;
88 Context = alcGetCurrentContext();
89 SuspendContext(Context);
91 if (n >= 0)
93 // Check that all effectslots are valid
94 for (i = 0; i < n; i++)
96 if (!alIsAuxiliaryEffectSlot(effectslots[i]))
98 alSetError(AL_INVALID_NAME);
99 break;
103 if (i == n)
105 // All effectslots are valid
106 for (i = 0; i < n; i++)
108 // Recheck that the effectslot is valid, because there could be duplicated names
109 if (alIsAuxiliaryEffectSlot(effectslots[i]))
111 ALeffectslot **list;
113 ALAuxiliaryEffectSlot = ((ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslots[i]));
115 // Remove Source from list of Sources
116 list = &g_AuxiliaryEffectSlotList;
117 while(*list && *list != ALAuxiliaryEffectSlot)
118 list = &(*list)->next;
120 if(*list)
121 *list = (*list)->next;
122 ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot->effectslot);
124 memset(ALAuxiliaryEffectSlot, 0, sizeof(ALeffectslot));
125 free(ALAuxiliaryEffectSlot);
127 g_AuxiliaryEffectSlotCount--;
132 else
133 alSetError(AL_INVALID_VALUE);
135 ProcessContext(Context);
138 AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
140 ALCcontext *Context;
141 ALeffectslot **list;
143 Context = alcGetCurrentContext();
144 SuspendContext(Context);
146 list = &g_AuxiliaryEffectSlotList;
147 while(*list && (*list)->effectslot != effectslot)
148 list = &(*list)->next;
150 ProcessContext(Context);
152 return (*list ? AL_TRUE : AL_FALSE);
155 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue)
157 ALCcontext *Context;
159 Context = alcGetCurrentContext();
160 SuspendContext(Context);
162 if (alIsAuxiliaryEffectSlot(effectslot))
164 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
166 switch(param)
168 case AL_EFFECTSLOT_EFFECT:
169 if(alIsEffect(iValue))
171 ALeffect *effect = (ALeffect*)ALTHUNK_LOOKUPENTRY(iValue);
172 if(!effect)
174 ALEffectSlot->effect.type = AL_EFFECT_NULL;
175 ALEffectSlot->effect.effect = 0;
177 else
178 memcpy(&ALEffectSlot->effect, effect, sizeof(*effect));
180 else
181 alSetError(AL_INVALID_VALUE);
182 break;
184 default:
185 alSetError(AL_INVALID_ENUM);
186 break;
189 else
190 alSetError(AL_INVALID_NAME);
192 ProcessContext(Context);
195 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
197 ALCcontext *Context;
199 Context = alcGetCurrentContext();
200 SuspendContext(Context);
202 if (alIsAuxiliaryEffectSlot(effectslot))
204 switch(param)
206 case AL_EFFECTSLOT_EFFECT:
207 alAuxiliaryEffectSloti(effectslot, param, piValues[0]);
208 break;
210 default:
211 alSetError(AL_INVALID_ENUM);
212 break;
215 else
216 alSetError(AL_INVALID_NAME);
218 ProcessContext(Context);
221 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue)
223 ALCcontext *Context;
225 (void)flValue;
227 Context = alcGetCurrentContext();
228 SuspendContext(Context);
230 if (alIsAuxiliaryEffectSlot(effectslot))
232 switch(param)
234 default:
235 alSetError(AL_INVALID_ENUM);
236 break;
239 else
240 alSetError(AL_INVALID_NAME);
242 ProcessContext(Context);
245 AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
247 ALCcontext *Context;
249 (void)pflValues;
251 Context = alcGetCurrentContext();
252 SuspendContext(Context);
254 if (alIsAuxiliaryEffectSlot(effectslot))
256 switch(param)
258 default:
259 alSetError(AL_INVALID_ENUM);
260 break;
263 else
264 alSetError(AL_INVALID_NAME);
266 ProcessContext(Context);
269 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue)
271 ALCcontext *Context;
273 Context = alcGetCurrentContext();
274 SuspendContext(Context);
276 if (alIsAuxiliaryEffectSlot(effectslot))
278 ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot);
280 switch(param)
282 case AL_EFFECTSLOT_EFFECT:
283 *piValue = ALEffectSlot->effect.effect;
284 break;
286 default:
287 alSetError(AL_INVALID_ENUM);
288 break;
291 else
292 alSetError(AL_INVALID_NAME);
294 ProcessContext(Context);
297 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
299 ALCcontext *Context;
301 Context = alcGetCurrentContext();
302 SuspendContext(Context);
304 if (alIsAuxiliaryEffectSlot(effectslot))
306 switch(param)
308 case AL_EFFECTSLOT_EFFECT:
309 alGetAuxiliaryEffectSloti(effectslot, param, piValues);
310 break;
312 default:
313 alSetError(AL_INVALID_ENUM);
314 break;
317 else
318 alSetError(AL_INVALID_NAME);
320 ProcessContext(Context);
323 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue)
325 ALCcontext *Context;
327 (void)pflValue;
329 Context = alcGetCurrentContext();
330 SuspendContext(Context);
332 if (alIsAuxiliaryEffectSlot(effectslot))
334 switch(param)
336 default:
337 alSetError(AL_INVALID_ENUM);
338 break;
341 else
342 alSetError(AL_INVALID_NAME);
344 ProcessContext(Context);
347 AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
349 ALCcontext *Context;
351 (void)pflValues;
353 Context = alcGetCurrentContext();
354 SuspendContext(Context);
356 if (alIsAuxiliaryEffectSlot(effectslot))
358 switch(param)
360 default:
361 alSetError(AL_INVALID_ENUM);
362 break;
365 else
366 alSetError(AL_INVALID_NAME);
368 ProcessContext(Context);
372 ALvoid ReleaseALAuxiliaryEffectSlots(ALvoid)
374 #ifdef _DEBUG
375 if(g_AuxiliaryEffectSlotCount > 0)
376 AL_PRINT("exit() %d AuxiliaryEffectSlot(s) NOT deleted\n", g_AuxiliaryEffectSlotCount);
377 #endif
379 while(g_AuxiliaryEffectSlotList)
381 ALeffectslot *temp = g_AuxiliaryEffectSlotList;
382 g_AuxiliaryEffectSlotList = g_AuxiliaryEffectSlotList->next;
384 // Release effectslot structure
385 memset(temp, 0, sizeof(ALeffectslot));
386 free(temp);
388 g_AuxiliaryEffectSlotCount = 0;