by Technicality » Mon Mar 01, 2021 1:46 am
Here's the code for the macro player in case you'd rather just copy/paste it into your own ahk script instead
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
#singleinstance force
ListLines Off
Process, Priority, , High
SetBatchLines, -1
SetKeyDelay, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
Gui, Add, Text,, Type Song Name Below
Gui, Add, Edit, w300 vSongName,
Gui, Add, Text,, Controls
Gui, Add, Text,, F1 pauses the app
Gui, Add, Text,, F2 pauses the app
Gui, Add, Text,, F3 closes the app
Gui, SongProgress:Add, Edit, w400 h300 vSheetProgress
StringCaseSense, On
Keys := []
noteOrSleep := []
KeysToPlay := []
SleepNext := []
nkey = 0
global notif := false
nchord := ""
rest = 0
;~~~~~~~~~~~~~~~~Adjust Delay Variable~~~~~~~~~~~~~
global Delay = 80
;~~~~~~~~~~~~~~~~Adjust Delay Variable~~~~~~~~~~~~~
global Delay2 := Delay / 10
global isSleep := false
counter := new SecondCounter
hotkey, F2, pauseScript
Gui, Show
F1::
global isSleep, notif
Gui, Submit, Nohide
FileDelete, Sheet Music/%SongName%.txt
Loop, read, %SongName%.ahk
{
Loop, parse, A_LoopReadLine, %A_Space%
{
var = %A_Loopfield%
if (isSleep = true){
if(notif = true){
nChord := ""
}
if (nChord > ""){
Keys.Push(nChord)
NoteOrSleep.Push(1)
nChord := ""
}
Keys.Push(var)
NoteOrSleep.Push(0)
isSleep := false
notif := false
}else if (notif = true){
if (nChord > ""){
Keys.Push(nChord)
NoteOrSleep.Push(1)
nChord := ""
}
notif := false
}else{
if (var = "{Numpad1"){
nkey = 1
}
if (var = "{Numpad2"){
nkey = 2
}
if (var = "{Numpad3"){
nkey = 3
}
if (var = "{Numpad4"){
nkey = 4
}
if (var = "{Numpad5"){
nkey = 5
}
if (var = "{Numpad6"){
nkey = 6
}
if (var = "{Numpad7"){
nkey = 7
}
if (var = "{Numpad8"){
nkey = 8
}
if (var = "{Numpad9}"){
nkey = 0
nchord := nchord . nKey
notif := true
}
if (var = "{Numpad0}"){
nkey = 9
nchord := nchord . nKey
notif := true
}
if (var = "down}"){
nchord := nchord . nKey
}
if (var = "up}"){
notif := true
}
}
if (var = "Sleep,"){
isSleep := true
}
}
}
klen := Keys.Length()
nlen := NoteOrSleep.Length()
Gui, Font, s12, Verdana
;Gui, SongProgress:Show,,Sheet Music
toLoop = 1
Loop %klen%
{
isNote := NoteOrSleep[toLoop]
toPlay := Keys[toLoop]
isNextNote := NoteOrSleep[toLoop + 1]
toPlayNext := Keys[toLoop + 1]
if (isNote = 0){
if ((toPlayNext = 0) || (toPlayNext = 9))
{
toSleep := toPlay - Delay
if (toSleep > 0)
{
KeysToPlay.Push(Delay)
SleepNext.Push(0)
KeysToPlay.Push(toPlayNext)
SleepNext.Push(1)
KeysToPlay.Push(toSleep)
SleepNext.Push(0)
toLoop++
}else{
KeysToPlay.Push(toPlay)
SleepNext.Push(0)
}
}else{
KeysToPlay.Push(toPlay)
SleepNext.Push(0)
}
}else{
KeysToPlay.Push(toPlay)
SleepNext.Push(1)
}
toLoop++
}
klen := KeysToPlay.Length()
nlen := SleepNext.Length()
Loop %klen%
{
toSheet := KeysToPlay[A_Index]
if StrLen(toSheet) > 1
{
toText .= "[" . KeysToPlay[A_Index] . "]" . " "
}else{
toText .= KeysToPlay[A_Index] . " "
}
}
;GuiControl,SongProgress:, SheetProgress, %toText%
Loop %klen%
{
isNote := SleepNext[A_Index]
toPlay := KeysToPlay[A_Index]
if (isNote = 1){
Loop, parse, toPlay
{
var := A_LoopField
if ((var = 9) || (var = 0))
{
if (counter.count > 0)
{
dif = %Delay%
dif -= (counter.count * 10)
;Msgbox, %dif%
Sleep, %dif%
}
counter.Stop()
counter.Start()
}
Send %var%
}
}else{
Sleep, %toPlay%
}
}
return
F3::ExitApp
pauseScript:
pause
return
GuiClose:
ExitApp
class SecondCounter {
__New() {
this.interval := 1
this.count := 1
; Tick() has an implicit parameter "this" which is a reference to
; the object, so we need to create a function which encapsulates
; "this" and the method to call:
this.timer := ObjBindMethod(this, "Tick")
}
Start() {
; Known limitation: SetTimer requires a plain variable reference.
timer := this.timer
this.count := 1
SetTimer % timer, % this.interval
;ToolTip % "Counter started"
}
Stop() {
; To turn off the timer, we must pass the same object as before:
timer := this.timer
this.count := 0
SetTimer % timer, Off
;ToolTip % "Counter stopped at " this.count
}
; In this example, the timer calls this method:
Tick() {
global Delay2
this.count++
if (this.count >= Delay2){
this.Stop()
this.count := 0
}
;ToolTip % this.count
}
}