wip: session meter

This commit is contained in:
Hane 2024-04-30 23:40:52 +02:00
commit dc8951776f
7 changed files with 30 additions and 5 deletions

View file

@ -294,6 +294,11 @@ void Endpoint::activateEndpointSessions() {
for (int i = 0; i < sessionCount; i++) { for (int i = 0; i < sessionCount; i++) {
IAudioSessionControl* sessionControlTmp; IAudioSessionControl* sessionControlTmp;
sessionEnumerator->GetSession(i, (IAudioSessionControl**)&sessionControlTmp); sessionEnumerator->GetSession(i, (IAudioSessionControl**)&sessionControlTmp);
/*todo: borrar when donezo
* float test2;
* IAudioMeterInformation* ttmp = (IAudioMeterInformation*)sessionControlTmp;
* ttmp->GetPeakValue(&test2);
*/
//todo:: asegurar lo del dynamic_cast //todo:: asegurar lo del dynamic_cast
IAudioSessionControl2* sessionControl; IAudioSessionControl2* sessionControl;
sessionControlTmp->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl); sessionControlTmp->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl);

View file

@ -100,7 +100,11 @@ Session::Session(Endpoint* ep, IAudioSessionControl2* sessionControl, size_t idx
this->ep = ep; this->ep = ep;
this->sessionControl = sessionControl; this->sessionControl = sessionControl;
this->idx = idx; this->idx = idx;
//https://matthewvaneerde.wordpress.com/2012/06/08/getting-audio-peak-meter-values-for-all-active-audio-sessions/
if (FAILED(sessionControl->QueryInterface(__uuidof(IAudioMeterInformation), (void**)&meterInformation))) { log_wdebugcpp(L"sPeakbros......"); };
//meterInformation = (IAudioMeterInformation*)sessionControl;
AudioSessionState msState; AudioSessionState msState;
sessionControl->GetState(&msState); sessionControl->GetState(&msState);
switch (msState) { switch (msState) {
@ -142,6 +146,13 @@ float Session::getVolume(int channel){
return volume; return volume;
} }
float Session::getPeakVolume() {
float peakVol;
if(meterInformation) meterInformation->GetPeakValue(&peakVol);
else return 0;
return peakVol;
}
/* /*
* uint32_t Endpoint::getChannelCount(){ * uint32_t Endpoint::getChannelCount(){
* return (uint32_t)channelCount; * return (uint32_t)channelCount;
@ -283,6 +294,7 @@ void Session::removeStateCallback(SessionStateCallback *ssc){
} }
Session::~Session() { Session::~Session() {
meterInformation->Release();
sessionControl->Release(); sessionControl->Release();
sessionVolume->Release(); sessionVolume->Release();
} }

View file

@ -33,6 +33,7 @@ class Session {
Session(Endpoint* ep, IAudioSessionControl2* sessionControl) : Session(ep, sessionControl, SIZE_MAX) {}; Session(Endpoint* ep, IAudioSessionControl2* sessionControl) : Session(ep, sessionControl, SIZE_MAX) {};
void setVolume(NGuid guid, int channel, float volume); void setVolume(NGuid guid, int channel, float volume);
float getVolume(int channel); float getVolume(int channel);
float getPeakVolume();
void setMute(NGuid guid, bool muted); void setMute(NGuid guid, bool muted);
bool getMute(); bool getMute();
SessionState getState(); SessionState getState();
@ -51,6 +52,7 @@ class Session {
SessionState sessionState; SessionState sessionState;
Endpoint* ep; Endpoint* ep;
IAudioSessionControl2* sessionControl = nullptr; IAudioSessionControl2* sessionControl = nullptr;
IAudioMeterInformation* meterInformation = nullptr;
ISimpleAudioVolume* sessionVolume = nullptr; ISimpleAudioVolume* sessionVolume = nullptr;
size_t idx; size_t idx;
}; };

View file

@ -36,6 +36,10 @@ void SessionHandler::setName(std::wstring newName){
session->setName(newName); session->setName(newName);
} }
float SessionHandler::getPeakVolume(){
return session->getPeakVolume();
}
bool SessionHandler::getMute(){ bool SessionHandler::getMute(){
return session->getMute(); return session->getMute();
} }

View file

@ -29,6 +29,7 @@ class SessionHandler {
void setState(SessionState state); void setState(SessionState state);
uint64_t getFrontIndex(); uint64_t getFrontIndex();
std::wstring getName(); std::wstring getName();
float getPeakVolume();
void setName(std::wstring newName); void setName(std::wstring newName);
void reviseSessionShowing(SessionState state); void reviseSessionShowing(SessionState state);
SessionVolumeInfo* getVolumeInfo(); SessionVolumeInfo* getVolumeInfo();

View file

@ -200,7 +200,7 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
muteButton = new QCheckBox(this); muteButton = new QCheckBox(this);
mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this); mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this);
mainSlider = new QSlider(Qt::Horizontal, this); mainSlider = new MeterSlider(Qt::Horizontal, this);
//mainLabel->setMaximumWidth(150 /*1/16ish 1080p*/); //mainLabel->setMaximumWidth(150 /*1/16ish 1080p*/);
//mainLabel->setMinimumWidth(150 /*1/16ish 1080p*/); //mainLabel->setMinimumWidth(150 /*1/16ish 1080p*/);
@ -248,9 +248,10 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
mainSlider->blockSignals(true); mainSlider->blockSignals(true);
muteButton->blockSignals(true); muteButton->blockSignals(true);
mainSlider->setValue((int)((sh->getVolumeInfo()->mainVolume + roundingFactor) * 100)); mainSlider->setValue((int)((sh->getVolumeInfo()->mainVolume + roundingFactor) * 100));
mainSlider->setPeakValue(sh->getPeakVolume());
mainSlider->update();
muteButton->setCheckState((sh->getVolumeInfo()->muted == false ? Qt::Unchecked : Qt::Checked)); muteButton->setCheckState((sh->getVolumeInfo()->muted == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(sh->getVolumeInfo()->muted ? STRING_UNMUTE : STRING_MUTE); muteButton->setText(sh->getVolumeInfo()->muted ? STRING_UNMUTE : STRING_MUTE);
//memcpy(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)); //memcpy(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid));
//TODO: el default = objcopy frees? //TODO: el default = objcopy frees?
@ -259,7 +260,7 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
mainSlider->blockSignals(false); mainSlider->blockSignals(false);
muteButton->blockSignals(false); muteButton->blockSignals(false);
}); });
volumePoller->start(10); volumePoller->start(2);
} }
void SessionWidget::calculateSize(uint64_t width, uint64_t height) { void SessionWidget::calculateSize(uint64_t width, uint64_t height) {

View file

@ -112,7 +112,7 @@ public slots:
private: private:
QLabel *mainLabel = nullptr; QLabel *mainLabel = nullptr;
QSlider *mainSlider = nullptr; MeterSlider *mainSlider = nullptr;
uint64_t idx; uint64_t idx;
QHBoxLayout *widgetLayout = nullptr; QHBoxLayout *widgetLayout = nullptr;
QCheckBox *muteButton = nullptr; QCheckBox *muteButton = nullptr;