-
Notifications
You must be signed in to change notification settings - Fork 0
/
presets.js
107 lines (103 loc) · 2.89 KB
/
presets.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
let category;
const getSelected = (menu_name) => {
const radio = document.querySelector(`input[name="${menu_name}"]:checked`);
if (radio) {
return radio.value
} else {
return null;
}
};
const onMenuChange = () => {
const f = (x) => {
if (x) return 'block';
return 'none';
}
category = getSelected('category');
document.getElementById('note-menu').style.display = f(
category === 'note'
);
document.getElementById('interval-menu').style.display = f(
category === 'interval'
);
const is_chord = category === 'chord';
document.getElementById('chord-menu').style.display = f(
is_chord
);
document.getElementById('negative-menu').style.display = f(
category && ! is_chord
);
document.getElementById('inversion-menu').style.display = f(
is_chord
);
if (category) {
usePreset(is_chord);
}
};
const usePreset = (is_chord) => {
const chord = getSelected(category);
if (chord === null) return;
let negative; let inversion;
if (is_chord) {
inversion = parseInt(getSelected('inversion'));
if (isNaN(inversion)) return;
} else {
negative = parseInt(getSelected('negative'));
if (isNaN(negative)) return;
}
piano.clearActivation();
amp_rotate.keys = [60];
switch (category) {
case 'note':
piano.setActivation(60 + parseInt(chord) * negative, 100);
break;
case 'interval':
piano.setActivation(60, 100);
const other = 60 + parseInt(chord) * negative;
piano.setActivation(other, 100);
amp_rotate.keys.push(other);
break;
case 'chord':
const components = {
maj: [4, 7],
min: [3, 7],
aug: [4, 8],
dim: [3, 6],
"7 ": [4, 7, 10],
"Maj7 ": [4, 7, 11],
"Maj9 ": [4, 7, 11, 14],
"Add2 ": [2, 4, 7],
"MinAdd2 ": [2, 3, 7],
"11(omit3, omit5)": [10, 14, 17],
"13 ": [4, 10, 21],
"sus4 ": [5, 7],
"sus2 ": [2, 7],
"Maj13(#11) ": [4, 7, 11, 14, 18, 21],
}[chord];
while (inversion > 1) {
inversion --;
components.unshift(components.pop() - 12);
}
piano.setActivation(60, 100);
components.forEach((offset) => {
piano.setActivation(60 + offset, 100);
amp_rotate.keys.push(60 + offset);
});
break;
}
};
let amp_rotate = {
keys: [],
progress: 0,
};
const handleAmpRotate = () => {
if (! parameters.amp_rotate) return;
const period = amp_rotate.keys.length;
amp_rotate.progress = (amp_rotate.progress + .003) % period;
const three_pillars = [-period, 0, +period].map((x) => (
x + amp_rotate.progress
));
amp_rotate.keys.forEach((pitch, i) => {
const distance = min(three_pillars.map((pillar) => (abs(pillar - i))));
piano.setActivation(pitch, max(0, 1.3 - distance) * 100, true);
});
};