Created
August 27, 2025 14:07
-
-
Save stephanwehner/2187326365dd6f53233ff721463efd0c to your computer and use it in GitHub Desktop.
how-to-swing-demo-sonic-pi
This file contains hidden or 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: Straight vs Swing | |
| # From Maxwell | |
| use_bpm 100 | |
| use_synth :piano | |
| swing_ratio = 0.65 # 0.60~0.70 = swing feel | |
| bars_per_section = 4 | |
| # Simple riff (C blues flavor), 1 bar = 8 eighth notes | |
| riff = [:c4, :eb4, :f4, :fs4, :g4, :bb4, :c5, :g4] | |
| define :play_riff_bar do |ratio| | |
| riff.each_with_index do |n, i| | |
| play n, release: 0.3, amp: 1.2 | |
| # Alternate long-short (swing) or even (straight) | |
| sleep(i.even? ? ratio : 1 - ratio) | |
| end | |
| end | |
| # Count-in | |
| 2.times { sample :elec_tick, amp: 0.6 ; sleep 0.5 } | |
| sleep 1 | |
| # Section A: Straight (even eighths) | |
| puts "Straight" | |
| bars_per_section.times { play_riff_bar 0.5 } | |
| # Small fill | |
| sample :drum_roll, amp: 0.6 | |
| sleep 1 | |
| # Section B: Swing (long-short eighths) | |
| puts "Swing" | |
| bars_per_section.times { play_riff_bar swing_ratio } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment