-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
80 lines (65 loc) · 1.94 KB
/
main.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
//shortening addEventListener because I hate typing it over and over
Object.prototype.ev = function (evtName, cbk) {
return this.addEventListener(evtName, cbk);
}
var conv = new Tone.Convolver("sounds/singlefootstep.wav").toMaster();
conv.wet.value = 1;
var filter = new Tone.Filter(4830, "lowpass", -12, 0, 0).toMaster();
var player = new Tone.Player("sounds/singlefootstep.wav").connect(filter).connect(conv);
var btn = document.getElementById("trigger");
btn.ev("click", function (evt) {
if (!document.body.classList.contains("added")) {
document.body.classList.add("added");
setInterval(function () {
player.start();
}, 200);
} else {
console.log("sound is already playing");
}
});
function increaseWet() {
if (conv.wet.value <= 1) {
conv.wet.value += 0.1;
console.log("convolver wet value " + conv.wet.value);
}
}
function decreaseWet() {
if (conv.wet.value >= 0) {
conv.wet.value -= 0.1;
console.log("convolver wet value " + conv.wet.value);
}
}
function increaseFreq() {
if (filter.frequency.value < 5000) {
filter.frequency.value += 100;
console.log("filter frequency: " + filter.frequency.value);
}
}
function decreaseFreq() {
if (filter.frequency.value > 100) {
filter.frequency.value -= 100;
console.log("filter frequency " + filter.frequency.value);
}
}
btn.ev("keydown", function (evt) {
switch (evt.key) {
case "ArrowUp":
evt.preventDefault();
increaseWet();
break;
case "ArrowDown":
evt.preventDefault();
decreaseWet();
break;
case "ArrowLeft":
evt.preventDefault();
decreaseFreq();
break;
case "ArrowRight":
evt.preventDefault();
increaseFreq();
break;
default:
console.log("not an arrow key");
}
})