Last active
May 23, 2017 08:58
-
-
Save eeropic/42f78df8b27347f89d50a202a4c5178a to your computer and use it in GitHub Desktop.
updated gist via ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| include('http://eerojohannes.com/midi/js/teoria.js') | |
| var l = console.log.bind(console) | |
| var keyboardPiano=["q","2","w","3","e","r","5","t","6","y","7","u"] | |
| var intervals=["m2","M2","m3","M3","P4","A4","P5","m6","M6","m7","M7"] | |
| l() | |
| function getNote(nr){ | |
| return teoria.note.fromMIDI(nr).toString(true) | |
| } | |
| function askRandomInterval(){ | |
| var randomNr=Math.floor(Math.random()*11) | |
| var randomIntervalNr=Math.floor(Math.random()*10) | |
| randomNote=getNote(randomNr) | |
| randomNoteInterval=getNote(randomNr+(randomIntervalNr+1)) | |
| l(randomNote+' '+intervals[randomIntervalNr]+'?') | |
| } | |
| function checkAnswer(inputNote){ | |
| if(inputNote==randomNoteInterval){ | |
| l(randomNoteInterval+" is correct") | |
| } | |
| else l(inputNote+"is INCORRECT, it's "+randomNoteInterval) | |
| } | |
| askRandomInterval(); | |
| function onKeyDown(event){ | |
| var inputNr=keyboardPiano.indexOf(event.key) | |
| var inputNote=getNote(inputNr) | |
| if(inputNr!=-1)checkAnswer(inputNote) | |
| askRandomInterval() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment