Handle events in alsamixer_getvolume. Closes #126

This issue can be worked around by calling mixer.handleevents() before
calling mixer.getvolume(), but it makes more sense to handle all events
before returning the volume.
This commit is contained in:
Lars Immisch
2023-05-12 02:43:51 +01:00
committed by Oswald Buddenhagen
parent c5153db0ac
commit 39d6acd3ac

View File

@@ -2157,13 +2157,10 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
{
snd_mixer_elem_t *elem;
int channel;
long ival;
PyObject *pcmtypeobj = NULL;
long pcmtype;
int iunits = VOLUME_UNITS_PERCENTAGE;
PyObject *result;
PyObject *item;
PyObject *result = NULL;
char *kw[] = { "pcmtype", "units", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:getvolume", kw, &pcmtypeobj, &iunits)) {
@@ -2187,6 +2184,9 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
}
volume_units_t units = iunits;
// handle updates that may have occurred
snd_mixer_handle_events(self->handle);
elem = alsamixer_find_elem(self->handle,self->controlname,self->controlid);
if (!pcmtypeobj || (pcmtypeobj == Py_None)) {
@@ -2201,6 +2201,8 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
result = PyList_New(0);
for (channel = 0; channel <= SND_MIXER_SCHN_LAST; channel++) {
long ival;
if (pcmtype == SND_PCM_STREAM_PLAYBACK &&
snd_mixer_selem_has_playback_channel(elem, channel))
{
@@ -2218,7 +2220,7 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
break;
}
item = PyLong_FromLong(ival);
PyObject* item = PyLong_FromLong(ival);
PyList_Append(result, item);
Py_DECREF(item);
}
@@ -2239,7 +2241,7 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
break;
}
item = PyLong_FromLong(ival);
PyObject* item = PyLong_FromLong(ival);
PyList_Append(result, item);
Py_DECREF(item);
}