1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-03 04:33:30 -05:00

Update the mixer class to support setting the name of the soundcard we want to get the mixer of

This commit is contained in:
Alexander Polynomdivision 2017-01-14 17:18:17 +01:00 committed by Michael Carlberg
parent 497221b1ab
commit 22e255747a
2 changed files with 12 additions and 3 deletions

View file

@ -18,13 +18,14 @@ POLYBAR_NS
namespace alsa { namespace alsa {
class mixer { class mixer {
public: public:
explicit mixer(string&& mixer_selem_name); explicit mixer(string&& mixer_selem_name, string&& sound_card_name);
~mixer(); ~mixer();
mixer(const mixer& o) = delete; mixer(const mixer& o) = delete;
mixer& operator=(const mixer& o) = delete; mixer& operator=(const mixer& o) = delete;
const string& get_name(); const string& get_name();
const string& get_sound_card();
bool wait(int timeout = -1); bool wait(int timeout = -1);
int process_events(); int process_events();
@ -42,6 +43,7 @@ namespace alsa {
snd_mixer_elem_t* m_elem{nullptr}; snd_mixer_elem_t* m_elem{nullptr};
string m_name; string m_name;
string s_name;
}; };
} }

View file

@ -12,7 +12,7 @@ namespace alsa {
/** /**
* Construct mixer object * Construct mixer object
*/ */
mixer::mixer(string&& mixer_selem_name) : m_name(forward<string>(mixer_selem_name)) { mixer::mixer(string&& mixer_selem_name, string&& soundcard_name) : m_name(forward<string>(mixer_selem_name)), s_name(soundcard_name) {
int err = 0; int err = 0;
if ((err = snd_mixer_open(&m_mixer, 1)) == -1) { if ((err = snd_mixer_open(&m_mixer, 1)) == -1) {
@ -21,7 +21,7 @@ namespace alsa {
snd_config_update_free_global(); snd_config_update_free_global();
if ((err = snd_mixer_attach(m_mixer, ALSA_SOUNDCARD)) == -1) { if ((err = snd_mixer_attach(m_mixer, s_name.c_str())) == -1) {
throw_exception<mixer_error>("Failed to attach hardware mixer control", err); throw_exception<mixer_error>("Failed to attach hardware mixer control", err);
} }
if ((err = snd_mixer_selem_register(m_mixer, nullptr, nullptr)) == -1) { if ((err = snd_mixer_selem_register(m_mixer, nullptr, nullptr)) == -1) {
@ -57,6 +57,13 @@ namespace alsa {
return m_name; return m_name;
} }
/**
* Get the name of the soundcard that is associated with the mixer
*/
const string& mixer::get_sound_card() {
return s_name;
}
/** /**
* Wait for events * Wait for events
*/ */