Using osc message for random seed

Hello,

I’m trying to change a random seed number within a live_loop, and while I can change the seed live in the sonic-pi editor, the same doesn’t work when sending seed number changes over osc message. See my below piece:

live_loop :taps, auto_cue: false do |idx|
  use_random_seed 2
  # I would love replace the above line with the below line
  #use_random_seed sync "/osc:192.168.8.95:33840/taps/seed"
  use_synth :dsaw
  use_real_time
  with_fx :reverb, room: 1  do
    32.times do
      ns = (scale :a1, :minor, num_octaves: 2)
      play ns.choose, release: 0.1, amp: 2, amp: rand + 0.5, cutoff: rrand(60, 90)
      sleep 0.125
    end
  end
end

Hoping someone could point me in the right direction. Thanks!

EDIT: just to clarify, what’s currently happening is that nothing happens when sending the appropriate osc message, ie

#from client
oscsend /taps/seed 123

I can see the message arriving in Sonic Pi.

Hi

You may have to access the value you want via an array as in this Robin piece if code.

live_loop :n1 do
  use_real_time
  b = sync "/osc/sync"
 #set time_warp to delay note to match  greatest latency. use rt so time not affected by bpm
  time_warp  rt(0.18) do 
    use_bpm b[0)
    play scale(:e4,:minor_pentatonic).tick,release: 0.25
  end
end

Thanks! That does the trick, see my code:

live_loop :taps, auto_cue: false do |idx|
  seed = sync "/osc:192.168.8.95*/taps/seed"
  #seed = 2
  use_random_seed seed[0]
  use_synth :dsaw
  with_fx :reverb, room: 1  do
    32.times do
      ns = (scale :d2, :minor, num_octaves: 2)
      play ns.choose, release: 0.1, amp: 2, amp: rand, cutoff: rrand(60, 80)
      sleep 0.125
    end
  end
end

So I get it to do the “32.time do” bit, but it’s not repeating, so I’m guessing I’m going to have to pass it in continuously somehow. Any idea?

Also, the same seed number passed in via osc doesn’t seem to result in the same randomness as from within Sonic Pi. Is there a reason for this?

Thanks again for the help.

hum maybe put an in_thread do and end embracing your 32.times

Nope, unfortunately, that doesn’t do it. I would have to freshen up on the looping vs in_thread it seems.

My ideal use case for this would be to map an external rotary button via osc enabling me to “scroll” through interesting randomness.

Use the search field to look for osc and robin posts, i think you will find your answer.