#Bsong1.rb
# 12 Oct 2017
# Use circle of fifths to cycle through
# all major keys using the property that
# chords 1,4 and 5 are major chords in that key
# and key modulation works well with an adjacent
# key on the circle of fifths
##############
#helper function
def midi2note(n)
nn=note(n)
if nn==nil
return nn
else
nn= note_info(nn)
nnn=nn.to_s.split(":")
mmm= nnn[3].chop
return mmm
end
end # midi2note
######
#Define tempo and note lengths and release fraction
#####
tempo=2.0
#define note timings
whole=1.0
half=whole/2.0
dothalf=half*1.5
quart=half/2.0
dotquart=quart*1.5
eighth=quart/2.0
doteighth=eighth*1.5
sixteenth=eighth/2
###################
#define some midi intervals
octave=note(:C5)-note(:C4)
fourth=note(:f4)-note(:c4)
fifth=note(:g4)-note(:c4)
third=note(:e4)-note(:c4)
one= note(:d4)-note(:c4)
#####
use_synth :fm
with_fx :level, amp: 0.3 do
x=note(:c4)
puts x
j=x
# y=chord(j,:major)
y=[j,j+third,j+fifth]
k=[]
i=0
while i<3
puts midi2note(y[i])
play y[i]
sleep quart
i+=1
end
while j!=72
j+=fourth
if j>(x+octave)then j=j-octave end
# y=chord(j,:major)
y=[j,j+third,j+fifth]
i=0
while i<3
puts midi2note(y[i])
play y[i]
sleep quart
i+=1
end
j+=one
if j>(x+octave)then j=j-octave end
# y=chord(j,:major)
y=[j,j+third,j+fifth]
i=0
while i<3
puts midi2note(y[i])
play y[i]
sleep quart
i+=1
end
k=k.push(midi2note(j))
end
puts k
end