forked from vult-dsp/vult
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonoin.vult
43 lines (36 loc) · 1.17 KB
/
monoin.vult
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
/* These two functions handle midi on/off events in order to behave
* like a monophonic sinthesizer that can hold 4 notes */
// Activates a note and returns the current note value
fun noteOn(n){
mem n1,n2,n3,n4;
mem count,pre;
// written this way because Vult does not have array support yet.
if(count == 0) { n1 = n; pre = n; } else
if(count == 1) { n2 = n; pre = n; }else
if(count == 2) { n3 = n; pre = n; }else
if(count == 3) { n4 = n; pre = n; }
if(count <= 4) count = count + 1;
return pre;
}
// Deactivates a note and returns the following note value;
fun noteOff(n){
mem n1,n2,n3,n4;
mem count,pre;
val found = false;
if(n == n1) { n1,n2,n3 = n2,n3,n4; found = true; } else
if(n == n2) { n2,n3 = n3,n4; found = true; } else
if(n == n3) { n3 = n4; found = true; } else
if(n == n4) { found = true; }
if(found && count>0) count = count - 1;
if(count == 1) pre = n1;
if(count == 2) pre = n2;
if(count == 3) pre = n3;
if(count == 4) pre = n4;
return pre;
}
// Returns true if any note is active
fun isGateOn(){
mem n1,n2,n3,n4;
mem count,pre;
return if count>0 then 1 else 0;
}