full functionality restored, slight cleanup

This commit is contained in:
Hane 2023-08-16 23:18:36 +02:00
commit 1797b39b30
5 changed files with 27 additions and 150 deletions

View file

@ -39,17 +39,7 @@ HRESULT EndpointCallback::QueryInterface(REFIID riid, VOID **ppvInterface) {
HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
if (pNotify == NULL) return E_INVALIDARG;
/*
* float extraChannelVol[pNotify->nChannels];
* for (UINT i = 0; i < pNotify->nChannels; i++){
* AUDIO_VOLUME_NOTIFICATION_DATA eventData = *pNotify;
* extraChannelVol[i] = pNotify->afChannelVolumes[i];
* }
*/
// osh->callbackInfo[this->ep->getIndex()]->caller = (NGuid)pNotify->guidEventContext;
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;
@ -59,33 +49,9 @@ HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
osh->callbackInfo[this->ep->getIndex()]->channelVolumes[i] = pNotify->afChannelVolumes[i];
} while(i++ < pNotify->nChannels);
//osh->receiveBackEndpointCallback(this->ep->getIndex());
/* NGuid* guid = osh->getGuid();
* //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
* if (memcmp(guid, &eventData.guidEventContext, sizeof(*guid)) == 0) {
* //log_debugcpp("Onnanokotify says You Shall Not Update Thy Interface.");
* } else {
* //log_debugcpp("Onnanokotify says Stored: " << guid->data1);
* //log_debugcpp("Onnanokotify says Grace of God: " << eventData.guidEventContext.Data1);
* osh->updateMuteCallback(this->ep->getIndex(), eventData.bMuted);
* osh->updateVolumeCallback(this->ep->getIndex(), AudioChannel::CHANNEL_MAIN ,eventData.fMasterVolume);
* //log_debugcpp("Onnanokotify says Reported Channel Qty: " << eventData.nChannels);
*
*
* for(UINT i = 0; i < eventData.nChannels; i++) {
* osh->updateVolumeCallback(this->ep->getIndex(), (uint32_t)i, extraChannelVol[i]);
* }
* }
*/
return S_OK;
}
/* EndpointCallback::~EndpointCallback(){
* PAUDIO_VOLUME_NOTIFICATION_DATA->Release();
* } */
Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
this->endpoint = ep;
this->idx = idx;
@ -129,11 +95,8 @@ uint32_t Endpoint::getChannelCount(){
bool Endpoint::getMute(){
BOOL mut;
if(FAILED(endpointVolume->GetMute(&mut))) { log_debugcpp("si"); }
//TODO: mutex test
//log_debugcpp("back BOOL is " << mut);
if(FAILED(endpointVolume->GetMute(&mut))) { /* TIP: Below */ }
bool mute = (bool)mut;
//log_debugcpp("translate to bool " << mute);
return mute;
}
@ -153,25 +116,18 @@ bool Endpoint::getMute(){
void Endpoint::setVolume(NGuid* guid, int channel, float volume) {
//TODO: mutex test
//TIP: There used to be log messages here. Now, it's a ghost town.
GUID tempMsGuid = NGuidToGUID(guid);
if (channel == AudioChannel::CHANNEL_MAIN) {
if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, &tempMsGuid))) { //log_debugcpp("MASTER VOLUME FAILED");
};
if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, &tempMsGuid))) {};
} else {
//log_debugcpp("Windows: Channel being updated: " << channel);
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) { /* log_debugcpp("CHANNEL "<< channel <<" VOLUME FAILED"); */ };
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) { };
}
}
void Endpoint::setMute(NGuid* guid, bool muted) {
//BOOL mut;
//log_debugcpp("bool mute arrives as " << mut);
//if(FAILED(endpointVolume->GetMute(&mut))) { log_debugcpp("si"); }
//log_debugcpp("translate to BOOL as " << mut);
//TODO: use new funcs
GUID tempMsGuid = NGuidToGUID(guid);
if(FAILED(endpointVolume->SetMute(muted, &tempMsGuid))) { log_debugcpp("MUTE FAILED"); };
if(FAILED(endpointVolume->SetMute(muted, &tempMsGuid))) { /* TIP: Above */ };
}
void Endpoint::setCallback(EndpointCallback *epc){

View file

@ -29,15 +29,12 @@ uint64_t EndpointHandler::getIndex(){
* -1 for master volume
*/
void EndpointHandler::setVolume(NGuid* guid, int channel, int value){
if (channel == ENDPOINT_MASTER_VOLUME)
if (channel == AudioChannel::CHANNEL_MAIN)
ep->setVolume(guid, channel, (float)value / 100);
else ep->setVolume(guid, channel, (float)value / 100);
}
void EndpointHandler::setMute(NGuid* guid, bool muted){
//Qt momento, de ahi el param?
//TODO: mutex test
//log_debugcpp("kinda handling the muting tbh");
ep->setMute(guid, muted);
}
@ -100,53 +97,3 @@ NGuid* OverseerHandler::getGuid() {
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){
this->endpointHandlers = ephs;
}
void OverseerHandler::setFrontVolumeCallback(std::function<void(uint64_t, uint32_t, float)> f) {
this->updateFrontVolumeCallback = f;
}
void OverseerHandler::setFrontMuteCallback(std::function<void(uint64_t, bool)> f) {
this->updateFrontMuteCallback = f;
}
/*
* void OverseerHandler::updateMuteCallback(uint64_t idx, bool muted){
* updateFrontMuteCallback(idx, muted);
* }
*/
/*
* void OverseerHandler::updateMainVolumeCallback(uint64_t idx, float newVal){
*
* }
*/
/*
* void OverseerHandler::updateVolumeCallback(uint64_t idx, uint32_t channel, float newVal){
* if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) {
* //TODO: mutex test
* //log_debugcpp("mainvolcallback float: " << newVal);
* updateFrontVolumeCallback(idx, AudioChannel::CHANNEL_MAIN, newVal);
* return;
* }
*
*
* // convert channel to bitmask
* uint32_t i = 0;
* while (i < channel)
* i++;
* uint32_t mask = (1 << i);
* //TODO: Mutex test
* //log_debugcpp("Back->Cont Channel: " << mask << " volcallback float: " << newVal);
*
* updateFrontVolumeCallback(idx, mask, newVal);
* }
*/
/*
* void OverseerHandler::receiveBackEndpointCallback(uint64_t index) {
* if (memcmp(os.getGuid(), callbackInfo.caller, sizeof(*guid)) != 0)
* updateFrontCallback(uint64_t index, &callbackInfo);
*
* }
*/

View file

@ -77,21 +77,16 @@ public:
uint64_t getPlaybackEndpointsCount();
void reloadEndpointHandlers();
NGuid* getGuid();
void setFrontMuteCallback(std::function<void(uint64_t, bool)> f);
void setFrontVolumeCallback(std::function<void(uint64_t, uint32_t, float)> f);
void setUpdateFrontCallback(std::function<void(uint64_t, BackEndpointCallbackInfo*)> f);
//TODO: A EPH
BackEndpointCallbackInfo** callbackInfo = nullptr;
int callbackInfoSize = 0;
/* void updateMuteCallback(uint64_t idx, bool muted); */
/* void updateVolumeCallback(uint64_t idx, uint32_t channel, float newVal); */
//void receiveBackEndpointCallback(uint64_t index);
private:
static Overseer os;
std::vector<EndpointHandler*> endpointHandlers;
std::function<void(uint64_t /* device */, uint32_t /* channel */, float /* value */)> updateFrontVolumeCallback;
std::function<void(uint64_t /* device */, bool /* mute */)> updateFrontMuteCallback;
//std::function<void(uint64_t /* device */, uint32_t /* channel */, float /* value */)> updateFrontVolumeCallback;
//std::function<void(uint64_t /* device */, bool /* mute */)> updateFrontMuteCallback;
};

View file

@ -52,11 +52,10 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
layout->addWidget(mainSlider, 0, 1);
/*
* 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(QSlider::*)(int), void(EndpointWidget::*)(int)>(mainSlider, &QSlider::valueChanged, this,&EndpointWidget::updateMainVolume);
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));
@ -77,13 +76,13 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
layout->addWidget(tmp, 1, i);
layout->addWidget(tmpLb, 2, i);
//TODO: check if there's a need to prevent deadlocks; probably this will eventually turn into its own func
/*
* connect(tmp, &QSlider::valueChanged, [this, i](int newValue){ this->eph->setVolume(osh->getGuid(), i, newValue); this->channelLabels.at(i)->setText(QString::number(newValue)); });
*/
connect(tmp, &QSlider::valueChanged, [this, i](int newValue){ this->eph->setVolume(osh->getGuid(), i, newValue); this->channelLabels.at(i)->setText(QString::number(newValue)); });
}
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, [this, idx](){
if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return;
mainSlider->setValue((int)(osh->callbackInfo[idx]->mainVolume * 100));
muteButton->setCheckState((osh->callbackInfo[idx]->muted == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(osh->callbackInfo[idx]->muted ? STRING_UNMUTE : STRING_MUTE);
@ -100,8 +99,6 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
}
void EndpointWidget::updateMute(bool muted){
//TODO: mutex test
//log_debugcpp("cliqui callboqui cloqui");
//TIP: Blocksignals here to diagnose slider visuals locking when playing DJ with external volume bar. Functionality is restored when mute checkbox is clicked.
//this->blockSignals(true);
this->muteButton->blockSignals(true);
@ -114,17 +111,12 @@ void EndpointWidget::updateMute(bool muted){
}
void EndpointWidget::updateMute(int checked){
log_debugcpp("cliqui slOtty cloqui");
bool muted = (checked == 2 ? true : false);
log_debugcpp("int: " << checked << " bool: " << muted);
this->eph->setMute(osh->getGuid(), muted);
//this->muteButton->setCheckState();
this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
}
void EndpointWidget::updateMainVolume(int newValue){
//TODO: mutex test
//log_debugcpp("updateMainVolume slot.");
this->eph->setVolume(osh->getGuid(), ENDPOINT_MASTER_VOLUME, newValue);
}
@ -132,8 +124,7 @@ void EndpointWidget::updateVolume(uint32_t channel, float newValue){
//this->blockSignals(true);
int newVal = newValue * 100;
if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) {
//TODO: mutex test
//log_debugcpp("mainvolcallback int: " << newVal);
//TIP: Above
//this->mainSlider->blockSignals(true);
if(this->mainSlider->value() != newVal) {
@ -143,8 +134,6 @@ void EndpointWidget::updateVolume(uint32_t channel, float newValue){
}
return;
}
//TODO: mutex test
//log_debugcpp("Cont->Front Channel:: " << channel << " volcallback int: " << newVal);
for (size_t i = 0; i < sizeof(uint32_t) * 8 && i < channelSliders.size(); ++i) {
if (((channel >> i) & 1) && this->channelSliders.at(i)->value() != newVal) {
@ -160,17 +149,6 @@ void EndpointWidget::updateVolume(uint32_t channel, float newValue){
//this->blockSignals(false);
}
/*
* void EndpointWidget::toggleFrontEvents(bool active){
* this->muteButton->blockSignals(active);
* this->mainSlider->blockSignals(active);
* for(uint32_t i = 0; i < this->channelSliders.size(); i++){
* this->channelSliders.at(i)->blockSignals(active);
* }
* }
*/
void EndpointWidget::setIndex(uint64_t idx){
this->idx = idx;
}
@ -217,14 +195,16 @@ void MainWindow::reloadEndpointWidgets() {
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), i, 0);
osh->setFrontVolumeCallback([this](uint64_t device, uint32_t channel, float value) {
if (device < ews.size())
ews.at(device)->updateVolume(channel, value);
});
osh->setFrontMuteCallback([this](uint64_t device, bool muted) {
if (device < ews.size())
ews.at(device)->updateMute(muted);
});
/*
* osh->setFrontVolumeCallback([this](uint64_t device, uint32_t channel, float value) {
* if (device < ews.size())
* ews.at(device)->updateVolume(channel, value);
* });
* osh->setFrontMuteCallback([this](uint64_t device, bool muted) {
* if (device < ews.size())
* ews.at(device)->updateMute(muted);
* });
*/
}
/*

View file

@ -72,7 +72,6 @@ public:
//void updateMainVolume(float newValue);
void updateVolume(uint32_t channel, float newValue);
void updateMute(bool muted);
//void toggleFrontEvents(bool active);
//void populateEndpointWidget(EndpointHandler *eph);
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);