]> git.tdb.fi Git - ext/openal.git/blob - al/eax/fx_slots.cpp
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / al / eax / fx_slots.cpp
1 #include "config.h"
2
3 #include "fx_slots.h"
4
5 #include <array>
6
7 #include "api.h"
8 #include "exception.h"
9
10
11 namespace
12 {
13
14
15 class EaxFxSlotsException :
16     public EaxException
17 {
18 public:
19     explicit EaxFxSlotsException(
20         const char* message)
21         :
22         EaxException{"EAX_FX_SLOTS", message}
23     {
24     }
25 }; // EaxFxSlotsException
26
27
28 } // namespace
29
30
31 void EaxFxSlots::initialize(ALCcontext& al_context)
32 {
33     initialize_fx_slots(al_context);
34 }
35
36 void EaxFxSlots::uninitialize() noexcept
37 {
38     for (auto& fx_slot : fx_slots_)
39     {
40         fx_slot = nullptr;
41     }
42 }
43
44 const ALeffectslot& EaxFxSlots::get(EaxFxSlotIndex index) const
45 {
46     if(!index.has_value())
47         fail("Empty index.");
48     return *fx_slots_[index.value()];
49 }
50
51 ALeffectslot& EaxFxSlots::get(EaxFxSlotIndex index)
52 {
53     if(!index.has_value())
54         fail("Empty index.");
55     return *fx_slots_[index.value()];
56 }
57
58 [[noreturn]]
59 void EaxFxSlots::fail(
60     const char* message)
61 {
62     throw EaxFxSlotsException{message};
63 }
64
65 void EaxFxSlots::initialize_fx_slots(ALCcontext& al_context)
66 {
67     auto fx_slot_index = EaxFxSlotIndexValue{};
68
69     for (auto& fx_slot : fx_slots_)
70     {
71         fx_slot = eax_create_al_effect_slot(al_context);
72         fx_slot->eax_initialize(al_context, fx_slot_index);
73         fx_slot_index += 1;
74     }
75 }