From c435fcfa076dfbf3d3205062dfca9d8bd7935043 Mon Sep 17 00:00:00 2001 From: Phireh Date: Mon, 14 Aug 2023 20:10:59 +0200 Subject: [PATCH 1/3] Remove frontend header from contclasses --- src/back/backlasses.cpp | 2 -- src/cont/contclasses.cpp | 44 ++++++++++++++++------------------------ src/cont/contclasses.h | 16 ++++++++++----- src/qt/qtclasses.cpp | 39 ++++++++++++++++++++++++++--------- src/qt/qtclasses.h | 1 + 5 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 5030f11..32c7940 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -55,7 +55,6 @@ HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) { } else { log_debugcpp("Onnanokotify says Stored: " << guid->data1); log_debugcpp("Onnanokotify says Grace of God: " << eventData.guidEventContext.Data1); - osh->toggleFrontEvents(this->ep->getIndex(), true); osh->updateMuteCallback(this->ep->getIndex(), eventData.bMuted); osh->updateMainVolumeCallback(this->ep->getIndex(), eventData.fMasterVolume); log_debugcpp("Onnanokotify says Reported Channel Qty: " << eventData.nChannels); @@ -66,7 +65,6 @@ HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) { } else osh->updateChannelVolumeCallback(this->ep->getIndex(), (uint32_t)0, pNotify->afChannelVolumes[0]); - osh->toggleFrontEvents(this->ep->getIndex(), false); } return S_OK; diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index 8281bb8..36b913d 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -1,5 +1,4 @@ #include "backlasses.h" -#include "qtclasses.h" #include "contclasses.h" //TODO: pragma once @@ -64,12 +63,6 @@ std::vector OverseerHandler::getPlaybackEndpoints() { return this->os.getPlaybackEndpoints(); } -/* - * Overseer* OverseerHandler::getOverseer(){ - * return &os; - * } - */ - std::vector OverseerHandler::getEndpointHandlers(){ return endpointHandlers; @@ -114,32 +107,29 @@ void OverseerHandler::setEndpointWidgets(std::vector ews){ } void OverseerHandler::updateMuteCallback(uint64_t idx, bool muted){ - epwMuteFunc f = &EndpointWidget::updateMute; - pinvoke_mem_fn(endpointWidgets.at(idx),f)(muted); - //std::invoke(f, endpointWidgets.at(idx), muted); + updateFrontMuteCallback(idx, muted); } void OverseerHandler::updateMainVolumeCallback(uint64_t idx, float newVal){ - //int translatedNewVal = newVal * 100; log_debugcpp("mainvolcallback float: " << newVal); - epwMainVolumeFunc f = &EndpointWidget::updateMainVolume; - pinvoke_mem_fn(endpointWidgets.at(idx),f)(newVal); - //std::invoke(f, endpointWidgets.at(idx), newVal); + updateFrontVolumeCallback(idx, AudioChannel::CHANNEL_MAIN, newVal); +} + +void OverseerHandler::setFrontVolumeCallback(std::function f) { + this->updateFrontVolumeCallback = f; +} + +void OverseerHandler::setFrontMuteCallback(std::function f) { + this->updateFrontMuteCallback = f; } void OverseerHandler::updateChannelVolumeCallback(uint64_t idx, uint32_t channel, float newVal){ - //int translatedNewVal = newVal * 100; + log_debugcpp("channel: " << channel << " volcallback float: " << newVal); - log_debugcpp("chanel: " << channel << " volcallback float: " << newVal); - epwChannelVolumeFunc f = &EndpointWidget::updateChannelVolume; - //std::invoke(f, endpointWidgets.at(idx), channel, newVal); - pinvoke_mem_fn(endpointWidgets.at(idx),f)(channel, newVal); - //TODO: Soy retrasado - //endpointWidgets.at(idx)->updateChannelVolume(channel, newVal); -} - -void OverseerHandler::toggleFrontEvents(uint64_t idx, bool active) { - epwToggleFrontFunc f = &EndpointWidget::toggleFrontEvents; - pinvoke_mem_fn(endpointWidgets.at(idx),f)(active); - //std::invoke(f, , active); + // convert channel to bitmask + int i = 0; + while (i++); + uint32_t mask = (1 << i); + + updateFrontVolumeCallback(idx, mask, newVal); } diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index 5714a79..bb47131 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -9,11 +9,16 @@ /* #endif */ class EndpointWidget; - class Endpoint; class EndpointCallback; class Overseer; +enum AudioChannel { + CHANNEL_LEFT = (1 << 0), + CHANNEL_RIGHT = (1 << 1), + CHANNEL_MAIN = ~0, +}; + struct NGuid { uint32_t data1; uint16_t data2; @@ -66,14 +71,15 @@ public: void reloadEndpointHandlers(); NGuid* getGuid(); void updateMuteCallback(uint64_t idx, bool muted); + void setFrontMuteCallback(std::function f); + void setFrontVolumeCallback(std::function f); void updateMainVolumeCallback(uint64_t idx, float newVal); void updateChannelVolumeCallback(uint64_t idx, uint32_t channel, float newVal); - void toggleFrontEvents(uint64_t idx, bool active); - //void parseExternalEndpointCallback(EndpointCallback *epc, PAUDIO_VOLUME_NOTIFICATION_DATA pNotify); - //static Overseer* getOverseer(); private: static Overseer os; std::vector endpointHandlers; - std::vector endpointWidgets; + std::vector endpointWidgets; + std::function updateFrontVolumeCallback = {}; + std::function updateFrontMuteCallback = {}; }; diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index a5d0b8a..24287e9 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -74,11 +74,11 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget( void EndpointWidget::updateMute(bool muted){ 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. - //this->muteButton->blockSignals(true); + this->muteButton->blockSignals(true); //this->eph->setMute(osh->getGuid(), muted); - this->muteButton->setChecked(eph->getMute() ? true : false); + this->muteButton->setChecked(muted); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); - //this->muteButton->blockSignals(false); + this->muteButton->blockSignals(false); } void EndpointWidget::updateMute(int checked){ @@ -107,14 +107,23 @@ void EndpointWidget::updateMainVolume(float newValue){ } void EndpointWidget::updateChannelVolume(uint32_t channel, float newValue){ - int newVal = newValue * 100; - log_debugcpp("chanel: " << channel << " volcallback int: " << newVal); - //TODO: Above - //this->channelSliders.at(channel)->blockSignals(true); - if(this->channelSliders.at(channel)->value() != newVal) { - this->channelSliders.at(channel)->setValue(newVal); - this->channelLabels.at(channel)->setText(QString::number((int)(newValue * 100))); + this->blockSignals(true); + if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) { + updateMainVolume(newValue); + } else { + int newVal = newValue * 100; + log_debugcpp("chanel: " << channel << " volcallback int: " << newVal); + //TODO: Above + //this->channelSliders.at(channel)->blockSignals(true); + + for (size_t i = 0; i < sizeof(uint32_t) * 8; ++i) { + if ((channel << i & 1) && this->channelSliders.at(channel)->value() != newVal) { + this->channelSliders.at(channel)->setValue(newVal); + this->channelLabels.at(channel)->setText(QString::number((int)(newValue * 100))); + } + } } + this->blockSignals(false); //this->channelSliders.at(channel)->blockSignals(false); } @@ -160,8 +169,18 @@ void MainWindow::reloadEndpointWidgets() { } osh->setEndpointWidgets(ews); 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]->updateChannelVolume(channel, value); + }); + osh->setFrontMuteCallback([this](uint64_t device, bool muted) { + if (device < ews.size()) + ews[device]->updateMute(muted); + }); } + //#include "qtclosemwh.h" /* diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index dc1a82a..788e279 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -103,6 +103,7 @@ class MainWindow : public QMainWindow { public: MainWindow(QWidget *parent = nullptr); void reloadEndpointWidgets(); + //TODO: destroy/empty existing EndpointWidgets //void setEndpointHandlers(std::vector *ephs); From c4b1c4b7966f0e0a8ef2d9bd9573211575b41fa3 Mon Sep 17 00:00:00 2001 From: Phireh Date: Mon, 14 Aug 2023 22:18:24 +0200 Subject: [PATCH 2/3] Correctly update channel sliders --- src/cont/contclasses.cpp | 3 ++- src/qt/qtclasses.cpp | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index 36b913d..3727fd4 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -128,7 +128,8 @@ void OverseerHandler::updateChannelVolumeCallback(uint64_t idx, uint32_t channel // convert channel to bitmask int i = 0; - while (i++); + while (i < channel) + i++; uint32_t mask = (1 << i); updateFrontVolumeCallback(idx, mask, newVal); diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 24287e9..bebddf2 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -108,23 +108,24 @@ void EndpointWidget::updateMainVolume(float newValue){ void EndpointWidget::updateChannelVolume(uint32_t channel, float newValue){ this->blockSignals(true); - if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) { + if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) updateMainVolume(newValue); - } else { - int newVal = newValue * 100; - log_debugcpp("chanel: " << channel << " volcallback int: " << newVal); - //TODO: Above - //this->channelSliders.at(channel)->blockSignals(true); + + int newVal = newValue * 100; + log_debugcpp("chanel: " << channel << " volcallback int: " << newVal); - for (size_t i = 0; i < sizeof(uint32_t) * 8; ++i) { - if ((channel << i & 1) && this->channelSliders.at(channel)->value() != newVal) { - this->channelSliders.at(channel)->setValue(newVal); - this->channelLabels.at(channel)->setText(QString::number((int)(newValue * 100))); - } + for (size_t i = 0; i < sizeof(uint32_t) * 8 && i < channelSliders.size(); ++i) { + if (((channel >> i) & 1) && this->channelSliders.at(i)->value() != newVal) { + this->channelSliders.at(i)->blockSignals(true); + + this->channelSliders.at(i)->setValue(newVal); + this->channelLabels.at(i)->setText(QString::number((int)(newValue * 100))); + + this->channelSliders.at(i)->blockSignals(false); } } + this->blockSignals(false); - //this->channelSliders.at(channel)->blockSignals(false); } void EndpointWidget::toggleFrontEvents(bool active){ From 831dceb89ac85bcc2abb70c561f57ecc2bd3d45b Mon Sep 17 00:00:00 2001 From: Hane Date: Tue, 15 Aug 2023 17:03:23 +0200 Subject: [PATCH 3/3] code cleanup; channels callback coalesced again --- src/back/backlasses.cpp | 6 +++--- src/cont/contclasses.cpp | 39 +++++++++++++++++++------------------- src/cont/contclasses.h | 11 +++++------ src/debug.h | 8 +++++++- src/qt/qtclasses.cpp | 41 +++++++++++++++++++++------------------- src/qt/qtclasses.h | 8 +------- 6 files changed, 58 insertions(+), 55 deletions(-) diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 32c7940..ef827dd 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -56,15 +56,15 @@ HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) { 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->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); if(multiChannel) 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 - 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; diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index 3727fd4..679f921 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -6,8 +6,8 @@ Overseer OverseerHandler::os; EndpointHandler::EndpointHandler(uint64_t idx) { - std::vector endpoints = osh->getPlaybackEndpoints(); - this->ep = endpoints.at(idx); + //std::vector endpoints = osh->getPlaybackEndpoints().at(idx); + this->ep = osh->getPlaybackEndpoints().at(idx); epc = new EndpointCallback(ep); //epName = ep->getName(); ep->setCallback(epc); @@ -25,7 +25,6 @@ uint64_t EndpointHandler::getIndex(){ return idx; } - /* * -1 for master volume */ @@ -101,20 +100,6 @@ void OverseerHandler::setEndpointHandlers(std::vector ephs){ this->endpointHandlers = ephs; } - -void OverseerHandler::setEndpointWidgets(std::vector 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 f) { this->updateFrontVolumeCallback = f; } @@ -123,11 +108,27 @@ void OverseerHandler::setFrontMuteCallback(std::function 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); // convert channel to bitmask - int i = 0; + uint32_t i = 0; while (i < channel) i++; uint32_t mask = (1 << i); diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index bb47131..320564f 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -64,7 +64,6 @@ class OverseerHandler { public: //OverseerHandler(); void setEndpointHandlers(std::vector ephs); - void setEndpointWidgets(std::vector ews); std::vector getEndpointHandlers(); std::vector getPlaybackEndpoints(); uint64_t getPlaybackEndpointsCount(); @@ -73,13 +72,13 @@ public: void updateMuteCallback(uint64_t idx, bool muted); void setFrontMuteCallback(std::function f); void setFrontVolumeCallback(std::function f); - void updateMainVolumeCallback(uint64_t idx, float newVal); - void updateChannelVolumeCallback(uint64_t idx, uint32_t channel, float newVal); + //void updateMainVolumeCallback(uint64_t idx, float newVal); + void updateVolumeCallback(uint64_t idx, uint32_t channel, float newVal); private: static Overseer os; std::vector endpointHandlers; - std::vector endpointWidgets; - std::function updateFrontVolumeCallback = {}; - std::function updateFrontMuteCallback = {}; + std::function updateFrontVolumeCallback; + std::function updateFrontMuteCallback; + }; diff --git a/src/debug.h b/src/debug.h index 78cb19c..e80893f 100644 --- a/src/debug.h +++ b/src/debug.h @@ -16,8 +16,14 @@ std::bitset varToBitset(T info) { #else #define log_debugcpp(str) -#define print_as_binary(len, info) +#define print_as_binary(len, type, info) #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); */ + diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index bebddf2..9a446ee 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -73,12 +73,14 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget( void EndpointWidget::updateMute(bool muted){ 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. - this->muteButton->blockSignals(true); + //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->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); } void EndpointWidget::updateMute(int checked){ @@ -96,18 +98,20 @@ void EndpointWidget::updateMainVolume(int newValue){ } void EndpointWidget::updateMainVolume(float newValue){ + //this->blockSignals(true); int newVal = newValue * 100; log_debugcpp("mainvolcallback int: " << newVal); //this->mainSlider->blockSignals(true); - //TODO: Above + if(this->mainSlider->value() != newVal) { this->mainSlider->setValue(newVal); } //this->mainSlider->blockSignals(false); + //this->blockSignals(false); } void EndpointWidget::updateChannelVolume(uint32_t channel, float newValue){ - this->blockSignals(true); + //this->blockSignals(true); if (channel == (uint32_t)AudioChannel::CHANNEL_MAIN) 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) { 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->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); - this->mainSlider->blockSignals(active); - for(uint32_t i = 0; i < this->channelSliders.size(); i++){ - this->channelSliders.at(i)->blockSignals(active); - } -} +/* + * 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){ @@ -168,7 +174,7 @@ void MainWindow::reloadEndpointWidgets() { ews.push_back(epw); layout->addWidget(epw, i, 0); } - osh->setEndpointWidgets(ews); + layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), i, 0); osh->setFrontVolumeCallback([this](uint64_t device, uint32_t channel, float value) { @@ -181,9 +187,6 @@ void MainWindow::reloadEndpointWidgets() { }); } - -//#include "qtclosemwh.h" - /* * void MainWindow::setPlotButton() { * button = new QPushButton("push"), diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 788e279..4482d23 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -71,7 +71,7 @@ public: void updateMainVolume(float newValue); void updateChannelVolume(uint32_t channel, float newValue); void updateMute(bool muted); - void toggleFrontEvents(bool active); + //void toggleFrontEvents(bool active); //void populateEndpointWidget(EndpointHandler *eph); //void setEndpointHandlers(std::vector *ephs); @@ -84,18 +84,12 @@ private: uint64_t idx; //std::vector *ephs; //std::vector *sliders; - //signals: //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 { Q_OBJECT //QWidget *centralWidget;