Hey,
mein erstes veröffentliches Script seit langem und eigentlich mein erstes GDI+ Experiment.
Ihr könnt damit eine MP3 Datei öffnen und den Pegel grafisch darstellen lassen:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=SoundPegel.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Bass.au3>
#include <BassConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <GdiPlus.au3>
$l_max = 0
$r_max = 0
$fps = 0
;~ BASS
_BASS_STARTUP("bass.dll")
_BASS_Init(0, -1, 44100, 0, "")
If @error Then
MsgBox(16,"ERROR","")
Exit
EndIf
$file = FileOpenDialog("Öffne Datei","","MP3 (*.mp3)")
$diff = InputBox("Toleranz","Gebe den Toleranzwert ein",1)
$hMusic = _BASS_StreamCreateFile(False,$file, 0, 0, 0)
_BASS_ChannelPlay($hMusic, 1)
$hLevels = _BASS_ChannelGetLevel ($hMusic)
$hLevels_l = (_BASS_HiWord ($hLevels) / 32768) * 100
$hLevels_r = (_BASS_LoWord ($hLevels) / 32768) * 100
AdlibRegister("_FPS",1000)
;~ GUI
$hGui = GUICreate("SoundPegel", 615, 166)
GUISetBkColor(0x000000)
GUISetState(@SW_SHOW)
GUISetState(@SW_MAXIMIZE)
;~ Texte - Labels
;~ Links
$lbl_1 = GUICtrlCreateLabel("",@DesktopWidth / 2 - 70,@DesktopHeight-80,100,50)
_font_set($lbl_1)
;~ Rechts
$lbl_2 = GUICtrlCreateLabel("",@DesktopWidth / 2 + 140,@DesktopHeight-80,100,50)
_font_set($lbl_2)
;~ Max Werte
$lbl_max_l = GUICtrlCreateLabel("",@DesktopWidth / 2 - 90,@DesktopHeight-60,100,50)
$lbl_max_r = GUICtrlCreateLabel("",@DesktopWidth / 2 + 120,@DesktopHeight-60,100,50)
_font_set($lbl_max_l)
_font_set($lbl_max_r)
;~ FPS
$lbl_fps = GUICtrlCreateLabel("",10,10,100,100)
_font_set($lbl_fps)
;~ GDI+
_GDIPlus_Startup() ;Starten
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF00E5FF) ;Brush setzen
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_GDIPlus_Shutdown() ;GDI+
_BASS_Free() ;BASS
Exit
EndSwitch
;~ Pegel bekommen
$hLevels_l_alt = $hLevels_l
$hLevels_r_alt = $hLevels_r
$hLevels = _BASS_ChannelGetLevel ($hMusic)
$hLevels_l = (_BASS_HiWord ($hLevels) / 32768) * 100
$hLevels_r = (_BASS_LoWord ($hLevels) / 32768) * 100
;~ Labels setzen
GUICtrlSetData($lbl_1,Round($hLevels_l,3))
GUICtrlSetData($lbl_2,Round($hLevels_r,3))
;~ Max Werte setzen - links
If $l_max < $hLevels_l and $hLevels_l <> 100 Then
$l_max = $hLevels_l
GUICtrlSetData($lbl_max_l,"Max: "&Round($l_max,3))
EndIf
;~ Max Werte setzen - rechts
If $r_max < $hLevels_r and $hLevels_r <> 100 Then
$r_max = $hLevels_r
GUICtrlSetData($lbl_max_r,"Max: " &Round($r_max,3))
EndIf
;~ GDI: Balken erstellen
If Abs($hLevels_l - $hLevels_l_alt) > $diff or Abs($hLevels_r - $hLevels_r_alt) > $diff Then
_WinAPI_RedrawWindow($hgui)
$img_l = _GDIPlus_GraphicsFillRect($hGraphic,@DesktopWidth / 2 - 100,@DesktopHeight-100 -($hLevels_l*5),100,$hLevels_l*5,$hBrush)
$img_r = _GDIPlus_GraphicsFillRect($hGraphic,@DesktopWidth / 2 +100,@DesktopHeight -100 -($hLevels_r*5),100,$hLevels_r*5,$hBrush)
EndIf
$fps += 1
WEnd
;~ Funktion damit alles übersichtlicher wirkt
Func _font_set($iCtrl)
GUICtrlSetBkColor($iCtrl,-1)
GUICtrlSetColor($iCtrl,0x00FBFF)
GUICtrlSetFont($iCtrl,10,100)
EndFunc
Func _FPS()
GUICtrlSetData($lbl_fps,"FPS: "&$fps)
$fps = 0
EndFunc
//Max Werte
//Vollbild
//Werte unter Balken
Vergisst nicht auf die BASS.dll UDF
StevenX