document.addEventListener('DOMContentLoaded',function(){const volumeSlider=document.getElementById('volumeControl');const volumeRValue=document.getElementById('volumeRValue');const tempoDisplay=document.getElementById('tempo-display');const tempoIncreaseBtn=document.getElementById('tempo-increase');const tempoDecreaseBtn=document.getElementById('tempo-decrease');function updateVolumeDisplay(value){volumeRValue.textContent=Math.round(parseFloat(value)*100)}
volumeSlider.addEventListener('input',(e)=>{updateVolumeDisplay(e.target.value)});volumeSlider.addEventListener('dblclick',(e)=>{volumeSlider.value=0.5;updateVolumeDisplay(0.5)});updateVolumeDisplay(volumeSlider.value);window.addEventListener("load",function(){document.querySelector(".ptpiano-loader").style.display="none";document.querySelector(".ptpiano-content").style.display="block"});const defaultTempo=160;tempoDisplay.textContent=defaultTempo;let tempoInterval;function updateTempo(newTempo){tempoDisplay.textContent=newTempo;pianoRecorder.setTempo(newTempo)}
function startChangingTempo(changeFn){changeFn();tempoInterval=setInterval(changeFn,100)}
function stopChangingTempo(){clearInterval(tempoInterval)}
function increaseTempo(){let currentTempo=parseInt(tempoDisplay.textContent);if(currentTempo<300){currentTempo++;updateTempo(currentTempo)}}
function decreaseTempo(){let currentTempo=parseInt(tempoDisplay.textContent);if(currentTempo>30){currentTempo--;updateTempo(currentTempo)}}
tempoIncreaseBtn.addEventListener('mousedown',()=>startChangingTempo(increaseTempo));tempoIncreaseBtn.addEventListener('mouseup',stopChangingTempo);tempoIncreaseBtn.addEventListener('mouseleave',stopChangingTempo);tempoDecreaseBtn.addEventListener('mousedown',()=>startChangingTempo(decreaseTempo));tempoDecreaseBtn.addEventListener('mouseup',stopChangingTempo);tempoDecreaseBtn.addEventListener('mouseleave',stopChangingTempo);tempoIncreaseBtn.addEventListener('touchstart',()=>startChangingTempo(increaseTempo));tempoIncreaseBtn.addEventListener('touchend',stopChangingTempo);tempoDecreaseBtn.addEventListener('touchstart',()=>startChangingTempo(decreaseTempo));tempoDecreaseBtn.addEventListener('touchend',stopChangingTempo);const paddleplayButton=document.getElementById('paddleBtn');paddleplayButton.addEventListener('click',async()=>{const markedKeys=document.querySelectorAll('.piano-keys .key.mark');console.log(`Selected keys: ${markedKeys.length}`);if(markedKeys.length===0||markedKeys.length>6)return;const playTogether=!0;if(playTogether){markedKeys.forEach(key=>{const note=key.dataset.key||key.dataset.note;if(note)playTune(note);})}else{for(let i=0;i<markedKeys.length-2;i++){const key=markedKeys[i];const note=key.dataset.key||key.dataset.note;if(note){playTune(note);await new Promise(res=>setTimeout(res,200))}}}})})