#include "backlasses.h" #include "contclasses.h" void setConfigDirToDefaults() { #define tryFileDir(dir, create) do { \ OverseerHandler::settingsPath = Environment::createSettingsPath(dir, create); \ set = ini::UserSettings::createSettings(OverseerHandler::settingsPath.c_str(), create); \ if(set) { \ return; \ } else OverseerHandler::settingsPath.clear(); \ } while(0) #define tryOpenFileDir(dir) tryFileDir(dir, false) #define tryCreateFileDir(dir) tryFileDir(dir, true) tryOpenFileDir(SettingsTargetDirectory::APP_PATH); tryOpenFileDir(SettingsTargetDirectory::HOME_DIR); tryCreateFileDir(SettingsTargetDirectory::HOME_DIR); tryCreateFileDir(SettingsTargetDirectory::APP_PATH); return; #undef tryOpenFileDir #undef tryCreateFileDir #undef tryFileDir } EndpointHandler::EndpointHandler(uint64_t idx, Flows flow) { //std::vector endpoints = osh->getPlaybackEndpoints().at(idx); this->idx = 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()); osh->pushBackEndpointHandler(this, flow); } void OverseerHandler::pushBackEndpointHandler(EndpointHandler* eph, Flows flow) { if (eph == nullptr) return; if (flow == Flows::FLOW_PLAYBACK) this->playbackEndpointHandlers.push_back(eph); else this->captureEndpointHandlers.push_back(eph); return; } void EndpointHandler::setFrontVisibilityInfo(EndpointState state, uint64_t frontIdx){ ephfv.visibility = state; ephfv.frontIdx = frontIdx; } uint64_t EndpointHandler::getFrontVisibilityIndex(){ return ephfv.frontIdx; } EndpointState EndpointHandler::getFrontVisibilityState(){ return ephfv.visibility; } Flows EndpointHandler::getFlow(){ return ep->getFlow(); } /* these two, currently unused. If I use them, I should feel bad. * Endpoint* EndpointHandler::getEndpoint() { * return this->ep; * } * * EndpointVolumeCallback* EndpointHandler::getEndpointVolumeCallback() { * return this->epc; * } */ BackEndpointVolumeCallbackInfo* EndpointHandler::getCallbackInfo(){ return &this->callbackInfo; } uint32_t EndpointHandler::getChannelCount(){ return ep->getChannelCount(); } void EndpointHandler::setIndex(uint64_t idx){ this->idx = idx; } uint64_t EndpointHandler::getIndex(){ return idx; } /* * -1 for master volume */ void EndpointHandler::setVolume(NGuid guid, int channel, int value){ if (channel == AudioChannel::CHANNEL_MAIN) ep->setVolume(guid, channel, (float)value / 100); else ep->setVolume(guid, channel, (float)value / 100); } void EndpointHandler::setMute(NGuid guid, bool muted){ ep->setMute(guid, muted); } std::wstring EndpointHandler::getName(){ return ep->getName(); } std::wstring EndpointHandler::getId(){ return ep->getId(); } float EndpointHandler::getVolume(int channel){ return ep->getVolume(channel); } bool EndpointHandler::getMute(){ return ep->getMute(); } size_t EndpointHandler::getState(){ return ep->getState(); } void EndpointHandler::setBackEndpointVolumeCallbackInfoContent(uint8_t state) { if(state == EndpointState::ENDPOINT_ACTIVE) { callbackInfo.muted = this->getMute(); callbackInfo.mainVolume = this->getVolume(AudioChannel::CHANNEL_MAIN); callbackInfo.channels = this->getChannelCount(); ep->setVolumeCallback(epc); callbackInfo.channelVolumes.resize(this->callbackInfo.channels); for(uint32_t i = 0; i < this->getChannelCount(); i++){ callbackInfo.channelVolumes.at(i) = this->getVolume(i); } } } void EndpointHandler::setState(uint8_t state){ ep->setState(state); this->setBackEndpointVolumeCallbackInfoContent(state); } void EndpointHandler::setState(uint8_t state, uint64_t index){ ep->setState(state); this->setFrontVisibilityInfo((EndpointState)state, index); this->setBackEndpointVolumeCallbackInfoContent(state); } float EndpointHandler::getPeakVolume() { return ep->getPeakVolume(); } uint8_t EndpointHandler::getRoles(){ return ep->getRoles(); } void EndpointHandler::setRoles(Roles newRole){ ep->setRoles(newRole); } void EndpointHandler::assignRoles(Roles newRole){ ep->assignRoles(newRole); } void EndpointHandler::removeRoles(Roles newRole){ ep->removeRoles(newRole); } void EndpointHandler::setAddSessionWidgetFunction(std::function addSessionWidget) { this->addSessionWidget = addSessionWidget; } void EndpointHandler::setRemoveSessionWidgetFunction(std::function removeSessionWidget) { this->removeSessionWidget = removeSessionWidget; } /* sessions */ size_t EndpointHandler::getSessionCount() { return ep->getSessionCount(); } std::vector EndpointHandler::getSessions(){ return ep->getSessions(); } std::vector EndpointHandler::getSessionHandlers(){ return this->sessionHandlers; } Endpoint* EndpointHandler::getEndpoint() { return this->ep; } void EndpointHandler::addSessionSendFront(Session* session) { ep->addSession(session); SessionHandler* sessionHandler = new SessionHandler(this, session, (getSessionCount() - 1)); sessionHandlers.push_back(sessionHandler); this->addSessionWidget(sessionHandler); } void EndpointHandler::sendSessionToFront(SessionHandler* sh) { this->addSessionWidget(sh); } void EndpointHandler::removeSessionFromFront(SessionHandler* sh) { this->removeSessionWidget(sh); } void EndpointHandler::deleteSessions() { ep->unregisterNewSessionNotification(ensc); ensc->Release(); for (auto sh : sessionHandlers) { delete sh; } sessionHandlers.resize(0); ep->deleteSessions(); } void EndpointHandler::createSessionHandlers() { ep->activateEndpointSessions(); ensc = new EndpointNewSessionCallback(this); ep->registerNewSessionNotification(ensc); if (this->flow == Flows::FLOW_PLAYBACK) { for (int i = 0; i < this->getSessionCount(); i++) { SessionHandler* sessionHandler = new SessionHandler(this, this->getSessions().at(i),i); sessionHandlers.push_back(sessionHandler); } } } EndpointHandler::~EndpointHandler() { ep->removeVolumeCallback(epc); ep->unregisterNewSessionNotification(ensc); epc->Release(); delete ep; } OverseerHandler::OverseerHandler() { this->os = new Overseer(); } void OverseerHandler::setSettingsPath(std::string path) { OverseerHandler::settingsPath = path; } std::string OverseerHandler::getSettingsPath(){ return OverseerHandler::settingsPath; } void OverseerHandler::updateStartupConfig(bool onStartup) { Environment::updateStartupConfig(onStartup); } void OverseerHandler::setStartupConfig(bool onStartup) { Environment::setStartupConfig(onStartup); } void OverseerHandler::populateSystemValues() { Environment::populateSystemValues(); } void OverseerHandler::openControlPanel() { Environment::openControlPanel(); } ProcessedNativeEvent OverseerHandler::processTopLevelWindowMessage(void* msg) { return Environment::processTopLevelWindowMessage(msg); } bool OverseerHandler::isLightMode() { return Environment::isLightMode(); } bool OverseerHandler::isToRunAtStartup() { return Environment::isToRunAtStartup(); } uint32_t OverseerHandler::getAccentColor() { return Environment::getAccentColor(); } std::vector OverseerHandler::getPlaybackEndpoints() { return this->os->getPlaybackEndpoints(); } 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("Playback VSize: " + std::to_string(this->getPlaybackEndpointsCount())); for(uint64_t i = 0; i < this->getPlaybackEndpointsCount(); 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())); } 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)); /* * if(i < (this->captureEndpointHandlers.size()) && * this->captureEndpointHandlers.at(i) != nullptr) * delete captureEndpointHandlers.at(i); */ 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, /* out */ Flows *flow = nullptr){ Flows localFlow; Endpoint* newEp = this->os->addEndpoint(endpointId, &localFlow); uint64_t ephIdx = (localFlow == Flows::FLOW_PLAYBACK ? this->getPlaybackEndpointsCount() : this->getCaptureEndpointsCount()) - 1; EndpointHandler* newEph = new EndpointHandler(ephIdx, localFlow); // std::vector getPlaybackEndpointHandlers(); //std::vector getCaptureEndpointHandlers(); if (flow != nullptr) *flow = localFlow; return newEph; } NGuid OverseerHandler::getGuid() { return this->os->getGuid(); } /* * void OverseerHandler::setChangeFrontDefaultsFunction(std::function changeFrontDefaults){ * this->changeFrontDefaults = changeFrontDefaults; * } * * void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpointId) { * this->changeFrontDefaults(role, endpointId); * } */ void OverseerHandler::roleBucketEntryCallback(Roles role, std::wstring endpointId){ this->roleBucketEntry(role, endpointId); } void OverseerHandler::setRoleBucketEntryFunction(std::function roleBucketEntry) { this->roleBucketEntry = roleBucketEntry; } 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()); allHandlers.insert(allHandlers.end(), this->playbackEndpointHandlers.begin(), this->playbackEndpointHandlers.end()); EndpointHandler* eph = nullptr; for (auto loopEph : allHandlers) { if (loopEph->getId() == endpointId) { eph = loopEph; break; } } //debug Flows flow; if (!eph) { if (state ^ EndpointState::ENDPOINT_ACTIVE) return; //flow = Flows::FLOW_CAPTURE; eph = osh->addEndpoint(endpointId, &flow); } else flow = eph->getFlow(); //todo: mic done but disabled. Tab-kun will come... if (flow == Flows::FLOW_CAPTURE) return; if(eph && EndpointState::ENDPOINT_ACTIVE & state) { this->addEndpointWidget(eph); } else if (eph && eph->getFrontVisibilityState() == EndpointState::ENDPOINT_ACTIVE){ this->removeEndpointWidget(eph->getFrontVisibilityIndex()); } return; } void OverseerHandler::setAddEndpointWidgetFunction(std::function addEndpointWidget){ this->addEndpointWidget = addEndpointWidget; } void OverseerHandler::setRemoveEndpointWidgetFunction(std::function removeEndpointWidget){ this->removeEndpointWidget = removeEndpointWidget; } void OverseerHandler::setEndpointHandlers(std::vector ephs){ this->playbackEndpointHandlers = ephs; }