mirror of
https://github.com/larsimmisch/pyalsaaudio.git
synced 2026-06-01 10:57:01 +00:00
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:
+8
-6
@@ -2157,13 +2157,10 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
|
|||||||
{
|
{
|
||||||
snd_mixer_elem_t *elem;
|
snd_mixer_elem_t *elem;
|
||||||
int channel;
|
int channel;
|
||||||
long ival;
|
|
||||||
PyObject *pcmtypeobj = NULL;
|
PyObject *pcmtypeobj = NULL;
|
||||||
long pcmtype;
|
long pcmtype;
|
||||||
int iunits = VOLUME_UNITS_PERCENTAGE;
|
int iunits = VOLUME_UNITS_PERCENTAGE;
|
||||||
PyObject *result;
|
PyObject *result = NULL;
|
||||||
PyObject *item;
|
|
||||||
|
|
||||||
char *kw[] = { "pcmtype", "units", NULL };
|
char *kw[] = { "pcmtype", "units", NULL };
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:getvolume", kw, &pcmtypeobj, &iunits)) {
|
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;
|
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);
|
elem = alsamixer_find_elem(self->handle,self->controlname,self->controlid);
|
||||||
|
|
||||||
if (!pcmtypeobj || (pcmtypeobj == Py_None)) {
|
if (!pcmtypeobj || (pcmtypeobj == Py_None)) {
|
||||||
@@ -2201,6 +2201,8 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
|
|||||||
result = PyList_New(0);
|
result = PyList_New(0);
|
||||||
|
|
||||||
for (channel = 0; channel <= SND_MIXER_SCHN_LAST; channel++) {
|
for (channel = 0; channel <= SND_MIXER_SCHN_LAST; channel++) {
|
||||||
|
long ival;
|
||||||
|
|
||||||
if (pcmtype == SND_PCM_STREAM_PLAYBACK &&
|
if (pcmtype == SND_PCM_STREAM_PLAYBACK &&
|
||||||
snd_mixer_selem_has_playback_channel(elem, channel))
|
snd_mixer_selem_has_playback_channel(elem, channel))
|
||||||
{
|
{
|
||||||
@@ -2218,7 +2220,7 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = PyLong_FromLong(ival);
|
PyObject* item = PyLong_FromLong(ival);
|
||||||
PyList_Append(result, item);
|
PyList_Append(result, item);
|
||||||
Py_DECREF(item);
|
Py_DECREF(item);
|
||||||
}
|
}
|
||||||
@@ -2239,7 +2241,7 @@ alsamixer_getvolume(alsamixer_t *self, PyObject *args, PyObject *kwds)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = PyLong_FromLong(ival);
|
PyObject* item = PyLong_FromLong(ival);
|
||||||
PyList_Append(result, item);
|
PyList_Append(result, item);
|
||||||
Py_DECREF(item);
|
Py_DECREF(item);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user