-
Notifications
You must be signed in to change notification settings - Fork 2
/
miditools.ahk
98 lines (80 loc) · 1.68 KB
/
miditools.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
; MidiKnob interface
; for endless knob which returns values 0..127
; and if on left or right 0 or 127 gets repeated
; we call <name>left or <name>right if rotated
Class MidiKnob
{
; Instance creation
__New(name)
{
this.lastvalue:=65
this.name:=name
}
; Instance destruction
__Delete()
{
}
calledCc(midi){
ccValue := midi.value
OutputDebug, CC1 %ccValue%`r`n
if (ccValue>this.lastvalue or ccValue==127){
labelNameSuffix:="right"
} else if (ccValue<this.lastvalue or ccValue==0){
labelNameSuffix:="left"
}
labelName:=this.name labelNameSuffix
If IsFunc( labelName )
%labelName%(midi)
this.lastvalue:=ccValue
}
}
; MidiRepeat interface
; runs <name>first if pressed
; starts to repeat <name>repeat after 500ms at interval of 10ms
; if midioff comes start <name>stop
Class MidiRepeat
{
; Instance creation
__New(name)
{
this.state:=0
this.name:=name
this.timer := ObjBindMethod(this, "fire")
}
; Instance destruction
__Delete()
{
}
fire(){
timer := this.timer
if (this.state==0){
return
} else if (this.state==1){
labelNameSuffix:="first"
this.state:=2
SetTimer % timer, 500
} else if (this.state==2){
labelNameSuffix:="repeat"
SetTimer % timer, 10
} else if (this.state==3){
labelNameSuffix:="stop"
SetTimer % timer, Off
}
labelName:=this.name labelNameSuffix
If IsFunc( labelName )
%labelName%(midi)
if (this.state==3){
this.state:=0
}
}
calledNoteOn(midi){
if (this.state==0){
this.state:=1
}
this.fire()
}
calledNoteOff(midi){
this.state:=3
this.fire()
}
}