-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm-script.js
More file actions
44 lines (39 loc) · 1.33 KB
/
m-script.js
File metadata and controls
44 lines (39 loc) · 1.33 KB
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
const play=document.querySelector(".play");
function makemusic(){
const kick = new Tone.Player("./Drums/kick-classic.wav").toDestination(); //or toMaster
const snare = new Tone.Player("./Drums/snare-lofi02.wav").toDestination(); //or toMaster
const hihat = new Tone.Player("./Drums/hihat-dist01.wav").toDestination(); //or toMaster
let counter=0;
Tone.start();
Tone.Transport.scheduleRepeat(repeatfunc, "8n");
Tone.Transport.bpm.value=120;
Tone.Transport.start();
// main function
function repeatfunc(){
let currbox=counter%8;
kickinput=document.querySelector(`.kick input:nth-child(${currbox+1})`);
snareinput=document.querySelector(`.snare input:nth-child(${currbox+1})`);
hihatinput=document.querySelector(`.hihat input:nth-child(${currbox+1})`);
if(kickinput.checked){
kick.start();
}
if(snareinput.checked){
snare.start();
}
if(hihatinput.checked){
hihat.start();
}
counter++;
}
}
play.addEventListener("click", start, {once: true}); //once true for not to repeat the func makemusic in case the user click it again
function start(){
makemusic();
}
const clear=document.querySelector(".clear");
clear.addEventListener("click", ()=>{
const inputs=document.querySelectorAll("input[type='checkbox']");
inputs.forEach(element => {
element.checked=false;
});
});