Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ellisgeek/876125 to your computer and use it in GitHub Desktop.
Save ellisgeek/876125 to your computer and use it in GitHub Desktop.
(function() {
// Notes from http://news.ycombinator.com/item?id=1952531
var notes = {
"suspended cymbal":"zk",
"snare":"bschk",
"brush":"pv",
"bass":"bk",
"flam1":"tk",
"roll tap":"vk",
"flam2":"kt",
"flam tap":"kttp",
"hi hat tap":"krp",
"short roll":"pv",
"better hi hat":"th",
"instant rimshot":"thp, ds"
};
function clickListen() {
var e = document.createEvent('MouseEvents');
e.initMouseEvent("click", true, true, window, 1, 12, 345, 7, 220, false, false, true, false, 0, null );
document.getElementsByClassName("gt-icon-listen-off")[0].dispatchEvent(e);
}
function playNote(event) {
var source = document.getElementById("source");
if (source.value === event.target.note) {
clickListen();
return;
}
source.value = event.target.note;
var state = 0;
var result_box = document.getElementById("result_box");
var timer = window.setInterval(function() {
if (state === 0 && result_box.childNodes[1] && result_box.childNodes[1].data === "...") {
state = 1;
} else if (state === 1 && (!result_box.childNodes[1] || !result_box.childNodes[1].data)) {
clickListen();
window.clearInterval(timer);
}
});
}
for (var name in notes) {
if (notes.hasOwnProperty(name)) {
var button = document.createElement("input");
button.type = "button";
button.value = name;
button.note = notes[name];
button.onclick = playNote;
document.body.appendChild(button);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment