Vista以降で動作するレベルメーター(修正版)
Vista以降で動作するレベルメーター(修正版)
#module#define CLSID_IMMDeviceEnumerator "{BCDE0395-E52F-467C-8E3D-C4579291692E}"#define IID_IMMDeviceEnumerator "{A95664D2-9614-4F35-A746-DE8DB63617E6}"#define IID_IMMDevice "{D666063F-1587-4E43-81F1-B948E807363F}"#define IID_IAudioEndpointVolume "{5CDF2C82-841E-4546-9722-0CF74078229A}"#define IID_IPerChannelDbLevel "{C2F8E001-F205-4BC9-99BC-C13B1E048CCB}"#define IID_IAudioMeterInformation "{C02216F6-8C67-4B5B-9D00-D008E73E0064}"#define ERender 0x00000000#define Console 0x00000000#usecom IMMDeviceEnumerator IID_IMMDeviceEnumerator CLSID_IMMDeviceEnumerator#comfunc Enumerator_GetDefaultAudioEndpoint 4 int,int,var#usecom IMMDevice IID_IMMDevice CLSID_IMMDeviceEnumerator#comfunc Device_Activate 3 var,int,int,var#usecom IAudioEndpointVolume IID_IAudioEndpointVolume CLSID_IMMDeviceEnumerator#comfunc Volume_SetMasterVolumeLevelScalar 7 float,var#comfunc Volume_GetMasterVolumeLevelScalar 9 var#comfunc Volume_SetMute 14 int,int#comfunc Volume_GetMute 15 var#usecom IPerChannelDbLevel IID_IPerChannelDbLevel CLSID_IMMDeviceEnumerator#comfunc DbLevel_GetChannelCount 3 var#comfunc DbLevel_GetLevelRange 4 int,var,var,var#comfunc DbLevel_GetLevel 5 int,var#comfunc DbLevel_SetLevel 6 int,float,int#comfunc DbLevel_SetLevelUniform 7 float,int#comfunc DbLevel_SetLevelAllChannels 8 float,int,int#usecom IAudioMeterInformation IID_IAudioMeterInformation CLSID_IMMDeviceEnumerator#comfunc MeterInformation_GetPeakValue 3 var#comfunc MeterInformation_GetMeteringChannelCount 4 var#comfunc MeterInformation_GetChannelsPeakValues 5 int,var#comfunc MeterInformation_QueryHardwareSupport 6 var#defcfunc todouble int p1temp = 0.0lpoke temp, 4, (p1 & 0x80000000) | (((p1 & 0x7fffffff) >> 3) + ((p1 & 0x7fffffff) ! 0) * 0x38000000)lpoke temp, 0, p1 << 29return temp#deffunc _OpenDevicenewcom pMMDeviceEnumerator,IMMDeviceEnumeratorif varuse(pMMDeviceEnumerator) = 0 : _CloseDevice : return -1newcom pMMDevice,IMMDevice,-1,0newcom pAudioEndpointVolume,IAudioEndpointVolume,-1,0newcom pAudioMeterInformation,IAudioMeterInformation,-1,0Enumerator_GetDefaultAudioEndpoint pMMDeviceEnumerator,ERender,Console,pMMDeviceif varuse(pMMDevice) = 0 : _CloseDevice : return -2guid = 0x5CDF2C82 , 0x4546841E , 0xF70C2297 , 0x9A227840Device_Activate pMMDevice,guid,1,0,pAudioEndpointVolumeif varuse(pAudioEndpointVolume) = 0 : _CloseDevice : return -3guid = 0xC02216F6, 0x4B5B8C67, 0x08D0009D, 0x64003EE7Device_Activate pMMDevice,guid,1,0,pAudioMeterInformationif varuse(pAudioMeterInformation) = 0 : _CloseDevice : return -4return 0#deffunc _CloseDeviceif vartype(pAudioMeterInformation) = 6{if varuse(pAudioMeterInformation) != 0{delcom pAudioMeterInformation}}if vartype(pAudioEndpointVolume) = 6{if varuse(pAudioEndpointVolume) != 0{delcom pAudioEndpointVolume}}if vartype(pMMDevice) = 6{if varuse(pMMDevice) != 0{delcom pMMDevice}}if vartype(pMMDeviceEnumerator) = 6{if varuse(pMMDeviceEnumerator) != 0{delcom pMMDeviceEnumerator}}return#deffunc SetMasterVolumeVista int vol_OpenDeviceif stat<0 : return statuuid = 0,0,0,0Volume_SetMasterVolumeLevelScalar pAudioEndpointVolume,1.0f*(double(vol)/100.0f),uuid_CloseDevicereturn#defcfunc GetMasterVolumeVista_OpenDeviceif stat<0 : return statvol = 0Volume_GetMasterVolumeLevelScalar pAudioEndpointVolume,vol_CloseDevicereturn int(todouble(vol)*100.0f)#deffunc SetMuteVista int flag_OpenDeviceif stat<0 : return statVolume_SetMute pAudioEndpointVolume,flag,0_CloseDevicereturn#defcfunc GetMuteVista_OpenDeviceif stat<0 : return statres = 0Volume_GetMute pAudioEndpointVolume,res_CloseDevicereturn res#defcfunc GetPeakValueVista_OpenDeviceif stat<0 : return statres = 0MeterInformation_GetPeakValue pAudioMeterInformation, res_CloseDevicereturn todouble(res)#defcfunc GetChannelsPeakValuesVista int ch_OpenDeviceif stat<0 : return statres = 0MeterInformation_GetChannelsPeakValues pAudioMeterInformation, ch, res_CloseDevicereturn todouble(res)#defcfunc GetMeteringChannelCountVista_OpenDeviceif stat<0 : return statres = 0MeterInformation_GetMeteringChannelCount pAudioMeterInformation, res_CloseDevicereturn res#globalwidth 120,400repeatpeak = GetPeakValueVista()title "" + peakcolor : boxf/*if peak<0.7{color ,255}else:if peak<0.9{color 255,255}else{color 255}boxf 0, 400-peak*100*4, 120, 400*/if peak>0.9{color 255boxf 0, 400-limitf(peak,0.9,1.0)*100*4, 120, 400}if peak>0.7{color 255,255boxf 0, 400-limitf(peak,0.7,0.9)*100*4, 120, 400}if peak>0{color ,255boxf 0, 400-limitf(peak,0,0.7)*100*4, 120, 400}color 255,255,255pos 0,0mes ""+strf("%02.2f",peak*100)+"%"redraw 1wait 1redraw 0loopstop