def GetDeviceLines(deviceId=0): deviceId = GetDeviceId(deviceId) mixercaps = MIXERCAPS() mixerline = MIXERLINE() hmixer = HMIXER() # Obtain the hmixer struct rc = mixerOpen(byref(hmixer), deviceId, 0, 0, 0) if rc != MMSYSERR_NOERROR: raise SoundMixerException() if mixerGetDevCaps(deviceId, byref(mixercaps), sizeof(MIXERCAPS)): raise SoundMixerException() for destinationNum in range(mixercaps.cDestinations): mixerline.cbStruct = sizeof(MIXERLINE) mixerline.dwDestination = destinationNum if mixerGetLineInfo( hmixer, byref(mixerline), MIXER_GETLINEINFOF_DESTINATION ): continue print "Destination:", destinationNum, mixerline.szName for name in GetControls(hmixer, mixerline): print " Control:", name for sourceNum in range(mixerline.cConnections): mixerline.cbStruct = sizeof(MIXERLINE) mixerline.dwDestination = destinationNum mixerline.dwSource = sourceNum if mixerGetLineInfo( hmixer, byref(mixerline), MIXER_GETLINEINFOF_SOURCE ): continue print " Source:", sourceNum, mixerline.szName for name in GetControls(hmixer, mixerline): print " Control:", name
def GetDeviceLines(deviceId=0): deviceId = GetDeviceId(deviceId) mixercaps = MIXERCAPS() mixerline = MIXERLINE() hmixer = HMIXER() # Obtain the hmixer struct rc = mixerOpen(byref(hmixer), deviceId, 0, 0, 0) if rc != MMSYSERR_NOERROR: raise SoundMixerException() if mixerGetDevCaps(deviceId, byref(mixercaps), sizeof(MIXERCAPS)): raise SoundMixerException() for destinationNum in range(mixercaps.cDestinations): mixerline.cbStruct = sizeof(MIXERLINE) mixerline.dwDestination = destinationNum if mixerGetLineInfo(hmixer, byref(mixerline), MIXER_GETLINEINFOF_DESTINATION): continue print "Destination:", destinationNum, mixerline.szName for name in GetControls(hmixer, mixerline): print " Control:", name for sourceNum in range(mixerline.cConnections): mixerline.cbStruct = sizeof(MIXERLINE) mixerline.dwDestination = destinationNum mixerline.dwSource = sourceNum if mixerGetLineInfo(hmixer, byref(mixerline), MIXER_GETLINEINFOF_SOURCE): continue print " Source:", sourceNum, mixerline.szName for name in GetControls(hmixer, mixerline): print " Control:", name
def GetControls(hmixer, mixerline): numCtrls = mixerline.cControls if numCtrls == 0: return [] mixerControlArray = (MIXERCONTROL * numCtrls)() mixerLineControls = MIXERLINECONTROLS() mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS) mixerLineControls.cControls = numCtrls mixerLineControls.dwLineID = mixerline.dwLineID mixerLineControls.pamxctrl = pointer(mixerControlArray[0]) mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL) mixerGetLineControls(hmixer, byref(mixerLineControls), MIXER_GETLINECONTROLSF_ALL) result = [] for i in range(numCtrls): mixerControl = mixerControlArray[i] dwControlType = mixerControl.dwControlType controlClass = MIXER_CONTROL_CLASSES[dwControlType & MIXERCONTROL_CT_CLASS_MASK] controlClassTypeName = controlClass["types"][dwControlType] flagNames = [] fdwControl = mixerControl.fdwControl if fdwControl & MIXERCONTROL_CONTROLF_DISABLED: flagNames.append("Disabled") if fdwControl & MIXERCONTROL_CONTROLF_MULTIPLE: flagNames.append("Multiple(%i)" % mixerControl.cMultipleItems) if fdwControl & MIXERCONTROL_CONTROLF_UNIFORM: flagNames.append("Uniform") result.append((mixerControl.szName, controlClass["name"], controlClassTypeName, ", ".join(flagNames))) return result
def GetControlValue(hmixer, mixerControl): valueDetails = MIXERCONTROLDETAILS_UNSIGNED() mixerControlDetails = MIXERCONTROLDETAILS() mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS) mixerControlDetails.item = 0 mixerControlDetails.dwControlID = mixerControl.dwControlID mixerControlDetails.cbDetails = sizeof(valueDetails) mixerControlDetails.paDetails = addressof(valueDetails) mixerControlDetails.cChannels = 1 # Get the control value rc = mixerGetControlDetails(hmixer, byref(mixerControlDetails), 0) if rc != MMSYSERR_NOERROR: raise SoundMixerException() return valueDetails.dwValue
def GetMixerControl(componentType, ctrlType, deviceId=0): """ Obtains an appropriate pointer and info for the volume control This function attempts to obtain a mixer control. Raises SoundMixerException if not successful. """ deviceId = GetDeviceId(deviceId) hmixer = HMIXER() # Obtain the hmixer struct rc = mixerOpen(byref(hmixer), deviceId, 0, 0, 0) if rc != MMSYSERR_NOERROR: raise SoundMixerException() mixerLineControls = MIXERLINECONTROLS() mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS) mixerLine = MIXERLINE() mixerLine.cbStruct = sizeof(MIXERLINE) mixerControl = MIXERCONTROL() mixerControl.cbStruct = sizeof(MIXERCONTROL) mixerLine.dwComponentType = componentType # Obtain a line corresponding to the component type rc = mixerGetLineInfo( hmixer, byref(mixerLine), MIXER_GETLINEINFOF_COMPONENTTYPE ) if rc != MMSYSERR_NOERROR: raise SoundMixerException() mixerLineControls.dwLineID = mixerLine.dwLineID mixerLineControls.dwControlType = ctrlType mixerLineControls.cControls = 1 mixerLineControls.cbmxctrl = sizeof(mixerControl) mixerLineControls.pamxctrl = pointer(mixerControl) # Get the control rc = mixerGetLineControls( hmixer, byref(mixerLineControls), MIXER_GETLINECONTROLSF_ONEBYTYPE ) if MMSYSERR_NOERROR != rc: raise SoundMixerException() return hmixer, mixerControl
def GetControls(hmixer, mixerline): numCtrls = mixerline.cControls if numCtrls == 0: return [] mixerControlArray = (MIXERCONTROL * numCtrls)() mixerLineControls = MIXERLINECONTROLS() mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS) mixerLineControls.cControls = numCtrls mixerLineControls.dwLineID = mixerline.dwLineID mixerLineControls.pamxctrl = pointer(mixerControlArray[0]) mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL) mixerGetLineControls( hmixer, byref(mixerLineControls), MIXER_GETLINECONTROLSF_ALL ) result = [] for i in range(numCtrls): mixerControl = mixerControlArray[i] dwControlType = mixerControl.dwControlType controlClass = MIXER_CONTROL_CLASSES[ dwControlType & MIXERCONTROL_CT_CLASS_MASK ] controlClassTypeName = controlClass["types"][dwControlType] flagNames = [] fdwControl = mixerControl.fdwControl if fdwControl & MIXERCONTROL_CONTROLF_DISABLED: flagNames.append("Disabled") if fdwControl & MIXERCONTROL_CONTROLF_MULTIPLE: flagNames.append("Multiple(%i)" % mixerControl.cMultipleItems) if fdwControl & MIXERCONTROL_CONTROLF_UNIFORM: flagNames.append("Uniform") result.append( ( mixerControl.szName, controlClass["name"], controlClassTypeName, ", ".join(flagNames) ) ) return result
def SetControlValue(hmixer, mixerControl, value): """ Sets the volumne from the pointer of the object passed through ' [Note: original source taken from MSDN http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q178456&] This function sets the value for a volume control. Returns True if successful """ valueDetails = MIXERCONTROLDETAILS_UNSIGNED() valueDetails.dwValue = value mixerControlDetails = MIXERCONTROLDETAILS() mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS) mixerControlDetails.item = 0 mixerControlDetails.dwControlID = mixerControl.dwControlID mixerControlDetails.cbDetails = sizeof(valueDetails) mixerControlDetails.paDetails = addressof(valueDetails) mixerControlDetails.cChannels = 1 # Set the control value rc = mixerSetControlDetails(hmixer, byref(mixerControlDetails), 0) if rc != MMSYSERR_NOERROR: raise SoundMixerException()
def GetMixerDevices(useList=False): """ Returns a list of all mixer device names available on the system. """ mixcaps = MIXERCAPS() result = [] # get the number of Mixer devices in this computer result.append("Primary Sound Driver") for i in range(mixerGetNumDevs()): # get info about the device if mixerGetDevCaps(i, byref(mixcaps), sizeof(MIXERCAPS)): continue # store the name of the device result.append(mixcaps.szPname) return result if useList else dict((i - 1, result[i]) for i in range(len(result)))