Last active
July 14, 2020 21:51
-
-
Save eudes/d30365efa5e712cded7377945a690350 to your computer and use it in GitHub Desktop.
A simple music tracker for patatap
This file contains 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
// - 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:30em; height: 40em; 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() | |
// sample sequence :) | |
seq = [ | |
['A'], // single note | |
[], // send no notes to just pass a subdivision | |
['D'], | |
['A', 'P'], // multiple notes at the same time | |
[], | |
['D'], | |
[], | |
['E', 'O'], | |
[], | |
['A'], | |
[], | |
['D'], | |
['K'], | |
['A'], | |
[], | |
['D'], | |
[], | |
['E'], | |
[], | |
['A'], | |
['I'], | |
['D'], | |
[], | |
['A'], | |
['I'], | |
['D', 'K'], | |
[], | |
['E', 'N'], | |
[], | |
['A', 'C'], | |
[], | |
['D', 'N'], | |
[], | |
['E', 'U', 'D', 'E', 'S'], | |
[], | |
['G', 'O'], | |
[], | |
[() => {bpm+=40; console.log(`Up we go. BPM: ${bpm}`)}], // you can send functions too. These don't count as a beat. | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment