Skip to content

Commit

Permalink
Codestyle fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitozz committed Jan 23, 2019
1 parent 5d2f4ab commit 0e8407f
Show file tree
Hide file tree
Showing 25 changed files with 2,496 additions and 2,505 deletions.
660 changes: 330 additions & 330 deletions alsawork/alsadevice.cpp

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions alsawork/alsadevice.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* alsadevice.h
* Copyright (C) 2014-2015 Vitaly Tonkacheyev
* Copyright (C) 2014-2019 Vitaly Tonkacheyev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,49 +30,49 @@
class AlsaDevice
{
public:
AlsaDevice(int id, const std::string &card);
~AlsaDevice();
AlsaDevice(AlsaDevice const &);
typedef std::shared_ptr<AlsaDevice> Ptr;
const std::string &name() const;
int id() const;
const std::vector<std::string> &mixers() const;
MixerSwitches::Ptr switches();
const std::string &currentMixer() const;
int currentMixerId() const;
bool havePlaybackMixers();
bool haveCaptureMixers();
bool haveMixers();
double getVolume();
bool getMute();
void setDeviceVolume(double volume);
void setCurrentMixer(int id);
void setCurrentMixer(const std::string &mixer);
void setSwitch(const std::string &mixer, int id, bool enabled);
void setMute(bool enabled);
static std::string formatCardName(long long int id);
AlsaDevice(int id, const std::string &card);
~AlsaDevice();
AlsaDevice(AlsaDevice const &);
typedef std::shared_ptr<AlsaDevice> Ptr;
const std::string &name() const;
int id() const;
const std::vector<std::string> &mixers() const;
MixerSwitches::Ptr switches();
const std::string &currentMixer() const;
int currentMixerId() const;
bool havePlaybackMixers();
bool haveCaptureMixers();
bool haveMixers();
double getVolume();
bool getMute();
void setDeviceVolume(double volume);
void setCurrentMixer(int id);
void setCurrentMixer(const std::string &mixer);
void setSwitch(const std::string &mixer, int id, bool enabled);
void setMute(bool enabled);
static std::string formatCardName(long long int id);

private:
snd_mixer_t *getMixerHanlde(int id);
snd_mixer_selem_channel_id_t checkMixerChannels(snd_mixer_elem_t *element);
snd_mixer_elem_t *initMixerElement(snd_mixer_t *handle, const char *mixer);
void checkError (int errorIndex);
void initMixerList();
double getNormVolume(snd_mixer_elem_t *element);
double getExp10(double value);
bool useLinearDb(long min, long max);
void setNormVolume(snd_mixer_elem_t *element, double volume);
void updateElements();
snd_mixer_t *getMixerHanlde(int id);
snd_mixer_selem_channel_id_t checkMixerChannels(snd_mixer_elem_t *element);
snd_mixer_elem_t *initMixerElement(snd_mixer_t *handle, const char *mixer);
void checkError (int errorIndex);
void initMixerList();
double getNormVolume(snd_mixer_elem_t *element);
double getExp10(double value);
bool useLinearDb(long min, long max);
void setNormVolume(snd_mixer_elem_t *element, double volume);
void updateElements();

private:
int id_;
std::string name_;
std::vector<std::string> volumeMixers_;
std::vector<std::string> captureMixers_;
std::vector<std::string> mixers_;
MixerSwitches::Ptr switches_;
int currentMixerId_;
std::string currentMixerName_;
int id_;
std::string name_;
std::vector<std::string> volumeMixers_;
std::vector<std::string> captureMixers_;
std::vector<std::string> mixers_;
MixerSwitches::Ptr switches_;
int currentMixerId_;
std::string currentMixerName_;

};

Expand Down
180 changes: 90 additions & 90 deletions alsawork/alsawork.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* alsawork.cpp
* Copyright (C) 2012-2015 Vitaly Tonkacheyev
* Copyright (C) 2012-2019 Vitaly Tonkacheyev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -22,196 +22,196 @@
#include <stdexcept>

AlsaWork::AlsaWork()
: cardList_(std::vector<std::string>())
: cardList_(std::vector<std::string>())
{
getCards();
int id = 0;
std::for_each(cardList_.begin(), cardList_.end(), [&](const std::string &name){
devices_.push_back(AlsaDevice::Ptr(new AlsaDevice(id, name)));
++id;
});
setCurrentCard(0);
setCurrentMixer(0);
getCards();
int id = 0;
for(const std::string &name : cardList_){
devices_.push_back(AlsaDevice::Ptr(new AlsaDevice(id, name)));
++id;
}
setCurrentCard(0);
setCurrentMixer(0);
}

AlsaWork::~AlsaWork()
{
if (!devices_.empty())
devices_.clear();
currentAlsaDevice_.reset();
snd_config_update_free_global();
if (!devices_.empty())
devices_.clear();
currentAlsaDevice_.reset();
snd_config_update_free_global();
}

//public
void AlsaWork::setCurrentCard(int cardId)
{
if(cardId < int(devices_.size())) {
currentAlsaDevice_ = devices_.at(cardId);
}
if(cardId < int(devices_.size())) {
currentAlsaDevice_ = devices_.at(cardId);
}
}

void AlsaWork::setCurrentMixer(const std::string &mixer)
{
currentAlsaDevice_->setCurrentMixer(mixer);
currentAlsaDevice_->setCurrentMixer(mixer);
}

void AlsaWork::setCurrentMixer(int id)
{
currentAlsaDevice_->setCurrentMixer(id);
currentAlsaDevice_->setCurrentMixer(id);
}

void AlsaWork::setAlsaVolume(double volume)
{
currentAlsaDevice_->setDeviceVolume(volume);
currentAlsaDevice_->setDeviceVolume(volume);
}

double AlsaWork::getAlsaVolume() const
{
return currentAlsaDevice_->getVolume();
return currentAlsaDevice_->getVolume();
}

const std::string AlsaWork::getCardName(int index)
{
const std::string card(AlsaDevice::formatCardName(index));
snd_ctl_t *ctl;
int err = snd_ctl_open(&ctl, card.c_str(), SND_CTL_NONBLOCK);
if (err < 0) {
checkError(err);
return std::string();
}
snd_ctl_card_info_t *cardInfo;
snd_ctl_card_info_alloca(&cardInfo);
err = snd_ctl_card_info(ctl, cardInfo);
if (err < 0) {
checkError(err);
return std::string();
}
const std::string cardName = snd_ctl_card_info_get_name(cardInfo);
checkError(snd_ctl_close(ctl));
return cardName;
const std::string card(AlsaDevice::formatCardName(index));
snd_ctl_t *ctl;
int err = snd_ctl_open(&ctl, card.c_str(), SND_CTL_NONBLOCK);
if (err < 0) {
checkError(err);
return std::string();
}
snd_ctl_card_info_t *cardInfo;
snd_ctl_card_info_alloca(&cardInfo);
err = snd_ctl_card_info(ctl, cardInfo);
if (err < 0) {
checkError(err);
return std::string();
}
const std::string cardName = snd_ctl_card_info_get_name(cardInfo);
checkError(snd_ctl_close(ctl));
return cardName;
}

const std::string AlsaWork::getMixerName(int index)
{
std::string mixerName;
if (index >= 0 && index < currentAlsaDevice_->mixers().size()) {
mixerName = currentAlsaDevice_->mixers().at(index);
}
return mixerName;
std::string mixerName;
if (index >= 0 && index < currentAlsaDevice_->mixers().size()) {
mixerName = currentAlsaDevice_->mixers().at(index);
}
return mixerName;
}

std::string AlsaWork::getCurrentMixerName() const
{
return currentAlsaDevice_->currentMixer();
return currentAlsaDevice_->currentMixer();
}

const std::vector<std::string> &AlsaWork::getCardsList() const
{
return cardList_;
return cardList_;
}

const std::vector<std::string> &AlsaWork::getVolumeMixers() const
{
return currentAlsaDevice_->mixers();
return currentAlsaDevice_->mixers();
}

