fix(build): Only use one volume backend

This commit is contained in:
NBonaparte 2017-09-15 20:51:22 -07:00
parent 81913cf181
commit 4f15f42f2c
8 changed files with 74 additions and 32 deletions

View File

@ -30,6 +30,7 @@ function main
local build_ipc_msg="ON" local build_ipc_msg="ON"
local enable_alsa="ON" local enable_alsa="ON"
local enable_pulseaudio="ON"
local enable_i3="ON" local enable_i3="ON"
local enable_network="ON" local enable_network="ON"
local enable_mpd="ON" local enable_mpd="ON"
@ -41,6 +42,8 @@ function main
[[ "${p^^}" != "Y" ]] && enable_i3="OFF" [[ "${p^^}" != "Y" ]] && enable_i3="OFF"
read -r -p "$(msg "Include support for \"internal/volume\" (requires alsalib) ---------- [Y/n]: ")" -n 1 p && echo read -r -p "$(msg "Include support for \"internal/volume\" (requires alsalib) ---------- [Y/n]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && enable_alsa="OFF" [[ "${p^^}" != "Y" ]] && enable_alsa="OFF"
read -r -p "$(msg "Include support for \"internal/volume\" (requires libpulse) --------- [Y/n]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && enable_pulseaudio="OFF"
read -r -p "$(msg "Include support for \"internal/network\" (requires wireless_tools) -- [Y/n]: ")" -n 1 p && echo read -r -p "$(msg "Include support for \"internal/network\" (requires wireless_tools) -- [Y/n]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && enable_network="OFF" [[ "${p^^}" != "Y" ]] && enable_network="OFF"
read -r -p "$(msg "Include support for \"internal/mpd\" (requires libmpdclient) -------- [Y/n]: ")" -n 1 p && echo read -r -p "$(msg "Include support for \"internal/mpd\" (requires libmpdclient) -------- [Y/n]: ")" -n 1 p && echo
@ -50,6 +53,11 @@ function main
read -r -p "$(msg "Build \"polybar-msg\" used to send ipc messages --------------------- [Y/n]: ")" -n 1 p && echo read -r -p "$(msg "Build \"polybar-msg\" used to send ipc messages --------------------- [Y/n]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && build_ipc_msg="OFF" [[ "${p^^}" != "Y" ]] && build_ipc_msg="OFF"
# pulseaudio overrides alsa
if [[ "${enable_alsa}" == "ON" ]] && [[ "${enable_pulseaudio}" == "ON" ]]; then
enable_alsa="OFF"
fi
local cxx="c++" local cxx="c++"
local cc="cc" local cc="cc"
@ -68,6 +76,7 @@ function main
-DCMAKE_C_COMPILER="${cc}" \ -DCMAKE_C_COMPILER="${cc}" \
-DCMAKE_CXX_COMPILER="${cxx}" \ -DCMAKE_CXX_COMPILER="${cxx}" \
-DENABLE_ALSA:BOOL="${enable_alsa}" \ -DENABLE_ALSA:BOOL="${enable_alsa}" \
-DENABLE_PULSEAUDIO:BOOL="${enable_pulseaudio}"\
-DENABLE_I3:BOOL="${enable_i3}" \ -DENABLE_I3:BOOL="${enable_i3}" \
-DENABLE_MPD:BOOL="${enable_mpd}" \ -DENABLE_MPD:BOOL="${enable_mpd}" \
-DENABLE_NETWORK:BOOL="${enable_network}" \ -DENABLE_NETWORK:BOOL="${enable_network}" \

View File

@ -16,7 +16,7 @@ queryfont(FONT_SIJI ${FONT_SIJI} FIELDS family pixelsize)
# Strip disabled modules {{{ # Strip disabled modules {{{
if(NOT ENABLE_ALSA) if(NOT (ENABLE_ALSA OR ENABLE_PULSEAUDIO))
string(REPLACE " volume" "" MODULES_RIGHT ${MODULES_RIGHT}) string(REPLACE " volume" "" MODULES_RIGHT ${MODULES_RIGHT})
endif() endif()
if(NOT ENABLE_I3) if(NOT ENABLE_I3)

View File

@ -31,7 +31,7 @@
#if ENABLE_NETWORK #if ENABLE_NETWORK
#include "modules/network.hpp" #include "modules/network.hpp"
#endif #endif
#if ENABLE_ALSA #if ENABLE_ALSA || ENABLE_PULSEAUDIO
#include "modules/volume.hpp" #include "modules/volume.hpp"
#endif #endif
#if ENABLE_CURL #if ENABLE_CURL
@ -40,7 +40,7 @@
#if ENABLE_XKEYBOARD #if ENABLE_XKEYBOARD
#include "modules/xkeyboard.hpp" #include "modules/xkeyboard.hpp"
#endif #endif
#if not(ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_CURL && ENABLE_XKEYBOARD) #if not(ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && (ENABLE_ALSA || ENABLE_PULSEAUDIO) && ENABLE_CURL && ENABLE_XKEYBOARD)
#include "modules/unsupported.hpp" #include "modules/unsupported.hpp"
#endif #endif

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#if ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_CURL && ENABLE_XKEYBOARD #if ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && (ENABLE_ALSA || ENABLE_PULSEAUDIO) && ENABLE_CURL && ENABLE_XKEYBOARD
#error "Support has been enabled for all optional modules" #error "Support has been enabled for all optional modules"
#endif #endif
@ -40,7 +40,7 @@ namespace modules {
#if not ENABLE_NETWORK #if not ENABLE_NETWORK
DEFINE_UNSUPPORTED_MODULE(network_module, "internal/network"); DEFINE_UNSUPPORTED_MODULE(network_module, "internal/network");
#endif #endif
#if not ENABLE_ALSA #if not (ENABLE_ALSA || ENABLE_PULSEAUDIO)
DEFINE_UNSUPPORTED_MODULE(volume_module, "internal/volume"); DEFINE_UNSUPPORTED_MODULE(volume_module, "internal/volume");
#endif #endif
#if not ENABLE_CURL #if not ENABLE_CURL

View File

@ -1,26 +1,31 @@
#pragma once #pragma once
#include "settings.hpp" #include "settings.hpp"
#include "adapters/pulseaudio.hpp"
#include "modules/meta/event_module.hpp" #include "modules/meta/event_module.hpp"
#include "modules/meta/input_handler.hpp" #include "modules/meta/input_handler.hpp"
POLYBAR_NS POLYBAR_NS
// fwd // fwd
#if ENABLE_ALSA
namespace alsa { namespace alsa {
class mixer; class mixer;
class control; class control;
} }
//class pulseaudio; #elif ENABLE_PULSEAUDIO
class pulseaudio;
#endif
namespace modules { namespace modules {
enum class mixer { NONE = 0, MASTER, SPEAKER, HEADPHONE }; enum class mixer { NONE = 0, MASTER, SPEAKER, HEADPHONE };
enum class control { NONE = 0, HEADPHONE }; enum class control { NONE = 0, HEADPHONE };
#if ENABLE_ALSA
using mixer_t = shared_ptr<alsa::mixer>; using mixer_t = shared_ptr<alsa::mixer>;
using control_t = shared_ptr<alsa::control>; using control_t = shared_ptr<alsa::control>;
#elif ENABLE_PULSEAUDIO
using pulseaudio_t = shared_ptr<pulseaudio>; using pulseaudio_t = shared_ptr<pulseaudio>;
#endif
class volume_module : public event_module<volume_module>, public input_handler { class volume_module : public event_module<volume_module>, public input_handler {
public: public:
@ -57,12 +62,15 @@ namespace modules {
label_t m_label_volume; label_t m_label_volume;
label_t m_label_muted; label_t m_label_muted;
#if ENABLE_PULSEAUDIO
pulseaudio_t m_pulseaudio;
#elif ENABLE_ALSA
map<mixer, mixer_t> m_mixer; map<mixer, mixer_t> m_mixer;
map<control, control_t> m_ctrl; map<control, control_t> m_ctrl;
pulseaudio_t m_pulseaudio;
//int m_headphoneid{0}; int m_headphoneid{0};
//bool m_mapped{false}; bool m_mapped{false};
#endif
atomic<bool> m_muted{false}; atomic<bool> m_muted{false};
atomic<bool> m_headphones{false}; atomic<bool> m_headphones{false};
atomic<int> m_volume{0}; atomic<int> m_volume{0};

View File

@ -8,7 +8,6 @@ file(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_LIST_DIR} *.c[p]*)
list(REMOVE_ITEM files ipc.cpp) list(REMOVE_ITEM files ipc.cpp)
if(NOT ENABLE_ALSA) if(NOT ENABLE_ALSA)
list(REMOVE_ITEM files modules/volume.cpp)
list(REMOVE_ITEM files adapters/alsa/control.cpp) list(REMOVE_ITEM files adapters/alsa/control.cpp)
list(REMOVE_ITEM files adapters/alsa/mixer.cpp) list(REMOVE_ITEM files adapters/alsa/mixer.cpp)
endif() endif()
@ -31,6 +30,9 @@ endif()
if(NOT ENABLE_PULSEAUDIO) if(NOT ENABLE_PULSEAUDIO)
list(REMOVE_ITEM files adapters/pulseaudio.cpp) list(REMOVE_ITEM files adapters/pulseaudio.cpp)
endif() endif()
if(NOT (ENABLE_ALSA OR ENABLE_PULSEAUDIO))
list(REMOVE_ITEM files modules/volume.cpp)
endif()
if(NOT WITH_XRANDR) if(NOT WITH_XRANDR)
list(REMOVE_ITEM files x11/extensions/randr.cpp) list(REMOVE_ITEM files x11/extensions/randr.cpp)
endif() endif()

View File

@ -1,7 +1,6 @@
#include "adapters/pulseaudio.hpp" #include "adapters/pulseaudio.hpp"
// TODO possibly move all the callback functions to lambda functions // TODO possibly move all the callback functions to lambda functions
// also maybe use pa_operation_unref(op)
// create base volume backend class (mixer/control, pulseaudio inherits from base class) // create base volume backend class (mixer/control, pulseaudio inherits from base class)
// use index instead of name internally? // use index instead of name internally?
POLYBAR_NS POLYBAR_NS
@ -56,6 +55,7 @@ pulseaudio::pulseaudio(string&& sink_name) : spec_s_name(sink_name) {
pa_operation* op = pa_context_get_sink_info_by_name(m_context, sink_name.c_str(), sink_info_callback, this); pa_operation* op = pa_context_get_sink_info_by_name(m_context, sink_name.c_str(), sink_info_callback, this);
while (pa_operation_get_state(op) != PA_OPERATION_DONE) while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(op);
if (exists) if (exists)
s_name = sink_name; s_name = sink_name;
else { else {
@ -65,15 +65,20 @@ pulseaudio::pulseaudio(string&& sink_name) : spec_s_name(sink_name) {
} }
while (pa_operation_get_state(op) != PA_OPERATION_DONE) while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(op);
s_name = def_s_name; s_name = def_s_name;
// get the sink index // get the sink index
op = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), sink_info_callback, this); op = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), sink_info_callback, this);
while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(op);
} }
op = pa_context_subscribe(m_context, static_cast<pa_subscription_mask_t>(PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SERVER), op = pa_context_subscribe(m_context, static_cast<pa_subscription_mask_t>(PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SERVER),
simple_callback, this); simple_callback, this);
while (pa_operation_get_state(op) != PA_OPERATION_DONE) while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(op);
pa_context_set_subscribe_callback(m_context, subscribe_callback, this); pa_context_set_subscribe_callback(m_context, subscribe_callback, this);
pa_threaded_mainloop_unlock(m_mainloop); pa_threaded_mainloop_unlock(m_mainloop);
@ -84,7 +89,6 @@ pulseaudio::pulseaudio(string&& sink_name) : spec_s_name(sink_name) {
* Deconstruct pulseaudio * Deconstruct pulseaudio
*/ */
pulseaudio::~pulseaudio() { pulseaudio::~pulseaudio() {
pa_threaded_mainloop_unlock(m_mainloop);
pa_threaded_mainloop_stop(m_mainloop); pa_threaded_mainloop_stop(m_mainloop);
pa_context_disconnect(m_context); pa_context_disconnect(m_context);
pa_context_unref(m_context); pa_context_unref(m_context);
@ -123,6 +127,7 @@ int pulseaudio::process_events() {
o = pa_context_get_sink_info_by_name(m_context, spec_s_name.c_str(), sink_info_callback, this); o = pa_context_get_sink_info_by_name(m_context, spec_s_name.c_str(), sink_info_callback, this);
while (pa_operation_get_state(o) != PA_OPERATION_DONE) while (pa_operation_get_state(o) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(o);
if (exists) if (exists)
s_name = spec_s_name; s_name = spec_s_name;
break; break;
@ -131,15 +136,18 @@ int pulseaudio::process_events() {
o = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), get_sink_volume_callback, this); o = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), get_sink_volume_callback, this);
while (pa_operation_get_state(o) != PA_OPERATION_DONE) while (pa_operation_get_state(o) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(o);
break; break;
// get default sink // get default sink
case evtype::REMOVE: case evtype::REMOVE:
o = pa_context_get_server_info(m_context, get_default_sink_callback, this); o = pa_context_get_server_info(m_context, get_default_sink_callback, this);
while (pa_operation_get_state(o) != PA_OPERATION_DONE) while (pa_operation_get_state(o) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(o);
o = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), sink_info_callback, this); o = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), sink_info_callback, this);
while (pa_operation_get_state(o) != PA_OPERATION_DONE) while (pa_operation_get_state(o) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(o);
break; break;
} }
m_events.pop(); m_events.pop();
@ -154,9 +162,9 @@ int pulseaudio::process_events() {
int pulseaudio::get_volume() { int pulseaudio::get_volume() {
pa_threaded_mainloop_lock(m_mainloop); pa_threaded_mainloop_lock(m_mainloop);
pa_operation *op = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), get_sink_volume_callback, this); pa_operation *op = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), get_sink_volume_callback, this);
while (pa_operation_get_state(op) != PA_OPERATION_DONE) { while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
} pa_operation_unref(op);
pa_threaded_mainloop_unlock(m_mainloop); pa_threaded_mainloop_unlock(m_mainloop);
// alternatively, user pa_cvolume_avg_mask() to average selected channels // alternatively, user pa_cvolume_avg_mask() to average selected channels
//return math_util::percentage(pa_cvolume_avg(&cv), PA_VOLUME_MUTED, PA_VOLUME_NORM); //return math_util::percentage(pa_cvolume_avg(&cv), PA_VOLUME_MUTED, PA_VOLUME_NORM);
@ -172,11 +180,13 @@ void pulseaudio::set_volume(float percentage) {
pa_operation *op = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), get_sink_volume_callback, this); pa_operation *op = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), get_sink_volume_callback, this);
while (pa_operation_get_state(op) != PA_OPERATION_DONE) while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(op);
pa_volume_t vol = math_util::percentage_to_value<pa_volume_t>(percentage, PA_VOLUME_MUTED, PA_VOLUME_NORM); pa_volume_t vol = math_util::percentage_to_value<pa_volume_t>(percentage, PA_VOLUME_MUTED, PA_VOLUME_NORM);
pa_cvolume_scale(&cv, vol); pa_cvolume_scale(&cv, vol);
op = pa_context_set_sink_volume_by_name(m_context, s_name.c_str(), &cv, simple_callback, this); op = pa_context_set_sink_volume_by_name(m_context, s_name.c_str(), &cv, simple_callback, this);
while (pa_operation_get_state(op) != PA_OPERATION_DONE) while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(op);
pa_threaded_mainloop_unlock(m_mainloop); pa_threaded_mainloop_unlock(m_mainloop);
} }
@ -188,6 +198,7 @@ void pulseaudio::set_mute(bool mode) {
pa_operation *op = pa_context_set_sink_mute_by_name(m_context, s_name.c_str(), mode, simple_callback, this); pa_operation *op = pa_context_set_sink_mute_by_name(m_context, s_name.c_str(), mode, simple_callback, this);
while (pa_operation_get_state(op) != PA_OPERATION_DONE) while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(op);
pa_threaded_mainloop_unlock(m_mainloop); pa_threaded_mainloop_unlock(m_mainloop);
} }
@ -206,6 +217,7 @@ bool pulseaudio::is_muted() {
pa_operation *op = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), check_mute_callback, this); pa_operation *op = pa_context_get_sink_info_by_name(m_context, s_name.c_str(), check_mute_callback, this);
while (pa_operation_get_state(op) != PA_OPERATION_DONE) while (pa_operation_get_state(op) != PA_OPERATION_DONE)
pa_threaded_mainloop_wait(m_mainloop); pa_threaded_mainloop_wait(m_mainloop);
pa_operation_unref(op);
pa_threaded_mainloop_unlock(m_mainloop); pa_threaded_mainloop_unlock(m_mainloop);
return muted; return muted;
} }

View File

@ -1,8 +1,11 @@
#include "modules/volume.hpp" #include "modules/volume.hpp"
#if ENABLE_ALSA
#include "adapters/alsa/control.hpp" #include "adapters/alsa/control.hpp"
#include "adapters/alsa/generic.hpp" #include "adapters/alsa/generic.hpp"
#include "adapters/alsa/mixer.hpp" #include "adapters/alsa/mixer.hpp"
#elif ENABLE_PULSEAUDIO
#include "adapters/pulseaudio.hpp" #include "adapters/pulseaudio.hpp"
#endif
#include "drawtypes/label.hpp" #include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp" #include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp" #include "drawtypes/ramp.hpp"
@ -14,14 +17,16 @@
POLYBAR_NS POLYBAR_NS
#if ENABLE_ALSA
using namespace alsa; using namespace alsa;
#endif
namespace modules { namespace modules {
template class module<volume_module>; template class module<volume_module>;
volume_module::volume_module(const bar_settings& bar, string name_) : event_module<volume_module>(bar, move(name_)) { volume_module::volume_module(const bar_settings& bar, string name_) : event_module<volume_module>(bar, move(name_)) {
// Load configuration values // Load configuration values
/* #if ENABLE_ALSA
m_mapped = m_conf.get(name(), "mapped", m_mapped); m_mapped = m_conf.get(name(), "mapped", m_mapped);
auto master_mixer_name = m_conf.get(name(), "master-mixer", "Master"s); auto master_mixer_name = m_conf.get(name(), "master-mixer", "Master"s);
@ -68,10 +73,10 @@ namespace modules {
} catch (const control_error& err) { } catch (const control_error& err) {
throw module_error(err.what()); throw module_error(err.what());
} }
*/ #elif ENABLE_PULSEAUDIO
auto sink_name = m_conf.get(name(), "sink", ""s); auto sink_name = m_conf.get(name(), "sink", ""s);
//m_pulseaudio = new pulseaudio_t::element_type{move(sink_name)};
m_pulseaudio = factory_util::unique<pulseaudio>(move(sink_name)); m_pulseaudio = factory_util::unique<pulseaudio>(move(sink_name));
#endif
// Add formats and elements // Add formats and elements
m_formatter->add(FORMAT_VOLUME, TAG_LABEL_VOLUME, {TAG_RAMP_VOLUME, TAG_LABEL_VOLUME, TAG_BAR_VOLUME}); m_formatter->add(FORMAT_VOLUME, TAG_LABEL_VOLUME, {TAG_RAMP_VOLUME, TAG_LABEL_VOLUME, TAG_BAR_VOLUME});
@ -93,18 +98,18 @@ namespace modules {
} }
void volume_module::teardown() { void volume_module::teardown() {
/* #if ENABLE_ALSA
m_mixer.clear(); m_mixer.clear();
m_ctrl.clear(); m_ctrl.clear();
*/
//m_pulseaudio.clear();
m_pulseaudio.reset();
snd_config_update_free_global(); snd_config_update_free_global();
#elif ENABLE_PULSEAUDIO
m_pulseaudio.reset();
#endif
} }
bool volume_module::has_event() { bool volume_module::has_event() {
// Poll for mixer and control events // Poll for mixer and control events
/* #if ENABLE_ALSA
try { try {
if (m_mixer[mixer::MASTER] && m_mixer[mixer::MASTER]->wait(25)) { if (m_mixer[mixer::MASTER] && m_mixer[mixer::MASTER]->wait(25)) {
return true; return true;
@ -121,19 +126,20 @@ namespace modules {
} catch (const alsa_exception& e) { } catch (const alsa_exception& e) {
m_log.err("%s: %s", name(), e.what()); m_log.err("%s: %s", name(), e.what());
} }
*/ #elif ENABLE_PULSEAUDIO
try { try {
if (m_pulseaudio->wait(25)) if (m_pulseaudio->wait(25))
return true; return true;
} catch (const pulseaudio_error& e) { } catch (const pulseaudio_error& e) {
m_log.err("%s: %s", name(), e.what()); m_log.err("%s: %s", name(), e.what());
} }
#endif
return false; return false;
} }
bool volume_module::update() { bool volume_module::update() {
// Consume pending events // Consume pending events
/* #if ENABLE_ALSA
if (m_mixer[mixer::MASTER]) { if (m_mixer[mixer::MASTER]) {
m_mixer[mixer::MASTER]->process_events(); m_mixer[mixer::MASTER]->process_events();
} }
@ -146,15 +152,16 @@ namespace modules {
if (m_ctrl[control::HEADPHONE]) { if (m_ctrl[control::HEADPHONE]) {
m_ctrl[control::HEADPHONE]->process_events(); m_ctrl[control::HEADPHONE]->process_events();
} }
*/ #elif ENABLE_PULSEAUDIO
m_pulseaudio->process_events(); m_pulseaudio->process_events();
#endif
// Get volume, mute and headphone state // Get volume, mute and headphone state
m_volume = 100; m_volume = 100;
m_muted = false; m_muted = false;
m_headphones = false; m_headphones = false;
/* #if ENABLE_ALSA
try { try {
if (m_mixer[mixer::MASTER]) { if (m_mixer[mixer::MASTER]) {
m_volume = m_volume * (m_mapped ? m_mixer[mixer::MASTER]->get_normalized_volume() / 100.0f m_volume = m_volume * (m_mapped ? m_mixer[mixer::MASTER]->get_normalized_volume() / 100.0f
@ -185,7 +192,7 @@ namespace modules {
} catch (const alsa_exception& err) { } catch (const alsa_exception& err) {
m_log.err("%s: Failed to query speaker mixer (%s)", name(), err.what()); m_log.err("%s: Failed to query speaker mixer (%s)", name(), err.what());
} }
*/ #elif ENABLE_PULSEAUDIO
try { try {
if (m_pulseaudio) { if (m_pulseaudio) {
m_volume = m_volume * m_pulseaudio->get_volume() / 100.0f; m_volume = m_volume * m_pulseaudio->get_volume() / 100.0f;
@ -194,6 +201,7 @@ namespace modules {
} catch (const pulseaudio_error& err) { } catch (const pulseaudio_error& err) {
m_log.err("%s: Failed to query pulseaudio sink (%s)", name(), err.what()); m_log.err("%s: Failed to query pulseaudio sink (%s)", name(), err.what());
} }
#endif
// Replace label tokens // Replace label tokens
if (m_label_volume) { if (m_label_volume) {
@ -252,12 +260,14 @@ namespace modules {
return false; return false;
} else if (cmd.compare(0, 3, EVENT_PREFIX) != 0) { } else if (cmd.compare(0, 3, EVENT_PREFIX) != 0) {
return false; return false;
//} else if (!m_mixer[mixer::MASTER]) { #if ENABLE_ALSA
// return false; } else if (!m_mixer[mixer::MASTER]) {
return false;
#endif
} }
try { try {
/* #if ENABLE_ALSA
vector<mixer_t> mixers; vector<mixer_t> mixers;
bool headphones{m_headphones}; bool headphones{m_headphones};
@ -297,7 +307,7 @@ namespace modules {
mixer->process_events(); mixer->process_events();
} }
} }
*/ #elif ENABLE_PULSEAUDIO
if (m_pulseaudio && !m_pulseaudio->get_name().empty()) { if (m_pulseaudio && !m_pulseaudio->get_name().empty()) {
if (cmd.compare(0, strlen(EVENT_TOGGLE_MUTE), EVENT_TOGGLE_MUTE) == 0) { if (cmd.compare(0, strlen(EVENT_TOGGLE_MUTE), EVENT_TOGGLE_MUTE) == 0) {
printf("toggling mute\n"); printf("toggling mute\n");
@ -314,6 +324,7 @@ namespace modules {
m_pulseaudio->process_events(); m_pulseaudio->process_events();
} }
} }
#endif
} catch (const exception& err) { } catch (const exception& err) {
m_log.err("%s: Failed to handle command (%s)", name(), err.what()); m_log.err("%s: Failed to handle command (%s)", name(), err.what());
} }