NetLogo and Music - Happy Birthday example
11/18/2009
extensions [sound]
to playNote [ theNote theLength ]
sound:start-note "TRUMPET" theNote 65
wait theLength
sound:stop-note "TRUMPET" theNote
end
to happyBirthday ; http://www.8notes.com/scores/1110.asp
playNote 60 0.3 ; hap
playNote 60 0.1 ; py 60 = C
playNote 62 0.4 ; birth 62 = D
playNote 60 0.4 ; day 64 = E
playNote 65 0.4 ; to 65 = F
playNote 64 0.8 ; you 67 = G
; 69 = A
playNote 60 0.3 ; hap 70 = B flat
playNote 60 0.1 ; py ; 16th = 0.1 seconds
playNote 62 0.4 ; birth ; 8th = 0.2 seconds
playNote 60 0.4 ; day ; Quarter note = 0.4 seconds
playNote 67 0.4 ; to ; Half note = 0.8 seconds
playNote 65 0.8 ; you
playNote 60 0.3 ; hap
playNote 60 0.1 ; py
playNote 72 0.4 ; birth
playNote 69 0.4 ; day
playNote 65 0.4 ; dear
playNote 64 0.4 ; stu
playNote 62 0.4 ; dent
playNote 70 0.3 ; hap
playNote 70 0.1 ; py
playNote 69 0.4 ; birth
playNote 65 0.4 ; day
playNote 67 0.4 ; to
playNote 65 0.8 ; you
end
Much improved use of NetLogo to "sing" Happy Birthday
extensions [sound]
to playHappyBirthday
( foreach [ 60 60 62 60 65 64 60 60 62 60 67 65 60 60 72 69 65 64 62 70 70 69 65 67 65 ]
[ .3 .1 .4 .4 .4 .8 .3 .1 .4 .4 .4 .8 .3 .1 .4 .4 .4 .4 .4 .3 .1 .4 .4 .4 .8 ]
[
playNote ?1 ?2
]
)
end
to playNote [ theNote theLength ]
sound:start-note "TRUMPET" theNote 65
wait theLength
sound:stop-note "TRUMPET" theNote
end