Created
April 6, 2015 12:33
-
-
Save rbnpi/1f024a6914a4a985901f to your computer and use it in GitHub Desktop.
Sonic Pi and Minecraft Royal Fireworks Music. Load BOTH programs into SEPARATE workspaces. Run SP-HandelFireworksMinuet.rb program first, then SP-MinecraftFirework.rb and switch immediately to Minecraft to view the display. Accompanying article at http://rbnrpi.wordpress Link for required samples is http://r.newman.ch/rpi/Fireworks.zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Handel's Firework Music Minuet coded by Robin Newman, April 2015 | |
#requires version 2.5dev or later | |
#used to accompany SP/Minecraft Fireworks program (in a different workspace) | |
#from which it is cuded to start. | |
use_debug false | |
use_sample_pack_as '/home/pi/samples/Fireworks',:fireworks #adjust location as necessary | |
#first deal with selecting and setting up the samples | |
inst0=:fireworks__trumpet_cs5 | |
samplepitch0=:cs5 | |
inst1=:fireworks__tenor_trombone_as3 | |
samplepitch1=:as3 | |
inst2=:fireworks__bass_trombone_as2 | |
samplepitch2=:as2 | |
#preload all the samples | |
load_flag=0 | |
if sample_loaded? inst0 then #check if sample already loaded | |
load_flag=1 | |
end | |
load_samples [inst0,inst1,inst2] | |
if load_flag==0 then #samples not loaded so allow time | |
sleep 3 | |
end | |
#put the sample names and pitches into an array i | |
i=[[inst0,samplepitch0],[inst1,samplepitch1],[inst2,samplepitch2]] | |
#define variables that need to be used globally | |
s=0 #note duration scale factor | |
#this function plays the sample at the relevant pitch for the note desired | |
#the note duration is used to set up the envelope parameters | |
define :pl do |inst,samplepitch,nv,dv,vol=1,st=0| | |
shift=note(nv)-note(samplepitch) | |
#start: param used with very small value to give more immediate attack for some samples | |
sample inst,rate: (pitch_ratio shift),sustain: 0.8*dv,release: 0.2*dv,amp: vol,start: st | |
end | |
#this function plays an array of notes and associated array of durations | |
#also uses sample name (inst), sample normal pitch,sample start and shift (transpose) parameters | |
define :plarray do |inst,samplepitch,narray,darray,shift=0,vol=1,st=0| | |
narray.zip(darray) do |nv,dv| | |
if nv != :r | |
pl(inst,samplepitch,note(nv)+shift,dv*s,vol) | |
end | |
sleep dv*s | |
end | |
end | |
#set_bpm sets bpm required adjusting note duration variables accordingly | |
define :set_bpm do |n| | |
s=1.0/8*60/n.to_f | |
end | |
#set relative note duration variables | |
dsq = 1.0 #must be float as divided later | |
sq = 2 | |
sqd = 3 | |
q = 4 | |
qt = 2.0/3*q | |
qd = 6 | |
qdd = 7 | |
c = 8 | |
cd = 12 | |
cdd = 14 | |
m = 16 | |
md = 24 | |
mdd = 28 | |
b = 32 | |
bd = 48 | |
#set up the part lists | |
n1=[:bb4,:f4,:d4,:bb3,:f4,:bb4,:bb4,:d5,:bb4,:bb4,:bb4,:c5,:bb4,:c5,:c5,:d5,:c5,:d5,:eb5,:d5,:c5] | |
d1=[m,c,c,c,c,c,c,c,md,c,q,q,c,c,q,q,c,c,c,c,md] | |
n2=[:f4,:r,:f3,:r,:f4,:d4,:f4,:f4,:d4,:f4,:d4,:f4,:d4,:f4,:f4,:f4,:f4,:f4,:f4,:f4] | |
d2=[m,c,m,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,md] | |
n3=[:d5,:r,:bb4,:f4,:d5,:bb4,:bb4,:d5,:bb4,:bb4,:d5,:bb4,:bb4,:a4,:a4,:bb4,:a4,:bb4,:c5,:bb4,:a4,:c5,:a4] | |
d3=[m,c,m,c,c,c,c,c,c,c,c,c,c,c,q,q,c,c,c,c,c,c,c] | |
n4=[:bb2,:r,:bb3,:f3,:d3,:bb2,:d3,:bb2,:f3,:f3,:f3,:bb3,:a3,:bb3,:f3,:a3,:f3] | |
d4=[m,c+2*md,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c] | |
n1b=[:d5,:eb5,:f5,:f5,:g5,:f5,:eb5,:d5,:c5,:d5,:eb5,:eb5,:f5,:eb5,:d5,:c5,:bb4,:c5,:bb4,:bb4,:eb5,:c5,:d5,:d5,:eb5,:c5,:bb4] | |
n1fb=[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c,c,c,c,c,md] | |
n3sb=[:f4] | |
n3c=[:d5,:r,:bb4,:f4,:d5,:bb4,:bb4,:bb4,:bb4,:c5,:bb4,:d5,:bb4,:d5,:a4,:a4,:bb4,:a4,:bb4,:a4,:bb4,:bb4,:c5,:a4,:a4,:bb4] | |
d3sb=[md] | |
d3c=[m,c,m,c,c,c,c,c,q,q,c,c,c,c,c,q,q,c,c,c,c,q,q,c,c,md] | |
n4sb=[:bb2] | |
n4c=[:bb2,:r,:bb2,:f3,:bb2,:bb3,:f3,:d3,:bb2,:d3,:bb2,:f3,:eb3,:d3,:c3,:bb2,:bb2,:eb3,:f3,:bb2] | |
d4sb=[md] | |
d4c=[m,c+md,c,c,c,c,c,c,c,c,c,m,c,c,c,c,c,c,c,md] | |
lar=[n1,d1,n2,d2,n3,d3,n4,d4,n1b,d1b,n2b,d2b,n3b,d3b,n4b,d4b,n1fb,d1fb,n2fb,d2fb,n3fb,d3fb,n4fb,d4fb] | |
lar.concat [n1sb,d1sb,n2sb,d2sb,n3sb,d3sb,n4sb,d4sb,n1c,d1c,n2c,d2c,n3c,d3c,n4c,d4c] | |
define :part do |x| | |
in_thread do | |
plarray(i[0][0],i[0][1],lar[x],lar[(x+1)],0,0.7) #trumpet I | |
end | |
in_thread do | |
plarray(i[0][0],i[0][1],lar[x+2],lar[x+3],0,0.6) #trumpet II | |
end | |
in_thread do | |
plarray(i[1][0],i[1][1],lar[x+4],lar[x+5],-12,0.6) #trombone I | |
end | |
plarray(i[2][0],i[2][1],lar[x+6],lar[x+7],0,0.4) #trombone II | |
end | |
set_bpm(110) #set tempo 40 crotchets or 80 quavers per minute | |
sync :fireworks | |
with_fx :reverb,room: 0.8,mix: 0.6 do #add some reverb | |
# with_fx :level,amp: 1.1 do #boost levels | |
part(0) | |
part(8) | |
part(16) | |
part(8) | |
part(24) | |
part(32) | |
part(0) | |
part(8) | |
part(24) | |
# end | |
end | |
cue :finish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Sonic Pi/Minecraft Firework display coded by Robin Newman, April 2015 | |
#requires SP 2.5dev or later | |
#requires Pi(2) | |
#Used in conjunction with Handel's Royal Fireworks minuet coded for SP | |
#placed in a separate workspace and cued form this progarm. | |
use_debug false | |
mc_set_area :air,-127,-20,-127,127,127,127 #clear a large area in the world | |
mc_set_area :grass,-60,-1,-60,60,0,60 #to stand on | |
sleep 6 #wait for this all to complete. | |
cue :fireworks #cue the music program | |
#set up some variables | |
s=0 #gap between placing blocks set to 0 for max speed | |
angresolution=2 #angular increment between points in degrees | |
#use Ruby Math package to define some trig stuff | |
pi=Math::PI #from Ruby Math module | |
define :cos do |v| #set up call to Math cosine | |
return Math.cos(v) | |
end | |
define :sin do |v| #set up call to Math sine | |
return Math.sin(v) | |
end | |
define :rad do |v| | |
return v * Math::PI/180 | |
end | |
define :circle do |brick,xs,ys,zs,r,updown,ang=angresolution| | |
if updown == 1 then | |
0.step(360,ang) do |i| | |
mc_set_block brick,xs + r*sin(rad(i)),ys+r*cos(rad(i)),zs | |
sleep s | |
end | |
else | |
360.step(0,-ang) do |i| | |
mc_set_block :air,xs + r*sin(rad(i)),ys+r*cos(rad(i)),zs | |
sleep s | |
end | |
end | |
#sleep 0.1 | |
end | |
define :target do |xs,ys,zs| | |
1.downto(0) do |v| | |
circle(:iron,xs,ys,zs,1,v,16) | |
circle(:iron,xs,ys,zs,2,v,16) | |
circle(:iron,xs,ys,zs,3,v,8) | |
circle(:iron,xs,ys,zs,4,v,8) | |
circle(:gold,xs,ys,zs,5,v,4) | |
circle(:diamond,xs,ys,zs,6,v,4) | |
circle(:iron,xs,ys,zs,7,v,4) | |
2.times do |i| | |
circle(:gold,xs,ys,zs,8+3*i,v) | |
circle(:diamond,xs,ys,zs,9+3*i,v) | |
circle(:iron,xs,ys,zs,10+3*i,v) | |
end | |
end | |
end | |
mc_teleport 0,30,0 | |
flag=0 | |
in_thread do | |
sync :finish | |
flag=1 | |
sleep 2 | |
end | |
until flag == 1 do | |
in_thread {sample :ambi_lunar_land,rate: 1.5,release: 3.5,amp: 2} | |
sleep 2 | |
target(rrand_i(-15,15),30,rrand_i(8,35)) | |
sleep rrand_i(3,6) | |
end | |
mc_chat_post "Sonic Pi and Minecraft, perform Handel's Royal Fireworks Music" | |
mc_chat_post "Coded by Robin Newman, April 2015" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment