back to front now works without hangs?
This commit is contained in:
parent
966cf91a23
commit
d1f0bcaf26
5 changed files with 166 additions and 78 deletions
|
|
@ -39,33 +39,45 @@ 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];
|
||||
bool multiChannel = false;
|
||||
AUDIO_VOLUME_NOTIFICATION_DATA eventData = *pNotify;
|
||||
if(pNotify->nChannels > 1) {
|
||||
multiChannel = true;
|
||||
for (UINT i = 0; i < pNotify->nChannels; i++){
|
||||
extraChannelVol[i] = pNotify->afChannelVolumes[i];
|
||||
}
|
||||
}
|
||||
NGuid* guid = osh->getGuid();
|
||||
/*
|
||||
* float extraChannelVol[pNotify->nChannels];
|
||||
* for (UINT i = 0; i < pNotify->nChannels; i++){
|
||||
* AUDIO_VOLUME_NOTIFICATION_DATA eventData = *pNotify;
|
||||
* extraChannelVol[i] = pNotify->afChannelVolumes[i];
|
||||
* }
|
||||
*/
|
||||
|
||||
if (memcmp(guid, &eventData, 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);
|
||||
// osh->callbackInfo[this->ep->getIndex()]->caller = (NGuid)pNotify->guidEventContext;
|
||||
memcpy(osh->callbackInfo[this->ep->getIndex()]->caller, &pNotify->guidEventContext,sizeof(NGuid) );
|
||||
|
||||
if(multiChannel)
|
||||
for(UINT i = 0; i < eventData.nChannels; i++) {
|
||||
osh->updateVolumeCallback(this->ep->getIndex(), (uint32_t)i, extraChannelVol[i]);
|
||||
}
|
||||
else
|
||||
osh->updateVolumeCallback(this->ep->getIndex(), (uint32_t)0, pNotify->afChannelVolumes[0]);
|
||||
}
|
||||
osh->callbackInfo[this->ep->getIndex()]->muted = pNotify->bMuted;
|
||||
osh->callbackInfo[this->ep->getIndex()]->mainVolume = pNotify->fMasterVolume;
|
||||
osh->callbackInfo[this->ep->getIndex()]->channels = pNotify->nChannels;
|
||||
|
||||
UINT i = 0;
|
||||
do {
|
||||
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;
|
||||
}
|
||||
|
|
@ -118,9 +130,10 @@ uint32_t Endpoint::getChannelCount(){
|
|||
bool Endpoint::getMute(){
|
||||
BOOL mut;
|
||||
if(FAILED(endpointVolume->GetMute(&mut))) { log_debugcpp("si"); }
|
||||
log_debugcpp("back BOOL is " << mut);
|
||||
//TODO: mutex test
|
||||
//log_debugcpp("back BOOL is " << mut);
|
||||
bool mute = (bool)mut;
|
||||
log_debugcpp("translate to bool " << mute);
|
||||
//log_debugcpp("translate to bool " << mute);
|
||||
return mute;
|
||||
}
|
||||
|
||||
|
|
@ -140,12 +153,14 @@ bool Endpoint::getMute(){
|
|||
|
||||
|
||||
void Endpoint::setVolume(NGuid* guid, int channel, float volume) {
|
||||
//TODO: mutex test
|
||||
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))) { //log_debugcpp("MASTER VOLUME FAILED");
|
||||
};
|
||||
} else {
|
||||
log_debugcpp("Windows: Channel being updated: " << channel);
|
||||
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) { log_debugcpp("CHANNEL "<< channel <<" VOLUME FAILED"); };
|
||||
//log_debugcpp("Windows: Channel being updated: " << channel);
|
||||
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) { /* log_debugcpp("CHANNEL "<< channel <<" VOLUME FAILED"); */ };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ void EndpointHandler::setVolume(NGuid* guid, int channel, int value){
|
|||
|
||||
void EndpointHandler::setMute(NGuid* guid, bool muted){
|
||||
//Qt momento, de ahi el param?
|
||||
log_debugcpp("kinda handling the muting tbh");
|
||||
//TODO: mutex test
|
||||
//log_debugcpp("kinda handling the muting tbh");
|
||||
ep->setMute(guid, muted);
|
||||
}
|
||||
|
||||
|
|
@ -108,9 +109,11 @@ 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::updateMuteCallback(uint64_t idx, bool muted){
|
||||
* updateFrontMuteCallback(idx, muted);
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* void OverseerHandler::updateMainVolumeCallback(uint64_t idx, float newVal){
|
||||
|
|
@ -118,21 +121,32 @@ void OverseerHandler::updateMuteCallback(uint64_t idx, bool muted){
|
|||
* }
|
||||
*/
|
||||
|
||||
void OverseerHandler::updateVolumeCallback(uint64_t idx, uint32_t channel, float newVal){
|
||||
if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) {
|
||||
log_debugcpp("mainvolcallback float: " << newVal);
|
||||
updateFrontVolumeCallback(idx, AudioChannel::CHANNEL_MAIN, newVal);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* 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);
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
// convert channel to bitmask
|
||||
uint32_t i = 0;
|
||||
while (i < channel)
|
||||
i++;
|
||||
uint32_t mask = (1 << i);
|
||||
|
||||
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);
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,10 +20,18 @@ enum AudioChannel {
|
|||
};
|
||||
|
||||
struct NGuid {
|
||||
uint32_t data1;
|
||||
uint16_t data2;
|
||||
uint16_t data3;
|
||||
unsigned char data4[8];
|
||||
uint32_t data1;
|
||||
uint16_t data2;
|
||||
uint16_t data3;
|
||||
unsigned char data4[8];
|
||||
};
|
||||
|
||||
struct BackEndpointCallbackInfo {
|
||||
NGuid* caller = new NGuid();
|
||||
bool muted;
|
||||
float mainVolume;
|
||||
size_t channels;
|
||||
float* channelVolumes = nullptr;
|
||||
};
|
||||
|
||||
class EndpointHandler {
|
||||
|
|
@ -69,15 +77,20 @@ public:
|
|||
uint64_t getPlaybackEndpointsCount();
|
||||
void reloadEndpointHandlers();
|
||||
NGuid* getGuid();
|
||||
void updateMuteCallback(uint64_t idx, bool muted);
|
||||
void setFrontMuteCallback(std::function<void(uint64_t, bool)> f);
|
||||
void setFrontVolumeCallback(std::function<void(uint64_t, uint32_t, float)> f);
|
||||
//void updateMainVolumeCallback(uint64_t idx, float newVal);
|
||||
void updateVolumeCallback(uint64_t idx, uint32_t channel, float newVal);
|
||||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
* }
|
||||
*/
|
||||
|
||||
EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(parent){
|
||||
EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent) : QWidget(parent){
|
||||
this->idx = idx;
|
||||
this->eph = eph;
|
||||
layout = new QGridLayout();
|
||||
this->setLayout(layout);
|
||||
|
|
@ -34,9 +35,13 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
|
|||
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(ENDPOINT_MASTER_VOLUME) * 100;
|
||||
//TODO: APARTE
|
||||
osh->callbackInfo[idx]->mainVolume = eph->getVolume(ENDPOINT_MASTER_VOLUME);
|
||||
mainSlider->setValue((int)volume);
|
||||
log_debugcpp("ENDPOINT SET WITH VOLUME " << volume);
|
||||
|
||||
|
|
@ -46,8 +51,15 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
|
|||
mainMuteLayout->addWidget(muteButton, 0, 1);
|
||||
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));
|
||||
|
||||
for(uint32_t i = 0; i < eph->getChannelCount(); i++){
|
||||
QSlider* tmp = new QSlider(Qt::Horizontal);
|
||||
|
|
@ -55,6 +67,8 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
|
|||
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));
|
||||
|
|
@ -63,24 +77,39 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
|
|||
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](){
|
||||
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);
|
||||
for(uint32_t i = 0; i < osh->callbackInfo[idx]->channels; i++){
|
||||
this->channelSliders.at(i)->setValue((int)(osh->callbackInfo[idx]->channelVolumes[i] * 100));
|
||||
this->channelLabels.at(i)->setText(QString::number((int)(osh->callbackInfo[idx]->channelVolumes[i] * 100)));
|
||||
}
|
||||
});
|
||||
timer->start(10);
|
||||
|
||||
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 0);
|
||||
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 1);
|
||||
log_debugcpp("ENDPOINT_WIDGETED");
|
||||
}
|
||||
|
||||
void EndpointWidget::updateMute(bool muted){
|
||||
log_debugcpp("cliqui callboqui cloqui");
|
||||
//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);
|
||||
this->muteButton->blockSignals(true);
|
||||
|
||||
//this->eph->setMute(osh->getGuid(), muted);
|
||||
this->muteButton->setChecked(muted);
|
||||
this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
|
||||
//this->muteButton->blockSignals(false);
|
||||
this->muteButton->blockSignals(false);
|
||||
//this->blockSignals(false);
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +123,8 @@ void EndpointWidget::updateMute(int checked){
|
|||
}
|
||||
|
||||
void EndpointWidget::updateMainVolume(int newValue){
|
||||
log_debugcpp("updateMainVolume slot.");
|
||||
//TODO: mutex test
|
||||
//log_debugcpp("updateMainVolume slot.");
|
||||
this->eph->setVolume(osh->getGuid(), ENDPOINT_MASTER_VOLUME, newValue);
|
||||
}
|
||||
|
||||
|
|
@ -102,16 +132,19 @@ void EndpointWidget::updateVolume(uint32_t channel, float newValue){
|
|||
//this->blockSignals(true);
|
||||
int newVal = newValue * 100;
|
||||
if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) {
|
||||
log_debugcpp("mainvolcallback int: " << newVal);
|
||||
//TODO: mutex test
|
||||
//log_debugcpp("mainvolcallback int: " << newVal);
|
||||
//this->mainSlider->blockSignals(true);
|
||||
|
||||
if(this->mainSlider->value() != newVal) {
|
||||
this->mainSlider->blockSignals(true);
|
||||
this->mainSlider->setValue(newVal);
|
||||
this->mainSlider->blockSignals(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
log_debugcpp("Cont->Front Channel:: " << channel << " volcallback int: " << newVal);
|
||||
//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) {
|
||||
|
|
@ -162,23 +195,35 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
}
|
||||
|
||||
void MainWindow::reloadEndpointWidgets() {
|
||||
unsigned int i = 0;
|
||||
size_t i = 0;
|
||||
for (; i < (osh->getEndpointHandlers().size()); i++) {
|
||||
log_debugcpp("EPWidget creation");
|
||||
EndpointWidget *epw = new EndpointWidget(osh->getEndpointHandlers().at(i), widget);
|
||||
//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) );
|
||||
|
||||
EndpointWidget *epw = new EndpointWidget(i, osh->getEndpointHandlers().at(i), widget);
|
||||
ews.push_back(epw);
|
||||
layout->addWidget(epw, i, 0);
|
||||
|
||||
}
|
||||
|
||||
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[device]->updateVolume(channel, value);
|
||||
ews.at(device)->updateVolume(channel, value);
|
||||
});
|
||||
osh->setFrontMuteCallback([this](uint64_t device, bool muted) {
|
||||
if (device < ews.size())
|
||||
ews[device]->updateMute(muted);
|
||||
ews.at(device)->updateMute(muted);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <QGridLayout>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QTimer>
|
||||
/*
|
||||
* #else
|
||||
* class QSlider;
|
||||
|
|
@ -53,7 +54,7 @@ class EndpointWidget : public QWidget {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EndpointWidget(EndpointHandler* eph, QWidget *parent = nullptr);
|
||||
EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr);
|
||||
//TODO: get();
|
||||
EndpointHandler* eph;
|
||||
void setIndex(uint64_t idx);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue