https://sonic-pi.net/
https://twitter.com/sonic_pi
https://twitter.com/samaaron
https://www.patreon.com/samaaron
https://in-thread.sonic-pi.net/ (official help and discussion forum)
https://www.reddit.com/r/SonicPi/
https://www.raspberrypi.org/magpi/issues/essentials-sonic-pi-v1/
https://sonic-pi.net/tutorial
http://sonic-pi.mehackit.org/exercises/en/10-cheatsheet/01-cheatsheet.html
https://rbnrpi.wordpress.com and YouTube channel https://www.youtube.com/channel/UCtUhMj_RnVKy5Jiyr-fWZwg
https://www.youtube.com/watch?v=xpaO8HTrQ1M - YOW! Perth talk
https://www.youtube.com/watch?v=gETE5Pe_Fdk - Zendesk talk
https://www.youtube.com/watch?v=qnzlH02SSqU - Bach Suite no 3 BWV 1068
https://www.youtube.com/watch?v=5gRcWfWusN0#t=1m12s - Brandenburg Concerto No 2
https://www.codecademy.com/learn/learn-ruby
https://launchschool.com/books/ruby/read/basics
https://learnrubythehardway.org/book/
https://repl.it/languages/Ruby - Browser based environment for running Ruby code
ADSR envelope
https://blog.landr.com/wp-content/uploads/2016/10/ASDR-01.jpg
https://www.youtube.com/watch?v=4HIS9Tqukr8#t=16s
play 60
Plays midi note 60 - higher number -> higher pitch, lower number -> lower pitch
play 65.2341234
You can use decimals...
play 60 +2
... and do maths too
play :c2
Plays C in the second octave
play :bb
or play bf
Plays B flat in the 4th octave (default)
play :fs6
Plays F sharp in the 6th octave
NOTE: #
is used as the comment character. This means the computer will ignore everything after it on the same line. It's good for putting in human readable notes about what that bit of code does or keeping code in the file that you don't want to run.
This will play two notes at the same time
play 60
play 61
This will play the two notes sequentially with a gap of one beat (NOT seconds
play 60
sleep 1
play 61
play chord(55, :major)
or
play_chord([60,62,67])
You can play arpeggios too!
loop do
play chord(:d, :major).tick
sleep 0.5
end
See Four_Chord_Song.rb
You need to loop through them otherwise they all play at once
loop do
play (scale :c, :major).tick
sleep 1
end
or
play_pattern_timed scale(:c, :major), [1]
format is play_pattern_timed <notes to play>, <sequence of sleep times between each notes>
Now Randomize It!
play_pattern_timed scale(60, :egyptian).shuffle, [1, 0.5]
or
loop do
play (scale 50, :major, num_octaves: 2).choose
sleep 1
end
https://sonicpisamples.100yen.co.uk/ - website with Sonic Pi samples
sample :drum_cymbal_pedal
or
sample <location_of_file_on_your_computer>
- easiest way is to drag the file from Finder/File Explorer
You can also play them at different speeds
sample :loop_amen, rate: 0.5
or pick out specific notes
loop do
sample :loop_amen, onset: 1
sleep 0.125
end
or even randomise it
loop do
sample :loop_amen, onset: pick
sleep 0.125
end
use_synth :pluck
play chord(:c, :maj)
Oh, cool! We have a digital uke 😃
Testing all the synths with GOT theme (growl one sounds pretty cool)
use_bpm 120
synth_names.each do |s|
use_synth s
puts "using synth #{s}"
play_pattern_timed [:g, :c, :eb, :f, :g, :c, :eb, :f, :d ],[1, 1, 0.5, 0.5, 1, 1, 0.5, 0.5, 2]
sleep 1
play_pattern_timed [:d, :bb3, :eb, :d, :f, :bb3, :eb, :d, :c],[2, 2, 0.5, 0.5, 1.5, 2, 0.5, 0.5, 2]
end
in_thread
and live_loop
allow you to run multiple blocks of code at the same time. in_thread
will execute the code once whereas live_loop
continuously runs the code in a loop until you stop it.
Both will take a delay: n param which will delay execution by n beats(see Frere_Jaques.rb)
OSC is a protocol similar to MIDI used internally by Sonic Pi but you can also use it to communicate with other devices e.g. phone apps, lights, other computers. I use this one https://play.google.com/store/apps/details?id=com.ffsmultimedia.osccontroller which is free. Another commonly used one is https://hexler.net/products/touchosc.
Example with slider
live_loop :slider_tune do
use_real_time
note = sync "/osc/demo/slider1" #change this to match your OSC interface
puts "playing note #{note[0]} "
play (note[0])
end
Example with buttons to control samples
live_loop :grid_toggle do
use_real_time
start = sync "/osc/demo/gridToggle1" #change this to match your OSC interface
if start[0] == 1.0
sample :drum_cymbal_hard
sleep 1
end
end