Last active
September 21, 2019 07:48
-
-
Save rbnpi/15f228ed6fd31ae53b7fbfd4c28a573a to your computer and use it in GitHub Desktop.
Extended 12 days of Christmas Sonic Pi Project based on https://projects.raspberrypi.org/en/projects/code-a-carol adding harmony
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
#12 days of Christmas | |
#based on https://projects.raspberrypi.org/en/projects/code-a-carol | |
#tune altered slightly, based on https://sheetmusic-free.com/download/6888/ | |
#I've added sustain/release for each note | |
#using pl function, also ability to play chords with pl | |
#also added simple accompaniment part. | |
#I cycle synth used each verse, and adjust tempo last two verses | |
#also added slight reverb. | |
#I modifiy many of the functions to allow refinements for each day, | |
#by utilising a days parameter. | |
define :pl do |notes,durations| #allows for sustain and release values appropriate to duration | |
notes.zip(durations).each do |n,d| | |
if n.respond_to?(:each) #allow for chords | |
n.each do |nv| #if chord notes in [..] play them all together | |
play nv,sustain: 0.9*d,release: 0.1*d | |
end | |
else #otherwise play the single note entry | |
play n,sustain: 0.9*d,release: 0.1*d | |
end | |
sleep d #sleep for note/chord duration | |
end | |
end | |
define :intro do |days| | |
extra=0.5 | |
extra=0 if days==1 #amend last note durations for day 1 | |
notes=[:c4,:c4,:c4,:f4,:f4,:f4,:e4,:f4,:g4,:a4,:bb4,:g4,:a4] | |
durations=[0.5,0.5,1,0.5,0.5,1,0.5,0.5,0.5,0.5,0.5,0.5,1.5+extra] | |
notesb=[:r,[:f3,:a3],:bb3,:c4,:f3] | |
durationsb=[1,4,1,1,1.5,0.5+extra] | |
in_thread do | |
pl notesb,durationsb | |
end | |
pl notes,durations | |
end | |
define :partridge do |days| | |
extra=0 | |
extra=1 if days==12 #allow changed duration for last verse | |
notes=[:bb4,:c5,:d5,:bb4,:a4,:f4,:g4,:f4] | |
durations=[0.5,1,0.5,0.5,0.5,0.5,1,3+extra] | |
notesb=[:r,:a3,:bb3,:c4,:bb3,:a3,:g3,:f3] | |
durationsb=[0.5,1,1,1,1,1,1,0.5+extra] | |
in_thread do | |
pl notesb,durationsb #play part 2 in a thread | |
end | |
pl notes,durations | |
end | |
define :item do |days| | |
if days <5 | |
notes=[:c5,:g4,:a4,:bb4] | |
durations=[1,0.5,0.5,1] | |
else | |
notes=[:c5,:g4,:a4,:bb4,:g4] | |
durations=[1,0.5,0.5,0.5,0.5] | |
end | |
notesb=[:c4] | |
durationsb=[3] | |
in_thread do | |
pl notesb,durationsb #play part 2 in a thread | |
end | |
pl notes,durations | |
end | |
define :five_gold_rings do | |
notes=[:c5,:d5,:b4,:c5] | |
durations=[2,1,1,4] | |
notesb=[[:a3,:c4],[:gs3,:b3],[:g3,:bb3]] | |
durationsb=[2,2,4] | |
in_thread do | |
pl notesb,durationsb #play part 2 in a thread | |
end | |
pl notes,durations | |
end | |
define :four_three_two do | |
notes=[:c5,:bb4,:a4,:g4,:f4,:bb4,:d4,:f4,:g4,:f4,:e4,:d4,:c4] | |
durations=[0.5,0.5,0.5,0.5,1,1,01,1,0.5,0.5,0.5,0.5,1] | |
notesb=[:f3,:d3,:bb3,:c3] | |
durationsb=[2,1,3,3] | |
in_thread do | |
pl notesb, durationsb #play part 2 in a thread | |
end | |
pl notes,durations | |
end | |
#play everything | |
with_fx :reverb,room: 0.6,mix: 0.6 do | |
days=1 | |
12.times do | |
use_synth (ring :pulse,:chiplead,:fm,:saw).tick | |
if current_synth == :fm | |
use_transpose 12 #:fm defaults to an octave low, so compensate | |
else | |
use_transpose 0 | |
end | |
use_transpose current_transpose+2 if days >10 #bump last 2 verses up a tone | |
#next line allows different bmp setting for each verse. | |
use_bpm [120,120,120,120,120,120,120,120,120,120,120,160].look | |
intro days | |
if days >=5 | |
repeat = days - 5 | |
repeat.times do | |
item days | |
end | |
use_bpm 120 if days == 12 #slow five gold rings last verse | |
five_gold_rings | |
use_bpm 110 if days == 12 #slow remainder last verse | |
four_three_two | |
pl [:a4], [0.5] #extra note/duration sent as lists to pl | |
elsif days > 1 | |
repeat = days - 1 | |
repeat.times do | |
item days | |
end | |
pl [:a4], [0.5] #extra note/duration sent as lists to pl | |
end | |
use_bpm 100 if days == 12 #rall for last partridge | |
partridge days | |
days = days + 1 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment