Hardware Reference
In-Depth Information
The following list includes some different synths in Sonic Pi you can try out.
pretty_bell
dull_bell
fm
beep
saw_beep
More sounds will be added to the Sonic Pi application in time, so be sure to watch for
them and keep your Pi application packages updated using sudo apt-get update .
Creating a Surprising Tune
So far, you have run your music program in sequence and then using a repeating loop.
To add an element of fun, you could add a junction using a conditional. You used con-
ditionals in Adventures 3 and 5 in both Scratch and Python. Setting conditions allows
different paths to be followed, as if you were at a junction.
Type the following example script into your current Workspace to try it out (see Figure
7-10):
10.times do
if rand < 0.5
play 42
else
play 30
end
sleep 0.25
end
The first line is the start of the repeating loop. Everything after do and before end
will be played 10 times. The second line is the start of the conditional statement. The
condition used here is like flipping a coin: rand stands for random, and it will return
a random value between 0 and 1. If the value returned is less than 0.5 then this state-
ment is true and the MIDI note 42 will be played. If the value returned is not less than
0.5, then the statement is false and MIDI note 30 will be played instead. Only one of
the play steps will be run. To complete the condition, end is used. Each time the
loop plays, a new value for rand is generated.
T
What do you think happens if the rand returns the value 0.5? Is the statement
true or false?
Search WWH ::




Custom Search