Jump to content

Recommended Posts

Posted

I have made a GUI with a start-pause button.

The script of the start-pause function looks something like this

$nMsg = GUIGetMsg()
Switch $nMsg
Case $StartPause
If $pause = 1 Then
    $pause = 0
    GUICtrlSetData($StartPause, "Pause")
Else
    $pause = 1
    GUICtrlSetData($StartPause, "Start")
EndIf
EndSwitch

The problem is that it only pauses for like 3 seconds and then turns itself back on.

The full code is here (but it's messy)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#Region ### START Koda GUI section ### Form=c:\users\aske\desktop\sheet maker.kxf
$Form1_1 = GUICreate("Form1", 486, 203, 288, 207, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$scalelist = GUICtrlCreateList("", 16, 16, 105, 175, BitOR($LBS_NOTIFY,$WS_VSCROLL,$WS_BORDER))
GUICtrlSetData(-1, "ionian|dorian|frygian|lydian|mixolydian|aeloian|locrian|minor-pentatonic|major-pentatonic|blues")
$List2 = GUICtrlCreateList("", 136, 16, 33, 175, BitOR($LBS_NOTIFY,$WS_VSCROLL,$WS_BORDER))
GUICtrlSetData(-1, "Gb|Db|Ab|Eb|Bb|F|C|G|D|A|E|H|F#")
$sight = GUICtrlCreateInput("0", 280, 16, 81, 21)
$measures = GUICtrlCreateInput("2", 248, 56, 113, 21)
$from = GUICtrlCreateInput("1", 216, 96, 57, 21)
$to = GUICtrlCreateInput("18", 304, 96, 57, 21)
$jump = GUICtrlCreateInput("6", 256, 128, 105, 21)
$StartPause = GUICtrlCreateButton("Start", 320, 160, 67, 25)
$Force = GUICtrlCreateButton("Force", 248, 160, 67, 25)
$posInfo = GUICtrlCreateLabel("-", 432, 16, 7, 17)
$noteInfo = GUICtrlCreateLabel("-", 432, 48, 7, 17)
$AltTop = GUICtrlCreateCheckbox("AltTop", 184, 160, 49, 17)
$xtraInfo = GUICtrlCreateLabel("-", 432, 112, 7, 17)
$lFrom = GUICtrlCreateLabel("From:", 184, 96, 30, 17)
$lTo = GUICtrlCreateLabel("To:", 280, 96, 20, 17)
$lMeasures = GUICtrlCreateLabel("Measures:", 184, 56, 53, 17)
$lsightper = GUICtrlCreateLabel("% for accidental:", 184, 16, 82, 17)
$lInterval = GUICtrlCreateLabel("Max interval:", 184, 128, 64, 17)
$lPos = GUICtrlCreateLabel("Position:", 376, 16, 44, 17)
$lNote = GUICtrlCreateLabel("Note:", 376, 48, 30, 17)
$lOctave = GUICtrlCreateLabel("Octave:", 376, 80, 42, 17)
$lInfo = GUICtrlCreateLabel("Info:", 376, 112, 25, 17)
$octaveInfo = GUICtrlCreateLabel(".", 432, 80, 7, 17)
$resetpos = GUICtrlCreateButton("Reset pos", 392, 160, 67, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


; ------------------------------------------------------------

Global $vPosToNote[8]; Is set to Gb-major
    $vPosToNote[0] = 0  ; NOT IN USE
Global $vNoteToPos[14]; Is set to Gb-major - 0 and 13 are imaginary
Global $vPos = 1 ; The position of the cursor. 1 = Deep C
Global $vOctave = 0
Global $vCurScale[13] ; Where the current scale is
Global $vScaleSize = 12
Global $vMaxInt
Global $vMinPos
Global $vMaxPos
Global $vAltTop
Global $vMeasures = 300
Global $vProSight
Global $vKeyDiff = 0
Global $vLastNote = 0
Global $note3 = 0
Global $pause = 1
Global $vForce = 0

HotKeySet("{F7}", "testscale")
HotKeySet("{F9}", "setsinglenote")
HotKeySet("{F8}", "makesheet")
HotKeySet("{F10}", "quit")

SetGbMajor()

func getFromGui()
    $vMaxInt    = GuiCtrlRead($jump)    ; Max interval

    ; Position - Note
    ;   1   2   3   4   5   6   7   8   9   10  ...
    ;   C   C#  D   D#  E   F   F#  G   G#  A   ...
    $vMinPos    = GuiCtrlRead($from)    ; Min position
    $vMaxPos    = GuiCtrlRead($to)      ; Max position
    $vAltTop    = GuiCtrlRead($AltTop)
    $vMeasures  = GuiCtrlRead($measures)
    $vProSight  = GuiCtrlRead($sight)

    setScale(GuiCtrlRead($scaleList))
    info($vCurScale[3])
EndFunc

Func getNote($pos)
    $pos = Mod($pos, 7)
    If $pos = 0 Then
        $pos = 7
    EndIf

    Return $vPosToNote[$pos]
EndFunc

func getPos($note2)
    $pos = 0

    while $note2 > 12
        $note2 -= 12
        $pos += 7
    WEnd

    If $vNoteToPos[$note2] = 0 Then
        $pos += 102
    EndIf

    $pos += $vNoteToPos[$note2]

    Return $pos
EndFunc

Func SetGbMajor()
    $vPosToNote[1] = 12 ; Cb
    $vPosToNote[2] = 2  ; Db
    $vPosToNote[3] = 4  ; Eb
    $vPosToNote[4] = 6  ; F
    $vPosToNote[5] = 7  ; Gb
    $vPosToNote[6] = 9  ; Ab
    $vPosToNote[7] = 11 ; Bb

    $vNoteToPos[0] = 1 ; Imaginary
    $vNoteToPos[1] = 0
    $vNoteToPos[2] = 2
    $vNoteToPos[3] = 0
    $vNoteToPos[4] = 3
    $vNoteToPos[5] = 0
    $vNoteToPos[6] = 4
    $vNoteToPos[7] = 5
    $vNoteToPos[8] = 0
    $vNoteToPos[9] = 6
    $vNoteToPos[10] = 0
    $vNoteToPos[11] = 7
    $vNoteToPos[12] = 1
    $vNoteToPos[13] = 0 ; Imaginary
EndFunc

Func showNote($n)
    While $n > 12
        $n -= 12
    WEnd

    Switch($n)
        Case 0
            Return 0
        Case 1
            Return "C"
        Case 2
            return "C#"
        Case 3
            return 'D'
        Case 4
            return "D#"
        Case 5
            return 'E'
        Case 6
            return 'F'
        Case 7
            return "F#"
        Case 8
            return 'G'
        Case 9
            return "G#"
        Case 10
            return 'A'
        Case 11
            return "Bb"
        Case Else
            return 'H'
    EndSwitch
EndFunc

Func info($info = "undeclared")
    If $info <> "undeclared" Then
        GUICtrlSetData($XtraInfo, $info)
    EndIf

    GUICtrlSetData($PosInfo, $vPos)
    GUICtrlSetData($NoteInfo, showNote($vLastNote))
EndFunc

Func setKey()
    Dim $n = 0
    Switch(GUICtrlRead($List2))
        Case "Gb"
            $n = 1
        Case "Db"
            $n = 2
        Case "Ab"
            $n = 3
        Case "Eb"
            $n = 4
        Case "Bb"
            $n = 5
        Case "F"
            $n = 6
        Case "C"
            $n = 7
        Case "G"
            $n = 8
        Case "D"
            $n = 9
        Case "A"
            $n = 10
        Case "E"
            $n = 11
        Case "H"
            $n = 12
        Case "F#"
            $n = 13
    EndSwitch

    $n -= 1

    $vKeyDiff = 6

    SetGbMajor()
    $pos1 = 1
    $pos2 = 1
    For $i = 1 To $n
        $vPosToNote[$pos1] += 1
        $vNoteToPos[$pos2] = $vNoteToPos[$pos2-1]
        $vNoteToPos[$pos2-1] = 0
        If $vPosToNote[$pos1] = 13 Then
            $vPosToNote[$pos1] = 1
        EndIf
        $pos1 += 4
        If $pos1 > 7 Then
            $pos1 -= 7
        EndIf
        $pos2 += 7  ; a fifth
        If $pos2 > 12 Then
            $pos2 -= 12
        EndIf

        $vKeyDiff += 7
        If $vKeyDiff > 12 Then
            $vKeyDiff -= 12
        EndIf
    Next

EndFunc

Func setScale($scale)
    If $scale = "ionian" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 3
        $vCurScale[3] = 5
        $vCurScale[4] = 6
        $vCurScale[5] = 8
        $vCurScale[6] = 10
        $vCurScale[7] = 12
        $vScaleSize = 7
    ElseIf $scale = "dorian" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 3
        $vCurScale[3] = 4
        $vCurScale[4] = 6
        $vCurScale[5] = 8
        $vCurScale[6] = 10
        $vCurScale[7] = 11
        $vScaleSize = 7
    ElseIf $scale = "frygian" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 2
        $vCurScale[3] = 4
        $vCurScale[4] = 6
        $vCurScale[5] = 8
        $vCurScale[6] = 9
        $vCurScale[7] = 11
        $vScaleSize = 7
    ElseIf $scale = "lydian" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 3
        $vCurScale[3] = 5
        $vCurScale[4] = 7
        $vCurScale[5] = 8
        $vCurScale[6] = 10
        $vCurScale[7] = 12
        $vScaleSize = 7
    ElseIf $scale = "mixolydian" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 3
        $vCurScale[3] = 5
        $vCurScale[4] = 6
        $vCurScale[5] = 8
        $vCurScale[6] = 10
        $vCurScale[7] = 11
        $vScaleSize = 7
    ElseIf $scale = "aeolian" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 3
        $vCurScale[3] = 4
        $vCurScale[4] = 6
        $vCurScale[5] = 8
        $vCurScale[6] = 9
        $vCurScale[7] = 11
        $vScaleSize = 7
    ElseIf $scale = "locrian" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 2
        $vCurScale[3] = 4
        $vCurScale[4] = 6
        $vCurScale[5] = 7
        $vCurScale[6] = 9
        $vCurScale[7] = 11
        $vScaleSize = 7
    ElseIf $scale = "major-pentatonic" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 3
        $vCurScale[3] = 5
        $vCurScale[4] = 8
        $vCurScale[5] = 10
        $vScaleSize = 5
    ElseIf $scale = "minor-pentatonic" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 4
        $vCurScale[3] = 6
        $vCurScale[4] = 8
        $vCurScale[5] = 11
        $vScaleSize = 5
    ElseIf $scale = "blues" Then
        $vCurScale[1] = 1
        $vCurScale[2] = 4
        $vCurScale[3] = 6
        $vCurScale[4] = 7
        $vCurScale[5] = 8
        $vCurScale[6] = 11
        $vScaleSize = 6
    EndIf
EndFunc

Func comment($text)
    ToolTip($text, 0, 0)
    Sleep(500)
EndFunc

Func altmod($n1, $n2)
    $i = 0
    while $n1 > $n2
        $n1 -= $n2
        $i += 1
    WEnd
    return $i
EndFunc

Func nextNote()
    Dim $newNotes[120] ; 10 octaves must be enough

    Dim $altScale[13]
    For $i = 0 To 12
        $altScale[$i] = $vCurScale[$i]
    Next

    For $i = 1 to $vScaleSize   ; Set the key
        $altScale[$i] += $vKeyDiff
        if $altScale[$i] > 12 Then
            $altScale[$i] -= 12
        EndIf
    Next

    $min = $vLastNote - $jump
    If $min < $vMinPos Then
        $min = $vMinPos
    EndIf

    $max = $vLastNote + $jump
    If $max > $vMaxPos Then
        $max = $vMaxPos
    EndIf

    $n = -1
    $octaves = -1

    While ($octaves*12+1) <= $max
        For $i = 1 to $vScaleSize
            If ($altScale[$i]+$octaves*12) <= $max AND ($altScale[$i]+$octaves*12) > $min Then
                $n += 1
                $newNotes[$n] = ($altScale[$i]+$octaves*12)
            EndIf
        Next
        $octaves += 1
    WEnd

    $nextNote = $newNotes[Random( 0, $n, 1)]

    Return $nextNote
EndFunc

Func setNote($note = -1)
    If $note = -1 Then
        $note = nextNote()
    EndIf

    If getPos($note) < 100 Then
            While getPos($note) < $vPos
                Send("{DOWN}")
                Sleep(2)
                $vPos -= 1
            WEnd
            While getPos($note) > $vPos
                Send("{UP}")
                Sleep(2)
                $vPos += 1
            WEnd
            Sleep(10)
            Send("{ENTER}")
        Else
            While (getPos($note-1)) < $vPos
                Send("{DOWN}")
                Sleep(2)
                $vPos -= 1
            WEnd
            While (getPos($note-1)) > $vPos
                Send("{UP}")
                Sleep(2)
                $vPos += 1
            WEnd
            Sleep(10)
            Send("{ENTER}")
            Sleep(10)
            Send("+{NUMPADADD}")
            Sleep(10)
        EndIf

        $vLastNote = $note
        info("undeclared")
EndFunc

Func testScale()
    setKey()
    setScale(GuiCtrlRead($scaleList))
    _ArrayDisplay($vCurScale)
    _ArrayDisplay($vNoteToPos)
    For $i = 1 to $vScaleSize
        setNote($vCurScale[$i])
        Sleep(2000)
        Send("{RIGHT}")
        Sleep(2000)
    Next
    setPos(1)
EndFunc

Func setPos($newPos)
    While $newPos < $vPos
        Send("{DOWN}")
        Sleep(2)
        $vPos -= 1
    WEnd
    While $newPos > $vPos
        Send("{UP}")
        Sleep(2)
        $vPos += 1
    WEnd
EndFunc

Func makeSheet()
    For $i = 1 To ($vMeasures*8)
        setNote()
        Sleep(30)
        Send("{RIGHT}")
        Sleep(30)
        checkGuiMsg()
        If $pause = 1 Then
            $i = ($vMeasures*8)+1
        EndIf
    Next
    setPos(1)
EndFunc

Func setSingleNote()
    setKey()
    getFromGui()
    setnote()
EndFunc

Func quit()
    Exit
EndFunc

Func checkGuiMsg()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartPause
            $pause = Not $pause
            If $pause = 1 Then
                $pause = 0
                setKey()
                getFromGui()
                GUICtrlSetData($StartPause, "Pause")
                WinActivate(WinGetTitle("Guitar Pro"))
                Sleep(500)
                makeSheet()
            Else
                GUICtrlSetData($StartPause, "Start")
            EndIf
        Case $Force
            If $vForce = 0 Then
                $vForce = 1
                WinActivate(WinGetTitle("Guitar Pro"))
                While GUIGetMsg() <> $Force
                    Sleep(100)
                    Send("{NUMPADADD}")
                    For $i = 0 to 7
                        Sleep(100)
                        Send("{ENTER}")
                        Sleep(100)
                        Send("{RIGHT}")
                    Next
                WEnd
            EndIf
        Case $resetpos
            $pause = 1
            $vForce = 0
            $vPos = 0
    EndSwitch
EndFunc

While 1
    checkGuiMsg()
WEnd
  • Moderators
Posted

icemens,

Welcome to the AutoIt forum. :graduated:

There is a problem in your checkGuiMsg() function which is preventing it from working correctly. You are changing the $pause variable twice which means it never gets set! If you remove the <<<<<<<<<<< line shown below the function works correctly: :(

Func checkGuiMsg()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartPause
            $pause = Not $pause
            If $pause = 1 Then
                ;$pause = 0  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                setKey()
                getFromGui()
                GUICtrlSetData($StartPause, "Pause")
                WinActivate(WinGetTitle("Guitar Pro"))
                Sleep(500)
                makeSheet()
            Else
                GUICtrlSetData($StartPause, "Start")
            EndIf
        Case $Force
            If $vForce = 0 Then
                $vForce = 1
                WinActivate(WinGetTitle("Guitar Pro"))
                While GUIGetMsg() <> $Force
                    Sleep(100)
                    ; Send("{NUMPADADD}")
                    For $i = 0 to 7
                        Sleep(100)
                        ; Send("{ENTER}")
                        Sleep(100)
                        ; Send("{RIGHT}")
                    Next
                WEnd
            EndIf
        Case $resetpos
            $pause = 1
            $vForce = 0
            $vPos = 0
    EndSwitch
EndFunc

You also need to set $pause to 0 (not 1) when you first declare it. :D

Once these changes are made, I get the button working correctly. I have no idea where the 3 secs wait comes from. You have a .5 sec Sleep, perhaps the remaining delay came from the other functions within the loop - as I do not have the Guitar Pro app you are using I cannot test further. Please come back if the problem persists. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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
×
×
  • Create New...