Skip to content

Instantly share code, notes, and snippets.

@lisaolson
Last active October 13, 2016 05:11
Show Gist options
  • Save lisaolson/d7d66862bf7827cbd6c3d71470c137b0 to your computer and use it in GitHub Desktop.
Save lisaolson/d7d66862bf7827cbd6c3d71470c137b0 to your computer and use it in GitHub Desktop.

Sonic Pi

Sonic Pi is a coding music synth made for learning how to code while making awesome tunes!

Why Use Sonic Pi

  • The real question is, why not use Sonic Pi? It's coding and music! What could be better than that?
  • You can practice coding in ruby
  • And practice your dj skills
  • It's also set up with lessons, so you could teach kids/adults to code in a super fun way.

So, if you're convinced...

How to Install

Using the command line, you can install it into the app you're working on like this:

  gem install sonic-pi

**There's also a separate download with a desktop icon so you can code from their sonic-pi desktop app. http://sonic-pi.net/

Basics of Sonic Pi

  1. Play
  2. - Play is a method used like so:
    play 40
    play :C
    - play correlates directly with actual piano notes.
    - So, 'play 40' plays the 40th key on the keyboard.
    - play :C plays the note C.
    Adding play :C5 would play the 5th octave of C. <br>
         - To get fancy, you could add s or b to signify sharp or flat<br>
    		- play :Cb => C flat<br>
    
    <li> Sleep </li>
    - sleep is the method that dictates how long to sleep. <br>
    	-  So, the code sleep 1.2 would 'sleep' for 1.2 seconds.<br>
    
    <li> Amplitude </li>
      Amplitude is how loud the sound is.
        - High amplitude produces loud sound, low amplitude produces quieter sound. 
          **default is amp: 1
              example: play 60, amp: 0.5
    <li> Synths </li>
        Synths are some of the built-in sounds. There's a TON of built-in sound effects to choose from.
        Synth is just one of those sound effects. 
          Syntax: use_synth 
              20 different synths to choose from 
    

Conclusion

Sonic Pi is a fun way to code with Ruby and make music. A completed song would look like this:

use_synth :hollow with_fx :reverb, mix: 0.7 do

live_loop :note1 do play choose([:D4,:E4]), attack: 6, release: 6 sleep 8 end

live_loop :note2 do play choose([:Fs4,:G4]), attack: 4, release: 5 sleep 10 end

live_loop :note3 do play choose([:A4, :Cs5]), attack: 5, release: 5 sleep 11 end

end

Note

To integrate Sonic-Pi into Atom, download the package below.

Resources

http://sonic-pi.net/ - Official Sonic-Pi Website https://atom.io/packages/atom-sonic - To integrate Sonic-Pi into Atom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment