fx_slots.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "config.h"
  2. #include "fx_slots.h"
  3. #include <array>
  4. #include "api.h"
  5. #include "exception.h"
  6. namespace
  7. {
  8. class EaxFxSlotsException :
  9. public EaxException
  10. {
  11. public:
  12. explicit EaxFxSlotsException(
  13. const char* message)
  14. :
  15. EaxException{"EAX_FX_SLOTS", message}
  16. {
  17. }
  18. }; // EaxFxSlotsException
  19. } // namespace
  20. void EaxFxSlots::initialize(ALCcontext& al_context)
  21. {
  22. initialize_fx_slots(al_context);
  23. }
  24. void EaxFxSlots::uninitialize() noexcept
  25. {
  26. for (auto& fx_slot : fx_slots_)
  27. {
  28. fx_slot = nullptr;
  29. }
  30. }
  31. const ALeffectslot& EaxFxSlots::get(EaxFxSlotIndex index) const
  32. {
  33. if(!index.has_value())
  34. fail("Empty index.");
  35. return *fx_slots_[index.value()];
  36. }
  37. ALeffectslot& EaxFxSlots::get(EaxFxSlotIndex index)
  38. {
  39. if(!index.has_value())
  40. fail("Empty index.");
  41. return *fx_slots_[index.value()];
  42. }
  43. [[noreturn]]
  44. void EaxFxSlots::fail(
  45. const char* message)
  46. {
  47. throw EaxFxSlotsException{message};
  48. }
  49. void EaxFxSlots::initialize_fx_slots(ALCcontext& al_context)
  50. {
  51. auto fx_slot_index = EaxFxSlotIndexValue{};
  52. for (auto& fx_slot : fx_slots_)
  53. {
  54. fx_slot = eax_create_al_effect_slot(al_context);
  55. fx_slot->eax_initialize(al_context, fx_slot_index);
  56. fx_slot_index += 1;
  57. }
  58. }