Run a block at the given times

at

[times (list), params (list)]

Given a list of times, run the block once after waiting each given time. If passed an optional params list, will pass each param individually to each block call. If params is smaller than args, the values will rotate through. If no params are passed, the times are fed as the default params. If the block is given 2 args, both the times and the params are fed through. Finally, a third parameter to the block will receive the index of the time.

Introduced in v2.1

Example 0 

at [1, 2, 4] do 
  play 75          
end                



# plays a note after waiting 1 second,
# then after 1 more second,
# then after 2 more seconds (4 seconds total)



Example 1 

at [1, 2, 3], [75, 76, 77] do |n| 
  play n
end


# plays 3 different notes
 
 



Example 2 

at [1, 2, 3],
    [{:amp=>0.5}, {:amp=> 0.8}] do |p|
  sample :drum_cymbal_open, p         
end


 
# alternate soft and loud
# cymbal hits three times
 



Example 3 

at [0, 1, 2] do |t|
  puts t
end


# when no params are given to at, the times are fed through to the block
#=> prints 0, 1, then 2
 



Example 4 

at [0, 1, 2], [:a, :b] do |t, b| 
  puts [t, b]
end


#If you specify the block with 2 args, it will pass through both the time and the param
#=> prints out [0, :a], [1, :b], then [2, :a]
 



Example 5 

at [0, 0.5, 2] do |t, idx| 
  puts [t, idx]
end


#If you the block with 2 args, and no param list to at, it will pass through both the time and the index
#=> prints out [0, 0], [0.5, 1], then [2, 2]
 



Example 6 

at [0, 0.5, 2], [:a, :b] do |t, b, idx| 
  puts [t, b, idx]
end


#If specify the block with 3 args, it will pass through the time, the param and the index
#=> prints out [0, :a, 0], [0.5, :b, 1], then [2, :a, 2]