rounding factor and sndvol trick note: ready to move on

This commit is contained in:
Hane 2023-08-17 19:50:01 +02:00
commit 8e9de6a771

View file

@ -51,8 +51,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
mainMuteLayout->addWidget(muteButton, 0, 1);
layout->addWidget(mainSlider, 0, 1);
//TODO:0 = mute and muted, change volume = unmuted are client side tricks = 2 callbacks, one for volume, one for mute state. Implement as an user selectable option?
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));
@ -83,24 +82,26 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
});
}
//Polling time
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));
//if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return;
const float roundingFactor = 0.005;
mainSlider->blockSignals(true);
muteButton->blockSignals(true);
mainSlider->setValue((int)((osh->callbackInfo[idx]->mainVolume + roundingFactor) * 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)->setValue((int)((osh->callbackInfo[idx]->channelVolumes[i] + roundingFactor) * 100));
this->channelLabels.at(i)->setText(QString::number((int)((osh->callbackInfo[idx]->channelVolumes[i] + roundingFactor) * 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);
mainSlider->blockSignals(false);
muteButton->blockSignals(false);
});
timer->start(10);
@ -130,6 +131,7 @@ void EndpointWidget::updateMute(int checked){
}
void EndpointWidget::updateMainVolume(int newValue){
//QObject* obj = sender();
this->eph->setVolume(osh->getGuid(), AudioChannel::CHANNEL_MAIN, newValue);
}
@ -203,6 +205,7 @@ void MainWindow::reloadEndpointWidgets() {
memcpy(osh->callbackInfo[i]->caller, osh->getGuid(),sizeof(NGuid) );
EndpointWidget *epw = new EndpointWidget(i, osh->getEndpointHandlers().at(i), widget);
//TODO: ALWAYS PUSH BACK??? PSZ CHANGE DIS WHEN IMPLEMENTING DYN ENDPOINT DET
ews.push_back(epw);
layout->addWidget(epw, i, 0);