Raspberry Pi-Sonic Pi (sound programming), sonicpi

Source: Internet
Author: User

Raspberry Pi-Sonic Pi (sound programming), sonicpi

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



How can I test Raspberry Pi's communication with the PIC 32 UART?

Nothing. Although I do not know how
PIC 32 UART
Communication. Raspberry Pi is a minipc. A toy. It's fun. Used for learning.

Linux is indeed quite easy to develop. Easier than windows. This is true for professionals. Non-professionals do not like linux very much.

PIC 32 UART seems to be a serial port. Don't understand.

How to change Raspberry Pi Login Name

Run in terminal first
Sudo-s
Then run adduser your_name
Follow the prompts to have your own account.

The original account is pi. Do not delete it. You can change its password. In this way, it is not easy to be mistakenly logged on.

Hostname? It should be defined in the/etc/hosts file.

The user name is in. /Etc/passwd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.