count = snd_mixer_poll_descriptors_count(self->handle);
if (count <= 0)
Py_RETURN_NONE;
- pfd = malloc(sizeof(struct pollfd) * count);
- if (pfd == NULL)
- Py_RETURN_NONE;
+ pfd = alloca(sizeof(struct pollfd) * count);
count = snd_mixer_poll_descriptors(self->handle, pfd, count);
if (count <= 0)
Py_RETURN_NONE;
Py_RETURN_NONE;
}
+static PyObject *
+pyalsamixer_getpollfds(struct pyalsamixer *self, void *priv)
+{
+ PyObject *l, *t;
+ struct pollfd *pfds;
+ int i, count;
+
+ count = snd_mixer_poll_descriptors_count(self->handle);
+ if (count < 0) {
+pfds_error:
+ PyErr_Format(PyExc_IOError, "poll descriptors error: %s", snd_strerror(count));
+ return NULL;
+ }
+ pfds = alloca(sizeof(struct pollfd) * count);
+ count = snd_mixer_poll_descriptors(self->handle, pfds, count);
+ if (count < 0)
+ goto pfds_error;
+
+ l = PyList_New(count);
+ if (!l)
+ return NULL;
+ for (i = 0; i < count; ++i) {
+ t = PyTuple_New(2);
+ if (t) {
+ PyTuple_SET_ITEM(t, 0, PyInt_FromLong(pfds[i].fd));
+ PyTuple_SET_ITEM(t, 1, PyInt_FromLong(pfds[i].events));
+ PyList_SetItem(l, i, t);
+ }
+ }
+ return l;
+}
+
PyDoc_STRVAR(list__doc__,
"list() -- Return a list (tuple) of element IDs in (name,index) tuple.");
static PyGetSetDef pyalsamixer_getseters[] = {
- {"count", (getter)pyalsamixer_getcount, NULL, "mixer element count", NULL},
+ {"count", (getter)pyalsamixer_getcount, NULL, "mixer element count", NULL},
+ {"poll_fds", (getter)pyalsamixer_getpollfds, NULL, "list of (fd, eventbits) tuples", NULL},
{NULL}
};
from pyalsa.alsahcontrol import HControl, Element, Info
-hctl = HControl()
+hctl = HControl(name='hw:1')
list = hctl.list()
for id in list:
elem = Element(hctl, id[1:])
info = Info(elem)
- if info.isUser:
+ if info.is_user:
print 'Removing element %s' % repr(id)
- hctl.elementRemove(id[1:])
+ hctl.element_remove(id[1:])