forked from zfisch/musicalmessage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.js
executable file
·94 lines (83 loc) · 2.17 KB
/
message.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
//This file sets up a system for mapping keystrokes to sounds and storing them in an array. The listener loops through the array indefinitely.
//set up key mapping
sounds = [];
for(i=0; i<222; i++) {
sounds[i] = '' + i + '.wav';
};
//capture keystrokes of a message
var keys = document.getElementById("keyStrokes");
keys.addEventListener("keydown", captureKeys, false);
var message = [];
var counter = 0;
function captureKeys(e){
playKey(e.keyCode);
if (counter < 16) {
message[counter] = e.keyCode;
counter += 1;
console.log(message);
//make sure to set up play key sound here!!
} else {
message[counter] = e.keyCode;
message.length = 16;
counter = 0;
console.log(message);
}
};
//play sound for each key hit
function playKey(e){
document.getElementById(e).play();
};
//play message
//Eric turned this into a While Loop
function playMessage() {
setInterval(function(){
var i = 0;
while (i < message.length) {
console.log("key down # " + message.length);
console.log(message[i]);
playKey(message[i]);
i++;
}
}, 1000);
}
// // This was your original play message
// function playMessage() {
// i = 0;
// if (message.length == 0) {
// alert("Please leave a message for me to play!");
// } else {
// window.setInterval( function changeSounds() {
// if (i == message.length) {
// console.log(i);
// console.log(message);
// playKey(message[i]);
// i = 0;
// } else {
// console.log(i);
// console.log(message);
// playKey(message[i]);
// i += 1;
// };
// }, 500);
// }
// };
//play message after user clicks listen
function playMessageTwo() {
oscillator.start();
i = 0;
if (message.length == 0) {
alert("Please leave a message for me to play!");
} else {
window.setInterval( function changeFrequency() {
if (i > message.length) {
i = 0;
oscillator.frequency.value = (message[i] * 10);
} else {
oscillator.frequency.value = (message[i] * 10);
i += 1;
};
console.log(message);
console.log(oscillator.frequency.value);
}, 5000);
}
};