Skip to content

Instantly share code, notes, and snippets.

@interstar
Created June 22, 2021 20:44
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 interstar/3563b1164501a12636e2aca75bc66a06 to your computer and use it in GitHub Desktop.
Save interstar/3563b1164501a12636e2aca75bc66a06 to your computer and use it in GitHub Desktop.
# PLAY OUT
#
# MENTUFACTURER
# Original sketch in Sonic Pi of the track
# https://mentufacturer.bandcamp.com/track/play-out
# Note, because of a bug, there's a long section of just drums before the rest kicks in
# MIDI Chord generation
define :oneChord do | tonic, mode, deg |
majorKeyTriads = [:M,:m,:m,:M,:M,:m,:dim]
minorKeyTriads = [:m,:dim,:M,:m,:m,:M,:M]
majorKey7s = [:M7,:m7,:m7,:M7,:dom7,:m7,:halfdiminished]
minorKey7s = [:m7,:halfdiminished,:M7,:m7,:m7,:M7,:dom7]
# First test if deg is actually an array.
# Because if it is, this is a more complex chord item
if deg.class == Array then
# Representation here is [chord-deg, inversion]
# chord-deg is understood as degree to calculate chord,
# inversion is 1 (first inversion), 2 (2nd inversion),
# -1 (first inversion and drop an octave
# -2 (second inversion and drop an octave)
t,m,c = oneChord(tonic,mode,deg[0])
case deg[1]
when 0
newChord = c
when 1
newChord = c[1..10]+[c[0]+12]
when 2
newChord = c[2..10]+[c[0]+12]+[c[1]+12]
when 3
newChord = c[3..10]+[c[0]+12]+[c[1]+12]+[c[2]+12]
when -1
newChord = (c[1..10]+[c[0]+12]).map {|n| n-12 }
when -2
newChord = (c[2..10]+[c[0]+12]+[c[1]+12]).map {|n| n - 12}
when -3
newChord = (c[3..10]+[c[0]+12]+[c[1]+12]+[c[2]+12]).map {|n| n - 12}
else
newChord = c
end
return [t,m,newChord]
end
# Modal interchange (negative numbers major <-> minor)
if deg < 0 then
return oneChord(tonic,(mode=="major") ? "minor" : "major",-deg)
end
case deg
when 1..7 # Simple Triads
root = degree(deg,tonic,mode)
lookup = (mode == "major") ? majorKeyTriads : minorKeyTriads
theChord = chord(root,lookup[deg-1])
when 71..77 # Seventh Chords
deg = deg - 70
root = degree(deg,tonic,mode)
lookup = (mode == "major") ? majorKey7s : minorKey7s
theChord = chord(root,lookup[deg-1])
when 21..27 # Secondary dominants
deg = deg - 20
original_root = degree(deg,tonic,mode)
root = degree(5,original_root,mode)
theChord = chord(root,:dom7)
tonic = root
when 41..47 # augmented (built out of intervals of 4)
deg = deg - 40
root = degree(deg,tonic,mode)
theChord = [root,root+4,root+8]
when 61..67 # Secondary diminished.(1 below 7)
# Diminished 7ths half-step below the chord
deg = deg - 60
croot = degree(deg,tonic,mode)
root = croot -1 # half step down
theChord = chord(root,:dim7)
tonic = root
end
return [tonic,mode,theChord]
end
define :chordSeq do | tonic, mode, degs |
cs = []
degs.each { | deg |
xs = oneChord(tonic,mode,deg)
cs.append(xs)
}
cs
end
define :euclidianTimes do | n1, n2, len |
euclid = spread(n1,n2,rotate: 1)
div = 1.0*n2
div = 1 / div
puts euclid
puts div
count = 1
i = 0
times = []
euclid.each {|e|
if (i > 0) then
if e == true then
# old beat ended
times = times.concat [count*div*len]
count = 1
else
count = count+1
end
end
i=i+1
}
times = times.concat [count*div*len]
#puts times
return times
end
define :eT do | n1, n2, len|
return euclidianTimes(n1, n2, len)
end
use_bpm 100
tonic,mode,c = []
ct = []
cs = []
live_loop :clock do
cs1 = chordSeq(:Eb3,"minor",
[71,[26,-1],76,[-24,-1],74,[23,-2],73,[21,1]])
cs2 = chordSeq(:Eb3,"minor",
[71,[26,-1],76,[-24,-1],74,25,[45,1],[21,2]])
cs = [cs1,cs2].flatten(1)
sample :ambi_lunar_land
cue :progstart
cs.each { | xs |
tonic,mode,c = xs
sleep 4
}
end
with_fx :reverb do
with_synth :piano do
live_loop :piano do
sync :progstart
cs.length.times do
play c, amp: 0.8, decay: 1.8
play c[0]-12, amp: 0.3, decay: 2
sleep 1.5
play c[0]-12, amp: 0.3, decay: 2
sleep 1
play c[2]-12, amp: 0.3, decay: 2
sleep 1
play c[1]-12, amp: 0.3, decay: 2
sleep 0.5
end
end
end
end
with_fx :gverb do
with_synth :tri do
live_loop :riff do
ct = [eT(7,12,4),eT(7,12,4),
eT(4,8,4),eT(4,8,4),
eT(7,12,4),eT(7,12,4),
eT(4,8,4),eT(4,8,4)
]
ct = [ct,ct].flatten()
sync :progstart
ct.each {|t|
n = c.choose+24
play n, amp: 0.1, attack: 0.3, decay: 0.1, sustain: 0.01, sustain_level: 0.3, release: 0.2
sleep t
}
end
end
end
live_loop :drums do
sample :bd_fat
sleep 0.5
sleep 0.5
sample :sn_dolf, amp: 0.7
sleep 0.5
sleep 0.5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment