Skip to content

Instantly share code, notes, and snippets.

@interstar
Last active July 9, 2022 00:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save interstar/508e6e480253c01aeb2fb81618bbe634 to your computer and use it in GitHub Desktop.
Save interstar/508e6e480253c01aeb2fb81618bbe634 to your computer and use it in GitHub Desktop.
Sonic Pi Chord Generation 2 (now with secondary dominants and modal interchange)
# MIDI Chord generation
# Now with modal interchange and secondary dominants
# See https://www.youtube.com/watch?v=3yryQbRgsGo
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]
# 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)
end
return theChord
end
define :chordSeq do | tonic, mode, degs |
cs = []
degs.each { | deg |
theChord = oneChord(tonic,mode,deg)
cs.append [tonic,mode,theChord]
}
cs
end
use_bpm 96
live_loop :piano do
#cs = chordSeq(:C3,"minor",[1,76,4,75, 5,7,74,5,
# 1,76,4,75, 5,7,74,1])
#cs = chordSeq(:C3,"major",[1,24,4,26,6,25,5,21])
cs = chordSeq(:C3,"major",[
71,6,23,73,
4,-4, 75, 75,
-76, -73, 1, 1
])
cs.each {| xs |
tonic,mode,c = xs
c.each {|cn| midi_note_on cn, 90, channel: 1,
port: "loopbe_internal_midi_1" }
sleep 2
c.each {|cn| midi_note_off cn, channel: 1,
port: "loopbe_internal_midi_1"}
n = c.choose+12
midi n, 90, channel: 1,
port: "loopbe_internal_midi_1"
sleep 0.5
midi n, 90, channel: 1,
port: "loopbe_internal_midi_1"
sleep 0.5
n = c.choose+24
midi n, 90, channel: 1,
port: "loopbe_internal_midi_1"
sleep 0.5
midi scale(tonic,mode).choose+24, 80,
channel: 1,
port: "loopbe_internal_midi_1"
sleep 0.5
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment