Created
June 17, 2019 22:31
-
-
Save amark/b95dff8b74c977a5c563c692347cf2a2 to your computer and use it in GitHub Desktop.
Revisions
-
amark created this gist
Jun 17, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/13.8.12/Tone.js"></script> <textarea id="foo" style="width: 100%; height: 100%;">this track continues into the new line & here but this is a different track playing simultaneously with first.</textarea> <script>;(function(){ foo.onmouseup = function(){ play(foo.value) } window.play = function play(S){ var N = [], f = true; S = split(S, '\n\n'); // split song into sections if haven't already S.forEach(function(s, T){ if(!f){ return N.push(s) } f = false; // handle recurse if(typeof s == 'string'){ s = s.replace('&\n', '') } // parse once var n = []; // do we have next? T = split(s, '\n'); T.forEach(function(t){ // For each track, of the first section, of the current version of the song new Tone.Synth().toMaster().triggerAttackRelease(convert(t[0])+'4', '0.1s'); // ... play the first note of each track! t = t.slice(1); if(t.length){ n.push(t) } // handle recurse }); if(n.length){ N.push(n) } }); if(N.length){ setTimeout(function(){ play(N) }, 100) } } function convert(t){ var notes = 'ABCDEFG'.split(''); return notes[t.charCodeAt(0) % notes.length] } function split(t, on){ return typeof t == 'string'? t.split(on) : t; } }());</script>