Skip to content

Instantly share code, notes, and snippets.

@AlexandreRangel
Last active June 10, 2017 03:32
Show Gist options
  • Save AlexandreRangel/d0f336c52cfc2366c882 to your computer and use it in GitHub Desktop.
Save AlexandreRangel/d0f336c52cfc2366c882 to your computer and use it in GitHub Desktop.
Sonic Pi music code
# Alexandre rANGEL - www.quasecinema.org
# Leo and Aquarius v13 / 24-Jan-2016
# Sonic Pi 2.12
use_bpm 136
startClock = 200 # 0 to start song at beginning
clock = 0 # global var
bar = 0 # global var
set_volume! 1.0
t = Time.new
use_random_seed = 3 #(t.year + t.month + t.day + t.hour + t.min + t.sec)
# download sample, rename to bell.wav and put in your samples folder
# http://freesound.org/people/ivanbailey/sounds/41343/
sampleBell = '/Users/rangel/Documents/SamplesPi/bell.wav' # your path here
load_sample sampleBell
#############################################################
# use_synth :beep # countdown sync
# play 90, attack: 0, sustain: 1, release: 0, amp: 2
# sleep 2
# play 90, attack: 0, sustain: 1, release: 0, amp: 2
# sleep 2
# play 90, attack: 0, sustain: 1, release: 0, amp: 2
# sleep 4
#############################################################
live_loop :metro do
cue :metro
sleep 0.5
clock = startClock + tick
bar = clock / 4
puts "bar : #{bar}"
puts (ring "1 |","2 | |","3 | | |","4 | | | |")[clock]
end #metro
with_fx :compressor, pre_amp: 1.1, threshold: 0.5, slope_below: 1.5, mix: 0.75 do
sample sampleBell
#############################################################
live_loop :track5 do #ambient
with_fx :pitch_shift, pitch: [-24,-12,-12,0,0,0,0,8,12,12,16,24].choose,
window_size: rrand(0.001,0.2), time_dis: (rrand(0.01,0.1) / 2) do
with_fx :distortion, distort: rrand(0.3,0.666), mix: rrand(0.5,0.9) do
with_fx :echo, phase: [1,2,4,4,4,8,8,16].choose, reps: [1,2,3].choose,
mix: rrand(0.4,0.99) do
with_fx :compressor, pre_amp: (rrand(1.0,1.5) * 1.0),
threshold: 0.4, slope_above: 0.266, relax_time: 2 do
sample sampleBell,
start: rrand(0.025,0.086), pitch: [-12,-8,-4,-2,0,2,4,8,12].choose,
window_size: rrand(0.01,0.2), amp: rrand(0.9,1.1) * 1.1, norm: [0,0].choose,
pan: rrand(-0.8,0.8), pan_slide: [1,2,4,8,16].choose,
beat_stretch: rrand(4,160), attack: [1,2,4,4,8,8,16].choose
#[32,32,32,64,128,256,512].choose
end
end
end
end
sleep [2,4,4,4,4,4,8,8,8,16].choose
end
sleep 8
sample sampleBell, rate: -2
sleep 4
#############################################################
live_loop :track1 do #kick
sample :bd_klub, amp: ring(0.8,1.2,0.8,1.6)[tick] * [1.2,1.3].choose
sample :bd_haus, amp: ring(0.8,0.3,0.8,0.5)[tick] * [1.2,1.3].choose
if one_in(24)
sample sampleBell, rate: [-4,-2,-2,-1,-1,1,2,4].choose, amp: 0.75
end # if
sleep 1
sleep 15 if one_in(256)
end
#############################################################
live_loop :track2 do #hat
use_synth [:pnoise].choose
with_fx :pitch_shift, pitch: 16, window_size: [rrand(0.0001,0.001),rrand(0.0001,0.1)].choose do
play :C3, amp: ring(0.3,0.2,0.3,0.33)[tick] * rrand(0,0.3), release: [1,2,3,4].choose
end
with_fx :pitch_shift, window_size: [rrand(0.0001,0.001),rrand(0.0001,0.1)].choose do
play :C3, amp: ring(0.3,0.2,0.3,0.33)[tick] * 0.4
end
sleep 1.5
sleep 1.5 * 4 if one_in(128)
end
#############################################################
end # compressor
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment