Skip to content

Instantly share code, notes, and snippets.

@nischalshrestha
Last active January 31, 2023 15:50
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 nischalshrestha/d630b2446766ad5772fc36e0219099ac to your computer and use it in GitHub Desktop.
Save nischalshrestha/d630b2446766ad5772fc36e0219099ac to your computer and use it in GitHub Desktop.
Sonic Pi: Making music with code!
##| You can play notes, chords, scales Oh my!
##| Midi notes
play 64
##| Or with more human-friendly note names :<letter><octave>
##| play :c2
##| play has attack, decay, sustain, release parameters to shape the sound
##| play :c, attack: 1, decay: 0.5, sustain: 2, release: 0.1
##| Chords
##| play chord(:c, :major)
##| play chord(:c, :minor)
##| play chord(:c, )
##| but this will let us play the notes in succession
##| play_pattern scale(:c, :major_pentatonic)
# You can use different synths!
# Woah! this reminds me of {withr}
with_synth :saw do
play_pattern scale(:c, :minor), attack: 1, release: 0.5, amp: 0.5
end
## You can make beats!
sample :drum_bass_hard
##| sleep 0.125
##| sample :drum_bass_soft
##| sleep 0.25
##| sample :drum_cymbal_open
##| Live loop sounds to repeat
live_loop :notes do
play scale(:c, :minor).tick
sleep 0.25
end
live_loop :beat do
sample :bd_haus
sleep 0.5
end
# EFFECTS!!!
live_loop :notes do
with_fx :reverb, room: 0.0, damp: 0, mix: 0.0 do
with_synth :piano do
play scale(:c2, :minor).choose, release: 0.25
end
sleep 0.25
end
end
##| Recreating a Colin Bender arppegio pattern from lockdown day 40:
##| https://youtu.be/iF8Lgj-jzAo?t=9132
##| intervals for readability
root = 0
second = 1
third = 2
fourth = 3
fifth = 4
eighth = 7
tenth = 9
##| the 4 arpeggios
cm = scale(:c5, :minor, num_octaves: 2)
abM = scale(:ab4, :major, num_octaves: 2)
ebM = scale(:eb5, :major, num_octaves: 2)
bdim = chord(:b4, 'm+5', num_octaves: 2)
##| interval pattern for the first 3 arps
indices = [root, third, fifth, third, eighth, fifth, tenth, eighth]
##| the bdim has a slightly different interval pattern
dim_indices = [root, second, third, second, fourth, third, fifth, fourth]
##| setup the scales and intervals list to iterate
scales = [cm, abM, ebM, bdim]
intervals = [indices, indices, indices, dim_indices]
##| constant for the time (0.1 ish is nice but can be too fast for some PCs so change as needed)
note_duration = 0.115
##| loop through the arpeggios!
live_loop :main_arp do
amp = 0.5
s = scales.tick
i = intervals.look
with_fx :reverb, room: 0.8, mix: 0.5 do
16.times do
# get the next note for the current arpeggio
# Note: we specify :note value for `i.tick()` so that we separate
# this tick from the main tick and iterate within the current
# interval recipe for current arppegio
note = s[i.tick(:note)]
##| with_synth :saw do
##| play note - 12, amp: amp, attack: 0.05, sustain: 0.01, release: 0.05
##| end
##| with_synth :saw do
##| play note, amp: amp, attack: 0.025, sustain: 0.01, release: 0.05
##| end
##| with_synth :saw do
##| play note - 12 * 2, amp: amp, attack: 0.01, sustain: 0.01, release: 0.08
##| end
##| with_synth :saw do
##| play note - 12 * 3, amp: amp, attack: 0.025, sustain: 0.01, release: 0.08
##| end
with_synth :saw do
play note - 12 * 4, amp: amp + 0.25, attack: 0.05, sustain: 0.01, release: 0.08
end
##| with_synth :beep do
##| play note, amp: 0.5, attack: 0.05, sustain: 0.05, release: 0.01, pan: rrand_i(-1, 1)
##| end
sleep note_duration
end
end
end
# simple bass drum
live_loop :bass_drum do
with_fx :lpf, cutoff: 100 do
sample :bd_haus, amp: 2
sleep note_duration * 16
end
end
##| chord swells
roots_low = [chord(:c2, :minor), chord(:ab2, :major), chord(:eb2, :major), chord(:b2, 'm+5')]
roots_high = [chord(:c5, :minor), chord(:ab4, :major), chord(:eb5, :major), chord(:b4, 'm+5')]
live_loop :swells do
r1 = roots_low.tick
r2 = roots_high.look
amp = 0.5
with_fx :reverb, room: 0.9, mix: 0.9 do
with_fx :lpf, cutoff: 0 do
##| set attack to glide into the peak volume of each note
with_synth :saw do
play r1, amp: amp, attack: 0.2, sustain: 0.5, release: 1, pan: -0.5
play r1, amp: amp, attack: 0.4, sustain: 0.5, release: 1, pan: 0.5
play r2, amp: amp + 0.5, attack: 0.5, sustain: 0.1, release: 1, pan: 0
end
end
sleep note_duration * 16
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment