From 44ccde6ac890d727a1c4e581a10d644f01c5c74f Mon Sep 17 00:00:00 2001 From: Hane Date: Thu, 14 Sep 2023 18:01:32 +0200 Subject: [PATCH] almost captured, only to hotplug. such is life... --- src/back/backfuncs.h | 1 - src/back/backlasses.cpp | 154 ++++++++++++++++++++++++++++++--------- src/back/backlasses.h | 21 +++++- src/cont/contclasses.cpp | 98 ++++++++++++++++++++----- src/cont/contclasses.h | 15 +++- src/qt/qtclasses.cpp | 11 +-- 6 files changed, 236 insertions(+), 64 deletions(-) diff --git a/src/back/backfuncs.h b/src/back/backfuncs.h index f66a295..1062ba1 100644 --- a/src/back/backfuncs.h +++ b/src/back/backfuncs.h @@ -3,7 +3,6 @@ GUID NGuidToGUID(NGuid guid) { msGuid.Data1 = guid.data1; msGuid.Data2 = guid.data2; msGuid.Data3 = guid.data3; - msGuid.Data1 = guid.data1; for (int i = 0; i < 8; i++){ msGuid.Data4[i] = guid.data4[i]; //log_debugcpp("MSGUID DATA4 BYTE " << i << ": "); diff --git a/src/back/backlasses.cpp b/src/back/backlasses.cpp index 4e4f4a1..8983942 100644 --- a/src/back/backlasses.cpp +++ b/src/back/backlasses.cpp @@ -39,30 +39,30 @@ HRESULT EndpointVolumeCallback::QueryInterface(REFIID riid, VOID **ppvInterface) HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify) { if (pNotify == NULL) return E_INVALIDARG; - //delete osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller; - //osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.freeData4(); + //delete osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller; + //osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.freeData4(); //Could've made a function or = override to hide this within Nguid, but back in cont = bad. - osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data1 \ + osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data1 \ = pNotify->guidEventContext.Data1; - osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data2 \ + osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data2 \ = pNotify->guidEventContext.Data2; - osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data3 \ + osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data3 \ = pNotify->guidEventContext.Data3; for(int i = 0; i < 8 /* Data4 size */; i++){ - osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data4[i] = pNotify->guidEventContext.Data4[i]; + osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller.data4[i] = pNotify->guidEventContext.Data4[i]; } - //memcpy(&osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller, &pNotify->guidEventContext,sizeof(NGuid) ); + //memcpy(&osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->caller, &pNotify->guidEventContext,sizeof(NGuid) ); - osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->muted = pNotify->bMuted; - osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->mainVolume = pNotify->fMasterVolume; - osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channels = pNotify->nChannels; + osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->muted = pNotify->bMuted; + osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->mainVolume = pNotify->fMasterVolume; + osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channels = pNotify->nChannels; UINT j = 0; //todo: do while here caused stack corruption; sus while(j < pNotify->nChannels) { - osh->getEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channelVolumes[j] = pNotify->afChannelVolumes[j]; + osh->getPlaybackEndpointHandlers().at(this->ep->getIndex())->getCallbackInfo()->channelVolumes[j] = pNotify->afChannelVolumes[j]; j++; } return S_OK; @@ -76,9 +76,10 @@ HRESULT EndpointVolumeCallback::OnNotify(PAUDIO_VOLUME_NOTIFICATION_DATA pNotify * */ //todo: not on construct since it expects them to already exist; smells like refactor! -void EndpointSituationCallback::fill(IMMDeviceEnumerator *deviceEnumerator, std::vector playbackDevices){ +void EndpointSituationCallback::fill(IMMDeviceEnumerator *deviceEnumerator, std::vector playbackDevices, std::vector captureDevices){ this->deviceEnumerator = deviceEnumerator; this->playbackDevices = playbackDevices; + this->captureDevices = captureDevices; } ULONG EndpointSituationCallback::AddRef(){ @@ -151,10 +152,14 @@ HRESULT EndpointSituationCallback::OnDeviceStateChanged(LPCWSTR pwstrDeviceId, D osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_ACTIVE); break; case DEVICE_STATE_DISABLED: - case DEVICE_STATE_NOTPRESENT: - case DEVICE_STATE_UNPLUGGED: osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_DISABLED); break; + case DEVICE_STATE_NOTPRESENT: + osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_NOTPRESENT); + break; + case DEVICE_STATE_UNPLUGGED: + osh->reviseEndpointShowing(endpointId, EndpointState::ENDPOINT_UNPLUGGED); + break; } return S_OK; @@ -189,6 +194,11 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){ activateEndpointVolume(); reloadEndpointChannels(); + + /* + * if(FAILED(endpoint->Activate(__uuidof(IAudioMeterInformation), + * CLSCTX_ALL, NULL, (void**)&endpointPeakMeter))) { log_debugcpp("peakbros..."); } + */ //todo:: atexit into exit Gather ID LPWSTR tempString = nullptr; @@ -206,6 +216,11 @@ Endpoint::Endpoint(IMMDevice* ep, uint64_t idx){ friendlyName = std::wstring(pv.pwszVal); } +/* + * Endpoint::Endpoint(IMMDevice* endpoint) : Endpoint(endpoint, 0) {}; + */ + + void Endpoint::activateEndpointVolume() { if (this->endpointVolume == nullptr) if(FAILED(endpoint->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&this->endpointVolume))) { log_debugcpp(std::string("no endpointVolume (IAudioEndpointVolume)")); }; @@ -372,6 +387,33 @@ void Endpoint::removeRoles(Roles role){ this->endpointRoles = roles; } +void Endpoint::setFlow() { + IMMEndpoint* flowGetter; + //this should be as simple as writing IID_IMMEndpoint, but it just won't find the macro, so I copied it. Sad. + GUID manual; + manual.Data1 = 0x1be09788; + manual.Data2 = 0x6894; + manual.Data3 = 0x4089; + manual.Data4[0] = 0x85; + manual.Data4[1] = 0x86; + manual.Data4[2] = 0x9a; + manual.Data4[3] = 0x2a; + manual.Data4[4] = 0x6c; + manual.Data4[5] = 0x26; + manual.Data4[6] = 0x5a; + manual.Data4[7] = 0xc5; + if(FAILED(this->endpoint->QueryInterface((const _GUID)manual, (void**)&flowGetter))) + { log_debugcpp("no flow..."); } + EDataFlow MSflow; + HRESULT vafllar = flowGetter->GetDataFlow(&MSflow); + this->flow = (MSflow == EDataFlow::eRender ? Flows::FLOW_PLAYBACK : Flows::FLOW_CAPTURE); + flowGetter->Release(); +} + +Flows Endpoint::getFlow() { + return this->flow; +} + Endpoint::~Endpoint(){ log_debugcpp("murio endpoint-san uwu"); properties->Release(); @@ -394,6 +436,7 @@ void Overseer::initCOMLibrary() { GUID tempGuid; if(FAILED(CoCreateGuid(&tempGuid))) { log_debugcpp("Failed to obtain GUID: " ); }; + //todo: wtf? why is it working? floats are ptrs... this->guid = GUIDToNGuid(&tempGuid); //if(FAILED(CoCreateInstance(__uuidof(CPolicyConfigClient), @@ -403,28 +446,34 @@ void Overseer::initCOMLibrary() { //TODO: Uninitialize COM } -void Overseer::reloadEndpoints() { +void Overseer::reloadEndpoints(Flows flow) { IMMDeviceCollection *deviceCollection; + unsigned int numEndpoints; + EDataFlow MSflow = (flow == Flows::FLOW_PLAYBACK ? EDataFlow::eRender : EDataFlow::eCapture); // | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED // NOTPRESENT shows a lot of garbage, unnamed devices. - if(FAILED(deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED, &deviceCollection) )) + if(FAILED(deviceEnumerator->EnumAudioEndpoints(MSflow, DEVICE_STATE_ACTIVE | DEVICE_STATE_DISABLED | DEVICE_STATE_NOTPRESENT | DEVICE_STATE_UNPLUGGED, &deviceCollection) )) { log_debugcpp("si"); }; /* * Counting them */ - if(FAILED(deviceCollection->GetCount(&numPlaybackEndpoints))) { log_debugcpp("si");}; - if(numPlaybackEndpoints == 0) { log_debugcpp("si"); }; + if(FAILED(deviceCollection->GetCount(&numEndpoints))) { log_debugcpp("si");}; + if(numEndpoints == 0) { log_debugcpp("si"); }; /* * Retrieving actual endpoints and storing them on their own class */ IMMDevice *temp; - for (unsigned int i = 0; i < numPlaybackEndpoints; i++){ + for (unsigned int i = 0; i < numEndpoints; i++){ if(deviceCollection->Item(i, &temp) != 0) { log_debugcpp("si"); }; Endpoint *endpoint = new Endpoint(temp, i); + endpoint->setFlow(); //endpoint->setIndex(i); - this->playbackDevices.push_back(endpoint); + if (flow == Flows::FLOW_PLAYBACK) + this->playbackDevices.push_back(endpoint); + else + this->captureDevices.push_back(endpoint); //TODO: le porblemx std::cout + "ola" + std::endl; } @@ -447,30 +496,65 @@ void Overseer::reloadEndpoints() { val = eCommunications; break; } - deviceEnumerator->GetDefaultAudioEndpoint(EDataFlow::eRender, val, &temp); + deviceEnumerator->GetDefaultAudioEndpoint(MSflow, val, &temp); LPWSTR id = nullptr; - - for (unsigned int j = 0; j < numPlaybackEndpoints; j++){ - std::wstring eptId = playbackDevices.at(j)->getId(); - temp->GetId(&id); - int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, eptId.c_str(), -987, id, -987, NULL, NULL, 0); - if (comparison - 2 == 0) { - log_wdebugcpp(L"ola defaul de " + std::to_wstring(i) + L" es " + id); - playbackDevices.at(j)->assignRoles((Roles)(1 << i)); + + if (flow == Flows::FLOW_PLAYBACK) { + for (unsigned int j = 0; j < numEndpoints; j++) { + std::wstring eptId = playbackDevices.at(j)->getId(); + temp->GetId(&id); + int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, eptId.c_str(), -987, id, -987, NULL, NULL, 0); + if (comparison - 2 == 0) { + log_wdebugcpp(L"ola defaul playback de " + + std::to_wstring(i) + L" es " + id); + playbackDevices.at(j)->assignRoles((Roles)(1 << i)); + } } - //uint8_t debg = playbackDevices.at(j)->getRoles(); - } + } else { + for (unsigned int j = 0; j < numEndpoints; j++){ + std::wstring eptId = captureDevices.at(j)->getId(); + temp->GetId(&id); + int comparison = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, eptId.c_str(), -987, id, -987, NULL, NULL, 0); + if (comparison - 2 == 0) { + log_wdebugcpp(L"ola defaul capture de " + + std::to_wstring(i) + L" es " + id); + captureDevices.at(j)->assignRoles((Roles)(1 << i)); + } + } + } } } +Endpoint* Overseer::addEndpoint(std::wstring endpointId, /* out */Flows* flow = nullptr) { + IMMDevice* newep; + if(FAILED(deviceEnumerator->GetDevice((LPCWSTR)endpointId.c_str(), &newep))) + log_debugcpp("ay caramba con la hot metida."); + + Endpoint *endpoint = new Endpoint(newep); + + Flows getFlow = endpoint->getFlow(); + if (getFlow == Flows::FLOW_PLAYBACK) { + endpoint->setIndex(osh->getPlaybackEndpointsCount()); + this->playbackDevices.push_back(endpoint); + } else { + endpoint->setIndex(osh->getCaptureEndpointsCount()); + this->captureDevices.push_back(endpoint); + } + if (flow != nullptr) *flow = getFlow; + return endpoint; +} + Overseer::Overseer() { //: epsc(deviceEnumerator, playbackDevices){ //Initializing COM library log_debugcpp("Initializing Overseer"); initCOMLibrary(); //Obtaining playback endpoint collection on this point in time - reloadEndpoints(); - this->epsc.fill(deviceEnumerator, playbackDevices); + reloadEndpoints(Flows::FLOW_PLAYBACK); + //reloadEndpoints(Flows::FLOW_CAPTURE); + + //Registering for endpoint information callback + this->epsc.fill(deviceEnumerator, playbackDevices, captureDevices); if(FAILED(deviceEnumerator->RegisterEndpointNotificationCallback(((IMMNotificationClient*)&epsc)))) { log_debugcpp("when no enchufas......"); } } @@ -482,6 +566,10 @@ std::vector Overseer::getPlaybackEndpoints() { return playbackDevices; } +std::vector Overseer::getCaptureEndpoints() { + return captureDevices; +} + Overseer::~Overseer(){ log_debugcpp("cum"); deviceEnumerator->Release(); diff --git a/src/back/backlasses.h b/src/back/backlasses.h index 3bf02d3..ebfc07e 100644 --- a/src/back/backlasses.h +++ b/src/back/backlasses.h @@ -33,6 +33,8 @@ class Endpoint { public: Endpoint(IMMDevice* endpoint, uint64_t idx); + //todo: how to forward declare delegate constructors? + Endpoint(IMMDevice* endpoint) : Endpoint(endpoint, 0) {}; void reloadEndpointChannels(); uint64_t getIndex(); void setIndex(uint64_t idx); @@ -47,6 +49,8 @@ class Endpoint { void setRoles(Roles role); void assignRoles(Roles role); void removeRoles(Roles role); + void setFlow(); + Flows getFlow(); std::wstring getId(); std::wstring getName(); void setVolumeCallback(EndpointVolumeCallback *epc); @@ -58,13 +62,17 @@ class Endpoint { uint32_t channelCount = 0; IMMDevice* endpoint; - IAudioEndpointVolume *endpointVolume = nullptr; + Flows flow; + IAudioEndpointVolume *endpointVolume = nullptr; IPropertyStore *properties; std::wstring friendlyName; std::wstring endpointId; unsigned long endpointState; Roles endpointRoles = (Roles)0; uint64_t idx; + /* Not implemented in llvm-mingw. Sad! + * IAudioMeterInformation *endpointPeakMeter = nullptr; + */ }; class EndpointVolumeCallback : public IAudioEndpointVolumeCallback { @@ -95,11 +103,12 @@ class EndpointSituationCallback : public IMMNotificationClient { HRESULT OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState); HRESULT OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key); - void fill(IMMDeviceEnumerator *deviceEnumerator, std::vector playbackDevices); + void fill(IMMDeviceEnumerator *deviceEnumerator, std::vector playbackDevices, std::vector captureDevices); private: ULONG ref = 1; IMMDeviceEnumerator *deviceEnumerator; std::vector playbackDevices; + std::vector captureDevices; }; class Overseer { @@ -107,7 +116,10 @@ class Overseer { public: Overseer(); std::vector getPlaybackEndpoints(); - void reloadEndpoints(); + std::vector getCaptureEndpoints(); + + void reloadEndpoints(Flows flow); + Endpoint* addEndpoint(std::wstring endpointId, /* out */ Flows* flow); NGuid getGuid(); //void setEndpointStatusCallback(); //void setEndpointStatusCallback(); @@ -121,11 +133,12 @@ class Overseer { private: NGuid guid; - unsigned int numPlaybackEndpoints; + IMMDeviceEnumerator *deviceEnumerator; EndpointSituationCallback epsc; //IPolicyConfig *policyConfig; std::vector playbackDevices; + std::vector captureDevices; void initCOMLibrary(); //IMMDeviceCollection *deviceCollection; //int numCaptureEndpoints; diff --git a/src/cont/contclasses.cpp b/src/cont/contclasses.cpp index 84411f7..937ee67 100644 --- a/src/cont/contclasses.cpp +++ b/src/cont/contclasses.cpp @@ -2,15 +2,28 @@ #include "contclasses.h" //TODO: pragma once -EndpointHandler::EndpointHandler(uint64_t idx) { +EndpointHandler::EndpointHandler(uint64_t idx, Flows flow) { //std::vector endpoints = osh->getPlaybackEndpoints().at(idx); this->idx = idx; - this->ep = osh->getPlaybackEndpoints().at(idx); + this->flow = flow; + this->ep = (flow == Flows::FLOW_PLAYBACK ? osh->getPlaybackEndpoints().at(idx) : osh->getCaptureEndpoints().at(idx)); + epc = new EndpointVolumeCallback(ep); this->callbackInfo.caller = osh->getGuid(); //epName = ep->getName(); - this->setBackEndpointVolumeCallbackInfoContent(this->getState()); + this->setBackEndpointVolumeCallbackInfoContent(this->getState()); + osh->pushBackEndpointHandler(this, flow); + +} + +void OverseerHandler::pushBackEndpointHandler(EndpointHandler* eph, Flows flow) { + if (eph == nullptr) return; + if (flow = Flows::FLOW_PLAYBACK) + playbackEndpointHandlers.push_back(eph); + else + captureEndpointHandlers.push_back(eph); + return; } void EndpointHandler::setFrontVisibilityInfo(EndpointState state, uint64_t frontIdx){ @@ -139,35 +152,79 @@ std::vector OverseerHandler::getPlaybackEndpoints() { return this->os->getPlaybackEndpoints(); } -std::vector OverseerHandler::getEndpointHandlers(){ - return endpointHandlers; +std::vector OverseerHandler::getCaptureEndpoints() { + return this->os->getCaptureEndpoints(); +} + +std::vector OverseerHandler::getPlaybackEndpointHandlers(){ + return playbackEndpointHandlers; +} + +std::vector OverseerHandler::getCaptureEndpointHandlers(){ + return captureEndpointHandlers; } uint64_t OverseerHandler::getPlaybackEndpointsCount(){ return this->os->getPlaybackEndpoints().size(); } +uint64_t OverseerHandler::getCaptureEndpointsCount(){ + return this->os->getCaptureEndpoints().size(); +} + void OverseerHandler::reloadEndpointHandlers(){ + //todo: add capture + //std::vector* ephs = new std::vector; - log_debugcpp(" VSize: " + std::to_string(this->getPlaybackEndpointsCount())); + log_debugcpp("Playback VSize: " + std::to_string(this->getPlaybackEndpointsCount())); for(uint64_t i = 0; i < this->getPlaybackEndpointsCount(); i++){ - log_debugcpp("Creating handler " + std::to_string(i)); + log_debugcpp("Creating Playback handler " + std::to_string(i)); + + EndpointHandler* ephexx = new EndpointHandler(i, Flows::FLOW_PLAYBACK); + //this->playbackEndpointHandlers.push_back(ephexx); + log_debugcpp("Created Playback handler " + std::to_string(i) + ", adding to vector. " + " VSize: " + std::to_string(this->playbackEndpointHandlers.size())); - if(i < (this->endpointHandlers.size()) && - this->endpointHandlers.at(i) != nullptr) - delete endpointHandlers.at(i); + } + + log_debugcpp("Capture VSize: " + + std::to_string(this->getCaptureEndpointsCount())); + + for(uint64_t i = 0; i < this->getCaptureEndpointsCount(); i++){ + log_debugcpp("Creating Capture handler " + std::to_string(i)); - EndpointHandler* eph = new EndpointHandler(i); - log_debugcpp("Created handler " + std::to_string(i) + ", adding to vector. " + " VSize: " + std::to_string(this->getPlaybackEndpointsCount())); + /* + * if(i < (this->captureEndpointHandlers.size()) && + * this->captureEndpointHandlers.at(i) != nullptr) + * delete captureEndpointHandlers.at(i); + */ - if (i >= this->endpointHandlers.size()) - endpointHandlers.push_back(eph); - else endpointHandlers.at(i) = eph; + EndpointHandler* ephoo = new EndpointHandler(i, Flows::FLOW_CAPTURE); + //this->captureEndpointHandlers.push_back(ephoo); + log_debugcpp("Created Capture handler " + std::to_string(i) + ", adding to vector. " + " VSize: " + std::to_string(this->captureEndpointHandlers.size())); + + /* + * if (i >= this->captureEndpointHandlers.size()) + * captureEndpointHandlers.push_back(eph); + * else captureEndpointHandlers.at(i) = eph; + */ } //setEndpointHandlers(ephs); } +EndpointHandler* OverseerHandler::addEndpoint(std::wstring endpointId){ + Flows flow; + Endpoint* newEp = this->os->addEndpoint(endpointId, &flow); + + uint64_t ephIdx = (flow == Flows::FLOW_PLAYBACK ? this->getPlaybackEndpointsCount() : this->getCaptureEndpointsCount()); + + EndpointHandler* newEph = new EndpointHandler(ephIdx, flow); + // std::vector getPlaybackEndpointHandlers(); + //std::vector getCaptureEndpointHandlers(); + + return newEph; +} + NGuid OverseerHandler::getGuid() { return this->os->getGuid(); } @@ -182,13 +239,20 @@ void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpo void OverseerHandler::reviseEndpointShowing(std::wstring endpointId, EndpointState state) { EndpointHandler* eph = nullptr; - for (auto loopEph : this->endpointHandlers) { + for (auto loopEph : this->playbackEndpointHandlers) { if (loopEph->getId() == endpointId) { eph = loopEph; break; } } + if (!eph) { + + } + + //todo: testing missing shiez. sowwy + //if(!eph) osh-> + if(EndpointState::ENDPOINT_ACTIVE & state) { this->addEndpointWidget(eph); } else if (eph->getFrontVisibilityState() == EndpointState::ENDPOINT_ACTIVE){ @@ -207,5 +271,5 @@ void OverseerHandler::setRemoveEndpointWidgetFunction(std::function ephs){ - this->endpointHandlers = ephs; + this->playbackEndpointHandlers = ephs; } diff --git a/src/cont/contclasses.h b/src/cont/contclasses.h index f071433..b64389d 100644 --- a/src/cont/contclasses.h +++ b/src/cont/contclasses.h @@ -62,7 +62,7 @@ struct BackEndpointVolumeCallbackInfo { class EndpointHandler { public: - EndpointHandler(uint64_t idx); + EndpointHandler(uint64_t idx, Flows flow); void setBackEndpointVolumeCallbackInfoContent(uint8_t state); //these two, currently unused. If I use them, I should feel bad. @@ -84,6 +84,7 @@ public: uint64_t getFrontVisibilityIndex(); EndpointState getFrontVisibilityState(); + Flows getFlow(); float getVolume(int channel); bool getMute(); size_t getState(); @@ -102,7 +103,7 @@ private: uint64_t idx; Endpoint *ep = nullptr; EndpointVolumeCallback *epc = nullptr; - + Flows flow; BackEndpointVolumeCallbackInfo callbackInfo; struct EndpointHandlerFrontVisibility { EndpointState visibility = EndpointState::ENDPOINT_ALL; @@ -125,15 +126,21 @@ public: void setAddEndpointWidgetFunction(std::function addEndpointWidget); void setEndpointHandlers(std::vector ephs); - std::vector getEndpointHandlers(); + std::vector getPlaybackEndpointHandlers(); + std::vector getCaptureEndpointHandlers(); std::vector getPlaybackEndpoints(); + std::vector getCaptureEndpoints(); + void pushBackEndpointHandler(EndpointHandler* eph, Flows flow); uint64_t getPlaybackEndpointsCount(); + uint64_t getCaptureEndpointsCount(); void reloadEndpointHandlers(); + EndpointHandler* addEndpoint(std::wstring endpointId); NGuid getGuid(); private: Overseer *os; - std::vector endpointHandlers; + std::vector playbackEndpointHandlers; + std::vector captureEndpointHandlers; std::function changeFrontDefaults; std::function removeEndpointWidget; std::function addEndpointWidget; diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 8759873..da01a60 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -207,11 +207,12 @@ void MainWindow::customEvent(QEvent* ev) { } void MainWindow::removeEndpointWidget(EndpointWidgetEvent* ev){ - uint64_t i = ev->payload; + uint64_t i = ev->payload; this->ews.at(i)->setParent(nullptr); this->layout->removeWidget(ews.at(i)); uint64_t saisu = ews.size(); //delete ews.at(index); + delete ews.at(i); while ((i + 1) < ews.size()) { ews.at(i) = ews.at(i + 1); ews.at(i)->setIndex(i); @@ -407,11 +408,11 @@ void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) { void MainWindow::reloadEndpointWidgets() { size_t i = 0; - for (size_t epwIndex = 0; i < (osh->getEndpointHandlers().size()); i++) { - if (osh->getEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){ + for (size_t epwIndex = 0; i < (osh->getPlaybackEndpointHandlers().size()); i++) { + if (osh->getPlaybackEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){ log_debugcpp("EPWidget creation"); - //osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid(); - EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getEndpointHandlers().at(i), widget); + //osh->getPlaybackEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid(); + EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getPlaybackEndpointHandlers().at(i), widget); epwIndex++; //alfinal estoes solopara inicializarlmao ews.push_back(epw);