failed attempt at redrawing
This commit is contained in:
parent
e42c2dd6c9
commit
f84ddaef6c
8 changed files with 142 additions and 25 deletions
|
|
@ -1,5 +1,50 @@
|
|||
#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){
|
||||
this->endpoint = ep;
|
||||
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"); };
|
||||
}
|
||||
|
||||
void Endpoint::setCallback(EndpointCallback *epc){
|
||||
endpointVolume->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)*epc);
|
||||
}
|
||||
|
||||
void Endpoint::removeCallback(EndpointCallback *epc){
|
||||
endpointVolume->UnregisterControlChangeNotify((IAudioEndpointVolumeCallback*)*epc);
|
||||
}
|
||||
|
||||
Endpoint::~Endpoint(){
|
||||
log_debugcpp("cum");
|
||||
|
|
@ -87,6 +139,8 @@ void Overseer::initCOMLibrary(){
|
|||
(void**)&deviceEnumerator)) )
|
||||
{ log_debugcpp("si"); };
|
||||
|
||||
if(FAILED(CoCreateGuid(guid))) { log_debugcpp("guyyyyyy"); };
|
||||
|
||||
}
|
||||
|
||||
void Overseer::reloadEndpoints() {
|
||||
|
|
@ -129,6 +183,10 @@ Overseer::Overseer(){
|
|||
|
||||
//int Overseer::getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
|
||||
|
||||
LPGUID Overseer::getGuid() {
|
||||
return guid;
|
||||
}
|
||||
|
||||
std::vector<Endpoint*> Overseer::getPlaybackEndpoints() {
|
||||
return playbackDevices;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,22 @@
|
|||
//#include <comip.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 {
|
||||
|
||||
public:
|
||||
|
|
@ -30,6 +46,8 @@ class Endpoint {
|
|||
void setMute();
|
||||
bool getMute();
|
||||
LPWSTR getName();
|
||||
void setCallback(EndpointCallback *epc);
|
||||
void removeCallback(EndpointCallback *epc);
|
||||
~Endpoint();
|
||||
|
||||
private:
|
||||
|
|
@ -46,6 +64,7 @@ class Overseer {
|
|||
Overseer();
|
||||
std::vector<Endpoint*> getPlaybackEndpoints();
|
||||
void reloadEndpoints();
|
||||
LPGUID getGuid();
|
||||
//~Overseer();
|
||||
//int getDefaultPlaybackEndpoint(Endpoint** defaultEndpoint);
|
||||
//int getDefaultCaptureEndpoint(Endpoint** defaultEndpoint);
|
||||
|
|
@ -54,6 +73,7 @@ class Overseer {
|
|||
~Overseer();
|
||||
|
||||
private:
|
||||
LPGUID guid;
|
||||
unsigned int numPlaybackEndpoints;
|
||||
IMMDeviceEnumerator *deviceEnumerator;
|
||||
std::vector<Endpoint*> playbackDevices;
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
Overseer OverseerHandler::os;
|
||||
|
||||
EndpointHandler::EndpointHandler(Endpoint *ept, QObject *parent) : QObject(parent) {
|
||||
this->ept = ept;
|
||||
eptName = QString::fromStdWString(ept->getName());
|
||||
EndpointHandler::EndpointHandler(Endpoint *ep, EndpointCallback *epc, QObject *parent) : QObject(parent) {
|
||||
this->ep = ep;
|
||||
this->epc = epc;
|
||||
epName = QString::fromStdWString(ept->getName());
|
||||
ep->setCallback(*epc);
|
||||
}
|
||||
|
||||
/*
|
||||
* -1 for master volume
|
||||
*/
|
||||
|
|
@ -33,6 +36,13 @@ bool EndpointHandler::getMute(){
|
|||
return ept->getMute();
|
||||
}
|
||||
|
||||
EndpointHandler::~EndpointHandler() {
|
||||
ep->removeCallback(*epc);
|
||||
delete epc;
|
||||
delete ep;
|
||||
}
|
||||
|
||||
|
||||
Overseer* OverseerHandler::getOverseer(){
|
||||
return &os;
|
||||
}
|
||||
|
|
@ -41,10 +51,29 @@ OverseerHandler::OverseerHandler(QObject *parent) : QObject(parent) {
|
|||
|
||||
}
|
||||
|
||||
std::vector<EndpointHandler*>* OverseerHandler::getEndpointHandlers(){
|
||||
return endpointHandlers;
|
||||
std::vector<EndpointWidget*>* OverseerHandler::getEndpointWidgets(){
|
||||
return &endpointWidgets;
|
||||
}
|
||||
|
||||
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> *ephs){
|
||||
this->endpointHandlers = ephs;
|
||||
void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify){
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include "backlasses.h"
|
||||
|
||||
|
|
@ -7,15 +8,18 @@ class EndpointHandler : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
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();
|
||||
float getVolume(int channel);
|
||||
bool getMute();
|
||||
|
||||
private:
|
||||
Endpoint *ept;
|
||||
QString eptName;
|
||||
//QSlider *slidy;
|
||||
//QSlider *slidy;
|
||||
|
||||
public slots:
|
||||
void setValue(int channel, int value);
|
||||
|
|
@ -31,18 +35,17 @@ class OverseerHandler : public QObject {
|
|||
|
||||
public:
|
||||
OverseerHandler(QObject *parent = nullptr);
|
||||
void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
||||
std::vector<EndpointHandler*>* getEndpointHandlers();
|
||||
void setEndpointWidgets(std::vector<EndpointWidget*> ews);
|
||||
std::vector<EndpointWidget*>* getEndpointWidgets();
|
||||
void parseExternalEndpointCallback(EndpointCallback *epc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify);
|
||||
static Overseer* getOverseer();
|
||||
|
||||
private:
|
||||
static Overseer os;
|
||||
std::vector<EndpointHandler*> *endpointHandlers;
|
||||
std::vector<EndpointWidget*> endpointWidgets;
|
||||
//QSlider *slidy;
|
||||
|
||||
//public slots:
|
||||
//void setValue(int value);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#define STRING_UNMUTE "Unmute"
|
||||
//INIT BACK
|
||||
|
||||
|
||||
class OverseerHandler;
|
||||
extern OverseerHandler *osh;
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ MainWindow::MainWindow(std::vector<EndpointHandler*> *ephs, QWidget *parent) : Q
|
|||
ews.push_back(epw);
|
||||
layout->addWidget(epw, i, 0);
|
||||
}
|
||||
osh->setEndpointWidgets(ews);
|
||||
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
|
|||
* ...
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,9 @@ class EndpointWidget : public QWidget {
|
|||
|
||||
public:
|
||||
EndpointWidget(EndpointHandler* eph, QWidget *parent = nullptr);
|
||||
//void populateEndpointWidget(EndpointHandler *eph);
|
||||
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
||||
|
||||
private:
|
||||
//TODO: get();
|
||||
EndpointHandler* eph;
|
||||
|
||||
QPushButton *muteButton = nullptr;
|
||||
QLabel *mainLabel = nullptr, *leftChannelLabel = nullptr, *rightChannelLabel = nullptr;
|
||||
QSlider *mainSlider = nullptr;
|
||||
|
|
@ -31,6 +29,11 @@ private:
|
|||
QSlider *rightChannelSlider = nullptr;
|
||||
QGridLayout *layout = nullptr;
|
||||
QGridLayout *mainMuteLayout = nullptr;
|
||||
//void populateEndpointWidget(EndpointHandler *eph);
|
||||
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
||||
|
||||
private:
|
||||
|
||||
//std::vector<EndpointHandler*> *ephs;
|
||||
//std::vector<QSlider> *sliders;
|
||||
|
||||
|
|
@ -67,3 +70,4 @@ private:
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <QMainWindow>
|
||||
|
||||
#include "qtclasses.h"
|
||||
#include "global.h"
|
||||
|
||||
OverseerHandler *osh = new OverseerHandler();
|
||||
|
||||
|
|
@ -21,14 +22,14 @@ QApplication* createApplication(int &argc, char *argv[])
|
|||
int main (int argc, char* argv[]) {
|
||||
//QApplication::setStyle("windowsvista");
|
||||
//INIT CONT
|
||||
std::vector<Endpoint*> epts = OverseerHandler::getOverseer()->getPlaybackEndpoints();
|
||||
std::vector<Endpoint*> eps = OverseerHandler::getOverseer()->getPlaybackEndpoints();
|
||||
std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>;
|
||||
for(unsigned int i = 0; i < epts.size(); i++){
|
||||
EndpointHandler *eph = new EndpointHandler(epts.at(i));
|
||||
for(unsigned int i = 0; i < eps.size(); i++){
|
||||
EndpointCallback* epc = new EndpointCallback();
|
||||
EndpointHandler* eph = new EndpointHandler(eps.at(i), epc);
|
||||
ephs->push_back(eph);
|
||||
}
|
||||
|
||||
osh->setEndpointHandlers(ephs);
|
||||
//INIT FRONT
|
||||
QScopedPointer<QApplication> app(createApplication(argc, argv));
|
||||
MainWindow window = MainWindow(ephs);
|
||||
|
|
@ -37,3 +38,4 @@ int main (int argc, char* argv[]) {
|
|||
window.show();
|
||||
return app->exec();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue