Jump to content

Multicolor progress meter problems


Recommended Posts

I found this multicolor progress coding and decided to incorporate it with another script to colorize the bar based on the signal level of the audio input on the sound card...microphone. My problem is I can't get the colors the way I want them...I can't figure out that part of the code. I've been messing with this two hour and a half and I'm fed up. I want the color to go from green to yellow to red. I would also like the color to switch over at certain parts...like green up to 60% then yellow up to 80% and then red up to 100%...but if that's not possible just simply green to yellow to red.

Please, somebody say they can figure this out. Thanks.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Extend\INM DB Meter.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;#requireadmin

#include <Array.au3>
#include <Array2.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#Include <string.au3>
#Include <GUIConstants.au3>
#include <misc.au3>
#include <MailSlot.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("GUIOnEventMode", 1)


Global Const $hMailSlot_To_Main = "\\.\mailslot\INavMedia-Media1";===Send data to INavMedia

Global Const $hMailSlot_PRE_Setup = "\\.\mailslot\INavMedia-Media2";===Receive data from INavMedia
Global Const $hMailSlot_From_Main = _MailSlotCreate($hMailSlot_PRE_Setup)


$SH = TrayCreateItem ( "Show/Hide")
TrayItemSetOnEvent($SH,"_ShowHide")
TraySetState()


$333 = DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)
Global $AppName = RegRead("HKEY_CURRENT_USER\SOFTWARE\INavMedia", "App Name")
Global $DB = RegRead("HKEY_CURRENT_USER\SOFTWARE\INavMedia", "Audio Clipping DB")
$dot = False
$bg = 0x222222
$graph = 0xFFFFFF
Global $Run_DBMeter = True
Dim $lpszDevice
Dim $lpszDeviceID
Dim $lpszOpenFlags
Dim $lpszRequest
Dim $lpszFlags
Dim $lpszCommand
Dim $lpszReturnString
Dim $cchReturn
Dim $mciError
$lpszDevice = "new type waveaudio"
$lpszOpenFlags = "alias mywave"
$lpszFlags = ""
$lpszCommand = StringFormat("open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags)
$lpszReturnString = _StringRepeat(" ", 100)
$cchReturn = StringLen($lpszReturnString)
$mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then _mciShowError($mciError[0])
$lpszDeviceID = "mywave"
$lpszRequest = "level"
$lpszFlags = ""
$lpszCommand = StringFormat("status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("DB Meter", 245, 50, @DesktopWidth-255, 10, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE,$WS_EX_TOPMOST))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ShowHide")

$InputValue = GUICtrlCreateCombo("", 5, 10, 50, 50)
    GUICtrlSetData(-1, "1|2|3|4|5|6", $DB)
    $Meter = $DB
    GUICtrlSetFont(-1, 16, 700)
    GUICtrlSetOnEvent(-1,"_SaveDB")

;$Progress1 = GUICtrlCreateProgress(9, 8, 39, 169, $PBS_VERTICAL+$PBS_SMOOTH)
    ;GUICtrlSetColor(-1,0x0)
    ;GUICtrlSetbkColor(-1,0x00FF00)

$Progress2 = GUICtrlCreateProgress(65, 8, 170, 30, $PBS_SMOOTH)
    ;GUICtrlSetBkColor(-1,0x0)
    ;GUICtrlSetColor(-1,0x00FF00)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

    ;====If we receive the message to stop or pause music, set indicator to stop retrieving level
    Local $iSize = _MailSlotCheckForNextMessage($hMailSlot_From_Main)
    If $iSize Then
        Local $sData = _MailSlotRead($hMailSlot_From_Main, $iSize, 2)
        $Run_DBMeter = $sData[1]
        GUICtrlSetData($Progress2,0)
    EndIf


    If $Run_DBMeter = "True" Then

    ;   If BitAND(WinGetState($AppName & " - Visual Screen"), 2) Then;===Check if window is visible

            $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
            If $mciError[0] <> 0 Then _mciShowError($mciError[0])
            $mciError = ($Meter*$mciError[2])
            ConsoleWrite($mciError & @CRLF)
            If $mciError > 100 Then $mciError = 100
            GUICtrlSetData($Progress2,$mciError)


            _SETPROGCOLOR($mciError)
        ;   ControlSetText($AppName & " - Visual Screen", "Next", 158, $mciError)
            _MailSlotWrite($hMailSlot_To_Main, $mciError, 2, "99")

    ;   EndIf

    EndIf

    ;If Not WinExists($AppName & " - Visual Screen") Then Exit

    Sleep(150)
WEnd

Func _SaveDB()
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\INavMedia", "Audio Clipping DB", "REG_SZ", GUICtrlRead($InputValue) )
    $Meter = GUICtrlRead($InputValue)
EndFunc

Func _ShowHide()
    ;ConsoleWrite(WinGetState($Form1) & @CR)
    $KEYBOARDSTATE = WinGetState($Form1)
    If $KEYBOARDSTATE = 5 Then
        GUISetState(@SW_SHOW, $Form1)
    ElseIf $KEYBOARDSTATE = 7 Or $KEYBOARDSTATE = 15 Then
        GUISetState(@SW_HIDE, $Form1)
    EndIf
EndFunc

Func _SETPROGCOLOR($MXVOL)

#cs
    $MXVOL2 = $MXVOL * 700;The number being multiplied is an arbitrary number to change the color. The number should generally range between 300 and 800 but can be anything, just calculate using the math within this function.
;   #cs
;   GUICtrlSetData($MEDIA_PLAYER_ARRAY[15], $MXVOL2 / 65535 * 100)
    $REDNESS = Int(100 - ($MXVOL2 / 860 * 512 / 350))
    If $REDNESS < 0 Then $REDNESS = 0
    $GREENESS = Int(($MXVOL2 / 200 * 512 / 100) - 257)
    If $GREENESS < 0 Then $GREENESS = 0
    $BLUENESS = Int(255 - ($REDNESS + $GREENESS))

;   _ConsoleWrite("MAIN " & $MXVOL2)
;   _ConsoleWrite("RED " & $REDNESS)
;   _ConsoleWrite("GREEN " & $GREENESS)
;   _ConsoleWrite("BLUE " & $BLUENESS)

    $PROGCOLOR = ($REDNESS * 256 * 256) + ($GREENESS * 256) + $BLUENESS

#ce



    $MXVOL = $MXVOL + 200
    If $MXVOL < 0 Then $MXVOL = 0
    If $MXVOL > 1000 Then $MXVOL = 1000

    $Redness = Int(255 - ($MXVOL / 1000 * 512))
    If $Redness < 0 Then $MXVOL = 0

    $Greeness = Int(($MXVOL / 1000 * 512) - 257)
    If $Greeness < 0 Then $Greeness = 0

    $Blueness = Int(255 - ($Redness + $Greeness))

    $PROGCOLOR = ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness


    GUICtrlSetColor($Progress2, $PROGCOLOR)
;   #ce
EndFunc   ;==>_SETPROGCOLOR

Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
    Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
EndFunc   ;==>_mciSendString

Func _mciShowError($mciError)
    Dim $errStr; Error message
    $errStr = _StringRepeat( " ", 100) ; Reserve some space for the error message
    $Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr))
    MsgBox(0, "MCI test", "MCI Error Number " & $mciError & ":" & $Result[2])
EndFunc   ;==>_mciShowError

 

Edited by Champak
Link to comment
Share on other sites

You mean something like this here?

Func _SETPROGCOLOR($MXVOL)

#cs
    $MXVOL2 = $MXVOL * 700;The number being multiplied is an arbitrary number to change the color. The number should generally range between 300 and 800 but can be anything, just calculate using the math within this function.
;   #cs
;   GUICtrlSetData($MEDIA_PLAYER_ARRAY[15], $MXVOL2 / 65535 * 100)
    $REDNESS = Int(100 - ($MXVOL2 / 860 * 512 / 350))
    If $REDNESS < 0 Then $REDNESS = 0
    $GREENESS = Int(($MXVOL2 / 200 * 512 / 100) - 257)
    If $GREENESS < 0 Then $GREENESS = 0
    $BLUENESS = Int(255 - ($REDNESS + $GREENESS))

;   _ConsoleWrite("MAIN " & $MXVOL2)
;   _ConsoleWrite("RED " & $REDNESS)
;   _ConsoleWrite("GREEN " & $GREENESS)
;   _ConsoleWrite("BLUE " & $BLUENESS)

    $PROGCOLOR = ($REDNESS * 256 * 256) + ($GREENESS * 256) + $BLUENESS

#ce



;~     $MXVOL = $MXVOL + 200
;~     If $MXVOL < 0 Then $MXVOL = 0
;~     If $MXVOL > 1000 Then $MXVOL = 1000

;~     $Redness = Int(255 - ($MXVOL / 1000 * 512))
;~     If $Redness < 0 Then $MXVOL = 0

;~     $Greeness = Int(($MXVOL / 1000 * 512) - 257)
;~     If $Greeness < 0 Then $Greeness = 0

;~     $Blueness = Int(255 - ($Redness + $Greeness))

;~     $PROGCOLOR = ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness

    Switch $MXVOL
        Case 0 To 60
            $PROGCOLOR = 0x00FF00
        Case 61 to 80
            $PROGCOLOR = 0xFFFF00
        Case Else
            $PROGCOLOR = 0xFF0000
    EndSwitch
    GUICtrlSetColor($Progress2, $PROGCOLOR)
;   #ce
EndFunc   ;==>_SETPROGCOLOR

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks for the effort, but thats what I originally did. I didnt like it because it wasnt a smooth transition between the colors and just looked rough to me. Something like that may work if i could make it look like the actual old style db meters where it stayed green up to a certain level...yellow up to a certain level and then peak at red like the attached image. I think I can do that by making three progress bars and breaking them up maybe? I dont know how id go about that, its morning and I'm just waking and my brain isnt functioning right now. I'll check into this after work later.

 

image.png

Link to comment
Share on other sites

Well, I would use an image displaying only a portion of it depending of the db level. This can be achieved with GDI+.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Check this:

; PsaltyDS edited by Terenz
#include <GuiConstants.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>

$hGUI = GUICreate("Progress Bar Test", 300, 130)
$sProgressBar = GUICtrlCreateProgress(10, 10, 280, 30, $PBS_Smooth)
If StringInStr(@OSType, "WIN32_NT") Then
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($sProgressBar), "wstr", " ", "wstr", " ")
EndIf
$sUpButton = GUICtrlCreateButton("UP", 15, 50, 76, 40)
$sDownButton = GUICtrlCreateButton("DOWN", 112, 50, 76, 40)
$sStopButton = GUICtrlCreateButton("STOP", 209, 50, 76, 40)
$sLabelInfo = GUICtrlCreateLabel("Red = 0, Green = 0, Blue = 0, Color = 0xFF0000", 10, 100, 280, 20, $SS_Center)

GUISetState()

$Progress = 0; Will be 0 thru 1000
$Increment = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sUpButton
            $Increment = +1
        Case $sDownButton
            $Increment = -1
        Case $sStopButton
            $Increment = 0
    EndSwitch
    If $Increment <> 0 Then
        _SetProgColor()
    EndIf
WEnd

Func _SetProgColor()
    $Progress = $Progress + $Increment
    If $Progress < 0 Then $Progress = 0
    If $Progress > 1000 Then $Progress = 1000
    GUICtrlSetData($sProgressBar, Int($Progress / 10))

    $Redness = Int(255 - ($Progress / 1000 * 512))
    If $Redness < 0 Then $Redness = 0

    $Greeness = Int(($Progress / 1000 * 512) - 257)
    If $Greeness < 0 Then $Greeness = 0

    $Blueness = Int(255 - ($Redness + $Greeness))

    $ProgColor = ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness
    _GUICtrlSetData($sLabelInfo, "Red = " & $Redness & ", Green = " & $Greeness & ", Blue = " & $Blueness & ", Color = 0x" & Hex($ProgColor, 6))
    GUICtrlSetColor($sProgressBar, $ProgColor)
EndFunc   ;==>_SetProgColor

Func _GUICtrlSetData($iCtrlID, $sData)
    If GUICtrlRead($iCtrlID, 1) <> $sData Then GUICtrlSetData($iCtrlID, $sData)
EndFunc   ;==>_GUICtrlSetData

Don't ask me how to change colors because i don't know lol, you need to play with RGB

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

So this is what I came up with, still not really what I want...but will suffice for now. I made it blend from green to orange and then put a label at the end of the progress bar that turns red if the progress is above 95.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=Extend\INM DB Meter.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;#requireadmin

#include <Array.au3>
#include <Array2.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#Include <string.au3>
#Include <GUIConstants.au3>
#include <misc.au3>
#include <MailSlot.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("GUIOnEventMode", 1)


Global Const $hMailSlot_To_Main = "\\.\mailslot\INavMedia-Media1";===Send data to INavMedia

Global Const $hMailSlot_PRE_Setup = "\\.\mailslot\INavMedia-Media2";===Receive data from INavMedia
Global Const $hMailSlot_From_Main = _MailSlotCreate($hMailSlot_PRE_Setup)


$SH = TrayCreateItem ( "Show/Hide")
TrayItemSetOnEvent($SH,"_ShowHide")
TraySetState()


$333 = DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)
Global $AppName = RegRead("HKEY_CURRENT_USER\SOFTWARE\INavMedia", "App Name")
Global $DB = RegRead("HKEY_CURRENT_USER\SOFTWARE\INavMedia", "Audio Clipping DB")
Global $Run_DBMeter = True
Global $lpszDevice = "new type waveaudio"
Global $lpszOpenFlags = "alias mywave"
Global $lpszFlags = ""
Global $lpszCommand = StringFormat("open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags)
Global $lpszReturnString = _StringRepeat(" ", 100)
Global $cchReturn = StringLen($lpszReturnString)
Global $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then _mciShowError($mciError[0])
Global $lpszDeviceID = "mywave"
Global $lpszRequest = "level"
Global $lpszFlags = ""
$lpszCommand = StringFormat("status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("DB Meter", 245, 50, @DesktopWidth-255, 10, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE,$WS_EX_TOPMOST))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ShowHide")

$InputValue = GUICtrlCreateCombo("", 5, 10, 60, 50)
    GUICtrlSetData(-1, "1|2|3|4|5|6", $DB)
    $Meter = $DB
    GUICtrlSetFont(-1, 16, 700)
    GUICtrlSetOnEvent(-1,"_SaveDB")

$Progress1 = GUICtrlCreateProgress(65, 10, 165, 30, $PBS_SMOOTH)
    GUICtrlSetBkColor($Progress1, "0x000000")

$BackgroundRim = GUICtrlCreateLabel("", 228, 10.5, 12, 30)
    GUICtrlSetBkColor($BackgroundRim, "0x000000")

$Progress2 = GUICtrlCreateLabel("", 229, 12, 10, 26)
    GUICtrlSetBkColor($Progress2, "0x000000")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###
$mciError2 = 0
While 1

    ;====If we receive the message to stop or pause music, set indicator to stop retrieving level
    Local $iSize = _MailSlotCheckForNextMessage($hMailSlot_From_Main)
    If $iSize Then
        Local $sData = _MailSlotRead($hMailSlot_From_Main, $iSize, 2)
        $Run_DBMeter = $sData[1]
        GUICtrlSetData($Progress1,0)
    EndIf


    If $Run_DBMeter = "True" Then

    ;   If BitAND(WinGetState($AppName & " - Visual Screen"), 2) Then;===Check if window is visible

            $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
            If $mciError[0] <> 0 Then _mciShowError($mciError[0])
            $mciError = ($Meter*$mciError[2])
            ConsoleWrite($mciError & @CRLF)
            If $mciError > $mciError2 Then
                $Increment = +1
                $mciError2 = $mciError
            Else
                $Increment = -1
                $mciError2 = $mciError
            EndIf


            If $mciError > 100 Then $mciError = 100


            _SETPROGCOLOR($mciError)
        ;   ControlSetText($AppName & " - Visual Screen", "Next", 158, $mciError)
            _MailSlotWrite($hMailSlot_To_Main, $mciError, 2, "99")

    ;   EndIf

    EndIf

    ;If Not WinExists($AppName & " - Visual Screen") Then Exit

    Sleep(50)
WEnd

Func _SaveDB()
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\INavMedia", "Audio Clipping DB", "REG_SZ", GUICtrlRead($InputValue) )
    $Meter = GUICtrlRead($InputValue)
EndFunc

Func _ShowHide()
    ;ConsoleWrite(WinGetState($Form1) & @CR)
    $KEYBOARDSTATE = WinGetState($Form1)
    If $KEYBOARDSTATE = 5 Then
        GUISetState(@SW_SHOW, $Form1)
    ElseIf $KEYBOARDSTATE = 7 Or $KEYBOARDSTATE = 15 Then
        GUISetState(@SW_HIDE, $Form1)
    EndIf
EndFunc


Func _SETPROGCOLOR($MXVOL)



    $MXVOL2 = $MXVOL; + 1
    If $MXVOL2 < 0 Then $MXVOL2 = 0
    If $MXVOL2 > 1000 Then $MXVOL2 = 1000

    $Redness = Int(255 - ($MXVOL2 / 100 * 112))
    If $Redness < 0 Then $Redness = 0

    $Greeness = Int(($MXVOL2 / 100 * 512) - 257  )
    If $Greeness < 0 Then $Greeness = 0

    $Blueness = Int(255 - ($Redness + $Greeness))

    $PROGCOLOR = ( $Greeness * 256 * 256) + ($Redness * 256)

    ;TrayTip($mciError,$Increment,1)

    GUICtrlSetData($Progress1, Int($MXVOL2))
    GUICtrlSetColor($Progress1, $PROGCOLOR)

    If $mciError > 95 Then
        GUICtrlSetBkColor($Progress2, 0xFF0000)
    Else
        GUICtrlSetBkColor($Progress2, "0x000000")
    EndIf


EndFunc   ;==>_SETPROGCOLOR

Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
    Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
EndFunc   ;==>_mciSendString

Func _mciShowError($mciError)
    Dim $errStr; Error message
    $errStr = _StringRepeat( " ", 100) ; Reserve some space for the error message
    $Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr))
    MsgBox(0, "MCI test", "MCI Error Number " & $mciError & ":" & $Result[2])
EndFunc   ;==>_mciShowError

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...