aboutsummaryrefslogtreecommitdiffstats
path: root/al/eax_fx_slots.cpp
blob: 41b18f7774bfdfaf524c40c3c5d86409d4c81a1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "eax_fx_slots.h"

#include <array>

#include "eax_exception.h"

#include "eax_api.h"


namespace
{


class EaxFxSlotsException :
    public EaxException
{
public:
    explicit EaxFxSlotsException(
        const char* message)
        :
        EaxException{"EAX_FX_SLOTS", message}
    {
    }
}; // EaxFxSlotsException


} // namespace


void EaxFxSlots::initialize(
    ALCcontext& al_context)
{
    initialize_fx_slots(al_context);
}

void EaxFxSlots::uninitialize() noexcept
{
    for (auto& fx_slot : fx_slots_)
    {
        fx_slot->eax_uninitialize();
        fx_slot = nullptr;
    }
}

const ALeffectslot& EaxFxSlots::get(
    EaxFxSlotIndex index) const
{
    if (!index.has_value())
    {
        fail("Empty index.");
    }

    return *fx_slots_[index.get()];
}

ALeffectslot& EaxFxSlots::get(
    EaxFxSlotIndex index)
{
    return const_cast<ALeffectslot&>(const_cast<const EaxFxSlots*>(this)->get(index));
}


[[noreturn]]
void EaxFxSlots::fail(
    const char* message)
{
    throw EaxFxSlotsException{message};
}

void EaxFxSlots::initialize_fx_slots(
    ALCcontext& al_context)
{
    auto fx_slot_index = EaxFxSlotIndexValue{};

    for (auto& fx_slot : fx_slots_)
    {
        fx_slot = eax_create_al_effect_slot(al_context);
        fx_slot->eax_initialize(al_context, fx_slot_index);
        fx_slot_index += 1;
    }
}