Play current synth

play  note (symbol_or_number)

Play note with current synth. Accepts a set of standard options which include control of an amplitude envelope with attack:, decay:, sustain: and release: phases. These phases are triggered in order, so the duration of the sound is attack + decay + sustain + release times. The duration of the sound does not affect any other notes. Code continues executing whilst the sound is playing through its envelope phases.

If duration: is supplied and sustain: isn’t, it causes sustain: to be set so that all four phases add up to the duration.

Accepts optional args for modification of the synth being played. See each synth’s documentation for synth-specific opts. See use_synth and with_synth for changing the current synth.

If note is nil, :r or :rest, play is ignored and treated as a rest. Also, if the on: opt is specified and returns false, or nil then play is similarly ignored and treated as a rest.

Note that the default opts listed are only a guide to the most common opts across all the synths. Not all synths support all the default opts and each synth typically supports many more opts specific to that synth. For example, the :tb303 synth supports 45 unique opts. For a full list of a synth’s opts see its documentation in the Help system.

Introduced in v2.0

Options

amp:

The amplitude of the note

amp_slide:

The duration in beats for amplitude changes to take place

pan:

The stereo position of the sound. -1 is left, 0 is in the middle and 1 is on the right. You may use a value in between -1 and 1 such as 0.25

pan_slide:

The duration in beats for the pan value to change

attack:

Amount of time (in beats) for sound to reach full amplitude (attack_level). A short attack (i.e. 0.01) makes the initial part of the sound very percussive like a sharp tap. A longer attack (i.e 1) fades the sound in gently.

decay:

Amount of time (in beats) for the sound to move from full amplitude (attack_level) to the sustain amplitude (sustain_level).

sustain:

Amount of time (in beats) for sound to remain at sustain level amplitude. Longer sustain values result in longer sounds. Full length of sound is attack + decay + sustain + release.

release:

Amount of time (in beats) for sound to move from sustain level amplitude to silent. A short release (i.e. 0.01) makes the final part of the sound very percussive (potentially resulting in a click). A longer release (i.e 1) fades the sound out gently.

attack_level:

Amplitude level reached after attack phase and immediately before decay phase

decay_level:

Amplitude level reached after decay phase and immediately before sustain phase. Defaults to sustain_level unless explicitly set

sustain_level:

Amplitude level reached after decay phase and immediately before release phase.

env_curve:

Select the shape of the curve between levels in the envelope. 1=linear, 2=exponential, 3=sine, 4=welch, 6=squared, 7=cubed

slide:

Default slide time in beats for all slide opts. Individually specified slide opts will override this value

pitch:

Pitch adjustment in semitones. 1 is up a semitone, 12 is up an octave, -12 is down an octave etc. Decimal numbers can be used for fine tuning.

on:

If specified and false/nil/0 will stop the synth from being played. Ensures all opts are evaluated.

Examples

# Example 1

play 50



# Plays note 50 on the current synth



# Example 2

play 50, attack: 1



# Plays note 50 with a fade-in time of 1s



# Example 3

play 62, pan: -1, release: 3



# Play note 62 in the left ear with a fade-out time of 3s.



# Example 4


s = play :e3, release: 4
sleep 1
control s, note: :e5
sleep 0.5
use_synth :dsaw
play :e3  



# controlling a synth synchronously
 
 
 
 
 
# This is triggered after 1.5s from start



# Example 5


play :e3, release: 4 do |s|
  sleep 1                                              
  control s, note: :e5                                 
end

sleep 0.5
use_synth :dsaw
play :e3



# Controlling a synth asynchronously
 
# This block is run in an implicit in_thread
# and therefore is asynchronous
 
 
 
 
# This is triggered after 0.5s from start