-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jonisb/Branch-0.1
Branch 0 1
- Loading branch information
Showing
8 changed files
with
830 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
from __future__ import print_function, unicode_literals, absolute_import | ||
#from ctypes import POINTER | ||
#from ctypes.wintypes import DWORD, BOOL | ||
#from comtypes import * | ||
#from comtypes.gen.MMDeviceAPILib import * | ||
from ctypes import POINTER as _POINTER, HRESULT as _HRESULT, c_float as _c_float | ||
from ctypes.wintypes import ( | ||
BOOL as _BOOL, | ||
DWORD as _DWORD, | ||
#c_ulong as _c_ulong, | ||
UINT as _UINT, | ||
#c_int as _c_int, | ||
#c_uint32 as _c_uint32, | ||
#c_float as _c_float, | ||
#LPWSTR as _LPWSTR, | ||
#LPCWSTR as _LPCWSTR, | ||
#c_wchar_p as _PCWSTR, | ||
#LPCWSTR as _PCWSTR, | ||
#PCWSTR as _PCWSTR, | ||
) | ||
from comtypes import ( | ||
GUID as _GUID, | ||
IUnknown as _IUnknown, | ||
COMMETHOD as _COMMETHOD, | ||
STDMETHOD as _STDMETHOD, | ||
) | ||
from .MMConstants import * | ||
|
||
from ctypes import * | ||
|
||
""" | ||
typedef struct AUDIO_VOLUME_NOTIFICATION_DATA | ||
{ | ||
GUID guidEventContext; | ||
BOOL bMuted; | ||
float fMasterVolume; | ||
UINT nChannels; | ||
float afChannelVolumes[ 1 ]; | ||
} AUDIO_VOLUME_NOTIFICATION_DATA; | ||
typedef struct AUDIO_VOLUME_NOTIFICATION_DATA *PAUDIO_VOLUME_NOTIFICATION_DATA; | ||
""" | ||
class AUDIO_VOLUME_NOTIFICATION_DATA(Structure): | ||
pass | ||
AUDIO_VOLUME_NOTIFICATION_DATA._fields_ = [ | ||
('guidEventContext', _GUID), | ||
('bMuted', _BOOL), | ||
('fMasterVolume', _c_float), | ||
('nChannels', _UINT), | ||
('afChannelVolumes', (_c_float * 1)), | ||
] | ||
PAUDIO_VOLUME_NOTIFICATION_DATA = _POINTER(AUDIO_VOLUME_NOTIFICATION_DATA) | ||
|
||
IID_IAudioEndpointVolumeCallback = _GUID('{657804FA-D6AD-4496-8A60-352752AF4F89}') | ||
|
||
class IAudioEndpointVolumeCallback(_IUnknown): | ||
_iid_ = IID_IAudioEndpointVolumeCallback | ||
_methods_ = [ | ||
_COMMETHOD([], _HRESULT, 'OnNotify', | ||
(['in'], PAUDIO_VOLUME_NOTIFICATION_DATA, 'pNotify') | ||
), | ||
] | ||
|
||
IID_IAudioEndpointVolume = _GUID('{5CDF2C82-841E-4546-9722-0CF74078229A}') | ||
|
||
class IAudioEndpointVolume(_IUnknown): | ||
_iid_ = _GUID('{5CDF2C82-841E-4546-9722-0CF74078229A}') | ||
_methods_ = [ | ||
_COMMETHOD([], _HRESULT, 'RegisterControlChangeNotify', | ||
(['in'], _POINTER(IAudioEndpointVolumeCallback), 'pNotify') | ||
), | ||
_COMMETHOD([], _HRESULT, 'UnregisterControlChangeNotify', | ||
(['in'], _POINTER(IAudioEndpointVolumeCallback), 'pNotify') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetChannelCount', | ||
(['out','retval'], _POINTER(_UINT), 'pnChannelCount'), | ||
), | ||
_COMMETHOD([], _HRESULT, 'SetMasterVolumeLevel', | ||
(['in'], _c_float, 'fLevelDB'), | ||
(['in'], _POINTER(_GUID), 'pguidEventContext') | ||
), | ||
_COMMETHOD([], _HRESULT, 'SetMasterVolumeLevelScalar', | ||
(['in'], _c_float, 'fLevelDB'), | ||
(['in'], _POINTER(_GUID), 'pguidEventContext') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetMasterVolumeLevel', | ||
(['out','retval'], _POINTER(_c_float), 'pfLevelDB') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetMasterVolumeLevelScalar', | ||
(['out','retval'], _POINTER(_c_float), 'pfLevelDB') | ||
), | ||
_COMMETHOD([], _HRESULT, 'SetChannelVolumeLevel', | ||
(['in'], _UINT, 'nChannel'), | ||
(['in'], _c_float, 'fLevelDB'), | ||
(['in'], _POINTER(_GUID), 'pguidEventContext') | ||
), | ||
_COMMETHOD([], _HRESULT, 'SetChannelVolumeLevelScalar', | ||
(['in'], _UINT, 'nChannel'), | ||
(['in'], _c_float, 'fLevelDB'), | ||
(['in'], _POINTER(_GUID), 'pguidEventContext') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetChannelVolumeLevel', | ||
(['in'], _UINT, 'nChannel'), | ||
(['out','retval'], _POINTER(_c_float), 'pfLevelDB') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetChannelVolumeLevelScalar', | ||
(['in'], _UINT, 'nChannel'), | ||
(['out','retval'], _POINTER(_c_float), 'pfLevelDB') | ||
), | ||
_COMMETHOD([], _HRESULT, 'SetMute', | ||
(['in'], _BOOL, 'bMute'), | ||
(['in'], _POINTER(_GUID), 'pguidEventContext') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetMute', | ||
(['out','retval'], _POINTER(_BOOL), 'pbMute') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetVolumeStepInfo', | ||
(['out','retval'], _POINTER(_UINT), 'pnStep'), | ||
(['out','retval'], _POINTER(_UINT), 'pnStepCount'), | ||
), | ||
_COMMETHOD([], _HRESULT, 'VolumeStepUp', | ||
(['in'], _POINTER(_GUID), 'pguidEventContext') | ||
), | ||
_COMMETHOD([], _HRESULT, 'VolumeStepDown', | ||
(['in'], _POINTER(_GUID), 'pguidEventContext') | ||
), | ||
_COMMETHOD([], _HRESULT, 'QueryHardwareSupport', | ||
(['out','retval'], _POINTER(_DWORD), 'pdwHardwareSupportMask') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetVolumeRange', | ||
(['out','retval'], _POINTER(_c_float), 'pfLevelMinDB'), | ||
(['out','retval'], _POINTER(_c_float), 'pfLevelMaxDB'), | ||
(['out','retval'], _POINTER(_c_float), 'pfVolumeIncrementDB') | ||
), | ||
|
||
] | ||
|
||
if __name__ == '__main__': | ||
import sys | ||
sys.exit() | ||
import win32com | ||
import comtypes.client | ||
|
||
MMDeviceApiLib = \ | ||
GUID('{2FDAAFA3-7523-4F66-9957-9D5E7FE698F6}') | ||
IID_IMMDevice = \ | ||
GUID('{D666063F-1587-4E43-81F1-B948E807363F}') | ||
IID_IMMDeviceEnumerator = \ | ||
GUID('{A95664D2-9614-4F35-A746-DE8DB63617E6}') | ||
CLSID_MMDeviceEnumerator = \ | ||
GUID('{BCDE0395-E52F-467C-8E3D-C4579291692E}') | ||
IID_IMMDeviceCollection = \ | ||
GUID('{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}') | ||
IID_IAudioEndpointVolume = \ | ||
GUID('{5CDF2C82-841E-4546-9722-0CF74078229A}') | ||
|
||
class IMMDeviceCollection(_IUnknown): | ||
_iid_ = GUID('{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}') | ||
pass | ||
|
||
class IMMDevice(_IUnknown): | ||
_iid_ = GUID('{D666063F-1587-4E43-81F1-B948E807363F}') | ||
_methods_ = [ | ||
_COMMETHOD([], _HRESULT, 'Activate', | ||
(['in'], _POINTER(GUID), 'iid'), | ||
(['in'], _DWORD, 'dwClsCtx'), | ||
(['in'], _POINTER(_DWORD), 'pActivationParans'), | ||
(['out','retval'], _POINTER(_POINTER(IAudioEndpointVolume)), 'ppInterface') | ||
), | ||
_STDMETHOD(_HRESULT, 'OpenPropertyStore', []), | ||
_STDMETHOD(_HRESULT, 'GetId', []), | ||
_STDMETHOD(_HRESULT, 'GetState', []) | ||
] | ||
pass | ||
|
||
class IMMDeviceEnumerator(_IUnknown): | ||
_iid_ = GUID('{A95664D2-9614-4F35-A746-DE8DB63617E6}') | ||
|
||
_methods_ = [ | ||
_COMMETHOD([], _HRESULT, 'EnumAudioEndpoints', | ||
(['in'], _DWORD, 'dataFlow'), | ||
(['in'], _DWORD, 'dwStateMask'), | ||
(['out','retval'], _POINTER(_POINTER(IMMDeviceCollection)), 'ppDevices') | ||
), | ||
_COMMETHOD([], _HRESULT, 'GetDefaultAudioEndpoint', | ||
(['in'], _DWORD, 'dataFlow'), | ||
(['in'], _DWORD, 'role'), | ||
(['out','retval'], _POINTER(_POINTER(IMMDevice)), 'ppDevices') | ||
) | ||
] | ||
|
||
|
||
|
||
|
||
enumerator = comtypes.CoCreateInstance( | ||
CLSID_MMDeviceEnumerator, | ||
IMMDeviceEnumerator, | ||
comtypes.CLSCTX_INPROC_SERVER | ||
) | ||
|
||
print(enumerator) | ||
endpoint = enumerator.GetDefaultAudioEndpoint( 0, 1 ) | ||
print(endpoint) | ||
volume = endpoint.Activate( IID_IAudioEndpointVolume, comtypes.CLSCTX_INPROC_SERVER, None ) | ||
print(volume) | ||
print(volume.GetMasterVolumeLevel()) | ||
print(volume.GetVolumeRange()) | ||
#volume.SetMasterVolumeLevel(-20.0, None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import print_function, unicode_literals | ||
from comtypes import GUID as _GUID | ||
#from comtypes.client import ShowEvents, GetEvents | ||
#from _ctypes import COMError | ||
try: | ||
from MMDeviceAPILib import _tagpropertykey, eRender, eCapture, eAll, EDataFlow_enum_count, eConsole, eMultimedia, eCommunications, ERole_enum_count | ||
except ImportError: | ||
from comtypes.client import GetModule | ||
GetModule("mmdeviceapi.tlb") | ||
from comtypes.gen.MMDeviceAPILib import _tagpropertykey, eRender, eCapture, eAll, EDataFlow_enum_count, eConsole, eMultimedia, eCommunications, ERole_enum_count | ||
|
||
PROPERTYKEY = _tagpropertykey | ||
|
||
# EDataFlow enumeration: The EDataFlow enumeration defines constants that indicate the direction in which audio data flows between an audio endpoint device and an application. | ||
EDataFlow = {eRender: 'eRender', eCapture: 'eCapture', eAll: 'eAll', EDataFlow_enum_count: 'EDataFlow_enum_count'} | ||
|
||
# ERole enumeration: The ERole enumeration defines constants that indicate the role that the system has assigned to an audio endpoint device. | ||
ERole = {eConsole: 'eConsole', eMultimedia: 'eMultimedia', eCommunications: 'eCommunications', ERole_enum_count: 'ERole_enum_count'} | ||
|
||
# DEVICE_STATE_XXX Constants: The DEVICE_STATE_XXX constants indicate the current state of an audio endpoint device. | ||
DEVICE_STATE_ACTIVE = 0x00000001 | ||
DEVICE_STATE_DISABLED = 0x00000002 | ||
DEVICE_STATE_NOTPRESENT = 0x00000004 | ||
DEVICE_STATE_UNPLUGGED = 0x00000008 | ||
DEVICE_STATEMASK_ALL = 0x0000000F | ||
DEVICE_STATE = {DEVICE_STATE_ACTIVE: 'DEVICE_STATE_ACTIVE', DEVICE_STATE_DISABLED: 'DEVICE_STATE_DISABLED', DEVICE_STATE_NOTPRESENT: 'DEVICE_STATE_NOTPRESENT', DEVICE_STATE_UNPLUGGED: 'DEVICE_STATE_UNPLUGGED', DEVICE_STATEMASK_ALL: 'DEVICE_STATEMASK_ALL'} | ||
|
||
#The STGM constants are flags that indicate conditions for creating and deleting the object and access modes for the object. The STGM constants are included in the IStorage, IStream, and IPropertySetStorage interfaces and in the StgCreateDocfile, StgCreateStorageEx, StgCreateDocfileOnILockBytes, StgOpenStorage, and StgOpenStorageEx functions. | ||
#The storage-access mode. This parameter specifies whether to open the property store in read mode, write mode, or read/write mode. Set this parameter to one of the following STGM constants: | ||
STGM_READ = 0x00000000 | ||
STGM_WRITE = 0x00000001 | ||
STGM_READWRITE = 0x00000002 | ||
|
||
#Each PKEY_Xxx property identifier in the following list is a constant of type PROPERTYKEY that is defined in header file Functiondiscoverykeys_devpkey.h. All audio endpoint devices have these three device properties. | ||
PKEY_Device_FriendlyName = PROPERTYKEY(_GUID('{A45C254E-DF1C-4EFD-8020-67D146A850E0}'), 14) | ||
PKEY_Device_DeviceDesc = PROPERTYKEY(_GUID('{A45C254E-DF1C-4EFD-8020-67D146A850E0}'), 2) | ||
PKEY_DeviceInterface_FriendlyName = PROPERTYKEY(_GUID('{026E516E-B814-414B-83CD-856D6FEF4822}'), 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from ctypes import HRESULT as _HRESULT | ||
from ctypes.wintypes import ( | ||
DWORD as _DWORD, | ||
LPCWSTR as _PCWSTR, | ||
) | ||
from comtypes import IUnknown as _IUnknown | ||
from comtypes import ( | ||
GUID as _GUID, | ||
COMMETHOD as _COMMETHOD, | ||
STDMETHOD as _STDMETHOD, | ||
) | ||
|
||
CLSID_CPolicyConfigVistaClient = _GUID('{294935CE-F637-4E7C-A41B-AB255460B862}') | ||
IID_IPolicyConfigVista = _GUID('{568b9108-44bf-40b4-9006-86afe5b5a620}') | ||
class IPolicyConfigVista(_IUnknown): | ||
_iid_ = IID_IPolicyConfigVista | ||
_methods_ = ( | ||
_STDMETHOD(_HRESULT, 'GetMixFormat', []), | ||
_STDMETHOD(_HRESULT, 'GetDeviceFormat', []), | ||
_STDMETHOD(_HRESULT, 'SetDeviceFormat', []), | ||
_STDMETHOD(_HRESULT, 'GetProcessingPeriod', []), | ||
_STDMETHOD(_HRESULT, 'SetProcessingPeriod', []), | ||
_STDMETHOD(_HRESULT, 'GetShareMode', []), | ||
_STDMETHOD(_HRESULT, 'SetShareMode', []), | ||
_STDMETHOD(_HRESULT, 'GetPropertyValue', []), | ||
_STDMETHOD(_HRESULT, 'SetPropertyValue', []), | ||
_COMMETHOD([], _HRESULT, | ||
'SetDefaultEndpoint', | ||
(['in'], _PCWSTR, 'wszDeviceId'), | ||
(['in'], _DWORD, 'eRole')), | ||
_STDMETHOD(_HRESULT, 'SetEndpointVisibility', [])) | ||
|
||
if __name__ == '__main__': | ||
pass |
Oops, something went wrong.