diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 0d35bed..147a594 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -134,13 +134,10 @@ HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify } -/* - * EndpointSituationCallback::EndpointSituationCallback(std::vector* playbackDevices, std::vector* captureDevices){ - * this->captureDevices = captureDevices; - * this->playbackDevices = playbackDevices; - * } - */ +EndpointSituationCallback::EndpointSituationCallback(Overseer* os){ + this->os = os; +} ULONG EndpointSituationCallback::AddRef(){ @@ -227,13 +224,7 @@ HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, D } HRESULT EndpointSituationCallback::OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key) { - - /* Lacking impl again? */ - PWSTR test; - HRESULT ctrl = PSGetNameFromPropertyKey(key, &test); - if (ctrl == S_OK) log_wdebugcpp(test); - - + os->updateEndpointInfo(std::wstring(pwstrDeviceId)); return S_OK; } @@ -266,20 +257,29 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){ log_wdebugcpp(endpointId); CoTaskMemFree(tempString); - endpoint->OpenPropertyStore(STGM_READ, &properties); - PROPVARIANT pv; - properties->GetValue(PKEY_Device_FriendlyName , &pv); - if (pv.pwszVal == nullptr) - friendlyName = L"Unnamed Not Present Endpoint"; - else - friendlyName = std::wstring(pv.pwszVal); + endpoint->OpenPropertyStore(STGM_READ, &properties); + this->updateName(); - this->setFlow(); + this->setFlow(); if (this->flow == Flows::FLOW_PLAYBACK) { activateEndpointSessions(); } } +void Endpoint::updateName() { + PROPVARIANT pv; + #define store_name(key, propvariant, wstr) do { \ + properties->GetValue(key , &propvariant); \ + if (pv.pwszVal == nullptr) wstr = L"Unnamed Not Present Endpoint"; \ + else wstr = std::wstring(pv.pwszVal); \ + } while (0) + + store_name(PKEY_Device_FriendlyName, pv, friendlyName); + store_name(PKEY_Device_DeviceDesc, pv, descriptionName); + store_name(PKEY_DeviceInterface_FriendlyName, pv, deviceName); + #undef store_name +} + void Endpoint::activateEndpointSessions() { //sessionManager; if (FAILED(endpoint->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**) &sessionManager))) { log_wdebugcpp(L"sesionbros..."); return; } @@ -666,7 +666,7 @@ Endpoint* Overseer::addEndpoint(std::wstring endpointId, /* out */Flows* flow = return endpoint; } -Overseer::Overseer() { //: epsc(&playbackDevices, &captureDevices){ +Overseer::Overseer() : epsc(this){ //Initializing COM library log_debugcpp("Initializing Overseer"); initCOMLibrary(); @@ -719,6 +719,18 @@ std::vector Overseer::getCaptureEndpoints() { return captureDevices; } +void Overseer::updateEndpointInfo(std::wstring endpointId) { + log_wdebugcpp(L"new name Endpoint id: " + endpointId); + //todo: reintroduce capture devices + for(auto ep : playbackDevices) { + if (ep->getId() == endpointId) { + ep->updateName(); + osh->updateFrontEndpointName(ep); + break; + } + } +} + Overseer::~Overseer(){ log_debugcpp("cum"); deviceEnumerator->Release(); diff --git a/src/back/backlasses.h b/src/back/backlasses.h index c6148c4..9e3aba2 100644 --- a/src/back/backlasses.h +++ b/src/back/backlasses.h @@ -32,6 +32,7 @@ class Endpoint { Flows getFlow(); std::wstring getId(); std::wstring getName(); + void updateName(); void setVolumeCallback(EndpointVolumeCallback *epc); void removeVolumeCallback(EndpointVolumeCallback *epc); @@ -57,6 +58,8 @@ class Endpoint { IAudioEndpointVolume *endpointVolume = nullptr; IPropertyStore *properties; std::wstring friendlyName; + std::wstring descriptionName; + std::wstring deviceName; std::wstring endpointId; unsigned long endpointState; Roles endpointRoles = (Roles)0; @@ -84,8 +87,7 @@ class EndpointVolumeCallback : public IAudioEndpointVolumeCallback { class EndpointSituationCallback : public IMMNotificationClient { public: - //EndpointSituationCallback(IMMDeviceEnumerator *deviceEnumerator, std::vector playbackDevices, std::vector captureDevices); - //EndpointSituationCallback(std::vector* playbackDevices, std::vector* captureDevices); + EndpointSituationCallback(Overseer* os); ULONG AddRef(); ULONG Release(); HRESULT QueryInterface(REFIID riid, VOID **ppvInterface); @@ -97,9 +99,7 @@ class EndpointSituationCallback : public IMMNotificationClient { private: ULONG ref = 1; - //IMMDeviceEnumerator *deviceEnumerator; - //std::vector* playbackDevices; - //std::vector* captureDevices; + Overseer* os; }; class Overseer { @@ -107,9 +107,9 @@ class Overseer { public: Overseer(); void openControlPanel(); - //todo: restore/overseer std::vector getPlaybackEndpoints(); std::vector getCaptureEndpoints(); + void updateEndpointInfo(std::wstring endpointId); void reloadEndpoints(Flows flow); Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow); diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index 5e0a4ee..c7a2cf0 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -294,6 +294,13 @@ void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpo this->changeFrontDefaults(role, endpointId); } +void OverseerHandler::updateFrontEndpointName(Endpoint* ep) { + //todo: reintroduce capture devices + for (auto eph : playbackEndpointHandlers) { + if (eph->getEndpoint() == ep) eph->getCallbackInfo()->updateName = true; + } +} + void OverseerHandler::reviseEndpointShowing(std::wstring endpointId, EndpointState state) { std::vector allHandlers; allHandlers.insert(allHandlers.end(), this->captureEndpointHandlers.begin(), this->captureEndpointHandlers.end()); diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index 2f70b56..f52d956 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -18,6 +18,7 @@ struct BackEndpointVolumeCallbackInfo { float mainVolume; size_t channels; std::vector channelVolumes; + bool updateName = false; }; class EndpointHandler { @@ -30,7 +31,7 @@ public: //EndpointVolumeCallback* getEndpointVolumeCallback(); //Endpoint* getEndpoint(); - //std::wstring epName; + //todo: name refactor BackEndpointVolumeCallbackInfo* getCallbackInfo(); uint32_t getChannelCount(); @@ -103,6 +104,7 @@ public: void setChangeFrontDefaultsFunction(std::function changeFrontDefaults); void changeFrontDefaultsCallback(Roles role, std::wstring endpointId); + void updateFrontEndpointName(Endpoint* ep); //void setReviseEndpointShowingFunction(std::function reviseEndpointShowing); void reviseEndpointShowing(std::wstring endpointId, EndpointState state); void setRemoveEndpointWidgetFunction(std::function removeEndpointWidget); diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index d1bdde2..9411a3e 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -420,6 +420,11 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i //if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW. //todo: global + constexpr + ratio const float roundingFactor = 0.005; + if (eph->getCallbackInfo()->updateName) { + eph->getCallbackInfo()->updateName = false; + mainLabel->setText(QString::fromStdWString(eph->getName())); + mainLabel->setMinimumHeight(mainLabel->sizeHint().height()); + } mainSlider->blockSignals(true); muteButton->blockSignals(true); mainSlider->setValue((int)((eph->getCallbackInfo()->mainVolume + roundingFactor) * 100));