teaching machines

Pentatouch, Part II

June 13, 2019 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:

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.

You should see the button number first and then the button state. When using repack, it’s pretty easy for the packing to incorrectly start in the middle of a pair. You can reset the alignment of packing to the stream of numbers by sending a bng on the left inlet of repack:

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 our note abstraction. But select only sends along bng messages. There’s another object named route that expects a list of numbers, strips off the first number, chooses an outlet based on that first number, and forwards the remainder of the list 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 a later 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. Which pairs of notes sound pleasing together when played at the same time? Which don’t?