more cleanup
This commit is contained in:
@@ -28,8 +28,9 @@ class __declspec(uuid("3bc52579-15fd-43bb-9686-6273c238535e")) TrayGUID;
|
||||
UINT const WMAPP_NOTIFYCALLBACK = WM_APP + 1;
|
||||
UINT const WMAPP_HIDEFLYOUT = WM_APP + 2;
|
||||
|
||||
DrawData* hackyDrawData;
|
||||
ApplicationData* hackyAppData;
|
||||
// Globals for use in callbacks
|
||||
DrawData* gDrawData;
|
||||
ApplicationData* gAppData;
|
||||
bool justDocked = false;
|
||||
bool isHidden = false;
|
||||
|
||||
@@ -45,32 +46,11 @@ int main()
|
||||
startImgui(callbacks, "Audio Thingy", 600, 400);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (code >= 0)
|
||||
{
|
||||
CWPSTRUCT* data = (CWPSTRUCT*)lParam;
|
||||
|
||||
if (data->message == WMAPP_NOTIFYCALLBACK)
|
||||
{
|
||||
switch (data->lParam)
|
||||
{
|
||||
case NIN_SELECT:
|
||||
glfwShowWindow(hackyDrawData->window);
|
||||
glfwRestoreWindow(hackyDrawData->window);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CallNextHookEx(NULL, code, wParam, lParam);
|
||||
}
|
||||
|
||||
void init(DrawData& drawData, ApplicationData& appData)
|
||||
{
|
||||
// sad :(
|
||||
hackyDrawData = &drawData;
|
||||
hackyAppData = &appData;
|
||||
gDrawData = &drawData;
|
||||
gAppData = &appData;
|
||||
|
||||
// Load text font
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
@@ -118,7 +98,7 @@ void init(DrawData& drawData, ApplicationData& appData)
|
||||
|
||||
// Set window minimize behavior
|
||||
glfwSetWindowIconifyCallback(drawData.window, [](GLFWwindow* window, int isIconified) {
|
||||
if (isIconified && hackyAppData->settings.docked)
|
||||
if (isIconified && gAppData->settings.docked)
|
||||
{
|
||||
glfwHideWindow(window);
|
||||
}
|
||||
@@ -126,7 +106,7 @@ void init(DrawData& drawData, ApplicationData& appData)
|
||||
});
|
||||
|
||||
glfwSetWindowFocusCallback(drawData.window, [](GLFWwindow* window, int isFocused) {
|
||||
if (!isFocused && hackyAppData->settings.docked && !justDocked)
|
||||
if (!isFocused && gAppData->settings.docked && !justDocked)
|
||||
{
|
||||
glfwIconifyWindow(window);
|
||||
}
|
||||
@@ -136,18 +116,7 @@ void init(DrawData& drawData, ApplicationData& appData)
|
||||
initSettings(drawData, appData);
|
||||
|
||||
// Set up audio device api
|
||||
HRESULT audioResult;
|
||||
audioResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||
isError(audioResult, "Failed to initialize COM: ");
|
||||
|
||||
audioResult = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&appData.audioData->deviceEnumerator));
|
||||
isError(audioResult, "Failed to set up audio device enumerator: ");
|
||||
|
||||
appData.audioData->audioNotificationListener = new AudioNotificationListener(appData.audioData);
|
||||
audioResult = appData.audioData->deviceEnumerator->RegisterEndpointNotificationCallback(appData.audioData->audioNotificationListener);
|
||||
isError(audioResult, "Failed to register audio notification listener: ");
|
||||
|
||||
reloadDeviceLists(*appData.audioData);
|
||||
initAudio(appData);
|
||||
}
|
||||
|
||||
void draw(DrawData& drawData, ApplicationData& appData)
|
||||
@@ -155,8 +124,8 @@ void draw(DrawData& drawData, ApplicationData& appData)
|
||||
justDocked = false;
|
||||
|
||||
// sad :(
|
||||
hackyDrawData = &drawData;
|
||||
hackyAppData = &appData;
|
||||
gDrawData = &drawData;
|
||||
gAppData = &appData;
|
||||
|
||||
// Actual Drawing
|
||||
if (isHidden)
|
||||
@@ -400,3 +369,24 @@ void drawCircle(float radius, ImU32 color)
|
||||
ImVec2 windowPos = ImGui::GetWindowPos();
|
||||
drawList->AddCircleFilled(ImVec2(cursorPos.x + windowPos.x, cursorPos.y + windowPos.y + ImGui::GetTextLineHeight() / 2.), radius, color);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (code >= 0)
|
||||
{
|
||||
CWPSTRUCT* data = (CWPSTRUCT*)lParam;
|
||||
|
||||
if (data->message == WMAPP_NOTIFYCALLBACK)
|
||||
{
|
||||
switch (data->lParam)
|
||||
{
|
||||
case NIN_SELECT:
|
||||
glfwShowWindow(gDrawData->window);
|
||||
glfwRestoreWindow(gDrawData->window);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CallNextHookEx(NULL, code, wParam, lParam);
|
||||
}
|
||||
|
||||
@@ -12,3 +12,5 @@ void cleanup(DrawData& drawData, ApplicationData& appData);
|
||||
ImVec2 menuBar(DrawData& drawData, ApplicationData& appData);
|
||||
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title);
|
||||
void drawCircle(float radius, ImU32 color);
|
||||
|
||||
LRESULT trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
@@ -47,9 +47,6 @@
|
||||
<ClInclude Include="Util.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="PolicyConfig.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ApplicationData.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -65,6 +62,9 @@
|
||||
<ClInclude Include="Settings.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="PolicyConfig.h">
|
||||
<Filter>Header Files\Audio</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CopyFileToFolders Include="Montserrat-Regular.ttf">
|
||||
|
||||
@@ -10,31 +10,20 @@
|
||||
#include "AudioApi.h"
|
||||
#include "PolicyConfig.h"
|
||||
|
||||
HRESULT getDeviceProperty(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData)
|
||||
void initAudio(ApplicationData& appData)
|
||||
{
|
||||
PropVariantInit(outData);
|
||||
HRESULT nameResult = propertyStore->GetValue(propertyKey, outData);
|
||||
return nameResult;
|
||||
}
|
||||
HRESULT audioResult;
|
||||
audioResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||
isError(audioResult, "Failed to initialize COM: ");
|
||||
|
||||
HRESULT getDevicePropertyString(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData, const wchar_t*& outString, const wchar_t* defaultStr)
|
||||
{
|
||||
HRESULT result = getDeviceProperty(propertyStore, propertyKey, outData);
|
||||
outString = outData->vt != VT_LPWSTR ? defaultStr : outData->pwszVal;
|
||||
return result;
|
||||
}
|
||||
audioResult = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&appData.audioData->deviceEnumerator));
|
||||
isError(audioResult, "Failed to set up audio device enumerator: ");
|
||||
|
||||
void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole role)
|
||||
{
|
||||
IPolicyConfigVista* pPolicyConfig;
|
||||
appData.audioData->audioNotificationListener = new AudioNotificationListener(appData.audioData);
|
||||
audioResult = appData.audioData->deviceEnumerator->RegisterEndpointNotificationCallback(appData.audioData->audioNotificationListener);
|
||||
isError(audioResult, "Failed to register audio notification listener: ");
|
||||
|
||||
HRESULT hr = CoCreateInstance(__uuidof(CPolicyConfigVistaClient), NULL, CLSCTX_ALL, __uuidof(IPolicyConfigVista), (LPVOID*)&pPolicyConfig);
|
||||
if (!isError(hr, "Failed to set default audio device: "))
|
||||
{
|
||||
hr = pPolicyConfig->SetDefaultEndpoint(deviceId, role);
|
||||
pPolicyConfig->Release();
|
||||
reloadDeviceLists(audioData);
|
||||
}
|
||||
reloadDeviceLists(*appData.audioData);
|
||||
}
|
||||
|
||||
void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList, EDataFlow deviceType)
|
||||
@@ -145,6 +134,33 @@ void reloadDeviceLists(AudioData& audioData)
|
||||
loadAudioDevices(audioData, audioData.recordingDevices, EDataFlow::eCapture);
|
||||
}
|
||||
|
||||
HRESULT getDeviceProperty(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData)
|
||||
{
|
||||
PropVariantInit(outData);
|
||||
HRESULT nameResult = propertyStore->GetValue(propertyKey, outData);
|
||||
return nameResult;
|
||||
}
|
||||
|
||||
HRESULT getDevicePropertyString(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData, const wchar_t*& outString, const wchar_t* defaultStr)
|
||||
{
|
||||
HRESULT result = getDeviceProperty(propertyStore, propertyKey, outData);
|
||||
outString = outData->vt != VT_LPWSTR ? defaultStr : outData->pwszVal;
|
||||
return result;
|
||||
}
|
||||
|
||||
void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole role)
|
||||
{
|
||||
IPolicyConfigVista* pPolicyConfig;
|
||||
|
||||
HRESULT hr = CoCreateInstance(__uuidof(CPolicyConfigVistaClient), NULL, CLSCTX_ALL, __uuidof(IPolicyConfigVista), (LPVOID*)&pPolicyConfig);
|
||||
if (!isError(hr, "Failed to set default audio device: "))
|
||||
{
|
||||
hr = pPolicyConfig->SetDefaultEndpoint(deviceId, role);
|
||||
pPolicyConfig->Release();
|
||||
reloadDeviceLists(audioData);
|
||||
}
|
||||
}
|
||||
|
||||
float getVolume(IAudioEndpointVolume* volumeInterface)
|
||||
{
|
||||
float volume;
|
||||
|
||||
@@ -4,11 +4,14 @@
|
||||
|
||||
#include "ApplicationData.h"
|
||||
|
||||
void initAudio(ApplicationData& appData);
|
||||
void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList, EDataFlow deviceType);
|
||||
void reloadDeviceLists(AudioData& audioData);
|
||||
|
||||
HRESULT getDeviceProperty(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData);
|
||||
HRESULT getDevicePropertyString(IPropertyStore* propertyStore, const PROPERTYKEY propertyKey, PROPVARIANT* outData, const wchar_t*& outString, const wchar_t* defaultStr = L"Unknown");
|
||||
void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole role);
|
||||
void loadAudioDevices(AudioData& audioData, std::vector<AudioDevice>& deviceList, EDataFlow deviceType);
|
||||
void reloadDeviceLists(AudioData& audioData);
|
||||
|
||||
float getVolume(IAudioEndpointVolume* volumeInterface);
|
||||
void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume);
|
||||
float getMeterValue(IAudioMeterInformation* meterInterface);
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "Settings.h"
|
||||
|
||||
extern bool justDocked;
|
||||
extern DrawData* hackyDrawData;
|
||||
extern ApplicationData* hackyAppData;
|
||||
extern DrawData* gDrawData;
|
||||
extern ApplicationData* gAppData;
|
||||
|
||||
void initSettings(DrawData& drawData, ApplicationData& appData)
|
||||
{
|
||||
@@ -22,7 +22,7 @@ void initSettings(DrawData& drawData, ApplicationData& appData)
|
||||
|
||||
void* settingsReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name)
|
||||
{
|
||||
ApplicationSettings* settings = &hackyAppData->settings;
|
||||
ApplicationSettings* settings = &gAppData->settings;
|
||||
*settings = ApplicationSettings();
|
||||
return (void*)settings;
|
||||
}
|
||||
@@ -46,8 +46,8 @@ void settingsReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* en
|
||||
void settingsWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* outBuf)
|
||||
{
|
||||
outBuf->appendf("[%s][%s]\n", "ApplicationSettings", "ApplicationSettings");
|
||||
outBuf->appendf("docked=%i\n", (int)hackyAppData->settings.docked);
|
||||
outBuf->appendf("autostart=%i\n", (int)hackyAppData->settings.autostart);
|
||||
outBuf->appendf("docked=%i\n", (int)gAppData->settings.docked);
|
||||
outBuf->appendf("autostart=%i\n", (int)gAppData->settings.autostart);
|
||||
outBuf->append("\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user