On Tue, Jun 01, 2010 at 10:11:59PM +0200, pascal wrote:
Thanks for the wmiirc_local.py example. I used it as a base for mine. I'm having some troubles to figure out the "mixer" plugin. I thought I would try to write an equivalent myself before asking, but I can't, I'm getting headaches. Would you mind posting yours?

Sure, if you really want it. The alsamixer module isn't mine, though, and it'd buggy. The only reason I use it is that some programs change the PCM mixer value and you can't access it via OSD.

The Linux version is attached.

--
Kris Maglione

I'm confident that tomorrow's Unix will look like today's Unix, only
cruftier.
        --Russ Cox

import fcntl

from pyxp.fields import Int

SOUND_MIXER_READ_DEVMASK = 0x80044DFE
MIXER_READ  = 0x80044D00
MIXER_WRITE = 0xC0044D00

mod = 0

mixers = ('vol', 'bass', 'treble', 'synth', 'pcm', 'speaker',
          'line', 'mic', 'cd', 'mix', 'pcm2', 'rec', 'igain',
          'ogain', 'line1', 'line2', 'line3', 'dig1', 'dig2',
          'dig3', 'phin', 'phout', 'video', 'radio', 'monitor')
mixerfd = open('/dev/mixer')
res = fcntl.ioctl(mixerfd, SOUND_MIXER_READ_DEVMASK, '    ')
mask = Int(4).decode(res, 0)

def findmixer(name):
    for i, mixer in enumerate(mixers):
        if (1 << i) & mask and mixer == name:
            return i

def getlevel(name):
    mixer = findmixer(name);
    res = fcntl.ioctl(mixerfd, MIXER_READ + mixer, '  ')
    return (ord(res[0]) + ord(res[1])) / 2

def setlevel(name, level):
    mixer = findmixer(name);
    fcntl.ioctl(mixerfd, MIXER_WRITE + mixer,
                chr(level & 0x7f) * 2 + '\0\0')

# vim:se sts=4 sw=4 et:

Reply via email to