Inspired by @martin’s code (thank you) here’s my go at a randomised sequence generator, where the sequence stays stuck until I want to change it. I’m sure this will be useful.
But this is the point where someone gently points out that Sam’s written an in-built one already.
I’m starting to want to have my own function library - is that possible?
#Randomised sequences that stick
define :getseq do |length, notes, seed|
#Generate a randomised sequence based on the seed
for i in 0..length-1
notes = scale :C4, :major, num_octaves: 1
#Change the sequence length and seed
seq1 = getseq(7,notes,1)
live_loop :main do
play seq1.tick, amp: 0.2
live_loop :bass, sync: :main do
play :C3, amp: 0.2
You can define individual functions, and then allow them to be available on Sonic Pi start up using
init.rb - is that close enough?
In fact I think that something like this is just a useful - slightly different effect but easier to code live! A randomised sequence that repeats - that’s the key thing. My ideal would be a sequences that gradually evolves rather than hops between states.
seq = notes.shuffle
Re function library, I do a similar thing by defining my utility functions in a dedicated file, and then using
run_file in init.rb
That sounds good, I’ll experiment
NB if you use the latest 3.3beta on Mac released to Patreon supporters today then be aware that the location of init.rb has moved to
Windows and Raspberry Pi me.
The ring operations take, shuffle etc. are rich pickings for this directed randomness. But I’ve decided what I need is a shuffle that where I can control the amount of shuffling if you see what I mean. I think I should be able to do that. Like you specify how many elements get swapped, or how far apart they are.
I built my own prototype version of exactly that too a little while ago. Haven’t used it for a little while, so I forget if it was fully tested and working but I was also wanting such a thing. I am hopeful that a version of it will make its way into the official functions.
Ah ah, great minds I think this would be really good for the live stuff I’m working on now, so I’ll give it a go too.
EDIT mind you, the existing ring functions are at least as rich as what you get in a modular sequencer and more flexible in combo, so maybe I should exhaust those possibilities before chomping at the bit for new functions. Users…can’t live with them…
I have found the new
use_random_stream command in latest SP3.3.0beta useful for controlling what is selected. I itilised it for example in my beethoven mashup program I haven’t published this yet because it contained this command, which I used in my own build. I changed the selection during the program using
use_random_stream [:white,:pink].choose to change the effect of subsequent “random” commands.
Oh yes, that does look interesting. With a bit of experimenting now I have found some nice ways of using the ring functions to give more of evolving feel to a sequence. I guess at bottom I’m trying to hear some of the conventional ways to cadance a solo - increasing complexity, embellishment, motivic development. Simply adding more randomness (which is the easiest to do) is a way, but a bit of a one-trick pony. I think this new
use_random_stream could help things along.