teaching machines

Pentatouch, Part II

July 12, 2018 by . Filed under electronics, music, public.

This post is part of a series of notes and exercises for a summer camp on making musical instruments with Arduino and Pure Data.

With the pentatouch hardware in place, we now turn our attention to generating its music in Pure Data. We break down the patch into three steps: pairing the data, branching based on the button identifier, and generating each button’s note.

Reading Two Numbers

We will use the comport object like before, but instead of reading one number at a time, we will need to read two numbers: the button identifier and the button state. By itself, comport fires off any number it reads immediately. To pause the flow of data until two numbers have been read, we use the repack object:

To get repack, we’ll need to install a Pure Data package named zexy. Follow these steps to install it:

Recreate this in a new Pure Data patch named pentatouch.pd. Run it and press buttons on the pentatouch. You should see pairs of numbers in the console window.

Branching

Recall that the buttons are identified 0 through 4. Each of these buttons should produce a different note. How do we do that? Think back to select. We gave it a menu of numbers, and it sent a bng along the outlet that corresponds to the number it saw. We want to do something similar here.

We want the first number in each pair—the button identifier—to choose which path we take. But we want the second number—the button’s state, a 0 or 1—to get sent along to play a note. This is somewhat like select, but not exactly, as it only sends along a bng. We use the route object to send along other data:

The route object expects a pair of numbers, splits it up, chooses an outlet based on the first number, and forwards the second number along that outlet.

Try it. Connect route to five toggle (tgl) objects to test it.

Generating Sound

We are ready to produce sound. The good news is that we already have our note abstraction hiding away that complexity. We can simply add a note below each toggle:

Note the MIDI numbers in this patch: 60, 62, 64, 65, and 67. 60 is the MIDI number for C in the fourth octave and is called the root. From C, we jump by 2 to 62, by 2 again to 64, by 1 to 65, and by 2 to 67. The jumps are 2, 2, 1, and 2. We’ll talk more about this pattern in the next exercise. The entire sequence is C, D, E, F, and G.

Once your patch is in place, test it. You should be able to hear a do-re-mi-fa-so progression.

Challenges

After you get your pentatouch working, answer the following questions on a piece of scratch paper.

  1. Search for a simple and short melody from your childhood. What’s the name of the song? Can you play it using the pentatouch? If you can’t, find a different melody. Write down the notes. Practice your melody and be prepared to play it for the group.
  2. Change the fundamental from 60 to something else. Adjust the other numbers to maintain the same 2-2-1-2 jumping pattern. Does it still sound like a do-re-mi-fa-so progression?
  3. A chord is multiple notes played simultaneously. Write down some combinations of notes that sound good together. Also write down some that don’t sound good together.