From cd2d0b5da82b74fcca59008ae81101ba2eae7c44 Mon Sep 17 00:00:00 2001 From: Hane Date: Thu, 26 Jan 2023 19:42:18 +0100 Subject: [PATCH] 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(); +}