Sonic Pi's onset: option indexes a sample's drum hits like a list, so you can play individual hits by number
Sonic Pi lets you treat a drum-break sample as an array of its individual hits using the onset: option. sample :loop_amen, onset: 5 plays the sixth hit of the Amen break — the sixth because computer scientists count from zero. This lets you work through each drum in a break ‘like a list’, indexing to a specific hit, picking a random one, or iterating over them all, giving a programmatic alternative to manually slicing a break in a DAW. It illustrates a broader Sonic Pi idea: audio files are data structures you can traverse in code.
Examples
sample :loop_amen, onset: 0 # first hit\nsample :loop_amen, onset: rand # a random hit, quite fun\nliked as an interview-question demo: index individual drums from the Amen break by number.
Assessment
What does onset: 5 select from a sample, and why the sixth hit rather than the fifth? How does this differ from slicing a break by hand in a DAW?