Refactored program structure

This commit is contained in:
Hane 2023-08-11 16:39:10 +02:00
commit 80685f1a21
10 changed files with 140 additions and 96 deletions

View file

@ -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"

View file

@ -1,7 +1,7 @@
#include <backlasses.h>
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;
}

View file

@ -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 <vector>
#include <iostream>
#include <wstring>
#include "contclasses.h"
/* #include <vector> */
/* #include <iostream> */
/* #include <wstring> */
#include <Windows.h>
#include <mmdeviceapi.h>
@ -20,24 +22,9 @@
//#include <comip.h>
#include <Winerror.h>
//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<Endpoint*> 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<Endpoint*> playbackDevices;

View file

@ -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<Endpoint*> 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<Endpoint*> OverseerHandler::getPlaybackEndpoints() {
return os->getPlaybackEndpoints();
return os.getPlaybackEndpoints();
}
/*
@ -64,38 +64,46 @@ std::vector<Endpoint*> OverseerHandler::getPlaybackEndpoints() {
*/
std::vector<EndpointHandler*>* OverseerHandler::getEndpointHandlers(){
return &endpointHandlers;
std::vector<EndpointHandler*> OverseerHandler::getEndpointHandlers(){
return endpointHandlers;
}
uint64_t OverseerHandler::getPlaybackEndpointsCount(){
return os->getplaybackEndpoints().size();
return os.getPlaybackEndpoints().size();
}
void OverseerHandler::reloadEndpointHandlers(){
//std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>;
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<EndpointHandler*> ews){
this->endpointHandlers = ews;

View file

@ -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<EndpointHandler*> ews);
std::vector<EndpointHandler*>* getEndpointHandlers();
std::vector<EndpointHandler*> getEndpointHandlers();
std::vector<Endpoint*> 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<EndpointHandler*> endpointHandlers;
//QSlider *slidy;
//public slots:
//void setValue(int value);
};

View file

@ -8,3 +8,4 @@
#else
#define log_debugcpp(str)
#endif

View file

@ -1,5 +1,11 @@
#pragma once
#include <vector>
#include <iostream>
#include <string>
#include "debug.h"
//TODO enum capullo
#define ENDPOINT_MASTER_VOLUME -1
#define ENDPOINT_LEFT_CHANNEL_VOLUME 0

View file

@ -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);

View file

@ -2,13 +2,16 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <vector>
//#include <vector>
#include <QMainWindow>
#include <QApplication>
#include <QLabel>
#include <QSlider>
#include <QGridLayout>
#include <QPushButton>
//#include "debug.h"
#include "global.h"
#include "contclasses.h"
//#include <Q>
//#include <QWidgets>
@ -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<EndpointHandler*> *ephs, QWidget *parent = nullptr);
MainWindow(QWidget *parent = nullptr);
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
private:

View file

@ -1,6 +1,3 @@
#include <iostream>
#include <vector>
//#include <stdio.h>
//#include <stdlib.h>
@ -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<QApplication> app(createApplication(argc, argv));