7 #include "core/logging.h"
13 ALCenum
EnumFromEventType(const alc::EventType type
)
17 case alc::EventType::DefaultDeviceChanged
: return ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT
;
18 case alc::EventType::DeviceAdded
: return ALC_EVENT_TYPE_DEVICE_ADDED_SOFT
;
19 case alc::EventType::DeviceRemoved
: return ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT
;
20 case alc::EventType::Count
: break;
22 throw std::runtime_error
{"Invalid EventType: "+std::to_string(al::to_underlying(type
))};
29 std::optional
<alc::EventType
> GetEventType(ALCenum type
)
33 case ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT
: return alc::EventType::DefaultDeviceChanged
;
34 case ALC_EVENT_TYPE_DEVICE_ADDED_SOFT
: return alc::EventType::DeviceAdded
;
35 case ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT
: return alc::EventType::DeviceRemoved
;
40 void Event(EventType eventType
, DeviceType deviceType
, ALCdevice
*device
, std::string_view message
) noexcept
42 auto eventlock
= std::unique_lock
{EventMutex
};
43 if(EventCallback
&& EventsEnabled
.test(al::to_underlying(eventType
)))
44 EventCallback(EnumFromEventType(eventType
), al::to_underlying(deviceType
), device
,
45 static_cast<ALCsizei
>(message
.length()), message
.data(), EventUserPtr
);
50 FORCE_ALIGN ALCboolean ALC_APIENTRY
alcEventControlSOFT(ALCsizei count
, const ALCenum
*events
,
51 ALCboolean enable
) noexcept
53 if(enable
!= ALC_FALSE
&& enable
!= ALC_TRUE
)
55 alcSetError(nullptr, ALC_INVALID_ENUM
);
60 alcSetError(nullptr, ALC_INVALID_VALUE
);
67 alcSetError(nullptr, ALC_INVALID_VALUE
);
71 alc::EventBitSet eventSet
{0};
72 for(ALCenum type
: al::span
{events
, static_cast<ALCuint
>(count
)})
74 auto etype
= alc::GetEventType(type
);
77 WARN("Invalid event type: 0x%04x\n", type
);
78 alcSetError(nullptr, ALC_INVALID_ENUM
);
81 eventSet
.set(al::to_underlying(*etype
));
84 auto eventlock
= std::unique_lock
{alc::EventMutex
};
85 if(enable
) alc::EventsEnabled
|= eventSet
;
86 else alc::EventsEnabled
&= ~eventSet
;
90 FORCE_ALIGN
void ALC_APIENTRY
alcEventCallbackSOFT(ALCEVENTPROCTYPESOFT callback
, void *userParam
) noexcept
92 auto eventlock
= std::unique_lock
{alc::EventMutex
};
93 alc::EventCallback
= callback
;
94 alc::EventUserPtr
= userParam
;