polling data source vector'd and moved to eph

This commit is contained in:
Hane 2023-08-22 18:28:09 +02:00
commit 8c1cea2da9
4 changed files with 41 additions and 53 deletions

View file

@ -39,14 +39,18 @@ 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;
memcpy(osh->callbackInfo[this->ep->getIndex()]->caller, &pNotify->guidEventContext,sizeof(NGuid) ); //TODO: MEMORY LEAK. FREE DATA4 FROM NGUID.
osh->callbackInfo[this->ep->getIndex()]->muted = pNotify->bMuted; //TODO: el default = objcopy frees?
osh->callbackInfo[this->ep->getIndex()]->mainVolume = pNotify->fMasterVolume; //delete osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller;
osh->callbackInfo[this->ep->getIndex()]->channels = pNotify->nChannels; memcpy(osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller, &pNotify->guidEventContext,sizeof(NGuid) );
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->muted = pNotify->bMuted;
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->mainVolume = pNotify->fMasterVolume;
osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channels = pNotify->nChannels;
UINT i = 0; UINT i = 0;
do { do {
osh->callbackInfo[this->ep->getIndex()]->channelVolumes[i] = pNotify->afChannelVolumes[i]; osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channelVolumes[i] = pNotify->afChannelVolumes[i];
} while(i++ < pNotify->nChannels); } while(i++ < pNotify->nChannels);
return S_OK; return S_OK;

View file

