Skip to content

Commit 0e8407f

Browse files
committed
Codestyle fixed
1 parent 5d2f4ab commit 0e8407f

25 files changed

+2496
-2505
lines changed

alsawork/alsadevice.cpp

+330-330
Large diffs are not rendered by default.

alsawork/alsadevice.h

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* alsadevice.h
3-
* Copyright (C) 2014-2015 Vitaly Tonkacheyev
3+
* Copyright (C) 2014-2019 Vitaly Tonkacheyev
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -30,49 +30,49 @@
3030
class AlsaDevice
3131
{
3232
public:
33-
AlsaDevice(int id, const std::string &card);
34-
~AlsaDevice();
35-
AlsaDevice(AlsaDevice const &);
36-
typedef std::shared_ptr<AlsaDevice> Ptr;
37-
const std::string &name() const;
38-
int id() const;
39-
const std::vector<std::string> &mixers() const;
40-
MixerSwitches::Ptr switches();
41-
const std::string &currentMixer() const;
42-
int currentMixerId() const;
43-
bool havePlaybackMixers();
44-
bool haveCaptureMixers();
45-
bool haveMixers();
46-
double getVolume();
47-
bool getMute();
48-
void setDeviceVolume(double volume);
49-
void setCurrentMixer(int id);
50-
void setCurrentMixer(const std::string &mixer);
51-
void setSwitch(const std::string &mixer, int id, bool enabled);
52-
void setMute(bool enabled);
53-
static std::string formatCardName(long long int id);
33+
AlsaDevice(int id, const std::string &card);
34+
~AlsaDevice();
35+
AlsaDevice(AlsaDevice const &);
36+
typedef std::shared_ptr<AlsaDevice> Ptr;
37+
const std::string &name() const;
38+
int id() const;
39+
const std::vector<std::string> &mixers() const;
40+
MixerSwitches::Ptr switches();
41+
const std::string &currentMixer() const;
42+
int currentMixerId() const;
43+
bool havePlaybackMixers();
44+
bool haveCaptureMixers();
45+
bool haveMixers();
46+
double getVolume();
47+
bool getMute();
48+
void setDeviceVolume(double volume);
49+
void setCurrentMixer(int id);
50+
void setCurrentMixer(const std::string &mixer);
51+
void setSwitch(const std::string &mixer, int id, bool enabled);
52+
void setMute(bool enabled);
53+
static std::string formatCardName(long long int id);
5454

5555
private:
56-
snd_mixer_t *getMixerHanlde(int id);
57-
snd_mixer_selem_channel_id_t checkMixerChannels(snd_mixer_elem_t *element);
58-
snd_mixer_elem_t *initMixerElement(snd_mixer_t *handle, const char *mixer);
59-
void checkError (int errorIndex);
60-
void initMixerList();
61-
double getNormVolume(snd_mixer_elem_t *element);
62-
double getExp10(double value);
63-
bool useLinearDb(long min, long max);
64-
void setNormVolume(snd_mixer_elem_t *element, double volume);
65-
void updateElements();
56+
snd_mixer_t *getMixerHanlde(int id);
57+
snd_mixer_selem_channel_id_t checkMixerChannels(snd_mixer_elem_t *element);
58+
snd_mixer_elem_t *initMixerElement(snd_mixer_t *handle, const char *mixer);
59+
void checkError (int errorIndex);
60+
void initMixerList();
61+
double getNormVolume(snd_mixer_elem_t *element);
62+
double getExp10(double value);
63+
bool useLinearDb(long min, long max);
64+
void setNormVolume(snd_mixer_elem_t *element, double volume);
65+
void updateElements();
6666

6767
private:
68-
int id_;
69-
std::string name_;
70-
std::vector<std::string> volumeMixers_;
71-
std::vector<std::string> captureMixers_;
72-
std::vector<std::string> mixers_;
73-
MixerSwitches::Ptr switches_;
74-
int currentMixerId_;
75-
std::string currentMixerName_;
68+
int id_;
69+
std::string name_;
70+
std::vector<std::string> volumeMixers_;
71+
std::vector<std::string> captureMixers_;
72+
std::vector<std::string> mixers_;
73+
MixerSwitches::Ptr switches_;
74+
int currentMixerId_;
75+
std::string currentMixerName_;
7676

7777
};
7878

alsawork/alsawork.cpp

+90-90
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* alsawork.cpp
3-
* Copyright (C) 2012-2015 Vitaly Tonkacheyev
3+
* Copyright (C) 2012-2019 Vitaly Tonkacheyev
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -22,196 +22,196 @@
2222
#include <stdexcept>
2323

2424
AlsaWork::AlsaWork()
25-
: cardList_(std::vector<std::string>())
25+
: cardList_(std::vector<std::string>())
2626
{
27-
getCards();
28-
int id = 0;
29-
std::for_each(cardList_.begin(), cardList_.end(), [&](const std::string &name){
30-
devices_.push_back(AlsaDevice::Ptr(new AlsaDevice(id, name)));
31-
++id;
32-
});
33-
setCurrentCard(0);
34-
setCurrentMixer(0);
27+
getCards();
28+
int id = 0;
29+
for(const std::string &name : cardList_){
30+
devices_.push_back(AlsaDevice::Ptr(new AlsaDevice(id, name)));
31+
++id;
32+
}
33+
setCurrentCard(0);
34+
setCurrentMixer(0);
3535
}
3636

3737
AlsaWork::~AlsaWork()
3838
{
39-
if (!devices_.empty())
40-
devices_.clear();
41-
currentAlsaDevice_.reset();
42-
snd_config_update_free_global();
39+
if (!devices_.empty())
40+
devices_.clear();
41+
currentAlsaDevice_.reset();
42+
snd_config_update_free_global();
4343
}
4444

4545
//public
4646
void AlsaWork::setCurrentCard(int cardId)
4747
{
48-
if(cardId < int(devices_.size())) {
49-
currentAlsaDevice_ = devices_.at(cardId);
50-
}
48+
if(cardId < int(devices_.size())) {
49+
currentAlsaDevice_ = devices_.at(cardId);
50+
}
5151
}
5252

5353
void AlsaWork::setCurrentMixer(const std::string &mixer)
5454
{
55-
currentAlsaDevice_->setCurrentMixer(mixer);
55+
currentAlsaDevice_->setCurrentMixer(mixer);
5656
}
5757

5858
void AlsaWork::setCurrentMixer(int id)
5959
{
60-
currentAlsaDevice_->setCurrentMixer(id);
60+
currentAlsaDevice_->setCurrentMixer(id);
6161
}
6262

6363
void AlsaWork::setAlsaVolume(double volume)
6464
{
65-
currentAlsaDevice_->setDeviceVolume(volume);
65+
currentAlsaDevice_->setDeviceVolume(volume);
6666
}
6767

6868
double AlsaWork::getAlsaVolume() const
6969
{
70-
return currentAlsaDevice_->getVolume();
70+
return currentAlsaDevice_->getVolume();
7171
}
7272

7373
const std::string AlsaWork::getCardName(int index)
7474
{
75-
const std::string card(AlsaDevice::formatCardName(index));
76-
snd_ctl_t *ctl;
77-
int err = snd_ctl_open(&ctl, card.c_str(), SND_CTL_NONBLOCK);
78-
if (err < 0) {
79-
checkError(err);
80-
return std::string();
81-
}
82-
snd_ctl_card_info_t *cardInfo;
83-
snd_ctl_card_info_alloca(&cardInfo);
84-
err = snd_ctl_card_info(ctl, cardInfo);
85-
if (err < 0) {
86-
checkError(err);
87-
return std::string();
88-
}
89-
const std::string cardName = snd_ctl_card_info_get_name(cardInfo);
90-
checkError(snd_ctl_close(ctl));
91-
return cardName;
75+
const std::string card(AlsaDevice::formatCardName(index));
76+
snd_ctl_t *ctl;
77+
int err = snd_ctl_open(&ctl, card.c_str(), SND_CTL_NONBLOCK);
78+
if (err < 0) {
79+
checkError(err);
80+
return std::string();
81+
}
82+
snd_ctl_card_info_t *cardInfo;
83+
snd_ctl_card_info_alloca(&cardInfo);
84+
err = snd_ctl_card_info(ctl, cardInfo);
85+
if (err < 0) {
86+
checkError(err);
87+
return std::string();
88+
}
89+
const std::string cardName = snd_ctl_card_info_get_name(cardInfo);
90+
checkError(snd_ctl_close(ctl));
91+
return cardName;
9292
}
9393

9494
const std::string AlsaWork::getMixerName(int index)
9595
{
96-
std::string mixerName;
97-
if (index >= 0 && index < currentAlsaDevice_->mixers().size()) {
98-
mixerName = currentAlsaDevice_->mixers().at(index);
99-
}
100-
return mixerName;
96+
std::string mixerName;
97+
if (index >= 0 && index < currentAlsaDevice_->mixers().size()) {
98+
mixerName = currentAlsaDevice_->mixers().at(index);
99+
}
100+
return mixerName;
101101
}
102102

103103
std::string AlsaWork::getCurrentMixerName() const
104104
{
105-
return currentAlsaDevice_->currentMixer();
105+
return currentAlsaDevice_->currentMixer();
106106
}
107107

108108
const std::vector<std::string> &AlsaWork::getCardsList() const
109109
{
110-
return cardList_;
110+
return cardList_;
111111
}
112112

113113
const std::vector<std::string> &AlsaWork::getVolumeMixers() const
114114
{
115-
return currentAlsaDevice_->mixers();
115+
return currentAlsaDevice_->mixers();
116116
}
117117

118118
MixerSwitches::Ptr AlsaWork::getSwitchList() const
119119
{
120-
return currentAlsaDevice_->switches();
120+
return currentAlsaDevice_->switches();
121121
}
122122

123123
void AlsaWork::setMute(bool enabled)
124124
{
125-
currentAlsaDevice_->setMute(enabled);
125+
currentAlsaDevice_->setMute(enabled);
126126
}
127127

128128
bool AlsaWork::getMute()
129129
{
130-
return currentAlsaDevice_->getMute();
130+
return currentAlsaDevice_->getMute();
131131
}
132132

133133
void AlsaWork::setSwitch(const std::string &mixer, int id, bool enabled)
134134
{
135-
currentAlsaDevice_->setSwitch(mixer, id, enabled);
135+
currentAlsaDevice_->setSwitch(mixer, id, enabled);
136136
}
137137

138138
bool AlsaWork::checkCardId(int cardId)
139139
{
140-
try {
141-
if (cardId < int(cardList_.size()) && !cardList_.at(cardId).empty()) {
142-
return true;
143-
}
144-
}
145-
catch (std::out_of_range &ex) {
146-
std::cerr << "alsawork.cpp::145:: Item out of Range " << ex.what() << std::endl;
147-
}
148-
return false;
140+
try {
141+
if (cardId < int(cardList_.size()) && !cardList_.at(cardId).empty()) {
142+
return true;
143+
}
144+
}
145+
catch (std::out_of_range &ex) {
146+
std::cerr << "alsawork.cpp::145:: Item out of Range " << ex.what() << std::endl;
147+
}
148+
return false;
149149
}
150150

151151
//private
152152
void AlsaWork::checkError (int errorIndex)
153153
{
154-
if (errorIndex < 0) {
155-
std::cerr << snd_strerror(errorIndex) << std::endl;
156-
}
154+
if (errorIndex < 0) {
155+
std::cerr << snd_strerror(errorIndex) << std::endl;
156+
}
157157
}
158158

159159
int AlsaWork::getTotalCards()
160160
{
161-
int cards = 0;
162-
int index = -1;
163-
while (true) {
164-
checkError(snd_card_next(&index));
165-
if (index < 0) {
166-
break;
167-
}
168-
++cards;
169-
}
170-
return cards;
161+
int cards = 0;
162+
int index = -1;
163+
while (true) {
164+
checkError(snd_card_next(&index));
165+
if (index < 0) {
166+
break;
167+
}
168+
++cards;
169+
}
170+
return cards;
171171
}
172172

173173
void AlsaWork::getCards()
174174
{
175-
if (!cardList_.empty())
176-
cardList_.clear();
177-
totalCards_ = getTotalCards();
178-
if (totalCards_ >= 1) {
179-
for (int card = 0; card < totalCards_; card++) {
180-
const std::string cname(getCardName(card));
181-
cardList_.push_back(cname);
182-
}
183-
}
175+
if (!cardList_.empty())
176+
cardList_.clear();
177+
totalCards_ = getTotalCards();
178+
if (totalCards_ >= 1) {
179+
for (int card = 0; card < totalCards_; card++) {
180+
const std::string cname(getCardName(card));
181+
cardList_.push_back(cname);
182+
}
183+
}
184184
}
185185

186186
bool AlsaWork::haveVolumeMixers()
187187
{
188-
return currentAlsaDevice_->haveMixers();
188+
return currentAlsaDevice_->haveMixers();
189189
}
190190

191191
bool AlsaWork::cardExists(int id)
192192
{
193-
return bool(id >= 0 && id < totalCards_);
193+
return bool(id >= 0 && id < totalCards_);
194194
}
195195

196196
bool AlsaWork::mixerExists(const std::string &name)
197197
{
198-
return Tools::itemExists(currentAlsaDevice_->mixers(), name);
198+
return Tools::itemExists(currentAlsaDevice_->mixers(), name);
199199
}
200200

201201
bool AlsaWork::mixerExists(int id)
202202
{
203-
return bool(id >=0 && id < (int)currentAlsaDevice_->mixers().size());
203+
return bool(id >=0 && id < (int)currentAlsaDevice_->mixers().size());
204204
}
205205

206206
int AlsaWork::getFirstCardWithMixers()
207207
{
208-
AlsaDevicePtrList::iterator it = std::find_if(devices_.begin(),
209-
devices_.end(),
210-
[](const AlsaDevice::Ptr &dev){return dev->haveMixers();});
211-
return (it != devices_.end()) ? it - devices_.begin() : 0;
208+
auto it = std::find_if(devices_.begin(),
209+
devices_.end(),
210+
[](const AlsaDevice::Ptr &dev){return dev->haveMixers();});
211+
return (it != devices_.end()) ? it - devices_.begin() : 0;
212212
}
213213

214214
int AlsaWork::getCurrentMixerId() const
215215
{
216-
return currentAlsaDevice_->currentMixerId();
216+
return currentAlsaDevice_->currentMixerId();
217217
}

0 commit comments

Comments
 (0)