1. Introduction to Pure Data
Pure Data , a.k.a. Pd , is a visual programming language and environment for audio and visuals. It is open source and it was made by Miller Puckette during the 1990s. Visual programming means that instead of writing code (a series of keywords and symbols that have a specific meaning in a programming language), you use a graphical interface to create programs, where in most cases, a box represents a certain function, and you connect these boxes with lines, which represent patch cords on analog audio devices. This kind of programming is also called data flow programming because of the way the parts of a program are connected, which indicates how its data flows from one part of the program to another.
Visual programming can have various advantages compared to textual programming. One advantage is that a visual programming language can be very flexible and quick for prototyping, where in many textual programming cases, you need to write a good amount of lines of code before you can achieve even something simple. Another advantage is that you can say that visual programming is more intuitive than textual programming. When non-programmers confront visual code, its very likely that they will get a better idea as to what this code does than when confronting textual code. On the other hand, there are also disadvantages and limitations imposed by visual programming. These are technical and concern things like DSP chains, recursion, and others, but we wont bother with these issues in this book, as well never reach these limits. Nevertheless, Pd is a very powerful and flexible programming language used by professionals and hobbyists alike around the world.
Throughout this book, well use Pd for all of our audio and sequencing programming, always in combination with the Arduino. The Arduino is a prototyping platform used for physical computing (among other things), which enables us to connect the physical world with the world of computers. A thorough introduction to Arduino is given in . This chapter is an introduction to Pd, where well go through its basics, its philosophy, as well as some general electronic music techniques. If you are already using Pd and know its basics, you can skip this chapter and go straight to the next one. Still, if youre using Pd but have a fuzzy understanding on some of its concepts, you might want to read this chapter. Mind that the introduction to Pd made in this chapter is centralized around the chapters that follow, and even though some generic concepts will be covered, it is focused on the techniques that will be used in this books projects.
In order to follow this chapter and the rest of this book, youll need to install Pd on your computer. Luckily, Pd runs on all three major operating systems: OS X, Linux, and Windows. You can download it for free from its web site at https://puredata.info/ . You will find two version of Pd: vanilla and extended. Pd-vanilla (simply Pure Data) is the vanilla version of Pd, as its nickname states. Its the version made and maintained by Miller Puckette, and it consists of the core of Pd. Most of the things well be doing in this book can be made with vanilla, but Pd-extended adds some missing features to Pd that we will sometimes use. For example, the communication between Pd and Arduino is achieved with Pd-extended and not vanilla. Of course, you can add these features to vanilla, but its beyond the scope of this book to explain how to do this, so well be using Pd-extended in all of our projects. Find the version for your OS and install it on your computer before you go on reading.
By the end of this chapter, youll be able to
understand how a Pd program works
create small and simple programs in Pd
find help in the Pd environment
create oscillators in Pd
make use of existing abstractions in Pd and create your own
realize standard electronic music techniques in Pd
Pd Basics: How It Works
Pd consists of several elements that work together to create programs. The most basic elements are the object and the message . An object is a function that receives input and gives output. Figure shows the osc Pd object.
This specific object is a sine wave oscillator with a 440-hertz (Hz) frequency. Theres no need to understand what this object does; well go through that in a bit. There are a few things we need to note. First of all, there is specific text inside the object box, in this case osc 440. osc stands for oscillator , and the (called the tilde ) means that this object is a signal object. In Pd, there are two types of objects: signal and control. A signal object is a function that deals with signals (a digital form of an electric signal). A signal object will run its function for as long as the audio is on (the audio is also called the DSP, which stands for digital signal processing , or the DAC, digital-to-analog converter ). A control object is independent of audio and runs its function only when it is told to. Well get a better picture of the difference between the two as we go. The last part of the text, 440, is called an argument . This is the data that a function receives, and we provide it as an argument when we want to initialize an object with it. It is not necessary to provide an argument; when theres no argument in an object, the object is initialized with the value(s) of zero (0).
The second main element in Pd is the message, which is shown in Figure .
It is a little bit different from the object, because on its right side, it is indented, and it looks a bit like a flag. The message delivers data. Theres no function here, only the data we write in the message (sometimes referred to as a message box ). One thing the object and the message have in common is the inlets and the outlets. These are the little rectangles on the top and the bottom, respectively, of the object and the message. All messages have the same form, no matter what we type in them. They all have one inlet to receive data and one outlet to provide the data typed in them. The objects differ, in the sense that each object has as many inlets as it needs to receive data for its function, and as many outlets as it needs to give the output(s) of the function. With the osc object, we can see that it has two inlets and one outlet. The left inlet and the outlet are different than the right inlet. Their rectangle is filled, whereas the right inlet has its rectangle blank, like the message does. The filled inlets/outlets are signal inlets/outlets and the blank ones are control inlets/outlets. Their differences are the same as the signal and control objects. Note that a signal object can have control inlets/outlets, but a control object cannot have signal inlets/outlets.
Objects and messages in Pd are connected with lines, which we also simply call connections . A message connected to the osc object is shown in Figure .