Skip to content

Commit

Permalink
restructure to use clocks and sequins
Browse files Browse the repository at this point in the history
  • Loading branch information
trentgill committed May 12, 2021
1 parent c29e0b5 commit f307624
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions timeline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
-- out2: volume
-- out3: filter cf

scale = {0,6,11,-12,-1,4,0,0,7,6,4,1}
scaleIX = 1
function next_note()
local n = scale[scaleIX]/12
scaleIX = scaleIX%#scale + 1
return n
end
seq = sequins{0,6,11,-12,-1,4,0,0,7,6,4,1}

function make_note()
output[1].volts = next_note()
output[1].volts = seq()
output[2]( ar(0.008, 1) )
end
function shift_pitch()
output[1].slew = 0.1
output[1].volts = next_note()
output[1].volts = seq()
end
function fsweepup_note()
output[3].slew = 0.5
Expand All @@ -33,40 +27,36 @@ end
function wobble_glissando()
output[3]( lfo() )
output[1].slew = 0.1
output[1].volts = next_note()
output[1].volts = seq()
end
function ratchet3()
output[2]( times( 3, { to(5,0.07), to(0,0.02) }))
end
function rapid_notes()
output[1].slew = 0.005
output[1]( loop{ to( next_note, 0.1 ) } )
output[1]( loop{ to( 2, 0.1 ) } )
end

function init()
output[3].slew = 2
ii.jf.mode(1)
ii.jf.run_mode(1)

metro[1].time = 1
metro[1].event = timeline_step
metro[1]:start()
timeline_step() -- call instantly
end

-- timeline helpers
function timeline_step()
timeline[line][2]() -- call the action!
local dur = timeline[line][1] -- grab current timestamp
line = line +1 -- next line
if not timeline[line] then return end -- stop if at end
dur = timeline[line][1] - dur -- compare timestamp delta
if dur == 0 then -- multiple simultaneous timestamps
timeline_step() -- just recurse
else metro[1].time = dur end -- or wait until next time
clock.run(run_timeline) -- call instantly
end

-- timeline runtime
line = 1 -- track which line is active
function run_timeline()
local dur = 0
while timeline[line] do
dur = timeline[line][1] - dur -- compare timestamp delta
if dur > 0 then clock.sleep(dur) end
timeline[line][2]() -- call the action!
dur = timeline[line][1] -- grab current timestamp
line = line +1 -- next line
end
end

-- time -- action
timeline =
Expand Down

0 comments on commit f307624

Please sign in to comment.