HowTo? Control line-in volume/mute via the SoundMixer.py

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
Kindt.nick
Posts: 16
Joined: Mon Dec 28, 2009 6:21 pm

HowTo? Control line-in volume/mute via the SoundMixer.py

Post by Kindt.nick » Tue Jan 19, 2010 12:23 pm

Hi,

I'm trying to control the volume and/or the mute function of the line-in on my soundcard.
I've google, searched in the forum, tried a couple of things but I can't seem to get it working.
I think I need to get the correct structure from somewhere (just like they do in the soundmixer.py file)
but I can't get to that structure. Could anybody help me?

This is what I allready did:

Code: Select all

#################################################
COMMAND:
-----------
print eg.WinApi.SoundMixer.GetMixerDevices()

RESULT:
--------
[u'C-Media Wave Device']

#################################################
COMMAND:
-----------
print eg.WinApi.SoundMixer.GetDeviceLines()

RESULT:
--------
Destination: 0 Volumeregeling
        Control: (u'Hoofdvolume', 'Fader', 'Volume', '')
        Control: (u'Hoofdniveau dempen', 'Switch', 'Mute', '')
    Source: 0 Wave
            Control: (u'Volume', 'Fader', 'Volume', '')
            Control: (u'Dempen', 'Switch', 'Mute', '')
    Source: 1 SW-synthesizer
            Control: (u'Volume', 'Fader', 'Volume', '')
            Control: (u'Dempen', 'Switch', 'Mute', '')
    Source: 2 Microfoon
            Control: (u'Microfoonversterking', 'Switch', 'OnOff', 'Uniform')
            Control: (u'Microfoonvolume', 'Fader', 'Volume', 'Uniform')
            Control: (u'Microfoon dempen', 'Switch', 'Mute', 'Uniform')
    Source: 3 Cd-speler
            Control: (u'Volume van lijn', 'Fader', 'Volume', '')
            Control: (u'Lijn dempen', 'Switch', 'Mute', '')
    Source: 4 Aux/Phone
            Control: (u'Volume van aux', 'Fader', 'Volume', '')
            Control: (u'Aux dempen', 'Switch', 'Mute', '')
    Source: 5 Lijningang
            Control: (u'Volume van lijningang', 'Fader', 'Volume', '')
            Control: (u'Lijn dempen', 'Switch', 'Mute', '')
Destination: 1 Opnameregeling
        Control: (u'Opnamebron', 'List', 'Mux', 'Multiple(6), Uniform')
    Source: 0 Stereo Mix
            Control: (u'Volume van stereo-mix', 'Fader', 'Volume', '')
    Source: 1 Microfoon
            Control: (u'Microfoonversterking', 'Switch', 'OnOff', 'Uniform')
            Control: (u'Microfoonvolume', 'Fader', 'Volume', 'Uniform')
    Source: 2 Cd-speler
            Control: (u'Volume van lijningang', 'Fader', 'Volume', '')
    Source: 3 Aux/Phone
            Control: (u'Volume van aux', 'Fader', 'Volume', '')
    Source: 4 Lijningang
            Control: (u'Volume van lijningang', 'Fader', 'Volume', '')
    Source: 5 Wave
            Control: (u'Volume van wave', 'Fader', 'Volume', '')
None
So I would think the following should work:

Code: Select all

#################################################
COMMAND:
-----------
print eg.WinApi.SoundMixer.SetControlValue(u'Hoofdvolume', u'Dempen', 1)

RESULT:
--------
Fout in Actie: "print eg.WinApi.SoundMixer.SetControlValue(u'Hoofdvolume', u'Dempen', 1)"
Traceback (most recent call last) (1476):
  File "<string>", line 1, in <module>
  File "C:\Program Files\EventGhost\eg\WinApi\SoundMixer.py", line 139, in SetControlValue
AttributeError: 'unicode' object has no attribute 'dwControlID'
But as you can see, it doesn't... :s

Thx in advance,
Nick

Kindt.nick
Posts: 16
Joined: Mon Dec 28, 2009 6:21 pm

Re: HowTo? Control line-in volume/mute via the SoundMixer.py

Post by Kindt.nick » Wed Jan 20, 2010 9:00 pm

Ok,

Appaerently I found it by myself, although I think there is an easier way.
I must admit, I 'stole' some code from the soundmixer.py library

Code: Select all

####################################################################################################
# NOTE
# ----
# HOW TO get te corresponding componentType for each line?
# 1. Delete the Soundmixer.pyc file in the eg/winapi directory
# 2. Add the following line at the end of the GetDeviceLines() function:
#       print mixerline.dwComponentType
# 3. Save file and restart Eventghost. This way the .py file gets compiled into a .pyc file.
# 4. Run the followin python command "print eg.WinApi.SoundMixer.GetDeviceLines()"
# 5. For each channel you get the corresponding componentType and possible commands. (fader, mute, etc)
# 6. Optionally you can remove the added line in the soundmixer.py file, delete the soundmixer.pyc file an restart EventGhost to restore the library

####################################################################################################
# DEFINES
# -------
MIXERCONTROL_CONTROLTYPE_MUTE = 536936450 # Variable c_long '536936450l'
MIXERCONTROL_CONTROLTYPE_VOLUME = 1342373889 # Variable c_long '1342373889l'

MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = 4
MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = 4101
MIXERLINE_COMPONENTTYPE_SRC_LINE = 4098
MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = 4099
MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER = 4100
MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE = 4106
MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = 4104

####################################################################################################
# FUNCTIONS
# ---------
def GetLineMute(deviceId=0, componentType=4):
    # Obtain the volumne control object
    hmixer, mixerControl = eg.WinApi.SoundMixer.GetMixerControl(componentType, MIXERCONTROL_CONTROLTYPE_MUTE, deviceId)

    # Then get the volume
    return eg.WinApi.SoundMixer.GetControlValue(hmixer, mixerControl)    

def SetLineMute(mute=True, deviceId=0, componentType=4):
    # Obtain the volumne control object
    hmixer, mixerControl = eg.WinApi.SoundMixer.GetMixerControl(componentType, MIXERCONTROL_CONTROLTYPE_MUTE, deviceId)

    # Then set the volume
    return eg.WinApi.SoundMixer.SetControlValue(hmixer, mixerControl, int(mute))

def ToggleLineMute(deviceId=0, componentType=4):
    flag = not GetLineMute(deviceId, componentType)
    SetLineMute(flag, deviceId, componentType)
    return flag
####################################################################################################
# MAIN PROGRAM
# ------------
ToggleLineMute(0, MIXERLINE_COMPONENTTYPE_SRC_LINE)
Greetings,
Nick

Post Reply