Skip to content

Instantly share code, notes, and snippets.

@rbnpi
Last active Jun 9, 2021
Embed
What would you like to do?
starwars.rb The StarWars theme arranged for Sonic Pi, based on a version by Max Loh http://www.maxloh.com/sheetmusic/ Hear it at https://soundcloud.com/rbnman/starwars
#Star Wars theme arranged for Sonic Pi by Robin Newman December 2015
#Based on arrangement by Max Loh www.maxloh.com featured on youtube
use_synth :dsaw
s=0.11 #adjust tempo here
sq=1*s #note timings
sq7=4*sq/7.0 #for semiquaver run
q=2*sq
qt=2/3.0*q #for triplets
c=2*q
cd=3*q
m=4*q
md=6*q
b=8*q
semivol=0.3 #volume settings
full=1
soft=0.5
define :ldc do |dlist| #used to calculate part lengths in crotchets to make it easy to set delays
dur=0
dlist.each do |d|
dur+=d
end
return (dur/c).round
end
#bass rhythm part
co= [:c2, :c4]
cor=[co,co,co,co,:r,co,:r]
cor4=cor[0..4]
#puts cor4 #for debugging
lhn=[co,:r,co,:r]+cor*7+cor4*2+[:r]
dor=[qt,qt,qt,q,q,q,q]
dor4=dor[0..4]
lhd=[q,q,q,q]+dor*7+dor4*2+[q]
lhn=lhn.ring #put into rings to allow multiple indexed plays
lhd=lhd.ring
puts "data checks part lengths and durations"
puts "lh"
puts lhn.length
puts lhd.length
#define some chords
ch1=[:ab3,:db4,:f4,:ab4]
ch2=[:f3,:ab3,:db4,:f4]
ch3=[:b3,:e4,:gs4,:b4]
ch4=[:bb3,:eb4,:g4,:bb4]
rhn=[:r,ch1,ch1,ch2,:r,ch1,ch1,ch2,:r,ch3,ch3,ch4,ch3,ch4,ch1,:r,[:c5,:c6],:b5,:a5,:g5]
rhd=[b+cd,q,md,q,m,q,md,q,m,q,md+m,qt,qt,qt,q,cd,sq,sq,sq,sq]
rhn=rhn.ring
rhd=rhd.ring
puts "rh"
puts rhn.length
puts rhd.length
ra=[full]*16+[soft]*4 #volume part
ra=ra.ring
puts "ra vol length"
puts ra.length
r1=[:c5,:b5,:a5,:g5];r2=[:a6,:g6,:f6,:e6];r3=[:g5,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b6,:g6,:cb7],[:ab5,:f6,:ab6],\
:r, [:g5,:eb6,:g6],[:f5,:d6,:f6],[:eb5,:c6,:eb6],[:d5,:b5,:d6],:r,[:c5,:a5,:c6],[:g5,:d5,:g6]]
rhn4=rhn4.ring
rhd4=[cd,q,q,q,q,q,qt,qt,qt,qt*2,qt,c,qt*2,qt,q,q,q,sq,sq,q,q,q,sq,sq,b]
rhd4=rhd4.ring
rhn4b=[:r,:c6,:b5].ring
rhd4b=[12*c,m,m].ring
lhn4=[[:f1,:f2],[:f2,:b2],[:f2,:c3],[:f2,:d3],[:f2,:e3],[:f2,:f3],[:f2,:d3,:g3],:r,[:d2,:d3],[:eb2,:eb3],[:f2,:f3],:r,\
[:g2,:g3],[:ab2,:ab3],[:bb2,:bb3],[:c3,:c4],:r,[:d3,:d4],[:g3,:g4],[:g3,:g4],[:g2,:g3],[:g3,:g4],[:g3,:g4],[:g3,:g4]]
lhd4=[c,c,c,c,c,c,c,c,q,q,q,sq,sq,q,q,q,sq,sq,q,q,q,q+qt,qt,qt]
lhd4=lhd4.ring
finalern=[[:c4,:g4,:c5,:e5,:g5,:c6,:c7], [:c4,:g4,:c5,:e5,:g5,:c6,:c7]]
finalerd=[q,q+7*c]
finaleln=[[:c2,:e2,:g2,:c3],[:c2,:e2,:g2,:c3]]
finaleld=[q,q+7*c]
puts "rh4"
puts rhn4.length #length and duration checks for debugging and setting intersection delays
puts rhd4.length
puts "lh4"
puts lhn4.length
puts lhd4.length
puts "part durations in crotchets"
puts ldc(rhd)
puts ldc(rhd2)
puts ldc(rhd3)
puts ldc(rhd4)
#now start playing
with_fx :reverb,room: 0.8 do
2.times do #play twice through. Can set higher if desired or loop for continuous
live_loop :lh do
tick
play lhn.look,release: lhd.look,amp: full
sleep lhd.look
stop if look%lhd.length==lhd.length - 1 # % (modulus) allows for replay without resetting tick
end
live_loop :rh do
tick
play rhn.look,release: rhd.look,amp: ra.look
sleep rhd.look
stop if look%rhd.length==rhd.length - 1
end
sleep 27*c
live_loop :rh2 do
tick
play rhn2.look,release: rhd2.look,amp: soft
sleep rhd2.look
stop if look%rhd2.length==rhd2.length - 1
end
live_loop :lh2 do
tick
play lhn2.look,release: lhd2.look,amp: soft
sleep lhd2.look
stop if look%lhd2.length==lhd2.length - 1
end
sleep 15*c
live_loop :rh3 do
tick
play rhn3.look,release: rhd3.look,amp: soft
sleep rhd3.look
stop if look%rhd3.length==rhd3.length - 1
end
live_loop :lh3 do
tick
play lhn3.look,release: lhd3.look,amp: la3.look
sleep lhd3.look
stop if look%lhd3.length==lhd3.length - 1
end
sleep 48*c
live_loop :rh4 do #make more sustained from here on in, using sustain and release
tick
play rhn4.look,sustain: rhd4.look*0.9,release: rhd4.look*0.1,amp: full
sleep rhd4.look
stop if look%rhd4.length==rhd4.length - 1
end
live_loop :lh4 do
tick
play lhn4.look,sustain: (lhd4.look)*0.9,release: (lhd4.look)*0.1,amp: full
sleep lhd4.look
stop if look%lhd4.length==lhd4.length - 1
end
live_loop :rh4b do #extra two notes in rh part
tick
play rhn4b.look,sustain: (rhd4b.look) * 0.9, release: (rhd4b.look) * 0.1,amp: full
sleep rhd4b.look
stop if look%rhd4b.length==rhd4b.length - 1
end
sleep 16*c
end
live_loop :finalel do #plays final chords
tick
play finaleln.look,sustain: (finaleld.look)*0.9,release: (finaleld.look)*0.1,amp: full
sleep finaleld.look
stop if look==finaleld.length - 1
end
live_loop :finaler do #plays final chords
tick
play finalern.look,sustain: (finalerd.look)*0.9,release: (finalerd.look)*0.1,amp: full
sleep finalerd.look
stop if look==finalerd.length - 1
end
end
@mvict
Copy link

mvict commented May 12, 2021

Impressive!!! Thank you for sharing

Two little syntax errors
Missing comma in line 91:
better:
lc1=[:c2,:g2,:e3,:g3];lc2=[:f2,:c3,:a3,:c4];lc1p=[:c2,:g2,:e3,:g3,:c4];lc3=[:bb2,:f3];lc4=[:g2, :f3]
And ] misplaced in line 93:
better:
lc9=[:g3,:f4,:c4,:a3,:c4];lc10=[:f4,:c4,:a3,:c4]*3

Loading

@rbnpi
Copy link
Author

rbnpi commented May 12, 2021

Thanks @mvict I've updated line 91. I need to look more closely at line 93. I think it may be correct. A chord followed by some separate notes. However it is so long since I wrote this (6 years) it may take some time to checkout.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment