Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkbosman/2edbcf47ee2c5d4c625955bec63b678d to your computer and use it in GitHub Desktop.
Save dirkbosman/2edbcf47ee2c5d4c625955bec63b678d to your computer and use it in GitHub Desktop.
Sonic Pi: Basic Quantized Drum Beat
# Sonic Pi (http://sonic-pi.net/)
# Basic Quantized Drum Beat
# Globals
$bpm = 128
$bps = $bpm / 60
$qunatize = 1.0 / 32.0
# Helper step sequencing method
def sync_steps(steps, quantize = 1.0 / 4.0)
step_count = 0
loop do
sync :tick
step_count += ($qunatize / quantize)
if step_count >= steps
break
end
end
end
# Definitions for basic drum beats
def hat_pedal
sample :drum_cymbal_pedal
end
def hat_closed
sample :drum_cymbal_closed
end
def kick
sample :drum_heavy_kick
end
# Simple Four-on-the-floor beat
def song
in_thread do
loop do
kick
sync_steps(4)
end
end
in_thread do
loop do
3.times do
sync_steps(2)
hat_closed
sync_steps(2)
end
sync_steps(2)
hat_pedal
sync_steps(1)
hat_pedal
sync_steps(1)
end
end
end
# Queue the song
in_thread do
sync :tick
song
end
# Start up the sync thread using global quantization
in_thread do
loop do
cue :tick
sleep $qunatize / $bps
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment