const sounds = [];
function klavyesesYap()
{
var girisK=document.getElementById('textt').value;
const array = girisK.split(",");
if (sounds.length > 0) {
sounds.forEach((sound) => {
sound.pause();
sound.currentTime = 0;
})
sounds.length = 0;
}
for(j = 0; j < array.length; j++)
{
if ( array[j] == 'W' )
{
var tom1 = new Audio("ses/tom-1.mp3");
sounds.push(tom1);
}
else if (array[j] == 'A')
{
var tom2 = new Audio("ses/tom-2.mp3");
sounds.push(tom2);
}
else if (array[j] == 'S')
{
var crash = new Audio("ses/crash.mp3");
sounds.push(crash);
}
else if (array[j] == 'D')
{
var tom4 = new Audio("ses/tom-4.mp3");
sounds.push(tom4);
}
else if (array[j] == 'J')
{
var snare = new Audio("ses/snare.mp3");
sounds.push(snare);
}
else if (array[j] == 'K')
{
var crash = new Audio("ses/crash.mp3");
sounds.push(crash);
}
else if (array[j] == 'L')
{
var kick = new Audio("ses/kick-bass.mp3");
sounds.push(kick);
}
else
{
var bip = new Audio('ses/bip.mp3');
sounds.push(bip);
}
}
if (sounds.length > 0) {
sounds.forEach((sound, index) => {
setTimeout(() => {
sound.play();
if (index === sounds.length - 1) {
sound.addEventListener('ended', () => {
sounds.length = 0;
}, {once: true});
}
}, index * 2000);
});
}
}