mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
module/alsa: volume/muted: default to “unset”; use first available channel
This commit is contained in:
parent
ae7d54fb80
commit
db12ceb026
2 changed files with 23 additions and 32 deletions
|
@ -40,12 +40,12 @@ alsa - Monitors an alsa soundcard for volume and mute/unmute changes
|
||||||
: string
|
: string
|
||||||
: no
|
: no
|
||||||
: The name of the channel to use as source for the volume level
|
: The name of the channel to use as source for the volume level
|
||||||
(default: *Front Left*).
|
(default: first available channel, usually "Front Left").
|
||||||
| muted
|
| muted
|
||||||
: string
|
: string
|
||||||
: no
|
: no
|
||||||
: The name of the channel to use as source for the muted state
|
: The name of the channel to use as source for the muted state
|
||||||
(default: *Front Left*).
|
(default: first available channel, usually "Front Left").
|
||||||
|
|
||||||
|
|
||||||
# EXAMPLES
|
# EXAMPLES
|
||||||
|
|
|
@ -110,7 +110,7 @@ update_state(struct module *mod, snd_mixer_elem_t *elem)
|
||||||
if (max > 0) {
|
if (max > 0) {
|
||||||
tll_foreach(m->channels, it) {
|
tll_foreach(m->channels, it) {
|
||||||
const char *name = snd_mixer_selem_channel_name(it->item);
|
const char *name = snd_mixer_selem_channel_name(it->item);
|
||||||
if (strcmp(name, m->volume_channel) != 0)
|
if (m->volume_channel != NULL && strcmp(name, m->volume_channel) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int r = snd_mixer_selem_get_playback_volume(elem, it->item, &cur);
|
int r = snd_mixer_selem_get_playback_volume(elem, it->item, &cur);
|
||||||
|
@ -129,7 +129,7 @@ update_state(struct module *mod, snd_mixer_elem_t *elem)
|
||||||
/* Get muted state */
|
/* Get muted state */
|
||||||
tll_foreach(m->channels, it) {
|
tll_foreach(m->channels, it) {
|
||||||
const char *name = snd_mixer_selem_channel_name(it->item);
|
const char *name = snd_mixer_selem_channel_name(it->item);
|
||||||
if (strcmp(name, m->muted_channel) != 0)
|
if (m->muted_channel != NULL && strcmp(name, m->muted_channel) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int r = snd_mixer_selem_get_playback_switch(elem, it->item, &unmuted);
|
int r = snd_mixer_selem_get_playback_switch(elem, it->item, &unmuted);
|
||||||
|
@ -233,36 +233,27 @@ run_while_online(struct module *mod)
|
||||||
LOG_INFO("%s,%s: channels: %s", m->card, m->mixer, channels_str);
|
LOG_INFO("%s,%s: channels: %s", m->card, m->mixer, channels_str);
|
||||||
|
|
||||||
/* Verify volume/muted channel names are valid and exists */
|
/* Verify volume/muted channel names are valid and exists */
|
||||||
bool have_volume_channel = false;
|
bool volume_channel_is_valid = m->volume_channel == NULL;
|
||||||
bool have_muted_channel = false;
|
bool muted_channel_is_valid = m->muted_channel == NULL;
|
||||||
|
|
||||||
tll_foreach(m->channels, it) {
|
tll_foreach(m->channels, it) {
|
||||||
const char *chan_name = snd_mixer_selem_channel_name(it->item);
|
const char *chan_name = snd_mixer_selem_channel_name(it->item);
|
||||||
if (strcmp(chan_name, m->volume_channel) == 0)
|
if (m->volume_channel != NULL && strcmp(chan_name, m->volume_channel) == 0)
|
||||||
have_volume_channel = true;
|
volume_channel_is_valid = true;
|
||||||
if (strcmp(chan_name, m->muted_channel) == 0)
|
if (m->muted_channel != NULL && strcmp(chan_name, m->muted_channel) == 0)
|
||||||
have_muted_channel = true;
|
muted_channel_is_valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!have_volume_channel) {
|
if (!volume_channel_is_valid) {
|
||||||
const char *first_chan_name =
|
assert(m->volume_channel != NULL);
|
||||||
snd_mixer_selem_channel_name(tll_front(m->channels));
|
LOG_ERR("volume: invalid channel name: %s", m->volume_channel);
|
||||||
|
goto err;
|
||||||
LOG_WARN("%s: not a valid channel name, using '%s' as volume source",
|
|
||||||
m->volume_channel, first_chan_name);
|
|
||||||
|
|
||||||
free(m->volume_channel);
|
|
||||||
m->volume_channel = strdup(first_chan_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!have_muted_channel) {
|
if (!muted_channel_is_valid) {
|
||||||
const char *first_chan_name =
|
assert(m->muted_channel != NULL);
|
||||||
snd_mixer_selem_channel_name(tll_front(m->channels));
|
LOG_ERR("muted: invalid channel name: %s", m->muted_channel);
|
||||||
|
goto err;
|
||||||
LOG_WARN("%s: not a valid channel name, using '%s' as muted source",
|
|
||||||
m->muted_channel, first_chan_name);
|
|
||||||
|
|
||||||
free(m->muted_channel);
|
|
||||||
m->muted_channel = strdup(first_chan_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initial state */
|
/* Initial state */
|
||||||
|
@ -408,8 +399,8 @@ alsa_new(const char *card, const char *mixer,
|
||||||
priv->label = label;
|
priv->label = label;
|
||||||
priv->card = strdup(card);
|
priv->card = strdup(card);
|
||||||
priv->mixer = strdup(mixer);
|
priv->mixer = strdup(mixer);
|
||||||
priv->volume_channel = strdup(volume_channel);
|
priv->volume_channel = volume_channel != NULL ? strdup(volume_channel) : NULL;
|
||||||
priv->muted_channel = strdup(muted_channel);
|
priv->muted_channel = muted_channel != NULL ? strdup(muted_channel) : NULL;
|
||||||
|
|
||||||
struct module *mod = module_common_new();
|
struct module *mod = module_common_new();
|
||||||
mod->private = priv;
|
mod->private = priv;
|
||||||
|
@ -432,8 +423,8 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited)
|
||||||
return alsa_new(
|
return alsa_new(
|
||||||
yml_value_as_string(card),
|
yml_value_as_string(card),
|
||||||
yml_value_as_string(mixer),
|
yml_value_as_string(mixer),
|
||||||
volume != NULL ? yml_value_as_string(volume) : "Front Left",
|
volume != NULL ? yml_value_as_string(volume) : NULL,
|
||||||
muted != NULL ? yml_value_as_string(muted) : "Front Left",
|
muted != NULL ? yml_value_as_string(muted) : NULL,
|
||||||
conf_to_particle(content, inherited));
|
conf_to_particle(content, inherited));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue