Making Custom Beats: makeBeat

makeBeat() allows us to compose music note by note instead of at the measure level, perfect for drum beats. This approach is often called step sequencing in music production.

Strings

We need to understand the string data type to use makeBeat(). In Python, a string is a series of characters with single or double quotation marks around it, like "Hello World!" or 'This is a test sentence'. Strings are often used in programming to represent non-numerical data such as words, but can include numbers. For example, the string "123 Ferst Dr." could represent an address, using numbers, spaces, letters, and punctuation. Like numbers (and other types of data), strings can be assigned to variables: address = "123 Ferst Dr."

We need to understand the string data type to use makeBeat(). In JavaScript, a string is a series of characters with single or double quotation marks around it, like "Hello World!" or 'This is a test sentence'. Strings are often used in programming to represent non-numerical data such as words, but can include numbers. For example, the string "123 Ferst Dr." could represent an address, using numbers, spaces, letters, and punctuation. Like numbers (and other types of data), strings can be assigned to variables: address = "123 Ferst Dr."

Note that 5 and "5" mean very different things to the computer: 5 is a number it can perform math on, while math operations won’t work with the string "5". For example, 5 + 6 is evaluated as 11, while "5" + "6" is evaluated as "56".

Beat Patterns with Strings

We use strings with makeBeat() to define rhythmic, or beat, patterns. In EarSketch, we can use beat pattern strings, or series of characters, to refer to sixteenth note sub-beats of a measure. A character can be a letter, number, whitespace, punctuation, or symbol, as a single unit of information. The configuration of characters allow us to place clips at specific places in the measure and define the clip’s play length. Here is an example of a beat pattern string, assigned to a variable called myDrumBeat:

myDrumBeat = "0-00-00-0++0+0"

  • 0 starts playing a clip.

  • - is a rest, meaning silence.

  • + extends the audio clip into the next sixteenth note sub-beat. It always follows a 0 or +.

A 16-character beat string makes up a measure, but beat strings do not have to be this length; the beat string "0+++", lasting for one beat, is perfectly acceptable. EarSketch reads the string from left to right, adding the chosen clip to the DAW according to the string’s rhythm. The myDrumBeat string, above, creates the following rhythm in the DAW:

makeBeatFinal
Figure 11.2: Rhythm created by the myDrumBeat string

Here is a recording of the same beat:

makeBeat()

makeBeat() takes four arguments:

  1. Clip Name

  2. Track Number

  3. Measure Number: makeBeat() only requires a starting measure; the string length determines the end measure.

  4. Beat String

You may want to create an interesting beat, but you will also want to control how many times it repeats throughout your song. You could specify each and every measure you want it to play, or you can let the code do some of the heavy lifting for you with for-loops. In the next chapter, we will learn about this coding technique to efficiently achieve repetitions.

# Rhythms: Using several makeBeat() calls with different rhythms

# Setup
from earsketch import *
setTempo(120)

# Music
synth = DUBSTEP_FILTERCHORD_002
cymbal = OS_CLOSEDHAT01
beat1 = "-00-00+++00--0-0"
beat2 = "0--0--000--00-0-"

makeBeat(synth, 1, 1, beat1)
makeBeat(cymbal, 2, 1, beat2)
// Rhythms: Using several makeBeat() calls with different rhythms

// Setup
setTempo(120);

// Music
var synth = DUBSTEP_FILTERCHORD_002;
var cymbal = OS_CLOSEDHAT01;
var beat1 = "-00-00+++00--0-0";
var beat2 = "0--0--000--00-0-";

makeBeat(synth, 1, 1, beat1);
makeBeat(cymbal, 2, 1, beat2);

Chapter 11 Summary

  • A string is a data type that consists of a series of characters encapsulated by single or double quotes. Strings are most often used to represent non-numerical data.

  • Strings are used with the makeBeat() function to create rhythmic patterns in EarSketch. makeBeat() takes a beat string to define each sixteenth note sub-beat of its pattern. A 0 starts playing a clip, a + extends the note for the next sub-beat, and - creates a rest.

  • makeBeat() takes four arguments:

    • clipName: The clip a beat is constructed from.

    • trackNumber: The track on which music is placed.

    • measureNumber: The starting measure of the beat. The beat string determines the total length.

    • beatString: A string that specifies the rhythm created.

Questions

Which of these options is a string?

  • "Five"

  • 5

  • FIVE

  • Five

What does “0” represent in a beat pattern string?

  • Start playing the clip

  • Rest

  • Extend the clip

  • End the clip