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 CUBICinfinity/2faa85d3ff46233bec33cc0e74697d77 to your computer and use it in GitHub Desktop.
Save CUBICinfinity/2faa85d3ff46233bec33cc0e74697d77 to your computer and use it in GitHub Desktop.
ice_cave_36.rb
# heptatonic (0–6)
define :ma do
[5,7,9,11,12,14,15]
end
# heptatonic (0–6)
# 12 TET
define :mb do
[5,7,9,10,12,14,15]
end
# heptatonic (0–6)
define :mc do
[5,7,9,10,12.3333333333333333,13.6666666666666667,15.6666666666666667]
end
# decatonic (0–10)
# 18 TET
define :md do
[5, 6.3333333333333333, 7.6666666666666667, 8.3333333333333333,
9.6666666666666667, 11, 12.3333333333333333, 13.6666666666666667,
14.3333333333333333, 15.6666666666666667]
end
# heptatonic (0–6)
define :me do
[5, 6.3333333333333333, 8.3333333333333333, 10.3333333333333333,
12.3333333333333333, 13.6666666666666667, 15]
end
# undecatonic (0–11)
define :mf do
[2, 3.3333333333333333, 4, 5.3333333333333333, 6.6666666666666667, 8,
8.6666666666666667,10, 10.6666666666666667, 12, 12.6666666666666667]
end
define :getnote do |mode, octave, note|
mode[note] + 12 * octave
end
define :rmelody do |mode_size, size|
[(ring 3,4,4,4,4,5).pick(size),
(line 0, mode_size-1, steps: mode_size-1).pick(size)]
end
define :rcmelody do |mode_size, size| # , chord_size, variance|
overtones = (line 0, mode_size-1, steps: mode_size-1).pick(size).to_a
overtone_octaves = (ring 3,4,4,4,4,5).pick(size).to_a
undertones = []
undertone_octaves = []
for i in 0..(size-1) do
interval = choose([-2,-3,-3,-4])
if overtones[i] + interval < 0
undertones = undertones.append(size + overtones[i] + interval)
undertone_octaves = undertone_octaves.append(overtone_octaves[i] - 1)
else
undertones = undertones.append(overtones[i] + interval)
undertone_octaves = undertone_octaves.append(overtone_octaves[i])
end
end
[[overtone_octaves,overtones], [undertone_octaves,undertones]]
end
define :rrhythm do |note_count, beats|
rn = note_count # remaining notes
rb = beats # remaining beats
pd = (1..(beats*2)).map { |b| 1.0*beats/b } # possible durations
cd = [] # chosen durations
while rn > 0 do
while pd.length > 1 && pd[0] + pd[pd.length-1] * (rn - 1.0) > rb
pd = pd.drop(1)
end
d = choose(pd) # new duration
rn = rn - 1
rb = rb - d
cd = cd.append(d)
end
cd.ring.shuffle
end
define :rrhythm2 do |note_count, beats|
rn = note_count # remaining notes
rb = beats # remaining beats
pd = (0..(beats)).map { |b| 1.0*beats/2**b } # possible durations
cd = [] # chosen durations
while rn > 0 do
while pd.length > 1 && pd[0] + pd[pd.length-1] * (rn - 1.0) > rb
pd = pd.drop(1)
end
d = choose(pd) # new duration
rn = rn - 1
rb = rb - d
cd = cd.append(d)
end
cd.ring.shuffle
end
# melody map to mode
# melody[0] is octaves, melody[1] is notes
define :mm do |mode, melody|
if melody[0].length == melody[1].length
(0..melody[0].length()).map { |i| mode[melody[1][i]] + 12*melody[0][i] }
else
raise "octaves and notes need to be the same length."
end
end
# chord melody map to mode
define :cmm do |mode, chords|
output = Array.new(chords[0][0].length) { Array.new(chords.length, 0) }
for i in 0..(chords[0][0].length-1) do
for j in 0..(chords.length-1) do
output[i][j] = mode[chords[j][1][i]] + 12*chords[j][0][i]
end
end
output
end
use_bpm 30
use_synth :dark_ambience
in_thread do
play 2, sustain: 144, amp: 0.5
play 32, sustain: 144, amp: 0.5
end
sleep 7
use_synth :hollow
use_random_seed 1
r1 = rrhythm 8, 6
r2 = rrhythm 8, 6
m1 = rmelody 7, 9
print "A"
play_pattern_timed(mm(ma, m1), r1)
print "B"
play_pattern_timed(mm(mb, m1), r1)
m2 = rmelody 7, 9
print "B2"
play_pattern_timed(mm(mb, m2), r1)
print "C2"
play_pattern_timed(mm(mc, m2), r1)
m3 = rcmelody 7, 9
print "C3"
play_pattern_timed(cmm(mc, m3), r1, amp: 1.5)
m4 = rmelody 10, 9
m5 = rmelody 10, 9
m6 = rcmelody 10, 9
print "D4,D5"
play_pattern_timed(mm(md, m4), r2)
play_pattern_timed(mm(md, m5), r1)
m7 = rcmelody 11, 9
print "E7"
play_pattern_timed(cmm(me, m7), r1, amp: 1.5)
play_pattern_timed(cmm(mf, m7), r1, amp: 1.5)
m9 = rcmelody 10, 9
print "D9"
play_pattern_timed(cmm(md, m9), r2, amp: 1.5)
play_pattern_timed(cmm(mf, m9), r2, amp: 1.5)
play_pattern_timed(mm(mc, m4), r2)
play_pattern_timed(mm(mc, m5), r1)
print "D4,D6"
play_pattern_timed(mm(mf, m4), r2)
play_pattern_timed(cmm(mf, m6), r1, amp: 1.5)
play_pattern_timed(cmm(md, m9), r2.drop_last(1).to_a.append(3), amp: 1.5)
sleep 3
play_pattern_timed(mm(ma, m1), r1, amp: 0.3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment