From 4f40ceaadee419d9ee115cc3fd3ae16b5900f4ef Mon Sep 17 00:00:00 2001 From: Hane Date: Thu, 26 Jan 2023 19:42:18 +0100 Subject: [PATCH 1/3] testo da --- .gitignore | 6 ++ bueno.bat | 2 + qtest.pro | 7 ++ src/back/testmain.cpp | 227 ++++++++++++++++++++++++++++++++++++++++++ src/qt/mainwindow.cpp | 24 +++++ src/qt/mainwindow.h | 16 +++ src/qtestmain.cpp | 25 +++++ 7 files changed, 307 insertions(+) create mode 100644 .gitignore create mode 100644 bueno.bat create mode 100644 qtest.pro create mode 100644 src/back/testmain.cpp create mode 100644 src/qt/mainwindow.cpp create mode 100644 src/qt/mainwindow.h create mode 100644 src/qtestmain.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fde2162 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +build +*.rdbg +*.pdb +Makefile +Makefile.Debug +Makefile.Release \ No newline at end of file diff --git a/bueno.bat b/bueno.bat new file mode 100644 index 0000000..cd190f0 --- /dev/null +++ b/bueno.bat @@ -0,0 +1,2 @@ +qmake -o build\Makefile .\qtest.pro +mingw32-make.exe -C .\build -f Makefile.Release diff --git a/qtest.pro b/qtest.pro new file mode 100644 index 0000000..35ebcaa --- /dev/null +++ b/qtest.pro @@ -0,0 +1,7 @@ +QT += widgets +INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" +DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" +VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" +SOURCES += qtestmain.cpp mainwindow.cpp +HEADERS += mainwindow.h +#DESTDIR += "build" diff --git a/src/back/testmain.cpp b/src/back/testmain.cpp new file mode 100644 index 0000000..ea700e1 --- /dev/null +++ b/src/back/testmain.cpp @@ -0,0 +1,227 @@ +#define WIN32_LEAN_AND_MEAN + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +//#include +//#include +#include + + +//#define EXIT_ON_ERROR(hres, className) \ + if (FAILED(hres)) { printf("%s\n", #className); goto Exit; } + + +#define EXIT_ON_ERROR(hres) \ + if (FAILED(hres)) { printf("%s - %d\n", __FILE__, __LINE__); goto Exit; } + + +#define SAFE_RELEASE(punk) \ + if ((punk) != NULL) \ + { (punk)->Release(); (punk) = NULL; } + +//#pragma once + +/* + * Comentarios patrocinados por David + * Enviar mensaje a @Phireh + */ + +// const IID IntID_IAudioEndpointVolume = __uuidof(IAudioEndpointVolume); + +IMMDeviceEnumerator *deviceEnumeratorPtr = NULL; +IMMDeviceCollection *deviceCollectionPtr = NULL; +IMMDevice *endpointPtr = NULL; + +IAudioEndpointVolume *endpointVolumePtr = NULL; +IAudioSessionManager2 *sessionManagerPtr = NULL; + +IAudioSessionEnumerator *sessionEnumeratorPtr = NULL; +IAudioSessionControl2 *sessionControl2Ptr = NULL; +ISimpleAudioVolume *sessionVolumePtr = NULL; + +void PrintEndpointNames() { + + HRESULT hr = S_OK; + IPropertyStore *deviceEndpointPropertiesPtr = NULL; + LPWSTR endpointID = NULL; + + hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + EXIT_ON_ERROR(hr) + + //MMDeviceEnumerator es el CLSID de toda la vaina de MMDevicear + hr = CoCreateInstance( + __uuidof(MMDeviceEnumerator), NULL, + CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), + (void**)&deviceEnumeratorPtr); + EXIT_ON_ERROR(hr) + + //hr = deviceEnumeratorPtr->EnumAudioEndpoints(eRender, DEVICE_STATE_&deviceCollectionPtr); + //Llamar a dispositivo por defecto. 2o param no importa lmao + hr = deviceEnumeratorPtr->GetDefaultAudioEndpoint(eRender, eConsole, &endpointPtr); + EXIT_ON_ERROR(hr) + + // UINT count; + // hr = deviceCollectionPtr->GetCount(&count); + // EXIT_ON_ERROR(hr) + + // if (count == 0) { + // printf("No endpoints found.\n"); + // } + + // hr = deviceCollectionPtr->Item(i, &endpointPtr); + // EXIT_ON_ERROR(hr) + + //RECUPERAR ENDPOINT ID + hr = endpointPtr->GetId(&endpointID); + EXIT_ON_ERROR(hr) + + //RECUPERAR STRUCT DE PROPIEDADES + hr = endpointPtr->OpenPropertyStore(STGM_READ, &deviceEndpointPropertiesPtr); + EXIT_ON_ERROR(hr) + + + PROPVARIANT varName; + // Initialize container for property value. + PropVariantInit(&varName); + + // Get the endpoint's friendly-name property. + hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName); + EXIT_ON_ERROR(hr) + + //PINTAR ID + PROPIEDAD RECUPERADA + printf("Endpoint %d: \"%S\" (%S)\n", 0, varName.pwszVal, endpointID); + + + //Activamos desde Device para tener control sobre el Endpoint + hr = endpointPtr->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolumePtr); + EXIT_ON_ERROR(hr) + + hr = endpointVolumePtr->SetMasterVolumeLevelScalar(0.4f, NULL); + EXIT_ON_ERROR(hr); + + //Registramos el gestor de sesiones para conseguir el handle que da el handle de sesiones a nivel informativo + //Y justo despues, el que da control a nivel sonoro xdddddddddddddddddddddddddddddddddddddddddddddd + hr = endpointPtr->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**) &sessionManagerPtr); + EXIT_ON_ERROR(hr); + + + //Ahora si viene el handle de las sesiones xdddddddddd + hr = sessionManagerPtr->GetSessionEnumerator(&sessionEnumeratorPtr); + EXIT_ON_ERROR(hr); + + //Cogemos el numero de sesiones y recorremos para coger cada una + //Luego tho, que soy una puta vaga y hay que probar cositas + INT sessionCount; + hr = sessionEnumeratorPtr->GetCount(&sessionCount); + EXIT_ON_ERROR(hr); + + hr = sessionEnumeratorPtr->GetSession(2, (IAudioSessionControl**)&sessionControl2Ptr); + EXIT_ON_ERROR(hr); + + LPWSTR sessionDisplayName; + hr = sessionControl2Ptr->GetDisplayName(&sessionDisplayName); + EXIT_ON_ERROR(hr); + + + printf("Sesion 0 de endpoint %S: \"%S\" \n Num sesiones: (%d)\n", varName.pwszVal, sessionDisplayName, sessionCount); + + //hr = sessionControlPtr->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl2Ptr); + //EXIT_ON_ERROR(hr); + + //hr = sessionControl2Ptr->GetProcessId(&foundProcessId); + //EXIT_ON_ERROR(hr); + + hr = sessionControl2Ptr->QueryInterface(__uuidof(ISimpleAudioVolume), (void**)&sessionVolumePtr); + EXIT_ON_ERROR(hr); + + hr = sessionVolumePtr->SetMute(TRUE, 0); + EXIT_ON_ERROR(hr); + + //Limpiamos memoria + CoTaskMemFree(endpointID); + endpointID = NULL; + PropVariantClear(&varName); + SAFE_RELEASE(deviceEndpointPropertiesPtr) + SAFE_RELEASE(endpointPtr) + SAFE_RELEASE(endpointVolumePtr); + SAFE_RELEASE(sessionManagerPtr); + SAFE_RELEASE(sessionEnumeratorPtr); + SAFE_RELEASE(sessionControlPtr); + SAFE_RELEASE(sessionControl2Ptr); + SAFE_RELEASE(sessionVolumePtr); +/* + // Each loop prints the name of an endpoint device. + for (ULONG i = 0; i < count; i++) { + // Get pointer to endpoint number i. + hr = deviceCollectionPtr->Item(i, &endpointPtr); + EXIT_ON_ERROR(hr) + + // Get the endpoint ID string. + hr = endpointPtr->GetId(&endpointID); + EXIT_ON_ERROR(hr) + + hr = endpointPtr->OpenPropertyStore(STGM_READ, &deviceEndpointPropertiesPtr); + EXIT_ON_ERROR(hr) + + PROPVARIANT varName; + // Initialize container for property value. + PropVariantInit(&varName); + + // Get the endpoint's friendly-name property.2 + hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName); + EXIT_ON_ERROR(hr) + + // Print endpoint friendly name and endpoint ID. + printf("Endpoint %lu: \"%S\" (%S)\n", i, varName.pwszVal, endpointID); + + + + + + CoTaskMemFree(endpointID); + endpointID = NULL; + PropVariantClear(&varName); + SAFE_RELEASE(deviceEndpointPropertiesPtr) + SAFE_RELEASE(endpointPtr) + } +*/ + SAFE_RELEASE(deviceEnumeratorPtr) + SAFE_RELEASE(deviceCollectionPtr) + return; + +Exit: + printf("Error!\n"); + CoTaskMemFree(endpointID); + SAFE_RELEASE(deviceEnumeratorPtr) + SAFE_RELEASE(deviceCollectionPtr) + SAFE_RELEASE(endpointPtr) + SAFE_RELEASE(deviceEndpointPropertiesPtr) + CoUninitialize(); +} + +void onExit(){ + + + + + +} + + + +int main (int argc, char* argv[]) { + PrintEndpointNames(); +} diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp new file mode 100644 index 0000000..e406fae --- /dev/null +++ b/src/qt/mainwindow.cpp @@ -0,0 +1,24 @@ +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { + // setWindowState(Qt::WindowFullScreen); + // setCentralWidget(centralWidget); +} + +/* + * void MainWindow::setPlotButton() { + * button = new QPushButton("push"), + * button->setCheckable(true); + * connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))) + * QHBoxLayout *plotsLayout = new QHBoxLayout; + * plotsLayout->setSpacing(10); + * plotsLayout->addWidget(funPlot); + * QHBoxLayout *buttonsLayout = new QHBoxLayout ; + * buttonsLayout->addWidget(button); + * QVBoxLayout *widgetLayout = new QVBoxLayout; + * widgetLayout->addLayout(plotsLayout); + * widgetLayout->addLayout(buttonsLayout); + * setLayout(widgetLayout); + * ... + */ + diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h new file mode 100644 index 0000000..b3ab242 --- /dev/null +++ b/src/qt/mainwindow.h @@ -0,0 +1,16 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include + +class MainWindow : public QMainWindow { + Q_OBJECT + //QWidget *centralWidget; + + public: + MainWindow(QWidget *parent = nullptr); + + }; + +#endif diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp new file mode 100644 index 0000000..c200413 --- /dev/null +++ b/src/qtestmain.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include +#include + +//#include +#include +#include + +#include "mainwindow.h" + +QApplication* createApplication(int &argc, char *argv[]) +{ + return new QApplication(argc, argv); +} + + +int main (int argc, char* argv[]) { + QApplication::setStyle("windowsvista"); + QScopedPointer app(createApplication(argc, argv)); + MainWindow window = MainWindow(); + window.show(); + return app->exec(); +} From cd2d0b5da82b74fcca59008ae81101ba2eae7c44 Mon Sep 17 00:00:00 2001 From: Hane Date: Thu, 26 Jan 2023 19:42:18 +0100 Subject: [PATCH 2/3] to da --- .gitignore | 6 ++ bueno.bat | 2 + qtest.pro | 7 ++ src/back/testmain.cpp | 227 ++++++++++++++++++++++++++++++++++++++++++ src/qt/mainwindow.cpp | 24 +++++ src/qt/mainwindow.h | 16 +++ src/qtestmain.cpp | 25 +++++ 7 files changed, 307 insertions(+) create mode 100644 .gitignore create mode 100644 bueno.bat create mode 100644 qtest.pro create mode 100644 src/back/testmain.cpp create mode 100644 src/qt/mainwindow.cpp create mode 100644 src/qt/mainwindow.h create mode 100644 src/qtestmain.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fde2162 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +build +*.rdbg +*.pdb +Makefile +Makefile.Debug +Makefile.Release \ No newline at end of file diff --git a/bueno.bat b/bueno.bat new file mode 100644 index 0000000..cd190f0 --- /dev/null +++ b/bueno.bat @@ -0,0 +1,2 @@ +qmake -o build\Makefile .\qtest.pro +mingw32-make.exe -C .\build -f Makefile.Release diff --git a/qtest.pro b/qtest.pro new file mode 100644 index 0000000..35ebcaa --- /dev/null +++ b/qtest.pro @@ -0,0 +1,7 @@ +QT += widgets +INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" +DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" +VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" +SOURCES += qtestmain.cpp mainwindow.cpp +HEADERS += mainwindow.h +#DESTDIR += "build" diff --git a/src/back/testmain.cpp b/src/back/testmain.cpp new file mode 100644 index 0000000..ea700e1 --- /dev/null +++ b/src/back/testmain.cpp @@ -0,0 +1,227 @@ +#define WIN32_LEAN_AND_MEAN + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +//#include +//#include +#include + + +//#define EXIT_ON_ERROR(hres, className) \ + if (FAILED(hres)) { printf("%s\n", #className); goto Exit; } + + +#define EXIT_ON_ERROR(hres) \ + if (FAILED(hres)) { printf("%s - %d\n", __FILE__, __LINE__); goto Exit; } + + +#define SAFE_RELEASE(punk) \ + if ((punk) != NULL) \ + { (punk)->Release(); (punk) = NULL; } + +//#pragma once + +/* + * Comentarios patrocinados por David + * Enviar mensaje a @Phireh + */ + +// const IID IntID_IAudioEndpointVolume = __uuidof(IAudioEndpointVolume); + +IMMDeviceEnumerator *deviceEnumeratorPtr = NULL; +IMMDeviceCollection *deviceCollectionPtr = NULL; +IMMDevice *endpointPtr = NULL; + +IAudioEndpointVolume *endpointVolumePtr = NULL; +IAudioSessionManager2 *sessionManagerPtr = NULL; + +IAudioSessionEnumerator *sessionEnumeratorPtr = NULL; +IAudioSessionControl2 *sessionControl2Ptr = NULL; +ISimpleAudioVolume *sessionVolumePtr = NULL; + +void PrintEndpointNames() { + + HRESULT hr = S_OK; + IPropertyStore *deviceEndpointPropertiesPtr = NULL; + LPWSTR endpointID = NULL; + + hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + EXIT_ON_ERROR(hr) + + //MMDeviceEnumerator es el CLSID de toda la vaina de MMDevicear + hr = CoCreateInstance( + __uuidof(MMDeviceEnumerator), NULL, + CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), + (void**)&deviceEnumeratorPtr); + EXIT_ON_ERROR(hr) + + //hr = deviceEnumeratorPtr->EnumAudioEndpoints(eRender, DEVICE_STATE_&deviceCollectionPtr); + //Llamar a dispositivo por defecto. 2o param no importa lmao + hr = deviceEnumeratorPtr->GetDefaultAudioEndpoint(eRender, eConsole, &endpointPtr); + EXIT_ON_ERROR(hr) + + // UINT count; + // hr = deviceCollectionPtr->GetCount(&count); + // EXIT_ON_ERROR(hr) + + // if (count == 0) { + // printf("No endpoints found.\n"); + // } + + // hr = deviceCollectionPtr->Item(i, &endpointPtr); + // EXIT_ON_ERROR(hr) + + //RECUPERAR ENDPOINT ID + hr = endpointPtr->GetId(&endpointID); + EXIT_ON_ERROR(hr) + + //RECUPERAR STRUCT DE PROPIEDADES + hr = endpointPtr->OpenPropertyStore(STGM_READ, &deviceEndpointPropertiesPtr); + EXIT_ON_ERROR(hr) + + + PROPVARIANT varName; + // Initialize container for property value. + PropVariantInit(&varName); + + // Get the endpoint's friendly-name property. + hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName); + EXIT_ON_ERROR(hr) + + //PINTAR ID + PROPIEDAD RECUPERADA + printf("Endpoint %d: \"%S\" (%S)\n", 0, varName.pwszVal, endpointID); + + + //Activamos desde Device para tener control sobre el Endpoint + hr = endpointPtr->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolumePtr); + EXIT_ON_ERROR(hr) + + hr = endpointVolumePtr->SetMasterVolumeLevelScalar(0.4f, NULL); + EXIT_ON_ERROR(hr); + + //Registramos el gestor de sesiones para conseguir el handle que da el handle de sesiones a nivel informativo + //Y justo despues, el que da control a nivel sonoro xdddddddddddddddddddddddddddddddddddddddddddddd + hr = endpointPtr->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**) &sessionManagerPtr); + EXIT_ON_ERROR(hr); + + + //Ahora si viene el handle de las sesiones xdddddddddd + hr = sessionManagerPtr->GetSessionEnumerator(&sessionEnumeratorPtr); + EXIT_ON_ERROR(hr); + + //Cogemos el numero de sesiones y recorremos para coger cada una + //Luego tho, que soy una puta vaga y hay que probar cositas + INT sessionCount; + hr = sessionEnumeratorPtr->GetCount(&sessionCount); + EXIT_ON_ERROR(hr); + + hr = sessionEnumeratorPtr->GetSession(2, (IAudioSessionControl**)&sessionControl2Ptr); + EXIT_ON_ERROR(hr); + + LPWSTR sessionDisplayName; + hr = sessionControl2Ptr->GetDisplayName(&sessionDisplayName); + EXIT_ON_ERROR(hr); + + + printf("Sesion 0 de endpoint %S: \"%S\" \n Num sesiones: (%d)\n", varName.pwszVal, sessionDisplayName, sessionCount); + + //hr = sessionControlPtr->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl2Ptr); + //EXIT_ON_ERROR(hr); + + //hr = sessionControl2Ptr->GetProcessId(&foundProcessId); + //EXIT_ON_ERROR(hr); + + hr = sessionControl2Ptr->QueryInterface(__uuidof(ISimpleAudioVolume), (void**)&sessionVolumePtr); + EXIT_ON_ERROR(hr); + + hr = sessionVolumePtr->SetMute(TRUE, 0); + EXIT_ON_ERROR(hr); + + //Limpiamos memoria + CoTaskMemFree(endpointID); + endpointID = NULL; + PropVariantClear(&varName); + SAFE_RELEASE(deviceEndpointPropertiesPtr) + SAFE_RELEASE(endpointPtr) + SAFE_RELEASE(endpointVolumePtr); + SAFE_RELEASE(sessionManagerPtr); + SAFE_RELEASE(sessionEnumeratorPtr); + SAFE_RELEASE(sessionControlPtr); + SAFE_RELEASE(sessionControl2Ptr); + SAFE_RELEASE(sessionVolumePtr); +/* + // Each loop prints the name of an endpoint device. + for (ULONG i = 0; i < count; i++) { + // Get pointer to endpoint number i. + hr = deviceCollectionPtr->Item(i, &endpointPtr); + EXIT_ON_ERROR(hr) + + // Get the endpoint ID string. + hr = endpointPtr->GetId(&endpointID); + EXIT_ON_ERROR(hr) + + hr = endpointPtr->OpenPropertyStore(STGM_READ, &deviceEndpointPropertiesPtr); + EXIT_ON_ERROR(hr) + + PROPVARIANT varName; + // Initialize container for property value. + PropVariantInit(&varName); + + // Get the endpoint's friendly-name property.2 + hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName); + EXIT_ON_ERROR(hr) + + // Print endpoint friendly name and endpoint ID. + printf("Endpoint %lu: \"%S\" (%S)\n", i, varName.pwszVal, endpointID); + + + + + + CoTaskMemFree(endpointID); + endpointID = NULL; + PropVariantClear(&varName); + SAFE_RELEASE(deviceEndpointPropertiesPtr) + SAFE_RELEASE(endpointPtr) + } +*/ + SAFE_RELEASE(deviceEnumeratorPtr) + SAFE_RELEASE(deviceCollectionPtr) + return; + +Exit: + printf("Error!\n"); + CoTaskMemFree(endpointID); + SAFE_RELEASE(deviceEnumeratorPtr) + SAFE_RELEASE(deviceCollectionPtr) + SAFE_RELEASE(endpointPtr) + SAFE_RELEASE(deviceEndpointPropertiesPtr) + CoUninitialize(); +} + +void onExit(){ + + + + + +} + + + +int main (int argc, char* argv[]) { + PrintEndpointNames(); +} diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp new file mode 100644 index 0000000..e406fae --- /dev/null +++ b/src/qt/mainwindow.cpp @@ -0,0 +1,24 @@ +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { + // setWindowState(Qt::WindowFullScreen); + // setCentralWidget(centralWidget); +} + +/* + * void MainWindow::setPlotButton() { + * button = new QPushButton("push"), + * button->setCheckable(true); + * connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))) + * QHBoxLayout *plotsLayout = new QHBoxLayout; + * plotsLayout->setSpacing(10); + * plotsLayout->addWidget(funPlot); + * QHBoxLayout *buttonsLayout = new QHBoxLayout ; + * buttonsLayout->addWidget(button); + * QVBoxLayout *widgetLayout = new QVBoxLayout; + * widgetLayout->addLayout(plotsLayout); + * widgetLayout->addLayout(buttonsLayout); + * setLayout(widgetLayout); + * ... + */ + diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h new file mode 100644 index 0000000..b3ab242 --- /dev/null +++ b/src/qt/mainwindow.h @@ -0,0 +1,16 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include + +class MainWindow : public QMainWindow { + Q_OBJECT + //QWidget *centralWidget; + + public: + MainWindow(QWidget *parent = nullptr); + + }; + +#endif diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp new file mode 100644 index 0000000..c200413 --- /dev/null +++ b/src/qtestmain.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include +#include + +//#include +#include +#include + +#include "mainwindow.h" + +QApplication* createApplication(int &argc, char *argv[]) +{ + return new QApplication(argc, argv); +} + + +int main (int argc, char* argv[]) { + QApplication::setStyle("windowsvista"); + QScopedPointer app(createApplication(argc, argv)); + MainWindow window = MainWindow(); + window.show(); + return app->exec(); +} From 3ea2e739ae59950dc8d0d16c80a14a9359b4c6a4 Mon Sep 17 00:00:00 2001 From: Hane Date: Fri, 3 Feb 2023 03:04:08 +0100 Subject: [PATCH 3/3] 1er real; slider x ept ok no evts no map --- qtest.pro | 11 +++--- src/back/backlasses.cpp | 73 ++++++++++++++++++++++++++++++++++++++++ src/back/backlasses.h | 56 ++++++++++++++++++++++++++++++ src/cont/contclasses.cpp | 27 +++++++++++++++ src/cont/contclasses.h | 46 +++++++++++++++++++++++++ src/qt/mainwindow.cpp | 24 ------------- src/qt/mainwindow.h | 16 --------- src/qt/qtclasses.cpp | 48 ++++++++++++++++++++++++++ src/qt/qtclasses.h | 38 +++++++++++++++++++++ src/qtestmain.cpp | 29 ++++++++++++---- 10 files changed, 317 insertions(+), 51 deletions(-) create mode 100644 src/back/backlasses.cpp create mode 100644 src/back/backlasses.h create mode 100644 src/cont/contclasses.cpp create mode 100644 src/cont/contclasses.h delete mode 100644 src/qt/mainwindow.cpp delete mode 100644 src/qt/mainwindow.h create mode 100644 src/qt/qtclasses.cpp create mode 100644 src/qt/qtclasses.h diff --git a/qtest.pro b/qtest.pro index 35ebcaa..bf1ff63 100644 --- a/qtest.pro +++ b/qtest.pro @@ -1,7 +1,8 @@ +CONFIG += debug console QT += widgets -INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" -DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" -VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" -SOURCES += qtestmain.cpp mainwindow.cpp -HEADERS += mainwindow.h +INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont" +DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont" +VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont" +SOURCES += qtestmain.cpp qtclasses.cpp backlasses.cpp contclasses.cpp +HEADERS += qtclasses.h backlasses.h contclasses.h #DESTDIR += "build" diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp new file mode 100644 index 0000000..c64fa51 --- /dev/null +++ b/src/back/backlasses.cpp @@ -0,0 +1,73 @@ +#include + +Endpoint::Endpoint(IMMDevice* ep){ + this->endpoint = ep; + if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { log_debugcpp("si"); }; +} + +void Endpoint::setVolume(float volume) { + if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, NULL))) { log_debugcpp("si"); }; +} + + +void Overseer::initCOMLibrary(){ + if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { log_debugcpp("si"); }; + + + //Retrieving endpoint enumerator + //MMDeviceEnumerator es el CLSID de toda la vaina de MMDevicear + if(FAILED(CoCreateInstance( __uuidof(MMDeviceEnumerator), NULL, + CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), + (void**)&deviceEnumerator)) ) + { log_debugcpp("si"); }; + +} + +void Overseer::reloadEndpoints() { + IMMDeviceCollection *deviceCollection; + // | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED + if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &deviceCollection) )) + { log_debugcpp("si"); }; + + + //Counting them + if(FAILED(deviceCollection->GetCount(&numPlaybackEndpoints))) { log_debugcpp("si");}; + if(numPlaybackEndpoints == 0) { log_debugcpp("si"); }; + + + //Retrieving actual endpoints and storing them on their own class + for (unsigned int i = 0; i < numPlaybackEndpoints; i++){ + IMMDevice *temp; + if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); }; + Endpoint *endpoint = new Endpoint(temp); + this->playbackDevices.push_back(endpoint); + //TODO: le porblemx std::cout << "ola" << std::endl; + } + + deviceCollection->Release(); +} + +Overseer::Overseer(){ + //Initializing COM library + initCOMLibrary(); + + //Obtaining playback endpoint collection on this point in time + reloadEndpoints(); +} + +//Overseer::int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint){ +//if (FAILED(deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &endpointPtr))) +// return 1; +//return 0; +//} + +//int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint); + +std::vector Overseer::getPlaybackEndpoints() { + return playbackDevices; +} + +//int Overseer::getCaptureEndpoints(std::vector *captureEndpoints); + +//IMMDeviceEnumerator** Overseer::setOrigin(); + diff --git a/src/back/backlasses.h b/src/back/backlasses.h new file mode 100644 index 0000000..19a1539 --- /dev/null +++ b/src/back/backlasses.h @@ -0,0 +1,56 @@ +#pragma once +#define WIN32_LEAN_AND_MEAN +#define log_debugcpp(str) do { \ + std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \ + } while (0) + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +//#include +//#include +#include + +class Endpoint { + + public: + Endpoint(IMMDevice* endpoint); + void setVolume(float volume); + + private: + IMMDevice* endpoint; + IAudioEndpointVolume *endpointVolume; + +}; + +class Overseer { + //TODO singleton? + public: + Overseer(); + std::vector getPlaybackEndpoints(); + void reloadEndpoints(); + //~Overseer(); + //int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint); + //int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint); + //int getCaptureEndpoints(std::vector *captureEndpoints); + //IMMDeviceEnumerator** setOrigin(); + + private: + unsigned int numPlaybackEndpoints; + IMMDeviceEnumerator *deviceEnumerator; + std::vector playbackDevices; + void initCOMLibrary(); + //IMMDeviceCollection *deviceCollection; + //int numCaptureEndpoints; + //std::vector *captureDevices; +}; + diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp new file mode 100644 index 0000000..9d92d42 --- /dev/null +++ b/src/cont/contclasses.cpp @@ -0,0 +1,27 @@ +#include "contclasses.h" + +Overseer OverseerHandler::os; + +EndpointHandler::EndpointHandler(Endpoint *ept, QObject *parent) : QObject(parent) { + this->ept = ept; +} + +void EndpointHandler::setValue(int value){ + ept->setVolume((float)value / 100); +} + +Overseer OverseerHandler::getOverseer(){ + return os; +} + +OverseerHandler::OverseerHandler(QObject *parent) : QObject(parent) { + +} + +std::vector* OverseerHandler::getEndpointHandlers(){ + return endpointHandlers; +} + +void OverseerHandler::setEndpointHandlers(std::vector *ephs){ + this->endpointHandlers = ephs; +} diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h new file mode 100644 index 0000000..44f184a --- /dev/null +++ b/src/cont/contclasses.h @@ -0,0 +1,46 @@ +#pragma once +#include +#include "backlasses.h" + + +class EndpointHandler : public QObject { + Q_OBJECT + +public: + EndpointHandler(Endpoint *ept, QObject *parent = nullptr); + + +private: + Endpoint *ept; + //QSlider *slidy; + +public slots: + void setValue(int value); + + +//signals: + + +}; + + +class OverseerHandler : public QObject { + Q_OBJECT + +public: + OverseerHandler(QObject *parent = nullptr); + void setEndpointHandlers(std::vector *ephs); + std::vector* getEndpointHandlers(); + static Overseer getOverseer(); + +private: + static Overseer os; + std::vector *endpointHandlers; + //QSlider *slidy; + + //public slots: + //void setValue(int value); + + + +}; diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp deleted file mode 100644 index e406fae..0000000 --- a/src/qt/mainwindow.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "mainwindow.h" - -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - // setWindowState(Qt::WindowFullScreen); - // setCentralWidget(centralWidget); -} - -/* - * void MainWindow::setPlotButton() { - * button = new QPushButton("push"), - * button->setCheckable(true); - * connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))) - * QHBoxLayout *plotsLayout = new QHBoxLayout; - * plotsLayout->setSpacing(10); - * plotsLayout->addWidget(funPlot); - * QHBoxLayout *buttonsLayout = new QHBoxLayout ; - * buttonsLayout->addWidget(button); - * QVBoxLayout *widgetLayout = new QVBoxLayout; - * widgetLayout->addLayout(plotsLayout); - * widgetLayout->addLayout(buttonsLayout); - * setLayout(widgetLayout); - * ... - */ - diff --git a/src/qt/mainwindow.h b/src/qt/mainwindow.h deleted file mode 100644 index b3ab242..0000000 --- a/src/qt/mainwindow.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include - -class MainWindow : public QMainWindow { - Q_OBJECT - //QWidget *centralWidget; - - public: - MainWindow(QWidget *parent = nullptr); - - }; - -#endif diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp new file mode 100644 index 0000000..9a6df6f --- /dev/null +++ b/src/qt/qtclasses.cpp @@ -0,0 +1,48 @@ +#include "qtclasses.h" + +MainWindow::MainWindow(std::vector *ephs, QWidget *parent) : QMainWindow(parent) { + // setWindowState(Qt::WindowFullScreen); + // setCentralWidget(centralWidget); + widget = new QWidget(); + layout = new QGridLayout(); + pintas = new QLabel(tr("Defaulto da")); + + widget->setLayout(layout); + setCentralWidget(widget); + layout->addWidget(pintas, 0, 0); + + setWindowTitle("slidea resbala nu c"); + + setEndpointHandlers(ephs); + for (unsigned int i = 0; i < this->ephs->size(); i++){ + QSlider *teSlider = new QSlider(Qt::Horizontal); + teSlider->setFocusPolicy(Qt::StrongFocus); + teSlider->setTickPosition(QSlider::TicksBothSides); + teSlider->setTickInterval(5); + teSlider->setSingleStep(1); + layout->addWidget(teSlider, 0, i + 1); + connect(teSlider, &QSlider::valueChanged, ephs->at(i), &EndpointHandler::setValue); + } +} + +void MainWindow::setEndpointHandlers(std::vector *ephs){ + this->ephs = ephs; +} + +/* + * void MainWindow::setPlotButton() { + * button = new QPushButton("push"), + * button->setCheckable(true); + * connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))) + * QHBoxLayout *plotsLayout = new QHBoxLayout; + * plotsLayout->setSpacing(10); + * plotsLayout->addWidget(funPlot); + * QHBoxLayout *buttonsLayout = new QHBoxLayout ; + * buttonsLayout->addWidget(button); + * QVBoxLayout *widgetLayout = new QVBoxLayout; + * widgetLayout->addLayout(plotsLayout); + * widgetLayout->addLayout(buttonsLayout); + * setLayout(widgetLayout); + * ... + */ + diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h new file mode 100644 index 0000000..edca5b8 --- /dev/null +++ b/src/qt/qtclasses.h @@ -0,0 +1,38 @@ +#pragma once +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include "contclasses.h" +//#include +//#include + + +class MainWindow : public QMainWindow { + Q_OBJECT + //QWidget *centralWidget; + +public: + MainWindow(std::vector *ephs, QWidget *parent = nullptr); + +private: + std::vector *ephs; + std::vector *sliders; + QWidget *widget; + QGridLayout *layout; + QLabel *pintas; + + //public slots: + // void setEndpointHandlers(std::vector *ephs); + + //signals: + //void valueChanged(int value); + +}; + +#endif diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp index c200413..98372e8 100644 --- a/src/qtestmain.cpp +++ b/src/qtestmain.cpp @@ -1,15 +1,20 @@ #include #include -#include -#include +//#include +//#include //#include #include #include -#include "mainwindow.h" +#include "qtclasses.h" +//TODO david #include "backlasses.h" + +//INIT BACK +OverseerHandler *osh = new OverseerHandler(); + QApplication* createApplication(int &argc, char *argv[]) { return new QApplication(argc, argv); @@ -17,9 +22,21 @@ QApplication* createApplication(int &argc, char *argv[]) int main (int argc, char* argv[]) { - QApplication::setStyle("windowsvista"); - QScopedPointer app(createApplication(argc, argv)); - MainWindow window = MainWindow(); + //QApplication::setStyle("windowsvista"); + //INIT CONT + std::vector epts = OverseerHandler::getOverseer().getPlaybackEndpoints(); + std::vector* ephs = new std::vector; + for(unsigned int i = 0; i < epts.size(); i++){ + EndpointHandler *eph = new EndpointHandler(epts.at(i)); + ephs->push_back(eph); + } + + osh->setEndpointHandlers(ephs); + //INIT FRONT + QScopedPointer app(createApplication(argc, argv)); + MainWindow window = MainWindow(ephs); + window.setEndpointHandlers(ephs); + app->setStyle("windowsvista"); window.show(); return app->exec(); }