const synthBass=new Tone.MonoSynth({oscillator:{type:"triangle"},envelope:{attack:0.01},}).toDestination();synthBass.volume.value=-7;let bassNotesArr=[["ля минор","A1","C2","E2","A1","C2","E2"],["си минор","B1","D2","F#2","B1","D2","F#2"],["до минор","C2","D#2","G2","C2","D#2","G2"],["ре минор"," D2","F2","A2","D2","F2","D2"],["ми минор","E2","G2","B2","E2","G2","B2"],["фа минор","F2","G#2","C3","F2","G#2","C3"],["соль минор","G2","A#2","D3","G2","A#2","D3"],["ля Мажор","A1","C#2","E2","A1","C#2","A2"],["си Мажор","B1","D#2","F#2","B1","D#2","B2"],["до Мажор","C2","E2","G2","C2","E2","C2"],["ре Мажор"," D2","F#2","A2","D2","F#2","D2"],["ми Мажор","E2","G#2","B2","E2","G#2","E2"],["фа Мажор","F2","A2","C2","F2","A2","C3"],["соль Мажор","G2","B2","D3","G2","B2","D3"],];bassN=bassNotesArr[0];let autoBassBool=false;const autoBassBtn=document.querySelector("#autoBassBtn");autoBassBtn.addEventListener("click",()=>{if(autoBassBool===false){autoBassBtn.classList.add("activeGreen");autoBassBool=true;}else if(autoBassBool===true){autoBassBtn.classList.remove("activeGreen");autoBassBool=false;}});function autoBassOff(){autoBassBtn.classList.remove("activeGreen");autoBassBool=false;} let bassPatternSelect=document.querySelector("#bassPatternSelect");bassNotesArr.forEach((part)=>{let optionBass=document.createElement("option");optionBass.value=bassNotesArr.indexOf(part);optionBass.text=part[0];bassPatternSelect.appendChild(optionBass);});function onSelectBass(){bassN=bassNotesArr[this.value];autoBassBtn.classList.add("activeGreen");autoBassBool=true;} bassPatternSelect.addEventListener("change",onSelectBass);let currentPattern=["TkdmTkdm","CXXXXXXX","--------","--S---S-","--------","K---K---","--------",];let draw=function(){};let playIsOn=false;let currentTeme=Lessons.Teme02;lessonResetCreateCopy();let patternNum=0;currentPattern=currentTeme.Pattern[patternNum];let cursorPosX=50;let widthStep=0;let gridSize=4;let cursorColor="rgba(41, 103, 173, 0.2)";const patternNumLabel=document.querySelector("#patternNumLabel");patternNumLabel.textContent=patternNum+1+" / "+currentTeme.Pattern.length;const SetTemeName=document.querySelector("#setTemeName");SetTemeName.textContent=currentTeme.TemeName;const ShowBeatSize=document.querySelector("#showBeatSize");ShowBeatSize.textContent=currentTeme.BarSize+"/8";let playBeat=1;let beatSize=currentPattern[0].length;let precount=beatSize;let precountSwitcher=0;precount=0;let songStartPosition="0m";let tempo=60;let metronomeDuration=0;let toneAudioTrack=new Tone.Player();const speedDoublerBtn=document.querySelector("#speedDoublerBtn");speedDoublerBtn.addEventListener("click",speedDoubler);let speedDoublerValue=1;let metronomDevider=1;let metronomDeviderBool=false;const metronomDeviderBtn=document.querySelector("#metronomDeviderBtn");metronomDeviderBtn.addEventListener("click",setMetronomeDevider);let devider=1;function setMetronomeDevider(){++devider;if(devider===1){metronomDevider=1;metronomDeviderBtn.classList.remove("metronomDeviderHalf");metronomDeviderBtn.classList.add("metronomDeviderEighth");} if(devider===2){metronomDevider=2;metronomDeviderBtn.classList.remove("metronomDeviderEighth");metronomDeviderBtn.classList.add("metronomDeviderQuarter");} if(devider===3){metronomDevider=3;metronomDeviderBtn.classList.remove("metronomDeviderQuarter");metronomDeviderBtn.classList.add("metronomDeviderDotted");} if(devider===4){metronomDevider=4;metronomDeviderBtn.classList.remove("metronomDeviderDotted");metronomDeviderBtn.classList.add("metronomDeviderHalf");} if(devider>=4){devider=0;}} let precountOnBool=false;const precountSwitcherBtn=document.querySelector("#precountSwitcherBtn");precountSwitcherBtn.addEventListener("click",function(){playerStop();if(precountSwitcher===0){precountOnBool=true;precountSwitcher=beatSize;precountSwitcherBtn.classList.add("activeGreen");}else if(precountSwitcher!==0){precountOnBool=false;precountSwitcher=0;precountSwitcherBtn.classList.remove("activeGreen");}});let repeatSetter=8;let measureRepeat=repeatSetter*beatSize;let measureCount=0;let measureOnBool=false;let measureIsOn=false;const timerTypeBtn=document.querySelector(".timerTypeClass");timerTypeBtn.addEventListener("click",measureTimeSwitcher);function measureTimeSwitcher(){if(measureOnBool===false){measureOnBool=true;timerTypeBtn.classList.add("activeGreen");timerTypeBtn.classList.add("timerNewBackgroundImage");timezero();hideTimeButtons();showMesButtons();}else if(measureOnBool===true){measureOnBool=false;measureIsOn=false;timerTypeBtn.classList.remove("activeGreen");timerTypeBtn.classList.remove("timerNewBackgroundImage");showTimeButtons();hideMesButtons();}} function hideTimeButtons(){const tButtons=document.querySelectorAll(".timerBtn");tButtons.forEach((btn)=>btn.classList.add("dNone"));} function showTimeButtons(){const tButtons=document.querySelectorAll(".timerBtn");tButtons.forEach((btn)=>btn.classList.remove("dNone"));} function hideMesButtons(){const mButtons=document.querySelectorAll(".mesBtn");mButtons.forEach((btn)=>btn.classList.add("dNone"));} function showMesButtons(){const mButtons=document.querySelectorAll(".mesBtn");mButtons.forEach((btn)=>btn.classList.remove("dNone"));mButtons.forEach((btn)=>btn.classList.remove("activeGreen"));measureCount=0;} let playbackRateTemp;let tempTempoForChange=tempo;let volMetronome=new Tone.Volume(0).toDestination();volMetronome.volume.value=-10;volMetronome.mute=false;let metronome=new Tone.Synth({oscillator:{type:"square"},envelope:{release:0.01,sustain:0.001,volume:20},}).connect(volMetronome);let correctTime=0.0;const precountLable=document.querySelector("#precountLable");let precountLabelCount=0;let speedTrainerOnBool=false;let finishPlus=100;let speedUpVal=1;let sizeOfProgress=0;let rampCount=tempo;let finishRamp=tempo+finishPlus;const tempoRunProgress=document.querySelector("#tempoRunProgress");const tempoRunProgressIncide=document.querySelector(".tempoRunProgressIncide");const currentTempoLabel=document.querySelector("#currentTempoLabel");let speedProgressStep=1;function setTempoTrainerLabels(){currentTempoLabel.textContent=tempo;const startTempoLabel=document.querySelector("#startTempoLabel");startTempoLabel.textContent=tempo;const finishTempoLabel=document.querySelector("#finishTempoLabel");finishTempoLabel.textContent=tempo+finishPlus;rampCount=tempo;finishRamp=tempo+finishPlus;} const runOnOfButton=document.querySelector("#runOnOfButton");runOnOfButton.addEventListener("click",()=>{playerStop();if(speedTrainerOnBool===false){speedTrainerOnBool=true;runOnOfButton.classList.add("activeGreen");tempoRunProgress.classList.remove("dNone");setTempoTrainerLabels();}else if(speedTrainerOnBool===true){speedTrainerOnBool=false;runOnOfButton.classList.remove("activeGreen");tempoRunProgress.classList.add("dNone");}});Tone.Transport.scheduleRepeat((time)=>{if(rampCount>=tempo+finishPlus){playerStop();} if(speedTrainerOnBool===false){Tone.Transport.bpm.value=tempo;} cursorPosX+=widthStep;Tone.Draw.schedule(()=>{precountLable.textContent=precountLabelCount;draw();},time);precountLabelCount++;precount--;precountLable.style.opacity=1;if(precount<0){precountLable.style.opacity=0;cursorColor="rgba(41, 103, 173, 0.2)";if(currentPattern[1][playBeat-1]==="C"){crash.start(time+correctTime);} if(currentPattern[1][playBeat-1]==="R"){ride.start(time+correctTime);} if(currentPattern[1][playBeat-1]==="X"){hihat.start(time+correctTime);} if(currentPattern[1][playBeat-1]==="O"){oHihat.start(time+correctTime);} if(currentPattern[2][playBeat-1]==="H"){tom1.start(time+correctTime);} if(currentPattern[4][playBeat-1]==="L"){tom2.start(time+correctTime);} if(currentPattern[3][playBeat-1]==="S"){snare.start(time+correctTime);} if(currentPattern[3][playBeat-1]==="G"){gSnare.start(time+correctTime);} if(currentPattern[3][playBeat-1]==="$"){aSnare.start(time+correctTime);} if(currentPattern[3][playBeat-1]==="%"){rim.start(time+correctTime);} if(currentPattern[5][playBeat-1]==="K"){kik.start(time+correctTime);if(autoBassBool===true){if(playBeat!==1){synthBass.triggerAttackRelease(bassN[Math.floor(Math.random()*6)+1],0.05,time);}}} if(currentPattern[6][playBeat-1]==="F"){fhat.start(time+correctTime);}} if(playBeat===1){if(autoBassBool===true){synthBass.triggerAttackRelease(bassN[1],0.05,time);} metronome.triggerAttackRelease("C6",0.01,time+correctTime);cursorPosX=50;if(speedTrainerOnBool===true){rampCount+=speedUpVal;sizeOfProgress+=(500/finishPlus)*speedUpVal;Tone.Transport.bpm.value=rampCount;tempoRunProgressIncide.style.width=sizeOfProgress+"px";currentTempoLabel.textContent=rampCount;}}else{if((playBeat-1)%metronomDevider===0) metronome.triggerAttackRelease("C5",0.01,time+correctTime);} playBeat++;if(playBeat>beatSize){playBeat=1;} if(measureIsOn===true){measureCount++;if(measureCount>measureRepeat){measureCount=1;nextPattern();}}},"8n");function playerStart(){playBtn.classList.add("startStopBtnChangeBackImg");precount=precountSwitcher;playBeat=1;Tone.Transport.start();Tone.start();} function playerStop(){playBtn.classList.remove("startStopBtnChangeBackImg");cursorColor="rgba(41, 103, 173, 0)";cursorPosX=-3000;playIsOn=false;playBeat=1;precount=precountSwitcher;measureCount=0;Tone.Transport.stop();setTimeout(function(){precountLabelCount=0;precountLable.textContent="";cursorPosX=-3000;draw();if(speedTrainerOnBool===true){rampCount=tempo;tempoRunProgressIncide.style.width="0px";sizeOfProgress=0;musicReset();}},100);} let speedDoublerSwitchCounter=1;let eigthNote=96;Tone.Transport._scheduledEvents[0].event._interval=eigthNote;function speedDoubler(){playerStop();if(speedDoublerSwitchCounter===0){speedDoublerValue=1;speedDoublerBtn.innerHTML="X1";Tone.Transport._scheduledEvents[0].event._interval=eigthNote;setTempo();}else if(speedDoublerSwitchCounter===1){speedDoublerValue=2;speedDoublerBtn.innerHTML="X2";Tone.Transport._scheduledEvents[0].event._interval=eigthNote/2;setTempo();}else if(speedDoublerSwitchCounter===2){speedDoublerBtn.innerHTML="X4";Tone.Transport._scheduledEvents[0].event._interval=eigthNote/4;setTempo();} speedDoublerSwitchCounter++;if(speedDoublerSwitchCounter>2){speedDoublerSwitchCounter=0;}} const tempoLabel=document.querySelector("#tempoLabel");const setTempoRange=document.querySelector("#setTempoRange");function setTempo(){playerStop();Tone.Transport.bpm.value=Number(setTempoRange.value);tempo=Number(setTempoRange.value);tempoLabel.textContent=setTempoRange.value;playbackRateTemp=tempo/tempTempoForChange;toneAudioTrack.playbackRate=playbackRateTemp;setTempoTrainerLabels();} setTempo();const beatSizeLabel=document.querySelector("#beatSizeLabel");const setBeatSizeRange=document.querySelector("#setBeatSizeRange");setBeatSizeRange.value=currentPattern[0].length;beatSizeLabel.textContent=currentPattern[0].length;function setBeatSize(){playerStop();beatSize=Number(setBeatSizeRange.value);beatSizeLabel.textContent=setBeatSizeRange.value;if(precountOnBool===true){precountSwitcher=beatSize;} if(beatSize===3||beatSize===6||beatSize===9||beatSize===12||beatSize===18||beatSize===24){gridSize=3;}else{gridSize=4;} precount=beatSize;measureRepeat=repeatSetter*beatSize;addBetSizeTO32();draw();if((isEditorOn=true)){removeEditorButtons();createEditorButtons();}} function addBetSizeTO32(){if(currentPattern[0].length<32){currentPattern[0]+="TkdmTkdmTkdmTkdmTkdmTkdmTkdmTkdm";currentPattern[1]+="--------------------------------";currentPattern[2]+="--------------------------------";currentPattern[3]+="--------------------------------";currentPattern[4]+="--------------------------------";currentPattern[5]+="--------------------------------";currentPattern[6]+="--------------------------------";}} function switchBarSize(){playerStop();beatSize=currentTeme.BarSize;setBeatSizeRange.value=beatSize;beatSizeLabel.textContent=beatSize;currentPattern=currentTeme.Pattern[0];patternNumLabel.textContent=patternNum+1;if(beatSize===3||beatSize===6||beatSize===9||beatSize===12||beatSize===18||beatSize===24){gridSize=3;}else{gridSize=4;} draw();} const beatSizeUpBtn=document.querySelector("#beatSizeUpBtn");beatSizeUpBtn.addEventListener("click",beatSizeUpFun);function beatSizeUpFun(){playerStop();beatSize++;if(beatSize>32){beatSize=32;} setBeatSizeRange.value=beatSize;beatSizeLabel.textContent=beatSize;if(beatSize===3||beatSize===6||beatSize===9||beatSize===12||beatSize===18||beatSize===24){gridSize=3;}else{gridSize=4;} addBetSizeTO32();draw();if((isEditorOn=true)){removeEditorButtons();createEditorButtons();}} const beatSizeDownBtn=document.querySelector("#beatSizeDownBtn");beatSizeDownBtn.addEventListener("click",beatSizeDownFun);function beatSizeDownFun(){playerStop();beatSize--;if(beatSize<1){beatSize=1;} setBeatSizeRange.value=beatSize;beatSizeLabel.textContent=beatSize;if(beatSize===3||beatSize===6||beatSize===9||beatSize===12||beatSize===18||beatSize===24){gridSize=3;}else{gridSize=4;} draw();if((isEditorOn=true)){removeEditorButtons();createEditorButtons();}} function nullPattern(){patternNum=0;patternNumLabel.textContent=patternNum+1+" / "+currentTeme.Pattern.length;addBetSizeTO32();draw();if((isEditorOn=true)){removeEditorButtons();createEditorButtons();}else if((isEditorOn=false)){removeEditorButtons();}} const nextPatternBtn=document.querySelector("#nextPatternBtn").addEventListener("click",nextPattern);function nextPattern(){patternNum++;if(patternNum>=currentTeme.Pattern.length){patternNum=0;} currentPattern=currentTeme.Pattern[patternNum];patternNumLabel.textContent=patternNum+1+" / "+currentTeme.Pattern.length;if(lockCymbalsBool===true){setCymbalsPattern();} addBetSizeTO32();draw();} const prevPatternBtn=document.querySelector("#prevPatternBtn").addEventListener("click",prevPattern);function prevPattern(){patternNum--;if(patternNum<0){patternNum=currentTeme.Pattern.length-1;} currentPattern=currentTeme.Pattern[patternNum];patternNumLabel.textContent=patternNum+1+" / "+currentTeme.Pattern.length;if(lockCymbalsBool===true){setCymbalsPattern();} addBetSizeTO32();draw();} const resetPatternBtn=document.querySelector("#resetPatternBtn").addEventListener("click",resetPattern);function resetPattern(){patternNum=0;currentPattern=currentTeme.Pattern[patternNum];patternNumLabel.textContent=patternNum+1+" / "+currentTeme.Pattern.length;if(lockCymbalsBool===true){setCymbalsPattern();} addBetSizeTO32();draw();} const lockCymbalsButton=document.querySelector("#lockCymbalsButton");lockCymbalsButton.addEventListener("click",lockCymbalsFun);let lockCymbalsBool=false;const CymalParts=["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-","-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X","X---X---X---X---X---X---X---X---","--X---X---X---X---X---X---X---X-","XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-","X-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XX","XX--XX--XX--XX--XX--XX--XX--XX--","-XX--XX--XX--XX--XX--XX--XX--XX-","--XX--XX--XX--XX--XX--XX--XX--XX","X--XX--XX--XX--XX--XX--XX--XX--X","XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO","OXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOX","X-O-X-O-X-O-X-O-X-O-X-O-X-O-X-O-","O-X-O-X-O-X-O-X-O-X-O-X-O-X-O-X-","XXO-XXO-XXO-XXO-XXO-XXO-XXO-XXO-","O-XXO-XXO-XXO-XXO-XXO-XXO-XXO-XX","RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR","R-R-R-R-R-R-R-R-R-R-R-R-R-R-R-R-","-R-R-R-R-R-R-R-R-R-R-R-R-R-R-R-R","R---R---R---R---R---R---R---R---","--R---R---R---R---R---R---R---R-","RRR-RRR-RRR-RRR-RRR-RRR-RRR-RRR-","R-RRR-RRR-RRR-RRR-RRR-RRR-RRR-RR","RR--RR--RR--RR--RR--RR--RR--RR--","-RR--RR--RR--RR--RR--RR--RR--RR-","--RR--RR--RR--RR--RR--RR--RR--RR","R--RR--RR--RR--RR--RR--RR--RR--R","X--X--X--X--X--X--X--X--X--X--X-","X-XX-XX-XX-XX-XX-XX-XX-XX-XX-XX-","O-XO-XO-XO-XO-XO-XO-XO-XO-XO-XO-","X--X-XX--X-XX--X-XX--X-XX--X-XX-","O--X-XO--X-XO--X-XO--X-XO--X-XO-","R--R--R--R--R--R--R--R--R--R--R-","R-RR-RR-RR-RR-RR-RR-RR-RR-RR-RR-","R--R-RR--R-RR--R-RR--R-RR--R-RR-",];let cymbPartToLock=CymalParts[0];let cymPartCount=-1;function lockCymbalsFun(){cymPartCount++;if(cymPartCount>=CymalParts.length){lockCymbalsButton.classList.remove("activeGreen");cymPartCount=-1;lockCymbalsBool=false;cymbPartToLock=lessonsForReset[0][1];lockCymbalsButton.textContent="";setCymbalsPattern();} if(cymPartCount!==-1){lockCymbalsBool=true;lockCymbalsButton.classList.add("activeGreen");lockCymbalsButton.textContent=cymPartCount+1;cymbPartToLock=CymalParts[cymPartCount];setCymbalsPattern();}} function lockCymbalsOff(){lockCymbalsButton.classList.remove("activeGreen");cymPartCount=-1;lockCymbalsBool=false;cymbPartToLock=lessonsForReset[0][1];lockCymbalsButton.textContent="";setCymbalsPattern();} function setCymbalsPattern(){currentPattern[1]=cymbPartToLock;draw();} function setTextKonnakol(){konnakolCountSwitcher();} const setVolDrumsRange=document.querySelector("#setVolDrumsRange");function setVolDrums(){volDrums.volume.value=Number(setVolDrumsRange.value);} const setVolMetronomeRange=document.querySelector("#setVolMetronomeRange");function setVolMetronome(){volMetronome.volume.value=Number(setVolMetronomeRange.value);} const mes4Btn=document.querySelector("#mes4Btn");mes4Btn.addEventListener("click",set8repeat);function set8repeat(){const mButtons=document.querySelectorAll(".mesBtn");mButtons.forEach((btn)=>btn.classList.remove("activeGreen"));if(measureIsOn===false){mes4Btn.classList.add("activeGreen");playerStop();measureIsOn=true;repeatSetter=4;measureRepeat=repeatSetter*beatSize;}else if(measureIsOn===true){mButtons.forEach((btn)=>btn.classList.remove("activeGreen"));measureIsOn=false;playerStop();}} const mes8Btn=document.querySelector("#mes8Btn");mes8Btn.addEventListener("click",set16repeat);function set16repeat(){const mButtons=document.querySelectorAll(".mesBtn");mButtons.forEach((btn)=>btn.classList.remove("activeGreen"));if(measureIsOn===false){mes8Btn.classList.add("activeGreen");playerStop();measureIsOn=true;repeatSetter=8;measureRepeat=repeatSetter*beatSize;}else if(measureIsOn===true){mButtons.forEach((btn)=>btn.classList.remove("activeGreen"));measureIsOn=false;playerStop();}} const mes16Btn=document.querySelector("#mes16Btn");mes16Btn.addEventListener("click",set32repeat);function set32repeat(){const mButtons=document.querySelectorAll(".mesBtn");mButtons.forEach((btn)=>btn.classList.remove("activeGreen"));if(measureIsOn===false){mes16Btn.classList.add("activeGreen");playerStop();measureIsOn=true;repeatSetter=16;measureRepeat=repeatSetter*beatSize;}else if(measureIsOn===true){mButtons.forEach((btn)=>btn.classList.remove("activeGreen"));measureIsOn=false;playerStop();}}