ripdad Posted November 4, 2010 Posted November 4, 2010 (edited) Edit - See post #10 for new scriptAfter a night of study about MCI, I'm pleased to release a much needed code. Better late than never!expandcollapse popup; MCI Stereo Level Meter v0.0.3 ; Released: November 06, 2010 ; AutoIt3 v3.3.6 ; Reference: "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_recording.asp" Opt('GUIOnEventMode', 1) Local $ui = GUICreate('Stereo Level Meter', 200, 100, -1, -1, Default, 0x00000008 + 0x00000200) Local $ProgressBarL = GUICtrlCreateProgress(85, 30, 10, 60, 0x04) GUICtrlSetBkColor($ProgressBarL, 0xDDFFDD) Local $ProgressBarR = GUICtrlCreateProgress(97, 30, 10, 60, 0x04) GUICtrlSetBkColor($ProgressBarR, 0xDDFFDD) Local $L_Input = GUICtrlCreateInput('', 20, 70, 50, 18) GUICtrlSetBkColor($L_Input, 0xDDFFDD) Local $R_Input = GUICtrlCreateInput('', 120, 70, 50, 18) GUICtrlSetBkColor($R_Input, 0xDDFFDD) Local $iInput = GUICtrlCreateInput('', 2, 2, 198, 18) GUICtrlSetBkColor($iInput, 0xDDFFDD) Local $CursorTrap = GUICtrlCreateInput('', 200, 10, 4, 20) Local $btn1 = GUICtrlCreateButton('Mono', 20, 40, 50, 20) Local $btn2 = GUICtrlCreateButton('Stereo', 120, 40, 50, 20) GUISetState(@SW_SHOW, $ui) ControlFocus('', '', $CursorTrap) GUICtrlSetOnEvent($btn1, '_Mono') GUICtrlSetOnEvent($btn2, '_Stereo') GUISetOnEvent(-3, '_Exit') ; Local $Rtn, $MCI_Request[9] = [8, 'bitspersample', 'bytespersec', 'channels', 'input', 'output', 'ready', 'samplespersec', 'time format'] Global $MCI_Level, $MCI_Rtn, $LeftChannel, $RightChannel Local $Init = MCI_Open() Local $SetCh = MCI_SetCh(2) If ($Init == 0) And ($SetCh == 0) Then AdlibRegister('MCI_Status_Level', 1) ; For $i = 1 To $MCI_Request[0] $Rtn = MCI_Status($MCI_Request[$i]) GUICtrlSetData($iInput, 'MCI_Status_' & $MCI_Request[$i] & ': ' & $Rtn) If $i = $MCI_Request[0] Then $i = 0 Sleep(2000) Next ; Func _Exit() AdlibUnRegister('MCI_Status_Level') GUIDelete($ui) Exit EndFunc ; Func MCI_Status_Level() $MCI_Level = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave level', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Level[0] <> 0 Then AdlibUnRegister('MCI_Status_Level') Return EndIf $LeftChannel = Round(_LoWord((100 * $MCI_Level[2])) / 128) - 1 $RightChannel = Round(_HiWord((100 * $MCI_Level[2])) / 128) - 1 If $RightChannel = -1 Then $RightChannel = $LeftChannel GUICtrlSetData($ProgressBarL, $LeftChannel) GUICtrlSetData($ProgressBarR, $RightChannel) GUICtrlSetData($L_Input, 'L - ' & Round($LeftChannel)) GUICtrlSetData($R_Input, 'R - ' & $RightChannel) EndFunc ; Func MCI_Status($request) Local $MCI_Status = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave ' & $request, 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Status[0] <> 0 Then Return -1 Return $MCI_Status[2] EndFunc ; Func MCI_Open() Local $MCI_Open = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'open new type waveaudio alias mywave buffer 2', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Open[0] <> 0 Then Return -1 Return $MCI_Open[0] EndFunc ; Func MCI_SetCh($numchannels) Local $MCI_SetCh = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'set mywave bitspersample 8 channels ' & $numchannels & ' samplespersec 11025', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_SetCh[0] <> 0 Then Return -1 Return $MCI_SetCh[0] EndFunc ; Func _Mono() MCI_SetCh(1) EndFunc ; Func _Stereo() MCI_SetCh(2) EndFunc ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFuncUpdate: Several tweaks including using Adlib for faster speed. Included a few status requests for potential UDF. Edited December 8, 2010 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
twitchyliquid64 Posted November 5, 2010 Posted November 5, 2010 Lovely script man! I've been looking for some audio stuff myself and came up with nothing. Cheers for the effort. One other thing; How would I modify this to read a microphone? I am a dj and I wanna make a beat keeper. ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search
ripdad Posted November 5, 2010 Author Posted November 5, 2010 It reads the mixer inputs. Just open the mixer and enable mic in the recording dialog. By the way .. the readings on this meter are nominal peaks. It's not a great instrument like some meters I've seen, but it does give a fair audio indication. On another note: I think msdn has the channels backwards (ie: left is right and right is left) Anyone notice this or is this just my setup? If this is true - I'll change it. I've also made a few tweaks which I'll update soon. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
ripdad Posted November 5, 2010 Author Posted November 5, 2010 Update "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
UEZ Posted November 6, 2010 Posted November 6, 2010 (edited) You searched for a progressbar which is showing from top to buttom. I added a GDI+ progressbar which should work as you wanted but I couldn't test it because my micro is not working. expandcollapse popup[b] ; MCI Stereo Level Meter v0.0.3 ; Released: November 06, 2010 ; AutoIt3 v3.3.6 ; Reference: "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_recording.asp" #include <GDIPlus.au3> #Include <Memory.au3> _GDIPlus_Startup() Opt('GUIOnEventMode', 1) Local $ui = GUICreate('Stereo Level Meter', 200, 100, -1, -1, Default, 0x00000008 + 0x00000200) ;~ Local $ProgressBarL = GUICtrlCreateProgress(85, 30, 10, 60, 0x04) ;~ GUICtrlSetBkColor($ProgressBarL, 0xDDFFDD) ;~ Local $ProgressBarR = GUICtrlCreateProgress(97, 30, 10, 60, 0x04) ;~ GUICtrlSetBkColor($ProgressBarR, 0xDDFFDD) Local $L_Input = GUICtrlCreateInput('', 20, 70, 50, 18) GUICtrlSetBkColor($L_Input, 0xDDFFDD) Local $R_Input = GUICtrlCreateInput('', 120, 70, 50, 18) GUICtrlSetBkColor($R_Input, 0xDDFFDD) Local $iInput = GUICtrlCreateInput('', 2, 2, 198, 18) GUICtrlSetBkColor($iInput, 0xDDFFDD) Local $CursorTrap = GUICtrlCreateInput('', 200, 10, 4, 20) Local $btn1 = GUICtrlCreateButton('Mono', 20, 40, 50, 20) Local $btn2 = GUICtrlCreateButton('Stereo', 120, 40, 50, 20) ControlFocus('', '', $CursorTrap) GUICtrlSetOnEvent($btn1, '_Mono') GUICtrlSetOnEvent($btn2, '_Stereo') GUISetOnEvent(-3, '_Exit') ; Local $Rtn, $MCI_Request[9] = [8, 'bitspersample', 'bytespersec', 'channels', 'input', 'output', 'ready', 'samplespersec', 'time format'] Global $MCI_Level, $MCI_Rtn, $LeftChannel, $RightChannel, $ii Local $Init = MCI_Open() Local $SetCh = MCI_SetCh(2) Local $hBrush = _GDIPlus_BrushCreateSolid() Local $hImage = Load_BMP_From_Mem(Progressbar_Bg()) Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($ui) Local $bg_w = 10, $bg_h = 60 Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($bg_w, $bg_h, $hGraphic) Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) Progressbar(0, 0) [size=2]GUISetState(@SW_SHOW, $ui)[/size] [size=2][/size] If ($Init == 0) And ($SetCh == 0) Then AdlibRegister('MCI_Status_Level', 1) [size=2];~ [/size]AdlibRegister('MCI_Status_Level', 1) ; For $i = 1 To $MCI_Request[0] $Rtn = MCI_Status($MCI_Request[$i]) GUICtrlSetData($iInput, 'MCI_Status_' & $MCI_Request[$i] & ': ' & $Rtn) If $i = $MCI_Request[0] Then $i = 0 Sleep(2000) Next ; Func Progressbar($lChl, $rChl) _GDIPlus_GraphicsClear($hContext) _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $bg_w, $bg_h) _GDIPlus_BrushSetSolidColor($hBrush, 0x8000E000) _GDIPlus_GraphicsFillRect($hContext, 1, 1, 5, Ceiling($lChl * ($bg_h - 0.02)), $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0x80008000) _GDIPlus_GraphicsFillRect($hContext, 6, 1, 3, Ceiling($lChl * ($bg_h - 0.02)), $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0x8000FF00) _GDIPlus_GraphicsFillRect($hContext, 1, Ceiling($lChl * ($bg_h - 0.02)), 8, 1, $hBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 85, 30, $bg_w, $bg_h) _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $bg_w, $bg_h) _GDIPlus_BrushSetSolidColor($hBrush, 0x8000E000) _GDIPlus_GraphicsFillRect($hContext, 1, 1, 5, Ceiling($rChl * ($bg_h - 0.02)), $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0x80008000) _GDIPlus_GraphicsFillRect($hContext, 6, 1, 3, Ceiling($rChl * ($bg_h - 0.02)), $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0x8000FF00) _GDIPlus_GraphicsFillRect($hContext, 1, Ceiling($rChl * ($bg_h - 0.02)), 8, 1, $hBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 97, 30, $bg_w, $bg_h) Return 1 EndFunc Func _Exit() _GDIPlus_ImageDispose($hImage) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hContext) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() AdlibUnRegister('MCI_Status_Level') GUIDelete($ui) Exit EndFunc ; Func MCI_Status_Level() $MCI_Level = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave level', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Level[0] <> 0 Then AdlibUnRegister('MCI_Status_Level') Return EndIf $LeftChannel = Round(_LoWord((100 * $MCI_Level[2])) / 128) - 1 $RightChannel = Round(_HiWord((100 * $MCI_Level[2])) / 128) - 1 If $RightChannel = -1 Then $RightChannel = $LeftChannel Progressbar($LeftChannel, $RightChannel) ;~ GUICtrlSetData($ProgressBarL, $LeftChannel) ;~ GUICtrlSetData($ProgressBarR, $RightChannel) GUICtrlSetData($L_Input, 'L - ' & Round($LeftChannel)) GUICtrlSetData($R_Input, 'R - ' & $RightChannel) EndFunc ; Func MCI_Status($request) Local $MCI_Status = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave ' & $request, 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Status[0] <> 0 Then Return -1 Return $MCI_Status[2] EndFunc ; Func MCI_Open() Local $MCI_Open = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'open new type waveaudio alias mywave buffer 2', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Open[0] <> 0 Then Return -1 Return $MCI_Open[0] EndFunc ; Func MCI_SetCh($numchannels) Local $MCI_SetCh = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'set mywave bitspersample 8 channels ' & $numchannels & ' samplespersec 11025', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_SetCh[0] <> 0 Then Return -1 Return $MCI_SetCh[0] EndFunc ; Func _Mono() MCI_SetCh(1) EndFunc ; Func _Stereo() MCI_SetCh(2) EndFunc ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFunc Func Load_BMP_From_Mem($mem_image) ;coded by UEZ - thanks to progandy form the MemGlobalAlloc lines Local $memBitmap, $len, $tMem, $hImage $memBitmap = Binary($mem_image) ;load image saved in variable (memory) and convert it to binary $len = BinaryLen($memBitmap) ;get length of image $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) $pData = _MemGlobalLock($hData) ;translate the handle into a pointer $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE $hStream = _WinAPI_CreateStreamOnHGlobal($pData) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream) ;Creates a Bitmap object based on an IStream COM interface $tMem = "" Return $hBitmapFromStream EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_CreateStreamOnHGlobal ; Description ...: Creates a stream object that uses an HGLOBAL memory handle to store the stream contents ; Syntax.........: _WinAPI_CreateStreamOnHGlobal([$hGlobal = 0[, $fDeleteOnRelease = True]]) ; Parameters ....: $hGlobal - A memory handle. If 0, a new handle is to be allocated instead ; $fDeleteOnRelease - If True, the release of the IStream interface releases the memory handle as well. ; Otherwise, it's the responsibility of the user to release this memory handle. ; Return values .: Success - A pointer to new stream object ; Failure - 0 ; Remarks .......: None ; Related .......: _MemGlobalFree ; Link ..........; @@MsdnLink@@ CreateStreamOnHGlobal ; Example .......; No ; =============================================================================================================================== Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True) Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[3] EndFunc ;==>_WinAPI_CreateStreamOnHGlobal ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_BitmapCreateFromStream ; Description ...: Creates a Bitmap object based on an IStream COM interface ; Syntax.........: _GDIPlus_BitmapCreateFromStream($pStream) ; Parameters ....: $pStream - Pointer to an IStream COM interface ; Return values .: Success - Returns a handle to a new Bitmap object ; Failure - 0 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources ; Related .......: _GDIPlus_ImageDispose, _WinAPI_CreateStreamOnHGlobal ; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromStream ; Example .......; Yes ; =============================================================================================================================== Func _GDIPlus_BitmapCreateFromStream($pStream) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0) If @error Then Return SetError(@error, @extended, 0) $GDIP_STATUS = $aResult[0] Return $aResult[2] EndFunc ;==>_GDIPlus_BitmapCreateFromStream Func Progressbar_Bg() Local _ $BinaryImage = '0x89504E470D0A1A0A0000000D494844520000000A0000003C080300000068CFDB3F00000093504C5445DADADAD1D1D1DDDDDDB2B2B2D5D5D5D3D3D3D9D9D9A1A1A1C6C6C6D4D4D4D6D6D6C5C5C5CBCB' $BinaryImage &= 'CBE5E5E5CACACADBDBDBE1E1E1CCCCCCC7C7C7D7D7D7C3C3C3FAFAFAC0C0C0E7E7E7E3E3E3FCFCFC8C8C8CA5A5A59D9D9DD8D8D8949494AEAEAEC1C1C1BDBDBDF3F3F39B9B9BE0E0E0C2C2C2A8A8A8BF' $BinaryImage &= 'BFBFC4C4C4E2E2E2DCDCDC919191CFCFCFE4E4E4C8C8C8CECECEEAEAEA1C3995C00000007849444154785EEDD2351203310C405149667B19C3CC7CFFD365BC8D32394226DDEBFF87D7F2303566BBB8F6' $BinaryImage &= '6037E98E0851CD40B4C51C71DD351310E3422B756C42E439776E15AAC81148B9AFB281B9F7A7AC1C78A96B5BDE22EFA4F5E38991290124287F827F7258CECD13F01A5FC3F0463C172FF731E21B648C1B' $BinaryImage &= '772CF6E1A90000000049454E44AE426082' Return $BinaryImage EndFunc[/b] Br, UEZ Edited November 6, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
ripdad Posted November 7, 2010 Author Posted November 7, 2010 UEZ - I had a little trouble with it at first. Seems the formatting was messed up a little with html code. From your script: [size=2]GUISetState(@SW_SHOW, $ui)[/size] [size=2][/size] If ($Init == 0) And ($SetCh == 0) Then AdlibRegister('MCI_Status_Level', 1) [size=2] I cleaned it up and got it working enough to test the turn around speed of the function --> 4ms Not bad at all - the best I've seen so far. It's displaying left to right though on my screen. I'll work with it and see if I can get proper aspect. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
ripdad Posted November 7, 2010 Author Posted November 7, 2010 Okay .. I think I have the hang of it. Managed to get it down to 3ms. Thanks UEZ - you've been a great help. expandcollapse popup#include <GDIPlus.au3> #include <Memory.au3> _GDIPlus_Startup() ; Opt('GUIOnEventMode', 1) Local $ui = GUICreate('Stereo Level Meter', 200, 200, -1, -1, Default, 0x00000008 + 0x00000200) Local $L_Input = GUICtrlCreateInput('', 20, 70, 50, 18) GUICtrlSetBkColor($L_Input, 0xDDFFDD) Local $iInput = GUICtrlCreateInput('', 2, 2, 198, 18) GUICtrlSetBkColor($iInput, 0xDDFFDD) Local $CursorTrap = GUICtrlCreateInput('', 200, 10, 4, 20) ; Local $hBrush = _GDIPlus_BrushCreateSolid() Local $hImage = Load_BMP_From_Mem(Progressbar_Bg()); Load Background Image Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($ui) Local $bg_w = 10, $bg_h = 100 Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($bg_w, $bg_h, $hGraphic) Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) Progressbar(0, 0) ; GUISetState(@SW_SHOW, $ui) ControlFocus('', '', $CursorTrap) GUISetOnEvent(-3, '_Exit') ; Local $Rtn, $MCI_Request[9] = [8, 'bitspersample', 'bytespersec', 'channels', 'input', 'output', 'ready', 'samplespersec', 'time format'] Global $MCI_Level, $MCI_Rtn, $LeftChannel, $RightChannel Local $Init = MCI_Open() Local $SetCh = MCI_SetCh(2) ; If ($Init == 0) And ($SetCh == 0) Then AdlibRegister('MCI_AdLib', 4) ; For $i = 1 To $MCI_Request[0] $Rtn = MCI_Status($MCI_Request[$i]) GUICtrlSetData($iInput, 'MCI_Status_' & $MCI_Request[$i] & ': ' & $Rtn) If $i = $MCI_Request[0] Then $i = 0 Sleep(2000) Next ; Func MCI_AdLib() $timer = TimerInit() MCI_Status_Level() GUICtrlSetData($L_Input, Round(TimerDiff($timer)) & 'ms') EndFunc ; Func Progressbar($lChl, $rChl) _GDIPlus_GraphicsClear($hContext) ; Left Channel _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $bg_w, $bg_h) _GDIPlus_BrushSetSolidColor($hBrush, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext, 1, 1, 8, $lChl, $hBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 85, 40, $bg_w, $bg_h) ; Right Channel _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $bg_w, $bg_h) _GDIPlus_BrushSetSolidColor($hBrush, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext, 1, 1, 8, $rChl, $hBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 97, 40, $bg_w, $bg_h); Position and Draw Return 1 EndFunc ; Func _Exit() _GDIPlus_ImageDispose($hImage) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hContext) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() AdlibUnRegister('MCI_Status_Level') GUIDelete($ui) Exit EndFunc ; Func MCI_Status_Level() $MCI_Level = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave level', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Level[0] <> 0 Then AdlibUnRegister('MCI_Status_Level') Return EndIf $LeftChannel = Round(_LoWord((100 * $MCI_Level[2])) / 128) - 1 $RightChannel = Round(_HiWord((100 * $MCI_Level[2])) / 128) - 1 If $RightChannel = -1 Then $RightChannel = $LeftChannel Progressbar($LeftChannel, $RightChannel) EndFunc ; Func MCI_Status($request) Local $MCI_Status = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'status mywave ' & $request, 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Status[0] <> 0 Then Return -1 Return $MCI_Status[2] EndFunc ; Func MCI_Open() Local $MCI_Open = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'open new type waveaudio alias mywave buffer 2', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_Open[0] <> 0 Then Return -1 Return $MCI_Open[0] EndFunc ; Func MCI_SetCh($numchannels) Local $MCI_SetCh = DllCall('winmm.dll', 'long', 'mciSendStringA', 'str', 'set mywave bitspersample 8 channels ' & $numchannels & ' samplespersec 11025', 'str', $MCI_Rtn, 'long', 64, 'long', 0) If $MCI_SetCh[0] <> 0 Then Return -1 Return $MCI_SetCh[0] EndFunc ; Func _Mono() MCI_SetCh(1) EndFunc ; Func _Stereo() MCI_SetCh(2) EndFunc ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFunc Func Load_BMP_From_Mem($mem_image) ;coded by UEZ - thanks to progandy form the MemGlobalAlloc lines Local $memBitmap, $len, $tMem, $hImage $memBitmap = Binary($mem_image) ;load image saved in variable (memory) and convert it to binary $len = BinaryLen($memBitmap) ;get length of image $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) $pData = _MemGlobalLock($hData) ;translate the handle into a pointer $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE $hStream = _WinAPI_CreateStreamOnHGlobal($pData) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream) ;Creates a Bitmap object based on an IStream COM interface $tMem = "" Return $hBitmapFromStream EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_CreateStreamOnHGlobal ; Description ...: Creates a stream object that uses an HGLOBAL memory handle to store the stream contents ; Syntax.........: _WinAPI_CreateStreamOnHGlobal([$hGlobal = 0[, $fDeleteOnRelease = True]]) ; Parameters ....: $hGlobal - A memory handle. If 0, a new handle is to be allocated instead ; $fDeleteOnRelease - If True, the release of the IStream interface releases the memory handle as well. ; Otherwise, it's the responsibility of the user to release this memory handle. ; Return values .: Success - A pointer to new stream object ; Failure - 0 ; Remarks .......: None ; Related .......: _MemGlobalFree ; Link ..........; @@MsdnLink@@ CreateStreamOnHGlobal ; Example .......; No ; =============================================================================================================================== Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True) Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[3] EndFunc ;==>_WinAPI_CreateStreamOnHGlobal ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_BitmapCreateFromStream ; Description ...: Creates a Bitmap object based on an IStream COM interface ; Syntax.........: _GDIPlus_BitmapCreateFromStream($pStream) ; Parameters ....: $pStream - Pointer to an IStream COM interface ; Return values .: Success - Returns a handle to a new Bitmap object ; Failure - 0 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources ; Related .......: _GDIPlus_ImageDispose, _WinAPI_CreateStreamOnHGlobal ; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromStream ; Example .......; Yes ; =============================================================================================================================== Func _GDIPlus_BitmapCreateFromStream($pStream) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0) If @error Then Return SetError(@error, @extended, 0) $GDIP_STATUS = $aResult[0] Return $aResult[2] EndFunc ;==>_GDIPlus_BitmapCreateFromStream Func Progressbar_Bg(); PNG Graphic Local _ $BinaryImage = '0x89504E470D0A1A0A0000000D494844520000000A0000003C080300000068CFDB3F00000093504C5445DADADAD1D1D1DDDDDDB2B2B2D5D5D5D3D3D3D9D9D9A1A1A1C6C6C6D4D4D4D6D6D6C5C5C5CBCB' $BinaryImage &= 'CBE5E5E5CACACADBDBDBE1E1E1CCCCCCC7C7C7D7D7D7C3C3C3FAFAFAC0C0C0E7E7E7E3E3E3FCFCFC8C8C8CA5A5A59D9D9DD8D8D8949494AEAEAEC1C1C1BDBDBDF3F3F39B9B9BE0E0E0C2C2C2A8A8A8BF' $BinaryImage &= 'BFBFC4C4C4E2E2E2DCDCDC919191CFCFCFE4E4E4C8C8C8CECECEEAEAEA1C3995C00000007849444154785EEDD2351203310C405149667B19C3CC7CFFD365BC8D32394226DDEBFF87D7F2303566BBB8F6' $BinaryImage &= '6037E98E0851CD40B4C51C71DD351310E3422B756C42E439776E15AAC81148B9AFB281B9F7A7AC1C78A96B5BDE22EFA4F5E38991290124287F827F7258CECD13F01A5FC3F0463C172FF731E21B648C1B' $BinaryImage &= '772CF6E1A90000000049454E44AE426082' Return $BinaryImage EndFunc #cs ( Save ) Func Progressbar($lChl, $rChl) _GDIPlus_GraphicsClear($hContext) ; Left Channel _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $bg_w, $bg_h) _GDIPlus_BrushSetSolidColor($hBrush, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext, 1, 1, 8, $lChl, $hBrush); Ceiling($lChl * ($bg_h - 0.02)), $hBrush) ;_GDIPlus_BrushSetSolidColor($hBrush, 0x80008000) ;_GDIPlus_GraphicsFillRect($hContext, 6, 1, 3, $lChl, $hBrush); Ceiling($lChl * ($bg_h - 0.02)), $hBrush) ;_GDIPlus_BrushSetSolidColor($hBrush, 0x8000FF00) ;_GDIPlus_GraphicsFillRect($hContext, 1, $lChl, 8, 1, $hBrush); Ceiling($lChl * ($bg_h - 0.02)), 8, 1, $hBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 85, 30, $bg_w, $bg_h); ### Position and Draw ; Right Channel _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $bg_w, $bg_h) _GDIPlus_BrushSetSolidColor($hBrush, 0xF000E000) _GDIPlus_GraphicsFillRect($hContext, 1, 1, 8, $rChl, $hBrush); Ceiling($rChl * ($bg_h - 0.02)), $hBrush) ;_GDIPlus_BrushSetSolidColor($hBrush, 0x80008000) ;_GDIPlus_GraphicsFillRect($hContext, 6, 1, 3, $rChl, $hBrush); Ceiling($rChl * ($bg_h - 0.02)), $hBrush) ;_GDIPlus_BrushSetSolidColor($hBrush, 0x8000FF00) ;_GDIPlus_GraphicsFillRect($hContext, 1, $rChl, 8, 1, $hBrush); $rChl * ($bg_h - 0.02)), 8, 1, $hBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 97, 30, $bg_w, $bg_h); ### Position and Draw Return 1 EndFunc #ce "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
ripdad Posted November 23, 2010 Author Posted November 23, 2010 (edited) This is just too cool not to share.- It has up-to-date code for the stand-alone MCI Stereo Level Meter.- Includes calibration and decay rate.expandcollapse popup; Released: Nov-23-2010 Local $ui = GUICreate('MCI Stereo Level Meter', 250, 120, -1, -1, Default, 0x00000008) Local $ctp = GUICtrlCreateInput('', 185, 5, 4, 20) Global $pbl = GUICtrlCreateInput('', 25, 12, 200, 16, 0x00, 0x00000020) GUICtrlSetFont($pbl, 6, 600, Default, 'arial narrow') GUICtrlSetBkColor($pbl, 0x000000) GUICtrlSetColor($pbl, 0x00FFFF) Global $pbr = GUICtrlCreateInput('', 25, 28, 200, 16, 0x00, 0x00000020) GUICtrlSetFont($pbr, 6, 600, Default, 'arial narrow') GUICtrlSetBkColor($pbr, 0x000000) GUICtrlSetColor($pbr, 0x00FFFF) GUICtrlCreateLabel('Calibrate', 10, 60, 45, 15) Local $cal = GUICtrlCreateSlider(60, 60, 150, 15) Local $calN = GUICtrlCreateLabel('30', 220, 60, 28, 15) GUICtrlSetLimit($cal, 100, 0) GUICtrlSetData($cal, 50) GUICtrlCreateLabel('Decay', 10, 90, 45, 15) Local $dec = GUICtrlCreateSlider(60, 90, 150, 15) Local $decN = GUICtrlCreateLabel('1', 220, 90, 28, 15) GUICtrlSetLimit($dec, 11, 1) GUICtrlSetData($dec, 6) GUISetState(@SW_SHOW, $ui) ControlFocus('', '', $ctp) ; Global $mciLevel, $LeftChannel, $RightChannel, $rs, $temp, $sDiv, $tDiv, $tDec, $decay Global $mciDll = DllOpen(@SystemDir & '\winmm.dll') If @error Then Exit mciInit() AdLibRegister('mci_Status_Level', 3) ; Do; Main loop $rs = GUICtrlRead($cal) If $rs <> $tDiv Then $tDiv = $rs $sDiv = (100 / $tDiv) GUICtrlSetData($calN, $tDiv) ControlFocus('', '', $ctp) EndIf $rs = GUICtrlRead($dec) If $rs <> $tDec Then $tDec = $rs $decay = $rs / 4 GUICtrlSetData($decN, $decay) ControlFocus('', '', $ctp) EndIf Until GUIGetMsg() = -3 ; ; Cleanup before exit AdLibUnRegister('mci_Status_Level') GUIDelete($ui) mciSendString('stop myStatus') mciSendString('close myStatus') DllClose($mciDll) Exit ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFunc ; Func n2sRepeat($sNum = '', $string = '|', $sRtn = ''); Element repeater For $n = 1 To $sNum $sRtn &= $string Next Return $sRtn EndFunc ; Func mciInit(); Open a live stream and set 2 channel parameters mciSendString('open new type waveaudio alias myStatus buffer 2') If @error Then Exit mciSendString('set myStatus bitspersample 8 channels 2 samplespersec 11025') If @error Then Exit EndFunc ; Func mci_Status_Level(); Get levels and apply decay rate $mciLevel = mciSendString('status myStatus level') If @error Then Exit $temp = Round((_LoWord($mciLevel) / 128) * 100 / $sDiv) - 1 If $temp > $LeftChannel Then $LeftChannel = $temp; <-- snitched from bassenc udf - thanks BrettF $temp = Round((_HiWord($mciLevel) / 128) * 100 / $sDiv) - 1 If $temp > $RightChannel Then $RightChannel = $temp; <-- GUICtrlSetData($pbl, n2sRepeat($LeftChannel)) GUICtrlSetData($pbr, n2sRepeat($RightChannel)) $LeftChannel -= $decay; <-- $RightChannel -= $decay; <-- EndFunc ; Func mciSendString($string = '', $mciMsg = ''); Custom MCI Command and Error Function (Nov-19-2010) $mciMsg = DllCall($mciDll, 'long', 'mciSendStringA', 'str', $string, 'str', '', 'int', 180, 'ptr', 0) If @error Then Return SetError(@error) If $mciMsg[0] <> 0 Then Local $eMsg = DllCall($mciDll, 'long', 'mciGetErrorStringA', 'int', $mciMsg[0], 'str', '', 'int', 180) If @error Then Return SetError(@error) MsgBox(8208, 'MCI Stereo Level Meter', 'MCI Error: ' & $mciMsg[0] & @CRLF & $eMsg[2]) Return SetError(-1) EndIf SetError(0) Return $mciMsg[2] EndFunc ;EditChanged some math Edited November 24, 2010 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
ripdad Posted November 23, 2010 Author Posted November 23, 2010 (edited) Here's another using GDIPlus ...expandcollapse popup; Released: Nov-23-2010 [with GDIPlus] #include <GDIPlus.au3> Local $ui = GUICreate('MCI Stereo Level Meter', 300, 120, -1, -1, Default, 0x00000008) Local $ctp = GUICtrlCreateInput('', 300, 5, 4, 15) GUICtrlCreateLabel('Calibrate', 10, 40, 45, 15) Local $cal = GUICtrlCreateSlider(60, 40, 150, 15) Local $calN = GUICtrlCreateLabel('50', 220, 40, 28, 15) GUICtrlSetLimit($cal, 100, 0) GUICtrlSetData($cal, 50) GUICtrlCreateLabel('Decay', 10, 70, 45, 15) Local $dec = GUICtrlCreateSlider(60, 70, 150, 15) Local $decN = GUICtrlCreateLabel('1.5', 220, 70, 28, 15) GUICtrlSetLimit($dec, 11, 1) GUICtrlSetData($dec, 6) ; _GDIPlus_Startup() Global $hImage1, $hBrush1 = _GDIPlus_BrushCreateSolid() Global $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($ui) Global $bg_w1 = 10, $bg_h1 = 80 Global $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($bg_w1, $bg_h1, $hGraphic1) Global $hContext1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1) GUISetState(@SW_SHOW, $ui) ControlFocus('', '', $ctp) ; Global $mciLevel, $LeftChannel, $RightChannel, $rs, $temp, $sDiv, $tDiv, $tDec, $decay Global $mciDll = DllOpen(@SystemDir & '\winmm.dll') If @error Then Exit mciInit() AdLibRegister('mci_Status_Level', 3) ; Do; Main loop $rs = GUICtrlRead($cal) If $rs <> $tDiv Then $tDiv = $rs $sDiv = (100 / $tDiv) GUICtrlSetData($calN, $tDiv) ControlFocus('', '', $ctp) EndIf $rs = GUICtrlRead($dec) If $rs <> $tDec Then $tDec = $rs $decay = $rs / 4 GUICtrlSetData($decN, $decay) ControlFocus('', '', $ctp) EndIf Until GUIGetMsg() = -3 ; ; Cleanup before exit AdLibUnRegister('mci_Status_Level') GUIDelete($ui) mciSendString('stop myStatus') mciSendString('close myStatus') DllClose($mciDll) Exit ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFunc ; Func mciInit(); Open a live stream and set 2 channel parameters mciSendString('open new type waveaudio alias myStatus buffer 2') If @error Then Exit mciSendString('set myStatus bitspersample 8 channels 2 samplespersec 11025') If @error Then Exit EndFunc ; Func mci_Status_Level(); Get levels and apply decay rate $mciLevel = mciSendString('status myStatus level') If @error Then Exit $temp = Round((_LoWord($mciLevel) / 128) * 100 / $sDiv) - 1 If $temp > $LeftChannel Then $LeftChannel = $temp; <-- snitched from bassenc udf - thanks BrettF $temp = Round((_HiWord($mciLevel) / 128) * 100 / $sDiv) - 1 If $temp > $RightChannel Then $RightChannel = $temp; <-- _GDIPlus_GraphicsClear($hContext1); Left Channel _GDIPlus_BrushSetSolidColor($hBrush1, 0xFEFFFFC0) _GDIPlus_GraphicsFillRect($hContext1, 1, 63, 8, 2, $hBrush1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xFE00D300) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 8, $LeftChannel, $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 259, 100, $bg_w1, -$bg_h1) _GDIPlus_GraphicsClear($hContext1); Right Channel _GDIPlus_BrushSetSolidColor($hBrush1, 0xFEFFFFC0) _GDIPlus_GraphicsFillRect($hContext1, 1, 63, 8, 2, $hBrush1) _GDIPlus_BrushSetSolidColor($hBrush1, 0xFE00D300) _GDIPlus_GraphicsFillRect($hContext1, 1, 1, 8, $RightChannel, $hBrush1) _GDIPlus_GraphicsDrawImageRect($hGraphic1, $hBitmap1, 270, 100, $bg_w1, -$bg_h1) $LeftChannel -= $decay; <-- $RightChannel -= $decay; <-- EndFunc ; Func mciSendString($string = '', $mciMsg = ''); Custom MCI Command and Error Function (Nov-19-2010) $mciMsg = DllCall($mciDll, 'long', 'mciSendStringA', 'str', $string, 'str', '', 'int', 180, 'ptr', 0) If @error Then Return SetError(@error) If $mciMsg[0] <> 0 Then Local $eMsg = DllCall($mciDll, 'long', 'mciGetErrorStringA', 'int', $mciMsg[0], 'str', '', 'int', 180) If @error Then Return SetError(@error) MsgBox(8208, 'MCI Stereo Level Meter', 'MCI Error: ' & $mciMsg[0] & @CRLF & $eMsg[2]) Return SetError(-1) EndIf SetError(0) Return $mciMsg[2] EndFunc ;EditChanged some math Edited November 24, 2010 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
ripdad Posted December 8, 2010 Author Posted December 8, 2010 MCI Stereo Level Meter with Advanced Graphics Released: Dec-08-2010 Basically, there are 3 graphic layers at work in this one. 1) The background Gradient GDI+ image 2) The left and right Gradient GDI+ image 3) The transparent PNG scale overlay We'll concentrate on the 3rd. How is it done? Draw the image in an image editor. I used Paint Shop Pro. First, paint the background of it in some bright color you won't be using. I used green. Then draw whatever image on top of it. When done, save as filetype image.png. Click out. In IrfanView, open image.png and then save as trans-image.png. A box will come up... make sure "Save Transparent Color" is check-marked. Click save. Click on green color. Click out. You now have the transparent overlay. Convert trans-image.png to binary and add it in like the one at the bottom of the script. Have fun! expandcollapse popup; MCI Stereo Level Meter with Advanced Graphics ; Released: Dec-08-2010 ; #include <GDIPlus.au3> #include <Memory.au3> Global $mciLevel, $LeftChannel, $RightChannel, $temp, $peakL, $peakR, $decay = 4 Global $mciDll = DllOpen(@SystemDir & '\winmm.dll') If @error Then Exit mciInit() _GDIPlus_Startup() Local $ui = GUICreate("Example", 300, 200, 200, 200, Default, 0x00000008) GUISetBKColor(0x000000) If @OSBuild < 7600 Then WinSetTrans($ui, "", 0xFF); workaround for XP machines Global $Scale = Load_BMP_From_Mem(BinaryImage()); Load Scale Overlay Image Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($ui) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(200, 18, $hGraphic) Global $ContextA = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; Global $YellowBrush = _GDIPlus_BrushCreateSolid() _GDIPlus_BrushSetSolidColor($YellowBrush, 0xFFFFFF00) ; Local $aFact[4] = [0.0, 0.0, 0.0, 0.0] Local $aPosit[4] = [0.0, 0.0, 0.0, 0.0] Local $iX = 0, $iY = 0, $iWidth = 240, $iHeight = 9 Global $hBrushLn = GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFact, $aPosit, 0xFF55EE00, 0xFFFF0000, 0x00000000) Global $hBrushBg = GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, 18, $aFact, $aPosit, 0xFF55AA00, 0xFF550000, 0x00000000) ; GUISetState(@SW_SHOW, $ui) AdLibRegister('mci_Status_Level', 10) ; Do; Main loop Until GUIGetMsg() = -3 ; ; Cleanup before exit AdLibUnRegister('mci_Status_Level') GUIDelete($ui) mciSendString('stop myStatus') mciSendString('close myStatus') DllClose($mciDll) _GDIPlus_BitmapDispose($Scale) _GDIPlus_BrushDispose($hBrushBg) _GDIPlus_BrushDispose($hBrushLn) _GDIPlus_BrushDispose($YellowBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Exit ; Func _HiWord($value); From WinAPI.au3 Return BitShift($value, 16) EndFunc ; Func _LoWord($value); From WinAPI.au3 Return BitAND($value, 0xFFFF) EndFunc ; Func mciInit(); Open a live stream and set 2 channel parameters mciSendString('open new type waveaudio alias myStatus buffer 2') If @error Then Exit mciSendString('set myStatus bitspersample 8 channels 2 samplespersec 11025') If @error Then Exit EndFunc Func mci_Status_Level() $mciLevel = mciSendString('status myStatus level') If @error Then Exit $temp = Round((_LoWord($mciLevel) / 128) * 200) - 1 If $temp > $LeftChannel Then $LeftChannel = $temp; <-- snitched from bassenc udf - thanks BrettF If $temp > $peakL Then $peakL = $temp If $temp < 2 Then $peakL = $temp $temp = Round((_HiWord($mciLevel) / 128) * 200) - 1 If $temp > $RightChannel Then $RightChannel = $temp; <-- If $temp > $peakR Then $peakR = $temp If $temp < 2 Then $peakR = $temp ; _GDIPlus_GraphicsClear($ContextA); Clear Contents _GDIPlus_GraphicsFillRect($ContextA, 0, 0, 200, 18, $hBrushBg); Gradient BackGround Brush _GDIPlus_GraphicsFillRect($ContextA, 0, 0, $LeftChannel, 9, $hBrushLn); Gradient Channel Brush (Left) _GDIPlus_GraphicsFillRect($ContextA, $peakL, 2, 2, 6, $YellowBrush); yellow peak brush (Left) _GDIPlus_GraphicsFillRect($ContextA, 0, 9, $RightChannel, 9, $hBrushLn); Gradient Channel Brush (Right) _GDIPlus_GraphicsFillRect($ContextA, $peakR, 10, 2, 6, $YellowBrush); yellow peak brush (Right) _GDIPlus_GraphicsDrawImageRect($ContextA, $Scale, 0, 0, 200, 18); Transparent overlay scale (PNG image) ; ; You can also draw it on .. but you're limited as to what and how you want the graphic made. ; _GDIPlus_GraphicsDrawString($ContextA, ' -24 -12 -6 -3 -1', 0, 2, "Arial", 10, 0) ; _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 50, 90, 200, 18); Draw the complete graphic ; $LeftChannel -= $decay; <-- $RightChannel -= $decay; <-- $peakL -= 0.5 $peakR -= 0.5 EndFunc Func mciSendString($string = '', $mciMsg = ''); Custom MCI Command and Error Function (Nov-19-2010) $mciMsg = DllCall($mciDll, 'long', 'mciSendStringA', 'str', $string, 'str', '', 'int', 180, 'ptr', 0) If @error Then Return SetError(@error) If $mciMsg[0] <> 0 Then Local $eMsg = DllCall($mciDll, 'long', 'mciGetErrorStringA', 'int', $mciMsg[0], 'str', '', 'int', 180) If @error Then Return SetError(@error) MsgBox(8208, 'MCI Stereo Level Meter', 'MCI Error: ' & $mciMsg[0] & @CRLF & $eMsg[2]) Return SetError(-1) EndIf Return $mciMsg[2] EndFunc ; ==== GDIPlus_CreateLineBrushFromRect === ; Author: Malkey ; Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors. ; $aFactors - If non-array, default array will be used. ; Pointer to an array of real numbers that specify blend factors. Each number in the array ; specifies a percentage of the ending color and should be in the range from 0.0 through 1.0. ; $aPositions - If non-array, default array will be used. ; Pointer to an array of real numbers that specify blend factors' positions. Each number in the array ; indicates a percentage of the distance between the starting boundary and the ending boundary ; and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the ; gradient and 1.0 indicates the ending boundary. There must be at least two positions ; specified: the first position, which is always 0.0, and the last position, which is always ; 1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a ; line, parallel to the boundary lines, that is a certain fraction of the distance from the ; starting boundary to the ending boundary. For example, a blend position of 0.7 indicates ; the line that is 70 percent of the distance from the starting boundary to the ending boundary. ; The color is constant on lines that are parallel to the boundary lines. ; $iArgb1 - First Top color in 0xAARRGGBB format ; $iArgb2 - Second color in 0xAARRGGBB format ; $LinearGradientMode - LinearGradientModeHorizontal = 0x00000000, ; LinearGradientModeVertical = 0x00000001, ; LinearGradientModeForwardDiagonal = 0x00000002, ; LinearGradientModeBackwardDiagonal = 0x00000003 ; $WrapMode - WrapModeTile = 0, ; WrapModeTileFlipX = 1, ; WrapModeTileFlipY = 2, ; WrapModeTileFlipXY = 3, ; WrapModeClamp = 4 ; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2, ; LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient) ; Reference: http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx ; Func GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0) Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000 If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001 If $WrapMode = -1 Then $WrapMode = 1 $tRect = DllStructCreate("float X;float Y;float Width;float Height") $pRect = DllStructGetPtr($tRect) DllStructSetData($tRect, "X", $iX) DllStructSetData($tRect, "Y", $iY) DllStructSetData($tRect, "Width", $iWidth) DllStructSetData($tRect, "Height", $iHeight) $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0) If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0] If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0] $iCount = UBound($aPositions) $tFactors = DllStructCreate("float[" & $iCount & "]") $pFactors = DllStructGetPtr($tFactors) For $iI = 0 To $iCount - 1 DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1) Next $tPositions = DllStructCreate("float[" & $iCount & "]") $pPositions = DllStructGetPtr($tPositions) For $iI = 0 To $iCount - 1 DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1) Next DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], "ptr", $pFactors, "ptr", $pPositions, "int", $iCount) Return $aRet[6] EndFunc Func Load_BMP_From_Mem($mem_image) ;coded by UEZ - thanks to progandy form the MemGlobalAlloc lines Local $memBitmap, $len, $tMem, $hImage $memBitmap = Binary($mem_image) ;load image saved in variable (memory) and convert it to binary $len = BinaryLen($memBitmap) ;get length of image $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002) $pData = _MemGlobalLock($hData) ;translate the handle into a pointer $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data _MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE $hStream = _WinAPI_CreateStreamOnHGlobal($pData) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($hStream) ;Creates a Bitmap object based on an IStream COM interface $tMem = "" Return $hBitmapFromStream EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_CreateStreamOnHGlobal ; Description ...: Creates a stream object that uses an HGLOBAL memory handle to store the stream contents ; Syntax.........: _WinAPI_CreateStreamOnHGlobal([$hGlobal = 0[, $fDeleteOnRelease = True]]) ; Parameters ....: $hGlobal - A memory handle. If 0, a new handle is to be allocated instead ; $fDeleteOnRelease - If True, the release of the IStream interface releases the memory handle as well. ; Otherwise, it's the responsibility of the user to release this memory handle. ; Return values .: Success - A pointer to new stream object ; Failure - 0 ; Remarks .......: None ; Related .......: _MemGlobalFree ; Link ..........; @@MsdnLink@@ CreateStreamOnHGlobal ; Example .......; No ; =============================================================================================================================== Func _WinAPI_CreateStreamOnHGlobal($hGlobal = 0, $fDeleteOnRelease = True) Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $hGlobal, "int", $fDeleteOnRelease, "ptr*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[3] EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _GDIPlus_BitmapCreateFromStream ; Description ...: Creates a Bitmap object based on an IStream COM interface ; Syntax.........: _GDIPlus_BitmapCreateFromStream($pStream) ; Parameters ....: $pStream - Pointer to an IStream COM interface ; Return values .: Success - Returns a handle to a new Bitmap object ; Failure - 0 and either: ; |@error and @extended are set if DllCall failed ; |$GDIP_STATUS contains a non zero value specifying the error code ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources ; Related .......: _GDIPlus_ImageDispose, _WinAPI_CreateStreamOnHGlobal ; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromStream ; Example .......; Yes ; =============================================================================================================================== Func _GDIPlus_BitmapCreateFromStream($pStream) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0) If @error Then Return SetError(@error, @extended, 0) $GDIP_STATUS = $aResult[0] Return $aResult[2] EndFunc Func BinaryImage($bin = 0); Transparent PNG Graphic $bin = "0x89504E470D0A1A0A0000000D49484452000000C8000000120802000000919F06800000000674524E53004000FF0040" & _ "FE112AA5000000097048597300000AEB00000AEB01828B0D5A000001E849444154785EED59FD8E833008D7CB3DD8F6E4" & _ "DB9BF5985C4853C052A5984CCCFED816CAEFA394565D1FE5B118AEF7FA36461A92754222B1804A301C89FF6EDC9FF375" & _ "9019D201EEC01AD687D2FD5B39901DEB56D31D27562DACD7F2C20FE722FE799232CFB943E02456335C93E98B2282CE70" & _ "B24B3B06542E2CC07E2ECF75BB1A1EF8130E9E5D01C6009AD73AE70E01635A631801392AEA4287A9D396508058B9B0A0" & _ "AAF09E054F60C4031DE91A37148015DC0CD1080C65EE06A39C5A6977884B408C3A4E55B4DA45114FF2ABE5C592AA2B89" & _ "A66129CE64C41B084EC019754BF769C09B1CF705B3CF16D461EF8FC79D61A35A58B4DFD53AEB055D7F3FC94CC412733A" & _ "82627E0E4DCDB294326F8E45C9D8B73EB8803CE7B25BED8EFFBF15D289AAD9F5EA8778C0125C40AEF0E530158E155355" & _ "D81EF0E0581F32F88E7F589A365093DC9C34C270DD81F6B6C27A3FE2AD0297178E87AAC2857EF8195877A07BAF22E55D" & _ "E849A6737B27013569AFD2AB9EB1E8F041E78086A217636AD7D805693FE204DC6702B0A8F5CEDB07396DC0BA6493D2AC" & _ "76371612AA4FDE9B3BD2A68C7CDF738958FB041CBD2020AFA562E476096E98ABF94AC758061936E640BED219F32BA38D" & _ "0E6461198DCAB03107AC8515F01280884762016830DC55328371AD853556AE197D7B07FE0050490DCA8B638EE3000000" & _ "0049454E44AE426082" Return $bin EndFunc "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now