-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonoNote.java
42 lines (34 loc) · 1.19 KB
/
monoNote.java
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
import com.cycling74.max.*;
public class monoNote extends MaxObject {
int lastNote = -1;
boolean lastTie = false;
float velScale = 1.f;
monoNote() {
declareInlets(new int[] { DataTypes.LIST, DataTypes.INT });
declareOutlets(new int[] { DataTypes.LIST });
}
protected void inlet(int a) {
velScale = ((float) a) / (127.f);
}
protected void list(Atom[] a) {
int note = a[1].getInt();
int vel = a[2].getInt();
float duration = a[3].getFloat();
boolean tie = duration == 120;
boolean rest = vel == 0;
int outVel = (int) (vel * velScale);
if (lastNote == -1 && !rest) {
outlet(0, new int[] { note, outVel });
} else if (lastTie && !rest && lastNote != note) {
outlet(0, new int[] { note, outVel });
outlet(0, new int[] { lastNote, 0 });
} else if (lastNote != -1 && rest) {
outlet(0, new int[] { lastNote, 0 });
} else if (lastNote != -1 && !lastTie) {
outlet(0, new int[] { lastNote, 0 });
outlet(0, new int[] { note, outVel });
}
lastNote = rest ? -1 : note;
lastTie = tie;
}
}