Last active
February 6, 2021 12:40
-
-
Save zackintosh/1daec9decfa323aee254 to your computer and use it in GitHub Desktop.
Sonic Pi: Basic Quantized Drum Beat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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