197 lines
5.1 KiB
C++
197 lines
5.1 KiB
C++
#include "backlasses.h"
|
|
#include "contclasses.h"
|
|
//TODO: pragma once
|
|
|
|
EndpointHandler::EndpointHandler(uint64_t idx) {
|
|
//std::vector<Endpoint*> endpoints = osh->getPlaybackEndpoints().at(idx);
|
|
this->ep = osh->getPlaybackEndpoints().at(idx);
|
|
epc = new EndpointVolumeCallback(ep);
|
|
//epName = ep->getName();
|
|
if (this->ep->getState() == 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[i] = this->getVolume(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/* 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::setState(uint8_t state){
|
|
ep->setState(state);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
EndpointHandler::~EndpointHandler() {
|
|
ep->removeVolumeCallback(epc);
|
|
epc->Release();
|
|
delete ep;
|
|
}
|
|
|
|
OverseerHandler::OverseerHandler() {
|
|
this->os = new Overseer();
|
|
}
|
|
|
|
std::vector<Endpoint*> OverseerHandler::getPlaybackEndpoints() {
|
|
return this->os->getPlaybackEndpoints();
|
|
}
|
|
|
|
|
|
std::vector<EndpointHandler*> OverseerHandler::getEndpointHandlers(){
|
|
return endpointHandlers;
|
|
}
|
|
|
|
uint64_t OverseerHandler::getPlaybackEndpointsCount(){
|
|
return this->os->getPlaybackEndpoints().size();
|
|
}
|
|
|
|
void OverseerHandler::reloadEndpointHandlers(){
|
|
//std::vector<EndpointHandler*>* ephs = new std::vector<EndpointHandler*>;
|
|
log_debugcpp(" VSize: " + std::to_string(this->getPlaybackEndpointsCount()));
|
|
|
|
for(uint64_t i = 0; i < this->getPlaybackEndpointsCount(); i++){
|
|
log_debugcpp("Creating handler " + std::to_string(i));
|
|
|
|
if(i < (this->endpointHandlers.size()) &&
|
|
this->endpointHandlers.at(i) != nullptr)
|
|
delete endpointHandlers.at(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->endpointHandlers.size())
|
|
endpointHandlers.push_back(eph);
|
|
else endpointHandlers.at(i) = eph;
|
|
}
|
|
//setEndpointHandlers(ephs);
|
|
}
|
|
|
|
NGuid OverseerHandler::getGuid() {
|
|
return this->os->getGuid();
|
|
}
|
|
|
|
void OverseerHandler::setChangeFrontDefaultsFunction(std::function<void(Roles, std::wstring)> changeFrontDefaults){
|
|
this->changeFrontDefaults = changeFrontDefaults;
|
|
}
|
|
|
|
void OverseerHandler::changeFrontDefaultsCallback(Roles role, std::wstring endpointId) {
|
|
this->changeFrontDefaults(role, endpointId);
|
|
}
|
|
|
|
void OverseerHandler::reviseEndpointShowing(std::wstring endpointId, EndpointState state) {
|
|
EndpointHandler* affected = nullptr;
|
|
for (auto eph : this->endpointHandlers) {
|
|
if (eph->getId() == endpointId) {
|
|
affected = eph;
|
|
break;
|
|
}
|
|
}
|
|
//todo:
|
|
if(EndpointState::ENDPOINT_ACTIVE & state) {
|
|
//todo:
|
|
return;
|
|
} else if (affected->getFrontVisibilityState() == EndpointState::ENDPOINT_ACTIVE){
|
|
this->removeEndpointWidget(affected->getFrontVisibilityIndex());
|
|
affected->setFrontVisibilityInfo(EndpointState::ENDPOINT_ALL, INT_MAX);
|
|
}
|
|
return;
|
|
//this->reviseEndpointShowing(endpointId, role);
|
|
}
|
|
|
|
void OverseerHandler::setRemoveEndpointWidgetFunction(std::function<void(uint64_t)> removeEndpointWidget){
|
|
this->removeEndpointWidget = removeEndpointWidget;
|
|
}
|
|
|
|
|
|
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){
|
|
this->endpointHandlers = ephs;
|
|
}
|