wip channel callback

This commit is contained in:
Hane 2023-08-13 18:29:24 +02:00
commit 4d9bae4c87
6 changed files with 28 additions and 47 deletions

View file

@ -25,41 +25,19 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
muteButton = new QCheckBox();
mainLabel = new QLabel(QString::fromStdWString(eph->getName()));
//leftChannelLabel = new QLabel("88");
//rightChannelLabel = new QLabel("77");
mainSlider = new QSlider(Qt::Horizontal);
//leftChannelSlider = new QSlider(Qt::Horizontal);
//rightChannelSlider = new QSlider(Qt::Horizontal);
//muteButton->setStyleSheet("background-color: #A3C1DA; color: red");
mainSlider->setFocusPolicy(Qt::StrongFocus);
mainSlider->setTickPosition(QSlider::TicksBothSides);
mainSlider->setTickInterval(5);
mainSlider->setSingleStep(1);
mainSlider->setRange(0,100);
/*
* leftChannelSlider->setTickInterval(5);
* leftChannelSlider->setSingleStep(1);
* leftChannelSlider->setRange(0,100);
* rightChannelSlider->setTickInterval(5);
* rightChannelSlider->setSingleStep(1);
* rightChannelSlider->setRange(0,100);
*/
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;
mainSlider->setValue((int)volume);
volume = eph->getVolume(ENDPOINT_LEFT_CHANNEL_VOLUME) * 100;
/*
* leftChannelSlider->setValue((int)volume);
* leftChannelLabel->setText(QString::number(volume));
* volume = eph->getVolume(ENDPOINT_RIGHT_CHANNEL_VOLUME) * 100;
* rightChannelSlider->setValue((int)volume);
* rightChannelLabel->setText(QString::number(volume));
*/
log_debugcpp("ENDPOINT SET WITH VOLUME " << volume);
mainMuteLayout = new QGridLayout();
@ -68,24 +46,9 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
mainMuteLayout->addWidget(muteButton, 0, 1);
layout->addWidget(mainSlider, 0, 1);
/*
* layout->addWidget(leftChannelSlider, 1, 0);
* layout->addWidget(leftChannelLabel, 2, 0);
* layout->addWidget(rightChannelSlider, 1, 1);
* layout->addWidget(rightChannelLabel, 2, 1);
*/
/*
* layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 0);
* layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 1);
*/
connect<void(QSlider::*)(int), void(EndpointWidget::*)(int)>(mainSlider, &QSlider::valueChanged, this,&EndpointWidget::updateMainVolume);
/*
* connect(leftChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setVolume(osh->getGuid(), ENDPOINT_LEFT_CHANNEL_VOLUME, newValue); this->leftChannelLabel->setText(QString::number(newValue)); });
* connect(rightChannelSlider, &QSlider::valueChanged, [this](int newValue){ this->eph->setVolume(osh->getGuid(), ENDPOINT_RIGHT_CHANNEL_VOLUME, newValue); this->rightChannelLabel->setText(QString::number(newValue)); });
*/
connect<void(QCheckBox::*)(int), void(EndpointWidget::*)(int)>(muteButton, &QCheckBox::stateChanged, this, (&EndpointWidget::updateMute));
for(uint32_t i = 0; i < eph->getChannelCount(); i++){
QSlider* tmp = new QSlider(Qt::Horizontal);
QLabel* tmpLb = new QLabel("");
@ -101,6 +64,7 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
layout->addWidget(tmpLb, 2, i);
connect(tmp, &QSlider::valueChanged, [this, i](int newValue){ this->eph->setVolume(osh->getGuid(), i, newValue); this->channelLabels.at(i)->setText(QString::number(newValue)); });
}
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 0);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 1);
log_debugcpp("ENDPOINT_WIDGETED");
@ -127,7 +91,6 @@ void EndpointWidget::updateMainVolume(int newValue){
this->eph->setVolume(osh->getGuid(), ENDPOINT_MASTER_VOLUME, newValue);
}
void EndpointWidget::updateMainVolume(float newValue){
int newVal = newValue * 100;
if(this->mainSlider->value() != newVal) {
@ -135,6 +98,13 @@ void EndpointWidget::updateMainVolume(float newValue){
}
}
void EndpointWidget::updateChannelVolume(uint32_t channel, float newValue){
int newVal = newValue * 100;
if(this->channelSliders.at(channel)->value() != newVal) {
this->channelSliders.at(channel)->setValue(newVal);
this->channelLabels.at(channel)->setText(QString::number((int)(newValue * 100)));
}
}
void EndpointWidget::setIndex(uint64_t idx){
this->idx = idx;