Tweak It

Still More Options


Do this
Look up the help file of your favourite synthesizer. Use at least one option you haven’t used before!

If the cutoff: option has a low parameter such as 30, what will happen?

Educator notes

All synths have options, like amp: and pan: that are common to all the synthesizers. Incidentally, these are also the options for play! Unfortunately, Sonic Pi will only show these options in the drop-down menu. Check the help file of each synthesizer to get to know the options unique to them!

Don’t Stop the Options

Transcript

Sometimes you may run into situations where you want all the notes of your melody to have a certain release: time or a cutoff: value. Writing the options after each play command would be a lot of work and what if you change your mind later? Well you would have to go through all the commands again. Sonic Pi makes your life a lot easier with a command called use_synth_defaults. use_synth defaults tell Sonic Pi what options to use for all the play commands that follow it. I'll write that into the beginning of my melody. After the command I press space and I write release: and I'll give a value for release. Just like I would write after a play command. Now all the play commands that follow will have a release of 0.1 beats. I'm not stuck with only that value though. If I would want to make one of my notes have a longer release, I can give it it's own options as usual. There's no drop-down menu for use_synth_defaults like there is when you give options for play, so it's a good idea to have the help file of your synth open when you are using use_synth_defaults so that way you don't have to remember the names of all the options by heart. And by the way if you specify an option that doesn't exist, Sonic Pi will simply skip it without an error message. So for example if I make up an argument something like cucumba: and I will give it a value of 100 - very high. So, the code will run normally but the sound is not affected in any way since cucumba: doesn't actually exist as an option. Keep this in mind if your default options don't seem to work. Make sure you have spelled the name of the option correctly and make sure that the synth actually has this option.

Do this

Put a use_synth_defaults in your code to change the sound of all the play commands that follow.

You can change more than one option by separating them with a comma like this:

use_synth_defaults amp: 0.5, attack: 1, release: 0.25

How many options can you give to synths with the command use_synth_defaults?

Educator notes

It can be confusing and even a bit scary for the learners when suddenly they don’t have a drop down menu while using use_synth_defaults. But there is no need to panic! Instruct the learners to keep the help file open and find the names of the options there. Typing the option names also helps in remembering them!

Options for Sections


Do this

Put two different use_synth_defaults in your melody to create two sections.

Hint: you might want to use repeat blocks to repeat a pattern more than once. For example:

live_loop :section do
  use_synth :saw
  #set options for this section
  use_synth_defaults attack: 1
  8.times do
    #play some notes
    sleep 1
  end
  #set different options for the next part
  use_synth_defaults  attack: 0, release: 0.5
  16.times do
    #play some other notes
    sleep 0.5
  end
end

What will happen if you use use_synth_defaults without any parameters?

Educator notes

Misspelling an option can be a source of frustration for learners. The program will execute without errors, but there seems to be no change in sound. If nothing seems to happen, ask the learners to check that all the options are written correctly and that they have sensible values. If the values are the same as defaults, then there will also be no change either.

Every option that you don’t explicitly define in use_synth_defaults will be set to the ones shown in the helpfile. So if you want to carry over options when using multiple use_synth_defaults then you will have to type them as well.