Skip to content

Instantly share code, notes, and snippets.

@bradorego
Last active February 19, 2016 18:25
Show Gist options
  • Save bradorego/d4f808e6398db2b9bec4 to your computer and use it in GitHub Desktop.
Save bradorego/d4f808e6398db2b9bec4 to your computer and use it in GitHub Desktop.
# A small snippet in Sonic Pi that lets you randomly select functions
# from an array, then remove them, and stops the loop when you run
# out of functions.
#
# The purpose being you can define the sections of your song/composition
# as functions, and then let rPI randomly select the order in which those
# sections happen.
#
# This is part of an exploration for a dance piece I will be choreographing
# for Kanopy Dance Company's April 2016 show.
#
# More info at http://kanopydance.org
define :melody1 do
play 60, release: 0.5
sleep 0.5
play 60+5, release: 0.5
sleep 0.25
play 60+10, release: 0.5
sleep 1
end
define :melody2 do
play 60, release: 0.5
sleep 0.5
play 60-5, release: 0.5
sleep 0.25
play 60-10, release: 0.5
sleep 1
end
# you can fill the array with whatever you want, obviously. Different functions, repeats of the functions, etc.
m_arry = [method(:melody1), method(:melody2),method(:melody1), method(:melody2),method(:melody1), method(:melody2)]
m_index = 0
live_loop :foo do
if (m_arry.empty?)
stop
end
m_index = rand_i(m_arry.length)
m_arry[m_index].call
m_arry.delete_at(m_index)
puts m_arry.length
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment