code cleanup; channels callback coalesced again

This commit is contained in:
Hane 2023-08-15 17:03:23 +02:00
commit 831dceb89a
6 changed files with 58 additions and 55 deletions

View file

@ -56,15 +56,15 @@ HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
log_debugcpp("Onnanokotify says Stored: " << guid->data1); log_debugcpp("Onnanokotify says Stored: " << guid->data1);
log_debugcpp("Onnanokotify says Grace of God: " << eventData.guidEventContext.Data1); log_debugcpp("Onnanokotify says Grace of God: " << eventData.guidEventContext.Data1);
osh->updateMuteCallback(this->ep->getIndex(), eventData.bMuted); osh->updateMuteCallback(this->ep->getIndex(), eventData.bMuted);
osh->updateMainVolumeCallback(this->ep->getIndex(), eventData.fMasterVolume); osh->updateVolumeCallback(this->ep->getIndex(), AudioChannel::CHANNEL_MAIN ,eventData.fMasterVolume);
log_debugcpp("Onnanokotify says Reported Channel Qty: " << eventData.nChannels); log_debugcpp("Onnanokotify says Reported Channel Qty: " << eventData.nChannels);
if(multiChannel) if(multiChannel)
for(UINT i = 0; i < eventData.nChannels; i++) { for(UINT i = 0; i < eventData.nChannels; i++) {
osh->updateChannelVolumeCallback(this->ep->getIndex(), (uint32_t)i, extraChannelVol[i]); osh->updateVolumeCallback(this->ep->getIndex(), (uint32_t)i, extraChannelVol[i]);
} }
else else
osh->updateChannelVolumeCallback(this->ep->getIndex(), (uint32_t)0, pNotify->afChannelVolumes[0]); osh->updateVolumeCallback(this->ep->getIndex(), (uint32_t)0, pNotify->afChannelVolumes[0]);
} }
return S_OK; return S_OK;

View file

@ -6,8 +6,8 @@
Overseer OverseerHandler::os; Overseer OverseerHandler::os;
EndpointHandler::EndpointHandler(uint64_t idx) { EndpointHandler::EndpointHandler(uint64_t idx) {
std::vector<Endpoint*> endpoints = osh->getPlaybackEndpoints(); //std::vector<Endpoint*> endpoints = osh->getPlaybackEndpoints().at(idx);
this->ep = endpoints.at(idx); this->ep = osh->getPlaybackEndpoints().at(idx);
epc = new EndpointCallback(ep); epc = new EndpointCallback(ep);
//epName = ep->getName(); //epName = ep->getName();
ep->setCallback(epc); ep->setCallback(epc);
@ -25,7 +25,6 @@ uint64_t EndpointHandler::getIndex(){
return idx; return idx;
} }
/* /*
* -1 for master volume * -1 for master volume
*/ */
@ -101,20 +100,6 @@ void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){
this->endpointHandlers = ephs; this->endpointHandlers = ephs;
} }
void OverseerHandler::setEndpointWidgets(std::vector<EndpointWidget*> ews){
this->endpointWidgets = ews;
}
void OverseerHandler::updateMuteCallback(uint64_t idx, bool muted){
updateFrontMuteCallback(idx, muted);
}
void OverseerHandler::updateMainVolumeCallback(uint64_t idx, float newVal){
log_debugcpp("mainvolcallback float: " << newVal);
updateFrontVolumeCallback(idx, AudioChannel::CHANNEL_MAIN, newVal);
}
void OverseerHandler::setFrontVolumeCallback(std::function<void(uint64_t, uint32_t, float)> f) { void OverseerHandler::setFrontVolumeCallback(std::function<void(uint64_t, uint32_t, float)> f) {
this->updateFrontVolumeCallback = f; this->updateFrontVolumeCallback = f;
} }
@ -123,11 +108,27 @@ void OverseerHandler::setFrontMuteCallback(std::function<void(uint64_t, bool)> f
this->updateFrontMuteCallback = f; this->updateFrontMuteCallback = f;
} }
void OverseerHandler::updateChannelVolumeCallback(uint64_t idx, uint32_t channel, float newVal){ 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 == AudioChannel::CHANNEL_MAIN) {
log_debugcpp("mainvolcallback float: " << newVal);
updateFrontVolumeCallback(idx, AudioChannel::CHANNEL_MAIN, newVal);
return;
}
log_debugcpp("channel: " << channel << " volcallback float: " << newVal); log_debugcpp("channel: " << channel << " volcallback float: " << newVal);
// convert channel to bitmask // convert channel to bitmask
int i = 0; uint32_t i = 0;
while (i < channel) while (i < channel)
i++; i++;
uint32_t mask = (1 << i); uint32_t mask = (1 << i);

View file

@ -64,7 +64,6 @@ class OverseerHandler {
public: public:
//OverseerHandler(); //OverseerHandler();
void setEndpointHandlers(std::vector<EndpointHandler*> ephs); void setEndpointHandlers(std::vector<EndpointHandler*> ephs);
void setEndpointWidgets(std::vector<EndpointWidget*> ews);
std::vector<EndpointHandler*> getEndpointHandlers(); std::vector<EndpointHandler*> getEndpointHandlers();
std::vector<Endpoint*> getPlaybackEndpoints(); std::vector<Endpoint*> getPlaybackEndpoints();
uint64_t getPlaybackEndpointsCount(); uint64_t getPlaybackEndpointsCount();
@ -73,13 +72,13 @@ public:
void updateMuteCallback(uint64_t idx, bool muted); void updateMuteCallback(uint64_t idx, bool muted);
void setFrontMuteCallback(std::function<void(uint64_t, bool)> f); void setFrontMuteCallback(std::function<void(uint64_t, bool)> f);
void setFrontVolumeCallback(std::function<void(uint64_t, uint32_t, float)> f); void setFrontVolumeCallback(std::function<void(uint64_t, uint32_t, float)> f);
void updateMainVolumeCallback(uint64_t idx, float newVal); //void updateMainVolumeCallback(uint64_t idx, float newVal);
void updateChannelVolumeCallback(uint64_t idx, uint32_t channel, float newVal); void updateVolumeCallback(uint64_t idx, uint32_t channel, float newVal);
private: private:
static Overseer os; static Overseer os;
std::vector<EndpointHandler*> endpointHandlers; std::vector<EndpointHandler*> endpointHandlers;
std::vector<EndpointWidget*> endpointWidgets; std::function<void(uint64_t /* device */, uint32_t /* channel */, float /* value */)> updateFrontVolumeCallback;
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 */, bool /* mute */)> updateFrontMuteCallback = {};
}; };

View file

