channels added to front programmatically

This commit is contained in:
Hane 2023-08-13 17:43:09 +02:00
commit cb81b49367
6 changed files with 78 additions and 35 deletions

View file

@ -58,9 +58,11 @@ HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
* PAUDIO_VOLUME_NOTIFICATION_DATA->Release(); * PAUDIO_VOLUME_NOTIFICATION_DATA->Release();
* } */ * } */
Endpoint::Endpoint(IMMDevice* ep){ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
this->endpoint = ep; this->endpoint = ep;
this->idx = idx;
if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { log_debugcpp("si"); }; if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolume))) { log_debugcpp("si"); };
if (FAILED(endpointVolume->GetChannelCount(&channelCount))) log_debugcpp("get channel count fail");
//Obtaining friendly name: IPropertyStore creates PROPVARIANT per field //Obtaining friendly name: IPropertyStore creates PROPVARIANT per field
// hr = endpointPtr->GetId(&endpointID); // hr = endpointPtr->GetId(&endpointID);
endpoint->OpenPropertyStore(STGM_READ, &properties); endpoint->OpenPropertyStore(STGM_READ, &properties);
@ -92,6 +94,10 @@ float Endpoint::getVolume(int channel){
return volume; return volume;
} }
uint32_t Endpoint::getChannelCount(){
return (uint32_t)channelCount;
}
bool Endpoint::getMute(){ bool Endpoint::getMute(){
BOOL mut; BOOL mut;
@ -122,6 +128,7 @@ void Endpoint::setVolume(NGuid* guid, int channel, float volume) {
if (channel == ENDPOINT_MASTER_VOLUME) { if (channel == ENDPOINT_MASTER_VOLUME) {
if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, &tempMsGuid))) { log_debugcpp("si"); }; if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, &tempMsGuid))) { log_debugcpp("si"); };
} else { } else {
log_debugcpp("channel being updated: " << channel);
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) { log_debugcpp("si"); }; if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) { log_debugcpp("si"); };
} }
} }
@ -165,9 +172,7 @@ void Overseer::initCOMLibrary() {
GUID tempGuid; GUID tempGuid;
if(FAILED(CoCreateGuid(&tempGuid))) { log_debugcpp("Failed to obtain GUID: " ); }; if(FAILED(CoCreateGuid(&tempGuid))) { log_debugcpp("Failed to obtain GUID: " ); };
this->guid = GUIDToNGuid(&tempGuid); this->guid = GUIDToNGuid(&tempGuid);
//TODO: Release lpguid? //TODO: Release lpguid?
//TODO: Uninitialize COM //TODO: Uninitialize COM
} }
@ -188,8 +193,8 @@ void Overseer::reloadEndpoints() {
for (unsigned int i = 0; i < numPlaybackEndpoints; i++){ for (unsigned int i = 0; i < numPlaybackEndpoints; i++){
IMMDevice *temp; IMMDevice *temp;
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); }; if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
Endpoint *endpoint = new Endpoint(temp); Endpoint *endpoint = new Endpoint(temp, i);
endpoint->setIndex(i); //endpoint->setIndex(i);
this->playbackDevices.push_back(endpoint); this->playbackDevices.push_back(endpoint);
//TODO: le porblemx std::cout << "ola" << std::endl; //TODO: le porblemx std::cout << "ola" << std::endl;
} }

View file

@ -28,12 +28,11 @@ class EndpointCallback;
class Endpoint { class Endpoint {
public: public:
Endpoint(IMMDevice* endpoint); Endpoint(IMMDevice* endpoint, uint64_t idx);
uint64_t getIndex(); uint64_t getIndex();
void setIndex(uint64_t idx); void setIndex(uint64_t idx);
void setVolume(NGuid* guid, int channel, float volume); void setVolume(NGuid* guid, int channel, float volume);
/* float getLeftChannelVolume(); */ uint32_t getChannelCount();
/* float getRightChannelVolume(); */
float getVolume(int channel); float getVolume(int channel);
void setMute(NGuid* guid, bool muted); void setMute(NGuid* guid, bool muted);
bool getMute(); bool getMute();
@ -43,6 +42,7 @@ class Endpoint {
~Endpoint(); ~Endpoint();
private: private:
uint32_t channelCount;
IMMDevice* endpoint; IMMDevice* endpoint;
IAudioEndpointVolume *endpointVolume ; IAudioEndpointVolume *endpointVolume ;
IPropertyStore *properties; IPropertyStore *properties;

View file

@ -14,6 +14,10 @@ EndpointHandler::EndpointHandler(uint64_t idx) {
ep->setCallback(epc); ep->setCallback(epc);
} }
uint32_t EndpointHandler::getChannelCount(){
return ep->getChannelCount();
}
void EndpointHandler::setIndex(uint64_t idx){ void EndpointHandler::setIndex(uint64_t idx){
this->idx = idx; this->idx = idx;
} }

View file

@ -28,6 +28,8 @@ public:
EndpointCallback *epc = nullptr; EndpointCallback *epc = nullptr;
//std::wstring epName; //std::wstring epName;
uint32_t getChannelCount();
void setIndex(uint64_t idx); void setIndex(uint64_t idx);
uint64_t getIndex(); uint64_t getIndex();
void setVolume(int channel, float volume); void setVolume(int channel, float volume);

View file

@ -25,11 +25,11 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
muteButton = new QCheckBox(); muteButton = new QCheckBox();
mainLabel = new QLabel(QString::fromStdWString(eph->getName())); mainLabel = new QLabel(QString::fromStdWString(eph->getName()));
leftChannelLabel = new QLabel("88"); //leftChannelLabel = new QLabel("88");
rightChannelLabel = new QLabel("77"); //rightChannelLabel = new QLabel("77");
mainSlider = new QSlider(Qt::Horizontal); mainSlider = new QSlider(Qt::Horizontal);
leftChannelSlider = new QSlider(Qt::Horizontal); //leftChannelSlider = new QSlider(Qt::Horizontal);
rightChannelSlider = new QSlider(Qt::Horizontal); //rightChannelSlider = new QSlider(Qt::Horizontal);
//muteButton->setStyleSheet("background-color: #A3C1DA; color: red"); //muteButton->setStyleSheet("background-color: #A3C1DA; color: red");
mainSlider->setFocusPolicy(Qt::StrongFocus); mainSlider->setFocusPolicy(Qt::StrongFocus);
@ -37,23 +37,29 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
mainSlider->setTickInterval(5); mainSlider->setTickInterval(5);
mainSlider->setSingleStep(1); mainSlider->setSingleStep(1);
mainSlider->setRange(0,100); mainSlider->setRange(0,100);
leftChannelSlider->setTickInterval(5);
leftChannelSlider->setSingleStep(1); /*
leftChannelSlider->setRange(0,100); * leftChannelSlider->setTickInterval(5);
rightChannelSlider->setTickInterval(5); * leftChannelSlider->setSingleStep(1);
rightChannelSlider->setSingleStep(1); * leftChannelSlider->setRange(0,100);
rightChannelSlider->setRange(0,100); * rightChannelSlider->setTickInterval(5);
* rightChannelSlider->setSingleStep(1);
* rightChannelSlider->setRange(0,100);
*/
muteButton->setCheckState((eph->getMute() == false ? Qt::Unchecked : Qt::Checked)); muteButton->setCheckState((eph->getMute() == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE); muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
float volume = eph->getVolume(ENDPOINT_MASTER_VOLUME) * 100; float volume = eph->getVolume(ENDPOINT_MASTER_VOLUME) * 100;
mainSlider->setValue((int)volume); mainSlider->setValue((int)volume);
volume = eph->getVolume(ENDPOINT_LEFT_CHANNEL_VOLUME) * 100; 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; * leftChannelSlider->setValue((int)volume);
rightChannelSlider->setValue((int)volume); * leftChannelLabel->setText(QString::number(volume));
rightChannelLabel->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); log_debugcpp("ENDPOINT SET WITH VOLUME " << volume);
mainMuteLayout = new QGridLayout(); mainMuteLayout = new QGridLayout();
@ -61,20 +67,42 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
mainMuteLayout->addWidget(mainLabel, 0, 0); mainMuteLayout->addWidget(mainLabel, 0, 0);
mainMuteLayout->addWidget(muteButton, 0, 1); mainMuteLayout->addWidget(muteButton, 0, 1);
layout->addWidget(mainSlider, 0, 1); layout->addWidget(mainSlider, 0, 1);
layout->addWidget(leftChannelSlider, 1, 0);
layout->addWidget(leftChannelLabel, 2, 0); /*
layout->addWidget(rightChannelSlider, 1, 1); * layout->addWidget(leftChannelSlider, 1, 0);
layout->addWidget(rightChannelLabel, 2, 1); * layout->addWidget(leftChannelLabel, 2, 0);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 0); * layout->addWidget(rightChannelSlider, 1, 1);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 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<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));
/* /*
* connect(muteButton, &QPushButton::clicked, [this](bool clicked){ log_debugcpp("cliqui" << clicked << "cloqui"); this->eph->setMute(osh->getGuid()); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); }); * 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("");
tmp->setTickInterval(5);
tmp->setSingleStep(1);
tmp->setRange(0,100);
volume = eph->getVolume(i) * 100;
tmp->setValue((int) volume);
tmpLb->setText(QString::number(volume));
this->channelSliders.push_back(tmp);
this->channelLabels.push_back(tmpLb);
layout->addWidget(tmp, 1, i);
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"); log_debugcpp("ENDPOINT_WIDGETED");
} }

View file

@ -64,8 +64,12 @@ public:
QCheckBox *muteButton = nullptr; QCheckBox *muteButton = nullptr;
QLabel *mainLabel = nullptr, *leftChannelLabel = nullptr, *rightChannelLabel = nullptr; QLabel *mainLabel = nullptr, *leftChannelLabel = nullptr, *rightChannelLabel = nullptr;
QSlider *mainSlider = nullptr; QSlider *mainSlider = nullptr;
QSlider *leftChannelSlider = nullptr; std::vector<QSlider*> channelSliders;
QSlider *rightChannelSlider = nullptr; std::vector<QLabel*> channelLabels;
/*
* QSlider *leftChannelSlider = nullptr;
* QSlider *rightChannelSlider = nullptr;
*/
QGridLayout *layout = nullptr; QGridLayout *layout = nullptr;
QGridLayout *mainMuteLayout = nullptr; QGridLayout *mainMuteLayout = nullptr;
void updateMainVolume(float newValue); void updateMainVolume(float newValue);