Rings are the arrays of Sonic Pi, and the best way to arrange notes
These are tools for better accessing, adjusting, and using values from rings
.reverse- returns a reversed version of the ring
.sort- creates a sorted version of the ring
.shuffle- creates a shuffled version of the ring
.choose- returns a random item from the ring
.pick(3)- returns a ring with the results of calling
.pick- similar to
.pick(3)only the size defaults to the same as the original ring
.take(5)- returns a new ring containing only the first 5 elements
.drop(3)- returns a new ring with everything but the first 3 elements
.butlast- returns a new ring with the last element missing
.drop_last(3)- returns a new ring with the last 3 elements missing
.take_last(6)- returns a new ring with only the last 6 elements
.stretch(2)- repeats each element in the ring twice
.repeat(3)- repeats the entire ring 3 times
.mirror- adds the ring to a reversed version of itself
.reflect- same as mirror but doesn’t duplicate middle value
.scale(2)- returns a new ring with all elements multiplied by 2 (assumes ring contains numbers only)
If you’re making a ring by hand and want to include some rests, put in
:r to not play anything for that note. In this example,
ring :e3, :e3, :r, :g3, :r, :r, :r, :a3, it will play two notes, rest, play another note, then rest for three notes before the last.
.look is a slightly different version of
.tick increases the ring index,
.look plays the current ring note without increasing the index.
Ticking an array twice makes it start moving through the ring. Using tick and then look makes it stay on the first note until it get’s ticked again. Be sure to test uses of look to make sure it’s staying where it needs to.
Ring constructors are shortcuts to make different types of rings with different values. They’re useful for quickly making different sounds or beats.
Requires a starting note, an ending note, and a spacing value. It returns a ring starting from the ending value, with each one incremented by the spacing value. Once it reaches the end it starts over.
Bools lets you quickly create a ring of true/false boolean values, which can then be used to trigger sounds as needed.
Knit lets you combine several repeated values together in a larger sequence. It must be given an even number of arguments, and each pair of arguments is (in order):
- The note, or notes, to play
- The number of times that note is repeated
Spread takes two values - the first is the number of active beats, and the second is the total beats they’re distributed across. The distribution is done automatically through Euclidean Distribution, which basically tries to space them as evenly as possible.
What’s literally returned is a ring of boolean values, with the true values distributed based on the params. These can be used in a few different ways.