channels added to front programmatically
This commit is contained in:
parent
833b417441
commit
312de5ce2c
6 changed files with 78 additions and 35 deletions
|
|
@ -58,9 +58,11 @@ HRESULT EndpointCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) {
|
|||
* PAUDIO_VOLUME_NOTIFICATION_DATA->Release();
|
||||
* } */
|
||||
|
||||
Endpoint::Endpoint(IMMDevice* ep){
|
||||
Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){
|
||||
this->endpoint = ep;
|
||||
this->idx = idx;
|
||||
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
|
||||
// hr = endpointPtr->GetId(&endpointID);
|
||||
endpoint->OpenPropertyStore(STGM_READ, &properties);
|
||||
|
|
@ -92,6 +94,10 @@ float Endpoint::getVolume(int channel){
|
|||
return volume;
|
||||
}
|
||||
|
||||
uint32_t Endpoint::getChannelCount(){
|
||||
return (uint32_t)channelCount;
|
||||
}
|
||||
|
||||
|
||||
bool Endpoint::getMute(){
|
||||
BOOL mut;
|
||||
|
|
@ -122,6 +128,7 @@ void Endpoint::setVolume(NGuid* guid, int channel, float volume) {
|
|||
if (channel == ENDPOINT_MASTER_VOLUME) {
|
||||
if(FAILED(endpointVolume->SetMasterVolumeLevelScalar(volume, &tempMsGuid))) { log_debugcpp("si"); };
|
||||
} else {
|
||||
log_debugcpp("channel being updated: " << channel);
|
||||
if(FAILED(endpointVolume->SetChannelVolumeLevelScalar(channel, volume, &tempMsGuid))) { log_debugcpp("si"); };
|
||||
}
|
||||
}
|
||||
|
|
@ -165,9 +172,7 @@ void Overseer::initCOMLibrary() {
|
|||
|
||||
GUID tempGuid;
|
||||
if(FAILED(CoCreateGuid(&tempGuid))) { log_debugcpp("Failed to obtain GUID: " ); };
|
||||
|
||||
this->guid = GUIDToNGuid(&tempGuid);
|
||||
|
||||
//TODO: Release lpguid?
|
||||
//TODO: Uninitialize COM
|
||||
}
|
||||
|
|
@ -188,8 +193,8 @@ void Overseer::reloadEndpoints() {
|
|||
for (unsigned int i = 0; i < numPlaybackEndpoints; i++){
|
||||
IMMDevice *temp;
|
||||
if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); };
|
||||
Endpoint *endpoint = new Endpoint(temp);
|
||||
endpoint->setIndex(i);
|
||||
Endpoint *endpoint = new Endpoint(temp, i);
|
||||
//endpoint->setIndex(i);
|
||||
this->playbackDevices.push_back(endpoint);
|
||||
//TODO: le porblemx std::cout << "ola" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,11 @@ class EndpointCallback;
|
|||
class Endpoint {
|
||||
|
||||
public:
|
||||
Endpoint(IMMDevice* endpoint);
|
||||
Endpoint(IMMDevice* endpoint, uint64_t idx);
|
||||
uint64_t getIndex();
|
||||
void setIndex(uint64_t idx);
|
||||
void setVolume(NGuid* guid, int channel, float volume);
|
||||
/* float getLeftChannelVolume(); */
|
||||
/* float getRightChannelVolume(); */
|
||||
uint32_t getChannelCount();
|
||||
float getVolume(int channel);
|
||||
void setMute(NGuid* guid, bool muted);
|
||||
bool getMute();
|
||||
|
|
@ -43,6 +42,7 @@ class Endpoint {
|
|||
~Endpoint();
|
||||
|
||||
private:
|
||||
uint32_t channelCount;
|
||||
IMMDevice* endpoint;
|
||||
IAudioEndpointVolume *endpointVolume ;
|
||||
IPropertyStore *properties;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ EndpointHandler::EndpointHandler(uint64_t idx) {
|
|||
ep->setCallback(epc);
|
||||
}
|
||||
|
||||
uint32_t EndpointHandler::getChannelCount(){
|
||||
return ep->getChannelCount();
|
||||
}
|
||||
|
||||
void EndpointHandler::setIndex(uint64_t idx){
|
||||
this->idx = idx;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ public:
|
|||
EndpointCallback *epc = nullptr;
|
||||
//std::wstring epName;
|
||||
|
||||
uint32_t getChannelCount();
|
||||
|
||||
void setIndex(uint64_t idx);
|
||||
uint64_t getIndex();
|
||||
void setVolume(int channel, float volume);
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ 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");
|
||||
//leftChannelLabel = new QLabel("88");
|
||||
//rightChannelLabel = new QLabel("77");
|
||||
mainSlider = new QSlider(Qt::Horizontal);
|
||||
leftChannelSlider = new QSlider(Qt::Horizontal);
|
||||
rightChannelSlider = 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);
|
||||
|
|
@ -37,23 +37,29 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
|
|||
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);
|
||||
|
||||
/*
|
||||
* 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));
|
||||
|
||||
/*
|
||||
* 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();
|
||||
|
|
@ -61,20 +67,42 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(
|
|||
mainMuteLayout->addWidget(mainLabel, 0, 0);
|
||||
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);
|
||||
|
||||
/*
|
||||
* 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));
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,8 +64,12 @@ public:
|
|||
QCheckBox *muteButton = nullptr;
|
||||
QLabel *mainLabel = nullptr, *leftChannelLabel = nullptr, *rightChannelLabel = nullptr;
|
||||
QSlider *mainSlider = nullptr;
|
||||
QSlider *leftChannelSlider = nullptr;
|
||||
QSlider *rightChannelSlider = nullptr;
|
||||
std::vector<QSlider*> channelSliders;
|
||||
std::vector<QLabel*> channelLabels;
|
||||
/*
|
||||
* QSlider *leftChannelSlider = nullptr;
|
||||
* QSlider *rightChannelSlider = nullptr;
|
||||
*/
|
||||
QGridLayout *layout = nullptr;
|
||||
QGridLayout *mainMuteLayout = nullptr;
|
||||
void updateMainVolume(float newValue);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue