teaching machines

Abstractions

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.

Pure Data patches can get very messy very quickly. Imagine what it would look like if our monodrone had two buttons. Or three. Or five! Lines would canvas the screen like a spider web.

One way to manage complexity is to create an abstraction. Abstractions reduce a complex set of boxes into a single mega-box. Recall the patch for our monodrone:

These are the boxes that are responsible for producing a note:

Let’s reduce this collection into this single abstraction named note:

This note looks like any of the objects that we’ve been using. But there’s a big difference: we’re going to make it ourselves. Abstractions effectively add new commands to Pure Data. We are growing its language with new words.

See that 52 after note? That’s our note’s MIDI number. When we include it after the name of our abstraction, it’s called a creation argument.

To make an abstraction, copy the boxes from trigger to noteout into a new file. Save it under the name note.pd in the same directory as your monodrone. But we still need to make two changes. First, number boxes don’t work very well in abstractions because they don’t hold their values between saves. Change the stop and velocity boxes to float objects. Replace the note number box with a float object as well, but pass it $1. $1 refers to the first creation argument—which is 52 in the example.

Here’s our patch after these changes:

Second, we need to announce that this abstraction expects a number 0 or 1 to start or stop the note. Add an inlet object, and wire it up to the trigger.

We include the name button_state on the inlet. Abstractions can have multiple inlets, so it’s a good idea to give them meaningful names.

Finally, let’s replace the boxes in the monodrone with our new note abstraction:

Test it. It should sound the same as before, but the code is simpler. You’ve just managed complexity. This will be quite helpful as we jump to our next instrument: the five-fingered pentatouch.

Challenges

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

  1. If inlet is used by an abstraction to receive data as input, what object sends data along as output?
  2. Create an abstraction named double. It receives one number through an inlet, doubles the number, and sends the results along as output. Test your abstraction like this: