failed attempt at redrawing

This commit is contained in:
Hane 2023-08-09 15:55:25 +02:00
commit c28ec1f11d
8 changed files with 142 additions and 25 deletions

View file

@ -1,5 +1,50 @@
#include <backlasses.h> #include <backlasses.h>
ULONG EndpointCallback::AddRef(){
return InterlockedIncrement(&ref);
}
ULONG EndpointCallback::Release(){
ULONG tempRef = InterlockedDecrement(&ref);
if (tempRef == 0) {
delete this;
}
return tempRef;
}
HRESULT EndpointCallback::QueryInterface(REFIID riid, VOID **ppvInterface) {
if (IID_IUnknown == riid)
{
AddRef();
*ppvInterface = (IUnknown*)this;
}
else if (__uuidof(IAudioEndpointVolumeCallback) == riid)
{
AddRef();
*ppvInterface = (IAudioEndpointVolumeCallback*)this;
}
else
{
*ppvInterface = NULL;
return E_NOINTERFACE;
}
return S_OK;
}
HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
if (pNotify == NULL) return E_INVALIDARG;
LPGUID guid = osh->getOverseer()->getGuid();
if (pNotify->guidEventContext != *guid) {
osh->parseExternalEndpointCallback(this, pNotify);
}
return S_OK;
}
/* EndpointCallback::~EndpointCallback(){
* PAUDIO_VOLUME_NOTIFICATION_DATA->Release();
* } */
Endpoint::Endpoint(IMMDevice* ep){ Endpoint::Endpoint(IMMDevice* ep){
this->endpoint = ep; this->endpoint = ep;
if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { log_debugcpp("si"); }; if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { log_debugcpp("si"); };
@ -66,6 +111,13 @@ void Endpoint::setMute() {
if(FAILED(endpointVolume->SetMute((mut == false ? 1 : 0), NULL))) { log_debugcpp("si"); }; if(FAILED(endpointVolume->SetMute((mut == false ? 1 : 0), NULL))) { log_debugcpp("si"); };
} }
void Endpoint::setCallback(EndpointCallback *epc){
endpointVolume->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)*epc);
}
void Endpoint::removeCallback(EndpointCallback *epc){
endpointVolume->UnregisterControlChangeNotify((IAudioEndpointVolumeCallback*)*epc);
}
Endpoint::~Endpoint(){ Endpoint::~Endpoint(){
log_debugcpp("cum"); log_debugcpp("cum");
@ -87,6 +139,8 @@ void Overseer::initCOMLibrary(){
(void**)&deviceEnumerator)) ) (void**)&deviceEnumerator)) )
{ log_debugcpp("si"); }; { log_debugcpp("si"); };
if(FAILED(CoCreateGuid(guid))) { log_debugcpp("guyyyyyy"); };
} }
void Overseer::reloadEndpoints() { void Overseer::reloadEndpoints() {
@ -129,6 +183,10 @@ Overseer::Overseer(){
//int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint); //int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
LPGUID Overseer::getGuid() {
return guid;
}
std::vector<Endpoint*> Overseer::getPlaybackEndpoints() { std::vector<Endpoint*> Overseer::getPlaybackEndpoints() {
return playbackDevices; return playbackDevices;
} }

View file

@ -19,6 +19,22 @@
//#include <comip.h> //#include <comip.h>
#include <Winerror.h> #include <Winerror.h>
class EndpointCallback : public IAudioEndpointVolumeCallback {
public:
EndpointCallback();
ULONG AddRef();
ULONG Release();
HRESULT QueryInterface(REFIID riid, VOID **ppvInterface);
HRESULT OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA update);
~EndpointCallback();
private:
ULONG ref;
PAUDIO_VOLUME_NOTIFICATION_DATA update;
};
class Endpoint { class Endpoint {
public: public:
@ -30,6 +46,8 @@ class Endpoint {
void setMute(); void setMute();
bool getMute(); bool getMute();
LPWSTR getName(); LPWSTR getName();
void setCallback(EndpointCallback *epc);
void removeCallback(EndpointCallback *epc);
~Endpoint(); ~Endpoint();
private: private:
@ -46,6 +64,7 @@ class Overseer {
Overseer(); Overseer();
std::vector<Endpoint*> getPlaybackEndpoints(); std::vector<Endpoint*> getPlaybackEndpoints();
void reloadEndpoints(); void reloadEndpoints();
LPGUID getGuid();
//~Overseer(); //~Overseer();
//int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint); //int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint);
//int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint); //int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
@ -54,6 +73,7 @@ class Overseer {
~Overseer(); ~Overseer();
private: private:
LPGUID guid;
unsigned int numPlaybackEndpoints; unsigned int numPlaybackEndpoints;
IMMDeviceEnumerator *deviceEnumerator; IMMDeviceEnumerator *deviceEnumerator;
std::vector<Endpoint*> playbackDevices; std::vector<Endpoint*> playbackDevices;

View file

@ -2,10 +2,13 @@
Overseer OverseerHandler::os; Overseer OverseerHandler::os;
EndpointHandler::EndpointHandler(Endpoint *ept, QObject *parent) : QObject(parent) { EndpointHandler::EndpointHandler(Endpoint *ep, EndpointCallback *epc, QObject *parent) : QObject(parent) {
this->ept = ept; this->ep = ep;
eptName = QString::fromStdWString(ept->getName()); this->epc = epc;
epName = QString::fromStdWString(ept->getName());
ep->setCallback(*epc);
} }
/* /*
* -1 for master volume * -1 for master volume
*/ */
@ -33,6 +36,13 @@ bool EndpointHandler::getMute(){
return ept->getMute(); return ept->getMute();
} }
EndpointHandler::~EndpointHandler() {
ep->removeCallback(*epc);
delete epc;
delete ep;
}
Overseer* OverseerHandler::getOverseer(){ Overseer* OverseerHandler::getOverseer(){
return &os; return &os;
} }
@ -41,10 +51,29 @@ OverseerHandler::OverseerHandler(QObject *parent) : QObject(parent) {
} }
std::vector<EndpointHandler*>* OverseerHandler::getEndpointHandlers(){ std::vector<EndpointWidget*>* OverseerHandler::getEndpointWidgets(){
return endpointHandlers; return &endpointWidgets;
} }
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> *ephs){ void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify){
this->endpointHandlers = ephs; log_debugcpp("parsing in da ovasiar");
for (uint64_t i = 0; i < endpointWidgets.size(); i++){
if(endpointWidgets.at(i)->eph->epc == fEpc) {
endpointWidgets.at(i)->muteButton->setText(endpointWidgets.at(i)->eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
break;
}
}
/*
* connect(mainSlider, &QSlider::valueChanged, [this](int newValue){this->eph->setValue(ENDPOINT_MASTER_VOLUME, newValue); });
* connect(leftChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setValue(ENDPOINT_LEFT_CHANNEL_VOLUME, newValue); this->leftChannelLabel->setText(QString::number(newValue)); });
* connect(rightChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setValue(ENDPOINT_RIGHT_CHANNEL_VOLUME, newValue); this->rightChannelLabel->setText(QString::number(newValue)); });
* 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::setEndpointWidgets(std::vector<EndpointWidget*> ews){
this->endpointWidgets = ews;
}

View file

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <QObject> #include <QObject>
#include "backlasses.h" #include "backlasses.h"
@ -7,15 +8,18 @@ class EndpointHandler : public QObject {
Q_OBJECT Q_OBJECT
public: public:
EndpointHandler(Endpoint *ept, QObject *parent = nullptr); EndpointHandler(Endpoint *ept, EndpointCallback *epc, QObject *parent = nullptr);
//TODO: get();
Endpoint *ep;
EndpointCallback *epc;
QString epName;
QString getName(); QString getName();
float getVolume(int channel); float getVolume(int channel);
bool getMute(); bool getMute();
private: private:
Endpoint *ept; //QSlider *slidy;
QString eptName;
//QSlider *slidy;
public slots: public slots:
void setValue(int channel, int value); void setValue(int channel, int value);
@ -31,18 +35,17 @@ class OverseerHandler : public QObject {
public: public:
OverseerHandler(QObject *parent = nullptr); OverseerHandler(QObject *parent = nullptr);
void setEndpointHandlers(std::vector<EndpointHandler*> *ephs); void setEndpointWidgets(std::vector<EndpointWidget*> ews);
std::vector<EndpointHandler*>* getEndpointHandlers(); std::vector<EndpointWidget*>* getEndpointWidgets();
void parseExternalEndpointCallback(EndpointCallback *epc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify);
static Overseer* getOverseer(); static Overseer* getOverseer();
private: private:
static Overseer os; static Overseer os;
std::vector<EndpointHandler*> *endpointHandlers; std::vector<EndpointWidget*> endpointWidgets;
//QSlider *slidy; //QSlider *slidy;
//public slots: //public slots:
//void setValue(int value); //void setValue(int value);
}; };

View file

@ -9,7 +9,6 @@
#define STRING_UNMUTE "Unmute" #define STRING_UNMUTE "Unmute"
//INIT BACK //INIT BACK
class OverseerHandler; class OverseerHandler;
extern OverseerHandler *osh; extern OverseerHandler *osh;

View file

@ -85,6 +85,7 @@ MainWindow::MainWindow(std::vector<EndpointHandler*> *ephs, QWidget *parent) : Q
ews.push_back(epw); ews.push_back(epw);
layout->addWidget(epw, i, 0); layout->addWidget(epw, i, 0);
} }
osh->setEndpointWidgets(ews);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), i, 0); layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), i, 0);
} }
@ -112,3 +113,4 @@ MainWindow::MainWindow(std::vector<EndpointHandler*> *ephs, QWidget *parent) : Q
* ... * ...
*/ */

View file

@ -19,11 +19,9 @@ class EndpointWidget : public QWidget {
public: public:
EndpointWidget(EndpointHandler* eph, QWidget *parent = nullptr); EndpointWidget(EndpointHandler* eph, QWidget *parent = nullptr);
//void populateEndpointWidget(EndpointHandler *eph); //TODO: get();
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
private:
EndpointHandler* eph; EndpointHandler* eph;
QPushButton *muteButton = nullptr; QPushButton *muteButton = nullptr;
QLabel *mainLabel = nullptr, *leftChannelLabel = nullptr, *rightChannelLabel = nullptr; QLabel *mainLabel = nullptr, *leftChannelLabel = nullptr, *rightChannelLabel = nullptr;
QSlider *mainSlider = nullptr; QSlider *mainSlider = nullptr;
@ -31,6 +29,11 @@ private:
QSlider *rightChannelSlider = nullptr; QSlider *rightChannelSlider = nullptr;
QGridLayout *layout = nullptr; QGridLayout *layout = nullptr;
QGridLayout *mainMuteLayout = nullptr; QGridLayout *mainMuteLayout = nullptr;
//void populateEndpointWidget(EndpointHandler *eph);
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
private:
//std::vector<EndpointHandler*> *ephs; //std::vector<EndpointHandler*> *ephs;
//std::vector<QSlider> *sliders; //std::vector<QSlider> *sliders;
@ -67,3 +70,4 @@ private:
}; };
#endif #endif

View file

@ -9,6 +9,7 @@
#include <QMainWindow> #include <QMainWindow>
#include "qtclasses.h" #include "qtclasses.h"
#include "global.h"
OverseerHandler *osh = new OverseerHandler(); OverseerHandler *osh = new OverseerHandler();
@ -21,14 +22,14 @@ QApplication* createApplication(int &argc, char *argv[])
int main (int argc, char* argv[]) { int main (int argc, char* argv[]) {
//QApplication::setStyle("windowsvista"); //QApplication::setStyle("windowsvista");
//INIT CONT //INIT CONT
std::vector<Endpoint*> epts = OverseerHandler::getOverseer()->getPlaybackEndpoints(); std::vector<Endpoint*> eps = OverseerHandler::getOverseer()->getPlaybackEndpoints();
std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>; std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>;
for(unsigned int i = 0; i < epts.size(); i++){ for(unsigned int i = 0; i < eps.size(); i++){
EndpointHandler *eph = new EndpointHandler(epts.at(i)); EndpointCallback* epc = new EndpointCallback();
EndpointHandler* eph = new EndpointHandler(eps.at(i), epc);
ephs->push_back(eph); ephs->push_back(eph);
} }
osh->setEndpointHandlers(ephs);
//INIT FRONT //INIT FRONT
QScopedPointer<QApplication> app(createApplication(argc, argv)); QScopedPointer<QApplication> app(createApplication(argc, argv));
MainWindow window = MainWindow(ephs); MainWindow window = MainWindow(ephs);
@ -37,3 +38,4 @@ int main (int argc, char* argv[]) {
window.show(); window.show();
return app->exec(); return app->exec();
} }