Player object intro

Picking a sound

When FoxDot boots up it reserves all lower-case, two-character variable names, e.g. aap1, and bd, to be used as “players”. These are the objects that play sounds for us based on instructions we give them. The first instruction we give it telling it what instrument (synth) to play. To see a list of all available synths, evaluate the following:

print(SynthDefs)

This is short for Synth Definition. Choose one and assign it to a FoxDot player object using two “greater than” signs, aka a “double arrow”. If my chosen SynthDef was “pluck” and my chosen player object was p1 then I would assign “pluck” to p1 like so:

p1 >> pluck()

Make sure you include the brackets at the end of “pluck” or it won’t work. To stop an individual player object, simply execute p1.stop(). To stop all player objects, you can press Ctrl+., which is a shortcut for the command Clock.clear().

Assigning Instructions

The >> in Python is usually reserved for a type of operation, like how a ‘+’ symbol is used for addition, but it is not the case in FoxDot, and the reason will become clear shortly. By adding arguments in the brackets, you can change the notes being played back. The first argument, the note pitch (sometimes referred to as degree), doesn’t need to be named explicitly, but you’ll need to specify other attributes (such as duration) if you want to change them. These values can be a single value or a list of values that the player will play in turn. For example, the code below plays three notes in turn continuously until p1 is stopped:

p1 >> pluck([0, 2, 4], dur=[1, 1/2, 1/2], amp=0.75) 

The first argument is the pitch of the note we want to play, which is a list of 3 numbers; 0, 2, and 4. The player will play each of these in turn. By default all players will use the C-Major scale, which we can think of as a Python list:

CMajor = [C, D, E, F, G, A, B] 

The numbers we use for pitch refer to the index of the notes we want to pick from this scale. So, with our list of pitches [0, 2, 4] our notes would be:

CMajor[0] => C
CMajor[2] => E
CMajor[4] => G

The duration of these notes are derived from the dur keyword argument, which is also a list of three numbers; 1, 1/2, and 1/2. The position of these values relate to the position of the values we supplied for pitch. So the first note will last for 1 beat and the next two notes will last for half of 1 beat. The last keyword argument, amp is used to set the amplitude (loudness) of the note, where 0 is silent and 1 is louder. You’ll be able to find out about other keywords you can use in the Players Attributes section.

You can also add values to the Player to create variation in your sequences or even play chords. For example, the code below will play every 3 note 4 pitches higher:

p1 >> pluck([0, 1, 2, 3], dur=2) + [0, 0, 4] 

To create chords, use a tuple in place of a list. The code below will add a basic triad to each note played:

p1 >> pluck([0, 1, 2, 3], dur=2) + (0, 2, 4) 

Playing Samples

FoxDot can also play audio samples, such as percussion, using a special SynthDef called play. Instead of taking a list of numbers as its first argument it takes a string of characters where each character relates to a different sound. Here’s an example of a very basic drum pattern:

d1 >> play("x-o-") 

The string can also contain information about how the sequence should be played, which is done by using different types of brackets. Putting two or more characters in round brackets will alternate which sound to play on each loop through the sequence:

d1 >> play("(x-)(-x)o-") 

Putting multiple characters in square brackets will play them successively in the space of one step. This example plays a triplet of hi-hats during its fourth step:

d1 >> play("x-o[---]", dur=1)

You can also use curly braces to pick a sound at random, to add a little variety to your sequence:

d1 >> play("x-o{-=*}") 

These can all be used and nested together to create complex patterns:

d1 >> play("(x[--])xo{-[--][-x]}")