Created
June 30, 2019 16:30
-
-
Save charlieroberts/3aa779329c49e10557a8ca66093eeb0e to your computer and use it in GitHub Desktop.
Code snippet to use the Tidal mini-notation into Hydra
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
/* | |
Example usage: | |
osc( | |
Tidal( '<1 20> [50 100]*2' ), | |
0.01, | |
1.4 | |
).out( o0 ) | |
*/ | |
const s = document.createElement( 'script' ) | |
s.src = 'https://cdn.jsdelivr.net/gh/gibber-cc/tidal.pegjs/dist/pattern.js' | |
document.querySelector( 'head' ).appendChild( s ) | |
window.Tidal = function( pattern ) { | |
let val = null | |
let phase = 0 | |
let evts = [] | |
let end = -Infinity | |
const p = Pattern( pattern ) | |
const out = function() { | |
phase += 1/120 | |
if( evts.length <= 0 && phase > end ) { | |
phase = 0 | |
evts = p.query( phase, 1 ) | |
} | |
if( evts[0] !== undefined && phase > evts[0].arc.start.valueOf() ) { | |
const evt = evts.shift() | |
val = evt.value | |
end = evt.arc.end.valueOf() | |
} | |
return val | |
} | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment