-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindnotes.java
54 lines (48 loc) · 1.47 KB
/
findnotes.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
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.LinkedList;
import com.cycling74.max.*;
public class findnotes extends MaxObject {
float[] probs = new float[0];
Atom[] atoms = new Atom[0];
int[] notes = new int[0];
int nudge = 0;
findnotes() {
declareInlets(new int[] { DataTypes.LIST, DataTypes.LIST });
declareOutlets(new int[] { DataTypes.LIST });
}
protected void list(final Atom[] a) {
final int idx = getInlet();
switch (idx) {
case 0:
atoms = Atom.reverse(a);
break;
case 1:
probs = Atom.toFloat(a);
break;
}
bang();
}
public void setNudge(int n) {
nudge = n;
bang();
}
protected void bang() {
if (atoms.length > 0) {
final float[] floats = Atom.toFloat(Atom.rotate(atoms, -nudge));
final LinkedList<Integer> noteList = new LinkedList<Integer>();
for (int i = 0; i < floats.length; i++) {
float v = floats[i];
for (int j = 0; j < probs.length; j++) {
if ((v < 1.) ? (v < probs[j]) : (v == probs[j])) {
noteList.push(j);
break;
}
}
}
notes = new int[noteList.size()];
for (int i = 0; i < notes.length; i++) {
notes[i] = noteList.get(i);
}
outlet(0, notes);
}
}
}