@ -11,6 +11,17 @@ EndpointHandler::EndpointHandler(uint64_t idx) {
epc = new EndpointCallback(ep); epc = new EndpointCallback(ep);
//epName = ep->getName(); //epName = ep->getName();
ep->setCallback(epc); ep->setCallback(epc);
callbackInfo.muted = this->getMute();
callbackInfo.mainVolume = this->getVolume(AudioChannel::CHANNEL_MAIN);
callbackInfo.channels = this->getChannelCount();
callbackInfo.channelVolumes.resize(this->callbackInfo.channels);
for(uint32_t i = 0; i < this->getChannelCount(); i++){
callbackInfo.channelVolumes[i] = this->getVolume(i);
}
}
BackEndpointCallbackInfo* EndpointHandler::getCallbackInfo(){
return &this->callbackInfo;
} }
uint32_t EndpointHandler::getChannelCount(){ uint32_t EndpointHandler::getChannelCount(){

View file

@ -1,12 +1,6 @@
#pragma once #pragma once
#define invoke_mem_fn(object,ptrToMember) ((object).*(ptrToMember)) //#define invoke_mem_fn(object,ptrToMember) ((object).*(ptrToMember))
#define pinvoke_mem_fn(object,ptrToMember) ((object)->*(ptrToMember)) //#define pinvoke_mem_fn(object,ptrToMember) ((object)->*(ptrToMember))
/* #ifndef QTBLESSED */
/* //#define Q_OBJECT */
/* class QWidget{}; */
/* class QMainWindow{}; */
/* #endif */
class EndpointWidget; class EndpointWidget;
class Endpoint; class Endpoint;
@ -31,7 +25,7 @@ struct BackEndpointCallbackInfo {
bool muted; bool muted;
float mainVolume; float mainVolume;
size_t channels; size_t channels;
float* channelVolumes = nullptr; std::vector<float> channelVolumes;
}; };
class EndpointHandler { class EndpointHandler {
@ -43,6 +37,7 @@ public:
EndpointCallback *epc = nullptr; EndpointCallback *epc = nullptr;
//std::wstring epName; //std::wstring epName;
BackEndpointCallbackInfo* getCallbackInfo();
uint32_t getChannelCount(); uint32_t getChannelCount();
void setIndex(uint64_t idx); void setIndex(uint64_t idx);
@ -59,11 +54,8 @@ public:
~EndpointHandler(); ~EndpointHandler();
private: private:
uint64_t idx; uint64_t idx;
BackEndpointCallbackInfo callbackInfo;
//QSlider *slidy; //QSlider *slidy;
//signals:
}; };
@ -78,10 +70,6 @@ public:
void reloadEndpointHandlers(); void reloadEndpointHandlers();
NGuid* getGuid(); NGuid* getGuid();
//TODO: A EPH
BackEndpointCallbackInfo** callbackInfo = nullptr;
int callbackInfoSize = 0;
private: private:
static Overseer os; static Overseer os;
std::vector<EndpointHandler*> endpointHandlers; std::vector<EndpointHandler*> endpointHandlers;

View file

@ -35,13 +35,9 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
mainSlider->setSingleStep(1); mainSlider->setSingleStep(1);
mainSlider->setRange(0,100); mainSlider->setRange(0,100);
//TODO: APARTE
osh->callbackInfo[idx]->muted = eph->getMute();
muteButton->setCheckState((eph->getMute() == false ? Qt::Unchecked : Qt::Checked)); muteButton->setCheckState((eph->getMute() == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE); muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
float volume = eph->getVolume(AudioChannel::CHANNEL_MAIN) * 100; float volume = eph->getVolume(AudioChannel::CHANNEL_MAIN) * 100;
//TODO: APARTE
osh->callbackInfo[idx]->mainVolume = eph->getVolume(AudioChannel::CHANNEL_MAIN);
mainSlider->setValue((int)volume); mainSlider->setValue((int)volume);
log_debugcpp("ENDPOINT SET WITH VOLUME " << volume); log_debugcpp("ENDPOINT SET WITH VOLUME " << volume);
@ -55,9 +51,6 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
connect<void(QSlider::*)(int), void(EndpointWidget::*)(int)>(mainSlider, &QSlider::valueChanged, this,&EndpointWidget::updateMainVolume); connect<void(QSlider::*)(int), void(EndpointWidget::*)(int)>(mainSlider, &QSlider::valueChanged, this,&EndpointWidget::updateMainVolume);
connect<void(QCheckBox::*)(int), void(EndpointWidget::*)(int)>(muteButton, &QCheckBox::stateChanged, this, (&EndpointWidget::updateMute)); connect<void(QCheckBox::*)(int), void(EndpointWidget::*)(int)>(muteButton, &QCheckBox::stateChanged, this, (&EndpointWidget::updateMute));
//TODO: APARTE
osh->callbackInfo[idx]->channels = eph->getChannelCount();
osh->callbackInfo[idx]->channelVolumes = (float*)calloc(osh->callbackInfo[idx]->channels, sizeof(float));
for(uint32_t i = 0; i < eph->getChannelCount(); i++){ for(uint32_t i = 0; i < eph->getChannelCount(); i++){
QSlider* tmp = new QSlider(Qt::Horizontal); QSlider* tmp = new QSlider(Qt::Horizontal);
@ -65,8 +58,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
tmp->setTickInterval(5); tmp->setTickInterval(5);
tmp->setSingleStep(1); tmp->setSingleStep(1);
tmp->setRange(0,100); tmp->setRange(0,100);
//TODO: Aparte
osh->callbackInfo[idx]->channelVolumes[i] = eph->getVolume(i);
volume = eph->getVolume(i) * 100; volume = eph->getVolume(i) * 100;
tmp->setValue((int) volume); tmp->setValue((int) volume);
tmpLb->setText(QString::number(volume)); tmpLb->setText(QString::number(volume));
@ -84,22 +76,25 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
//Polling time //Polling time
timer = new QTimer(this); timer = new QTimer(this);
connect(timer, &QTimer::timeout, [this, idx](){ connect(timer, &QTimer::timeout, [this, eph](){
//if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; //if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW.
const float roundingFactor = 0.005; const float roundingFactor = 0.005;
mainSlider->blockSignals(true); mainSlider->blockSignals(true);
muteButton->blockSignals(true); muteButton->blockSignals(true);
mainSlider->setValue((int)((osh->callbackInfo[idx]->mainVolume + roundingFactor) * 100)); mainSlider->setValue((int)((eph->getCallbackInfo()->mainVolume + roundingFactor) * 100));
muteButton->setCheckState((osh->callbackInfo[idx]->muted == false ? Qt::Unchecked : Qt::Checked)); muteButton->setCheckState((eph->getCallbackInfo()->muted == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(osh->callbackInfo[idx]->muted ? STRING_UNMUTE : STRING_MUTE); muteButton->setText(eph->getCallbackInfo()->muted ? STRING_UNMUTE : STRING_MUTE);
for(uint32_t i = 0; i < osh->callbackInfo[idx]->channels; i++){ for(uint32_t i = 0; i < eph->getCallbackInfo()->channels; i++){
this->channelSliders.at(i)->blockSignals(true); this->channelSliders.at(i)->blockSignals(true);
this->channelSliders.at(i)->setValue((int)((osh->callbackInfo[idx]->channelVolumes[i] + roundingFactor) * 100)); this->channelSliders.at(i)->setValue((int)((eph->getCallbackInfo()->channelVolumes[i] + roundingFactor) * 100));
this->channelLabels.at(i)->setText(QString::number((int)((osh->callbackInfo[idx]->channelVolumes[i] + roundingFactor) * 100))); this->channelLabels.at(i)->setText(QString::number((int)((eph->getCallbackInfo()->channelVolumes[i] + roundingFactor) * 100)));
this->channelSliders.at(i)->blockSignals(false); this->channelSliders.at(i)->blockSignals(false);
} }
//memcpy(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)); //memcpy(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid));
*osh->callbackInfo[idx]->caller = *osh->getGuid();
//TODO: el default = objcopy frees?
//delete eph->getCallbackInfo()->caller;
*eph->getCallbackInfo()->caller = *osh->getGuid();
mainSlider->blockSignals(false); mainSlider->blockSignals(false);
muteButton->blockSignals(false); muteButton->blockSignals(false);
}); });
@ -193,17 +188,7 @@ void MainWindow::reloadEndpointWidgets() {
size_t i = 0; size_t i = 0;
for (; i < (osh->getEndpointHandlers().size()); i++) { for (; i < (osh->getEndpointHandlers().size()); i++) {
log_debugcpp("EPWidget creation"); log_debugcpp("EPWidget creation");
//TODO: APARTE *osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = *osh->getGuid();
if(i >= osh->callbackInfoSize) {
BackEndpointCallbackInfo** temp = (BackEndpointCallbackInfo**)calloc((i + 1), sizeof(BackEndpointCallbackInfo));
memcpy(temp,osh->callbackInfo, i * sizeof(sizeof(BackEndpointCallbackInfo)));
free(osh->callbackInfo);
osh->callbackInfo = temp;
osh->callbackInfo[i] = new BackEndpointCallbackInfo();
osh->callbackInfoSize++;
}
memcpy(osh->callbackInfo[i]->caller, osh->getGuid(),sizeof(NGuid) );
EndpointWidget *epw = new EndpointWidget(i, osh->getEndpointHandlers().at(i), widget); EndpointWidget *epw = new EndpointWidget(i, osh->getEndpointHandlers().at(i), widget);
//TODO: ALWAYS PUSH BACK??? PSZ CHANGE DIS WHEN IMPLEMENTING DYN ENDPOINT DET //TODO: ALWAYS PUSH BACK??? PSZ CHANGE DIS WHEN IMPLEMENTING DYN ENDPOINT DET
ews.push_back(epw); ews.push_back(epw);