This repository has been archived by the owner on Feb 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtxtParser.ahk
82 lines (76 loc) · 1.5 KB
/
txtParser.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class txtNote {
note := ""
deltaMs := 0
heldMs := 0
}
class TxtFile
{
notes := []
numNotes := 1
trackIndex := 1
__New(filename) {
file := FileOpen(filename, "r-d")
if(file) {
msTemp := 0
pauseMs := 100
holdMs := 100
delay := 0
while(!file.AtEOF) {
s := RegExReplace(file.ReadLine(), "\r\n$","")
i := SubStr(s, 1, 1)
if(i == ";") {
continue
}
if(i == "p") {
pauseMs := SubStr(s, 2)
continue
}
if(i == "d") {
delay := SubStr(s, 2)
continue
}
if(i == "h") {
holdMs := SubStr(s, 2)
continue
}
Loop, parse, s, %A_Space%
{
if(InStr(A_LoopField, "/")) {
; Parse as pause
n := 0
Loop, parse, A_LoopField
{
n += 1
}
msTemp += pauseMs * n
}
else if(Ord(A_LoopField) > 32) {
nstr := A_LoopField
hms := note.heldMs
ppos := InStr(nstr, ",")
if(ppos) {
; single note delay
hms := SubStr(nstr, ppos+1)
nstr := SubStr(nstr, 1, ppos-1)
} else {
hms := holdMs
}
; Parse as note
note := new txtNote()
note.note := nstr
note.deltaMs := msTemp + delay
note.heldMs := hms
msTemp := 0
this.notes.Push(note)
this.numNotes += 1
} else {
; Treat newline as a single / so you can hear it
msTemp += pauseMs
}
}
}
file.Close()
}
base.__New()
}
}