Hello! The idea came to me when I was looking at Mr Bomb’s video @mrbombmusic about random_source. I wanted to hear really the differences between them. So I wrote this inspired by his tutorial and it works, so if you see something to improve, it will be with pleasure…
use_bpm 95
use_random_source :pink
##change with perlin, etc
a = []
with_fx :reverb, mix: 0.8 do
200.times do
n = rand
a.push(n)
play n * 150, amp: 0.5
sleep 0.25
end
end
puts a
Very interesting and useful!
Here’s a tweaked version that steps through them all:
use_bpm 95
randomsources = [:white, :pink, :perlin, :light_pink, :dark_pink]
use_random_source :pink
##change with perlin, etc
a = []
randomsources.each do |x|
use_random_source x
with_fx :reverb, mix: 0.8 do
40.times do
n = rand
a.push(n)
play n * 150, amp: 0.5
sleep 0.25
end
end
puts a
sleep 2
end #each
I especially like perlin and dark_pink for melodies that don’t jump around too much.
Is there a clever way to constrain these random notes to a given scale?
Good Harry @HarryLeBlanc and thanks for sharing your amelioration of my initial patch…It has a better look now!
And it’s right, you can use one of them for a compostion but I find fascinating the idea in itself to be able to hear all these “discret” numbers, so small and inaudible at the beginning!
n is a random float between 0 and 1, a is an initially empty array, and a.push(n) simply appends a new random float to that array:
use_bpm 95
use_random_source :pink
##change with perlin, etc
a = []
puts a
sleep 1
5.times do
n = rand
a.push(n)
puts n
play n * 150, amp: 0.5
sleep 1
end
puts a
It simply appends elements to a pre-defined array.
Now I’m wondering how to quantize a series of random floats in an array to a musical scale and also how to impose lower and upper limits, in order to create a random-note sequencer.
Hi
look for “scale” in the tutorial and also in the Help/Lang document. One can get tied up in knots using ‘custom’ arrays or rings for constrained random melodies. Sonic Pi provides many useful functions for creating such patterns.
Look at the examples (and mr bomb’s response) in this post:
Thanks for these suggestions. I am aware of them and have used them in my own Sonic Pi coding, but are they truly random or are they pseudo-random (i.e. with some repetition)? I’m still intrigued by the possibility of scale-quantising truly random series of floating point numbers; however, I have not yet conceived of a means of achieving this.
I came up with a method to find the closest note to a scale. Here it is. (It relies on a function, cleanchordorscale, which can be found in my library YummyFillings.rb. It’s on github, under my username, HarryLeBlanc.)
Hope you find this useful. Should allow you to constrain random integers to any arbitrary scale or array of notes.
I think I’ll add it to YummyFillings.rb for the next release.
Cheers,
H