diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 8f56fa2..ced20f3 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -246,10 +246,6 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){ // CLSCTX_ALL, NULL, (void**)&audioClient))) { log_debugcpp("audioclntbros..."); } //audioClient->GetDevicePeriod(&defTime, &minTime); - //todo: check header - //if(FAILED(endpoint->Activate(__uuidof(IAudioMeterInformation), - // CLSCTX_ALL, NULL, (void**)&endpointPeakMeter))) { log_debugcpp("peakbros..."); } - //endpointPeakMeter->GetPeakValue(&test); } reloadEndpointChannels(); @@ -323,6 +319,12 @@ void Endpoint::activateEndpointVolume() { if (this->endpointVolume == nullptr){ HRESULT result = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&this->endpointVolume); + + //todo: check header + if(FAILED(endpoint->Activate(__uuidof(IAudioMeterInformation), + CLSCTX_ALL, NULL, (void**)&endpointPeakMeter))) { log_debugcpp("peakbros..."); } + // + //if (endpointVolume == nullptr) { //why they returning 0 after dealing with the error jfc CO_E_NOTINITIALIZED) { //CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE); //extraThread = true; @@ -356,6 +358,13 @@ std::wstring Endpoint::getId(){ return endpointId; } +float Endpoint::getPeakVolume() { + float peakVol; + if(endpointPeakMeter) endpointPeakMeter->GetPeakValue(&peakVol); + else return 0; + return peakVol; +} + float Endpoint::getVolume(int channel){ float volume; if (channel == AudioChannel::CHANNEL_MAIN) { diff --git a/src/back/backlasses.h b/src/back/backlasses.h index 207cba7..f2c0199 100644 --- a/src/back/backlasses.h +++ b/src/back/backlasses.h @@ -30,6 +30,7 @@ class Endpoint { void removeRoles(Roles role); void setFlow(); Flows getFlow(); + float getPeakVolume(); std::wstring getId(); std::wstring getName(); void updateName(); @@ -66,7 +67,7 @@ class Endpoint { unsigned long endpointState; Roles endpointRoles = (Roles)0; uint64_t idx; - //Not implemented in llvm-mingw. Sad! + //Not implemented in llvm-mingw. Sad! todo: mingw patch IAudioMeterInformation *endpointPeakMeter = nullptr; }; diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index c7a2cf0..f46571c 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -133,6 +133,10 @@ void EndpointHandler::setState(uint8_t state, uint64_t index){ this->setBackEndpointVolumeCallbackInfoContent(state); } +float EndpointHandler::getPeakVolume() { + return ep->getPeakVolume(); +} + uint8_t EndpointHandler::getRoles(){ return ep->getRoles(); } diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index 4a5f543..b0cea92 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -58,6 +58,7 @@ public: void setState(uint8_t state); void setState(uint8_t state, uint64_t idx); + float getPeakVolume(); /* sessions */ size_t getSessionCount(); std::vector getSessionHandlers(); diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 4dea7ac..c6faba8 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -5,6 +5,10 @@ CustomWidgetEvent::CustomWidgetEvent(QEvent::Type type, T payload) : QEvent(t this->payload = payload; } +void MeterSlider::setPeakValue(float peakValue) { + this->peakValue = peakValue; +} + void MeterSlider::paintEvent(QPaintEvent *event) { //Q_D(QSlider); /* @@ -23,11 +27,15 @@ void MeterSlider::paintEvent(QPaintEvent *event) { QStyle *style = QApplication::style(); int lol = style->pixelMetric(QStyle::PM_SliderSpaceAvailable); QPainter painter(this); - painter.setPen(Qt::blue); + //painter.setPen(Qt::blue); painter.setOpacity(1.0); painter.setClipping(false); painter.setCompositionMode(QPainter::CompositionMode::CompositionMode_Source); - painter.fillRect(0, (this->height() / 2) - 3, this->width(), 4, Qt::black); + float peakLength = (this->width() * (this->peakValue)); + //const qreal dpr = painter->device()->devicePixelRatio(); + QStyleOptionSlider slider = QStyleOptionSlider(); + QRect test = QApplication::style()->subControlRect(QStyle::CC_Slider, (QStyleOptionComplex*)&slider, QStyle::SC_SliderHandle); + painter.fillRect(0, (this->height() / 2) - 3, (this->width() * (this->peakValue)), 4, Qt::green); } void ExtendedCheckBox::customEvent(QEvent* ev) { @@ -482,6 +490,8 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i mainSlider->blockSignals(true); muteButton->blockSignals(true); mainSlider->setValue((int)((eph->getCallbackInfo()->mainVolume + roundingFactor) * 100)); + mainSlider->setPeakValue(eph->getPeakVolume()); + mainSlider->update(); mainVolumeLabel->setText(QString::number(mainSlider->value())); muteButton->setCheckState((eph->getCallbackInfo()->muted == false ? Qt::Unchecked : Qt::Checked)); muteButton->setText(eph->getCallbackInfo()->muted ? STRING_UNMUTE : STRING_MUTE); @@ -496,7 +506,7 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i mainSlider->blockSignals(false); muteButton->blockSignals(false); }); - timer->start(10); + timer->start(2); /* First Widget batch */ for (size_t i = 0; i < eph->getSessionCount(); i++) { diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index b39635d..3441442 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -27,8 +27,12 @@ #include #include #include +#include +#include +#include #include #include + //#include /* * #else @@ -71,12 +75,13 @@ public: class MeterSlider : public QSlider { Q_OBJECT +private: + float peakValue; protected: void paintEvent(QPaintEvent *event) override; - public: + void setPeakValue(float peakValue); using QSlider::QSlider; - }; class ExtendedCheckBox : public QCheckBox { diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp index 1d421cc..075b992 100644 --- a/src/qtestmain.cpp +++ b/src/qtestmain.cpp @@ -52,7 +52,7 @@ int main (int argc, char* argv[]) { * log_debugcpp(a.toStdString()); * } */ - //QApplication::setStyle("Fusion"); + QApplication::setStyle("Fusion"); //Check if running //https://stackoverflow.com/questions/48060989/qt-show-application-if-currently-running initialize_file_log();