-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound_manage.js
74 lines (51 loc) · 2.36 KB
/
sound_manage.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
let octave;
let notes = ['C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'G#', 'A', 'Bb', 'B', 'C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'G#', 'A', 'Bb', 'B', 'C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'A', 'Bb', 'B', 'C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'A', 'Bb', 'B', 'C'];
let Rightkeys = ['KeyQ', 'Digit2', 'KeyW', 'Digit3', 'KeyE', 'KeyR', 'Digit5', 'KeyT', 'Digit6', 'KeyY', 'Digit7', 'KeyU', 'KeyI', 'Digit9', 'KeyO', 'Digit0', 'KeyP', 'BracketLeft', 'Equal', 'BracketRight'];
let Leftkeys = ['KeyZ','KeyS','KeyX','KeyD','KeyC','KeyV', 'KeyG', 'KeyB', 'KeyH', 'KeyN', 'KeyM', 'KeyK', 'Comma', 'KeyL', 'Period', 'Semicolon','Slash']
octave = 4;
piano = new Tone.Sampler({
urls: {
C4: "C4v14.mp3",
"D#4": "D%234v14.mp3",
"F#4": "F%234v14.mp3",
C5: "C5v14.mp3",
"F#5": "F%235v14.mp3",
A5:"A5v14.mp3",
"D#5:":"D%235v14.mp3",
C6: "C6v14.mp3",
C7: "C7v14.mp3",
},
release: 0.8,
volume: 0.4,
baseUrl: "https://unpkg.com/@audio-samples/[email protected]/audio/",
}).toDestination();
const keyInteract = document.querySelectorAll('.key');
keyInteract.forEach(key => key.addEventListener('mousedown', changecolor));
function changecolor() {
this.style.backgroundColor = 'red';
console.log("hellp");
}
window.addEventListener('keypress', function (e) {
if (e.repeat) { return;}
var keyID = e.code;
for (let i = 0; i < 12; i++) { // controls assigning keys from c to b
if (keyID === Rightkeys[i]) {
piano.triggerAttackRelease(notes[i] + octave.toString(), "8n");
}
}
for (let i =12; i < 21; i++) { // controls assigning keys from c to b
if (keyID === Rightkeys[i]) {
piano.triggerAttackRelease(notes[i] + (octave+1).toString(), "8n");
}
}
for (let i = 7; i <27 ; i++) { // controls assigning keys from c to b
if (keyID === Leftkeys[i - 7]) {
if (i < 12) {
piano.triggerAttackRelease(notes[i] + (octave - 2).toString(), "8n");
}
if (i >= 12) {
piano.triggerAttackRelease(notes[i] + (octave - 1).toString(), "8n");
}
}
}
}, false);