From b15e5d6df73aa5647519b52ce9df4a32ecf46a51 Mon Sep 17 00:00:00 2001 From: Hane Date: Thu, 17 Aug 2023 12:40:32 +0200 Subject: [PATCH] fixed back->front channel bar desync --- src/back/backlasses.cpp | 6 +++--- src/global.h | 2 +- src/qt/qtclasses.cpp | 25 +++++++++++++++++-------- src/qt/qtclasses.h | 1 + 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index cdcb73f..546c863 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -80,10 +80,10 @@ std::wstring Endpoint::getName(){ float Endpoint::getVolume(int channel){ float volume; - if (channel == ENDPOINT_MASTER_VOLUME) { - if(FAILED(endpointVolume->GetMasterVolumeLevelScalar(&volume))) { log_debugcpp("si");} + if (channel == AudioChannel::CHANNEL_MAIN) { + if(FAILED(endpointVolume->GetMasterVolumeLevelScalar(&volume))) { /* log_debugcpp("si") */;} } else { - if(FAILED(endpointVolume->GetChannelVolumeLevelScalar(channel, &volume))) { log_debugcpp("si");} + if(FAILED(endpointVolume->GetChannelVolumeLevelScalar(channel, &volume))) { /* log_debugcpp("si"); */} } return volume; } diff --git a/src/global.h b/src/global.h index c4cf2af..b17f1bd 100644 --- a/src/global.h +++ b/src/global.h @@ -7,7 +7,7 @@ #include "debug.h" -#define ENDPOINT_MASTER_VOLUME -1 +//#define ENDPOINT_MASTER_VOLUME -1 /* #define ENDPOINT_LEFT_CHANNEL_VOLUME 0 */ /* #define ENDPOINT_RIGHT_CHANNEL_VOLUME 1 */ diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 6d58322..583d767 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -39,9 +39,9 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare 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; + float volume = eph->getVolume(AudioChannel::CHANNEL_MAIN) * 100; //TODO: APARTE - osh->callbackInfo[idx]->mainVolume = eph->getVolume(ENDPOINT_MASTER_VOLUME); + osh->callbackInfo[idx]->mainVolume = eph->getVolume(AudioChannel::CHANNEL_MAIN); mainSlider->setValue((int)volume); log_debugcpp("ENDPOINT SET WITH VOLUME " << volume); @@ -75,21 +75,30 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare this->channelLabels.push_back(tmpLb); 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)); }); + //TODO: check if there's a need to prevent deadlocks; probably this will eventually turn into its own func + //this causes channel bar desync when back -> front. blocksignals below fix it. huh. + 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); + timer = new QTimer(this); connect(timer, &QTimer::timeout, [this, idx](){ if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; + mainSlider->blockSignals(true); + muteButton->blockSignals(true); 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))); + this->channelSliders.at(i)->blockSignals(true); + 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))); + this->channelSliders.at(i)->blockSignals(false); } + //memcpy(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)); + *osh->callbackInfo[idx]->caller = *osh->getGuid(); + mainSlider->blockSignals(false); + muteButton->blockSignals(false); }); timer->start(10); @@ -117,7 +126,7 @@ void EndpointWidget::updateMute(int checked){ } void EndpointWidget::updateMainVolume(int newValue){ - this->eph->setVolume(osh->getGuid(), ENDPOINT_MASTER_VOLUME, newValue); + this->eph->setVolume(osh->getGuid(), AudioChannel::CHANNEL_MAIN, newValue); } void EndpointWidget::updateVolume(uint32_t channel, float newValue){ diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 5dc9f1d..53434b5 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -81,6 +81,7 @@ public slots: void updateMute(int checked); private: + QTimer* timer = nullptr; uint64_t idx; //std::vector *ephs; //std::vector *sliders;