4 #include "auxeffectslot.h"
13 static inline bool operator<(const SourceSend
&lhs
, const SourceSend
&rhs
)
14 { return lhs
.mSource
< rhs
.mSource
|| (lhs
.mSource
== rhs
.mSource
&& lhs
.mSend
< rhs
.mSend
); }
15 static inline bool operator==(const SourceSend
&lhs
, const SourceSend
&rhs
)
16 { return lhs
.mSource
== rhs
.mSource
&& lhs
.mSend
== rhs
.mSend
; }
17 static inline bool operator!=(const SourceSend
&lhs
, const SourceSend
&rhs
)
18 { return !(lhs
== rhs
); }
21 AuxiliaryEffectSlotImpl::AuxiliaryEffectSlotImpl(ContextImpl
&context
) : mContext(context
)
24 mContext
.alGenAuxiliaryEffectSlots(1, &mId
);
25 throw_al_error("Failed to create AuxiliaryEffectSlot");
28 AuxiliaryEffectSlotImpl::~AuxiliaryEffectSlotImpl()
30 if(UNLIKELY(mId
!= 0) && alcGetCurrentContext() == mContext
.getALCcontext())
32 mContext
.alDeleteAuxiliaryEffectSlots(1, &mId
);
37 void AuxiliaryEffectSlotImpl::addSourceSend(SourceSend source_send
)
39 auto iter
= std::lower_bound(mSourceSends
.begin(), mSourceSends
.end(), source_send
);
40 if(iter
== mSourceSends
.end() || *iter
!= source_send
)
41 mSourceSends
.insert(iter
, source_send
);
44 void AuxiliaryEffectSlotImpl::removeSourceSend(SourceSend source_send
)
46 auto iter
= std::lower_bound(mSourceSends
.begin(), mSourceSends
.end(), source_send
);
47 if(iter
!= mSourceSends
.end() && *iter
== source_send
)
48 mSourceSends
.erase(iter
);
52 DECL_THUNK1(void, AuxiliaryEffectSlot
, setGain
,, ALfloat
)
53 void AuxiliaryEffectSlotImpl::setGain(ALfloat gain
)
55 if(!(gain
>= 0.0f
&& gain
<= 1.0f
))
56 throw std::domain_error("Gain out of range");
57 CheckContext(mContext
);
58 mContext
.alAuxiliaryEffectSlotf(mId
, AL_EFFECTSLOT_GAIN
, gain
);
61 DECL_THUNK1(void, AuxiliaryEffectSlot
, setSendAuto
,, bool)
62 void AuxiliaryEffectSlotImpl::setSendAuto(bool sendauto
)
64 CheckContext(mContext
);
65 mContext
.alAuxiliaryEffectSloti(mId
, AL_EFFECTSLOT_AUXILIARY_SEND_AUTO
, sendauto
? AL_TRUE
: AL_FALSE
);
68 DECL_THUNK1(void, AuxiliaryEffectSlot
, applyEffect
,, Effect
)
69 void AuxiliaryEffectSlotImpl::applyEffect(Effect effect
)
71 const EffectImpl
*eff
= effect
.getHandle();
72 if(eff
) CheckContexts(mContext
, eff
->getContext());
73 CheckContext(mContext
);
75 mContext
.alAuxiliaryEffectSloti(mId
,
76 AL_EFFECTSLOT_EFFECT
, eff
? eff
->getId() : AL_EFFECT_NULL
81 void AuxiliaryEffectSlot::destroy()
83 AuxiliaryEffectSlotImpl
*i
= pImpl
;
87 void AuxiliaryEffectSlotImpl::destroy()
89 CheckContext(mContext
);
91 if(!mSourceSends
.empty())
93 Vector
<SourceSend
> source_sends
;
94 source_sends
.swap(mSourceSends
);
96 auto batcher
= mContext
.getBatcher();
97 for(const SourceSend
&srcsend
: source_sends
)
98 srcsend
.mSource
.getHandle()->setAuxiliarySend(nullptr, srcsend
.mSend
);
102 mContext
.alDeleteAuxiliaryEffectSlots(1, &mId
);
103 throw_al_error("AuxiliaryEffectSlot failed to delete");
106 mContext
.freeEffectSlot(this);
109 DECL_THUNK0(Vector
<SourceSend
>, AuxiliaryEffectSlot
, getSourceSends
, const)
110 DECL_THUNK0(size_t, AuxiliaryEffectSlot
, getUseCount
, const)