diff --git a/qtest.pro b/qtest.pro index 39fad14..73f3f80 100644 --- a/qtest.pro +++ b/qtest.pro @@ -1,6 +1,7 @@ QMAKE_CXXFLAGS += --target=x86_64-w64-mingw32 QMAKE_LINKER += clang++ QMAKE_LFLAGS += -v +DEFINES += DEBUG CONFIG += debug console QT += widgets INCLUDEPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\cont" diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 1a48dd7..1cf1006 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -1,7 +1,7 @@ #include EndpointCallback::EndpointCallback(Endpoint* ep){ - this.ep = ep; + this->ep = ep; } ULONG EndpointCallback::AddRef(){ @@ -36,13 +36,15 @@ HRESULT EndpointCallback::QueryInterface(REFIID riid, VOID **ppvInterface) { } HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) { - if (pNotify == NULL) return E_INVALIDARG; - AUDIO_VOLUME_NOTIFICATION_DATA eventData = *pNotify; - LPGUID guid = osh->getOverseer()->getGuid(); - - if (eventData.guidEventContext != *guid) { - osh->parseExternalEndpointCallback(this, eventData); - } + if (pNotify == NULL) return E_INVALIDARG; + /* + * AUDIO_VOLUME_NOTIFICATION_DATA eventData = *pNotify; + * LPGUID guid = osh->getOverseer()->getGuid(); + * + * if (eventData.guidEventContext != *guid) { + * osh->parseExternalEndpointCallback(this, eventData); + * } + */ return S_OK; } @@ -58,11 +60,11 @@ Endpoint::Endpoint(IMMDevice* ep){ endpoint->OpenPropertyStore(STGM_READ, &properties); PROPVARIANT pv; properties->GetValue(PKEY_Device_FriendlyName , &pv); - friendlyName = pv.pwszVal; + friendlyName = std::wstring(pv.pwszVal); } void Endpoint::setIndex(uint64_t idx){ - this.idx = idx; + this->idx = idx; } uint64_t Endpoint::getIndex(){ @@ -70,7 +72,7 @@ uint64_t Endpoint::getIndex(){ } -LPWSTR Endpoint::getName(){ +std::wstring Endpoint::getName(){ return friendlyName; } @@ -118,10 +120,10 @@ void Endpoint::setVolume(int channel, float volume) { } void Endpoint::setMute() { - log_debugcpp("bool mute arrives as " << mut); BOOL mut; + //log_debugcpp("bool mute arrives as " << mut); if(FAILED(endpointVolume->GetMute(&mut))) { log_debugcpp("si"); } - log_debugcpp("translate to BOOL as " << mute); + log_debugcpp("translate to BOOL as " << mut); if(FAILED(endpointVolume->SetMute((mut == false ? 1 : 0), NULL))) { log_debugcpp("si"); }; } @@ -135,7 +137,6 @@ void Endpoint::removeCallback(EndpointCallback *epc){ Endpoint::~Endpoint(){ log_debugcpp("cum"); - free(friendlyName); properties->Release(); endpointVolume->Release(); endpoint->Release(); @@ -153,8 +154,18 @@ void Overseer::initCOMLibrary(){ (void**)&deviceEnumerator)) ) { log_debugcpp("si"); }; - if(FAILED(CoCreateGuid(guid))) { log_debugcpp("guyyyyyy"); }; - + /* + * LPGUID tempGuid = nullptr; + * if(FAILED(CoCreateGuid(tempGuid))) { log_debugcpp("Failed to obtain GUID"); }; + * + * this->guid.data1 = tempGuid->Data1; + * this->guid.data2 = tempGuid->Data2; + * this->guid.data3 = tempGuid->Data3; + * for (int i = 0; i < 8; i++){ + * this->guid.data4[i] = tempGuid->Data4[i]; + * } + */ + //TODO: Release lpguid? } void Overseer::reloadEndpoints() { @@ -184,6 +195,7 @@ void Overseer::reloadEndpoints() { Overseer::Overseer(){ //Initializing COM library + log_debugcpp("Initializing Overseer"); initCOMLibrary(); //Obtaining playback endpoint collection on this point in time @@ -198,7 +210,8 @@ Overseer::Overseer(){ //int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint); -LPGUID Overseer::getGuid() { +//TODO guid +NGuid Overseer::getGuid() { return guid; } diff --git a/src/back/backlasses.h b/src/back/backlasses.h index 2da5724..9f97dde 100644 --- a/src/back/backlasses.h +++ b/src/back/backlasses.h @@ -1,11 +1,13 @@ #pragma once #define WIN32_LEAN_AND_MEAN +//done by qt by def #define UNICODE -#include "debug.h" +//#include "debug.h" #include "global.h" -#include -#include -#include +#include "contclasses.h" +/* #include */ +/* #include */ +/* #include */ #include #include @@ -20,24 +22,9 @@ //#include #include -//class EndpointWidget; +#include "contclasses.h" -class EndpointCallback : public IAudioEndpointVolumeCallback { - - public: - EndpointCallback(Endpoint* ep); - - ULONG AddRef(); - ULONG Release(); - HRESULT QueryInterface(REFIID riid, VOID **ppvInterface); - HRESULT OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA update); - ~EndpointCallback(); - - private: - ULONG ref = 1; - Endpoint* ep; - PAUDIO_VOLUME_NOTIFICATION_DATA update; -}; +class EndpointCallback; class Endpoint { @@ -51,7 +38,7 @@ class Endpoint { float getVolume(int channel); void setMute(); bool getMute(); - LPWSTR getName(); + std::wstring getName(); void setCallback(EndpointCallback *epc); void removeCallback(EndpointCallback *epc); ~Endpoint(); @@ -65,13 +52,30 @@ class Endpoint { // LPWSTR endpointID = NULL; }; +class EndpointCallback : public IAudioEndpointVolumeCallback { + + public: + EndpointCallback(Endpoint* ep); + + ULONG AddRef(); + ULONG Release(); + HRESULT QueryInterface(REFIID riid, VOID **ppvInterface); + HRESULT OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA update); + //~EndpointCallback(); + + private: + ULONG ref = 1; + Endpoint* ep; + //PAUDIO_VOLUME_NOTIFICATION_DATA update; +}; + class Overseer { //TODO singleton? public: Overseer(); std::vector getPlaybackEndpoints(); void reloadEndpoints(); - LPGUID getGuid(); + NGuid getGuid(); //~Overseer(); //int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint); //int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint); @@ -80,7 +84,7 @@ class Overseer { ~Overseer(); private: - LPGUID guid; + NGuid guid; unsigned int numPlaybackEndpoints; IMMDeviceEnumerator *deviceEnumerator; std::vector playbackDevices; diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index f5c2855..e26bf25 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -1,4 +1,4 @@ -#incluse "backlasses.h" +#include "backlasses.h" #include "contclasses.h" Overseer OverseerHandler::os; @@ -7,12 +7,12 @@ EndpointHandler::EndpointHandler(uint64_t idx) { std::vector endpoints = osh->getPlaybackEndpoints(); this->ep = endpoints.at(idx); epc = new EndpointCallback(ep); - epName = QString::fromStdWString(ept->getName()); - ep->setCallback(*epc); + //epName = ep->getName(); + //ep->setCallback(*epc); } void EndpointHandler::setIndex(uint64_t idx){ - this.idx = idx; + this->idx = idx; } uint64_t EndpointHandler::getIndex(){ @@ -25,36 +25,36 @@ uint64_t EndpointHandler::getIndex(){ */ void EndpointHandler::setValue(int channel, int value){ if (channel == ENDPOINT_MASTER_VOLUME) - ept->setVolume(channel, (float)value / 100); - else ept->setVolume(channel, (float)value / 100); + ep->setVolume(channel, (float)value / 100); + else ep->setVolume(channel, (float)value / 100); } void EndpointHandler::setMute(){ //Qt momento, de ahi el param? log_debugcpp("kinda handling the muting tbh"); - ept->setMute(); + ep->setMute(); } -QString EndpointHandler::getName(){ - return eptName; +std::wstring EndpointHandler::getName(){ + return ep->getName(); } float EndpointHandler::getVolume(int channel){ - return ept->getVolume(channel); + return ep->getVolume(channel); } bool EndpointHandler::getMute(){ - return ept->getMute(); + return ep->getMute(); } EndpointHandler::~EndpointHandler() { - ep->removeCallback(*epc); + ep->removeCallback(epc); delete epc; delete ep; } std::vector OverseerHandler::getPlaybackEndpoints() { - return os->getPlaybackEndpoints(); + return os.getPlaybackEndpoints(); } /* @@ -64,38 +64,46 @@ std::vector OverseerHandler::getPlaybackEndpoints() { */ -std::vector* OverseerHandler::getEndpointHandlers(){ - return &endpointHandlers; +std::vector OverseerHandler::getEndpointHandlers(){ + return endpointHandlers; } uint64_t OverseerHandler::getPlaybackEndpointsCount(){ - return os->getplaybackEndpoints().size(); + return os.getPlaybackEndpoints().size(); } void OverseerHandler::reloadEndpointHandlers(){ //std::vector* ephs = new std::vector; + log_debugcpp(" VSize: " << this->getPlaybackEndpointsCount()); + + for(uint64_t i = 0; i < this->getPlaybackEndpointsCount(); i++){ + log_debugcpp("Creating handler " << i); + + if(i < (this->endpointHandlers.size()) && + this->endpointHandlers.at(i) != nullptr) + delete endpointHandlers.at(i); + - for(uint64_t i = 0; i < osh->getPlaybackEndpointsCount(); i++){ - if(i < osh->getPlaybackEndpointsCount().size() && - osh->getPlaybackEndpointsCount().at(i) != nullptr) - delete ephs.at(i); EndpointHandler* eph = new EndpointHandler(i); - - if (i >= osh->getPlaybackEndpointsCount().size()) - ephs.push_back(eph); - else epsh.at(i) = eph; + log_debugcpp("Created handler " << i << ", adding to vector. " << " VSize: " << this->getPlaybackEndpointsCount()); + + if (i >= this->endpointHandlers.size()) + endpointHandlers.push_back(eph); + else endpointHandlers.at(i) = eph; } //setEndpointHandlers(ephs); } -void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify){ - log_debugcpp("parsing in da ovasiar"); - for (uint64_t i = 0; i < endpointHandlers.size(); i++){ - if(endpointHandlers.at(i)->eph->epc == fEpc) { - endpointHandlers.at(i)->muteButton->setText(endpointHandlers.at(i)->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); - break; - } - } +/* + * void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify){ + * log_debugcpp("parsing in da ovasiar"); + * for (uint64_t i = 0; i < endpointHandlers.size(); i++){ + * if(endpointHandlers.at(i)->eph->epc == fEpc) { + * endpointHandlers.at(i)->muteButton->setText(endpointHandlers.at(i)->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); + * break; + * } + * } + */ /* * connect(mainSlider, &QSlider::valueChanged, [this](int newValue){this->eph->setValue(ENDPOINT_MASTER_VOLUME, newValue); }); @@ -104,7 +112,7 @@ void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUD * connect(muteButton, &QPushButton::clicked, [this](bool clicked){ log_debugcpp("cliqui" << clicked << "cloqui"); this->eph->setMute(); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); }); * log_debugcpp("ENDPOINT_WIDGETED"); */ -} + void OverseerHandler::setEndpointHandlers(std::vector ews){ this->endpointHandlers = ews; diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index ceeb17c..db013b0 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -1,27 +1,36 @@ #pragma once -#include "backlasses.h" +class Endpoint; +class EndpointCallback; +class Overseer; +struct NGuid { + uint32_t data1; + uint16_t data2; + uint16_t data3; + unsigned char data4[8]; +}; class EndpointHandler { public: - EndpointHandler(Endpoint *ept); + EndpointHandler(uint64_t idx); //TODO: get(); Endpoint *ep; EndpointCallback *epc; - QString epName; + //std::wstring epName; void setIndex(uint64_t idx); + uint64_t getIndex(); void setVolume(int channel, float volume); - //todo qstrin????? idiota - QString getName(); + std::wstring getName(); float getVolume(int channel); bool getMute(); void setValue(int channel, int value); - void setMute(); + void setMute(); + ~EndpointHandler(); private: uint64_t idx; //QSlider *slidy; @@ -37,18 +46,16 @@ class OverseerHandler { public: //OverseerHandler(); void setEndpointHandlers(std::vector ews); - std::vector* getEndpointHandlers(); + std::vector getEndpointHandlers(); std::vector getPlaybackEndpoints(); uint64_t getPlaybackEndpointsCount(); - void parseExternalEndpointCallback(EndpointCallback *epc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify); + void reloadEndpointHandlers(); + + //void parseExternalEndpointCallback(EndpointCallback *epc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify); //static Overseer* getOverseer(); private: static Overseer os; std::vector endpointHandlers; - //QSlider *slidy; - - //public slots: - //void setValue(int value); - + }; diff --git a/src/debug.h b/src/debug.h index f91232b..6e4baa8 100644 --- a/src/debug.h +++ b/src/debug.h @@ -8,3 +8,4 @@ #else #define log_debugcpp(str) #endif + diff --git a/src/global.h b/src/global.h index 977e0b8..6b949b6 100644 --- a/src/global.h +++ b/src/global.h @@ -1,5 +1,11 @@ #pragma once +#include +#include +#include + +#include "debug.h" + //TODO enum capullo #define ENDPOINT_MASTER_VOLUME -1 #define ENDPOINT_LEFT_CHANNEL_VOLUME 0 diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 104f7da..79c1909 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -9,7 +9,7 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget( if (parent == nullptr) { log_debugcpp("owo?"); } muteButton = new QPushButton(); - mainLabel = new QLabel(eph->getName()); + mainLabel = new QLabel(QString::fromStdWString(eph->getName())); leftChannelLabel = new QLabel("88"); rightChannelLabel = new QLabel("77"); mainSlider = new QSlider(Qt::Horizontal); @@ -64,7 +64,7 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget( void EndpointWidget::setIndex(uint64_t idx){ - this.idx = idx; + this->idx = idx; } uint64_t EndpointWidget::getIndex(){ @@ -89,7 +89,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { * setEndpointHandlers(ephs); */ unsigned int i = 0; - for (; i < ephs->size(); i++) { + for (; i < (osh->getEndpointHandlers().size()); i++) { log_debugcpp("EPWidget creation"); EndpointWidget *epw = new EndpointWidget(osh->getEndpointHandlers().at(i), widget); ews.push_back(epw); diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 824fd89..a543c25 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -2,13 +2,16 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +//#include #include #include #include #include #include #include + +//#include "debug.h" +#include "global.h" #include "contclasses.h" //#include //#include @@ -22,6 +25,8 @@ public: //TODO: get(); EndpointHandler* eph; void setIndex(uint64_t idx); + uint64_t getIndex(); + void setVolume(int channel, float volume); QPushButton *muteButton = nullptr; @@ -53,7 +58,7 @@ class MainWindow : public QMainWindow { //QWidget *centralWidget; public: - MainWindow(std::vector *ephs, QWidget *parent = nullptr); + MainWindow(QWidget *parent = nullptr); //void setEndpointHandlers(std::vector *ephs); private: diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp index 5fa6360..453cce6 100644 --- a/src/qtestmain.cpp +++ b/src/qtestmain.cpp @@ -1,6 +1,3 @@ -#include -#include - //#include //#include @@ -22,7 +19,9 @@ QApplication* createApplication(int &argc, char *argv[]) int main (int argc, char* argv[]) { //QApplication::setStyle("windowsvista"); //INIT CONT + log_debugcpp("main init"); osh->reloadEndpointHandlers(); + log_debugcpp("Reloaded endpoint handlers"); //INIT FRONT QScopedPointer app(createApplication(argc, argv));