Last active
November 1, 2018 03:22
-
-
Save acharlieh/ae0956efc0a10911e19f8354aa9876d0 to your computer and use it in GitHub Desktop.
SonicPi Playground
This file contains 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
def bars(k) | |
n = chord(k,:sus4) | |
([n[0]]*4 + [n[1]]*2 + [n[0]]*2 + [n[2],n[1]] + [n[0]]*2) | |
end | |
use_bpm 200 | |
use_synth :piano | |
use_debug false | |
set :key, :C2 | |
mystop = false | |
live_loop :set do | |
stop if get[:stop] | |
bars(get[:key]).each_with_index do |key,i| | |
case i | |
when ->(i) { i%2 == 0 } | |
rn = chord(key,:dom7) | |
time = [1,1,1,2.0/3.0,1.0/3.0] | |
notes = [rn[0],rn[1],rn[2],rn[3]-1,rn[2]] | |
when ->(i) { i%2 == 1 } | |
rn = chord(key,:dom7).reverse | |
time = [1,1,2.0/3.0,1.0/3.0,1] | |
notes = [rn[0],rn[1]+2,rn[2]+3,rn[2]+3,rn[3]+4] | |
end | |
notes.zip(time).each_with_index do |(n,t),ni| | |
play n, sustain: t, amp: 2, pan: -0.75 | |
sleep t | |
end | |
end | |
end | |
beatoptions = [] | |
beatoptions += [ [2.0/3, 1.0/3] ] * 2 | |
beatoptions += [ [1.0/3, 2.0/3] ] * 0 | |
beatoptions += [ [1.0/3] * 3 ] * 0 | |
beatoptions += [ [1] ] * 5 | |
live_loop :improv, auto_cue: false, sync: "/live_loop/set" do | |
stop if get[:stop] | |
bars(get[:key]).each_with_index do |key,i| | |
nbeats = 4 | |
measure = [] | |
while nbeats > 0 | |
n = (1..nbeats).to_a.sample | |
if (n == 1) | |
measure += beatoptions.sample | |
else | |
measure += [ n ] | |
end | |
nbeats -= n | |
end | |
rn = scale(key+12,:blues_major, num_octives: 2) | |
notes = measure.size.times.collect { rn.sample } | |
notes.zip(measure.shuffle).each do |(note,time)| | |
play note, sustain: time, amp: 2, pan: 0.75 | |
sleep time | |
end | |
end | |
end | |
set :stop, mystop | |
stop unless mystop | |
sync "/live_loop/set" | |
key = bars(get[:key]).first | |
rn = scale(key,:blues_minor).reverse | |
play_pattern_timed rn.take(2), [1,2], amp: 2, pan: 0.75 | |
play_pattern_timed rn.drop(2).take(2), [1,2], amp: 2, pan: -0.75 | |
rn.drop(4).each do |note| | |
play note, sustain: 1, amp: 2, pan: 0.75 | |
play note, sustain: 1, amp: 2, pan: -0.75 | |
sleep 1 | |
end | |
play key, sustain: 2, amp: 2, pan: 0.75 | |
play key, sustain: 2, amp: 2, pan: -0.75 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment