Skip to content

Instantly share code, notes, and snippets.

@charlieroberts
Created June 30, 2019 16:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlieroberts/3aa779329c49e10557a8ca66093eeb0e to your computer and use it in GitHub Desktop.
Save charlieroberts/3aa779329c49e10557a8ca66093eeb0e to your computer and use it in GitHub Desktop.
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