12 #include "midi/base.h"
15 extern inline struct ALsfinstrument
*LookupInstrument(ALCdevice
*device
, ALuint id
);
16 extern inline struct ALsfinstrument
*RemoveInstrument(ALCdevice
*device
, ALuint id
);
19 AL_API
void AL_APIENTRY
alGenInstrumentsSOFT(ALsizei n
, ALuint
*ids
)
26 context
= GetContextRef();
30 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
32 device
= context
->Device
;
33 for(cur
= 0;cur
< n
;cur
++)
35 ALsfinstrument
*inst
= calloc(1, sizeof(ALsfinstrument
));
38 alDeleteInstrumentsSOFT(cur
, ids
);
39 SET_ERROR_AND_GOTO(context
, AL_OUT_OF_MEMORY
, done
);
41 ALsfinstrument_Construct(inst
);
43 err
= NewThunkEntry(&inst
->id
);
44 if(err
== AL_NO_ERROR
)
45 err
= InsertUIntMapEntry(&device
->InstrumentMap
, inst
->id
, inst
);
46 if(err
!= AL_NO_ERROR
)
48 ALsfinstrument_Destruct(inst
);
49 memset(inst
, 0, sizeof(*inst
));
52 alDeleteInstrumentsSOFT(cur
, ids
);
53 SET_ERROR_AND_GOTO(context
, err
, done
);
60 ALCcontext_DecRef(context
);
63 AL_API ALvoid AL_APIENTRY
alDeleteInstrumentsSOFT(ALsizei n
, const ALuint
*ids
)
70 context
= GetContextRef();
74 SET_ERROR_AND_GOTO(context
, AL_INVALID_VALUE
, done
);
76 device
= context
->Device
;
82 /* Check for valid ID */
83 if((inst
=LookupInstrument(device
, ids
[i
])) == NULL
)
84 SET_ERROR_AND_GOTO(context
, AL_INVALID_NAME
, done
);
86 SET_ERROR_AND_GOTO(context
, AL_INVALID_OPERATION
, done
);
91 if((inst
=RemoveInstrument(device
, ids
[i
])) == NULL
)
94 ALsfinstrument_Destruct(inst
);
96 memset(inst
, 0, sizeof(*inst
));
101 ALCcontext_DecRef(context
);
104 AL_API ALboolean AL_APIENTRY
alIsInstrumentSOFT(ALuint id
)
109 context
= GetContextRef();
110 if(!context
) return AL_FALSE
;
112 ret
= ((!id
|| LookupInstrument(context
->Device
, id
)) ?
115 ALCcontext_DecRef(context
);
121 /* ReleaseALInstruments
123 * Called to destroy any instruments that still exist on the device
125 void ReleaseALInstruments(ALCdevice
*device
)
128 for(i
= 0;i
< device
->InstrumentMap
.size
;i
++)
130 ALsfinstrument
*temp
= device
->InstrumentMap
.array
[i
].value
;
131 device
->InstrumentMap
.array
[i
].value
= NULL
;
133 ALsfinstrument_Destruct(temp
);
135 memset(temp
, 0, sizeof(*temp
));