diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 546c863..6c16ceb 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -38,17 +38,21 @@ HRESULT EndpointCallback::QueryInterface(REFIID riid, VOID **ppvInterface) { HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) { if (pNotify == NULL) return E_INVALIDARG; - - memcpy(osh->callbackInfo[this->ep->getIndex()]->caller, &pNotify->guidEventContext,sizeof(NGuid) ); - osh->callbackInfo[this->ep->getIndex()]->muted = pNotify->bMuted; - osh->callbackInfo[this->ep->getIndex()]->mainVolume = pNotify->fMasterVolume; - osh->callbackInfo[this->ep->getIndex()]->channels = pNotify->nChannels; + + //TODO: MEMORY LEAK. FREE DATA4 FROM NGUID. + //TODO: el default = objcopy frees? + //delete osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller; + 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; 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); - + return S_OK; } diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index b528c58..f51125d 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -11,6 +11,17 @@ EndpointHandler::EndpointHandler(uint64_t idx) { epc = new EndpointCallback(ep); //epName = ep->getName(); 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(){ diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index b8df406..acfa66b 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -1,12 +1,6 @@ #pragma once -#define invoke_mem_fn(object,ptrToMember) ((object).*(ptrToMember)) -#define pinvoke_mem_fn(object,ptrToMember) ((object)->*(ptrToMember)) - -/* #ifndef QTBLESSED */ -/* //#define Q_OBJECT */ -/* class QWidget{}; */ -/* class QMainWindow{}; */ -/* #endif */ +//#define invoke_mem_fn(object,ptrToMember) ((object).*(ptrToMember)) +//#define pinvoke_mem_fn(object,ptrToMember) ((object)->*(ptrToMember)) class EndpointWidget; class Endpoint; @@ -31,7 +25,7 @@ struct BackEndpointCallbackInfo { bool muted; float mainVolume; size_t channels; - float* channelVolumes = nullptr; + std::vector channelVolumes; }; class EndpointHandler { @@ -43,6 +37,7 @@ public: EndpointCallback *epc = nullptr; //std::wstring epName; + BackEndpointCallbackInfo* getCallbackInfo(); uint32_t getChannelCount(); void setIndex(uint64_t idx); @@ -59,11 +54,8 @@ public: ~EndpointHandler(); private: uint64_t idx; + BackEndpointCallbackInfo callbackInfo; //QSlider *slidy; - -//signals: - - }; @@ -77,10 +69,6 @@ public: uint64_t getPlaybackEndpointsCount(); void reloadEndpointHandlers(); NGuid* getGuid(); - - //TODO: A EPH - BackEndpointCallbackInfo** callbackInfo = nullptr; - int callbackInfoSize = 0; private: static Overseer os; diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index ace2e2b..4da3f95 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -35,13 +35,9 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare mainSlider->setSingleStep(1); mainSlider->setRange(0,100); - //TODO: APARTE - osh->callbackInfo[idx]->muted = eph->getMute(); muteButton->setCheckState((eph->getMute() == false ? Qt::Unchecked : Qt::Checked)); muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE); float volume = eph->getVolume(AudioChannel::CHANNEL_MAIN) * 100; - //TODO: APARTE - osh->callbackInfo[idx]->mainVolume = eph->getVolume(AudioChannel::CHANNEL_MAIN); mainSlider->setValue((int)volume); log_debugcpp("ENDPOINT SET WITH VOLUME " << volume); @@ -55,9 +51,6 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare connect(mainSlider, &QSlider::valueChanged, this,&EndpointWidget::updateMainVolume); connect(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++){ QSlider* tmp = new QSlider(Qt::Horizontal); @@ -65,8 +58,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare tmp->setTickInterval(5); tmp->setSingleStep(1); tmp->setRange(0,100); - //TODO: Aparte - osh->callbackInfo[idx]->channelVolumes[i] = eph->getVolume(i); + volume = eph->getVolume(i) * 100; tmp->setValue((int) volume); tmpLb->setText(QString::number(volume)); @@ -84,22 +76,25 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare //Polling time timer = new QTimer(this); - connect(timer, &QTimer::timeout, [this, idx](){ - //if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; + connect(timer, &QTimer::timeout, [this, eph](){ + //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; mainSlider->blockSignals(true); muteButton->blockSignals(true); - mainSlider->setValue((int)((osh->callbackInfo[idx]->mainVolume + roundingFactor) * 100)); - muteButton->setCheckState((osh->callbackInfo[idx]->muted == false ? Qt::Unchecked : Qt::Checked)); - muteButton->setText(osh->callbackInfo[idx]->muted ? STRING_UNMUTE : STRING_MUTE); - for(uint32_t i = 0; i < osh->callbackInfo[idx]->channels; i++){ + mainSlider->setValue((int)((eph->getCallbackInfo()->mainVolume + roundingFactor) * 100)); + muteButton->setCheckState((eph->getCallbackInfo()->muted == false ? Qt::Unchecked : Qt::Checked)); + muteButton->setText(eph->getCallbackInfo()->muted ? STRING_UNMUTE : STRING_MUTE); + for(uint32_t i = 0; i < eph->getCallbackInfo()->channels; i++){ this->channelSliders.at(i)->blockSignals(true); - this->channelSliders.at(i)->setValue((int)((osh->callbackInfo[idx]->channelVolumes[i] + roundingFactor) * 100)); - this->channelLabels.at(i)->setText(QString::number((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)((eph->getCallbackInfo()->channelVolumes[i] + roundingFactor) * 100))); this->channelSliders.at(i)->blockSignals(false); } //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); muteButton->blockSignals(false); }); @@ -193,17 +188,7 @@ void MainWindow::reloadEndpointWidgets() { size_t i = 0; for (; i < (osh->getEndpointHandlers().size()); i++) { log_debugcpp("EPWidget creation"); - //TODO: APARTE - 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) ); - + *osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = *osh->getGuid(); EndpointWidget *epw = new EndpointWidget(i, osh->getEndpointHandlers().at(i), widget); //TODO: ALWAYS PUSH BACK??? PSZ CHANGE DIS WHEN IMPLEMENTING DYN ENDPOINT DET ews.push_back(epw);