From ff28e7c86e7e4bed6d300be66a31c73ed40dc667 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 17 Feb 2024 00:40:55 +0100 Subject: [PATCH] Add ASIO device finder --- src/CMakeLists.txt | 2 +- src/engine/asiodevicefinder.cpp | 92 +++++++++++++++++++++++++++++++++ src/engine/asiodevicefinder.h | 41 +++++++++++++++ src/engine/devicefinders.cpp | 2 + 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/engine/asiodevicefinder.cpp create mode 100644 src/engine/asiodevicefinder.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b695dd6b..c8f06b3c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -850,7 +850,7 @@ optional_source(WIN32 HEADERS core/windows7thumbbar.h ) -optional_source(MSVC SOURCES engine/uwpdevicefinder.cpp) +optional_source(MSVC SOURCES engine/uwpdevicefinder.cpp engine/asiodevicefinder.cpp) optional_source(HAVE_SUBSONIC SOURCES diff --git a/src/engine/asiodevicefinder.cpp b/src/engine/asiodevicefinder.cpp new file mode 100644 index 00000000..5373b83e --- /dev/null +++ b/src/engine/asiodevicefinder.cpp @@ -0,0 +1,92 @@ +/* + * Strawberry Music Player + * Copyright 2024, Jonas Kvinge + * + * Strawberry is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Strawberry is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Strawberry. If not, see . + * + */ + +#include +#include +#include +#include + +#include + +#include "asiodevicefinder.h" +#include "enginedevice.h" +#include "core/logging.h" + +AsioDeviceFinder::AsioDeviceFinder() : DeviceFinder("asio", { "asiosink" }) {} + +EngineDeviceList AsioDeviceFinder::ListDevices() { + + EngineDeviceList devices; + + HKEY reg_key = nullptr; + LSTATUS status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"software\\asio", 0, KEY_READ, ®_key); + + for (DWORD i = 0; status == ERROR_SUCCESS; i++) { + WCHAR key_name[256]; + status = RegEnumKeyW(reg_key, i, key_name, sizeof(key_name)); + EngineDevice device = GetDevice(reg_key, key_name); + if (device.value.isValid()) { + devices.append(device); + } + } + + if (reg_key) { + RegCloseKey(reg_key); + } + + return devices; + +} + +EngineDevice AsioDeviceFinder::GetDevice(HKEY reg_key, LPWSTR key_name) { + + HKEY sub_key = nullptr; + const QScopeGuard scopeguard_sub_key = qScopeGuard([sub_key]() { + if (sub_key) { + RegCloseKey(sub_key); + } + }); + + LSTATUS status = RegOpenKeyExW(reg_key, key_name, 0, KEY_READ, &sub_key); + if (status != ERROR_SUCCESS) { + return EngineDevice(); + } + + DWORD type = REG_SZ; + WCHAR clsid_data[256]{}; + DWORD clsid_data_size = sizeof(clsid_data); + status = RegQueryValueExW(sub_key, L"clsid", 0, &type, (LPBYTE)clsid_data, &clsid_data_size); + if (status != ERROR_SUCCESS) { + return EngineDevice(); + } + + EngineDevice device; + device.value = QString::fromStdWString(clsid_data); + device.description = QString::fromStdWString(key_name); + + WCHAR desc_data[256]{}; + DWORD desc_data_size = sizeof(desc_data); + status = RegQueryValueExW(sub_key, L"description", 0, &type, (LPBYTE)desc_data, &desc_data_size); + if (status == ERROR_SUCCESS) { + device.description = QString::fromStdWString(desc_data); + } + + return device; + +} diff --git a/src/engine/asiodevicefinder.h b/src/engine/asiodevicefinder.h new file mode 100644 index 00000000..a6d66860 --- /dev/null +++ b/src/engine/asiodevicefinder.h @@ -0,0 +1,41 @@ +/* + * Strawberry Music Player + * Copyright 2024, Jonas Kvinge + * + * Strawberry is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Strawberry is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Strawberry. If not, see . + * + */ + +#ifndef ASIODEVICEFINDER_H +#define ASIODEVICEFINDER_H + +#include "config.h" + +#include + +#include "devicefinder.h" +#include "enginedevice.h" + +class AsioDeviceFinder : public DeviceFinder { + public: + explicit AsioDeviceFinder(); + + virtual bool Initialize() { return true; } + virtual EngineDeviceList ListDevices(); + + private: + EngineDevice GetDevice(HKEY reg_key, LPWSTR key_name); +}; + +#endif // ASIODEVICEFINDER_H diff --git a/src/engine/devicefinders.cpp b/src/engine/devicefinders.cpp index 4f86c425..2c5f93a1 100644 --- a/src/engine/devicefinders.cpp +++ b/src/engine/devicefinders.cpp @@ -45,6 +45,7 @@ # include "mmdevicefinder.h" # ifdef _MSC_VER # include "uwpdevicefinder.h" +# include "asiodevicefinder.h" # endif // _MSC_VER #endif // Q_OS_WIN32 @@ -73,6 +74,7 @@ void DeviceFinders::Init() { device_finders.append(new MMDeviceFinder); # ifdef _MSC_VER device_finders.append(new UWPDeviceFinder); + device_finders.append(new AsioDeviceFinder); # endif // _MSC_VER #endif // Q_OS_WIN32