Hardware Reference
In-Depth Information
DIGGING INTO THE CODE
You may notice that Sonic Pi does not use the same sort of programming lan-
guage that you have used in previous adventures. It actually uses a different
programming language called Ruby. Ruby uses the same computing concepts
as Scratch and Python, such as conditionals, iteration, and data structures.
A MIDI keyboard, or Musical Instrument Digital Interface, is a musical instrument
that can communicate with a computer. Piano sheet music notes and MIDI
keyboard notes are the same, only sheet music notes are represented by letters
G, C, A, and so on, whereas MIDI keyboard notes are represented by numbers.
(In fact, MIDI note numbers are in semitone steps. G, A, B are tones whereas 67,
68, 69 are semitones.)
Twinkle Twinkle Little Star
You have the building blocks to generate a simple tune with notes C, G and A—or in
this case 60 , 67 and 69 —along with delays in between those notes using sleep (see
Figure 7-6).
Amend your code so that it looks like the following, and click Play:
play 60
sleep 0.5
play 60
sleep 0.5
play 67
sleep 0.5
play 67
sleep 0.5
play 69
sleep 0.5
play 69
sleep 0.5
play 67
Remember that Sonic Pi will run through each line in your code in sequence. You could
go on and write the next part of the tune, but you will end up with a long list of play
and sleep , which could get confusing to read, especially if you mistype a line and cre-
ate a bug.
Search WWH ::




Custom Search