Skip to content

Instantly share code, notes, and snippets.

@Enkerli
Last active February 1, 2020 21:51
Show Gist options
  • Save Enkerli/49e9a1d1b0b22cc6547fc0bada30cd5f to your computer and use it in GitHub Desktop.
Save Enkerli/49e9a1d1b0b22cc6547fc0bada30cd5f to your computer and use it in GitHub Desktop.
# Simple Sonic Pi script which randomly picks part of a looping sample to create a groovy rhythm.
# https://soundcloud.com/synthbreath/sonic-pi-random-safari-loop
# Thanks to Sam Aaron for that “pick” trick! https://in-thread.sonic-pi.net/t/find-the-last-onset-within-a-sample/1299/10?u=enkerli
# And thanks to Martin Butz for the actual solution of finding the number of onsets in a sample! Quite elegant.
# https://in-thread.sonic-pi.net/t/find-the-last-onset-within-a-sample/1299/14?u=enkerli
# I also explored loops from sample libraries: https://soundcloud.com/synthbreath/sliced-loops
smp=:loop_safari
maxons=sample_buffer(smp, 0).onset_slices.last[:index]
loop do
ons=rand(0..maxons)
sample smp, onset: ons
sleep sample_duration(smp, onset: ons)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment