Materials:
– Portable Speakers
– Sonic Pi
Scratch’s ability to teach the foundations of coding to children and those with no prior experience with computers is one of his most notable features. It appeals to children in particular since it lets them to construct video games with which they may participate as part of their education. On the other hand, Sonic Pi, in this line, teaches individuals to code through music. With a simple language that employs basic logic processes in a manner that is more advanced than scratch.
Install Sonic Pi
Sonic pi will be installed by default if you have installed the most recent version of Raspbian. You’ll need to install it from the repos if you’re still on an older version.
For installing type the following:sudo apt-get install sonic-pi
First steps with Sonic Pi
Sonic Pi can be found in the education section. When you open it up, you’ll see something that recalls an IDE. The left-hand pane allows you to enter code for your project, complete with syntax highlighting. When Sonic Pi is running, an info pane shows exactly what’s being played, as well as any mistakes, which are displayed in their own pane for reference.
The ability to play a note is the first thing we try on Sonic Pi. We can get started with play 50
because Sonic Pi has a few defaults pre-set.
When you press the play button, the output pane will display what is currently being played. The default tone for Sonic Pi output is pretty_bell
, and 50 controls the pitch and tone of the sound.
Let’s set the rhythm :
with_tempo 300
let’s test it out, create a string of MIDI notes using play_pattern
play_pattern [25,25,45,45,25,25,60,60]
this will play pretty_bell
notes at these tones at the tempo we’ve set.
More complex melodies
By utilizing more of Sonic Pi’s functions, we may begin to create more complicated tunes. With the with_synth
function, you may modify the note type, reverse a pattern, and even build a finite loop using the x.times
function. Do
and end
indicate the start and end of the loop. Everything is played in order before repeating, similar to an if or while loop in regular programming.
We can use the in_thread
function to start a new thread for the Sonic Pi instance, allowing us to play multiple lines of music and code at once rather than sequentially. Using the play_pad
function, we can make it generates a random sequence of notes that play alongside extra notes generated by the mouse’s position and velocity.