I'm trying to create a small custom mixer that suits my needs, using python 2.7 and pyalsaaudio 0.7, but I'm stuck with events got from alsamixer when another program changes the volume values. I tried to understand how other mixers work (for example volti) and, as far as I understand, it should work as expected, but even if the method is similar, I still get a continuous loop of event response from io_add_watch. So, I suppose that I don't understand how io_add_watch works yet.
This is a small version of the code:
class MyMixer(gtk.Window):
def __init__(self):
super(MyMixer, self).__init__()
self.m = alsaaudio.Mixer(control='Headphone', id=1, cardindex=0)
""" here go the mixer widgets """
self.show_all()
fd, event = self.m.polldescriptors()[0]
self.watch = gobject.io_add_watch(fd, event, self.update)
def update(self, *args):
print 'changed'
""" here I update mixer widgets """
return True
mixer = MyMixer()
gtk.main()
What am I getting wrong?
When you get an event from the poll descriptors, you must call snd_mixer_handle_events()
.
pyalsaaudio
has no mechanism for that.