let timerInerval;let time=timerInerval;let timer;let timerIsWork=false;let timerBool_15=false;let timerBool_30=false;let timerBool_60=false;let timerBtn15=document.getElementById("Timer15");timerBtn15.addEventListener("click",timer15);let timerBtn30=document.getElementById("Timer30");timerBtn30.addEventListener("click",timer30);let timerBtn60=document.getElementById("Timer60");timerBtn60.addEventListener("click",timer60);function timer15(){timerBool_15=true;timerBool_30=false;timerBool_60=false;if(timerIsWork==false){clearInterval(timer);time=15000;timerIsWork=true;timer=setInterval(()=>resetProgBar(),time);clearInterval(progTimer);progressWith=0;progressInterval=75;progBtimer();}else if(timerIsWork==true){clearInterval(progTimer);clearInterval(timer);progressWith=0;timerIsWork=false;document.getElementById("ProgressBar").style.width=progressWith+"px";prog15.updateSize();prog30.updateSize();prog60.updateSize();}} function timer30(){timerBool_15=false;timerBool_30=true;timerBool_60=false;if(timerIsWork==false){clearInterval(timer);time=30000;timerIsWork=true;timer=setInterval(()=>resetProgBar(),time);clearInterval(progTimer);progressWith=0;progressInterval=150;progBtimer();}else if(timerIsWork==true){clearInterval(progTimer);clearInterval(timer);progressWith=0;timerIsWork=false;document.getElementById("ProgressBar").style.width=progressWith+"px";prog15.updateSize();prog30.updateSize();prog60.updateSize();}} function timer60(){timerBool_15=false;timerBool_30=false;timerBool_60=true;if(timerIsWork==false){clearInterval(timer);time=60000;timerIsWork=true;timer=setInterval(()=>resetProgBar(),time);clearInterval(progTimer);progressWith=0;progressInterval=300;progBtimer();}else if(timerIsWork==true){clearInterval(progTimer);clearInterval(timer);progressWith=0;timerIsWork=false;document.getElementById("ProgressBar").style.width=progressWith+"px";prog15.updateSize();prog30.updateSize();prog60.updateSize();}} let progressWith=0;let progressInterval;let progTimer;let progIncide=document.querySelector(".timerSpan");function progreesWithUp(){progressWith++;document.getElementById("ProgressBar").style.width=progressWith+"px";if(timerBool_15===true){prog15.updateSize();} if(timerBool_30===true){prog30.updateSize();} if(timerBool_60===true){prog60.updateSize();} if(progressWith>199){progressWith=0;}} function progBtimer(){progTimer=setInterval(progreesWithUp,progressInterval);} let sumBpm=0;let sumBpmCounter=-1;let bestBpmRes=0;function resetProgBar(){nextPattern();progressWith=0;prog15.updateSize();prog30.updateSize();prog60.updateSize();} function timezero(){clearInterval(progTimer);clearInterval(timer);progressWith=0;prog15.updateSize();prog30.updateSize();prog60.updateSize();timerIsWork=false;} class ProgressDiv{constructor(button){this.progDiv=document.createElement("div");this.progDiv.style.width=progressWith+"px";this.progDiv.style.height="80px";this.progDiv.style.borderRadius="4px";this.progDiv.style.top="0px";this.progDiv.style.left="0px";this.progDiv.style.position="absolute";this.progDiv.style.background="#2967ad8e";button.appendChild(this.progDiv);} updateSize(){this.progDiv.style.width=progressWith/2+"px";}} let prog15=new ProgressDiv(timerBtn15);let prog30=new ProgressDiv(timerBtn30);let prog60=new ProgressDiv(timerBtn60);const playBtn=document.querySelector("#playBtn");playBtn.addEventListener("click",startStopOnOff);function startStopOnOff(){if(playIsOn===false){playerStart();playIsOn=true;}else if(playIsOn===true){playerStop();playIsOn=false;draw();}} const Loader=document.querySelector(".loadDiv");document.body.onload=function(){setTimeout(()=>{Loader.style.display="none";},1000);};const appSettings=document.querySelector("#appSettings");const showSettingsBtn=document.querySelector("#showSettingsBtn");showSettingsBtn.addEventListener("click",function(e){if(appSettings.style.display==="none"){appSettings.style.display="flex";showSettingsBtn.classList.add("activeGreen");window.scrollTo(0,75);}else{appSettings.style.display="none";showSettingsBtn.classList.remove("activeGreen");window.scrollTo(0,0);}});const upTempoBtn=document.querySelector("#upTempoBtn");upTempoBtn.addEventListener("click",()=>{let tmpTempo=Number(setTempoRange.value);tmpTempo++;playerStop();Tone.Transport.bpm.value=tmpTempo;tempo=Number(setTempoRange.value);setTempoRange.value=tmpTempo;tempoLabel.textContent=setTempoRange.value;playbackRateTemp=tempo/tempTempoForChange;toneAudioTrack.playbackRate=playbackRateTemp;setTempo();});const downTempoBtn=document.querySelector("#downTempoBtn");downTempoBtn.addEventListener("click",()=>{let tmpTempo=Number(setTempoRange.value);tmpTempo--;playerStop();Tone.Transport.bpm.value=tmpTempo;tempo=Number(setTempoRange.value);setTempoRange.value=tmpTempo;tempoLabel.textContent=setTempoRange.value;playbackRateTemp=tempo/tempTempoForChange;toneAudioTrack.playbackRate=playbackRateTemp;setTempo();});addEventListener("keydown",keyControls);function keyControls(e){if(e.keyCode==187){let tmpTempo=Number(setTempoRange.value);tmpTempo++;playerStop();Tone.Transport.bpm.value=tmpTempo;tempo=Number(setTempoRange.value);setTempoRange.value=tmpTempo;tempoLabel.textContent=setTempoRange.value;playbackRateTemp=tempo/tempTempoForChange;toneAudioTrack.playbackRate=playbackRateTemp;setTempo();} if(e.keyCode==189){let tmpTempo=Number(setTempoRange.value);tmpTempo--;playerStop();Tone.Transport.bpm.value=tmpTempo;tempo=Number(setTempoRange.value);setTempoRange.value=tmpTempo;tempoLabel.textContent=setTempoRange.value;playbackRateTemp=tempo/tempTempoForChange;toneAudioTrack.playbackRate=playbackRateTemp;setTempo();} if(e.keyCode==80){if(playBtn.disabled==false){startStopOnOff();}} if(e.keyCode==88){if((timerIsWork==true)&(playIsOn===true)){startStopOnOff();timezero();} if((timerIsWork==false)&(playIsOn===true)){startStopOnOff();}else if((timerIsWork==true)&(playIsOn==false)){timezero();}} if(e.keyCode==49){timezero();timer15();} if(e.keyCode==50){timezero();timer30();} if(e.keyCode==51){timezero();timer60();} if(e.keyCode==84){timezero();} if(e.keyCode==190){nextPattern();} if(e.keyCode==188){prevPattern();} if(e.keyCode==76){resetPattern();} if(e.keyCode==27){} if(e.keyCode==77){} if(e.keyCode==78){} if(e.keyCode==66){} if(e.keyCode==86){} if(e.keyCode==68){} if(e.keyCode==82){} if(e.keyCode==69){} if(e.keyCode==83){speedDoubler();} if(e.keyCode==191){} if(e.keyCode==89){} if(e.keyCode==65){} if(e.keyCode==75){} if(e.keyCode==86){lockCymbalsOff();} if(e.keyCode==67){lockCymbalsFun();} if(e.keyCode==27){scrollToLesson();}} function clock(){let date=new Date(),hours=date.getHours()<10?"0"+date.getHours():date.getHours(),minutes=date.getMinutes()<10?"0"+date.getMinutes():date.getMinutes();seconds=date.getSeconds()<10?"0"+date.getSeconds():date.getSeconds();document.getElementById("clock").innerHTML=hours+":"+minutes;} setInterval(clock,1000);clock();const myModalSave=document.querySelector("#myModalSave");function saveInLC(){let temeToSave=JSON.stringify(currentTeme.Pattern);localStorage.setItem(`${currentTeme.TemeName}`,temeToSave);closeModal();} const saveInModal=document.querySelector("#saveInModal");saveInModal.addEventListener("click",()=>{saveInLC();myModalSave.style.display="none";});const loadUserTemeBtn=document.querySelector("#loadUserTemeBtn");loadUserTemeBtn.addEventListener("click",loadUserPatternFun);function loadUserPatternFun(){if(currentTeme["level"]==="sandbox"){loadFromLC();}} function loadFromLC(){if(localStorage.getItem(`${currentTeme.TemeName}`)!==null){let temeToLoad=localStorage.getItem(`${currentTeme.TemeName}`);currentTeme.Pattern=JSON.parse(temeToLoad);currentPattern=currentTeme.Pattern[patternNum];draw();}} const btnYes=document.getElementById("saveUserTemeBtn");btnYes.addEventListener("click",function(){myModalSave.style.display="block";});const doNotSaveInModal=document.querySelector("#doNotSaveInModal");doNotSaveInModal.addEventListener("click",function(){myModalSave.style.display="none";});window.onclick=function(event){if(event.target==myModalSave){myModalSave.style.display="none";}};function closeModal(){myModalSave.style.display="none";} let patternCopy=currentTeme.Pattern[patternNum];const copyPatternBtn=document.querySelector("#copyPatternBtn");copyPatternBtn.addEventListener("click",()=>{patternCopy=currentTeme.Pattern[patternNum];});const pastePatternBtn=document.querySelector("#pastePatternBtn");pastePatternBtn.addEventListener("click",()=>{let jsonPatternCopy=JSON.stringify(patternCopy);currentPattern=JSON.parse(jsonPatternCopy);currentTeme.Pattern[patternNum]=currentPattern;draw();});const favoriteContainer=document.querySelector("#favoriteContainer");const clearFavoriteTotal=document.querySelector("#clearFavoriteTotal");const myModalFavorite=document.getElementById("myModalFavorite");function addFavoriteFun(){localStorage.setItem(`${buttonForFavorite.id}`,`${buttonForFavorite.id}`);readFavoriteFromLC();clearFavoriteTotal.classList.remove("dNone");} function removeFromFavoriteFun(){if(currentTeme["level"]==="easy"){easyContainer.appendChild(buttonForFavorite);}else if(currentTeme["level"]==="medium"){mediumContainer.appendChild(buttonForFavorite);}else if(currentTeme["level"]==="hard"){hardContainer.appendChild(buttonForFavorite);}else if(currentTeme["level"]==="practice"){practiceContainer.appendChild(buttonForFavorite);}else if(currentTeme["level"]==="sandbox"){sandBoxContainer.appendChild(buttonForFavorite);}else{} sortInContainer(easyContainer);sortInContainer(mediumContainer);sortInContainer(hardContainer);sortInContainer(practiceContainer);sortInContainer(sandBoxContainer);localStorage.removeItem(`${buttonForFavorite.id}`);readFavoriteFromLC();if(favoriteContainer.childElementCount===0){clearFavoriteTotal.classList.add("dNone");}} function sortInContainer(container){const buttons=Array.from(container.querySelectorAll(".lessonButton"));buttons.sort((a,b)=>{const idA=parseInt(a.id.replace("lessonButtonId-",""),10);const idB=parseInt(b.id.replace("lessonButtonId-",""),10);return idA-idB;});buttons.forEach((button)=>container.appendChild(button));} function readFavoriteFromLC(){let totalStorage=localStorage;for(let el of Object.values(totalStorage)){if(el.includes("lessonButtonId-")){const btn=document.querySelector(`#${el}`);favoriteContainer.appendChild(btn);}} sortInContainer(favoriteContainer);if(favoriteContainer.childElementCount>0){clearFavoriteTotal.classList.remove("dNone");}} const favoriteBtnAdd=document.querySelector("#favoriteBtnAdd");let starOn=false;favoriteBtnAdd.addEventListener("click",function(){if(buttonForFavorite){if(starOn===false){starOn=true;favoriteBtnAdd.classList.add("favBtnActive");addFavoriteFun();}else if(starOn===true){starOn=false;favoriteBtnAdd.classList.remove("favBtnActive");removeFromFavoriteFun();}}});favoriteContainer.addEventListener("click",()=>{favoriteBtnAdd.classList.add("favBtnActive");starOn=true;});easyContainer.addEventListener("click",()=>{favoriteBtnAdd.classList.remove("favBtnActive");starOn=false;});mediumContainer.addEventListener("click",()=>{favoriteBtnAdd.classList.remove("favBtnActive");starOn=false;});hardContainer.addEventListener("click",()=>{favoriteBtnAdd.classList.remove("favBtnActive");starOn=false;});practiceContainer.addEventListener("click",()=>{favoriteBtnAdd.classList.remove("favBtnActive");starOn=false;});sandBoxContainer.addEventListener("click",()=>{favoriteBtnAdd.classList.remove("favBtnActive");starOn=false;});function clearFavoriteTotalFun(){let totalStorage=localStorage;for(let el of Object.values(totalStorage)){if(el.includes("lessonButtonId-")){const btn=document.querySelector(`#${el}`);localStorage.removeItem(`${btn.id}`);favoriteContainer.removeChild(btn);}} window.location.reload();} clearFavoriteTotal.addEventListener("click",function(){myModalFavorite.style.display="block";});window.addEventListener("click",function(e){if(e.target==myModalFavorite){myModalFavorite.style.display="none";}});function closeModal(){const myModalFavorite=document.getElementById("myModalFavorite");myModalFavorite.style.display="none";} const favoriteInModal=document.querySelector("#favoriteInModal");favoriteInModal.addEventListener("click",clearFavoriteTotalFun);const closeFavoriteInModal=document.querySelector("#closeFavoriteInModal").addEventListener("click",function(){myModalFavorite.style.display="none";});readFavoriteFromLC();