MixerSwitches::Ptr AlsaWork::getSwitchList() const
{
return currentAlsaDevice_->switches();
return currentAlsaDevice_->switches();
}

void AlsaWork::setMute(bool enabled)
{
currentAlsaDevice_->setMute(enabled);
currentAlsaDevice_->setMute(enabled);
}

bool AlsaWork::getMute()
{
return currentAlsaDevice_->getMute();
return currentAlsaDevice_->getMute();
}

void AlsaWork::setSwitch(const std::string &mixer, int id, bool enabled)
{
currentAlsaDevice_->setSwitch(mixer, id, enabled);
currentAlsaDevice_->setSwitch(mixer, id, enabled);
}

bool AlsaWork::checkCardId(int cardId)
{
try {
if (cardId < int(cardList_.size()) && !cardList_.at(cardId).empty()) {
return true;
}
}
catch (std::out_of_range &ex) {
std::cerr << "alsawork.cpp::145:: Item out of Range " << ex.what() << std::endl;
}
return false;
try {
if (cardId < int(cardList_.size()) && !cardList_.at(cardId).empty()) {
return true;
}
}
catch (std::out_of_range &ex) {
std::cerr << "alsawork.cpp::145:: Item out of Range " << ex.what() << std::endl;
}
return false;
}

//private
void AlsaWork::checkError (int errorIndex)
{
if (errorIndex < 0) {
std::cerr << snd_strerror(errorIndex) << std::endl;
}
if (errorIndex < 0) {
std::cerr << snd_strerror(errorIndex) << std::endl;
}
}

int AlsaWork::getTotalCards()
{
int cards = 0;
int index = -1;
while (true) {
checkError(snd_card_next(&index));
if (index < 0) {
break;
}
++cards;
}
return cards;
int cards = 0;
int index = -1;
while (true) {
checkError(snd_card_next(&index));
if (index < 0) {
break;
}
++cards;
}
return cards;
}

void AlsaWork::getCards()
{
if (!cardList_.empty())
cardList_.clear();
totalCards_ = getTotalCards();
if (totalCards_ >= 1) {
for (int card = 0; card < totalCards_; card++) {
const std::string cname(getCardName(card));
cardList_.push_back(cname);
}
}
if (!cardList_.empty())
cardList_.clear();
totalCards_ = getTotalCards();
if (totalCards_ >= 1) {
for (int card = 0; card < totalCards_; card++) {
const std::string cname(getCardName(card));
cardList_.push_back(cname);
}
}
}

bool AlsaWork::haveVolumeMixers()
{
return currentAlsaDevice_->haveMixers();
return currentAlsaDevice_->haveMixers();
}

bool AlsaWork::cardExists(int id)
{
return bool(id >= 0 && id < totalCards_);
return bool(id >= 0 && id < totalCards_);
}

bool AlsaWork::mixerExists(const std::string &name)
{
return Tools::itemExists(currentAlsaDevice_->mixers(), name);
return Tools::itemExists(currentAlsaDevice_->mixers(), name);
}

bool AlsaWork::mixerExists(int id)
{
return bool(id >=0 && id < (int)currentAlsaDevice_->mixers().size());
return bool(id >=0 && id < (int)currentAlsaDevice_->mixers().size());
}

int AlsaWork::getFirstCardWithMixers()
{
AlsaDevicePtrList::iterator it = std::find_if(devices_.begin(),
devices_.end(),
[](const AlsaDevice::Ptr &dev){return dev->haveMixers();});
return (it != devices_.end()) ? it - devices_.begin() : 0;
auto it = std::find_if(devices_.begin(),
devices_.end(),
[](const AlsaDevice::Ptr &dev){return dev->haveMixers();});
return (it != devices_.end()) ? it - devices_.begin() : 0;
}

int AlsaWork::getCurrentMixerId() const
{
return currentAlsaDevice_->currentMixerId();
return currentAlsaDevice_->currentMixerId();
}
Loading

0 comments on commit 0e8407f

Please sign in to comment.