Sonic pi is an open-source programming environment designed to explore and teach programming concepts by creating sound production music processes.
The Code executed by sonic pi is based on Ruby, which is a beautiful and concise programming language. This means that you can write a lot of code without having to worry too much about syntax and braces-though important for complex programs.
1. Getting Started (start learning)
You can find the sonic PI program in education of applications menu of raspbin system. Open this program and you will see a window similar to the following:
This is the sonic PI program interface. The window contains three parts. The biggest part is where you write code. We call it the programming panel. The control window in the upper-right corner is the output panel, which displays information about the execution process of your program. The window in the lower right is the error panel. When there is an error in your code, the error message is displayed here.
2. Making Sounds)
Enter the following content in Workspace 1:
play 60
Click play now, and the note will be executed. MIDI sets the value 60 to C.
TryPlay 60ChangePley 60Check for any errors.
Enter the following code:
play 60play 67play 69
Click the play button once.
These notes are executed so quickly that they sound as if they were simultaneously voiced. Use sleep to add pause between notes:
play 60sleep 1play 67sleep 2play 69
3. A tune: Frere Jacques (A Song: jaces)
The start of this song is:
C d e c or a 60 62 64 60 Note in Midi.
Comparison of notes and Midi notes:
C |
D |
E |
F |
G |
A |
B |
60 |
62 |
64 |
65 |
67 |
69 |
71 |
The following is a piece of music:
play 60sleep 0.5play 62sleep 0.5play 64sleep 0.5play 60sleep 0.5
4. looping)
To execute a series of commands repeatedly, you can use a loop. The following is an example of a ruby language loop:
2.times do play 60 sleep 0.5 play 62 sleep 0.5 play 64 sleep 0.5 play 60 sleep 0.5end
5. Functions (method)
You can define a series of executions in a method. You can call this method multiple times in the future to avoid copying and pasting multiple lines of code:
def frere play 60 sleep 0.5 play 62 sleep 0.5 play 64 sleep 0.5 play 60 sleep 0.5end
You can enter frere to call this method later. For example, call in a loop:
4.times do frereend
6. Synths (synthesizer)
The synthesizer enables the play method to make different sound effects. The default synthesizer is "pretty_bell", but you can change it by yourself:
"pretty_bell""dull_bell""beep""saw_beep""fm"
Try different synthesizer:
with_synth "fm"2.times do play 60 sleep 0.5 play 62 sleep 0.5end
7. threads (thread)
You can use a thread to play two songs at the same time. Similar to a loop, it is also a code block ending with the end Keyword:
in_thread do with_synth "saw_beep" 2.times do play 60 sleep 0.5 play 67 sleep 0.5 endend
8. workspaces)
You can use multiple workspaces in the sonic PI program window. This means you can try your code block in other workspaces without deleting the current code. We recommend that you use other workspaces to try the code for implementation or sandbox testing.
9. Sonic PI files (sonic PI files)
If you choose to save it as a file, you can return it or share it with others later. The sonic PI file is a simple text file, so you can view and edit it on another computer, or run it on another Raspberry Pi.
Address: http://www.raspberrypi.org/documentation/usage/sonic-pi/README.md
Raspberry Pi-sonic Pi (sound programming)