Skip to content

Instantly share code, notes, and snippets.

@trentgill
Created July 29, 2021 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trentgill/ec9fcf2d2583bb75934b7130baf231bb to your computer and use it in GitHub Desktop.
Save trentgill/ec9fcf2d2583bb75934b7130baf231bb to your computer and use it in GitHub Desktop.
ep3.lua
--- maps: S2E3 long distance
-- using i2c to communicate to external devices
-- ???
s = sequins
ws = ii.wsyn
wd = ii.wdel
cr = clock.run
dorian = s{0,2,3,5,7,9,10}:step(3)
notes = s{
s{0,3,6,9}:count(32), -- diminshed
s{0,4,8}:count(32), -- augmented
}:step(0)
alter = s{0,-1,-1,0,1,1,2}
rhythm = s{1,3,2,1,3,2,2}
function init()
clock.tempo = 150
clock.tempo = 75
ws.ar_mode(1)
-- play a cluster of 32 notes
cr(function()
for i= 1,32 do
clock.sync(rhythm())
ws.play_note(dorian()/12-1, 1.2)
end
end)
end
-- rising ramp action
function rr()
return fnl( ws.ramp, 0
, { to(5, 5)
, to(0, 0.5) }
, 20)
end
-- rising fm_ratio action. optional arg sets step's per second
function rf(fps)
return fnl( ws.fm_ratio, 1
, { to(11, 7) }
, fps)
end
-- call a function repetitively in time
-- the arg to the function is interpolated fps times per second
-- dest_ms is a table of `to()` calls for ASL-like sequences
function fnl(fn, origin, dest_ms, fps)
return clock.run(function()
fps = fps or 15 -- default
local spf = 1 / fps -- seconds per frame
fn(origin)
for _,v in ipairs(dest_ms) do
local count = math.floor(v[3] * fps) -- number of iterations
local stepsize = (v[2]-origin) / count -- how much to increment by each iteration
while count > 0 do
clock.sleep(spf)
origin = origin + stepsize -- move toward destination
count = count - 1 -- count iteration
fn(origin)
end
end
end)
end
-- example fn, plays some notes & performs some sweeps
function runramp()
cr(function()
-- for i = 1, 25 do
local i = 1
output[2].action = ar(0.003,3)
while true do
clock.sync(1)
local nn = (notes() + alter())/12
ii.wsyn.play_note(nn, 0.8 + math.random()/2)
if i % 8 == 0 then
output[1].volts = nn
output[2]()
end
i = i + 1
end
end)
fnl( wd.feedback, -5
, { to(5, 1)
, to(0, 1)
, to(5, 3)
, to(5, 2)
, to(0, 0.1)})
fnl( function(n) clock.tempo = n end, 150
, { to(600, 10)
, to(600, 10) }
, 60)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment