Sign in to follow this  
Followers 0
Znuffie

Slider Updates & Other Issues

6 posts in this topic

Hello,

I'm working on a Equalizer for my own personal usage, and I'm having some issues.

This is the code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>
#include <GuiToolTip.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Egalizatoru' lu' troo", 500, 345, 494, 390)
$EQ = GUICtrlCreateGroup("Equalizer", 5, 0, 490, 300, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER,$BS_FLAT))

Global $Count = 11
Global $Slider[$Count]
Global $Label[$Count]
Global $hTip[$Count]
Global $Legend[$Count]
Global $Line[$Count]
Global $Slider_hold[$Count]
Global $array[$Count] = ["0", "32", "64", "125", "250", "500", "1000", "2000", "4000", "8000", "16000"]

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

For $i = 0 to $Count - 1
    $Position = ($i * 40) + 32;
    $Slider[$i] = GUICtrlCreateSlider($Position, 32, 32, 240, BitOR($TBS_VERT, $TBS_AUTOTICKS, $TBS_BOTH, $TBS_TOOLTIPS))

    $hTip[$i] = _GUICtrlSlider_GetToolTips($Slider[$i])

    _GUICtrlSlider_SetTicFreq($Slider[$i], 20) ; set tics divisor
    _GUICtrlSlider_SetTipSide($Slider[$i], $TBTS_BOTTOM)
    _GUIToolTip_SetTitle($hTip[$i], "dB")
    _GUIToolTip_SetToolInfo($hTip[$i], "")
    _GUIToolTip_SetMargin($hTip[$i], -5, -5, -5, -20)
    _GUIToolTip_SetTipTextColor($hTip[$i], 0xFFFFFF)
    _GUIToolTip_SetTipBkColor($hTip[$i], 0x985428)

    GUICtrlSetLimit($Slider[$i], 120, -120)
    GUICtrlSetResizing($Slider[$i], $GUI_DOCKAUTO)
    GUICtrlSetColor($Slider[$i], 0xff0000)

    $Slider_Hold[$i] = GUICtrlRead($Slider[$i])

    If $array[$i] = 0 Then
        $labeltext = "PRE"
    Elseif $array[$i] >= 1000 Then
        $value = $array[$i] / 1000
        $labeltext = $value & " KHz"
    Else
        $labeltext = $array[$i] & " Hz"
    EndIf
    $Label[$i] = GUICtrlCreateLabel($labeltext, $Position, 16, 36, 16, $SS_CENTER)
    $Legend[$i] = GUICtrlCreateLabel(GUICtrlRead($Slider[$i]), $Position, 280, 28, 16, $SS_CENTER)
    GUICtrlSetBkColor($Legend[$i], 0xffffff)
Next

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetTip($EQ, "EQ Group")

$Button1 = GUICtrlCreateButton("Reset", 5, 312, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case GUICtrlRead($Slider[0]) <> $Slider_hold[0] to GUICtrlRead($Slider[$Count - 1]) <> $Slider_hold[$Count-1]
            For $i = 0 to $Count - 1
                SliderValue($i, $Slider[$i])
                $Slider_hold[$i] = GUICtrlRead($Slider[$i])
            Next

    EndSwitch
WEnd



Func SliderValue($button, $slider)
    $Index = $button
    $Value = GUICtrlRead($slider) / 10
    GUICtrlSetData($Legend[$Index], $Value)
    _GUIToolTip_SetTitle($hTip[$i], $Value & " dB")
    _GUIToolTip_SetToolInfo($hTip[$i], $Value)
    if $Index = 0 Then
        $line[$Index] = "Preamp: " & $Value & " dB" & @CRLF
    Else
        $line[$Index] = "Filter " & $Index & ": ON  PK       Fc    " & $array[$Index] & " Hz  Gain   " & $Value & " dB  Q  1,00" & @CRLF
    EndIf

;~  ConsoleWrite($line[$Index])
EndFunc

Func WM_VSCROLL()
EndFunc

My issues:

  1. Sliders are upside down! I want UP for positive and DOWN for negative values. Searched the forum, couldn't figure out a way to reverse them. $TBS_REVERSE doesn't seem to have any effect.
  2. I can't seem to figure out a way to update the value in real-time (not just when the mouse is released). Tried implementing a thing I saw on the forum, but I failed badly with my array of sliders, as you can see in the code. 
  3. I can't seem to find a way to make the tooltip "text" disappear. I want to update the Title, always (because I'm not using the integer, I need that value / 10). Again, searched the forum, nothing relevant came out.

 

Share this post


Link to post
Share on other sites



Znuffie,

- 1. Upside down sliders. Vertical sliders always work in that sense. Just negate the value you read from them - look at line " <<<<<<<< 1 " in the modified function below.

- 2. Real-time update. For me the tooltip values do update as the mouse is moved - do they not for you?

- 3. Tooltip formatting. The GUIToolTip UDF has been broken for a long time. Try using the new version from BrewManNH from here

And as a freebie: Check that you need to update the labels beneath the sliders before actually doing so - then they do not flicker as they were doing (look at " <<<<<<<< 2 ") ;)

Func SliderValue($button, $slider)
    $Index = $button
    $Value = -1 * (GUICtrlRead($slider) / 10) ; <<<<<<<<<<<<<<<<<<<<<<< 1
    If GUICtrlRead($Legend[$Index]) <> $Value Then ; <<<<<<<<<<<<<<<<<< 2
        GUICtrlSetData($Legend[$Index], $Value)
    EndIf
    _GUIToolTip_SetTitle($hTip[$i], $Value & " dB")
    _GUIToolTip_SetToolInfo($hTip[$i], $Value & " dB")
    if $Index = 0 Then
        $line[$Index] = "Preamp: " & $Value & " dB" & @CRLF
    Else
        $line[$Index] = "Filter " & $Index & ": ON  PK       Fc    " & $array[$Index] & " Hz  Gain   " & $Value & " dB  Q  1,00" & @CRLF
    EndIf

;~  ConsoleWrite($line[$Index])
EndFunc
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the quick reply!

About Nr. 2 - everything updates, until I change the first slider ($Slider[0]) value.

If I change that, everything stops. I assume it's something about:

Case GUICtrlRead($Slider[0]) <> $Slider_hold[0] to GUICtrlRead($Slider[$Count - 1]) <> $Slider_hold[$Count-1]

But I can't figure out another way to do it.

Edited by Znuffie

Share this post


Link to post
Share on other sites

Znuffie,

About Nr. 2 - everything updates, until I change the first slider ($Slider[0]) value

I see what you mean now - working on it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Znuffie,

We could get all fancy with message handlers, but this simple approach seems to work quite well. ;)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>
#include <GuiToolTip.au3>

$Form1 = GUICreate("Egalizatoru' lu' troo", 500, 345, 494, 390)
$EQ = GUICtrlCreateGroup("Equalizer", 5, 0, 490, 300, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER,$BS_FLAT))

Global $iCount = 11
Global $aSlider[$iCount]
Global $aLabel[$iCount]
Global $aLegend[$iCount]
Global $aLine[$iCount]
Global $aSlider_hold[$iCount]
Global $aArray[$iCount] = ["0", "32", "64", "125", "250", "500", "1000", "2000", "4000", "8000", "16000"]

For $i = 0 to $iCount - 1
    $Position = ($i * 40) + 32;
    $aSlider[$i] = GUICtrlCreateSlider($Position, 32, 32, 240, BitOR($TBS_VERT, $TBS_AUTOTICKS, $TBS_BOTH))
    GUICtrlSetLimit($aSlider[$i], 120, -120)

    If $aArray[$i] = 0 Then
        $aLabeltext = "PRE"
    Elseif $aArray[$i] >= 1000 Then
        $nValue = $aArray[$i] / 1000
        $aLabeltext = $nValue & " KHz"
    Else
        $aLabeltext = $aArray[$i] & " Hz"
    EndIf
    $aLabel[$i] = GUICtrlCreateLabel($aLabeltext, $Position, 16, 36, 16, $SS_CENTER)
    $aLegend[$i] = GUICtrlCreateLabel(0, $Position, 280, 28, 16, $SS_CENTER)

Next

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetTip($EQ, "EQ Group")

$Button1 = GUICtrlCreateButton("Reset", 5, 312, 75, 25)
GUISetState(@SW_SHOW)

; Get a time stamp
$nBegin = TimerInit()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Checkif a slider has been moved
    For $i = 0 To $iCount - 1
        If -1 * (GUICtrlRead($aSlider[$i]) / 10) <> GUICtrlRead($aLegend[$i]) Then
            _Slider_Update($i)
            ; Only one can move at a time so no point in looking further
            ExitLoop
        EndIf
    Next

    ; Hide the ToolTip every second
    If TimerDiff($nBegin) > 1000 Then
        _HideToolTip()
        $nBegin = TimerInit()
    EndIf


WEnd

Func _Slider_Update($Index)

    $nValue = -1 * (GUICtrlRead($aSlider[$Index]) / 10)
    GUICtrlSetData($aLegend[$Index], $nValue) ; No ned to check as we know it must be different or we would not be here

    ; Show the tootip
    ToolTip($nValue 7 " dB")

    If $Index = 0 Then
        $aLine[$Index] = "Preamp: " & $nValue & " dB" & @CRLF
    Else
        $aLine[$Index] = "Filter " & $Index & ": ON  PK       Fc    " & $aArray[$Index] & " Hz  Gain   " & $nValue & " dB  Q  1,00" & @CRLF
    EndIf

EndFunc

Func _HideToolTip()
    ; Hide ToolTip
    ToolTip("")
EndFunc
How about that? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Woah, that's awesome...

A lot more cleaner than my code! I can actually understand it better!

Thanks a lot! Now I just need to implement config file reading/writing and I'm good.

As an explanation of what I'm doing - I'm trying to write a "friendly" config for Equalizer APO.

Share this post


Link to post
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
Sign in to follow this  
Followers 0