Add methods to lookup cached buffers without loading them
[alure.git] / src / auxeffectslot.cpp
blob460841ee6882b77fc2d91dd7db423bef24c75d0d
2 #include "config.h"
4 #include "auxeffectslot.h"
6 #include <stdexcept>
8 #include "context.h"
9 #include "effect.h"
11 namespace alure
14 static inline bool operator<(const SourceSend &lhs, const SourceSend &rhs)
15 { return lhs.mSource < rhs.mSource || (lhs.mSource == rhs.mSource && lhs.mSend < rhs.mSend); }
16 static inline bool operator==(const SourceSend &lhs, const SourceSend &rhs)
17 { return lhs.mSource == rhs.mSource && lhs.mSend == rhs.mSend; }
18 static inline bool operator!=(const SourceSend &lhs, const SourceSend &rhs)
19 { return !(lhs == rhs); }
21 void AuxiliaryEffectSlotImpl::addSourceSend(SourceSend source_send)
23 auto iter = std::lower_bound(mSourceSends.begin(), mSourceSends.end(), source_send);
24 if(iter == mSourceSends.end() || *iter != source_send)
25 mSourceSends.insert(iter, source_send);
28 void AuxiliaryEffectSlotImpl::removeSourceSend(SourceSend source_send)
30 auto iter = std::lower_bound(mSourceSends.begin(), mSourceSends.end(), source_send);
31 if(iter != mSourceSends.end() && *iter == source_send)
32 mSourceSends.erase(iter);
36 void AuxiliaryEffectSlotImpl::setGain(ALfloat gain)
38 if(!(gain >= 0.0f && gain <= 1.0f))
39 throw std::runtime_error("Gain out of range");
40 CheckContext(mContext);
41 mContext->alAuxiliaryEffectSlotf(mId, AL_EFFECTSLOT_GAIN, gain);
44 void AuxiliaryEffectSlotImpl::setSendAuto(bool sendauto)
46 CheckContext(mContext);
47 mContext->alAuxiliaryEffectSloti(mId, AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, sendauto ? AL_TRUE : AL_FALSE);
50 void AuxiliaryEffectSlotImpl::applyEffect(Effect effect)
52 const EffectImpl *eff = effect.getHandle();
53 if(eff) CheckContexts(mContext, eff->getContext());
54 CheckContext(mContext);
56 mContext->alAuxiliaryEffectSloti(mId,
57 AL_EFFECTSLOT_EFFECT, eff ? eff->getId() : AL_EFFECT_NULL
62 void AuxiliaryEffectSlotImpl::release()
64 CheckContext(mContext);
65 if(isInUse())
66 throw std::runtime_error("AuxiliaryEffectSlot is in use");
68 alGetError();
69 mContext->alDeleteAuxiliaryEffectSlots(1, &mId);
70 if(alGetError() != AL_NO_ERROR)
71 throw std::runtime_error("AuxiliaryEffectSlot failed to delete");
72 mId = 0;
74 delete this;
78 DECL_THUNK1(void, AuxiliaryEffectSlot, setGain,, ALfloat)
79 DECL_THUNK1(void, AuxiliaryEffectSlot, setSendAuto,, bool)
80 DECL_THUNK1(void, AuxiliaryEffectSlot, applyEffect,, Effect)
81 void AuxiliaryEffectSlot::release()
83 pImpl->release();
84 pImpl = nullptr;
86 DECL_THUNK0(Vector<SourceSend>, AuxiliaryEffectSlot, getSourceSends, const)
87 DECL_THUNK0(bool, AuxiliaryEffectSlot, isInUse, const)
89 } // namespace alure