home/ atoms/ sonic-pi-ring

Rings in Sonic Pi wrap around on any index access, enabling infinite cycling of sequences

A ring is a circular list where any integer index — negative, zero, or beyond the end — wraps to a valid element. (ring 1,2,3)[4] returns 1. Normal arrays raise errors on out-of-bounds access; rings never do. Rings are created with the ring fn or by appending .ring to a list. scale() and chord() return rings. Rings are immutable: chain methods return new rings without modifying the original, making them safe to share across threads.

Examples

r = (ring 60, 62, 64, 67) live_loop :arp do play r.tick sleep 0.25 end # cycles through forever

Assessment

Explain what (ring :a,:b,:c)[7] returns and why. Create a ring of 4 chords and tick through them in a live_loop.

“use indexes that are negative or larger than the size of the ring and they'll wrap round to always point at one of the ring”
corpus · sonic-pi-built-in-tutorial · chunk 17