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