-
Notifications
You must be signed in to change notification settings - Fork 1
/
calcprobs.ts
49 lines (44 loc) · 1.13 KB
/
calcprobs.ts
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
inlets = 3;
outlets = 2;
var octProbs: number[] = [];
var noteProbs: number[] = [];
var noteToggles: number[] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
function list() {
switch (inlet) {
case 0:
octProbs = arrayfromargs(arguments);
octProbs.reverse();
break;
case 1:
noteProbs = arrayfromargs(arguments);
break;
case 2:
noteToggles = arrayfromargs(arguments);
break;
}
bang();
}
function bang() {
const used: number[] = [];
let note = 0;
const accumProbs: number[] = [];
let accum = 0;
for (let i = 0; i < octProbs.length; i++) {
for (let j = 0; j < noteProbs.length; j++) {
const prob = octProbs[i] * noteProbs[j] * noteToggles[j];
if (prob > 0) {
used.push(note);
}
accum += prob;
accumProbs.push(accum);
note++;
}
}
for (let i = 0; i < accumProbs.length; i++) {
accumProbs[i] = accumProbs[i] / accum;
}
outlet(0, used);
outlet(1, accumProbs);
}
let module = {};
export = {};