Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code snippet to use the Tidal mini-notation into Hydra
/*
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