-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.js
46 lines (40 loc) · 946 Bytes
/
custom.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
var chordsDiv = document.getElementById('chords');
var chords = [];
// Dragndrop stuff
function drag(event) {
event.dataTransfer.setData("text", event.target.value);
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
// event.preventDefault();
var data = event.dataTransfer.getData("text");
var visualData = document.createTextNode(data);
chordsDiv.appendChild(visualData);
chords.push(data);
}
// Play stuff
var audio;
var url;
var time;
var delay;
document.getElementById('play').onclick = function () {
delay = document.getElementById('delay').value;
if(!delay) {
delay = 1000;
}
var i = 0;
time = setInterval(function(){
console.log('I play ' + chords[i]);
audio = document.createElement('audio');
url = 'sounds/' + chords[i] + '.m4a';
audio.setAttribute('src', url);
audio.type = 'audio/mpeg'; //m4a?
audio.play();
i++;
if(!chords[i]){
clearInterval(time);
}
}, delay);
}