class: center, middle
- A way to make sound with ruby code
- An IDE
- Runs on many platforms
- Mac
- Windows
- Linux
- Raspberry Pi (Raspbian)
- Engaging education resource
- Sits at the intersection between three core domains
- Art - express yourself
- Technology - time / concurrency
- Education - open play rather than rigid structures
Play a single note, a C
play 60
Now lets try 3 notes: C, G, A
play 60
play 67
play 69
Now lets try 3 notes: C, G, A
play 60
play 67
play 69
Notice how they all sound at the same time, is that what you expected?
Same as #2 but with a pause in between each note, so you can hear them separately
play 60
sleep 1
play 67
sleep 1
play 69
With a loop to repeat a few notes
2.times do
play 60
sleep 1
play 67
sleep 1
play 69
sleep 1
end
With a loop to repeat a few notes
2.times do
play 60
sleep 1
play 67
sleep 1
play 69
sleep 1
end
Right, its just Ruby! :)
Notes can be expressed in numbers, but you might find it easier to use the note letter instead. Sonic Pi provides a nice set of symbos for this purpose
2.times do
play :c4
sleep 1
play :g4
sleep 1
play :a4
sleep 1
end
Notes can be expressed in numbers, but you might find it easier to use the note letter instead. Sonic Pi provides a nice set of symbos for this purpose
2.times do
play :c4
sleep 1
play :g4
sleep 1
play :a4
sleep 1
end
I'm not a musician, but I think the two characters denote the "Note" and "Octave" of each tone generated by Sonic Pi
Very often, this is one of the first songs a child will learn to play on an instrument. Can you tell which song this is?
play :b4; sleep 0.25
play :a4; sleep 0.25
play :g4; sleep 0.25
play :a4; sleep 0.25
play :b4; sleep 0.25
play :b4; sleep 0.25
play :b4; sleep 0.5
play :a4; sleep 0.25
play :a4; sleep 0.25
play :a4; sleep 0.5
play :b4; sleep 0.25
play :d5; sleep 0.25
play :d5; sleep 0.5
#Mary Had Little Lamb
A portion (or sample) of one sound recording so that it can be reused
2.times do
sample :loop_amen
sleep 1.753
end
Some times you'll find that its good to play multiple threads of music which overlap one another. This is done using the in_thread method, as shown below
in_thread do
loop do
sample :loop_amen
sleep 1.75
end
end
in_thread do
16.times do
play :b4; sleep 0.25
play :a4; sleep 0.25
play :g4; sleep 0.25
play :a4; sleep 0.25
play :b4; sleep 0.25
play :b4; sleep 0.25
play :b4; sleep 0.5
end
end
Just like many guitarists will have an effects pedal at their feet when they play, we can add effects to our sound as well. They can even be layered on top of one another like shown below
with_fx :reverb do
with_fx :distortion do
play :b4; sleep 0.25
play :a4; sleep 0.25
play :g4; sleep 0.25
play :a4; sleep 0.25
play :b4; sleep 0.25
play :b4; sleep 0.25
play :b4; sleep 0.5
end
end
class: center, middle
Slides available at https://github.com/clerb/soinic_pi_hacknight