Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated minified version

  • Loading branch information...
commit ee499b0979ef882aa79273da399fe581c4aa55d7 1 parent 5458ddd
stuartmemo authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  qwerty-hancock.min.js
2  qwerty-hancock.min.js
View
@@ -1 +1 @@
-(function(window,undefined){var qwertyHancock=function(id,width,height,octaves,keyboardStartNote,keyboardWhiteNotesColour,keyboardBlackNotesColour,keyboardHoverColour){var numberOfOctaves=octaves||3,totalWhiteKeys=numberOfOctaves*7,keyboardWidth=width||600,keyboardHeight=height||150,startNote=keyboardStartNote||'A3',startOctave=startNote.charAt(1),whiteNotesColour=keyboardWhiteNotesColour||'#FFF',blackNotesColour=keyboardBlackNotesColour||'#000',hoverColour=keyboardHoverColour||'#076cf0',whiteKeyWidth=keyboardWidth/totalWhiteKeys,blackKeyWidth=whiteKeyWidth/2,paper=new Raphael(id,keyboardWidth,keyboardHeight),notes=['C','D','E','F','G','A','B'],notesWithSharps=['A','C','D','F','G'],noteCounter=0,firstNote=startNote.charAt(0),octaveCounter=startOctave,qwertyOctave=startOctave,noteDown=false,keyDownCallback,keyUpCallback,raphKeys=[],raphSharpKeys=[],newNotes=[];var getFrequency=function(note){var notes=['A','A#','B','C','C#','D','D#','E','F','F#','G','G#'],octave;if(note.length===3){octave=note.charAt(2)}else{octave=note.charAt(1)}var keyNumber=notes.indexOf(note.slice(0,-1));if(keyNumber<3){keyNumber=keyNumber+12+((octave-1)*12)+1}else{keyNumber=keyNumber+((octave-1)*12)+1}return 440*Math.pow(2,(keyNumber-49)/12)};for(var i=0;i<7;i++){if(firstNote===notes[i]){keyOffset=i;break}}for(i=0;i<7;i++){if(i+keyOffset>6){newNotes[i]=notes[i+keyOffset-7]}else{newNotes[i]=notes[i+keyOffset]}}for(i=0;i<totalWhiteKeys;i++){if((i%notes.length)===0){noteCounter=0}var bizarreNoteCounter=(newNotes[noteCounter]);if(bizarreNoteCounter==='C'){octaveCounter++}raphKeys[i]=paper.rect(whiteKeyWidth*i,0,whiteKeyWidth,keyboardHeight).attr({id:newNotes[noteCounter],title:newNotes[noteCounter]+(octaveCounter-1),fill:whiteNotesColour}).mousedown(function(){noteDown=true;this.attr({fill:hoverColour});keyDownCallback(this.attr('title'),getFrequency(this.attrs.title))}).mouseover(function(){if(noteDown){this.attr({fill:hoverColour});keyDownCallback(this.attr('title'),getFrequency(this.attrs.title))}}).mouseup(function(){this.attr({fill:whiteNotesColour});noteDown=false;keyUpCallback(this.attr('title'),getFrequency(this.attrs.title))}).mouseout(function(){this.attr({fill:whiteNotesColour});keyUpCallback(this.attr('title'),getFrequency(this.attrs.title))});noteCounter++}octaveCounter=startOctave;for(i=0;i<totalWhiteKeys;i++){if((i%notes.length)===0){noteCounter=0}for(var j=0;j<notesWithSharps.length;j++){if(newNotes[noteCounter]===notesWithSharps[j]){bizarreNoteCounter=(newNotes[noteCounter]+'#');if(bizarreNoteCounter==='C#'){octaveCounter++}if((whiteKeyWidth*(i+1))<keyboardWidth){raphSharpKeys[i]=paper.rect((whiteKeyWidth*i)+(blackKeyWidth*1.5),0,blackKeyWidth,(keyboardHeight/3)*2).attr({id:newNotes[noteCounter],title:newNotes[noteCounter]+'#'+(octaveCounter-1),fill:blackNotesColour}).mousedown(function(){noteDown=true;this.attr({fill:hoverColour});keyDownCallback(this.attr('title'),getFrequency(this.attrs.title))}).mouseover(function(){if(noteDown){this.attr({fill:hoverColour});keyDownCallback(this.attr('title'),getFrequency(this.attrs.title))}}).mouseup(function(){this.attr({fill:blackNotesColour});noteDown=false;keyUpCallback(this.attr('title'),getFrequency(this.attrs.title))}).mouseout(function(){this.attr({fill:blackNotesColour});keyUpCallback(this.attr('title'),getFrequency(this.attrs.title))})}}}noteCounter++}var keyToKey={65:'Cl',87:'C#l',83:'Dl',69:'D#l',68:'El',70:'Fl',84:'F#l',71:'Gl',89:'G#l',72:'Al',85:'A#l',74:'Bl',75:'Cu',79:'C#u',76:'Du',80:'D#u',186:'Eu',222:'Fu'};var keyboardDown=function(key){for(var i=0;i<raphKeys.length;i++){if((typeof keyToKey[key.keyCode]!=='undefined')&&(typeof raphKeys[i]!=='undefined')){var keyPressed=keyToKey[key.keyCode].replace('l',qwertyOctave).replace('u',(parseInt(qwertyOctave,10)+1).toString());if(raphKeys[i].attrs.title===keyPressed){raphKeys[i].attr({fill:hoverColour});keyDownCallback(raphKeys[i].attrs.title,getFrequency(raphKeys[i].attrs.title))}}}for(i=0;i<raphSharpKeys.length;i++){if((typeof keyToKey[key.keyCode]!=='undefined')&&(typeof raphSharpKeys[i]!=='undefined')){keyPressed=keyToKey[key.keyCode].replace('l',qwertyOctave).replace('u',(parseInt(qwertyOctave,10)+1).toString());if(raphSharpKeys[i].attrs.title===keyPressed){raphSharpKeys[i].attr({fill:hoverColour});keyDownCallback(keyPressed,getFrequency(keyPressed))}}}};var keyboardUp=function(key){for(var i=0;i<raphKeys.length;i++){if((typeof keyToKey[key.keyCode]!=='undefined')&&(typeof raphKeys[i]!=='undefined')){var keyPressed=keyToKey[key.keyCode].replace('l',qwertyOctave).replace('u',(parseInt(qwertyOctave,10)+1).toString());if(raphKeys[i].attrs.title===keyPressed){raphKeys[i].attr({fill:whiteNotesColour});keyUpCallback(raphKeys[i].attrs.title,getFrequency(raphKeys[i].attrs.title))}}}for(i=0;i<raphSharpKeys.length;i++){if((typeof keyToKey[key.keyCode]!=='undefined')&&(typeof raphSharpKeys[i]!=='undefined')){keyPressed=keyToKey[key.keyCode].replace('l',qwertyOctave).replace('u',(parseInt(qwertyOctave,10)+1).toString());if(raphSharpKeys[i].attrs.title===keyPressed){raphSharpKeys[i].attr({fill:blackNotesColour});keyUpCallback(keyPressed,getFrequency(keyPressed))}}}};window.onkeydown=keyboardDown;window.onkeyup=keyboardUp;var setKeyDownCallback=function(userCallback){keyDownCallback=userCallback};var setKeyUpCallback=function(userCallback){keyUpCallback=userCallback};return{keyDown:setKeyDownCallback,keyUp:setKeyUpCallback}};window.qwertyHancock=qwertyHancock})(window);
+(function(a,b){var c=function(b,c,d,e,f,g,h,i,j){var k=e||3,l=k*7,m=c||600,n=d||150,o=f||"A3",p=o.charAt(1),q=g||"#FFF",r=h||"#000",s=i||"#076cf0",t=m/l,u=t/2,j=j||"en",v=new Raphael(b,m,n),w=["C","D","E","F","G","A","B"],x=["A","C","D","F","G"],y=0,z=o.charAt(0),A=p,B=p,C=false,D,E,F={},G=[],H=[],I=[];var J=function(a){var b=["A","A#","B","C","C#","D","D#","E","F","F#","G","G#"],c;if(a.length===3){c=a.charAt(2)}else{c=a.charAt(1)}var d=b.indexOf(a.slice(0,-1));if(d<3){d=d+12+(c-1)*12+1}else{d=d+(c-1)*12+1}return 440*Math.pow(2,(d-49)/12)};for(var K=0;K<7;K++){if(z===w[K]){keyOffset=K;break}}for(K=0;K<7;K++){if(K+keyOffset>6){I[K]=w[K+keyOffset-7]}else{I[K]=w[K+keyOffset]}}for(K=0;K<l;K++){if(K%w.length===0){y=0}var L=I[y];if(L==="C"){A++}G[K]=v.rect(t*K,0,t,n).attr({id:I[y],title:I[y]+(A-1),fill:q}).mousedown(function(){C=true;this.attr({fill:s});D(this.attr("title"),J(this.attrs.title))}).mouseover(function(){if(C){this.attr({fill:s});D(this.attr("title"),J(this.attrs.title))}}).mouseup(function(){this.attr({fill:q});C=false;E(this.attr("title"),J(this.attrs.title))}).mouseout(function(){if(C){this.attr({fill:q});E(this.attr("title"),J(this.attrs.title))}});y++}A=p;for(K=0;K<l;K++){if(K%w.length===0){y=0}for(var M=0;M<x.length;M++){if(I[y]===x[M]){L=I[y]+"#";if(L==="C#"){A++}if(t*(K+1)<m){H[K]=v.rect(t*K+u*1.5,0,u,n/3*2).attr({id:I[y],title:I[y]+"#"+(A-1),fill:r}).mousedown(function(){C=true;this.attr({fill:s});D(this.attr("title"),J(this.attrs.title))}).mouseover(function(){if(C){this.attr({fill:s});D(this.attr("title"),J(this.attrs.title))}}).mouseup(function(){this.attr({fill:r});C=false;E(this.attr("title"),J(this.attrs.title))}).mouseout(function(){if(C){this.attr({fill:r});E(this.attr("title"),J(this.attrs.title))}})}}}y++}if(j=="en"){var N={65:"Cl",87:"C#l",83:"Dl",69:"D#l",68:"El",70:"Fl",84:"F#l",71:"Gl",89:"G#l",72:"Al",85:"A#l",74:"Bl",75:"Cu",79:"C#u",76:"Du",80:"D#u",186:"Eu",222:"Fu"}}else if(j=="de"){var N={65:"Cl",87:"C#l",83:"Dl",69:"D#l",68:"El",70:"Fl",84:"F#l",71:"Gl",90:"G#l",72:"Al",85:"A#l",74:"Bl",75:"Cu",79:"C#u",76:"Du",80:"D#u",186:"Eu",222:"Fu"}}var O=function(a){if(a.keyCode in F)return;F[a.keyCode]=true;for(var b=0;b<G.length;b++){if(typeof N[a.keyCode]!=="undefined"&&typeof G[b]!=="undefined"){var c=N[a.keyCode].replace("l",B).replace("u",(parseInt(B,10)+1).toString());if(G[b].attrs.title===c){G[b].attr({fill:s});D(G[b].attrs.title,J(G[b].attrs.title))}}}for(b=0;b<H.length;b++){if(typeof N[a.keyCode]!=="undefined"&&typeof H[b]!=="undefined"){c=N[a.keyCode].replace("l",B).replace("u",(parseInt(B,10)+1).toString());if(H[b].attrs.title===c){H[b].attr({fill:s});D(c,J(c))}}}};var P=function(a){delete F[a.keyCode];for(var b=0;b<G.length;b++){if(typeof N[a.keyCode]!=="undefined"&&typeof G[b]!=="undefined"){var c=N[a.keyCode].replace("l",B).replace("u",(parseInt(B,10)+1).toString());if(G[b].attrs.title===c){G[b].attr({fill:q});E(G[b].attrs.title,J(G[b].attrs.title))}}}for(b=0;b<H.length;b++){if(typeof N[a.keyCode]!=="undefined"&&typeof H[b]!=="undefined"){c=N[a.keyCode].replace("l",B).replace("u",(parseInt(B,10)+1).toString());if(H[b].attrs.title===c){H[b].attr({fill:r});E(c,J(c))}}}};a.onkeydown=O;a.onkeyup=P;var Q=function(a){D=a};var R=function(a){E=a};return{keyDown:Q,keyUp:R}};a.qwertyHancock=c})(window)
Please sign in to comment.
Something went wrong with that request. Please try again.