var w,h,my={} my.hexs=['0','1','2','3','4','5','6','7','8','9',"A","B","C","D","E","F"];my.bins=["0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"];var AudioContext=window.AudioContext||window.webkitAudioContext||false;var BPM=120;var buffers={} if(AudioContext){var context=new AudioContext();} var tickTime=1/(4*BPM/(60*1000));function hexdrumsMain(){my.version='0.61' my.barSeqs=[{name:'Normal',id:'seq'},{name:'Binary',id:'bin'},{name:'Random',id:'rand'}];var barSeqId=getQueryVariable('seq','seq') my.barSeq=my.barSeqs[0] for(var i=0;i0){riffLoad(rStr) my.playQ=true}else{for(var i=0;i<6;i++){var sound=new Sound(i,my.soundFiles[i].name,my.soundFiles[i].file) sound.setHex('0000') my.sounds.push(sound)} my.playQ=false} for(var i=0;i';s+='
' s+='
BPM:
' s+='';s+='
120
';s+='
';s+=playHTML(36);s+='
';s+='
';s+='
' for(var r=0;r' s+=my.sounds[r].HTML() s+='
'} s+='';s+='
' s+='';s+='';s+='';s+='
' s+='
';s+='';s+='Sequence:' s+=radioHTML('Sequence','barseq',my.barSeqs,'barseqChg');s+='
';s+='';s+='';s+='';document.write(s);for(var i=0;i0)s+='~' s+=sound.name.split(' ').join('-') s+='_' s+=hex} document.getElementById('url').innerHTML='hex-drums2a3b.html?r='+encodeURI(s) my.pop.popup()} function riffLoad(s){s=decodeURI(s).split('-').join(' ') var sounds=s.split('~') my.sounds=[] for(var i=0;i=tickTime){my.beatTime=performance.now() beatDo()}} requestAnimationFrame(anim);} function beatDo(){for(var i=0;i';for(var i=0;i'+opt.name+'';} s+='';return s;} function dropdownGet(id){var div=document.getElementById(id);return div.options[div.selectedIndex].value;} function beatToggle(r,barNo,barN){console.log('beatToggle',r,barNo,barN) my.sounds[r].beatToggle(barNo,barN) my.sounds[r].beats2hex()} function padFull(pad,str,leftPadded){if(str==undefined)return pad;if(leftPadded){return(pad+str).slice(-pad.length);}else{return(str+pad).substring(0,pad.length);}} function getQueryVariable(variable,noVal){var query=window.location.search.substring(1);var vars=query.split("&");for(var i=0;i';s+='
';s+='';s+='
';s+=inStr;s+='';return s;};function Sound(id,name,file){this.id=id this.name=name this.file=file this.hex='0' this.barCount=4 this.barNo=0 this.beatCount=4 this.beatNo=0 this.binBars=[] this.lastBeat=null} Sound.prototype.beatDo=function(){this.beatNo++;if(this.beatNo>=this.beatCount){this.beatNo=0 switch(my.barSeq.id){case 'bin':this.binBarChoose(0) break case 'rand':this.barNo=randomInt(0,this.barCount-1) break case 'seq':default:this.barNo++ if(this.barNo>=this.barCount){this.barNo=0}}} var currentBeat=getBeatDiv(this.id,this.barNo,this.beatNo) if(currentBeat!=null){if(this.lastBeat!=null)this.lastBeat.classList.remove('ticked');currentBeat.classList.add('ticked');if(currentBeat.classList.contains('on')){playSound(my.soundPrefix+this.file);} this.lastBeat=currentBeat}} Sound.prototype.binBarChoose=function(n){if(typeof this.binBars[n]==='undefined')this.binBars[n]=0 if(this.binBars[n]==1){this.binBars[n]=0 if(n<(this.barCount-1)){this.binBarChoose(n+1)}else{this.barNo=n}}else{this.binBars[n]=1 this.barNo=n}} Sound.prototype.setHex=function(hex){this.hex=hex this.barCount=hex.length console.log('setHex',hex,hex.length)} Sound.prototype.clear=function(){this.hex='0' for(var i=0;i';s+='
' s+=this.barHTML() s+='
' s+='
' return s} Sound.prototype.barHTML=function(barNo,barN,onQ){var s='' for(var i=0;i' s+='0' s+=''} s+='
' s+='0' s+='
'} return s} Sound.prototype.beatSet=function(barNo,barN,onQ){var div=getBeatDiv(this.id,barNo,barN) div.classList.toggle('on',onQ);if(div.classList.contains('on')){div.innerHTML='1'}else{div.innerHTML='0'}} Sound.prototype.beatToggle=function(barNo,barN){console.log('beatToggle',barNo,barN) var div=getBeatDiv(this.id,barNo,barN) if(div.classList.contains('on')){div.classList.toggle('on',false);div.innerHTML='0'}else{div.classList.toggle('on',true);div.innerHTML='1'}} Sound.prototype.rand=function(){for(var i=0;i=0;i--){var div=getBeatDiv(this.id,grpn,i) if(div.classList.contains('on')){n+=mult} mult*=2} var div=document.getElementById('ltr'+this.id+'_'+grpn) div.innerHTML=my.hexs[n] return my.hexs[n]} Sound.prototype.hex2beats=function(){var txt=document.getElementById('hex'+this.id).value txt=txt.replace(/[^A-Fa-f0-9]/g,'0');this.barCount=txt.length var div=document.getElementById('bar'+this.id) div.innerHTML=this.barHTML() for(var i=0;i';s+='';} s+='';return s;} function randomInt(min,max){return Math.floor(Math.random()*(max-min+1)+min);}