Compare commits
7 Commits
ebdd35b1e1
...
1.0.4
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f5e24fa9c | |||
| cdffa1b50b | |||
| eec9e25e12 | |||
| 3b4853acda | |||
| cea13986f0 | |||
| 3641ffdad9 | |||
| 7fa68792fb |
@@ -1,13 +1,44 @@
|
|||||||
#include "ApplicationData.h"
|
#include "ApplicationData.h"
|
||||||
|
#include "Util.h"
|
||||||
|
#include "AudioApi.h"
|
||||||
|
#include <functiondiscoverykeys.h>
|
||||||
|
|
||||||
AudioDevice::AudioDevice()
|
AudioDevice::AudioDevice(IMMDevice* device, LPCWSTR deviceId)
|
||||||
{
|
{
|
||||||
|
id = std::wstring(deviceId);
|
||||||
|
|
||||||
|
IPropertyStore* propertyStore;
|
||||||
|
HRESULT err = device->OpenPropertyStore(STGM_READ, &propertyStore);
|
||||||
|
isError(err, "Failed to open prop store: ");
|
||||||
|
|
||||||
|
PROPVARIANT deviceNameProp;
|
||||||
|
const wchar_t* deviceName;
|
||||||
|
err = getDevicePropertyString(propertyStore, PKEY_Device_FriendlyName, &deviceNameProp, deviceName);
|
||||||
|
isError(err, "Failed to read name of device :");
|
||||||
|
name = utf8Encode(deviceName);
|
||||||
|
|
||||||
|
err = device->GetState(&state);
|
||||||
|
isError(err, "Failed to reat state of device: ");
|
||||||
|
|
||||||
|
err = device->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&volumeInterface);
|
||||||
|
isError(err, "Failed to get audio endpoint volume interface: ");
|
||||||
|
|
||||||
|
err = device->Activate(__uuidof(IAudioMeterInformation), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&meterInterface);
|
||||||
|
isError(err, "Failed to get audio meter interface: ");
|
||||||
|
|
||||||
|
getVolumeLimit(volumeInterface, &minVolumeDb, &maxVolumeDb);
|
||||||
|
|
||||||
|
if (propertyStore)
|
||||||
|
{
|
||||||
|
propertyStore->Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioDevice::AudioDevice(AudioDevice&& other) noexcept
|
AudioDevice::AudioDevice(AudioDevice&& other) noexcept
|
||||||
: device(other.device), volumeInterface(other.volumeInterface), meterInterface(other.meterInterface),
|
: device(other.device), volumeInterface(other.volumeInterface), meterInterface(other.meterInterface),
|
||||||
id(other.id), name(other.name), state(other.state),
|
id(other.id), name(other.name), state(other.state),
|
||||||
isDefaultConsole(other.isDefaultConsole), isDefaultMedia(other.isDefaultMedia), isDefaultCommunication(other.isDefaultCommunication)
|
isDefaultConsole(other.isDefaultConsole), isDefaultMedia(other.isDefaultMedia), isDefaultCommunication(other.isDefaultCommunication),
|
||||||
|
minVolumeDb(other.minVolumeDb), maxVolumeDb(other.maxVolumeDb)
|
||||||
{
|
{
|
||||||
other.device = nullptr;
|
other.device = nullptr;
|
||||||
other.volumeInterface = nullptr;
|
other.volumeInterface = nullptr;
|
||||||
@@ -25,6 +56,8 @@ AudioDevice& AudioDevice::operator=(AudioDevice&& other) noexcept
|
|||||||
this->isDefaultConsole = other.isDefaultConsole;
|
this->isDefaultConsole = other.isDefaultConsole;
|
||||||
this->isDefaultMedia = other.isDefaultMedia;
|
this->isDefaultMedia = other.isDefaultMedia;
|
||||||
this->isDefaultCommunication = other.isDefaultCommunication;
|
this->isDefaultCommunication = other.isDefaultCommunication;
|
||||||
|
this->minVolumeDb = other.minVolumeDb;
|
||||||
|
this->maxVolumeDb = other.maxVolumeDb;
|
||||||
|
|
||||||
other.device = nullptr;
|
other.device = nullptr;
|
||||||
other.volumeInterface = nullptr;
|
other.volumeInterface = nullptr;
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ public:
|
|||||||
std::wstring id = {};
|
std::wstring id = {};
|
||||||
std::string name = {};
|
std::string name = {};
|
||||||
unsigned long state = {};
|
unsigned long state = {};
|
||||||
bool isDefaultConsole = {};
|
bool isDefaultConsole = false;
|
||||||
bool isDefaultMedia = {};
|
bool isDefaultMedia = false;
|
||||||
bool isDefaultCommunication = {};
|
bool isDefaultCommunication = false;
|
||||||
|
float minVolumeDb = 0.f;
|
||||||
|
float maxVolumeDb = 0.f;
|
||||||
|
|
||||||
AudioDevice();
|
AudioDevice(IMMDevice* device, LPCWSTR deviceId);
|
||||||
AudioDevice(AudioDevice&& other) noexcept;
|
AudioDevice(AudioDevice&& other) noexcept;
|
||||||
AudioDevice& operator=(AudioDevice&& other) noexcept;
|
AudioDevice& operator=(AudioDevice&& other) noexcept;
|
||||||
~AudioDevice();
|
~AudioDevice();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "AsuroTool.h"
|
#include "AsuroTool.h"
|
||||||
|
|
||||||
|
const size_t MAX_FONT_PATH_LENGTH = 2048;
|
||||||
const UINT TRAY_ID = 420;
|
const UINT TRAY_ID = 420;
|
||||||
const UINT WMAPP_NOTIFYCALLBACK = WM_APP + 1;
|
const UINT WMAPP_NOTIFYCALLBACK = WM_APP + 1;
|
||||||
|
|
||||||
@@ -34,6 +36,13 @@ bool isHidden = false;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
std::wstring appDir;
|
||||||
|
getAppDir(appDir);
|
||||||
|
if (_wchdir(appDir.c_str()) != 0)
|
||||||
|
{
|
||||||
|
std::cout << "Failed to set working dir." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ApplicationData applicationData{};
|
ApplicationData applicationData{};
|
||||||
ImGuiCallbacks callbacks{};
|
ImGuiCallbacks callbacks{};
|
||||||
|
|
||||||
@@ -46,20 +55,30 @@ int main()
|
|||||||
|
|
||||||
void init(DrawData& drawData, ApplicationData& appData)
|
void init(DrawData& drawData, ApplicationData& appData)
|
||||||
{
|
{
|
||||||
|
std::wstring appPath;
|
||||||
|
getAppDir(appPath);
|
||||||
|
char appPathStr[MAX_FONT_PATH_LENGTH];
|
||||||
|
HRESULT convResult = WideCharToMultiByte(CP_UTF8, NULL, &appPath[0], -1, appPathStr, MAX_FONT_PATH_LENGTH, NULL, nullptr);
|
||||||
|
isError(convResult, "Failed to convert path: ");
|
||||||
|
|
||||||
// sad :(
|
// sad :(
|
||||||
gDrawData = &drawData;
|
gDrawData = &drawData;
|
||||||
gAppData = &appData;
|
gAppData = &appData;
|
||||||
|
|
||||||
// Load text font
|
// Load text font
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.Fonts->AddFontFromFileTTF("Montserrat-Regular.ttf", 18.0f);
|
std::string fontPath = std::string(appPathStr);
|
||||||
|
fontPath.append("\\Montserrat-Regular.ttf");
|
||||||
|
io.Fonts->AddFontFromFileTTF(fontPath.c_str(), 18.0f);
|
||||||
|
|
||||||
// Load icon font
|
// Load icon font
|
||||||
static const ImWchar icons_ranges[] = { 0xEA01, 0xF2DF, 0 };
|
static const ImWchar icons_ranges[] = { 0xEA01, 0xF2DF, 0 };
|
||||||
ImFontConfig icons_config;
|
ImFontConfig icons_config;
|
||||||
icons_config.MergeMode = true;
|
icons_config.MergeMode = true;
|
||||||
icons_config.PixelSnapH = true;
|
icons_config.PixelSnapH = true;
|
||||||
io.Fonts->AddFontFromFileTTF("remixicon.ttf", 14.0f, &icons_config, icons_ranges);
|
std::string iconFontPath = std::string(appPathStr);
|
||||||
|
iconFontPath.append("\\remixicon.ttf");
|
||||||
|
io.Fonts->AddFontFromFileTTF(iconFontPath.c_str(), 14.0f, &icons_config, icons_ranges);
|
||||||
|
|
||||||
// Set window icon
|
// Set window icon
|
||||||
HINSTANCE instance = GetModuleHandle(NULL);
|
HINSTANCE instance = GetModuleHandle(NULL);
|
||||||
@@ -286,8 +305,8 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
|
|||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
if (dev.state == DEVICE_STATE_ACTIVE)
|
if (dev.state == DEVICE_STATE_ACTIVE)
|
||||||
{
|
{
|
||||||
// Log scale because it looks better (no actual reason for these exact numbers)
|
static std::array<float, 2> meterValues{};
|
||||||
float meterValue = log10f(getMeterValue(dev.meterInterface) * 9. + 1.);
|
UINT channelCount = getMeterValues(dev.meterInterface, meterValues);
|
||||||
|
|
||||||
auto drawList = ImGui::GetWindowDrawList();
|
auto drawList = ImGui::GetWindowDrawList();
|
||||||
ImVec2 windowPos = ImGui::GetWindowPos();
|
ImVec2 windowPos = ImGui::GetWindowPos();
|
||||||
@@ -298,21 +317,32 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
|
|||||||
const float linePaddingX = 3.;
|
const float linePaddingX = 3.;
|
||||||
cursorPos.x += linePaddingX;
|
cursorPos.x += linePaddingX;
|
||||||
|
|
||||||
|
// BG line
|
||||||
drawList->AddLine(ImVec2(cursorPos.x, lineY), ImVec2(cursorPos.x + (space.x - 2. * linePaddingX), lineY), IM_COL32(120, 120, 120, 255), 2.);
|
drawList->AddLine(ImVec2(cursorPos.x, lineY), ImVec2(cursorPos.x + (space.x - 2. * linePaddingX), lineY), IM_COL32(120, 120, 120, 255), 2.);
|
||||||
drawList->AddLine(ImVec2(cursorPos.x, lineY), ImVec2(cursorPos.x + (space.x - 2. * linePaddingX) * meterValue, lineY), IM_COL32(200, 200, 255, 255), 3.);
|
|
||||||
|
// Channel lines
|
||||||
|
if (channelCount == 1)
|
||||||
|
{
|
||||||
|
drawList->AddLine(ImVec2(cursorPos.x, lineY), ImVec2(cursorPos.x + (space.x - 2. * linePaddingX) * meterValues[0], lineY), IM_COL32(200, 200, 255, 255), 3.);
|
||||||
|
}
|
||||||
|
if (channelCount == 2)
|
||||||
|
{
|
||||||
|
drawList->AddLine(ImVec2(cursorPos.x, lineY - 2), ImVec2(cursorPos.x + (space.x - 2. * linePaddingX) * meterValues[0], lineY - 2), IM_COL32(200, 200, 255, 255), 3.);
|
||||||
|
drawList->AddLine(ImVec2(cursorPos.x, lineY + 2), ImVec2(cursorPos.x + (space.x - 2. * linePaddingX) * meterValues[1], lineY + 2), IM_COL32(200, 200, 255, 255), 3.);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SetNextItemWidth(space.x);
|
||||||
|
ImGui::PushID(&dev.id);
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0));
|
||||||
|
|
||||||
float volume = getVolume(dev.volumeInterface);
|
float volume = getVolume(dev.volumeInterface);
|
||||||
float prevVolume = volume;
|
if (ImGui::SliderFloat("", &volume, 0., 1., "", ImGuiSliderFlags_NoRoundToFormat | ImGuiSliderFlags_AlwaysClamp))
|
||||||
ImGui::SetNextItemWidth(space.x);
|
|
||||||
ImGui::PushID(dev.device);
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0));
|
|
||||||
ImGui::SliderFloat("", &volume, 0., 1., "", ImGuiSliderFlags_NoRoundToFormat | ImGuiSliderFlags_AlwaysClamp);
|
|
||||||
ImGui::PopStyleColor();
|
|
||||||
ImGui::PopID();
|
|
||||||
if (prevVolume != volume)
|
|
||||||
{
|
{
|
||||||
setVolume(dev.volumeInterface, volume);
|
setVolume(dev.volumeInterface, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
|
|||||||
@@ -13,5 +13,4 @@ ImVec2 menuBar(DrawData& drawData, ApplicationData& appData);
|
|||||||
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title);
|
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title);
|
||||||
void drawCircle(float radius, ImU32 color);
|
void drawCircle(float radius, ImU32 color);
|
||||||
|
|
||||||
void GenerateTrayUUID(UUID* uuid);
|
|
||||||
LRESULT trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam);
|
LRESULT trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam);
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ IDI_ICON1 ICON "kaiju.ico"
|
|||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,0,1,1
|
FILEVERSION 1,0,4,1
|
||||||
PRODUCTVERSION 1,0,1,1
|
PRODUCTVERSION 1,0,4,1
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
@@ -89,12 +89,12 @@ BEGIN
|
|||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "Asuro"
|
VALUE "CompanyName", "Asuro"
|
||||||
VALUE "FileDescription", "Audio Thingy"
|
VALUE "FileDescription", "Audio Thingy"
|
||||||
VALUE "FileVersion", "1.0.1.1"
|
VALUE "FileVersion", "1.0.4.1"
|
||||||
VALUE "InternalName", "AsuroTool.exe"
|
VALUE "InternalName", "AsuroTool.exe"
|
||||||
VALUE "LegalCopyright", "Copyright (C) 2022"
|
VALUE "LegalCopyright", "Copyright (C) 2022"
|
||||||
VALUE "OriginalFilename", "AsuroTool.exe"
|
VALUE "OriginalFilename", "AsuroTool.exe"
|
||||||
VALUE "ProductName", "Audio Thingy"
|
VALUE "ProductName", "Audio Thingy"
|
||||||
VALUE "ProductVersion", "1.0.1.1"
|
VALUE "ProductVersion", "1.0.4.1"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|||||||
@@ -97,6 +97,9 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>pathcch.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@@ -114,6 +117,9 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>pathcch.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -127,6 +133,9 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>pathcch.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@@ -144,6 +153,9 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>pathcch.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <functiondiscoverykeys.h>
|
#include <functiondiscoverykeys.h>
|
||||||
#include <endpointvolume.h>
|
#include <endpointvolume.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@@ -66,57 +67,35 @@ void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList
|
|||||||
|
|
||||||
for (UINT i = 0; i < deviceCount; i += 1)
|
for (UINT i = 0; i < deviceCount; i += 1)
|
||||||
{
|
{
|
||||||
AudioDevice deviceData{};
|
IMMDevice* device;
|
||||||
|
err = deviceCollection->Item(i, &device);
|
||||||
err = deviceCollection->Item(i, &deviceData.device);
|
|
||||||
if (isError(err, std::stringstream("Failed to get device ") << i << ": "))
|
if (isError(err, std::stringstream("Failed to get device ") << i << ": "))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
LPWSTR deviceId;
|
LPWSTR deviceId;
|
||||||
err = deviceData.device->GetId(&deviceId);
|
err = device->GetId(&deviceId);
|
||||||
isError(err, std::stringstream("Failed to get device id ") << i << ": ");
|
if (!isError(err, std::stringstream("Failed to get device id ") << i << ": "))
|
||||||
deviceData.id = std::wstring(deviceId);
|
|
||||||
|
|
||||||
IPropertyStore* propertyStore;
|
|
||||||
err = deviceData.device->OpenPropertyStore(STGM_READ, &propertyStore);
|
|
||||||
isError(err, std::stringstream("Failed to open device ") << i << "prop store: ");
|
|
||||||
|
|
||||||
PROPVARIANT deviceNameProp;
|
|
||||||
const wchar_t* deviceName;
|
|
||||||
err = getDevicePropertyString(propertyStore, PKEY_Device_FriendlyName, &deviceNameProp, deviceName);
|
|
||||||
isError(err, std::stringstream("Failed to read name of device ") << i << ": ");
|
|
||||||
deviceData.name = utf8Encode(deviceName);
|
|
||||||
|
|
||||||
err = deviceData.device->GetState(&deviceData.state);
|
|
||||||
isError(err, std::stringstream("Failed to reat state of device ") << i << ": ");
|
|
||||||
|
|
||||||
err = deviceData.device->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&deviceData.volumeInterface);
|
|
||||||
isError(err, "Failed to get audio endpoint volume interface: ");
|
|
||||||
|
|
||||||
err = deviceData.device->Activate(__uuidof(IAudioMeterInformation), CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&deviceData.meterInterface);
|
|
||||||
isError(err, "Failed to get audio meter interface: ");
|
|
||||||
|
|
||||||
if (defaultConsoleId)
|
|
||||||
{
|
{
|
||||||
deviceData.isDefaultConsole = wcscmp(defaultConsoleId, deviceId) == 0;
|
AudioDevice audioDevice(device, deviceId);
|
||||||
}
|
|
||||||
if (defaultMediaId)
|
if (defaultConsoleId)
|
||||||
{
|
{
|
||||||
deviceData.isDefaultMedia = wcscmp(defaultMediaId, deviceId) == 0;
|
audioDevice.isDefaultConsole = wcscmp(defaultConsoleId, deviceId) == 0;
|
||||||
}
|
}
|
||||||
if (defaultCommunicationId)
|
if (defaultMediaId)
|
||||||
{
|
{
|
||||||
deviceData.isDefaultCommunication = wcscmp(defaultCommunicationId, deviceId) == 0;
|
audioDevice.isDefaultMedia = wcscmp(defaultMediaId, deviceId) == 0;
|
||||||
|
}
|
||||||
|
if (defaultCommunicationId)
|
||||||
|
{
|
||||||
|
audioDevice.isDefaultCommunication = wcscmp(defaultCommunicationId, deviceId) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
deviceList.push_back(std::move(audioDevice));
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceList.push_back(std::move(deviceData));
|
|
||||||
|
|
||||||
if (propertyStore)
|
|
||||||
{
|
|
||||||
propertyStore->Release();
|
|
||||||
}
|
|
||||||
CoTaskMemFree(deviceId);
|
CoTaskMemFree(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,13 +157,18 @@ void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume)
|
|||||||
isError(hr, "Failed to set volume level: ");
|
isError(hr, "Failed to set volume level: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
float getMeterValue(IAudioMeterInformation* meterInterface)
|
UINT getMeterValues(IAudioMeterInformation* meterInterface, std::array<float, 2>& outLevels)
|
||||||
{
|
{
|
||||||
float volume;
|
UINT channelCount;
|
||||||
if (FAILED(meterInterface->GetPeakValue(&volume)))
|
if (FAILED(meterInterface->GetMeteringChannelCount(&channelCount)) || channelCount > 2) return 0;
|
||||||
{
|
|
||||||
volume = 0.;
|
|
||||||
}
|
|
||||||
|
|
||||||
return volume;
|
if (FAILED(meterInterface->GetChannelsPeakValues(channelCount, &outLevels[0]))) return 0;
|
||||||
|
|
||||||
|
return channelCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getVolumeLimit(IAudioEndpointVolume* volumeInterface, float* outMin, float* outMax)
|
||||||
|
{
|
||||||
|
float dummy;
|
||||||
|
volumeInterface->GetVolumeRange(outMin, outMax, &dummy);
|
||||||
}
|
}
|
||||||
@@ -14,4 +14,5 @@ void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole
|
|||||||
|
|
||||||
float getVolume(IAudioEndpointVolume* volumeInterface);
|
float getVolume(IAudioEndpointVolume* volumeInterface);
|
||||||
void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume);
|
void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume);
|
||||||
float getMeterValue(IAudioMeterInformation* meterInterface);
|
UINT getMeterValues(IAudioMeterInformation* meterInterface, std::array<float, 2>& levels);
|
||||||
|
void getVolumeLimit(IAudioEndpointVolume* volumeInterface, float* outMin, float* outMax);
|
||||||
@@ -34,7 +34,25 @@ HRESULT __stdcall AudioNotificationListener::OnDeviceAdded(LPCWSTR pwstrDeviceId
|
|||||||
HRESULT result = audioData->deviceEnumerator->GetDevice(pwstrDeviceId, &newDevice);
|
HRESULT result = audioData->deviceEnumerator->GetDevice(pwstrDeviceId, &newDevice);
|
||||||
if (SUCCEEDED(result) && newDevice != nullptr)
|
if (SUCCEEDED(result) && newDevice != nullptr)
|
||||||
{
|
{
|
||||||
// TODO: add to device list
|
IMMEndpoint* endpoint;
|
||||||
|
result = newDevice->QueryInterface(&endpoint);
|
||||||
|
if (SUCCEEDED(result) && endpoint != nullptr)
|
||||||
|
{
|
||||||
|
EDataFlow dataFlow;
|
||||||
|
result = endpoint->GetDataFlow(&dataFlow);
|
||||||
|
if (SUCCEEDED(result))
|
||||||
|
{
|
||||||
|
AudioDevice audioDevice(newDevice, pwstrDeviceId);
|
||||||
|
if (dataFlow == EDataFlow::eCapture)
|
||||||
|
{
|
||||||
|
audioData->recordingDevices.push_back(std::move(audioDevice));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
audioData->playbackDevices.push_back(std::move(audioDevice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -50,7 +68,9 @@ HRESULT __stdcall AudioNotificationListener::OnDeviceRemoved(LPCWSTR pwstrDevice
|
|||||||
if (wcscmp(deviceListIterator->id.c_str(), pwstrDeviceId) == 0)
|
if (wcscmp(deviceListIterator->id.c_str(), pwstrDeviceId) == 0)
|
||||||
{
|
{
|
||||||
deviceListIterator = deviceList.erase(deviceListIterator);
|
deviceListIterator = deviceList.erase(deviceListIterator);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
deviceListIterator++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -81,12 +81,9 @@ void setAutostart(bool newValue)
|
|||||||
if (newValue)
|
if (newValue)
|
||||||
{
|
{
|
||||||
std::wstring appPath;
|
std::wstring appPath;
|
||||||
appPath.resize(MAX_PATH_LENGTH);
|
if (FAILED(getAppPath(appPath))) return;
|
||||||
hr = GetModuleFileName(NULL, &appPath[0], static_cast<DWORD>(appPath.size()));
|
|
||||||
if (isError(hr, "Failed to get executable name: ")) return;
|
|
||||||
appPath.resize(wcslen(appPath.data()));
|
|
||||||
|
|
||||||
hr = RegSetValueEx(runKey, KEY_APP_NAME, 0, REG_SZ, (BYTE*)appPath.c_str(), (appPath.size() + 1) * sizeof(wchar_t));
|
hr = RegSetValueEx(runKey, KEY_APP_NAME, 0, REG_SZ, (BYTE*)appPath.c_str(), static_cast<DWORD>((appPath.size() + 1) * sizeof(wchar_t)));
|
||||||
if (isError(hr, "Failed to write autostart key: ")) return;
|
if (isError(hr, "Failed to write autostart key: ")) return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "pathcch.h"
|
||||||
|
|
||||||
bool isError(const HRESULT result, const std::stringstream message)
|
bool isError(const HRESULT result, const std::stringstream message)
|
||||||
{
|
{
|
||||||
@@ -29,3 +30,24 @@ std::string utf8Encode(const std::wstring& wstr)
|
|||||||
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &resultString[0], sizeNeeded, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &resultString[0], sizeNeeded, NULL, NULL);
|
||||||
return resultString;
|
return resultString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HRESULT getAppPath(std::wstring& outPath)
|
||||||
|
{
|
||||||
|
const size_t MAX_PATH_LENGTH = 32767;
|
||||||
|
outPath.resize(MAX_PATH_LENGTH);
|
||||||
|
HRESULT hr = GetModuleFileName(NULL, &outPath[0], static_cast<DWORD>(outPath.size()));
|
||||||
|
if (isError(hr, "Failed to get executable name: ")) return hr;
|
||||||
|
outPath.resize(wcslen(outPath.data()));
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT getAppDir(std::wstring& outPath)
|
||||||
|
{
|
||||||
|
HRESULT hr = getAppPath(outPath);
|
||||||
|
if (FAILED(hr)) return hr;
|
||||||
|
|
||||||
|
hr = PathCchRemoveFileSpec(&outPath[0], static_cast<DWORD>(outPath.size()));
|
||||||
|
if (isError(hr, "Failed to get executable dir: ")) return hr;
|
||||||
|
outPath.resize(wcslen(outPath.data()));
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
@@ -6,3 +6,5 @@
|
|||||||
bool isError(const HRESULT result, const std::stringstream message);
|
bool isError(const HRESULT result, const std::stringstream message);
|
||||||
bool isError(const HRESULT result, const char* message);
|
bool isError(const HRESULT result, const char* message);
|
||||||
std::string utf8Encode(const std::wstring& wstr);
|
std::string utf8Encode(const std::wstring& wstr);
|
||||||
|
HRESULT getAppPath(std::wstring& outPath);
|
||||||
|
HRESULT getAppDir(std::wstring& outPath);
|
||||||
|
|||||||
@@ -107,6 +107,8 @@
|
|||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>E:\Code\glfw-3.3.7.bin.WIN64\lib-vc2022;D:\Applications\VulkanSDK\1.2.182.0\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>E:\Code\glfw-3.3.7.bin.WIN64\lib-vc2022;D:\Applications\VulkanSDK\1.2.182.0\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@@ -130,6 +132,8 @@
|
|||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>E:\Code\glfw-3.3.7.bin.WIN64\lib-vc2022;D:\Applications\VulkanSDK\1.2.182.0\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>E:\Code\glfw-3.3.7.bin.WIN64\lib-vc2022;D:\Applications\VulkanSDK\1.2.182.0\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -149,6 +153,8 @@
|
|||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>E:\Code\glfw-3.3.7.bin.WIN64\lib-vc2022;D:\Applications\VulkanSDK\1.2.182.0\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>E:\Code\glfw-3.3.7.bin.WIN64\lib-vc2022;D:\Applications\VulkanSDK\1.2.182.0\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@@ -172,6 +178,8 @@
|
|||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>E:\Code\glfw-3.3.7.bin.WIN64\lib-vc2022;D:\Applications\VulkanSDK\1.2.182.0\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>E:\Code\glfw-3.3.7.bin.WIN64\lib-vc2022;D:\Applications\VulkanSDK\1.2.182.0\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -96,6 +96,8 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@@ -112,6 +114,8 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -124,6 +128,8 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@@ -140,6 +146,8 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<IgnoreSpecificDefaultLibraries>
|
||||||
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user