Ich habe mal einen Visualizer (ich hoffe das nennt man so) mit GDIPlus geschrieben. Über Rückmeldungen würde ich mich freuen!
To do: Mehr Farbwechselfunktionen und Visualationsarten
Bedienung:
Mit Escape schließen und mit Enter zwischen den Visualationen wechseln.
Ihr benötigt 2 BassDlls und die dazugehörigen UDFs (alles im Anhang).
Neu: Version 2.1 mit 8 Visualisierungen
Ideen für neue Visualationen sind immer und herzlich willkommen!
Visualizer Version 2.1
;Thanks to BrettF, ProgAndy, eukalyptus from autoitscript.com for the Bass.dlls and their support!
;Thanks to Jurax, Ahnungslos and UEZ from AutoIt.de for their support, too!
;scripted by xp_fan
#include <Bass.au3>
#include <BassConstants.au3>
#include <BassTags.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIplus.au3>
#include <WinAPI.au3>
#include <Misc.au3>
_BASS_STARTUP(@ScriptDir & '\BASS.dll')
_Bass_Tags_Startup('BassTags.dll')
_BASS_Init(0, -1, 44100, 0, '')
If @error Then
MsgBox(0, 'Error', 'Sound konnte nicht Initialisiert werden!')
Exit
EndIf
Global $file = FileOpenDialog('Bitte wählen Sie eine Sounddatei aus!', '', 'MP3 Datei (*.mp3)')
If @error Then
Exit
EndIf
Global $MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, 0)
Global $ID3Album = _Bass_Tags_Read($MusicHandle, '%IFV1(%ALBM,%IUPC(%ALBM))')
If @error Then
Exit
EndIf
Global $ID3Title = _Bass_Tags_Read($MusicHandle, '%IFV1(%TRCK,%TRCK. )%IFV2(%ARTI,%ICAP(%ARTI), Nichts) - %IFV2(%TITL,%ICAP(%TITL) , Nichts )')
[/autoit] [autoit][/autoit] [autoit]If @error Then
Exit
EndIf
Global $fftstruct = DllStructCreate('float[128]')
_BASS_ChannelPlay($MusicHandle, 0)
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]Global $sleep = 30
Global $Koordinatenx[29]
Global $Koordinateny[29]
Global $counterR = 150
Global $counterG = 0
Global $counterB = 0
Global $Visualation = Random(1, 8, 1)
Global $HexFarbe1
Global $HexFarbe2
Global $full1 = 0
Global $full2 = 0
Global $full3 = 0
Global $full4 = 0
Global $full5 = 0
Global $hochz = 0
Global $distance = 7
Global $colorchange = 100
Global $brushchange = 50
Global $Alpha1 = 21
Global $Alpha2 = 255
Global $Colors1[12] = [0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00, 0xFFFFA500, 0xFF8B0000, 0xFFA146FF, 0xFFCEA66B, 0xFF0033EE, 0xFFFFD700, 0xFF999999, 0xFFEEEEEE]
Global $dll = DllOpen('user32.dll')
Global $hwnd = GUICreate('GDIPlus Visualizer Version 2.1', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwnd)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(700, 700, $hGraphic)
Global $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Global $Pen1 = _GDIPlus_PenCreate(0xFF0000FF, 20, 2)
Global $Pen2 = _GDIPlus_PenCreate(0x330000FF, 20, 2)
Global $hBrush1 = _GDIPlus_BrushCreateSolid(0x00FFFFFF)
Global $hBrush2 = _GDIPlus_BrushCreateSolid(0x00FFFFFF)
Global $hBrush3 = _GDIPlus_BrushCreateSolid(0x00FFFFFF)
Global $hBrush4 = _GDIPlus_BrushCreateSolid(0x00FFFFFF)
Global $hBrush5 = _GDIPlus_BrushCreateLinear(0, 200, 0, 400, 0x00FFFFFF, 0x00FFFFFF)
Global $hBrush6 = _GDIPlus_BrushCreateSolid(0xFFFF0000)
Global $hFormat = _GDIPlus_StringFormatCreate()
Global $hFamily = _GDIPlus_FontFamilyCreate('Arial')
Global $hFont = _GDIPlus_FontCreate($hFamily, 20, 1, 2)
Global $tLayout1 = _GDIPlus_RectFCreate(100, 70, 500, 35)
Global $tLayout2 = _GDIPlus_RectFCreate(100, 105, 500, 35)
_GDIPlus_GraphicsClear($hContext)
For $i = 1 To 28 Step 1
$Koordinatenx[$i] = Random(50, @DesktopWidth - 555, 1)
$Koordinateny[$i] = Random(200, @DesktopHeight - 333, 1)
Next
WinSetOnTop($hwnd, '', 1)
GUISetBkColor(0x000000)
GUISetCursor(16)
GUISetState(@SW_SHOW)
_Farbverlauf()
HotKeySet('{ENTER}', '_Count')
HotKeySet('{ESC}', 'OnAutoItExit')
AdlibRegister('_BrushColor', $brushchange)
AdlibRegister('_Color', $colorchange)
AdlibRegister('_Farbverlauf', 5000)
Global $song_length = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)
[/autoit] [autoit][/autoit] [autoit]While 1
Select
Case $song_length = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
Sleep(3000)
OnAutoItExit()
Case $Visualation = 1
_Tower()
Case $Visualation = 2
_TowerSmall()
Case $Visualation = 3
_Balken()
Case $Visualation = 4
_Speech()
Case $Visualation = 5
_Flummies()
Case $Visualation = 6
_FillCircles()
Case $Visualation = 7
_TowerFarbverlauf()
Case $Visualation = 8
_ColorByHeight()
EndSelect
Sleep($sleep)
WEnd
Func OnAutoItExit()
DllClose($dll)
_BASS_Stop()
_BASS_Free()
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_PenDispose($Pen1)
_GDIPlus_PenDispose($Pen2)
_GDIPlus_BrushDispose($hBrush1)
_GDIPlus_BrushDispose($hBrush2)
_GDIPlus_BrushDispose($hBrush3)
_GDIPlus_BrushDispose($hBrush4)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hContext)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_Shutdown()
AdlibUnRegister()
Exit
EndFunc ;==>OnAutoItExit
Func _Tower()
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Album, $hFont, $tLayout1, $hFormat, $hBrush1)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Title, $hFont, $tLayout2, $hFormat, $hBrush2)
_GDIPlus_PenSetWidth($Pen1, 20)
_GDIPlus_PenSetWidth($Pen2, 20)
$level = 300
_BASS_ChannelGetData($MusicHandle, DllStructGetPtr($fftstruct), $BASS_DATA_FFT256)
For $i = 1 To 28 Step 1
If $i > 5 Then $level = 500
_GDIPlus_GraphicsDrawLine($hContext, 20 * $i, 400, 20 * $i, 400 - DllStructGetData($fftstruct, 1, $i) * $level, $Pen1)
_GDIPlus_GraphicsDrawLine($hContext, 20 * $i, 400 + $distance, 20 * $i, (400 + $distance) + DllStructGetData($fftstruct, 1, $i) * $level, $Pen2)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 250, 100, @DesktopWidth - 300, @DesktopHeight)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
EndFunc ;==>_Tower
Func _TowerSmall()
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Album, $hFont, $tLayout1, $hFormat, $hBrush1)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Title, $hFont, $tLayout2, $hFormat, $hBrush2)
_GDIPlus_PenSetWidth($Pen1, 3)
_GDIPlus_PenSetWidth($Pen2, 3)
$level = 300
_BASS_ChannelGetData($MusicHandle, DllStructGetPtr($fftstruct), $BASS_DATA_FFT256)
For $i = 1 To 28 Step 1
If $i > 5 Then $level = 500
_GDIPlus_GraphicsDrawLine($hContext, 20 * $i - 10, 400, 20 * $i - 10, 400 - DllStructGetData($fftstruct, 1, $i) * $level, $Pen1)
_GDIPlus_GraphicsDrawLine($hContext, 20 * $i - 10, 400 + $distance, 20 * $i - 10, (400 + $distance) + DllStructGetData($fftstruct, 1, $i) * $level, $Pen2)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 250, 100, @DesktopWidth - 300, @DesktopHeight)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
EndFunc ;==>_TowerSmall
Func _Balken()
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Album, $hFont, $tLayout1, $hFormat, $hBrush1)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Title, $hFont, $tLayout2, $hFormat, $hBrush2)
_GDIPlus_PenSetWidth($Pen1, 14)
_GDIPlus_PenSetWidth($Pen2, 14)
$level = 500
_BASS_ChannelGetData($MusicHandle, DllStructGetPtr($fftstruct), $BASS_DATA_FFT256)
For $i = 1 To 28 Step 1
If $i > 5 Then $level = 700
_GDIPlus_GraphicsDrawLine($hContext, 70, 15 * $i + 150, 70 + DllStructGetData($fftstruct, 1, $i) * $level, 15 * $i + 150, $Pen1)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 250, 100, @DesktopWidth - 300, @DesktopHeight)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
EndFunc ;==>_Balken
Func _Speech()
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Album, $hFont, $tLayout1, $hFormat, $hBrush1)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Title, $hFont, $tLayout2, $hFormat, $hBrush2)
_GDIPlus_PenSetWidth($Pen1, 2)
_GDIPlus_PenSetWidth($Pen2, 2)
$level = 300
_BASS_ChannelGetData($MusicHandle, DllStructGetPtr($fftstruct), $BASS_DATA_FFT256)
For $i = 1 To 28 Step 1
If $i > 5 Then $level = 500
_GDIPlus_GraphicsDrawLine($hContext, 20 * $i, 400, (20 * $i) + 10, 400 - DllStructGetData($fftstruct, 1, $i) * $level, $Pen1)
_GDIPlus_GraphicsDrawLine($hContext, (20 * $i) + 10, 400 - DllStructGetData($fftstruct, 1, $i) * $level, (20 * $i) + 10, 400 + DllStructGetData($fftstruct, 1, $i) * $level, $Pen1)
_GDIPlus_GraphicsDrawLine($hContext, (20 * $i) + 10, 400 + DllStructGetData($fftstruct, 1, $i) * $level, (20 * $i) + 20, 400, $Pen1)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 250, 100, @DesktopWidth - 300, @DesktopHeight)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
EndFunc ;==>_Speech
Func _Flummies()
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Album, $hFont, $tLayout1, $hFormat, $hBrush1)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Title, $hFont, $tLayout2, $hFormat, $hBrush2)
$level = 300
_BASS_ChannelGetData($MusicHandle, DllStructGetPtr($fftstruct), $BASS_DATA_FFT256)
For $i = 1 To 28 Step 1
If $i > 5 Then $level = 500
_GDIPlus_GraphicsFillEllipse($hContext, 20 * $i, 400 - DllStructGetData($fftstruct, 1, $i) * $level, 15, 15, $hBrush3)
_GDIPlus_GraphicsFillEllipse($hContext, 20 * $i, 400 + DllStructGetData($fftstruct, 1, $i) * $level, 15, 15, $hBrush4)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 250, 100, @DesktopWidth - 300, @DesktopHeight)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
EndFunc ;==>_Flummies
Func _FillCircles()
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Album, $hFont, $tLayout1, $hFormat, $hBrush1)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Title, $hFont, $tLayout2, $hFormat, $hBrush2)
_BASS_ChannelGetData($MusicHandle, DllStructGetPtr($fftstruct), $BASS_DATA_FFT256)
$level = 110
For $i = 1 To 28 Step 1
If $i > 5 Then $level = 400
_GDIPlus_GraphicsFillEllipse($hContext, $Koordinatenx[$i] - DllStructGetData($fftstruct, 1, $i) * $level / 2, $Koordinateny[$i] - DllStructGetData($fftstruct, 1, $i) * $level / 2, DllStructGetData($fftstruct, 1, $i) * $level, DllStructGetData($fftstruct, 1, $i) * $level, $hBrush3)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 250, 100, @DesktopWidth - 300, @DesktopHeight)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
EndFunc ;==>_FillCircles
Func _TowerFarbverlauf()
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Album, $hFont, $tLayout1, $hFormat, $hBrush1)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Title, $hFont, $tLayout2, $hFormat, $hBrush2)
$level = 100
_BASS_ChannelGetData($MusicHandle, DllStructGetPtr($fftstruct), $BASS_DATA_FFT256)
For $i = 1 To 28 Step 1
If $i > 5 Then $level = 500
Global $hBrush5 = _GDIPlus_BrushCreateLinear(0, 400 - DllStructGetData($fftstruct, 1, $i) * $level - 2, 0, 400, $HexFarbe1, $HexFarbe2)
_GDIPlus_GraphicsFillRect($hContext, 20 * $i, 400 - DllStructGetData($fftstruct, 1, $i) * $level, 20, DllStructGetData($fftstruct, 1, $i) * $level, $hBrush5)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 250, 100, @DesktopWidth - 300, @DesktopHeight)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
EndFunc ;==>_TowerFarbverlauf
Func _Farbverlauf()
Do
Global $HexFarbe1 = $Colors1[Random(0, 11, 1)]
Global $HexFarbe2 = $Colors1[Random(0, 11, 1)]
Sleep(1)
Until $HexFarbe1 <> $HexFarbe2
EndFunc ;==>_Farbverlauf
Func _Color()
Select
Case $counterB = 0 And $counterG = 0 And $full3 = 0 And $full5 = 0; Start
$counterR += 1
If $counterR = 255 Then $counterG = 1
Case $counterR = 255 And $full4 = 0 And $full5 = 0; Wenn rot voll, dann Übergang nach gelb
$counterG += 1
If $counterG = 255 Then $counterR -= 1
Case $counterG = 255 And $full3 = 0 And $full4 = 0 And $full5 = 0; Wenn grün voll, dann Übergang nach grün
$counterR -= 1
If $counterR = 0 Then
$counterB = 1
$counterG = 254
EndIf
Case $counterG = 254 And $counterB >= 1 And $full2 = 0 And $full4 = 0 And $full5 = 0; Wenn rot leer, dann blau erhöhen
$counterB += 1
If $counterB = 255 And $counterG = 254 And $full3 = 0 Then
$counterG = 253
$full2 = 1
EndIf
Case $counterB = 255 And $full3 = 0 And $full4 = 0 And $full5 = 0; Wenn blau voll, grün vermindern
$counterG -= 1
If $counterG = 0 Then $full3 = 1
Case $full3 = 1 And $full4 = 0 And $full5 = 0; Wenn Blau voll und grün leer, rot erhöhen
$counterR += 1
If $counterR = 255 Then $full4 = 1
Case $full4 = 1 And $full5 = 0; Wenn rot voll, grün erhöhen, um weiß zu erhalten
$counterG += 1
If $counterG = 255 Then $full5 = 1
Case $full5 = 1
$counterR -= 1
$counterG -= 1
$counterB -= 1
If $counterG = 0 Then
$counterG = 0
$counterB = 0
$counterR = 0
$full1 = 0
$full2 = 0
$full3 = 0
$full4 = 0
$full5 = 0
EndIf
EndSelect
Local $Farbe = Hex($counterR, 2) & Hex($counterG, 2) & Hex($counterB, 2)
_GDIPlus_PenSetColor($Pen1, '0xDD' & $Farbe)
_GDIPlus_PenSetColor($Pen2, '0x33' & $Farbe)
_GDIPlus_BrushSetSolidColor($hBrush3, '0xDD' & $Farbe)
_GDIPlus_BrushSetSolidColor($hBrush4, '0x33' & $Farbe)
EndFunc ;==>_Color
Func _BrushColor()
If $Alpha1 = 21 Then
$hochz = 1
$Alpha1 += 1
$Alpha2 -= 1
EndIf
If $Alpha1 = 255 Then
$hochz = 0
$Alpha1 -= 1
$Alpha2 += 1
EndIf
If $hochz = 1 Then
$Alpha1 += 1
$Alpha2 -= 1
Else
$Alpha1 -= 1
$Alpha2 += 1
EndIf
_GDIPlus_BrushSetSolidColor($hBrush1, '0x' & Hex($Alpha1, 2) & 'FFFFFF')
_GDIPlus_BrushSetSolidColor($hBrush2, '0x' & Hex($Alpha2, 2) & 'FFFFFF')
EndFunc ;==>_BrushColor
Func _Count()
$Visualation += 1
If $Visualation >= 9 Then $Visualation = 1
EndFunc ;==>_Count
Func _GDIPlus_BrushCreateLinear($iX1, $iY1, $iX2, $iY2, $iARGB1 = 0xFF000000, $iARGB2 = 0xFFFFFFFF)
Local $aResult, $start, $end, $sPoint, $ePoint
$start = DllStructCreate("int X;int Y")
DllStructSetData($start, "X", $iX1)
DllStructSetData($start, "Y", $iY1)
$sPoint = DllStructGetPtr($start)
$end = DllStructCreate("int X;int Y")
DllStructSetData($end, "X", $iX2)
DllStructSetData($end, "Y", $iY2)
$ePoint = DllStructGetPtr($end)
$aResult = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushI", "ptr", $sPoint, "ptr", $ePoint, "int", $iARGB1, "int", $iARGB2, "int", 0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return SetError(0, $aResult[0], $aResult[6])
EndFunc ;==>_GDIPlus_BrushCreateLinear
Func _ColorByHeight()
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Album, $hFont, $tLayout1, $hFormat, $hBrush1)
_GDIPlus_GraphicsDrawStringEx($hContext, $ID3Title, $hFont, $tLayout2, $hFormat, $hBrush2)
$level = 100
_BASS_ChannelGetData($MusicHandle, DllStructGetPtr($fftstruct), $BASS_DATA_FFT256)
For $i = 1 To 28 Step 1
If $i > 5 Then $level = 500
$val = DllStructGetData($fftstruct, 1, $i)
$col = $val * 3.55 * $level
If $col > 255 Then $col = 255
_GDIPlus_BrushSetSolidColor($hBrush6, BitOR(0xFF000000, BitShift(255 - $col, -8), BitShift($col, -16)))
_GDIPlus_GraphicsFillRect($hContext, 20 * $i, 400 - $val * $level, 20, $val * $level, $hBrush6)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
Next
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 250, 100, @DesktopWidth - 300, @DesktopHeight)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
EndFunc ;==>_ColorByHeight