let volMusic=new Tone.Volume(-6).toDestination();volMusic.mute=true;let musicVolVal=0;let currentVolMusic=musicVolVal;function resetAudioBuffer(){toneAudioTrack.dispose();} const setVolMusicRange=document.querySelector("#setVolMusicRange");function setVolMusic(){volMusic.volume.value=Number(setVolMusicRange.value);} const musicTracks=new Tone.ToneAudioBuffers({track01:localTrack_01,track02:localTrack_02,track03:localTrack_03,track04:localTrack_04,track05:localTrack_05,track06:localTrack_06,track07:localTrack_07,track08:localTrack_08,track09:localTrack_09,track10:localTrack_10,track11:localTrack_11,track12:localTrack_12,track13:localTrack_13,track14:localTrack_14,track15:localTrack_15,track16:localTrack_16,track17:localTrack_17,track18:localTrack_18,});let mainTrackSelect=document.getElementById("songSelect");let trackOption_01=document.createElement("option");trackOption_01.value="song01";trackOption_01.text="Трек 1 - 50 bpm Pop Rock";mainTrackSelect.appendChild(trackOption_01);let trackOption_02=document.createElement("option");trackOption_02.value="song02";trackOption_02.text="Трек 2 - 60 bpm Pop Rock";mainTrackSelect.appendChild(trackOption_02);let trackOption_03=document.createElement("option");trackOption_03.value="song03";trackOption_03.text="Трек 3 - 70 bpm Pop Rock";mainTrackSelect.appendChild(trackOption_03);let trackOption_04=document.createElement("option");trackOption_04.value="song04";trackOption_04.text="Трек 4 - 80 bpm Pop Rock";mainTrackSelect.appendChild(trackOption_04);let trackOption_05=document.createElement("option");trackOption_05.value="song05";trackOption_05.text="Трек 5 - 90 bpm Pop Rock";mainTrackSelect.appendChild(trackOption_05);let trackOption_06=document.createElement("option");trackOption_06.value="song06";trackOption_06.text="Трек 6 - 100 bpm Pop Rock";mainTrackSelect.appendChild(trackOption_06);let trackOption_07=document.createElement("option");trackOption_07.value="song07";trackOption_07.text="Трек 7 - 110 bpm Pop Rock";mainTrackSelect.appendChild(trackOption_07);let trackOption_08=document.createElement("option");trackOption_08.value="song08";trackOption_08.text="Трек 8 - 120 bpm Pop Rock";mainTrackSelect.appendChild(trackOption_08);let trackOption_09=document.createElement("option");trackOption_09.value="song09";trackOption_09.text="Трек 9 - 120 bpm Latin Pop";mainTrackSelect.appendChild(trackOption_09);let trackOption_10=document.createElement("option");trackOption_10.value="song10";trackOption_10.text="Трек 10 - 130 bpm Disco";mainTrackSelect.appendChild(trackOption_10);let trackOption_11=document.createElement("option");trackOption_11.value="song11";trackOption_11.text="Трек 11 - 100 bpm Blues 12-8";mainTrackSelect.appendChild(trackOption_11);let trackOption_12=document.createElement("option");trackOption_12.value="song12";trackOption_12.text="Трек 12 - 90 bpm Jazz 12-8";mainTrackSelect.appendChild(trackOption_12);let trackOption_13=document.createElement("option");trackOption_13.value="song13";trackOption_13.text="Трек 13 - 90 bpm Afro Jazz 12-8";mainTrackSelect.appendChild(trackOption_13);let trackOption_14=document.createElement("option");trackOption_14.value="song14";trackOption_14.text="Трек 14 - 90 bpm Funk";mainTrackSelect.appendChild(trackOption_14);let trackOption_15=document.createElement("option");trackOption_15.value="song15";trackOption_15.text="Трек 15 - 100 bpm Funk";mainTrackSelect.appendChild(trackOption_15);let trackOption_16=document.createElement("option");trackOption_16.value="song16";trackOption_16.text="Трек 16 - 110 bpm Funk";mainTrackSelect.appendChild(trackOption_16);let trackOption_17=document.createElement("option");trackOption_17.value="song17";trackOption_17.text="Трек 17 - 120 bpm Funk";mainTrackSelect.appendChild(trackOption_17);let trackOption_18=document.createElement("option");trackOption_18.value="song18";trackOption_18.text="Трек 18 - 130 bpm Funk";mainTrackSelect.appendChild(trackOption_18);class SongTrack{constructor(name,trackFromBuffers,tempoOfsong,lengthOfsong,volumeOfsong){this.name=name;this.trackFromBuffers=trackFromBuffers;this.tempoOfsong=tempoOfsong;this.lengthOfsong=lengthOfsong;this.volumeOfsong=volumeOfsong;this.trackBuffer=musicTracks.get(this.trackFromBuffers);this.trackBuffer;} playTrack(){inputFRDiv.value="";playerStop();volMusic=new Tone.Volume(this.volumeOfsong).toDestination();toneAudioTrack=new Tone.Player().connect(volMusic).sync().start(0);toneAudioTrack.buffer=this.trackBuffer;setTempoRange.value=tempo;currentVolMusic=Math.round(volMusic.volume.value);tempo=this.tempoOfsong;tempTempoForChange=this.tempoOfsong;musicVolVal=this.volumeOfsong;setTempoRange.value=tempo;Tone.Transport.bpm.value=tempo;tempoLabel.innerText=tempo;Tone.Transport.loop=true;Tone.Transport.loopStart="0m";Tone.Transport.loopEnd=this.lengthOfsong;playbackRateTemp=1;toneAudioTrack.playbackRate=playbackRateTemp;setVolMusic();}} let mySelect=document.getElementById("songSelect");let tracks={song01:new SongTrack("song01","track01",50,"16m",-4),song02:new SongTrack("song02","track02",60,"16m",-6),song03:new SongTrack("song03","track03",70,"16m",-6),song04:new SongTrack("song04","track04",80,"16m",-6),song05:new SongTrack("song05","track05",90,"16m",-6),song06:new SongTrack("song06","track06",100,"24m",-6),song07:new SongTrack("song07","track07",110,"24m",-6),song08:new SongTrack("song08","track08",120,"24m",-8),song09:new SongTrack("song09","track09",120,"24m",-6),song10:new SongTrack("song10","track10",130,"24m",-6),song11:new SongTrack("song11","track11",100,"18m",-6),song12:new SongTrack("song12","track12",90,"18m",-6),song13:new SongTrack("song13","track13",90,"24m",-6),song14:new SongTrack("song14","track14",90,"16m",-8),song15:new SongTrack("song15","track15",100,"16m",-8),song16:new SongTrack("song16","track16",110,"16m",-8),song17:new SongTrack("song17","track17",120,"16m",-8),song18:new SongTrack("song18","track18",130,"16m",-8),};function onSelectTrack(){autoBassOff();resetAudioBuffer();playerStop();songStartPosition=`${countOfPositionStart}m`;if(this.value=="TrackZero"){volMusic.mute=true;}else{let selectedTrack=tracks[this.value];if(typeof selectedTrack!=="undefined"){selectedTrack.playTrack(0);}}} mySelect.addEventListener("change",onSelectTrack);let bufAu;let songFile=new Tone.Player(bufAu);let SongStartPosLb=document.getElementById("SongStartPos");let SongEndPosLb=document.getElementById("SongEndPos");let countOfPositionStart=0;let countOfPositionEnd=0;let input;let checkLoadLbl=document.getElementById("checkLoadLbl");const readerAudio=document.querySelector("#inputFR");readerAudio.addEventListener("change",(input)=>{autoBassOff();mainTrackSelect.value="TrackZero";let file=null;file=input.target.files[0];toneAudioTrack.dispose();playerStop();playBtn.disabled=true;bufAu=URL.createObjectURL(file);if(file.type!=="audio/mpeg"){inputFRDiv.value="";musicReset();return;} let nameFromTrack=String(input.target.value);let tempoParsed=parseInt(nameFromTrack.match(/\d+/));songStartPosition=`${countOfPositionStart}m`;Tone.Transport.loop=false;volMusic.mute=false;toneAudioTrack=new Tone.Player(bufAu).connect(volMusic).sync().start(0);toneAudioTrack.buffer=bufAu;timerLoaderTrack(true);toneAudioTrack.buffer.onload=function(){timerLoaderTrack(false);playBtn.disabled=false;};tempo=tempoParsed;tempTempoForChange=tempo;Tone.Transport.bpm.value=tempo;setTempoRange.value=tempo;tempoLabel.innerText=tempo;playbackRateTemp=1;toneAudioTrack.playbackRate=playbackRateTemp;});let inputFRDiv=document.getElementById("inputFR");let songLoadBool=false;let canvasLT=document.getElementById("canvasLoadTrack");canvasLT.classList.add("canvasLoadTrack");let ctxLT=canvasLT.getContext("2d");let musicLoadTimer;let loadTrackProgress=function(){canvasLT.width+=1;if(canvasLT.width>=640){canvasLT.width=0;}};function timerLoaderTrack(LT_run_bool){if(LT_run_bool==true){canvasLT.style.display="inline-block";musicLoadTimer=setInterval(loadTrackProgress,500/240);}else{canvasLT.style.display="none";clearInterval(musicLoadTimer);canvasLT.width=0;}} const musicOffBtn=document.querySelector("#musicOffBtn");musicOffBtn.addEventListener("click",musicReset);function musicReset(){resetAudioBuffer();mainTrackSelect.value="TrackZero";inputFRDiv.value="";playBtn.disabled=false;autoBassOff();}