Skip to content

Instantly share code, notes, and snippets.

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 AlexandreRangel/73738b7699dd7ec9bc9dd5f0cbab7326 to your computer and use it in GitHub Desktop.
Save AlexandreRangel/73738b7699dd7ec9bc9dd5f0cbab7326 to your computer and use it in GitHub Desktop.
Sonic Pi music code
# the computer is singing and playing based on rules since the beggining of the night - v18
# Alexandre rANGEL www.quasecinema.org Sonic Pi 2.9 20-Apr-2016
myBPM = 72
use_bpm myBPM
c1 = c2 = q1 = q2 = k1 = k2 = 0
set_volume! 0.75
use_random_seed (Time.new.year / Time.new.month / Time.new.day * Time.new.hour * Time.new.min * Time.new.sec)
# http://www.freesound.org/people/digifishmusic/sounds/44928 and http://www.freesound.org/people/toiletrolltube/sounds/179881
# download samples, rename to vocal_la_c4, cello and hatMetal and put it in your path, defined here:
use_sample_pack_as '/Users/rangel/pisamples', :mySamples
load_samples [:mySamples__vocal_la_c4,:mySamples__cello,:bd_gas,:bd_klub,:bd_fat,:bd_808]
live_loop :metro do ###############
clock = tick(:metro)
bar = clock / 4
puts "bar : #{bar}"
puts (ring "1 |","2 | |","3 | | |","4 | | | |")[clock]
tick_clock = tick
sleep 1
end #metro
with_fx :compressor, slope_below: 1.2, slope_above: 0.8, mix: 0.9 do
live_loop :vocal do ##############
with_fx :compressor, slope_below: 0.9, slope_above: 0.5, mix: 0.8 do
with_fx :flanger, phase: [1,4,8,16,21].choose do
with_fx :slicer, phase: [2,1,0.5,0.25].choose, phase_slide: 0.25/2 do
with_fx :echo, phase: [2,4,8].choose do
with_fx :gverb, mix: rrand(0.5,0.9) do
with_bpm [myBPM/4,myBPM/2,myBPM].choose do
with_fx :pitch_shift, pitch: rrand(-52,8), pitch_slide: 1.5, window_size: rrand(0.001,0.01) do
sample :mySamples__vocal_la_c4, rate: [-1,1,1,0.5,2].choose, amp: rrand(2,4.5)/2
sleep [3,1,2,2,4,4,8].choose
end
sleep [1,2,4].choose
with_fx :pitch_shift, pitch: rrand(-32,8), pitch_slide: 0.25, window_size: rrand(0.001,0.003) do
sample :mySamples__vocal_la_c4, rate: [-1,1,1,0.5,2].choose, amp: rrand(2,4)/2
sleep [8,2,2,4,4,1].choose
end
sleep [1,2,4].choose
with_fx :pitch_shift, pitch: rrand(-16,8), pitch_slide: 0.5, window_size: rrand(0.0001,0.0005) do
sample :mySamples__vocal_la_c4, rate: [-1,1,1,0.5,2].choose, amp: rrand(1,2)
sleep [1,2,2,4,4,8].choose
end
end
end
end
end
end
end
sleep 8 if one_in(12)
end
live_loop :cello do ################
x = (1.0/8)*rrand(1,7)
with_fx :slicer, phase: [0.25,0.5,0.5,0.5,0.75,1,1,1,2].choose, slope_down: [0,0,0.25,0.5].choose do
with_fx :pitch_shift, pitch: rrand(-8,8), window_size: rrand(0.0001,0.001) do
sample :mySamples__cello, amp: rrand(5,7.7), start: x, finish: x + (1.0/8), rate: [-0.5,0.5].choose, attack: 0.1, release: 0.2
end
x = (1.0/16)*rrand(1,15)
with_fx :pitch_shift, pitch: rrand(-24,8), window_size: rrand(0.001,0.01) do
sample :mySamples__cello, amp: rrand(5,7.7), start: x, finish: x + (1.0/16), rate: [-1,1,1].choose, attack: 0.1, release: 0.2
end
x = (1.0/32)*rrand(1,31)
with_fx :pitch_shift, pitch: rrand(-16,8), window_size: rrand(0.001,0.01) do
sample :mySamples__cello, amp: rrand(5,7.7), start: x, finish: x + (1.0/32), rate: [-1,1,1].choose, attack: 0.05, release: 0.1
end
sleep [1,2,4].choose
end
end
sleep 8 #delay start
live_loop :texture1 do ###############
with_fx :pitch_shift, windows_size: rrand(0.01,0.1), pitch: [-32,-24,16,-12,-8,-4].choose do
with_fx :pitch_shift, windows_size: rrand(0.01,0.1), pitch: [-32,-24,-16,-12,-8,-4].choose do
with_fx :krush, res: (ring 0.01,0.2,0.01,0.3)[tick/16] do
with_fx :wobble, phase: [0.5,1,2,4,4,8,8,16,16,32,64,128].choose do
use_synth :tb303
play (([60,64,68].choose) - ([8,16,24,32].choose)), attack: 0, sustain: 2, release: [6,14].choose, amp: 1, pan: 0.75
end
end
end
end
sleep 4
sleep 8 if one_in(12)
end
sleep 8 #delay start
live_loop :texture2 do #############
with_fx :pitch_shift, windows_size: rrand(0.01,0.1), pitch: [-32,-24,16,-12,0,4,8,12].choose do
with_fx :pitch_shift, windows_size: rrand(0.01,0.1), pitch: [-32,-24,-16,-12,0,4,8,12].choose do
with_fx :krush, res: (ring 0.01,0.18,0.01,0.24)[tick/16] do
with_fx :wobble, phase: [16,16,32,64,128,256].choose do
use_synth :prophet
play (([60,64,68].choose) - ([8,16,24,32].choose)), attack: 4, sustain: 2, release: 28, amp: rrand(3,8), pan: -1
use_synth :pulse
play (([60,64,68,72].choose) + ([8,16,24,32].choose)), attack: 4, sustain: 2, release: 28, amp: rrand(3,8), pan: -1
if one_in(2)
use_synth :beep
8.times do
play ( ([60,64,68,72].choose) + ([8,16,24,32].choose) ), attack: 0.1, sustain: 0.2, release: 0.1, amp: 3, pan: -1
sleep 0.25
end #for
end #if
end
end
end
end
sleep 2
with_fx :pitch_shift, windows_size: rrand(0.01,0.1),
pitch: [-32,-24,16,-12,0,4,8,12].choose do
with_fx :pitch_shift, windows_size: rrand(0.01,0.1), pitch: [-32,-24,-16,-12,0,4,8,12].choose do
with_fx :krush, res: (ring 0.01,0.18,0.01,0.24)[tick/16] do
with_fx :wobble, phase: [4,8,8,16,16,32,64,128,256].choose do
use_synth :prophet
play ( ([60,64,68].choose) - ([8,16,24,32].choose) ), attack: 4, sustain: 2, release: 28, amp: rrand(2,5), pan: +1
use_synth :pulse
play ( ([60,64,68,72].choose) + ([8,16,24,32].choose) ), attack: 4, sustain: 2, release: 28, amp: rrand(2,5), pan: +1
if one_in(7)
use_synth :beep
8.times do
play ( ([60,64,68,72].choose) + ([8,16,24,32].choose) ), attack: 0.1, sustain: 0.2, release: 0.1, amp: 10, pan: 0.9
sleep 0.25
end #for
end #if
end #wobble
end #krush
end #pitch
end #pitch
sleep 16
sleep 8 if one_in(12)
end
sleep 4 #delay start
live_loop :clap do ##############
with_fx :echo, phase: 0.1, mix: rrand(0.5,0.7) do
with_fx :krush, mix: [0.444,0.5].choose do
sample :drum_snare_hard, rate: rrand(2,2.1), amp: 0.84
sample :drum_snare_soft, rate: rrand(1,1.1), amp: 1.2
end
end
sleep (ring 8,4)[tick_clock/4]
end
sleep 18 #delay start
live_loop :beep do ##############
with_fx :echo, phase: (ring 2,0.5,0.25,0.5,3)[tick_clock/4] do
with_fx :pitch_shift, window_size: [0.01,0.01,0.01,0.02,0.04,0.001].choose, pitch: [-16,-8,0,8,12,24].choose do
sample :bd_pure, rate: [4,8].choose, amp: 3
sample :bd_pure, rate: rrand(5,10), amp: 1.333
use_synth :noise
play 60, attack: 0.1, release: rrand(0.7,0.9), pan: [-0.75,0.75].choose, pan_slide: [0.1,0.25,0.5,1].choose, amp: rrand(0.55,0.60) *0.3
end
end
sleep (ring 8,2,2,16,8,8,4,2,2,2,1,0.5,0.25,32)[tick_clock/64]
use_synth :beep
8.times do
play [:g1,:c2,:c3,:g4].choose, amp: [0,0.4,0.6,0.7,0.8,0.9,0.7].choose + 0.54, attack: 0.1, release: [0.1,2].choose
play chord(:c2, :minor).choose, amp: [0,0.4,0.6,0.7,0.8,0.9,0.7].choose + 0.57, attack: 0.1, release: [0.1,2].choose
sleep 0.5
end
8.times do
play [:g1,:g2,:g3,:g4].choose, release: 2, amp: [0,0.4,0.6,0.7,0.8,0.9,1.0].choose + 0.333, attack: 0.1, release: [0.1,2].choose
sleep 0.5
end
sleep (ring 8,2,2,16,8,8,4,2,2,2,1,0.5,0.25,32)[tick_clock/64]
sleep 8 if one_in(12)
end #beep
sleep 8
live_loop :hat do ###############
with_fx :lpf, cutoff: [120,125,130].choose, cutoff_slide: [0.5,1,2].choose, mix: rrand(0.3,0.6) do
use_synth :cnoise
with_fx :krush, mix: rrand(0.4,0.6) do
play 60, attack: 0.01, sustain: 0.5, release: (ring 2,1.8,2,0.2,2,1.8,2,0.8,0.8,0.8)[tick_clock], amp: (ring 0.07,0.09,0.11)[tick_clock/2] + rrand(0.2,0.444)
end #lpf
end
sleep (ring 16,8,4,4,4,4,4,4,4,4,4,4)[tick_clock/4]
sleep 8 if one_in(12)
end #hat
end #compressor
sleep 8.5 #offbeat from hat #############
live_loop :kick do
with_bpm 72/2 do
y = (ring 0.5,0.25,0.5,0.25,1.0/8,0.5,0.25,0.25,0.25,1.0/16,1.0/16,1.0/8,1.0/4,1.0/8,1.0/[8,4].choose)[k1/2]
with_fx :krush, mix: rrand(0.5,0.7) do
with_fx :echo, phase: (ring 0.25,0.5,2,16,4,8)[k1], decay: 1, mix: 0.6 do
sample [:bd_808,:bd_fat].choose, rate: rrand(0.93,0.98), amp: 2.2
sample :bd_haus, rate: rrand(0.9,0.94), amp: rrand(1.4,1.6) * 1.3
sleep y/2
sample :bd_fat, rate: rrand(0.93,0.98), amp: 2.0
sample :bd_gas, rate: rrand(0.9,0.94), amp: rrand(0.8,1.0) if one_in(4)
sleep y/2
sleep 1 if one_in([6,9].choose)
k1 = k1 + 1
end
end
end
sleep 8 if one_in(12)
end #kick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment