From e3b64261e015bdc1e469ee65e18411555b61a7f3 Mon Sep 17 00:00:00 2001 From: Squall-Leonhart Date: Wed, 8 Nov 2023 17:29:14 +1100 Subject: [PATCH] Custom Implementation for Default Device selection Tested on Windows Requires OSX/Linux testing. --- src/audio/CubebAPI.cpp | 12 ++++++++---- src/audio/CubebInputAPI.cpp | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/audio/CubebAPI.cpp b/src/audio/CubebAPI.cpp index 09e450113a..48b24ab1a7 100644 --- a/src/audio/CubebAPI.cpp +++ b/src/audio/CubebAPI.cpp @@ -188,15 +188,19 @@ std::vector CubebAPI::GetDevices() return {}; std::vector result; - result.reserve(devices.count); + result.reserve(devices.count + 1); // Reserve space for the default device + + // Add the default device to the list + auto defaultDevice = std::make_shared(nullptr, "default", L"Default Device"); + result.emplace_back(defaultDevice); + for (size_t i = 0; i < devices.count; ++i) { - //const auto& device = devices.device[i]; if (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED) { auto device = std::make_shared(devices.device[i].devid, devices.device[i].device_id, - boost::nowide::widen( - devices.device[i].friendly_name)); + boost::nowide::widen( + devices.device[i].friendly_name)); result.emplace_back(device); } } diff --git a/src/audio/CubebInputAPI.cpp b/src/audio/CubebInputAPI.cpp index de030fdc5b..c387ee1822 100644 --- a/src/audio/CubebInputAPI.cpp +++ b/src/audio/CubebInputAPI.cpp @@ -180,15 +180,19 @@ std::vector CubebInputAPI::GetDevices() return {}; std::vector result; - result.reserve(devices.count); + result.reserve(devices.count + 1); // Reserve space for the default device + + // Add the default device to the list + auto defaultDevice = std::make_shared(nullptr, "default", L"Default Device"); + result.emplace_back(defaultDevice); + for (size_t i = 0; i < devices.count; ++i) { - //const auto& device = devices.device[i]; if (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED) { auto device = std::make_shared(devices.device[i].devid, devices.device[i].device_id, - boost::nowide::widen( - devices.device[i].friendly_name)); + boost::nowide::widen( + devices.device[i].friendly_name)); result.emplace_back(device); } }