Force random notes into a scale after transposing

Hi everybody, Hi Sam,

I’m relatively new on Sonic Pi, so first let me thank Sonic Pi team and Sam Arron for making such a cool program! I’m having so much fun on it!

So here’s my question: I’m working on a project wich uses generating random notes and transposing to make variations. Is there a way to force the transposed result to respect a scale I defined before, such as in the “scale” midi effect in ableton?

Hope my question is clear, and many thanks in advance!

1 Like

I don’t know if my question is clear enough, so let me try to aks it a different way:

imagine I have a note X wich is randomly generated from different variables and decisions I made in the code, for example a E, but I would like this one to respect a scale of (still for example) C minor, so I get E flat instead.

How is that possible in Sonic Pi?

Again sorry if my question is dumb and the answer evident, I’m a newbie to Sonic Pi

Not quite sure of your question, but you can take a random integer and use it to index a list of allowed notes.
For example, you could have a three octave range of notes in the scale of :c and play notes from this chosen randomly like this.

notes = scale(:c3,:major,num_octaves: 3) # list of 22 notes
live_loop :test do
  puts n
  play notes[n]
  sleep 0.2

Hi @simcitizen - welcome to our community!

Fab question! I don’t have much to add at this point in addition to @robin.newman’s remarks other than to say that it might be easier to think of a random nth note of a scale rather than, say, E. That way you get to look up the nth note using the approach Robin demonstrates above.

Good luck and I look forward to hearing more of what you get up to with Sonic Pi!

Thanks Robin and Sam for your quick replies! You totally answered to my question! I’m going to immediatly test your suggestions!

1 Like