fixed back->front channel bar desync

This commit is contained in:
Hane 2023-08-17 12:40:32 +02:00
commit b15e5d6df7
4 changed files with 22 additions and 12 deletions

View file

@ -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;
}

View file

@ -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 */

View file

@ -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);
@ -76,20 +76,29 @@ 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
//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)->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){

View file

@ -81,6 +81,7 @@ public slots:
void updateMute(int checked);
private:
QTimer* timer = nullptr;
uint64_t idx;
//std::vector<EndpointHandler*> *ephs;
//std::vector<QSlider> *sliders;