Skip to content

Instantly share code, notes, and snippets.

@trentgill
Created July 23, 2020 22:38
Show Gist options
  • Save trentgill/15a4fab7da5aabca729e0905ce510314 to your computer and use it in GitHub Desktop.
Save trentgill/15a4fab7da5aabca729e0905ce510314 to your computer and use it in GitHub Desktop.
--- clocky -- a demo of norns' clock library on crow
-- NB: requires experimental crow beta
-- available from https://github.com/monome/crow/pull/352
myarp = {}
myarp2 = {}
mylfo = {}
--myskal = {0,2,4,7,9,12,14,16,19,24}
myskal = {3,6,9,15,18,21,-6}
--myskal2 = {2,4,6,9,11}
myskal2 = {-12,12,11,-1}
function init()
ii.jf[2].mode(1)
ii.wsyn.ar_mode(1)
clock.internal.set_tempo(80)
myarp = run_arp( function(v) ii.jf[2].play_note(v,5) end
, make_sequence( myskal
, 'drunk' )
, 1/2
)
myarp2 = run_arp( function(v) ii.wsyn.play_note(v,3) end
, make_sequence( myskal2
, 'next' )
, 4/3
)
--mylfo = fn_lfo( ii.wsyn.fm_index ) -- min, max, framerate, shape
output[1].slew = 1/30
mylfo = fn_lfo(
function(v)
ii.wsyn.fm_index(v)
output[1].volts = v
end)
end
function run_arp(fn,seq,sync)
return clock.run(
function()
while true do
clock.sync(sync)
fn( seq() )
end
end)
end
-- arg1: scale table eg{0,2,4,7,9}
-- arg2: behaviour enum:{'next','prev',rand','drunk'} -- n as next#
-- retv: function that generates the next note
function make_sequence( skal, behaviour )
skix = 1
return
function() -- was 'new_note'
if behaviour == 'next' then
skix = skix + 1
elseif behaviour == 'prev' then
skix = skix - 1
elseif behaviour == 'rand' then
skix = math.random(#skal)
elseif behaviour == 'drunk' then
skix = skix + math.random(-1,1)
end
-- clamp to skal size
while skix < 1 do skix = skix + #skal end
while skix > #skal do skix = skix - #skal end
-- scale 12TET notes to v8
return skal[skix] /12
end
end
function fn_lfo( fn, duration, min, max, fps )
-- set defaults
duration, min, max, fps = duration or 1
, min or 0
, max or 5
, fps or 30
local phase = 0
local range = max - min
return clock.run(
function()
while true do
phase = phase + 1/(duration*fps)
while phase >= 1 do phase = phase -1 end -- wrap
local o = phase * 2 -- triangle
o = (o > 1) and 1-o or o -- triangle
o = o * range + min -- maps to [min,max]
fn( o )
clock.sleep(1/fps)
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment