Skip to content

Instantly share code, notes, and snippets.

@eudes
Last active July 14, 2020 23:01
Show Gist options
  • Save eudes/03e840d5afe408dfb866efe954855162 to your computer and use it in GitHub Desktop.
Save eudes/03e840d5afe408dfb866efe954855162 to your computer and use it in GitHub Desktop.
// Remix of Queen's "We will rock you" for the patatap tracker
// see: https://gist.github.com/eudes/d30365efa5e712cded7377945a690350
// - Go to http://patatap.com/
// - open the developer console (note: F12 is disabled!, open with inspect)
// - execute this snippet
// - change 'seq' to change the note sequence. Keys must be uppercase
// - you can send 1 function instead of a note to control other stuff in the page
function keypress(char) {
$.event.trigger({type: 'keydown', which: char.charCodeAt(0)})
}
function bpmToMillis() {
return ((60 / bpm) * 1000) / subdivisions
}
async function tracker() {
while (seq.length > 0) { // avoid freeze if emptying seq
for (let notes of seq) {
if (notes.length > 0 && typeof notes[0] === 'function') {
notes[0]()
} else {
if (play) notes.forEach(keypress)
await new Promise((resolve) =>
setTimeout(resolve, bpmToMillis())
)
}
}
}
}
var seq = [['a']]
var bpm = 120
var subdivisions = 2
var play = true
// create a textarea for pasting sequences
$('body').append('<textarea id="seq" style="position:absolute; width:14em; height: 10em; color: black">// paste your sequence and press enter\nseq = [\n["A"]\n]</textarea>')
$('#seq').on('keyup', (e) => {
if(e.which == 13 && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) {
eval(e.target.value)
e.target.style.width = '20px'
e.target.style.height = '20px'
}
return e
})
tracker()
seq = [
['C'],
[],
['C'],
[],
['A'],
[],
[],
[],
['C'],
[],
['C'],
[],
['A'],
[],
[],
[],
['C'],
[],
['C'],
[],
['A'],
[],
[],
[],
['C'],
[],
['C'],
[],
['A'],
[],
[],
[],
['Z','C'],
['Z',],
['Z','C'],
['Z',],
['Z','K','A'],
[],
['Z',],
['Z',],
['Z','D','C'],
[],
['Z','D','C'],
[],
['Z','A'],
['Z',],
['Z',],
['Z',],
['Z','K','C'],
[],
['Z','C'],
['Z',],
['Z','A'],
['Z',],
['Z','N',],
[],
['Z','H','C'],
[],
['Z','H','C'],
[],
['Z','A'],
['Z',],
['Z',],
[],
['Z','K','C'],
[],
['Z','C'],
['Z',],
['Z','J','A'],
['E'],
['Z',],
['E'],
['Z','W','C'],
[],
['Z','W','C'],
[],
['Z','T','A'],
[],
[],
[],
['Z','C'],
['Z',],
['Z','C'],
[],
['Z','A'],
[],
['Z',],
[],
['Z','C'],
['Z',],
['Z','C'],
[],
['Z','A'],
[],
['Z',],
['Z',],
['Z','D','C'],
[],
['C'],
[],
['Z','D','A'],
[],
[],
[],
['Z','E','C'],
[],
['C'],
[],
['Z','E','A'],
[],
[],
[],
['Z','D','C'],
[],
['Z','D','C'],
[],
['A'],
[],
[],
[],
['Z','D','C'],
[],
['Z','D','C'],
[],
['A'],
[],
[],
[],
]
// try changing the bpm like this:
// bpm = 164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment