wip partial refactor
This commit is contained in:
parent
507dc37ad6
commit
e43e4c0569
7 changed files with 114 additions and 53 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
#include <backlasses.h>
|
#include <backlasses.h>
|
||||||
|
|
||||||
|
EndpointCallback::EndpointCallback(Endpoint* ep){
|
||||||
|
this.ep = ep;
|
||||||
|
}
|
||||||
|
|
||||||
ULONG EndpointCallback::AddRef(){
|
ULONG EndpointCallback::AddRef(){
|
||||||
return InterlockedIncrement(&ref);
|
return InterlockedIncrement(&ref);
|
||||||
}
|
}
|
||||||
|
|
@ -33,10 +37,11 @@ HRESULT EndpointCallback::QueryInterface(REFIID riid, VOID **ppvInterface) {
|
||||||
|
|
||||||
HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
|
HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
|
||||||
if (pNotify == NULL) return E_INVALIDARG;
|
if (pNotify == NULL) return E_INVALIDARG;
|
||||||
|
AUDIO_VOLUME_NOTIFICATION_DATA eventData = *pNotify;
|
||||||
|
LPGUID guid = osh->getOverseer()->getGuid();
|
||||||
|
|
||||||
LPGUID guid = osh->getOverseer()->getGuid();
|
if (eventData.guidEventContext != *guid) {
|
||||||
if (pNotify->guidEventContext != *guid) {
|
osh->parseExternalEndpointCallback(this, eventData);
|
||||||
osh->parseExternalEndpointCallback(this, pNotify);
|
|
||||||
}
|
}
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -56,6 +61,15 @@ Endpoint::Endpoint(IMMDevice* ep){
|
||||||
friendlyName = pv.pwszVal;
|
friendlyName = pv.pwszVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Endpoint::setIndex(uint64_t idx){
|
||||||
|
this.idx = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t Endpoint::getIndex(){
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LPWSTR Endpoint::getName(){
|
LPWSTR Endpoint::getName(){
|
||||||
return friendlyName;
|
return friendlyName;
|
||||||
}
|
}
|
||||||
|
|
@ -112,11 +126,11 @@ void Endpoint::setMute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Endpoint::setCallback(EndpointCallback *epc){
|
void Endpoint::setCallback(EndpointCallback *epc){
|
||||||
endpointVolume->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)*epc);
|
endpointVolume->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)epc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Endpoint::removeCallback(EndpointCallback *epc){
|
void Endpoint::removeCallback(EndpointCallback *epc){
|
||||||
endpointVolume->UnregisterControlChangeNotify((IAudioEndpointVolumeCallback*)*epc);
|
endpointVolume->UnregisterControlChangeNotify((IAudioEndpointVolumeCallback*)epc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Endpoint::~Endpoint(){
|
Endpoint::~Endpoint(){
|
||||||
|
|
@ -160,6 +174,7 @@ void Overseer::reloadEndpoints() {
|
||||||
IMMDevice *temp;
|
IMMDevice *temp;
|
||||||
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
|
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
|
||||||
Endpoint *endpoint = new Endpoint(temp);
|
Endpoint *endpoint = new Endpoint(temp);
|
||||||
|
endpoint->setIndex(i);
|
||||||
this->playbackDevices.push_back(endpoint);
|
this->playbackDevices.push_back(endpoint);
|
||||||
//TODO: le porblemx std::cout << "ola" << std::endl;
|
//TODO: le porblemx std::cout << "ola" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <wstring>
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <mmdeviceapi.h>
|
#include <mmdeviceapi.h>
|
||||||
|
|
@ -19,12 +20,12 @@
|
||||||
//#include <comip.h>
|
//#include <comip.h>
|
||||||
#include <Winerror.h>
|
#include <Winerror.h>
|
||||||
|
|
||||||
class EndpointWidget;
|
//class EndpointWidget;
|
||||||
|
|
||||||
class EndpointCallback : public IAudioEndpointVolumeCallback {
|
class EndpointCallback : public IAudioEndpointVolumeCallback {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EndpointCallback();
|
EndpointCallback(Endpoint* ep);
|
||||||
|
|
||||||
ULONG AddRef();
|
ULONG AddRef();
|
||||||
ULONG Release();
|
ULONG Release();
|
||||||
|
|
@ -33,7 +34,8 @@ class EndpointCallback : public IAudioEndpointVolumeCallback {
|
||||||
~EndpointCallback();
|
~EndpointCallback();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ULONG ref;
|
ULONG ref = 1;
|
||||||
|
Endpoint* ep;
|
||||||
PAUDIO_VOLUME_NOTIFICATION_DATA update;
|
PAUDIO_VOLUME_NOTIFICATION_DATA update;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -41,6 +43,8 @@ class Endpoint {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Endpoint(IMMDevice* endpoint);
|
Endpoint(IMMDevice* endpoint);
|
||||||
|
uint64_t getIndex();
|
||||||
|
void setIndex(uint64_t idx);
|
||||||
void setVolume(int channel, float volume);
|
void setVolume(int channel, float volume);
|
||||||
/* float getLeftChannelVolume(); */
|
/* float getLeftChannelVolume(); */
|
||||||
/* float getRightChannelVolume(); */
|
/* float getRightChannelVolume(); */
|
||||||
|
|
@ -56,7 +60,8 @@ class Endpoint {
|
||||||
IMMDevice* endpoint;
|
IMMDevice* endpoint;
|
||||||
IAudioEndpointVolume *endpointVolume ;
|
IAudioEndpointVolume *endpointVolume ;
|
||||||
IPropertyStore *properties;
|
IPropertyStore *properties;
|
||||||
LPWSTR friendlyName;
|
std::wstring friendlyName;
|
||||||
|
uint64_t idx;
|
||||||
// LPWSTR endpointID = NULL;
|
// LPWSTR endpointID = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,25 @@
|
||||||
|
#incluse "backlasses.h"
|
||||||
#include "contclasses.h"
|
#include "contclasses.h"
|
||||||
|
|
||||||
Overseer OverseerHandler::os;
|
Overseer OverseerHandler::os;
|
||||||
|
|
||||||
EndpointHandler::EndpointHandler(Endpoint *ep, EndpointCallback *epc, QObject *parent) : QObject(parent) {
|
EndpointHandler::EndpointHandler(uint64_t idx) {
|
||||||
this->ep = ep;
|
std::vector<Endpoint*> endpoints = osh->getPlaybackEndpoints();
|
||||||
this->epc = epc;
|
this->ep = endpoints.at(idx);
|
||||||
|
epc = new EndpointCallback(ep);
|
||||||
epName = QString::fromStdWString(ept->getName());
|
epName = QString::fromStdWString(ept->getName());
|
||||||
ep->setCallback(*epc);
|
ep->setCallback(*epc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EndpointHandler::setIndex(uint64_t idx){
|
||||||
|
this.idx = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t EndpointHandler::getIndex(){
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -1 for master volume
|
* -1 for master volume
|
||||||
*/
|
*/
|
||||||
|
|
@ -42,24 +53,46 @@ EndpointHandler::~EndpointHandler() {
|
||||||
delete ep;
|
delete ep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Endpoint*> OverseerHandler::getPlaybackEndpoints() {
|
||||||
Overseer* OverseerHandler::getOverseer(){
|
return os->getPlaybackEndpoints();
|
||||||
return &os;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OverseerHandler::OverseerHandler(QObject *parent) : QObject(parent) {
|
/*
|
||||||
|
* Overseer* OverseerHandler::getOverseer(){
|
||||||
|
* return &os;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<EndpointHandler*>* OverseerHandler::getEndpointHandlers(){
|
||||||
|
return &endpointHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<EndpointWidget*>* OverseerHandler::getEndpointWidgets(){
|
uint64_t OverseerHandler::getPlaybackEndpointsCount(){
|
||||||
return &endpointWidgets;
|
return os->getplaybackEndpoints().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverseerHandler::reloadEndpointHandlers(){
|
||||||
|
//std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
//setEndpointHandlers(ephs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify){
|
void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify){
|
||||||
log_debugcpp("parsing in da ovasiar");
|
log_debugcpp("parsing in da ovasiar");
|
||||||
for (uint64_t i = 0; i < endpointWidgets.size(); i++){
|
for (uint64_t i = 0; i < endpointHandlers.size(); i++){
|
||||||
if(endpointWidgets.at(i)->eph->epc == fEpc) {
|
if(endpointHandlers.at(i)->eph->epc == fEpc) {
|
||||||
endpointWidgets.at(i)->muteButton->setText(endpointWidgets.at(i)->eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
|
endpointHandlers.at(i)->muteButton->setText(endpointHandlers.at(i)->eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +106,7 @@ void OverseerHandler::parseExternalEndpointCallback(EndpointCallback *fEpc, PAUD
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverseerHandler::setEndpointWidgets(std::vector<EndpointWidget*> ews){
|
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ews){
|
||||||
this->endpointWidgets = ews;
|
this->endpointHandlers = ews;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,51 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include "backlasses.h"
|
#include "backlasses.h"
|
||||||
|
|
||||||
|
|
||||||
class EndpointHandler : public QObject {
|
class EndpointHandler {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EndpointHandler(Endpoint *ept, EndpointCallback *epc, QObject *parent = nullptr);
|
EndpointHandler(Endpoint *ept);
|
||||||
//TODO: get();
|
//TODO: get();
|
||||||
Endpoint *ep;
|
Endpoint *ep;
|
||||||
EndpointCallback *epc;
|
EndpointCallback *epc;
|
||||||
QString epName;
|
QString epName;
|
||||||
|
|
||||||
|
void setIndex(uint64_t idx);
|
||||||
|
void setVolume(int channel, float volume);
|
||||||
|
|
||||||
|
//todo qstrin????? idiota
|
||||||
QString getName();
|
QString getName();
|
||||||
float getVolume(int channel);
|
float getVolume(int channel);
|
||||||
bool getMute();
|
bool getMute();
|
||||||
|
|
||||||
private:
|
|
||||||
//QSlider *slidy;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setValue(int channel, int value);
|
void setValue(int channel, int value);
|
||||||
void setMute();
|
void setMute();
|
||||||
|
private:
|
||||||
|
uint64_t idx;
|
||||||
|
//QSlider *slidy;
|
||||||
|
|
||||||
//signals:
|
//signals:
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class OverseerHandler : public QObject {
|
class OverseerHandler {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OverseerHandler(QObject *parent = nullptr);
|
//OverseerHandler();
|
||||||
void setEndpointWidgets(std::vector<EndpointWidget*> ews);
|
void setEndpointHandlers(std::vector<EndpointHandler*> ews);
|
||||||
std::vector<EndpointWidget*>* getEndpointWidgets();
|
std::vector<EndpointHandler*>* getEndpointHandlers();
|
||||||
|
std::vector<Endpoint*> getPlaybackEndpoints();
|
||||||
|
uint64_t getPlaybackEndpointsCount();
|
||||||
void parseExternalEndpointCallback(EndpointCallback *epc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify);
|
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<EndpointWidget*> endpointWidgets;
|
std::vector<EndpointHandler*> endpointHandlers;
|
||||||
//QSlider *slidy;
|
//QSlider *slidy;
|
||||||
|
|
||||||
//public slots:
|
//public slots:
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,17 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(std::vector<EndpointHandler*> *ephs, QWidget *parent) : QMainWindow(parent) {
|
void EndpointWidget::setIndex(uint64_t idx){
|
||||||
|
this.idx = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t EndpointWidget::getIndex(){
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
||||||
// setWindowState(Qt::WindowFullScreen);
|
// setWindowState(Qt::WindowFullScreen);
|
||||||
// setCentralWidget(centralWidget);
|
// setCentralWidget(centralWidget);
|
||||||
widget = new QWidget();
|
widget = new QWidget();
|
||||||
|
|
@ -81,11 +91,10 @@ MainWindow::MainWindow(std::vector<EndpointHandler*> *ephs, QWidget *parent) : Q
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for (; i < ephs->size(); i++) {
|
for (; i < ephs->size(); i++) {
|
||||||
log_debugcpp("EPWidget creation");
|
log_debugcpp("EPWidget creation");
|
||||||
EndpointWidget *epw = new EndpointWidget(ephs->at(i), widget);
|
EndpointWidget *epw = new EndpointWidget(osh->getEndpointHandlers().at(i), widget);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ public:
|
||||||
EndpointWidget(EndpointHandler* eph, QWidget *parent = nullptr);
|
EndpointWidget(EndpointHandler* eph, QWidget *parent = nullptr);
|
||||||
//TODO: get();
|
//TODO: get();
|
||||||
EndpointHandler* eph;
|
EndpointHandler* eph;
|
||||||
|
void setIndex(uint64_t idx);
|
||||||
|
void setVolume(int channel, float volume);
|
||||||
|
|
||||||
QPushButton *muteButton = nullptr;
|
QPushButton *muteButton = nullptr;
|
||||||
QLabel *mainLabel = nullptr, *leftChannelLabel = nullptr, *rightChannelLabel = nullptr;
|
QLabel *mainLabel = nullptr, *leftChannelLabel = nullptr, *rightChannelLabel = nullptr;
|
||||||
|
|
@ -33,7 +35,7 @@ public:
|
||||||
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
uint64_t idx;
|
||||||
//std::vector<EndpointHandler*> *ephs;
|
//std::vector<EndpointHandler*> *ephs;
|
||||||
//std::vector<QSlider> *sliders;
|
//std::vector<QSlider> *sliders;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,17 +22,11 @@ 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*> eps = OverseerHandler::getOverseer()->getPlaybackEndpoints();
|
osh->reloadEndpointHandlers();
|
||||||
std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//INIT FRONT
|
//INIT FRONT
|
||||||
QScopedPointer<QApplication> app(createApplication(argc, argv));
|
QScopedPointer<QApplication> app(createApplication(argc, argv));
|
||||||
MainWindow window = MainWindow(ephs);
|
MainWindow window = MainWindow();
|
||||||
//window.setEndpointHandlers(ephs);
|
//window.setEndpointHandlers(ephs);
|
||||||
app->setStyle("windowsvista");
|
app->setStyle("windowsvista");
|
||||||
window.show();
|
window.show();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue