< Back to Sonic Pi notes

Control

How to change Sonic Pi sounds as they're playing

Control takes an ongoing sound and lets you adjust certain properties as it plays. You can change synth notes, amp, sustain, release, and others. It takes a few basic steps:

  1. Save the synth or sample into a variable, which will play it with any other set variables.
  2. You can have other actions after this, such as sleep.
  3. If you call the same variable with control, you can pass in different params that will change as it plays.
  4. Repeat as needed.

A simple example of this from the tutorials below:

s = play 60, release: 5
sleep 0.5
control s, note: 65
sleep 0.5
control s, note: 67
sleep 3
control s, note: 72

This is also possible with samples and effects.

with_fx :reverb do |r|
  play 50
  sleep 0.5
  control r, mix: 0.7
  play 55
  sleep 1
  control r, mix: 0.9
  sleep 1
  play 62
end

You can also pass different _slide parameters to these that will draw out or quicken the slide between the changes (the default is 1). Some of, but likely not all slide options, are below: