Random 303 fun with changing notes & settings each loop

I’d been looking to “emulate” a 303… but got sucked into the world of “random” (typical!)
anyway, I thought I’d post my playTime results if anyone is interested!
any “proper coders” that can streamline this, or point out proper ways of chopping up arrays etc, please do comment!


use_cue_logging false
use_debug false
use_bpm 60

# 303 ?

def shift  cutOff, res
  use_synth :tb303
  use_synth_defaults release: 0.125, cutoff: cutOff, res: res, wave: 0, sustain: rand() / 10.0, decay: range(0.05, 0.125, 0.05).to_a.sample
end

shift(0,0)
co = range(0, 130, 5).mirror
r  = range(0, 1, 0.01).mirror
counter = 0
oNotes = n = [:e1, :f1, :g1,:e2, :f2, :g2, :e3, :f3, :g3, :e4, :f4, :g4]
oTimes = [0.25, 0.5, 0.25, 0.125, 0.125, 0.5, 0.25]
times = oTimes.shuffle
notes = []
8.times do
  notes.append(oNotes.sample)
end


live_loop :threeohthree do
  tick
  #if look % 4 == 1
  cc = co.look.to_i
  rr = r.look
  '''
    if range(0, 10, 1).to_a.sample == 1 # random!
      cc = rand() * 100
      rr = rand()
    end
    '''
  shift(cc, rr)
  counter = look # counter + 1
  puts "shifted! cc=#{cc} rr=#{rr} counter=#{counter}"
  if [*5..8].include? counter
    notes = [:e1, [:e2, :f2].sample, :f2, :e2, :g3, :g2, :f1, :e3]
  elsif [*9..12].include? counter
    notes = [:e1, [:e2, :f2, :g2].sample, :f2, [:e2, :e3, :e4].sample, :g3, :g2, :f1, :e3]
  elsif [*13..24].include? counter
    notes = [:e1, [:e2, :f2, :g2].sample, :f2, [:e2, :e3, :e4].sample, :g3, [:g2, :g3, :f2, :f3, :e2, :e3, :e4].sample, :f1, :e3]
  else
    n = oNotes + [:g4, :a2, :d2, :c2]
    notes = []
    8.times do
      notes.append(n.sample)
    end
    times = oTimes.shuffle
  end
  #end
  with_fx :echo, decay: 4, mix: 0.2, phase: [0.125, 0.25, 0.5, 0.666, 0.999].look do
    play_pattern_timed notes, times
  end
end
1 Like

A small suggestion that comes to mind: if you’re not interested in using the alternate call to .sample where you ask for multiple items at once, (eg .sample(N)), then as far as I understand it, you can just use .choose. (No need to convert a ring to an array to use it either).

You could probably initialise notes a little differently if you wanted to as well.
Instead of appending 8 times to an empty array, you could do:

notes = oNotes.pick(8)

(Similarly where you append from a sampling of n)

1 Like

cheers for all that! much appreciated!
I have a story I often tell, one that I learned several things from…
I was running a workshop at a fairly high profile science festival… lots of kids attending were autistic, one of them asked me how to do something, and I said “oh, there’s many ways to skin a cat” … and his face went white… “we’re going to skin cats?!”…
I learned very quickly to not rely on my use of proverbial language in any workshop(!)
and, that there a lots of ways of doing something, but you don’t know unless you ask!
so, this is superb! thank you for replying!
yours
Phil.

1 Like