Uninterruptible sequencer template

I have heard that teaching is a good way of learning, so here I am, a learner, offering a useful(?) template for an adaptable sequencer.

The point of it is ithe first time you press play, and when you press it after stop, the sequencer restarts, but if you press play while it is playing, it continues from where it had got to.

Leave the lines involving SET and GET alone. (You can modify the sequence by changing the variables ax, bc, cx and dx if you like, probably best to do that at the end of the live_loop if they are likely to be outside the bounds of their respective arrays, as the code that sets them at the end of the live_loop increment item by one and then wraps them to fit inside their arrays.

Everything else is fair game for rewriting as you fancy. If you have really long lists of numbers for the sequencer arrays a, b, c, and d, put them in text files and uncomment the eval lines at the top.

It’s currently set up with a demonstrateion piece.

a = [  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 ]
b = [  0,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0 ]
c = [  0,  0,  0,  0,  1,  0,  0,  0,  0,  0,  0 ]
d = [  0,  0, 51, 54,  0,  0, 51, 48,  0,  0 ]

# a = eval_file ""
# b = eval_file ""
# c = eval_file ""
# d = eval_file ""

if not defined?(a1) then
  set :ai,0; set :bi,0; set :ci,0; set :di,0
end

set_mixer_control! amp: 0.75

live_loop :one do
  
  ax = get:ai; bx = get:bi; cx = get:ci; dx = get:di
  
  use_bpm 180
  use_synth :piano
  use_synth_defaults release: 3
  
  if a[ax] != 0
    play 60
  end
  if b[bx] != 0
    play 63
  end
  if c[cx] != 0
    play 66
  end
  if d[dx] != 0
    synth :fm, note:d[dx], attack:2, release:2, amp:0.15
  end
  
  if a[ax]+b[bx]+c[cx]+d[dx] == 0
    sample :bd_zome, amp: tick % 5 / 25.0
    sleep 1/2.0
  else
    sleep 1/3.0
  end
  
  set :ai,(ax+1)%a.size; set :bi,(bx+1)%b.size
  set :ci,(cx+1)%c.size; set :di,(dx+1)%d.size
end

Code updated to make the process automatic. No more need to comment out a line after the first use. :slight_smile: