mixer/src/cont/contclasses.cpp
2023-09-01 19:30:04 +02:00

131 lines
3.3 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();
ep->setVolumeCallback(epc);
callbackInfo.muted = this->getMute();
callbackInfo.mainVolume = this->getVolume(AudioChannel::CHANNEL_MAIN);
callbackInfo.channels = this->getChannelCount();
callbackInfo.channelVolumes.resize(this->callbackInfo.channels);
for(uint32_t i = 0; i < this->getChannelCount(); i++){
callbackInfo.channelVolumes[i] = this->getVolume(i);
}
}
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();
}
float EndpointHandler::getVolume(int channel){
return ep->getVolume(channel);
}
bool EndpointHandler::getMute(){
return ep->getMute();
}
uint8_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);
}
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: " << this->getPlaybackEndpointsCount());
for(uint64_t i = 0; i < this->getPlaybackEndpointsCount(); i++){
log_debugcpp("Creating handler " << i);
if(i < (this->endpointHandlers.size()) &&
this->endpointHandlers.at(i) != nullptr)
delete endpointHandlers.at(i);
EndpointHandler* eph = new EndpointHandler(i);
log_debugcpp("Created handler " << i << ", adding to vector. " << " VSize: " << 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 setChangeFrontDefaultsFunction(std::function<void(Roles, wchar* endpointId)> changeFrontDefaults){
this->changeFrontDefaults = changeFrontDefaults;
}
void OverseerHandler::setEndpointHandlers(std::vector<EndpointHandler*> ephs){
this->endpointHandlers = ephs;
}