-
Notifications
You must be signed in to change notification settings - Fork 1
/
findTiesAndAccents.ts
77 lines (67 loc) · 1.5 KB
/
findTiesAndAccents.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
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
inlets = 2;
outlets = 2;
let floats: number[] = [];
let choices: string[] = [];
let bot: number;
let top: number;
function list() {
switch (inlet) {
case 0:
floats = arrayfromargs(arguments);
bang();
break;
}
}
function setChoices() {
choices = arrayfromargs(arguments);
bang();
}
function setBot(n: number) {
bot = n;
bang();
}
function setTop(n: number) {
top = n;
bang();
}
function bang() {
const stages = [
bot,
1 + top,
1
]
const durations: number[] = []
const velocities: number[] = []
const addChoice = (choice: string | undefined) => {
if (choice !== undefined) {
velocities.push(
choice.indexOf('R') >= 0
? 0
: choice.indexOf('A') >= 0
? 127
: 63
)
durations.push(
choice.indexOf('T') >= 0
? 120
: 60
)
}
}
for (let f of floats) {
let i: number
f = f * nextFloatDown;
for (i = 0; i < stages.length; i++) {
if (f < stages[i]) {
break;
}
}
addChoice(choices[i]);
}
if (durations.length > 0 && velocities.length > 0) {
outlet(0, ["duration", 1, ...durations]);
outlet(0, ["velocity", 1, ...velocities]);
outlet(1, velocities.map(x => +(x === 127)));
}
}
const nextFloatDown = (1 - 2 ** -53);