@ -16,8 +16,14 @@ std::bitset<Y> varToBitset(T info) {
#else #else
#define log_debugcpp(str) #define log_debugcpp(str)
#define print_as_binary(len, info) #define print_as_binary(len, type, info)
#endif #endif
/* Here as a quick reference, in case smthn similar is needed again */
/* typedef void (EndpointWidget::*epwMuteFunc)(bool muted); */
/* typedef void (EndpointWidget::*epwMainVolumeFunc)(float newValue); */
/* typedef void (EndpointWidget::*epwChannelVolumeFunc)(uint32_t channel, float newValue); */
/* typedef void (EndpointWidget::*epwToggleFrontFunc)(bool active); */

View file

@ -73,12 +73,14 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
void EndpointWidget::updateMute(bool muted){ void EndpointWidget::updateMute(bool muted){
log_debugcpp("cliqui callboqui cloqui"); log_debugcpp("cliqui callboqui cloqui");
//TODO: Here to diagnose slider visuals locking when playing DJ with external volume bar. Functionality is restored when mute checkbox is clicked. //TIP: Blocksignals here to diagnose slider visuals locking when playing DJ with external volume bar. Functionality is restored when mute checkbox is clicked.
this->muteButton->blockSignals(true); //this->blockSignals(true);
//this->muteButton->blockSignals(true);
//this->eph->setMute(osh->getGuid(), muted); //this->eph->setMute(osh->getGuid(), muted);
this->muteButton->setChecked(muted); this->muteButton->setChecked(muted);
this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
this->muteButton->blockSignals(false); //this->muteButton->blockSignals(false);
//this->blockSignals(false);
} }
void EndpointWidget::updateMute(int checked){ void EndpointWidget::updateMute(int checked){
@ -96,18 +98,20 @@ void EndpointWidget::updateMainVolume(int newValue){
} }
void EndpointWidget::updateMainVolume(float newValue){ void EndpointWidget::updateMainVolume(float newValue){
//this->blockSignals(true);
int newVal = newValue * 100; int newVal = newValue * 100;
log_debugcpp("mainvolcallback int: " << newVal); log_debugcpp("mainvolcallback int: " << newVal);
//this->mainSlider->blockSignals(true); //this->mainSlider->blockSignals(true);
//TODO: Above
if(this->mainSlider->value() != newVal) { if(this->mainSlider->value() != newVal) {
this->mainSlider->setValue(newVal); this->mainSlider->setValue(newVal);
} }
//this->mainSlider->blockSignals(false); //this->mainSlider->blockSignals(false);
//this->blockSignals(false);
} }
void EndpointWidget::updateChannelVolume(uint32_t channel, float newValue){ void EndpointWidget::updateChannelVolume(uint32_t channel, float newValue){
this->blockSignals(true); //this->blockSignals(true);
if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN)
updateMainVolume(newValue); updateMainVolume(newValue);
@ -116,25 +120,27 @@ void EndpointWidget::updateChannelVolume(uint32_t channel, float newValue){
for (size_t i = 0; i < sizeof(uint32_t) * 8 && i < channelSliders.size(); ++i) { for (size_t i = 0; i < sizeof(uint32_t) * 8 && i < channelSliders.size(); ++i) {
if (((channel >> i) & 1) && this->channelSliders.at(i)->value() != newVal) { if (((channel >> i) & 1) && this->channelSliders.at(i)->value() != newVal) {
this->channelSliders.at(i)->blockSignals(true); //this->channelSliders.at(i)->blockSignals(true);
this->channelSliders.at(i)->setValue(newVal); this->channelSliders.at(i)->setValue(newVal);
this->channelLabels.at(i)->setText(QString::number((int)(newValue * 100))); this->channelLabels.at(i)->setText(QString::number((int)(newValue * 100)));
this->channelSliders.at(i)->blockSignals(false); //this->channelSliders.at(i)->blockSignals(false);
} }
} }
this->blockSignals(false); //this->blockSignals(false);
} }
void EndpointWidget::toggleFrontEvents(bool active){ /*
this->muteButton->blockSignals(active); * void EndpointWidget::toggleFrontEvents(bool active){
this->mainSlider->blockSignals(active); * this->muteButton->blockSignals(active);
for(uint32_t i = 0; i < this->channelSliders.size(); i++){ * this->mainSlider->blockSignals(active);
this->channelSliders.at(i)->blockSignals(active); * for(uint32_t i = 0; i < this->channelSliders.size(); i++){
} * this->channelSliders.at(i)->blockSignals(active);
} * }
* }
*/
void EndpointWidget::setIndex(uint64_t idx){ void EndpointWidget::setIndex(uint64_t idx){
@ -168,7 +174,7 @@ void MainWindow::reloadEndpointWidgets() {
ews.push_back(epw); ews.push_back(epw);
layout->addWidget(epw, i, 0); layout->addWidget(epw, i, 0);
} }
osh->setEndpointWidgets(ews);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 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) { osh->setFrontVolumeCallback([this](uint64_t device, uint32_t channel, float value) {
@ -181,9 +187,6 @@ void MainWindow::reloadEndpointWidgets() {
}); });
} }
//#include "qtclosemwh.h"
/* /*
* void MainWindow::setPlotButton() { * void MainWindow::setPlotButton() {
* button = new QPushButton("push"), * button = new QPushButton("push"),

View file

@ -71,7 +71,7 @@ public:
void updateMainVolume(float newValue); void updateMainVolume(float newValue);
void updateChannelVolume(uint32_t channel, float newValue); void updateChannelVolume(uint32_t channel, float newValue);
void updateMute(bool muted); void updateMute(bool muted);
void toggleFrontEvents(bool active); //void toggleFrontEvents(bool active);
//void populateEndpointWidget(EndpointHandler *eph); //void populateEndpointWidget(EndpointHandler *eph);
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs); //void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
@ -84,18 +84,12 @@ private:
uint64_t idx; uint64_t idx;
//std::vector<EndpointHandler*> *ephs; //std::vector<EndpointHandler*> *ephs;
//std::vector<QSlider> *sliders; //std::vector<QSlider> *sliders;
//signals: //signals:
//void valueChanged(int value); //void valueChanged(int value);
}; };
typedef void (EndpointWidget::*epwMuteFunc)(bool muted);
typedef void (EndpointWidget::*epwMainVolumeFunc)(float newValue);
typedef void (EndpointWidget::*epwChannelVolumeFunc)(uint32_t channel, float newValue);
typedef void (EndpointWidget::*epwToggleFrontFunc)(bool active);
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
//QWidget *centralWidget; //QWidget *centralWidget;