#pragma once #define NOMINMAX #include #include #include #include #include #include #include #include #include #include #include #include class MicrophoneDevice { public: using mute_changed_cb_t = std::function; private: friend struct VolumeNotifier; struct VolumeNotifier : winrt::implements { MicrophoneDevice* _subscribedDevice = nullptr; VolumeNotifier(MicrophoneDevice* subscribedDevice); virtual HRESULT __stdcall OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA data) override; }; wil::unique_cotaskmem_string _id; wil::unique_prop_variant _friendly_name; mute_changed_cb_t _mute_changed_callback; winrt::com_ptr _notifier; wil::com_ptr_nothrow _endpoint; wil::com_ptr_nothrow _device; constexpr static inline std::wstring_view FALLBACK_NAME = L"Unknown device"; constexpr static inline std::wstring_view FALLBACK_ID = L"UNKNOWN_ID"; public: MicrophoneDevice(MicrophoneDevice&&) noexcept = delete; MicrophoneDevice(const MicrophoneDevice&) noexcept = delete; MicrophoneDevice(wil::com_ptr_nothrow device, wil::com_ptr_nothrow endpoint); ~MicrophoneDevice(); bool active() const noexcept; void set_muted(const bool muted) noexcept; bool muted() const noexcept; void toggle_muted() noexcept; std::wstring_view id() const noexcept; std::wstring_view name() const noexcept; void set_mute_changed_callback(mute_changed_cb_t callback) noexcept; static std::unique_ptr getDefault(); static std::vector> getAllActive(); };