Skip to content

Instantly share code, notes, and snippets.

@alptugan
Last active June 4, 2023 12:21
Show Gist options
  • Save alptugan/8aa987492e3e3041078f71d8ec5d045f to your computer and use it in GitHub Desktop.
Save alptugan/8aa987492e3e3041078f71d8ec5d045f to your computer and use it in GitHub Desktop.
Sonic Pi Cheat Sheet
So, let’s flip a coin: if it’s heads, play a drum, if it’s tails, play a cymbal. Easy. We can emulate a coin flip with our one_in function (introduced in the section on randomness) specifying a probability of 1 in 2: one_in(2). We can then use the result of this to decide between two pieces of code, the code to play the drum and the code to play the cymbal:
loop do
if one_in(2)
sample :drum_heavy_kick
else
sample :drum_cymbal_closed
end
sleep 0.5
end
s = play 60, release: 5
sleep 0.5
control s, note: 65
sleep 0.5
control s, note: 67
sleep 3
control s, note: 72
with_fx :reverb do |r|
play 50
sleep 0.5
control r, mix: 0.7
play 55
sleep 1
control r, mix: 0.9
sleep 1
play 62
end
define :foo do
play 50
sleep 1
play 55
sleep 2
end
2.times do
foo
end
// Send parameters
define :chord_player do |root, repeats|
repeats.times do
play chord(root, :minor), release: 0.3
sleep 0.5
end
end
chord_player :e3, 2
sleep 0.5
chord_player :a3, 3
chord_player :g3, 4
sleep 0.5
chord_player :e3, 3
# FX
live_loop :guit do
with_fx :echo, mix: 0.5, phase: 0.25 do
sample :guit_em9, rate: 0.5
end
sleep 8
end
with_fx :echo, phase: 0.125 do
play 50
sleep 0.5
sample :elec_plip
sleep 0.5
play 62
end
// Nested FX
with_fx :reverb do
with_fx :echo, phase: 0.5, decay: 8 do
play 50
sleep 0.5
sample :elec_blup
sleep 0.5
play 62
end
end
# Template Loop
live_loop :loopName do
sample :bd_haus, attack:0.5 ,rate:0.5, amp: 30
sleep 0.5
end
use_random_seed 40
5.times do
play rrand(50, 100)
sleep 0.5
end
// Sync live_Loops
live_loop :foo do
play :e4, release: 0.5
sleep 0.5
end
live_loop :bar do
sync :foo
sample :bd_haus
sleep 1
end
choose([60, 65, 72])
loop do
play choose([60, 65, 72])
sleep 1
end
//
loop do
sample :loop_amen
sleep sample_duration :loop_amen
end
# play note
# properties :
# amp:1
# pan-> pan: -1, : pan:1 , pan:0
play :C4
# play sharp notes
play :Cs4
# play flat(bemol) notes
play :Cb4
/////// Chords
play chord(:E3, :minor), release: 0.3
chord(:E3, :m7)
chord(:E3, :minor)
chord(:E3, :dim7)
chord(:E3, :dom7)
play_pattern chord(:c4, :major7)
play_pattern_timed chord(:E3, :m7), 0.25
play_pattern_timed chord(:E3, :m13), [0.25, 0.5]
// Scales
play_pattern_timed scale(:c3, :major, num_octaves: 3), 0.125, release: 0.1
require "/Applications/Sonic Pi.app/app/server/sonicpi/lib/sonicpi/osc/osc"
t = OSC::UDPClient.new('192.168.1.41',12345)
t.send("/bass",343)
require 'socket'
t = UDPSocket.new
puts t
t.send "dddd",2, 'localhost', 12345
#t.send('localhost', 12345,"/hello",123)
# SAMPLE
# props
# rate: 1
# start: 0.4,
# finish: 0.6
sample : ambi_choir, rate : 1 ,start: 0.4, finish: 0.6
# local sample playing
sample "/Users/sam/Desktop/my-sound.wav"
play rrand(50, 95)
// Use default sample duration as loop time
loop do
sample :loop_amen
sleep sample_duration :loop_amen
end
s = play 60, release: 5, note_slide: 0.1
sleep 0.5
control s, note: 65
sleep 0.5
control s, note: 67
sleep 3
control s, note: 72
with_fx :wobble, phase: 1, phase_slide: 5 do |e|
use_synth :dsaw
play 50, release: 5
control e, phase: 0.025
end
# SYNTHS
use_synth :saw
use_synth :tb303
loop do
play 50, release: 0.1, cutoff: rrand(60, 120)
sleep 0.125
end
use_synth :tb303
loop do
play choose(chord(:E3, :minor)), release: 0.3, cutoff: rrand(60, 120)
sleep 0.25
end
// play with smaples and
define :my_loop do
use_synth :hoover
sample :drum_bass_hard, rate: rrand(0.1, 20)
play choose(chord(:e3, :major)), release: 0.2, cutoff: rrand(60, 130)
sleep 0.25
end
in_thread(name: :looper) do
loop do
my_loop
end
end
/// Set 2
live_loop :foo do
with_fx :echo, mix: 0.8, phase: 0.225 do
use_synth :mod_tri
play :e4, release: 0.5, amp:0.5
end
sleep 0.5
end
live_loop :bar do
sync :foo
sample :bd_haus
sleep 1
end
live_loop :foo2 do
sync:foo
sample :loop_garzul
use_synth :prophet
play :c1, release: 8, cutoff: rrand(70, 130)
sleep 8
end
/// Random streams
live_loop :rand_surfer do
use_synth :dsaw
notes = (scale :e2, :minor_pentatonic, num_octaves: 2)
16.times do
play notes.choose, release: 0.1, cutoff: rrand(70, 120)
sleep 0.125
end
end
in_thread do
loop do
sample :drum_heavy_kick
sleep 1
end
end
loop do
use_synth :fm
play 40, release: 0.2
sleep 0.5
end
// Naming threads
in_thread(name: :amen) do
loop do
sample :loop_amen
sleep sample_duration :loop_amen
end
end
// Sync threads
in_thread do
loop do
cue :tick
sleep 1
end
end
in_thread do
loop do
sync :tick
sample :drum_heavy_kick
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment